Skip to main content

cesr/
lib.rs

1//! CESR + KERI primitives for Rust as a single feature-gated crate.
2//!
3//! # Architecture: one wire message, three modules
4//!
5//! A KERI key event message is a serialized event body followed by
6//! CESR-framed attachments:
7//!
8//! ```text
9//! {"v":"KERI10JSON000189_","t":"icp","d":"EAgi…",…} -VAt -AAC AADB_mVj…88ch ABAN5tRO…88ch
10//! └──────────────────── body ─────────────────────┘└─────────── attachments ────────────┘
11//!                                                   │    │    └ two indexed Ed25519 sigs
12//!                                                   │    └ `-A` ControllerIdxSigs, count 2
13//!                                                   └ `-V` attachment frame, size in quadlets
14//! ```
15//!
16//! Each module owns one verb over that message:
17//!
18//! - [`stream`] **finds** it — cold-start detection and version-string
19//!   framing slice the body span; counters delimit the attachment groups.
20//! - [`keri`] **names** it — the typed domain: events, identifiers, seals,
21//!   thresholds. Pure data, no serialization of its own.
22//! - [`core`] **spells** it — the CESR primitive alphabet (`Matter`,
23//!   indexers, counters) that every layer above composes; [`b64`] is its
24//!   Base64 codec, [`crypto`] its digests, keypairs, and verifiers.
25//!
26//! The body codec — the strict canonical JSON parser with in-place SAID
27//! verification, the builders that write keripy's exact bytes back, and the
28//! end-to-end read and write spines over them — lives in the `keri-codec`
29//! crate, which composes this crate's `stream` framing with `keri`'s typed
30//! domain.
31//!
32//! # Features
33//!
34//! Each former separate crate is now a module gated by a cargo feature:
35//! `b64`, `core`, `crypto`, `stream`, `keri`, reachable as
36//! `cesr::core::*`, `cesr::crypto::*`, etc. (The former `utils` module — the
37//! CESR Base64 codec — is now `b64`.)
38//!
39//! The crate is `no_std`-capable: `std` (on by default) gives the std-backed
40//! surface; build `--no-default-features --features alloc,…` for embedded/wasm.
41#![no_std]
42#![cfg_attr(docsrs, feature(doc_cfg))]
43
44#[cfg(feature = "alloc")]
45extern crate alloc;
46
47#[cfg(feature = "std")]
48extern crate std;
49
50#[cfg(feature = "b64")]
51pub mod b64;
52#[cfg(feature = "core")]
53pub mod core;
54#[cfg(feature = "crypto")]
55pub mod crypto;
56
57#[cfg(feature = "core")]
58#[doc(inline)]
59pub use core::{
60    CesrVersion, Cigar, Dater, Diger, Labeler, Matter, Noncer, Number, Prefixer, Saider, Seqner,
61    Siger, Signer, Texter, Verfer, Verser,
62};
63#[cfg(feature = "crypto")]
64#[doc(inline)]
65pub use crypto::{Algorithm, Ed25519, KeyPair, Secp256k1, Secp256r1};
66
67/// The common imports for working with `cesr`.
68///
69/// `use cesr::prelude::*;` brings the traits you need in scope for method
70/// resolution, plus a handful of headliner types so you can write code from the
71/// glob alone. Every other public type is reachable at the crate root
72/// (`cesr::Matter`) or its module path (`cesr::core::Matter`).
73pub mod prelude {
74    // Traits — the primary payload (needed implicitly for method resolution).
75    #[cfg(feature = "crypto")]
76    #[doc(no_inline)]
77    pub use crate::crypto::Algorithm;
78
79    // Headliner types — enough to write code from the glob alone.
80    #[cfg(feature = "core")]
81    #[doc(no_inline)]
82    pub use crate::core::{Diger, Matter, Signer, Verfer};
83}