capsule_core/lib.rs
1//! Capsule's stateless core: pure functions over values — cryptography and the MLS authority,
2//! canonical CBOR, sidecar and CRDT logic, validation, media, LQIP, sharing and drop crypto, and
3//! ML orchestration.
4//!
5//! It holds no connection, file handle or database, and reads no environment, clock or
6//! filesystem: storage reaches it through ports such as `ml::VectorIndex`, and time and
7//! identifier randomness through [`ambient::Clock`] and [`ambient::Rng`], all of which callers
8//! implement. Local state — the SQLite index, the on-disk library, the `Workspace`, import
9//! execution, backup I/O and the hardware signers — lives in `capsule-library`; network state
10//! lives in `capsule-sdk`. Two exceptions, each confined to one module:
11//!
12//! - the OS CSPRNG behind `crypto::rng`: key material must never come from an injectable, and
13//! therefore replaceable, source;
14//! - `catch_unwind` in `media::decode`: a decoder panic on hostile input must become a typed
15//! error, not abort the caller.
16//!
17//! `cargo xtask architecture-check` enforces the rest.
18
19// ── WASM sealing surface (always compiled) ──────────────────────────────────
20// `cbor`, `crypto`, and `drop` are the only modules the guest web client (WASM) needs:
21// the [`drop::seal_drop`] path plus its cryptographic dependencies. They are free of any
22// dependency that cannot target `wasm32-unknown-unknown`, so a `--no-default-features` build
23// compiles exactly this surface. See
24// [Web Upload — the web client class](https://docs/design/web-upload/).
25pub mod cbor;
26pub mod crypto;
27pub mod drop;
28
29/// The `Clock` and `Rng` a caller injects, and the `IdSource` that mints UUIDv7s from them.
30/// Always compiled: pure over its two traits, no native deps.
31pub mod ambient;
32
33/// Share-link generation, encapsulation crypto, and the recipient-side [`sharing::open_scope`]
34/// path. Always compiled: it depends only on `cbor` + `crypto`, both of which
35/// target `wasm32-unknown-unknown`, so the browser share viewer (via `capsule-wasm`) can unwrap
36/// a link client-side. The native issuer (`ShareLinkIssuer` on `capsule-library`'s `Workspace`)
37/// is not needed in the browser; only the pure crypto + recipient-open path is.
38pub mod sharing;
39
40/// Client build identification — the `client_version` / `generated_by_client` grammar and the
41/// build-embedded git commit. Always compiled: pure string formatting, no native deps.
42pub mod client_build;
43
44/// The file extension an original is named by for its sidecar `content_type` — the one table
45/// the library's adoption and a restore share. Always compiled: a pure string table.
46pub mod content_type;
47
48/// The closed set of still-derivative formats and the structural check over it — the tier
49/// table's format column as a type. Always compiled, and for the same reason [`lqip`] is: the
50/// crates that *receive* a `DerivativeManifest` (`capsule-server`, `capsule-wasm`) build with
51/// `default-features = false`, so a check they cannot link is a check that never runs. Depends
52/// only on [`crypto::provenance`]. The one public path to its items: `media` does not
53/// re-export them.
54pub mod derivative_format;
55
56/// LQIP — the chromahash placeholder carried in the signed sidecar's `lqip` field.
57/// Always compiled, and deliberately so: the placeholder is produced by the import pipeline,
58/// read by the apps through the FFI crates, and read by the browser through `capsule-wasm`, so
59/// there is exactly one implementation and every surface links it. `chromahash` has zero
60/// runtime dependencies and targets `wasm32-unknown-unknown`. The one `native`-gated part is
61/// [`lqip::sidecar`], because [`sidecar`] itself is.
62pub mod lqip;
63
64// ── Native surface (`native`, default) ──────────────────────────────────────
65// Everything below serves the on-device library `capsule-library` builds — it links OpenMLS and
66// the media stack, neither of which the browser sealing path needs. Gated behind the default
67// `native` feature so a `--no-default-features` build drops it for the WASM sealing build.
68#[cfg(feature = "native")]
69pub mod backup;
70#[cfg(feature = "native")]
71pub mod cohort;
72#[cfg(feature = "native")]
73pub mod constants;
74#[cfg(feature = "native")]
75pub mod culling;
76#[cfg(feature = "native")]
77pub mod domain;
78// The cross-device add ceremony's wire form: the advertised key bundles, the relayed payloads
79// and the safety code. The Workspace verbs that draw and cross-sign them are `capsule-library`'s.
80// A plain comment for the reason `notify`'s is: an outer doc comment would resolve the module's
81// short intra-doc links at this declaration site.
82#[cfg(feature = "native")]
83pub mod enrollment;
84#[cfg(feature = "native")]
85pub mod exif;
86#[cfg(feature = "native")]
87pub mod federation;
88#[cfg(feature = "native")]
89pub mod import;
90/// Still decode, orientation, metadata normalisation and derivative generation over
91/// `rawshift-image` (`media` feature, implied by `native`). Feature-gated
92/// rather than `native`-gated so the codec stack is one manifest edit away from being dropped
93/// from a size-constrained build, and so the `wasm32-unknown-unknown` sealing surface provably
94/// does not link it. See [`media`].
95#[cfg(feature = "media")]
96pub mod media;
97#[cfg(feature = "native")]
98pub mod metadata;
99#[cfg(feature = "native")]
100pub mod ml;
101// `notify` — alert classes and their trigger predicates: one shared decision
102// function every platform evaluates, so the taxonomy is not reimplemented per client.
103// `native`-gated because an alert is composed from *decrypted device state*, and the
104// un-gated surface here is the key-free guest sealing path, which holds none of it. The
105// rationale lives as a plain comment rather than a doc comment because rustdoc merges an
106// outer `mod` doc with the module's own `//!` block and then resolves the whole thing at
107// the declaration site — which would break every short intra-doc link in `notify/mod.rs`.
108#[cfg(feature = "native")]
109pub mod notify;
110#[cfg(feature = "native")]
111pub mod sidecar;
112// Deliberately **not** `native`-gated: these are pure, key-less structural checks over
113// `crypto::{encryption, hash, primitives, provenance}` and nothing else. Gating them behind
114// `native` forced `capsule-server` — a key-free server that touches no SQLite and no MLS — to link
115// `rusqlite`, `sqlite-vec`, OpenMLS and libcrux in order to call the refuse-by-default invariants
116// it exists to enforce.
117pub mod validation;