Overview
The@atproto/repo package provides TypeScript implementation of AT Protocol repositories and the Merkle Search Tree (MST) data structure. Repositories are signed, content-addressed key/value stores that hold user data records.
Installation
Core Concepts
Repository Structure
An AT Protocol repository consists of:- Commit: Signed metadata pointing to the current data state
- MST (Merkle Search Tree): Content-addressed tree structure storing record keys and CIDs
- Blocks: CBOR-encoded record data and MST nodes
Merkle Search Tree (MST)
The MST is an ordered, deterministic tree structure where:- Keys are sorted alphabetically
- Insertion order doesn’t affect the final tree structure
- Each key is hashed to determine its layer in the tree
- Subtrees are referenced by their CID
Main Classes
Repo
The main repository class for creating and updating repositories.Promise<Repo>
Promise<Repo>
Promise<Repo>
Promise<CommitData>
Promise<Repo>
Promise<RepoRecord | null>
did: string- Repository DIDcid: CID- Current commit CIDcommit: Commit- Current commit objectdata: MST- Current MST rootstorage: RepoStorage- Block storage
MST
Merkle Search Tree implementation.Promise<MST>
MST
Promise<MST>
Promise<MST>
Promise<MST>
Promise<CID | null>
AsyncIterable<{ key: string; value: CID }>
Promise<CID>
Storage Implementations
MemoryBlockstore
In-memory block storage for testing and development.RepoStorage Interface
Interface for implementing custom storage backends.Record Operations
RecordWriteOp Types
CAR File Utilities
exportCarSlice
Exports a repository slice as a CAR (Content Addressable aRchive) file.Promise<Uint8Array>
importCarSlice
Imports blocks from a CAR file.Data Structures
BlockMap
Map of CIDs to block bytes.CidSet
Set of CIDs.Complete Example
Related Packages
- @atproto/crypto - Cryptographic operations for signing commits
- @atproto/lexicon - Schema validation for records
- @atproto/syntax - Identifier validation
- @atproto/common - Common utilities including CID handling