atproto_repo

Alpha, pre-release. Pre-1.0, evolving alongside at-record; expect breaking changes between 0.x releases.

Sans-io verification of atproto repository proofs. Given the CAR a PDS returns for com.atproto.sync.getRecord, the account’s DID and its signing key, verify_record shows that the record is in that account’s repository and that the repository head is signed by that key. The caller owns all IO: fetching the CAR and resolving the DID document.

Runs on both the Erlang and JavaScript targets. Signatures go through kryptos, hashing through gleam_crypto.

Usage

import atproto_repo/key
import atproto_repo/proof
import gleam/string

// publicKeyMultibase of the #atproto verification method in the DID document
let assert Ok(signing_key) =
  key.from_multikey("zQ3shunBKsXixLxKtC5qeSG9E4J5RkGN57im31pcTzbNQnm5w")

case
  proof.verify_record(
    car: car_bytes,
    did: "did:plc:ewvi7nxzyoun6zhxrhs64oiz",
    collection: "app.bsky.actor.profile",
    rkey: "self",
    key: signing_key,
  )
{
  Ok(verified) -> verified.record
  Error(error) -> panic as string.inspect(error)
}

VerifiedRecord carries the record’s Cid and decoded dag_cbor.Value, the commit’s Cid and its rev. Every ProofError variant names the step that failed: the CAR, a missing block (by CID), the commit’s shape, version or DID, the signature (including high-S), a malformed MST node, or the record not being in the tree.

Modules

ModuleWhat it does
atproto_repo/proofverify_record and its error vocabulary.
atproto_repo/keyPublicKey from did:key or Multikey; atproto signature verification (low-S).
atproto_repo/carCAR v1 reader; every block is hashed against the CID its section claims.
atproto_repo/limitsResource bounds for untrusted CARs, with safe defaults.
atproto_repo/cidThe atproto CIDv1 (SHA-256; DAG-CBOR or raw), as string and bytes.
atproto_repo/dag_cborStrict decoder and canonical encoder for the atproto DAG-CBOR subset.

What is and is not checked

✨ Search Document