Skip to main content

Module car

Module car 

Source
Expand description

CAR (Content Addressable aRchive) proof production and verification.

A CAR file bundles a set of (CID → block bytes) pairs with a set of root CIDs, so a recipient can store and re-verify the blocks offline. atproto’s getRepo / getRecord endpoints return CAR files; this module produces minimal CAR proofs — just enough blocks to verify one record against the signed commit.

§CARv1 wire format (IPLD)

CARv1 := header-section block-section*
  header-section := varint(len) ++ CBOR({ "version": 1, "roots": [CID,...] })
  block-section  := varint(len) ++ CID ++ raw-block-bytes

len is a unsigned-varint byte count of the rest of the section.

§verify_record_proof

verify_record_proof is the D5 untrusted-host check: given a (purported) signed commit, the account’s #atproto P-256 verifying key, an MST inclusion path, and the record bytes, confirm (1) the commit signature, (2) the MST path leads from the commit’s data root to the record’s entry, and (3) the record’s CID matches the entry’s value.

Functions§

build_car_v1
blocks need not be sorted; duplicates are harmless. The header’s roots is taken verbatim from roots.
build_car_v1_atproto
Public AT Protocol CARv1 builder. The native builder remains unchanged.
build_car_v1_sections
Build a CARv1 byte blob containing the given root CIDs and (cid → bytes) blocks.
build_public_record_proof_car
Build a public AT Protocol CAR proof without changing the native CAR builder. Every block CID and byte payload is derived from the public canonical codec, including the CAR header.
build_record_proof_car
Build a CAR proof for a single record: the commit block + all MST nodes on the path + the record block, rooted at the commit’s CID.
car_block_bytes
Build one length-framed CARv1 block section (varint(len) ++ CID ++ raw). Used by lazy/streaming CAR producers that encode blocks on demand.
car_header_bytes
Build just the CARv1 header section (varint-framed CBOR {version, roots}). Useful for lazy/streaming CAR producers that emit the header first, then block sections one at a time.
parse_car_v1
Parse a CARv1 blob into (roots, blocks). Used by tests / offline verifiers that read a fetched CAR.
parse_car_v1_atproto
Parse a CAR whose header uses public AT canonical DAG-CBOR. Block framing is identical to parse_car_v1; callers decide how to decode each block.
verify_record_proof
verifyRecordProof(commit, signingKey, path, record) — offline D5 verification.