~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

atproto: the space alpha's set hash, commit and record MACs, KEM and STAR

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:atproto/space

What changes

atproto::space: the space alpha's primitives a repo in a space is held together by, as @atproto/space has them:

  • LtHash, the homomorphic set hash a space repo's records are summed into (BLAKE3 expanded to 1024 u16 lanes), with element for a record's path and CID, and its state kept and read back.
  • Commit, a repo's commit in a space (repo, space, rev, the set hash's digest), its MAC under an agreed secret, and its STAR metadata; record_mac for one record; the atproto-space-mac and atproto-space-want-mac headers, written and (the want) read.
  • decapsulate and encapsulate: DHKEM(P-256, HKDF-SHA256) as RFC 9180 gives it, the secret a syncer's key share agrees with an author's KEM key, worked out either side.
  • star: a repo as a STAR archive, its commit then each record's path and DRISL in byte order.

Why

Step 4 of docs/design/README.md: a group's meta and members spaces, which the host keeps the group's repos in and is the authority for. Every read a syncer makes of them is vouched for with these MACs, and a repo is sent whole as STAR. This pull is the primitives alone; credentials and HTTP signatures come next, then the host's repos in spaces, then the authority.

How it was checked

Against vectors made by running @atproto/space (pds.js's space-vectors.json, vendored in tests/reference): every LtHash state and digest (empty, single elements, sets); a commit's set-hash data, MAC, MAC header and STAR archive, byte for byte; a record's MAC and header; a KEM decapsulation and the want-MAC header. And against knotless's own client of the alpha, in a scratch crate linking both: the same set hash state over the same records, and a commit MAC knotless's vouched accepts under the secret knotless agreed and this decapsulated. Round trips, and each key and header refused. cargo llvm-cov at 100% of lines and functions, clippy clean.

Shortcomings

The vectors name the October 22 alpha as their source; pds.js committed them with its October 29 update, and knotless's client, which agrees here, runs against the October 29 alpha. The MAC header is written as the reference writes it, not parsed as a general structured-field dictionary.

Approved

This adds atproto::space: the LtHash set hash, the commit and record MACs and their headers, DHKEM(P-256) encapsulate/decapsulate, and STAR. It also vendors the reference vectors, adds a test file, and updates the design doc. All checks pass: test with the coverage gate, fmt and clippy. The web and lexicons checks were skipped because the pull touches nothing they read.

I read every changed file except the space-vectors.json contents, which are generated data. The tests compare the code against them byte for byte. The KEM derivation follows RFC 9180 §4.1: suite id KEM || 0x0010, eae_prk extract with an empty salt, and a single-block expand with L=32. The HKDF with no salt (hmac(&[], ..)) is correct. The docs are updated as AGENTS.md asks.

Two small things, neither blocking:

  • length_prefixed casts text.len() to u16, which silently truncates above 65535 bytes. That's unlikely for a space URI, rev or DID, but it would give a wrong MAC rather than an error.
  • parse_want_mac splits on ,, so a quoted value containing a comma would be misparsed. Your shortcomings section already says the header isn't parsed as a general dictionary, and a did:key never contains a comma.
Merged as bdb7486