What problem does it solve?
Working with AT Protocol data requires handling CIDs, raw bytes, CBOR encoding, blob references, and branded identifier strings correctly, and hand-rolled approaches with multiformats, toISOString(), or ad-hoc base64 produce subtle bugs and invalid records.
Core Features & Use Cases
- CID and bytes handling: Parse, validate, and create CIDs with flavor constraints (raw, cbor, dasl), and convert binary data with base64 helpers, replacing direct multiformats usage.
- JSON and CBOR conversion: Convert between JSON strings, plain objects, and Lex values with lexParse/lexStringify, and encode deterministic CBOR (DRISL) for repo storage, CAR files, and event frames.
- Identifier and datetime types: Brand DIDs, handles, AT URIs, NSIDs, TIDs, and datetimes with nominal types and guards so unvalidated strings cannot leak into records or database rows.
- Use Case: When writing a PDS record, use cidForLex to hash the CBOR-encoded record, currentDatetimeString() instead of new Date().toISOString() for createdAt, and enumBlobRefs to walk the record for blob references.
Quick Start
Ask the AI to serialize an AT Protocol record to CBOR and compute its CID using @atproto/lex and @atproto/lex-cbor.