墨kazokuai.dev

The house link

contract 1text v1.2written in Sumi; canonical in KazokuAI's docs/house-link once adopted

The reference peer

A small app that does everything the text says, as either side of a pairing (Node 22 and Fastify): node reference-peer.mjs [--port 8397] [--name "Reference peer"] [--origin http://…]. Download it.

Signing vectors

Three claims objects signed under the key 0x00…0x1f; an implementation must get each MAC exactly (§11).

House link — pairing two apps and linking their members

Status: contract 1, text v1.2, 2026-10-07 (Sumi pass 12.1; v1.1, 2026-10-07, Sumi pass 12; v1.0, 2026-10-06, Sumi pass 11). Written from Sumi's brief R32 (pairing and linking, not SSO), R33 (audience, the minor flag) and R8 (hues), and the pass-11 prompt's rulings. Nothing here goes beyond them; where they left a shape open, this text picked the plainest one and the pass-11 report lists each pick. v1.1 adds one sentence to §5 step 2 (the confirm shows what follows the home before the yes) and the reference peer's confirm and member pages that show it; nothing a token, a check or an endpoint does changed, so the contract is still 1. v1.2 names example hosts only (sumi.home.arpa, peer.home.arpa, RFC 8375's residential names, and sumi.example) in §1, §11's vector 2 and §12 and in the reference peer's placeholders, so vector 2's canonical JSON, MAC and token are new; the rules are v1.1's and the contract is still 1.

This directory — LINK.md (this), link.schema.json (every body and every token's claims as JSON Schema), reference-peer.mjs (a small app that does everything this text says, both roles, from this text alone), VERSION (the contract number) and CHECKSUMS (sha256 of the three files) — was written in Sumi's repo at spec/house-link/. Its canonical home is docs/house-link/ in the KazokuAI repo, which adopts this text verbatim at contract 1; from then on Sumi's copy is the vendored one, checked by a test against the version it claims, as Sumi vendors the game-package contract.

Two apps a house runs side by side — Sumi and KazokuAI, or any two that speak this text — each keep their own members, their own sign-in and their own data. A pairing lets the two apps trust each other's signed words; a link says that one member of each is the same person. With both, a member can open the other app already signed in, see the same name and colour there, and send a game across. Neither app ever needs the other to sign anyone in: a member can always sign in to either app on its own, and unpairing leaves both apps as they were before.

Words: MUST, MUST NOT and MAY are requirements; "never" is MUST NOT.

1. Terms

2. Pairing

Made once, by one admin of each app. App A shows a code; app B's admin types it in with A's address.

  1. A shows a code. A's admin asks for one. The code is 8 symbols from Crockford's base-32 alphabet 0123456789ABCDEFGHJKMNPQRSTVWXYZ (32 symbols, no I, L, O or U), each drawn from a cryptographic random source, shown in two groups of four (7KQ2 M9XD) with A's origin beside it. It lasts 10 minutes from when it is shown, is good for one pairing, and ends when a new code is shown, when the admin cancels it, or after 5 wrong tries (§2.2). A that already has a peer shows no code.

  2. B's admin enters A's origin and the code. B normalizes the origin (§1) and sends, server to server:

    POST <A origin>/api/house-link/pair · content-type: application/json

    {"contract": 1, "code": "7KQ2M9XD", "origin": "<B origin>", "name": "<B's name>", "capabilities": ["…"]}
    

    B that already has a peer sends nothing.

  3. A checks the code. A reads the code case-insensitively, drops spaces and hyphens, and reads I and L as 1 and O as 0. Then, in this order: a peer already → 409 already_paired; contract not one A speaks → 400 contract; no code showing, or a different code → 403 bad_code (a wrong try, §2.2); the code past its 10 minutes → 403 expired_code. Otherwise the code is used up, A draws a key of 32 random bytes, stores the peer (§2.1) and answers 200:

    {"contract": 1, "key": "<43 characters: the key, base64url, no padding>", "origin": "<A origin>", "name": "<A's name>", "capabilities": ["…"]}
    

    origin is the origin A showed with the code.

  4. B stores the peer. B checks the answer: contract one it speaks, origin the origin its admin typed, key 32 bytes. Then it stores the peer as A did. If B can't keep it after A has answered, B's admin says so plainly and A's admin unpairs (a later pairing gets already_paired from A until then).

The admin of either app sees the peer's name, origin, capabilities and when they were paired, and can unpair.

2.1 What each app keeps

{peer origin, peer name, key, capabilities, paired_at, own origin} — own origin is the origin this app named in the pairing (A: the one shown with the code; B: the one it sent). Every token this app signs names it as iss, and every token it accepts must name it as aud (§3).

The key is a secret. An app keeps it with its other secrets (Sumi: secrets.toml, section [house_link], mode 600, written by the app) — never in its database, a log line, an error, a page or a report — and never sends it anywhere but in the pair answer above. Both apps use the same key for both directions.

2.2 Wrong tries

The pair route is open (B has no session on A). A counts wrong codes against the code showing: the fifth wrong try ends the code, and A's admin shows a new one. With 32^8 codes, 5 tries and 10 minutes, a guess succeeds about once in 2·10^11.

2.3 Unpairing

Either admin may unpair. The app signs an unpair token (§4) and sends, server to server,

DELETE <peer origin>/api/house-link/pair · authorization: HouseLink <token>

waits at most 10 seconds, and then deletes its side whatever the answer: the key, the peer, every link (§5), every nonce (§3.4). A peer that accepts the token (§3.3, with no link check) deletes the same and answers 200 {"ok": true}. An app that receives no notice keeps a pairing whose tokens nobody will sign again; its admin unpairs there too.

3. Tokens

Everything one app says to the other after pairing is a token: a JSON object of claims, signed with the key.

3.1 Canonical JSON

The bytes a token signs are its claims as canonical JSON: RFC 8785 (JCS) for the values this text uses — objects, arrays, strings, integers from −(2^53−1) to 2^53−1, true, false, null (never a fraction or an exponent):

3.2 Signing

mac   = HMAC-SHA256(key, canonical bytes)
token = base64url(canonical bytes) "." base64url(mac)

base64url is RFC 4648 §5 with no = padding. A token is one line, both parts in the URL-safe alphabet, one . between.

3.3 Checking a token

A receiver checks a token in this order and refuses at the first failure with the reason named (§9). Every refusal is a plain line to the member (when a member is looking) and a line in the receiver's log — never the token itself.

  1. Form. Two parts around one ., each base64url; the MAC part decodes to 32 bytes. Else malformed.
  2. Paired. The receiver has a peer and its key. Else not_paired.
  3. Signature. HMAC-SHA256 of the first part's decoded bytes under the key equals the MAC part, compared in constant time. Else bad_signature. Then the bytes are parsed as JSON; an object whose canonical form (§3.1) is exactly those bytes, with every claim §4 requires for its typ, each of its type — else malformed.
  4. Type. typ is the one this endpoint takes. Else wrong_type.
  5. Issuer and audience. iss is the peer's origin, else wrong_issuer; aud is the receiver's own origin (§2.1), else wrong_audience.
  6. Time. With now the receiver's clock in whole seconds since 1970-01-01 UTC and a skew of 30 seconds: exp > iat and exp − iat at most the type's lifetime (§4: 60 s for an assertion, 300 s for a link token), else too_long; iat ≤ now + 30, else skewed; now ≤ exp + 30, else expired.
  7. Nonce. The receiver has not accepted this nonce before (§3.4). Else replayed. From here on the nonce is spent, whatever step 8 says.
  8. Link. What the type needs (§4): the link for sub and member_id, else unknown_link; the intent named by intent, else unknown_intent.

3.4 Nonces

Every token carries a nonce: 16 bytes from a cryptographic random source, base64url (22 characters). A receiver keeps each nonce it accepted (step 7) with the token's exp, until now > exp + 30, and refuses a token whose nonce it holds. Kept nonces are the receiver's own, per peer; unpairing drops them.

3.5 Clocks

Both apps keep their clocks within 30 seconds of true time (NTP). The skew is the only slack; nothing else adjusts for it.

4. Token types

Every token has the five claims below, and its type's.

claim type meaning
typ string The token's type: one of this section's.
iss string, an origin The sender's own origin (§2.1).
aud string, an origin The receiver's origin, as the sender stored it (the peer origin).
iat integer, seconds When it was signed (Unix time).
exp integer, seconds When it stops being good (before the skew).
nonce string, 22 characters 16 random bytes, base64url, once only (§3.4).

A member's claims, where a type carries a member — the sender's member as the sender knows them:

claim type meaning
member_id string, 1–64 characters The sender's id for its member. Opaque to the receiver.
name string, 1–80 characters The member's name in the sender. A receiver MAY cut it to its own limit.
hue integer 0–359 The member's hue in the sender.
role "adult" · "minor" The member's role in the sender (§1).
typ lifetime claims beside the five sent to step 8
link ≤ 300 s the member's four POST /house-link/link (a browser form, §5) none
linked ≤ 300 s the member's four; intent (the link token's nonce); for (the member_id of that link token) POST /house-link/linked (a browser form, §5) the intent: one the receiver signed, not past its exp + 30, not used, for the member for
assert ≤ 60 s the member's four; sub (the receiver's id for this member) POST /house-link/assert (a browser form, §6) the link sub ↔ member_id
install ≤ 60 s as assert; sha256 (the request body's, lower-case hex) POST /api/house-link/games/install (§8) the link sub ↔ member_id
songs ≤ 60 s as install POST /api/house-link/songs/make (§8) the link sub ↔ member_id
unlink ≤ 60 s member_id (the sender's member); sub (the receiver's) DELETE /api/house-link/link (§5.3) the link sub ↔ member_id
unpair ≤ 60 s none DELETE /api/house-link/pair (§2.3) none

"The link sub ↔ member_id": the receiver has a link whose own member is sub and whose peer member is member_id. A receiver ignores claims it doesn't know (§10). Every length in this text counts Unicode code points, as JSON Schema's minLength and maxLength do (a name of 80 emoji is 80 characters, not 160).

5. Linking members

A member links their two accounts once, from either app, signed in to both. Call the app they start in S and the other O.

  1. S signs a link token. The member asks S to link (Sumi: Settings › Me › Link). S signs link with its member's four claims and keeps the token's nonce with its member's id as a pending intent until exp + 30. S opens O in a new tab with a form that posts the token: POST <O origin>/house-link/link · content-type: application/x-www-form-urlencoded · token=<token>.
  2. O asks its member. O checks the token (§3.3, steps 1–7). Then O shows its own signed-in member — signing in first if nobody is, never anyone else — "link <S's name>'s <name> to you?" with the hue and the role, and links only on an explicit yes. Before that yes, when either app is the home (§7), O shows what follows the home — the name, the hue with its swatch and the role that the non-home side's member will have once linked — and when neither is, says that nothing changes; O keeps the same note on its member's page afterwards. (A browser doesn't send SameSite=Lax cookies on a cross-site POST, so O will usually keep the checked token server-side under a random id and redirect, 303, to a page of its own that asks.) A no ends it there: nothing is sent, and S's intent expires.
  3. O links and answers. On yes, O stores the link — its member ↔ the token's member_id, with the token's name, hue and role to show — replacing any link either of the two had in O; applies §7; and signs linked with its member's four claims, intent = the link token's nonce and for = its member_id. The browser posts it back: POST <S origin>/house-link/linked · form · token=<token>.
  4. S links. S checks the token (§3.3, step 8: the pending intent), stores the link — its member for ↔ the token's member_id, with its name, hue and role — replacing any link either had in S, forgets the intent, applies §7, and shows the member their link.

A member has at most one link, and so has a peer member. Either app may start.

5.1 What each app keeps

A link is {own member id, peer member id, peer name, peer hue, peer role, linked_at}. The peer's name, hue and role are updated from every token the peer sends for that member (§7 says when they also change the app's own member).

A link stored over an older one leaves the older one's other half in the peer. That half is harmless: every check of a link takes both ids (step 8), so a token for the old pair finds nothing.

5.3 Unlinking

Either app's member may unlink (Sumi: Settings › Me › Unlink). The app deletes its link, signs unlink, and sends, server to server, DELETE <peer origin>/api/house-link/link · authorization: HouseLink <token>, waiting at most 10 s; its own link is gone whatever the answer. The peer deletes the link sub ↔ member_id and answers 200 {"ok": true} (or 404 unknown_link when it had none).

6. Open in

A linked member opens the other app already signed in (Sumi: Open in <peer> in Settings › Me and the avatar menu).

  1. S signs assert with its member's four claims and sub = the peer member id of the link, and the browser posts it — a form, the token in the body, never in a URL: POST <O origin>/house-link/assert · form · token=<token>.
  2. O checks it (§3.3, step 8: the link). On success O applies §7, starts its own session for sub — as its own sign-in would, by its own rules (a member it has switched off stays out, with a plain line) — and redirects, 303, to its root.
  3. On unknown_link, O shows "not linked here" and its own way to link (§5). On any other refusal, O shows the plain line for it (§9).

A token in a URL ends up in histories, logs and Referer headers: none of this text's tokens is ever put in one.

7. Sync

On every token it accepts that carries a member's claims (linked, assert, install, songs; and a link once its member says yes), the receiver updates the link's peer name, hue and role. Then:

An app that declared "home" never copies from its peer. If both declared it, neither copies.

8. Capabilities

A capability is a string an app declares in its pairing (capabilities[]); an app ignores one it doesn't know. To declare a new one, the apps pair again (contract 1). This text defines:

9. Refusals

Every refusal names one reason; the API answers {"error": "<plain line>", "reason": "<reason>"} (install and songs add their own fields, §8) with the status below. A browser route (/house-link/*) shows the plain line on a page instead.

reason status plain line (the receiver's words may differ)
bad_request 400 the request isn't one this text describes
contract 400 the other app speaks another contract
already_paired 409 already paired — unpair first
bad_code 403 that code isn't the one showing
expired_code 403 that code has expired — show a new one
malformed 400 that isn't a house-link token
not_paired 409 this app isn't paired
bad_signature 403 the signature doesn't hold
wrong_type 400 that token is for another step
wrong_issuer 403 that token comes from another app
wrong_audience 403 that token is for another app
too_long 403 that token lasts longer than this step allows
skewed 403 that token is from the future — check both clocks
expired 403 that token has expired — try again
replayed 403 that token was already used
unknown_link 404 not linked here
unknown_intent 404 that link wasn't asked for here, or it has expired
bad_body 400 the body isn't the one the token signed

10. Versioning

11. Signing vectors

The key for all three is the 32 bytes 0x00, 0x01, … 0x1f (base64url AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8). An implementation signs each claims object and must get exactly the canonical JSON, the MAC (hex) and the token shown.

Vector 1: an assert

claims, as written:

{"typ": "assert", "iss": "https://kazoku.example", "aud": "https://sumi.example", "iat": 1790000000, "exp": 1790000060, "nonce": "AAECAwQFBgcICQoLDA0ODw", "sub": "0123456789abcdef", "member_id": "m-42", "name": "Mika", "hue": 150, "role": "adult"}

canonical JSON:

{"aud":"https://sumi.example","exp":1790000060,"hue":150,"iat":1790000000,"iss":"https://kazoku.example","member_id":"m-42","name":"Mika","nonce":"AAECAwQFBgcICQoLDA0ODw","role":"adult","sub":"0123456789abcdef","typ":"assert"}

mac: 4ed38625c15f1c3558071f03939cee66b36fbd47f1d78e1788e6b6552ae033f7

token:

eyJhdWQiOiJodHRwczovL3N1bWkuZXhhbXBsZSIsImV4cCI6MTc5MDAwMDA2MCwiaHVlIjoxNTAsImlhdCI6MTc5MDAwMDAwMCwiaXNzIjoiaHR0cHM6Ly9rYXpva3UuZXhhbXBsZSIsIm1lbWJlcl9pZCI6Im0tNDIiLCJuYW1lIjoiTWlrYSIsIm5vbmNlIjoiQUFFQ0F3UUZCZ2NJQ1FvTERBME9EdyIsInJvbGUiOiJhZHVsdCIsInN1YiI6IjAxMjM0NTY3ODlhYmNkZWYiLCJ0eXAiOiJhc3NlcnQifQ.TtOGJcFfHDVYBx8Dk5zuZrNvvUfx144XiOa2VSrgM_c

claims, as written:

{"typ": "link", "iss": "http://sumi.home.arpa:8395", "aud": "http://peer.home.arpa:8397", "iat": 1790000123, "exp": 1790000423, "nonce": "_-_-_-_-_-_-_-_-_-_-_w", "member_id": "a1b2c3d4e5f60718", "name": "Noa \"the kid\" \\ 墨\tみ", "hue": 0, "role": "minor"}

canonical JSON:

{"aud":"http://peer.home.arpa:8397","exp":1790000423,"hue":0,"iat":1790000123,"iss":"http://sumi.home.arpa:8395","member_id":"a1b2c3d4e5f60718","name":"Noa \"the kid\" \\ 墨\tみ","nonce":"_-_-_-_-_-_-_-_-_-_-_w","role":"minor","typ":"link"}

mac: 2b306d3c7931f97f8e5509785f44f2d8f09c55434af7a82b51cd275fdd716d88

token:

eyJhdWQiOiJodHRwOi8vcGVlci5ob21lLmFycGE6ODM5NyIsImV4cCI6MTc5MDAwMDQyMywiaHVlIjowLCJpYXQiOjE3OTAwMDAxMjMsImlzcyI6Imh0dHA6Ly9zdW1pLmhvbWUuYXJwYTo4Mzk1IiwibWVtYmVyX2lkIjoiYTFiMmMzZDRlNWY2MDcxOCIsIm5hbWUiOiJOb2EgXCJ0aGUga2lkXCIgXFwg5aKoXHTjgb8iLCJub25jZSI6Il8tXy1fLV8tXy1fLV8tXy1fLV8tX3ciLCJyb2xlIjoibWlub3IiLCJ0eXAiOiJsaW5rIn0.KzBtPHkx-X-OVQl4X0Ty2PCcVUNK96grUc0nX91xbYg

Vector 3: an install

claims, as written:

{"typ": "install", "iss": "https://sumi.example", "aud": "https://kazoku.example", "iat": 1790000500, "exp": 1790000560, "nonce": "ZmZmZmZmZmZmZmZmZmZmZg", "sub": "m-42", "member_id": "0123456789abcdef", "name": "Mika", "hue": 359, "role": "adult", "sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}

canonical JSON:

{"aud":"https://kazoku.example","exp":1790000560,"hue":359,"iat":1790000500,"iss":"https://sumi.example","member_id":"0123456789abcdef","name":"Mika","nonce":"ZmZmZmZmZmZmZmZmZmZmZg","role":"adult","sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","sub":"m-42","typ":"install"}

mac: c88e6f7ed85fe444e1d3c92c1ae6e59c1ed7357b3146a703739b4e053d939077

token:

eyJhdWQiOiJodHRwczovL2them9rdS5leGFtcGxlIiwiZXhwIjoxNzkwMDAwNTYwLCJodWUiOjM1OSwiaWF0IjoxNzkwMDAwNTAwLCJpc3MiOiJodHRwczovL3N1bWkuZXhhbXBsZSIsIm1lbWJlcl9pZCI6IjAxMjM0NTY3ODlhYmNkZWYiLCJuYW1lIjoiTWlrYSIsIm5vbmNlIjoiWm1abVptWm1abVptWm1abVptWm1aZyIsInJvbGUiOiJhZHVsdCIsInNoYTI1NiI6ImUzYjBjNDQyOThmYzFjMTQ5YWZiZjRjODk5NmZiOTI0MjdhZTQxZTQ2NDliOTM0Y2E0OTU5OTFiNzg1MmI4NTUiLCJzdWIiOiJtLTQyIiwidHlwIjoiaW5zdGFsbCJ9.yI5vfthf5ETh08ksGublnB7XNXsxRqcDc5tOBT2TkHc

12. The reference peer

reference-peer.mjs is a small app (Node 22 and Fastify 5; nothing else) that does all of this text, as either app of a pairing: it shows a code or enters one, links from its side or confirms a link from the other, opens the other app or is opened, syncs as the home (it declares "home", "games.install" and "songs.make"), unlinks, unpairs, installs a package for a linked parent and refuses one for anyone else. It keeps everything in memory and has a tiny sign-in (pick a member; no passwords): it is for checking an implementation, never for a house to run.

node spec/house-link/reference-peer.mjs [--port 8397] [--name "Reference peer"] [--origin http://peer.home.arpa:8397]

It was written from this text, not from either app's code, and it is the reference for both apps' implementers: Sumi's tests run against it, and KazokuAI's half is written against it too. Where it and this text disagree, this text rules and the peer is fixed.

13. What this does not do