oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1-- Oficina ID, the native slice (docs/superpowers/specs/2026-11-14-oficina-id-native.md).
2--
3-- A grant is a device's long-lived Oficina ID credential (§3). Only the
4-- SHA-256 of its token is stored. identity_id is an HMAC of the person ref
5-- under a Home-only key, so a device can tell identities apart without
6-- holding the ref. Ended rows keep device_key for 365 days so that §4 can
7-- recognise a returning device; end_reason says how it ended.
8CREATE TABLE home_id_grants (
9 grant_hash TEXT PRIMARY KEY,
10 person_ref TEXT NOT NULL,
11 identity_id TEXT NOT NULL,
12 device_key TEXT NOT NULL,
13 platform TEXT NOT NULL,
14 method TEXT NOT NULL,
15 auth_time INTEGER NOT NULL,
16 created_at INTEGER NOT NULL,
17 last_used_day TEXT NOT NULL,
18 expires_at INTEGER NOT NULL,
19 ended_at INTEGER,
20 end_reason TEXT CHECK (end_reason IN ('expiry','lru','enrolment','signout','all_devices','revoke','replacement'))
21);
22CREATE INDEX home_id_grants_person ON home_id_grants(person_ref, ended_at);
23CREATE INDEX home_id_grants_device ON home_id_grants(device_key, person_ref);
24CREATE INDEX home_id_grants_ended ON home_id_grants(ended_at);
25
26-- The proof replay table (§3): one row per accepted jti, written only after
27-- the grant and the signature verify, kept 60 seconds. It is also the
28-- per-grant rate limit's counter.
29CREATE TABLE home_id_native_replay (
30 jti_hash TEXT PRIMARY KEY,
31 grant_hash TEXT NOT NULL,
32 person_ref TEXT NOT NULL,
33 expires_at INTEGER NOT NULL
34);
35CREATE INDEX home_id_native_replay_grant ON home_id_native_replay(grant_hash, expires_at);
36CREATE INDEX home_id_native_replay_person ON home_id_native_replay(person_ref, expires_at);
37CREATE INDEX home_id_native_replay_expiry ON home_id_native_replay(expires_at);
38
39-- A live email code (§4). The address is sealed before it is written and the
40-- row is deleted at verify or expiry, under secure_delete.
41-- blind_index is a Home-keyed HMAC used only to keep one live code per (address, device key);
42-- ip_bucket is blinded the same way. code_mac is an HMAC of the code, never
43-- the code.
44CREATE TABLE home_id_native_starts (
45 start_hash TEXT PRIMARY KEY,
46 sealed_address BLOB NOT NULL,
47 blind_index TEXT NOT NULL,
48 device_key TEXT NOT NULL,
49 platform TEXT NOT NULL,
50 ip_bucket TEXT NOT NULL,
51 code_mac TEXT NOT NULL,
52 sends INTEGER NOT NULL,
53 last_send INTEGER NOT NULL,
54 attempts INTEGER NOT NULL,
55 expires_at INTEGER NOT NULL,
56 UNIQUE (blind_index, device_key)
57);
58CREATE INDEX home_id_native_starts_ip ON home_id_native_starts(ip_bucket, expires_at);
59CREATE INDEX home_id_native_starts_expiry ON home_id_native_starts(expires_at);
60
61-- A code verified for an account that has a passkey (§4): the person must
62-- still assert one. Valid five minutes and bound to the start and its key.
63CREATE TABLE home_id_native_pending (
64 pending_hash TEXT PRIMARY KEY,
65 person_ref TEXT NOT NULL,
66 start_hash TEXT NOT NULL,
67 device_key TEXT NOT NULL,
68 platform TEXT NOT NULL,
69 method TEXT NOT NULL,
70 expires_at INTEGER NOT NULL
71);
72CREATE INDEX home_id_native_pending_expiry ON home_id_native_pending(expires_at);
73
74-- Persistent fixed-window counters for §4's limits. Keys are blinded; none
75-- shares a key with home_id_attempts, which recovery uses.
76CREATE TABLE home_id_native_buckets (
77 bucket TEXT PRIMARY KEY,
78 count INTEGER NOT NULL,
79 expires_at INTEGER NOT NULL
80);
81CREATE INDEX home_id_native_buckets_expiry ON home_id_native_buckets(expires_at);
82
83-- Native passkey challenges count within home_id_ceremonies; this records
84-- the device key and platform a native challenge is bound to (§5), keyed by
85-- the same challenge and deleted with it.
86CREATE TABLE home_id_native_ceremonies (
87 challenge TEXT PRIMARY KEY,
88 device_key TEXT NOT NULL,
89 platform TEXT NOT NULL,
90 pending TEXT NOT NULL,
91 expires_at INTEGER NOT NULL
92);
93
94-- The credential origin's copy of the "Sign out all devices" mark (§10): the
95-- press time, per person. No grant created at or before it authenticates,
96-- and rows older than five minutes are pruned.
97CREATE TABLE home_id_signed_out_all (
98 person_ref TEXT PRIMARY KEY,
99 at INTEGER NOT NULL
100);
101CREATE INDEX home_id_signed_out_all_at ON home_id_signed_out_all(at);
102