atproto_repo/proof

Offline proof that a record is in an account’s repository.

The input is the CAR a PDS returns for com.atproto.sync.getRecord: a signed commit, the MST nodes on the path to the record, and the record block. Nothing here does IO; the caller supplies the signing key it resolved from the account’s DID document.

Types

pub type NodeFault {
  NodeNotAMap
  NodeMissingField(String)
  NodeWrongFieldType(String)
  NodeEmptyKey
  NodePrefixTooLong(index: Int)
  NodePrefixNotMaximal(index: Int)
  NodeKeysNotAscending(index: Int)
  NodeMixedLayers
}

Constructors

  • NodeNotAMap
  • NodeMissingField(String)
  • NodeWrongFieldType(String)
  • NodeEmptyKey
  • NodePrefixTooLong(index: Int)
  • NodePrefixNotMaximal(index: Int)
  • NodeKeysNotAscending(index: Int)
  • NodeMixedLayers
pub type ProofError {
  InvalidPath
  BadCar(car.CarError)
  NoRoot
  MissingBlock(cid.Cid)
  NonBlessedCid(cid.Cid)
  CommitUndecodable(dag_cbor.DecodeError)
  CommitNotAMap
  CommitMissingField(String)
  CommitWrongFieldType(String)
  CommitNotReencodable(dag_cbor.EncodeError)
  UnsupportedCommitVersion(Int)
  WrongDid(expected: String, found: String)
  BadSignature(key.SignatureError)
  NodeUndecodable(cid.Cid, dag_cbor.DecodeError)
  MalformedNode(cid.Cid, NodeFault)
  NodeTooWide(node: cid.Cid, limit: Int, observed: Int)
  LayerMismatch(node: cid.Cid, expected: Int, found: Int)
  EmptyTopNode(cid.Cid)
  SubtreeBelowLeafLayer(cid.Cid)
  RecordNotInTree
  RecordUndecodable(cid.Cid, dag_cbor.DecodeError)
}

Constructors

pub type VerifiedRecord {
  VerifiedRecord(
    record_cid: cid.Cid,
    record: dag_cbor.Value,
    commit_cid: cid.Cid,
    commit_rev: String,
  )
}

Constructors

Values

pub fn verify_record(
  car bytes: BitArray,
  did did: String,
  collection collection: String,
  rkey rkey: String,
  key key: key.PublicKey,
) -> Result(VerifiedRecord, ProofError)

Checks that collection/rkey in the repository of did is the record in car: the commit is for did, its signature verifies under key (low-S, over the SHA-256 of the unsigned commit), and an MST path from the commit to the record exists in the CAR’s blocks.

The first CAR root is the commit, as the repository spec requires. Blocks off that path are ignored; every block is hash-checked on read.

pub fn verify_record_with(
  limits limits: limits.Limits,
  car bytes: BitArray,
  did did: String,
  collection collection: String,
  rkey rkey: String,
  key key: key.PublicKey,
) -> Result(VerifiedRecord, ProofError)

verify_record with explicit resource bounds.

✨ Search Document