atproto_repo/lib.rs
1//! Pure Rust implementation of AT Protocol repository structures.
2//!
3//! This crate provides:
4//! - **MST** (Merkle Search Tree) encoding/decoding
5//! - **Repository** structures for commits, records, and operations
6//!
7//! CAR v1 serialization, block storage, and varint encoding have been moved
8//! to the `atproto-dasl` crate. Types are re-exported here for backward
9//! compatibility.
10//!
11//! # Features
12//!
13//! - Pure Rust implementation (no external MST dependencies)
14//! - Built on `atproto-dasl` for DAG-CBOR encoding, CAR, and storage
15//! - Async-first streaming design using tokio
16//! - Configurable CID and signature verification
17//! - Memory limits for DoS prevention
18//! - Pluggable storage backends (memory, disk, hybrid)
19//!
20//! # Example Usage
21//!
22//! ```rust,ignore
23//! use atproto_repo::{CarReader, RepoConfig, MemoryStorage};
24//! use tokio::fs::File;
25//!
26//! async fn example() -> anyhow::Result<()> {
27//! // Read a CAR file
28//! let file = File::open("repo.car").await?;
29//! let reader = CarReader::new(file).await?;
30//!
31//! println!("Roots: {:?}", reader.roots());
32//!
33//! // Stream blocks into storage
34//! let mut storage = MemoryStorage::new();
35//! reader.stream_to_storage(&mut storage).await?;
36//!
37//! Ok(())
38//! }
39//! ```
40//!
41//! # Specifications
42//!
43//! - [CAR v1](https://ipld.io/specs/transport/car/carv1/)
44//! - [AT Protocol Repository](https://atproto.com/specs/repository)
45//! - [AT Protocol Data Repos](https://atproto.com/guides/data-repos)
46
47#![forbid(unsafe_code)]
48#![warn(missing_docs)]
49
50mod config;
51pub mod errors;
52pub mod mst;
53pub mod repo;
54
55// Re-export CAR types from atproto-dasl for backward compatibility
56pub use atproto_dasl::car::{CarBlock, CarConfig, CarHeader, CarReader, CarWriter, LimitsConfig};
57
58// Re-export storage types from atproto-dasl for backward compatibility
59pub use atproto_dasl::storage::{
60 BlockStorage, DiskStorage, MemoryStorage, SpillableBuffer, SpillableReader,
61};
62
63// Re-export error types from atproto-dasl for backward compatibility
64pub use atproto_dasl::{CarError, StorageError, VarintError};
65
66// Re-export CID utilities from atproto-dasl for backward compatibility
67pub use atproto_dasl::cid::{DAG_CBOR_CODEC, SHA256_CODE, compute_cid};
68
69// Re-export config types
70pub use config::RepoConfig;
71
72// Re-export error types defined in this crate
73pub use errors::{MstError, RepoError};
74
75// Re-export MST types
76pub use mst::{Mst, MstDiff, MstNode, TreeEntry};
77
78// Re-export repository types
79pub use repo::{Commit, DiskRepository, MemoryRepository, RecordPath, Repository};
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn test_compute_cid() {
87 let data = b"hello world";
88 let cid = compute_cid(data);
89
90 // Verify it is CIDv1 with the correct codec
91 assert_eq!(cid.version(), cid::Version::V1);
92 assert_eq!(cid.codec(), DAG_CBOR_CODEC);
93 }
94
95 #[test]
96 fn test_cid_deterministic() {
97 let data = b"test data";
98 let cid1 = compute_cid(data);
99 let cid2 = compute_cid(data);
100 assert_eq!(cid1, cid2);
101 }
102}