Skip to main content

dig_social_profile/
lib.rs

1//! # dig-social-profile — the DIG Network social-identity profile SCHEMA composite
2//!
3//! A DIG social identity is an **identity anchor** (a Chia `did:chia:` singleton in v1) PAIRED with a
4//! DataLayer store that holds the anchor's **profile**. The profile is a **sparse merkle tree** of
5//! standard SLOTS — one fixed 256-bit position per field — so any implementation reads and writes the
6//! same bytes, and any field can be proved (or proved absent) against a single 32-byte root.
7//!
8//! This crate is the profile SCHEMA + composite. It defines the standard slots, the deterministic
9//! value encoding, the DID anchoring/pairing predicate, the chain-independent [`resolve`] seam, and
10//! the DID->store [`IdentityProfile::mint_from_did`] launch driver — and it CONSUMES the lower
11//! layers:
12//!
13//! - [`dig_smt`] — the generic sparse-merkle-tree MECHANISM (tree, proof, sha256 hasher). The profile
14//!   root is byte-identical to what dig-identity historically produced (§5.1 / NC-9), proven by the
15//!   golden vectors in `tests/golden_vectors.rs`.
16//! - [`dig_did`] — the `did:chia:1…` string codec ([`did`] parses through it).
17//! - `dig_store` — the DataLayer store lifecycle ([`IdentityProfile::mint_from_did`] builds the
18//!   UNSIGNED launch spend through it; this crate never holds a key, never signs, never broadcasts).
19//! - `dig_identity` — the BLS identity-KEY primitive ([`slot`] derives slot keys with its canonical
20//!   `sha256` so the derivation shares one hash source with the key layer).
21//!
22//! The schema core is CHAIN-INDEPENDENT (no chain calls in [`slot`]/[`value`]/[`profile`]/[`proof`]/
23//! [`pairing`]/[`verify`]): on-chain DID resolution is a caller-supplied [`resolve::ChainSource`]
24//! TRAIT seam, so the schema layer still builds for wasm / no-network targets. Only
25//! [`IdentityProfile::mint_from_did`] reaches into dig-store to build the on-chain launch spend.
26//!
27//! ## What lives here
28//!
29//! | Concern | Module |
30//! |---|---|
31//! | Slot ids, the v2 slot map, slot-key derivation | [`slot`] |
32//! | The `tag ‖ len ‖ bytes` value encoding | [`value`] |
33//! | The portable `DPB` profile body (bytes <-> root) | [`body`] |
34//! | The mutable tree (over [`dig_smt`]): set/get/root/prove | [`tree`] |
35//! | Serializable proofs + root-only verification (over [`dig_smt`]) | [`proof`] |
36//! | The profile reader/writer + key resolution | [`profile`] / [`keys`] |
37//! | The identity anchor (DID) + discovery parse (via [`dig_did`]) | [`did`] |
38//! | The canonical XCH receive-address field codec | [`xch`] |
39//! | The DID<->store bidirectional-pairing predicate + ownership proof | [`pairing`] |
40//! | Composed "this datum belongs to this DID" verification | [`verify`] |
41//! | On-chain DID->profile resolution over a caller [`resolve::ChainSource`] | [`resolve`] |
42//! | The managed profile object + DID->store minting | [`identity_profile`] |
43//!
44//! ## Cargo features
45//!
46//! - **`chia`** (default) — the chia-anchored half: DID parsing/anchoring, the DID<->store pairing
47//!   predicate, the on-chain [`resolve`] seam, [`IdentityProfile`] minting, store update
48//!   [`authority`], composed [`verify`]ication, [`xch`] address validation, and the `Bytes32`/`Coin`
49//!   re-exports.
50//! - **no default features** — the pure BYTE CORE: [`slot`], [`value`], [`tree`], [`proof`],
51//!   [`profile`] and the portable [`body`] format, whose entire dependency set is
52//!   `dig-smt`, `sha2` and `thiserror`. A host riding a DIFFERENT chia-protocol line (dig-node patches it to dig-gossip's
53//!   vendored 0.26 fork, while this crate pins 0.36.1) can read and write profile bytes without a
54//!   second chia line in its build.
55//!
56//! Both surfaces compute byte-identical slot keys, values and roots — that is what the frozen golden
57//! vectors in `tests/golden_vectors.rs` assert.
58//!
59//! ## Proving a field against a root
60//!
61//! ```
62//! use dig_social_profile::{Profile, Value, slot::standard, proof};
63//!
64//! let mut profile = Profile::with_schema_v2();
65//! profile.set(standard::DISPLAY_NAME, Value::Utf8("Ada".into()));
66//!
67//! let tree = profile.build_tree().unwrap();
68//! let root = tree.root();
69//!
70//! // Prove the display name equals "Ada" using only (root, proof).
71//! let membership = tree.prove_membership(standard::DISPLAY_NAME).unwrap();
72//! let claim = Value::Utf8("Ada".into());
73//! assert!(proof::verify_membership(&root, standard::DISPLAY_NAME, &claim, &membership).unwrap());
74//!
75//! // Prove no peer id is present.
76//! let absent = tree.prove_non_membership(standard::PEER_ID).unwrap();
77//! assert!(proof::verify_non_membership(&root, standard::PEER_ID, &absent).unwrap());
78//! ```
79
80#[cfg(feature = "chia")]
81pub mod authority;
82pub mod body;
83#[cfg(feature = "chia")]
84pub mod did;
85pub mod error;
86#[cfg(feature = "chia")]
87pub mod identity_profile;
88pub mod keys;
89#[cfg(feature = "chia")]
90pub mod pairing;
91pub mod profile;
92pub mod proof;
93#[cfg(feature = "chia")]
94pub mod resolve;
95pub mod slot;
96pub mod tree;
97pub mod value;
98#[cfg(feature = "chia")]
99pub mod verify;
100#[cfg(feature = "chia")]
101pub mod xch;
102
103#[cfg(feature = "chia")]
104pub use authority::{
105    DelegationKind, ProfileUpdate, StoreAuthoritySource, StoreUpdateAuthority, WriterDelegation,
106};
107pub use body::{AnchoredRoot, VerifiedBody};
108#[cfg(feature = "chia")]
109pub use did::{parse_did_from_description, Did, DID_CHIA_PREFIX};
110pub use error::{Error, Result};
111#[cfg(feature = "chia")]
112pub use identity_profile::{IdentityProfile, IdentityProfileMint};
113pub use keys::DidKeys;
114#[cfg(feature = "chia")]
115pub use pairing::{
116    evaluate_pairing, is_authoritative_profile, store_belongs_to_did, IdentitySingleton,
117    PairingOutcome, SingletonLineage, StoreOwnershipProof, StoreRecord,
118};
119
120// Re-export the canonical Chia types the public API speaks, so consumers pin the same versions.
121#[cfg(feature = "chia")]
122pub use chia_protocol::{Bytes32, Coin};
123pub use profile::{resolve_did_keys, Profile, SlotEdit};
124pub use proof::{verify_membership, verify_non_membership, ProfileProof};
125// The on-chain resolution seam. The chain `resolve_did_keys` stays module-qualified
126// (`resolve::resolve_did_keys`) to avoid colliding with the networkless [`profile::resolve_did_keys`].
127#[cfg(feature = "chia")]
128pub use resolve::{
129    resolve_bls_public_key, resolve_identity_profile, ChainSource, ChainStoreState, ResolveError,
130};
131// The DataLayer store shapes `mint_from_did` speaks, re-exported so a consumer depends on ONE shape.
132#[cfg(feature = "chia")]
133pub use dig_store::{Datastore, DigDataStoreMetadata, MerkleCoinSpend, SizeBucket, StoreOwner};
134pub use slot::SlotId;
135pub use tree::ProfileTree;
136pub use value::{Value, ValueTag};
137#[cfg(feature = "chia")]
138pub use verify::{verify_profile_field_absent_for_did, verify_profile_field_for_did};
139#[cfg(feature = "chia")]
140pub use xch::{is_valid_xch_address, parse_xch_address};