1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! # dig-store — the DIG Network DataLayer store manager
//!
//! A **store** is the composition of two planes:
//!
//! - an **on-chain anchor** — a CHIP-0035 DataLayer singleton (owned by
//! [`dig-merkle`](https://github.com/DIG-Network/dig-merkle)) whose metadata carries the `.dig`
//! merkle root plus its label / description / size bucket / program hash; and
//! - an **off-chain data plane** — the `.dig` capsule format (owned by
//! [`dig-capsule`](https://github.com/DIG-Network/dig-capsule)).
//!
//! `dig-store` composes the two into ONE curated abstraction, with three concerns:
//!
//! 1. **Lifecycle** — a store is a coin that gets SPENT: [`create_store`], [`modify_store`],
//! [`melt_store`]. Each returns an UNSIGNED [`MerkleCoinSpend`]; the wallet-backend / node signs +
//! broadcasts. `dig-store` never holds a key, never signs, never dials the network.
//! 2. **Size proof** — a store anchors its `.dig` SIZE on chain as a power-of-2 [`SizeBucket`]
//! (1 MB..1 GB, NC-8 minimal encoding). Before keeping a downloaded `.dig`, a client runs
//! [`SizeProof::verify`]: a real size that does not match the anchored bucket is
//! [`SizeVerdict::Discard`]ed — a dig-node MUST NOT store or serve a size-mismatched capsule.
//! 3. **Getters** — a comprehensive read surface over both planes:
//! - **on-chain** (chain-proven, NC-9): [`get_store_did_owner`], [`get_store_singleton_tip`],
//! [`get_root_history`], [`get_latest_root`], [`get_latest_root_urn`], [`get_store_urn`], the
//! label / description / size / program-hash getters, and [`get_store_status`] — the aggregate
//! status snapshot from ONE consistent lineage walk;
//! - **off-chain** (from a compiled `.dig` module's bytes, wasmtime-free): [`get_capsule_identity`]
//! recovers a capsule's declared `(store_id, root_hash)`, and [`open_capsule`] additionally
//! cross-checks the declared `store_id` against a trusted anchor (fail-closed).
//!
//! The coin/identity types ([`Bytes32`], [`Coin`], [`CoinSpend`], [`DataStore`], [`DidRef`],
//! [`DigDataStoreMetadata`], [`MerkleCoinSpend`]) and the owner type ([`StoreOwner`]) are re-exported
//! VERBATIM from `dig-merkle`, and [`ChainSource`] from `dig-chainsource-interface`, so a consumer
//! depends on ONE canonical shape across the whole DataLayer surface.
//!
//! ## Invariants
//!
//! - **INV-1 — No network.** `dig-store` performs no chain I/O itself; on-chain getters take a
//! [`ChainSource`] the caller supplies (the user's verified node or a trusted provider set, NC-9),
//! and lifecycle operations are pure transforms of their inputs.
//! - **INV-2 — No keys, unsigned output.** Lifecycle operations return unsigned spends; signing is
//! always the caller's responsibility (inherited from `dig-merkle`).
//! - **INV-3 — Minimal on-chain encoding (NC-8).** The store's on-chain footprint is delegated
//! wholesale to `dig-merkle`, which owns the minimal byte layout; the size is a single-byte bucket.
//! - **INV-4 — On-chain proof always (NC-9).** Every getter that returns chain-anchored data proves
//! it against the chain; trust never comes from a self-declared field or an unverified peer.
//! - **INV-5 — `.dig` back-compat (§5.1).** The capsule surface reads every older `.dig` format
//! identically (inherited from `dig-capsule`'s reader, which dispatches on the DIGS blob version); the
//! public API is extended additively, never broken.
//!
//! ## The `store_id` trust boundary (off-chain capsule getters)
//!
//! [`get_capsule_identity`] recovers a capsule's DECLARED `store_id` from module bytes. That id is the
//! store's on-chain launcher id and is NOT self-verifiable from the bytes alone — treat it as a CLAIM
//! until cross-checked against a trusted anchor. [`open_capsule`] does that cross-check against a
//! caller-supplied anchor and fails closed on mismatch. The `root_hash` is always proven internally
//! consistent by the reader (it recomputes the merkle root and rejects a forged one).
// Public modules.
// The curated public surface — consumers depend on these paths, not the module layout.
pub use ;
pub use ChainSource;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Derives the [`LineageProof`] a child singleton spend must carry to be recreated from a hydrated
/// store (the lineage-getter surface). Re-exported verbatim from `dig-merkle` (the byte-source-of-
/// truth, INV-4) so a consumer builds the next spend against a store the walk returned without a
/// separate `dig-merkle` dependency. `dig-merkle` 0.4.3 derives its `parent_inner_puzzle_hash` via
/// the DataLayer updater path, so the resulting child spend is consensus-valid (no
/// `AssertMyParentIdFailed`, #1332).
pub use child_lineage_proof;
pub use ;