dig_did/lib.rs
1//! # dig-did — the DIG Network canonical Chia DID expert crate
2//!
3//! `dig-did` is a **pure, key-free, network-free** SpendBundle-builder for Chia Decentralized
4//! Identifiers (DIDs). It constructs the exact [`CoinSpend`]s for every DID
5//! lifecycle operation and reports — via [`required_signatures`] — the exact signatures a caller
6//! must produce. It never holds a secret key, never signs, and never touches the network. The
7//! consumer signs the reported messages, assembles the `SpendBundle`, and broadcasts.
8//!
9//! ## Invariants
10//!
11//! These four invariants hold across the entire crate and are the contract every unit is built to
12//! (SPEC §1):
13//!
14//! - **INV-1 — No network.** dig-did performs NO network or chain I/O. Every function is a pure
15//! transform of its inputs; the caller fetches coins and broadcasts bundles.
16//! - **INV-2 — No keys.** dig-did never accepts, holds, derives, or logs a secret key. It computes
17//! what must be signed ([`required_signatures`]); the caller's signer produces the signatures.
18//! - **INV-3 — Unsigned output.** Every operation returns an unsigned [`DidSpend`] — coin spends
19//! plus the recreated child DID. Signatures are always the caller's responsibility.
20//! - **INV-4 — SDK byte-source-of-truth.** Every puzzle, layer, and coin-spend byte is produced by
21//! `chia-wallet-sdk` (pinned to the 0.34 / chia-protocol 0.36 family). dig-did adds DID-workflow
22//! ergonomics on top; it never re-implements a puzzle or hand-rolls a spend bundle.
23//!
24//! ## Consumer pattern
25//!
26//! ```text
27//! build an unsigned DidSpend -> required_signatures(&spend.coin_spends, &constants)
28//! -> caller signs each reported message -> assemble SpendBundle -> broadcast
29//! ```
30//!
31//! ## Status
32//!
33//! The foundation (type surface, error taxonomy, inner-spend helpers, signing boundary) ships
34//! alongside **create** ([`create_did`], [`create_simple_did`], [`create_eve_did_only`]),
35//! **hydrate** ([`hydrate_did_from_parent_spend`], [`parse_did_coin_spend`],
36//! [`did_info_from_puzzle`]), the **did:chia:** string codec ([`did_string_from_launcher_id`],
37//! [`launcher_id_from_did_string`]), and the **lineage-proof spine** — the [`resolve::ChainSource`]
38//! chain-reading seam (the ONE canonical `dig-chainsource-interface` trait, re-exported),
39//! [`prove_lineage`] + [`AncestryProof`], and [`walk_did_lineage_to_tip`] — and the **DID→XCH address
40//! resolver** ([`resolve_xch_address`], [`resolve_xch_address_from_did_string`]), which authenticates
41//! a DID's current tip to its genuine launcher before returning the owner's payment [`Address`]; and
42//! **update** ([`spend_did_with_conditions`] — the DID-preserving owner spend that emits caller
43//! conditions, binding another operation to an authenticated act of the DID in one bundle).
44//!
45//! The remaining DID operations (recovery, transfer, launch, melt, attest, resolve-document) land in
46//! their own units against this foundation; their modules are declared below as doc-only stubs so
47//! the layout is final.
48
49// Internal helpers — not part of the public surface.
50mod context;
51
52// Test-only bundle-inspection helpers, shared across the operation modules' test suites.
53#[cfg(test)]
54mod test_support;
55
56// Public modules.
57pub mod amount;
58pub mod error;
59pub mod sign;
60pub mod types;
61
62// DID creation, hydration, and the did:chia string codec — shipped.
63pub mod create;
64pub mod did_string;
65pub mod hydrate;
66
67// The remaining DID operation modules — declared now so the crate layout is final; each is filled
68// in its own unit (doc-only until then, so they add no untested surface).
69pub mod attest;
70pub mod launch;
71pub mod melt;
72pub mod recovery;
73pub mod transfer;
74
75// DID-preserving owner spends (U3) — shipped.
76pub mod update;
77
78// Lineage authentication (U3): the chain-reading seam + singleton walk, and the lineage proof.
79pub mod lineage;
80pub mod resolve;
81
82// The curated public surface — consumers depend on these paths, not the module layout.
83pub use amount::SingletonAmount;
84pub use create::{create_did, create_eve_did_only, create_simple_did};
85pub use did_string::{did_string_from_launcher_id, launcher_id_from_did_string, DID_CHIA_PREFIX};
86pub use error::{DidError, DidResult};
87pub use hydrate::{did_info_from_puzzle, hydrate_did_from_parent_spend, parse_did_coin_spend};
88pub use lineage::{prove_lineage, AncestryProof, LineageModel};
89pub use melt::melt;
90pub use resolve::{
91 resolve_xch_address, resolve_xch_address_from_did_string, walk_did_lineage_to_tip, ChainSource,
92 DidTip, SingletonLineage, MAX_LINEAGE_DEPTH,
93};
94pub use sign::required_signatures;
95pub use types::{Bytes32, Coin, CoinSpend, Did, DidInfo, DidSpend, LineageProof, Owner, Proof};
96pub use update::spend_did_with_conditions;
97
98// The canonical bech32m address codec — re-exported so a consumer can render / decode a resolved XCH
99// payment address (from [`resolve_xch_address`]) without a direct `chia-sdk-utils` dependency.
100pub use chia_sdk_utils::Address;
101
102// Re-export the signing types a consumer needs to CALL [`required_signatures`] and consume its
103// result, so a downstream crate need not add a direct chia-wallet-sdk dependency for them.
104pub use chia_wallet_sdk::signer::{AggSigConstants, RequiredSignature};