Skip to main content

dig_account/
lib.rs

1//! # dig-account
2//!
3//! The DIG Network **user Account** — the fat, strictly-logical (zero-UI, headless-testable)
4//! encapsulation of everything an account can do.
5//!
6//! An **Account** is one master seed plus one or more **Profiles** (exactly one default). A
7//! **Profile** is a DID + dig-store + SMT-of-profile-info, minted and signed with the account
8//! seed's key at that profile index and recorded as a [`registry::ProfileAnchor`].
9//!
10//! This crate owns the object model, the unlock policy + keystore crypto, the in-process
11//! identity+money signer, per-profile key/DEK derivation, the on-chain **DID mint**, and all wallet
12//! ops, including the STORE half of a profile mint — a dig-store singleton launched from the DID's
13//! own coin, committed to a seeded profile SMT. It NEVER draws UI or drives an OS auth ceremony — the host harness (dig-app) injects a
14//! UI/auth provider that this crate calls back through for unlock and spend-confirm ceremonies.
15//!
16//! ## Custody split (the harness seam)
17//!
18//! dig-account is headless: it owns the account STATE machine + the crypto, but it never collects a
19//! password, renders a spend prompt, or drives an OS auth ceremony. The host harness (dig-app)
20//! implements [`AuthProvider`] and injects it; dig-account calls back
21//! through that seam for every unlock and every spend confirmation. The private key never leaves the
22//! crate; the UI never sees a seed.
23//!
24//! See `SPEC.md` for the normative contract.
25//!
26//! ## What carries a real implementation
27//!
28//! Everything below is implemented and tested against a real consensus validator or real crypto —
29//! there are no stubbed bodies left. The object model, the **profile registry** ([`registry`] —
30//! which profiles exist, which is active, which mints are half-finished), keystore (`store`),
31//! unlock policy (`auth::policy`), per-profile key/DEK derivation, and the money path (`wallet` —
32//! the canonical `WalletKey` + the concrete [`MoneySigner`](wallet::money_signer::LocalMoneySigner)
33//! over `dig-wallet-backend`'s `LocalSigner`, with the structured
34//! [`SpendSummary`]) carry real, tested implementations, as does the
35//! **on-chain DID mint** ([`mint`] — build, sign, push, and prove a `did:chia:` against real chain
36//! evidence) and the **full profile mint** ([`mint::profile`] — the two-bundle ceremony that binds a
37//! DID to a dig-store launched from its coin, resumable across a restart).
38//!
39//! A profile mint is deliberately THREE calls rather than one, because it spans two on-chain
40//! confirmations with a minutes-wide window between them in which the DID is already paid for:
41//! [`ProfileMinter::begin_profile_mint`], [`ProfileMinter::advance_profile_mint`] and
42//! [`ProfileMinter::profile_mint_status`].
43
44pub mod auth;
45pub mod chain_confirm;
46pub mod constants;
47mod continuation_guard;
48pub mod edit;
49pub mod error;
50pub mod id;
51pub mod keys;
52pub mod melt;
53pub mod mint;
54pub mod model;
55pub mod profile_mint;
56pub mod profile_resolve;
57pub mod registry;
58pub mod reward_distributor_mint;
59pub mod session;
60pub mod session_residency;
61pub mod signer;
62pub mod store;
63pub mod unlocked;
64pub mod wallet;
65
66pub use auth::factors::AuthFactors;
67pub use auth::policy::{AllOf, AuthPolicy, PasswordOnlyPolicy, UnlockError, UnlockGate};
68pub use auth::provider::{AuthProvider, SpendConfirmRequest, SpendDecision, UnlockRequest};
69pub use auth::second_factor::SecondFactor;
70pub use auth::second_factors::{
71    Challenge, ChallengeIssuer, CoseAlgorithm, PasskeyClock, PasskeyCredential, PasskeyError,
72    PasskeyFactor, SystemPasskeyClock, SystemTimeSource, TimeSource, TotpAlgorithm, TotpError,
73    TotpFactor, TotpParams, TotpSecret, UserVerification,
74};
75pub use chain_confirm::{
76    confirm_all_spendable_by_name, confirm_spendable_by_name, UnconfirmedInput,
77};
78pub use constants::MAINNET_ADDRESS_PREFIX;
79pub use edit::{
80    read_profile, CommittedEdit, EditError, EditResult, EditStatus, ProfileContentSource,
81    ProfileEdit, ProfileEditor, ProfileFields, ProfileSlot, ProfileSnapshot,
82};
83pub use error::{AccountError, Result};
84pub use id::{AccountId, ProfileIx};
85pub use keys::dek::profile_dek;
86pub use keys::wallet_key::WalletKey;
87pub use mint::reward_distributor::{
88    begin_reward_distributor_mint, RewardDistributorMintRequest, SignedRewardDistributorMint,
89    OFFER_XCH_AMOUNT,
90};
91pub use mint::reward_distributor_clawback::{
92    begin_reward_distributor_clawback, RewardDistributorClawbackRequest,
93    SignedRewardDistributorClawback,
94};
95pub use mint::reward_distributor_refill::{
96    begin_reward_distributor_refill, RewardDistributorRefillRequest, SignedRewardDistributorRefill,
97};
98#[cfg(feature = "coinset-push")]
99pub use mint::BlockingHttpTransport;
100pub use mint::{
101    interpret_push_answer, push_tx_request_json, ChainUnavailable, CoinsetPublisher,
102    ConfirmedRewardDistributor, ConfirmedStore, HttpAnswer, MintError, MintNetwork, MintOptions,
103    MintResult, MintStatus, MintedDid, OwnershipProof, PendingMint, PendingRewardDistributor,
104    PendingRewardDistributorRecord, PendingStoreLaunch, ProfileMintStatus, ProfileSeed,
105    PushOutcome, PushTransport, RecordField, RecordRejection, RewardDistributorStatus,
106    SpendPublisher, COINSET_MAINNET_PUSH_URL, MAX_MINT_FEE_MOJOS, MIN_CONFIRMATION_DEPTH,
107};
108pub use model::{Account, AccountRecord, Profile};
109pub use profile_mint::ProfileMinter;
110pub use profile_resolve::{
111    resolve_profile_store, ProfileResolveError, ProfileStoreResolution,
112    MAX_PROFILE_LAUNCHES_PER_DID, PROFILE_INTERMEDIATE_PUZZLE_HASH,
113};
114pub use registry::{
115    ActiveProfile, ActiveSwitch, ConfirmedStoreRecord, MintStage, MintedDidRecord,
116    PendingMintRecord, PendingStoreLaunchRecord, ProfileAnchor, ProfileEnd, ProfileEndOutcome,
117    ProfileEntry, ProfileMintInProgress, ProfileRegistry, ProfileVisibility,
118};
119pub use reward_distributor_mint::RewardDistributorMinter;
120pub use session::AccountSession;
121pub use session_residency::Residency;
122pub use signer::ProfileSigner;
123pub use store::{AccountStore, AccountStoreError};
124pub use unlocked::UnlockedAccount;
125pub use wallet::approval::{PendingApproval, SpendApproval, SpendRuling};
126pub use wallet::authorizer::WalletOps;
127pub use wallet::autosend::{AutoSendPolicy, OpClassLimits, SpendOpClass, DEFAULT_PERIOD_SECONDS};
128pub use wallet::cat_transfer::{
129    amount_in_dig, cat_coins, cat_curried_puzzle_hash, dig_cat_coins, dig_curried_puzzle_hash,
130    CatCoinListing, CatTransferError, CatTransferPlan, CatTransferRequest, CatTransferResult,
131    DIG_BASE_UNITS_PER_TOKEN, MAX_CAT_TRANSFER_INPUT_COINS, MAX_LISTED_CAT_COINS,
132};
133pub use wallet::clock::{Clock, FixedClock, SystemClock};
134pub use wallet::enforcer::PolicyAuthorizer;
135pub use wallet::money_signer::{LocalMoneySigner, MoneySigner};
136pub use wallet::policy::{CustodyPolicy, HotWallet, Vault};
137pub use wallet::summary::{SpendDestination, SpendRecipient, SpendSummary, SpendTier};
138pub use wallet::transfer::{
139    transfer_status, ConfirmedTransfer, PayableDestination, PendingTransfer, TransferError,
140    TransferPlan, TransferRequest, TransferResult, TransferStatus, MAX_TRANSFER_INPUT_COINS,
141};
142pub use wallet::vault_move::VaultMove;