atproto-record
Utilities for working with AT Protocol records.
Overview
A Rust library for working with AT Protocol records, providing AT-URI parsing, TID generation, datetime formatting, and CID generation. Built on IPLD DAG-CBOR serialization for deterministic content addressing.
Features
- AT-URI parsing: Parse and validate AT Protocol URIs (at://authority/collection/record_key) with robust error handling
- TID generation: Timestamp-based identifiers for AT Protocol records with microsecond precision
- CID generation: Content Identifier generation using DAG-CBOR serialization and SHA-256 hashing
- DateTime utilities: RFC 3339 datetime serialization with millisecond precision for consistent timestamp handling
- Typed records: Type-safe record handling with lexicon type validation
- Bytes handling: Base64 encoding/decoding for binary data in AT Protocol records
- Structured errors: Type-safe error handling following project conventions with detailed error messages
CLI Tools
The following command-line tool is available when built with the clap feature:
atproto-record-cid: Generate CID (Content Identifier) for AT Protocol records from JSON input
Library Usage
Generating CIDs
use json;
use Cid;
use ;
use Multihash;
// Serialize a record to DAG-CBOR and generate its CID
let record = json!;
let dag_cbor_bytes = to_vec?;
let hash = digest;
let multihash = wrap?;
let cid = new_v1;
println!;
Generating TIDs
use Tid;
// Generate a new timestamp-based identifier
let tid = new;
println!; // e.g., "3l2k4j5h6g7f8d9s"
// TIDs are sortable by creation time
let tid1 = new;
sleep;
let tid2 = new;
assert!;
AT-URI Parsing
use ATURI;
use FromStr;
// Parse an AT-URI into its components
let aturi = ATURIfrom_str?;
// Access the parsed components
println!; // "did:plc:abc123"
println!; // "app.bsky.feed.post"
println!; // "3k2k4j5h6g"
// The Display trait formats back to a valid AT-URI
println!; // "at://did:plc:abc123/app.bsky.feed.post/3k2k4j5h6g"
DateTime Utilities
use ;
use ;
// Use the datetime module for consistent RFC 3339 formatting
Command Line Usage
The CLI tool requires the clap feature:
# Build with CLI support
# Generate CID from JSON file
|
# Generate CID from inline JSON
|
# Example with a complete AT Protocol record
The tool outputs the CID in base32 format:
bafyreibjzlvhtyxnhbvvzl3gj4qmg2ufl2jbhh5qr3gvvxlm7ksf3qwxqq
License
MIT License