Skip to main content

dig_evidence/
lib.rs

1//! # dig-evidence — the DIG Network's library of ACTIVE on-chain evidence types
2//!
3//! One home for the evidence/proof TYPES the ecosystem produces and verifies. Every type here is an
4//! ACTIVE piece of evidence: it (a) knows what it proves, (b) GATHERS the specific on-chain
5//! information its proof needs through an INJECTED [`ChainSource`] reader (never taking an upward
6//! dependency on a node or transport), and (c) re-verifies offline from its own gathered contents.
7//!
8//! ## The pattern (modeled on `dig-did::prove_lineage`)
9//!
10//! Each type implements the [`Evidence`] trait and follows the same unforgeable-by-construction
11//! discipline as `dig-did`'s `AncestryProof`:
12//!
13//! - **Private fields.** A value cannot be forged by a struct literal — the only way to obtain one is
14//!   [`Evidence::gather`], which authenticates every field against the injected reader (or, for a
15//!   self-contained offline proof, against the supplied inputs). Holding a value witnesses the proof.
16//! - **Gather-only construction.** Construction reads chain state through the injected `ChainSource`
17//!   and authenticates it; it holds NO key, signs nothing, and does its own no network I/O.
18//! - **Fail-closed.** An unreadable chain, a missing/forged anchor, or a proof that does not fold is
19//!   an [`EvidenceError`], never a silently-accepted absence.
20//!
21//! ## Phase 1 evidence types (the MVP flywheel read→verify→cache→reshare integrity gate)
22//!
23//! | Type | Proves | Class |
24//! |------|--------|-------|
25//! | [`RangeInclusionEvidence`] | a content range's leaf is included under a generation root | self-authenticating (offline) |
26//! | [`RootAnchorEvidence`] | a generation root is committed on-chain by the store's launcher-anchored lineage | locally-observable (chain read) |
27//! | [`ReadIntegrityEvidence`] | both of the above, bound to the same root — the read→cache→reshare gate | composite |
28//!
29//! See `SPEC.md` for the full evidence taxonomy and the self-authenticating (broadcastable) vs
30//! locally-observable (NEVER broadcastable, #1438 anti-censorship) classification table.
31//!
32//! ## Reused primitives
33//!
34//! The merkle inclusion machinery is REUSED verbatim from `dig-capsule` ([`MerkleProof`] /
35//! [`ProofStep`], with the `digstore:leaf:v1` / `digstore:node:v1` domain-separation tags), the
36//! DataStore on-chain parse from `dig-merkle`, and the injected reader from
37//! `dig-chainsource-interface` — this crate reinvents no crypto and cannot skew from the canonical
38//! read-crypto.
39
40#![forbid(unsafe_code)]
41#![warn(missing_docs)]
42
43mod error;
44mod evidence;
45mod range_inclusion;
46mod read_integrity;
47mod root_anchor;
48
49pub use error::{EvidenceError, EvidenceResult};
50pub use evidence::Evidence;
51pub use range_inclusion::{RangeInclusionClaim, RangeInclusionEvidence};
52pub use read_integrity::{ReadIntegrityClaim, ReadIntegrityEvidence};
53pub use root_anchor::{RootAnchorClaim, RootAnchorEvidence, MAX_LINEAGE_DEPTH};
54
55// --- Re-exports: the shared building blocks a consumer needs to construct claims + read evidence,
56// so a downstream crate depends on JUST dig-evidence for the evidence surface. ---
57
58/// The injected reads-only chain seam every active evidence type gathers through, plus the coin/lineage
59/// shapes it reads. Re-exported so consumers construct claims without a direct
60/// `dig-chainsource-interface` dependency.
61pub use dig_chainsource_interface::{ChainSource, CoinRecord, SingletonLineage};
62
63/// The merkle inclusion-proof shapes and domain-separation tags, REUSED verbatim from `dig-capsule`.
64/// A [`RangeInclusionClaim`] is built from a [`ProofStep`] path; the tags are the byte-for-byte
65/// producer contract.
66pub use dig_capsule::format::Bytes32 as CapsuleBytes32;
67pub use dig_capsule::merkle::{MerkleProof, ProofStep, LEAF_TAG, NODE_TAG};
68
69// NOTE: `dig_did::{AncestryProof, LineageModel}` were re-exported here as a convenience. They are
70// not re-exported while `dig-did` remains on the chia-0.26 / wallet-sdk-0.30 family: this crate now
71// rides chia-0.36 / wallet-sdk-0.34 (following `dig-merkle` 0.5 + `dig-chainsource-interface` 0.3),
72// so the re-exported types carried a SECOND `Bytes32` that is not assignable to the `Bytes32` in
73// this crate's own API — the exact "one import" convenience the re-export existed to provide.
74// `dig-did::prove_lineage` remains the reference implementation this crate's pattern generalises.
75// Restore the re-export once dig-did publishes on the chia-0.36 family.
76
77/// The canonical URN content-verification contract (`FoldedProof` + the gate-then-decrypt
78/// `verify_inclusion` / `verify_and_decrypt` over injected crypto), re-exported so a consumer reaches
79/// the blind-client read-verification surface through `dig-evidence` alongside the on-chain evidence
80/// types. This is the URN-level counterpart to [`RangeInclusionEvidence`].
81pub use dig_urn_protocol::{verify_and_decrypt, verify_inclusion, ContentCrypto, FoldedProof};