dig_store/lib.rs
1//! # dig-store — the DIG Network DataLayer store manager
2//!
3//! A **store** is the composition of two planes:
4//!
5//! - an **on-chain anchor** — a CHIP-0035 DataLayer singleton (owned by
6//! [`dig-merkle`](https://github.com/DIG-Network/dig-merkle)) whose metadata carries the `.dig`
7//! merkle root plus its label / description / size bucket / program hash; and
8//! - an **off-chain data plane** — the `.dig` capsule format (owned by
9//! [`dig-capsule`](https://github.com/DIG-Network/dig-capsule)).
10//!
11//! `dig-store` composes the two into ONE curated abstraction, with three concerns:
12//!
13//! 1. **Lifecycle** — a store is a coin that gets SPENT: [`create_store`], [`modify_store`],
14//! [`melt_store`]. Each returns an UNSIGNED [`MerkleCoinSpend`]; the wallet-backend / node signs +
15//! broadcasts. `dig-store` never holds a key, never signs, never dials the network.
16//! 2. **Size proof** — a store anchors its `.dig` SIZE on chain as a power-of-2 [`SizeBucket`]
17//! (1 MB..1 GB, NC-8 minimal encoding). Before keeping a downloaded `.dig`, a client runs
18//! [`SizeProof::verify`]: a real size that does not match the anchored bucket is
19//! [`SizeVerdict::Discard`]ed — a dig-node MUST NOT store or serve a size-mismatched capsule.
20//! 3. **Getters** — a comprehensive, chain-proven (NC-9) read surface over every on-chain property
21//! ([`get_store_did_owner`], [`get_store_singleton_tip`], [`get_root_history`],
22//! [`get_latest_root`], [`get_latest_root_urn`], [`get_store_urn`], and the label / description /
23//! size / program-hash getters).
24//!
25//! The coin/identity types ([`Bytes32`], [`Coin`], [`CoinSpend`], [`DataStore`], [`DidRef`],
26//! [`DigDataStoreMetadata`], [`MerkleCoinSpend`]) and the owner type ([`StoreOwner`]) are re-exported
27//! VERBATIM from `dig-merkle`, and [`ChainSource`] from `dig-chainsource-interface`, so a consumer
28//! depends on ONE canonical shape across the whole DataLayer surface.
29//!
30//! ## Invariants
31//!
32//! - **INV-1 — No network.** `dig-store` performs no chain I/O itself; on-chain getters take a
33//! [`ChainSource`] the caller supplies (the user's verified node or a trusted provider set, NC-9),
34//! and lifecycle operations are pure transforms of their inputs.
35//! - **INV-2 — No keys, unsigned output.** Lifecycle operations return unsigned spends; signing is
36//! always the caller's responsibility (inherited from `dig-merkle`).
37//! - **INV-3 — Minimal on-chain encoding (NC-8).** The store's on-chain footprint is delegated
38//! wholesale to `dig-merkle`, which owns the minimal byte layout; the size is a single-byte bucket.
39//! - **INV-4 — On-chain proof always (NC-9).** Every getter that returns chain-anchored data proves
40//! it against the chain; trust never comes from a self-declared field or an unverified peer.
41//! - **INV-5 — `.dig` back-compat (§5.1).** The (deferred) capsule surface reads every older `.dig`
42//! format identically; the public API is extended additively, never broken.
43//!
44//! ## Off-chain capsule getters — deferred (SPEC §11)
45//!
46//! `open_capsule` / `get_capsule_identity` are NOT in this version: `dig-capsule 0.4.0` exposes no
47//! lightweight `bytes → (store_id, root_hash)` reader (the only path is the full wasmtime serve
48//! runtime). A `Capsule::from_module_bytes` reader is being added to `dig-capsule` release-first and
49//! the capsule getters land in a follow-up unit. The download-gating [`SizeProof`] needs no capsule
50//! open and is complete here.
51
52// Public modules.
53pub mod chain;
54pub mod error;
55pub mod lifecycle;
56pub mod size;
57pub mod store;
58pub mod types;
59pub mod urn;
60
61// The curated public surface — consumers depend on these paths, not the module layout.
62pub use chain::ChainSource;
63pub use error::{DigStoreError, DigStoreResult};
64pub use lifecycle::{create_store, melt_store, modify_store, CreateStoreParams, StoreOwner};
65pub use size::{SizeBucket, SizeProof, SizeVerdict};
66pub use store::{
67 get_latest_root, get_latest_root_urn, get_root_history, get_store_description,
68 get_store_did_owner, get_store_label, get_store_program_hash, get_store_singleton_tip,
69 get_store_size_bucket, get_store_urn,
70};
71pub use types::{
72 Bytes32, Coin, CoinSpend, DataStore, DidRef, DigDataStoreMetadata, MerkleCoinSpend, RootHistory,
73};
74pub use urn::{capsule_urn, retrieval_key, store_urn, URN_PREFIX};