Skip to main content

waggle_core/
lib.rs

1//! # waggle-core — the sans-I/O domain
2//!
3//! The core performs **no I/O, owns no clock, and generates no entropy**
4//! (design doc `03 §1`). Every effect is a parameter:
5//!
6//! - randomness arrives through [`Entropy`] (blanket-implemented for
7//!   closures — function passing, not global state),
8//! - time arrives as a [`Timestamp`] value in every signature that needs
9//!   one,
10//! - storage never appears here at all (see `waggle-store`).
11//!
12//! This is what lets the identical code run in the native daemon, in
13//! Cloudflare Workers wasm, and under deterministic tests.
14//!
15//! CP-0 shipped the foundation trio: [`Token`], [`Timestamp`], [`Entropy`].
16//! CP-1 adds the domain model: slugs ([`Sharer`], [`Channel`], [`Stage`]),
17//! targets ([`CanonicalUrl`], [`TargetMeta`], [`MediaRef`]), the
18//! three-zone [`AttributionManifest`] with variants, and [`mint`] — a pure
19//! function of `(spec, options, entropy, now)`. The sealed variant matcher
20//! and folds land in CP-2/CP-3 (design docs `02`–`04`).
21//!
22//! ```
23//! use waggle_core::{Entropy, Token};
24//!
25//! // A deterministic entropy source: fine for tests, never for production.
26//! let mut counter = 0u8;
27//! let mut entropy = |buf: &mut [u8]| {
28//!     for b in buf.iter_mut() {
29//!         counter = counter.wrapping_add(41);
30//!         *b = counter;
31//!     }
32//!     Ok(())
33//! };
34//! let token = Token::generate(8, &mut entropy).expect("entropy never fails here");
35//! assert_eq!(token.as_str().len(), 8);
36//! ```
37
38mod context;
39mod contract;
40mod entropy;
41mod event;
42mod fold;
43mod log;
44mod manifest;
45mod matcher;
46mod mint;
47mod reconstruct;
48mod resolve;
49mod slug;
50mod soa;
51mod target;
52mod time;
53mod token;
54pub mod trust;
55
56pub use context::{negotiate, ConsumerHint, ConsumerKind, ResolverContext};
57pub use contract::{
58    Contract, ContractError, Coverage, Region, FULL_COVERAGE_PERMILLE, MAX_CONTRACT_REGIONS,
59};
60pub use entropy::{Entropy, EntropyError};
61pub use event::{ActorClass, Event, FamilyClass, HarnessClass, Seq};
62pub use fold::{
63    outcome_of, replay, EntryTouchFold, Fold, FunnelFold, LineageFold, ManifestFold, Outcome,
64    RegionTouchFold,
65};
66pub use log::{Change, LogRecord};
67pub use manifest::{
68    apply_change, AttributionManifest, Constraint, Disposition, Extraction, MatchExpr, ModalitySet,
69    Posture, SignatureBlock, TreeNode, Variant, VariantBody, MANIFEST_SCHEMA_VERSION,
70};
71pub use matcher::{select_variant, Selected};
72pub use mint::{mint, MintError, MintOptions, MintSpec};
73pub use reconstruct::{apply_suffix, reconstruct, WorldState};
74pub use resolve::{resolve, Resolution, DEFAULT_REVALIDATE_MS};
75pub use slug::{Channel, Sharer, SlugError, Stage};
76pub use soa::{EventLog, InternTables, StageId, TokenId};
77pub use target::{
78    CanonicalUrl, MediaRef, Sha256Error, Sha256Hex, TargetError, TargetMeta,
79    INLINE_THRESHOLD_BYTES, MANIFEST_SIZE_CAP_BYTES,
80};
81pub use time::Timestamp;
82pub use token::{Token, TokenError, TOKEN_ALPHABET};