Skip to main content

dig_message/
lib.rs

1//! # dig-message — the DIG Network generic base message protocol
2//!
3//! ONE structured, typed, streamable, e2e-sealed envelope that every DIRECTED (1:1 / group) peer-to-
4//! peer message rides (chat, email, video signaling, presence, directed data requests, peer-RPC, and
5//! authenticated local IPC). Consensus BROADCAST (blocks/transactions/attestations) is the SPEC §5.4
6//! exemption and stays mTLS-authenticated + signed, not dig-message-sealed.
7//!
8//! ## What WU1 (this milestone) provides — the crypto-free foundation
9//! - [`DigMessageEnvelope`] + [`InnerMessage`] + [`StreamHeader`] + [`SealedPayload`] — the byte-
10//!   deterministic Chia-Streamable wire shapes (SPEC §2, §5.2).
11//! - [`encode_envelope`] / [`decode_envelope`] — the length-framed, size-bounded codec (SPEC §1).
12//! - [`compress_payload`] / [`decompress_payload`] — the additive compression layer (raw + zstd) with
13//!   the decompression-bomb guard (SPEC §1.1).
14//! - The pinned protocol [`constants`] and the [`MessageError`] taxonomy.
15//!
16//! ## What WU2 (this milestone) adds — the e2e SEAL pipeline (SPEC §5)
17//! - [`seal_message`] / [`open_message`] — the full compress → BLS-G2 sign → G1-DHKEM auth-seal (send)
18//!   and unseal → verify → replay → expiry → decompress (receive) pipeline, fail-closed at each step.
19//! - [`SealParams`] / [`OpenedMessage`] — the seal inputs + the opened, verified result.
20//! - [`ReplayGuard`] — the SPEC §5.6 anti-replay state machine (freshness window + bounded
21//!   sliding-window dedup + LRU sender cap).
22//! - [`TranscriptFields`] — the domain-separated signed transcript (SPEC §5.1 / §5.1a).
23//! - The seal uses `dig-identity`'s ONE BLS12-381 keypair (G2 sign + G1 DH); NO X25519, NO Ed25519.
24//!
25//! ## What later WUs add (the FIELDS are already final here)
26//! - **WU4** drives the SPEC §3 streaming state machine over [`StreamHeader`].
27//! - **WU5** adds the wasm/JS surface + the Rust↔wasm byte-agreement KAT.
28//!
29//! ## What WU3 (this milestone) adds — the extensible type registry (crypto-free, SPEC §4)
30//! - [`MessageBand`] + [`MessageType::band`] — the reserved id-band allocation + classification.
31//! - [`MessageKind`] — the compile-time seam a downstream type declares (id + typed payload).
32//! - [`MessageRegistry`] — the runtime register/lookup/route table, additive-only, with the SPEC §4
33//!   unknown-type rule (UNSUPPORTED_TYPE for request/stream, silent [`Dispatch::Dropped`] otherwise;
34//!   never a panic).
35
36pub mod compression;
37pub mod constants;
38pub mod envelope;
39pub mod error;
40pub mod registry;
41pub mod replay;
42pub mod seal;
43pub mod transcript;
44
45pub use compression::{
46    compress_payload, decompress_payload, CompressedPayload, COMPRESSION_NONE, COMPRESSION_ZSTD,
47};
48pub use constants::*;
49pub use envelope::{
50    decode_envelope, encode_envelope, DigMessageEnvelope, InnerMessage, InteractionShape,
51    MessageType, SealedPayload, StreamFrame, StreamHeader, FLAG_SEALED, FLAG_SHAPE_MASK,
52};
53pub use error::{MessageError, Result};
54pub use registry::{
55    Dispatch, MessageBand, MessageKind, MessageRegistry, BAND_CORE, BAND_DIG_CHAT, BAND_DIG_EMAIL,
56    BAND_DIG_VIDEO, BAND_EXPERIMENTAL, BAND_IPC, BAND_PEER_RPC, BAND_PRESENCE,
57};
58pub use replay::ReplayGuard;
59pub use seal::{open_message, seal_message, seal_with_ephemeral, OpenedMessage, SealParams};
60pub use transcript::TranscriptFields;