Skip to main content

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`]. The
42//! remaining DID operations (update, recovery, transfer, launch, melt, attest, resolve-document) land
43//! in their own units against this foundation; their modules are declared below as doc-only stubs so
44//! the layout is final.
45
46// Internal helpers — not part of the public surface.
47mod context;
48
49// Public modules.
50pub mod error;
51pub mod sign;
52pub mod types;
53
54// DID creation, hydration, and the did:chia string codec — shipped.
55pub mod create;
56pub mod did_string;
57pub mod hydrate;
58
59// The remaining DID operation modules — declared now so the crate layout is final; each is filled
60// in its own unit (doc-only until then, so they add no untested surface).
61pub mod attest;
62pub mod launch;
63pub mod melt;
64pub mod recovery;
65pub mod transfer;
66pub mod update;
67
68// Lineage authentication (U3): the chain-reading seam + singleton walk, and the lineage proof.
69pub mod lineage;
70pub mod resolve;
71
72// The curated public surface — consumers depend on these paths, not the module layout.
73pub use create::{create_did, create_eve_did_only, create_simple_did};
74pub use did_string::{did_string_from_launcher_id, launcher_id_from_did_string, DID_CHIA_PREFIX};
75pub use error::{DidError, DidResult};
76pub use hydrate::{did_info_from_puzzle, hydrate_did_from_parent_spend, parse_did_coin_spend};
77pub use lineage::{prove_lineage, AncestryProof, LineageModel};
78pub use resolve::{
79    resolve_xch_address, resolve_xch_address_from_did_string, walk_did_lineage_to_tip, ChainSource,
80    DidTip, SingletonLineage, MAX_LINEAGE_DEPTH,
81};
82pub use sign::required_signatures;
83pub use types::{Bytes32, Coin, CoinSpend, Did, DidInfo, DidSpend, LineageProof, Owner, Proof};
84
85// The canonical bech32m address codec — re-exported so a consumer can render / decode a resolved XCH
86// payment address (from [`resolve_xch_address`]) without a direct `chia-sdk-utils` dependency.
87pub use chia_sdk_utils::Address;
88
89// Re-export the signing types a consumer needs to CALL [`required_signatures`] and consume its
90// result, so a downstream crate need not add a direct chia-wallet-sdk dependency for them.
91pub use chia_wallet_sdk::signer::{AggSigConstants, RequiredSignature};