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 WU4 (this milestone) adds — the streaming state machine (SPEC §3)
26//! - [`StreamEndpoint`] — the per-peer registry driving OPEN/OPEN_ACK/DATA/CREDIT/CLOSE/CLOSE_ACK/RESET
27//! with ordered delivery (strictly-monotonic seq), credit backpressure, bidirectional half-close, and
28//! cancel. It seals EVERY frame with a fresh ephemeral (per-frame forward secrecy, no nonce reuse),
29//! opens + fully verifies every inbound frame, and bounds concurrent streams
30//! ([`MAX_CONCURRENT_STREAMS`]). A bad/unauthenticated/duplicate frame is DROPPED (never answered with
31//! a signed RESET — that would let the untrusted relay provoke a RESET reflection storm); a RESET is
32//! emitted ONLY for a state-machine violation by the authenticated peer on a known stream, or the
33//! concurrent-stream cap (gate items #1162).
34//! - [`StreamSession`] / [`StreamState`] / [`StreamEvent`] / [`StreamAccept`] — the pure state machine +
35//! its observable states, verified events, and the accept outcome.
36//!
37//! ## What later WUs add (the FIELDS are already final here)
38//! - **WU5** adds the wasm/JS surface + the Rust↔wasm byte-agreement KAT.
39//!
40//! ## What WU3 (this milestone) adds — the extensible type registry (crypto-free, SPEC §4)
41//! - [`MessageBand`] + [`MessageType::band`] — the reserved id-band allocation + classification.
42//! - [`MessageKind`] — the compile-time seam a downstream type declares (id + typed payload).
43//! - [`MessageRegistry`] — the runtime register/lookup/route table, additive-only, with the SPEC §4
44//! unknown-type rule (UNSUPPORTED_TYPE for request/stream, silent [`Dispatch::Dropped`] otherwise;
45//! never a panic).
46
47pub mod compression;
48pub mod constants;
49pub mod envelope;
50pub mod error;
51pub mod registry;
52pub mod replay;
53pub mod seal;
54pub mod stream;
55pub mod transcript;
56
57pub use compression::{
58 compress_payload, decompress_payload, CompressedPayload, COMPRESSION_NONE, COMPRESSION_ZSTD,
59};
60pub use constants::*;
61pub use envelope::{
62 decode_envelope, encode_envelope, DigMessageEnvelope, InnerMessage, InteractionShape,
63 MessageType, SealedPayload, StreamFrame, StreamHeader, FLAG_SEALED, FLAG_SHAPE_MASK,
64};
65pub use error::{MessageError, Result};
66pub use registry::{
67 Dispatch, MessageBand, MessageKind, MessageRegistry, BAND_CORE, BAND_DIG_CHAT, BAND_DIG_EMAIL,
68 BAND_DIG_VIDEO, BAND_EXPERIMENTAL, BAND_IPC, BAND_PEER_RPC, BAND_PRESENCE,
69};
70pub use replay::ReplayGuard;
71pub use seal::{open_message, seal_message, OpenedMessage, SealParams};
72pub use stream::{StreamAccept, StreamEndpoint, StreamEvent, StreamSession, StreamState};
73pub use transcript::TranscriptFields;