feat/oficina-id-native-connect
🤖 Oficina ID native slice A — the consumer (connect) half. Implements Home spec docs/superpowers/specs/2026-11-14-oficina-id-native.md (approved by Paul and cleared to build, 2026-11-14) §7, §8 and the matching §13 gates, in handoff and connect. Docs is wired to it on oficina/docs branch feat/oficina-id-native-connect. The Home id.* side (grant, codes, passkeys, assert) is a separate branch by another agent; the two meet only at the wire formats below. Do not merge without review. No deploy.
What changed
- handoff (
native.go):NativeChallenge/NativeNonce, the one derivation bothassertand the instance use, with a fixed test vector;Store.Verify(consumes nothing);Store.Reserve(burns(iss,jti)in its own committed transaction, refuses a jti already reserved or waiting in a browser inbox). - connect: one predicate.
IsHomeDerived(home-assertion, home-assertion-native, home-native-web) replaces the literal checks (finish's CurrentSubject, existingPerson, signedIn).Expiredrefuses native and native-web sessions 7 days afterAt, absolute, or with noAt. - connect: members choose (§8, browser). New
Config.Admit, set withUnlinkedandHomeOnlyor not at all (Newenforces it). The roster decision comes first and allocates nothing: a non-member gets today's unknown answer byte for byte, an unavailable roster 503, and a Member a sealed, single-use, browser-bound 10-minute choice proof (linkstore migration0003_choice_proofs.sql) plus a 303 to/account/home/choose.ChoosePage/ChoosePost: the form token is an HMAC of the proof cookie and the POST needs an exact same-originOrigin. "connect" consumes the proof and resumes linking through/signin/local. "new" refuses while any app session is present, consumes the proof in its own transaction, rechecks the link andAdmitwith no transaction open, allocates throughUnlinked, re-resolves and mints, then lands on/. Any app session at finish still gets unknown plus the marker, beforeAdmit, with no proof issued. - connect:
NativeExchange(§7).POST /native/oficina-idruns the spec's five steps in order and holds no transaction across any hook or the mint. It mints through the newConfig.MintNativeSession, with methodhome-assertion-native.Routes.Middlewarelets this one path past CSRF, because the exchange itself refusesOrigin/Sec-Fetch-Site. - Sign-out also clears a pending choice;
Sweepdrops expired proofs. The README documents all of it.
Wire notes (please check; flagged items need a ruling or the other agents' agreement)
- Nonce derivation (aligned with the Swift client, a1039a1). verifier = 32 random bytes, sent as 43-char unpadded base64url. challenge = base64url(SHA-256(the verifier's 43 ASCII characters)), the S256 convention
/native/exchangealready uses; this isassert'schallenge. nonce = base64url(SHA-256("oficina-id/native/v1"‖0x00‖ the challenge's raw 32 bytes)[:16]), 22 chars. It is cut to 16 bytes because a rastrillo assertion nonce must be exactly 16 bytes. Vector: verifierAAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8, challenge6oZqdX5MOLq_qBJ8vppAnT4fk6AP8UiP9zX8-Rev_9A, nonceZVVVj2zbBfhkAIwAOKNylg. *FLAG for the id. agent:** Home'sassertshould callhandoff.NativeNonce(repinhandoffin the root module) rather than reimplement it. - Request:
{"assertion","verifier","target"?,"choice"?},Content-Type: application/json, at most 12 KiB, unknown or duplicate members refused. NoOriginand noSec-Fetch-Site. This differs from rastrillo/native's/native/exchange, which needs same-origin evidence to pass CSRF. No cookies are needed; the Swift client should send none. - Answers are JSON
{"state":…},no-store, with noSet-Cookie:200 ok {name, value, expires_at[, target]}(sendname=valueas the Cookie on instance requests, as with/native/exchangetoday);403 unknown;409 choose;503 unavailable. Two additions (FLAG):400 invalidfor a malformed request and401 failedfor an assertion that is not accepted (bad, expired, wrong audience or verifier, or already used: fetch a fresh one and retry once).404when an instance has not enabled the exchange. target(FLAG: the spec names it but does not define it). I read it as an optional local path the app wants to open. It is validated withhandoff.SafePath(400 otherwise), echoed in the 200, and has no other effect.- Step 5's "recheck admission" (FLAG). Re-
Resolve(whoseLookupPersonrechecks a linked account's admission), plusAdmitagain for a Home-only person. A Home-only person the roster no longer lists therefore gets the identical 403 natively. The browser path does not ask the roster at mint, as before. - The choose page's button order (FLAG for Paul). The spec lists "Connect my existing account" first; Docs draws it as the primary button and "I'm new here — continue with Oficina ID" as the ghost.
- Natively, "Connect my existing account" opens
<origin>/account/home, as the spec says.choiceis sent only from the "I'm new here" button.
Deferred / not here
- Unlink: TODO for whoever builds it (Fable, 2026-11-14). Neither connect nor Docs has an unlink path today (Docs' triggers forbid deleting links). When one is built, unlinking a subject must delete every
IsHomeDerivedsession for it (home-assertion, home-assertion-native, home-native-web) and that subject'shome_choice_proofsrows, in the same change, with the "concurrent exchange, unlink and relink" gate from spec §13. Concurrent native choices for one subject are tested today (one person). - Known and accepted (Fable; recorded in the spec): an instance cannot tell a native assertion from a browser one minted through
/authorizewith a caller-chosen nonce equal to a native nonce. Only the subject's own browser can do that, for itself, so it grants no extra privilege. There is a comment at the nonce check innative.go. home-native-webis only recognised (predicate and age limit); minting it is slice D.- Slice C (Sheets, Calendar, Memoria, Calls), no change yet. To adopt: set
Admit(teammodeAdmitUnlinked:ErrNotMember→connect.ErrNoPerson),MintNativeSession; mountChoosePage/ChoosePost/NativeExchange; render statechoosefromChoiceFor+English["choose_*"]; useIsHomeDerived/Expired. A team-mode app that bumps connect without settingAdmitrefuses to boot (intended: §8's invariant). A sharedhome-choosetemplate could move into estilohomeconnect. teammode's own go.mod still pins an older connect (unchanged; nothing there calls the new API).
Repin after landing
connect/go.mod requires handoff at branch commit d11246a; after the squash, repin it to the main commit. Docs' branch pins connect+handoff at this branch's tip and needs the same repin.
Wire alignment with the Swift client (rastrillo/native native/oficina-id-slice-a @a1039a1)
- Challenge: I first hashed the verifier's raw bytes, then changed to hashing the string (
d11246a), so the two now match. - The 200 answer is a superset of
{name, value}: it also carriesstateandexpires_at, which the client ignores. 403, 409 and 503 match. NoOriginand no cookie on the request match.targetis never sent, which is fine because it is optional. - 400
invalidand 401failedare extra. The client should treat 401 from the exchange as "fetch a fresh assertion, retry once", not as a dead session. /native/web/endis slice D. connect does not serve it yet.- The directory (
https://oficina.works/native/oficina-id) needs its own NativeExchange-equivalent. The directory is Home's root module, not a connect consumer, so that belongs to the id.*/directory branch.handoff.Verify/Reserve/NativeNonceare there for it.
Review
Fable reviewed a4da657: APPROVE AFTER FIXES. The fixes are at c70205a:
- The writer-held gate now fails fast with "called with the writer held: [Unlinked]". I proved it with Fable's mutation: holding a transaction across Unlinked used to hang the gate for more than 3 minutes, and now fails it in 2 s.
- The gate also covers a known person's browser finish.
- Sign-out deletes the pending choice-proof row as well as its cookie.
CurrentSubjectignores an Expired session.MintNativeSessionnow states that the session store's lifetime must be at least 7 days.make testis green atc70205a.
Discussions
- No discussions on this branch yet.
Tasks 5/7 done
- handoff: native nonce derivation, Verify, Reserve (c43a910) Done
- connect: IsHomeDerived and the 7-day absolute limit Done
- connect: Admit first, member choice proof, choose page (browser §8) Done
- connect: NativeExchange (§7) with the §13 exchange gates, incl. writer-held probe Done
- Highest-capability review (Fable): APPROVE AFTER FIXES on a4da657; fixes at c70205a Done
Activity
- claude agent, operated by paul@keymail.dev opened After landing: repin connect's handoff and Docs' connect+handoff to the main commit
- claude agent, operated by paul@keymail.dev opened Agree wire notes with the id.* (assert) agent (handoff.NativeNonce, directory exchange); Swift aligned at d11246a; Paul rules on button order
- claude agent, operated by paul@keymail.dev opened Highest-capability review (Fable): APPROVE AFTER FIXES on a4da657; fixes at c70205a
- claude agent, operated by paul@keymail.dev opened connect: NativeExchange (§7) with the §13 exchange gates, incl. writer-held probe
- claude agent, operated by paul@keymail.dev opened connect: Admit first, member choice proof, choose page (browser §8)
- claude agent, operated by paul@keymail.dev opened connect: IsHomeDerived and the 7-day absolute limit
- claude agent, operated by paul@keymail.dev opened handoff: native nonce derivation, Verify, Reserve (c43a910)