moonproof-wallet 0.2.2

Native Rust wallet for the Midnight blockchain — HD derivation, coin balancing, Zswap/unshielded/dust transacting
Documentation
//! Dust sub-wallet — port of `@midnight-ntwrk/wallet-sdk-dust-wallet`.
//!
//! Midnight's transaction fees are paid in **DUST**, a per-NIGHT-UTXO
//! resource that accrues from the moment a NIGHT UTXO is registered for
//! dust generation. Without dust there is no way to pay a non-claim-rewards
//! transaction's fee, so this module is the missing piece between the
//! unshielded sub-wallet and a transaction that actually lands in-block.
//!
//! ## Module layout
//!
//! - [`state`] — `DustState`, the wallet's local view: wraps the ledger's
//!   [`moonproof_ledger::ledger::dust::DustLocalState`] with our public-key /
//!   pending-spends / sync-progress bookkeeping.
//! - [`balances`] — read-only projections over `DustState`: balance,
//!   available coins, generation info, "what would dust look like if I
//!   registered these NIGHTs?" estimation.
//! - [`transacting`] — pure-logic recipe builders for register /
//!   deregister / fee-balancing transactions. No I/O, no clocks.
//! - [`ledger_adapter`] — thin translation layer that turns a recipe into
//!   a `moonproof_ledger::ledger::Intent` / `Transaction`. Owns the
//!   `Db = InMemoryDB` choice and the prove/seal/serialize pipeline.
//!
//! ## Where dust shows up in tx submission
//!
//! 1. **Genesis**: a fresh wallet has NIGHT UTXOs but no dust. The first
//!    transaction is an *address-only* registration — `dust_actions =
//!    Some(DustActions { spends: [], registrations: [reg] })` where
//!    `reg.dust_address = Some(dust_pk)`. After this lands, the chain
//!    auto-delegates dust generation for subsequent NIGHT receipts.
//! 2. **Per-UTXO registration**: existing NIGHT UTXOs created *before*
//!    address delegation don't auto-generate dust. The wallet registers
//!    them by spending and re-receiving them inside an unshielded offer
//!    that carries the dust registration in the same intent.
//! 3. **Fee balancing**: every non-`ClaimRewards` transaction needs a
//!    dust input that covers `Transaction::fees_with_margin(...)`. The
//!    [`transacting::compute_fee_balancing_recipe`] helper iteratively
//!    converges on the minimum dust spend that covers the new tx's fee
//!    (the addition of dust spends increases the fee, so we re-estimate
//!    until the picked set covers the new estimate).

pub mod balances;
pub mod ledger_adapter;
pub mod roots;
pub mod state;
pub mod sync;
pub mod transacting;

pub use balances::{
    available_coins, available_coins_with_generated_dust, estimate_dust_generation,
    generation_info, pending_coins, split_night_utxos, total_coins, wallet_balance, DustFullInfo,
    DustGenerationDetails, NightUtxoForDust, UtxoWithDustEstimate,
};
pub use ledger_adapter::{
    build_dust_balancing_intent, build_dust_generation_intent, build_dust_transaction,
    finalize_dust_only_transaction, finalize_with_proving_provider,
    serialize_finalized_dust_transaction, serialize_signed_dust_transaction, sign_dust_intent,
    sign_dust_intent_multi, used_segment_ids, DustIntent, FinalizedDustTransaction,
    SignedDustTransaction,
};
pub use roots::DustTreeRoots;
pub use state::{CoinWithFee, DustState, PendingDustSpend, SyncProgressUpdate, UnprovenDustSpend};
pub use sync::{decode_dust_event, replay_hex_events};
pub use transacting::{
    build_dust_generation_recipe, compute_fee_balancing_recipe, fee_coverage_estimate,
    find_available_segment_id, next_segment_id_after, DustBalancingRecipe, DustGenerationRecipe,
    DustRegistrationSpec, FeeCoverageEstimate,
};