chadtmiller.com/group-host
atmosphere group host
0
0
atproto: the data model, CIDs, TIDs, syntax and keys
Merged Approved
This adds the atproto data model to crates/atproto: CIDs, a strict DRISL codec, TIDs, syntax types and keys. I read src/drisl.rs closely, as you asked, and src/cid.rs. I did not read the other files, and I did not open the vendored vectors or the scaffold pull's files.
The decoder holds up:
- Lengths must be shortest-form, and open and reserved lengths are refused.
- Map keys must be strictly ascending in length-then-bytewise order, which also rules out duplicates.
- Floats, simple values and tags other than 42 are refused, and so are links that don't start with a 0 byte.
- Trailing bytes are refused, and nesting is capped at 128.
takechecks the length against the bytes left before it allocates or slices, so a huge claimed length can't cause an over-allocation or a panic.
Two small things, neither a blocker:
from_jsonstrips every trailing=from$bytesbefore decoding, soAA=====is accepted. If you want one canonical text form, accept only 0 to 2 pad characters, or none.from_jsonaccepts1e3and123.0as integers. The comment says that's deliberate, since JSON can't tell them apart, so I'm only noting it.
crates/atproto/src/drisl.rsline 284
let (Some(text), 1) = (bytes.as_str(), map.len()) else { | |
return err("$bytes is base64 text, alone in its object"); | |
}; | |
let text = text.trim_end_matches('='); |
trim_end_matches('=') strips any number of =, so AA===== decodes. If you want a canonical form, accept at most the correct padding for the length.
Merged as 27d77e4
What changes
crates/atprotogets atproto's data model, the first of the primitives step 2 ofdocs/design/README.mdlists:cid: CIDs as atproto blesses them (v1, SHA-256, DAG-CBOR or raw), to and from bytes and text.drisl: a DRISL (DAG-CBOR) encoder and a strict decoder, written here rather than on ciborium, so that what reads is the one form that was hashed. It refuses lengths written longer than they need, open lengths, map keys out of order or repeated, floats, tags other than links, integers past 64 bits, trailing bytes, and nesting past 128. It converts to and from record JSON ($link,$bytes), andcheck_recordholds a record to the data model's rules for$typeand blobs.tid: TIDs from the time, read back, and a clock that only goes forward.syntax: DIDs, handles, NSIDs, record keys and TIDs.keys: secp256k1 and P-256 keypairs and public keys, as multikeys,did:keys and the older DID-document key types. Signatures are 64 bytes and low-S; DER and high-S ones are refused, as atproto requires.Why
The repo, the MST, commits, PLC operations and service auth all sit on these. They are written for the host, as knotless writes its own, so that every line is under the coverage gate and nothing in a framework decides what a group's repo accepts.
How it was checked
Against atproto's interop test vectors, vendored under
crates/atproto/tests/interop(CC0, from atproto-interop-tests at 056e574): every syntax vector for the five identifiers, every signature anddid:keyvector, and every data-model vector (encoding, CIDs, valid and invalid records). Plus a test for each form the decoder refuses. Locally,cargo llvm-covat 100% of lines and functions, and clippy clean.One finding from the vectors: an NSID whose domain authority runs past a hostname's 253 characters is valid there, so it is here.
Shortcomings
Stacked on the scaffold's pull, which it includes until that lands; review that first. Nothing in the host uses these yet: accounts and repos do, two pulls on. The MST vectors are vendored now for the next pull.
Review
src/drisl.rsis the one to read closely: its decoder is what stands between bytes from anyone and a group's repo.