zingolabs_zewif/lib.rs
1//! # Zcash Wallet Interchange Format (ZeWIF)
2//!
3//! `zewif` is a library that defines a standard data format for migrating wallet data
4//! between different Zcash wallet implementations. It provides a comprehensive set of
5//! types, tools, and utilities for serializing, deserializing, and manipulating Zcash
6//! wallet data in a way that preserves all critical information during migration.
7//!
8//! ## Core Features
9//!
10//! * **Complete Wallet Data Model**: Represents all aspects of a Zcash wallet including
11//! accounts, addresses, transactions, and keys
12//! * **Multi-Protocol Support**: Handles the Transparent, Sapling, and Orchard Zcash protocols.
13//! * **Type-Safe Representation**: Uses Rust's type system to ensure correct handling of Zcash concepts
14//! * **Extensible Metadata**: Supports custom metadata through an attachments system
15//!
16//! ## Core Components
17//!
18//! The ZeWIF format is organized hierarchically:
19//!
20//! - [`Zewif`]: The root container holding wallets and global transaction data
21//! - [`ZewifWallet`]: Individual wallet with accounts and network context
22//! - [`Account`]: Logical grouping of addresses and transaction references
23//! - [`Address`]: Individual addresses of various types (transparent, shielded, unified)
24//! - [`Transaction`]: Complete transaction data (inputs, outputs, metadata)
25//!
26//! ## Protocol Support
27//!
28//! ZeWIF handles the Zcash protocol versions:
29//!
30//! - **Transparent**: Bitcoin-compatible public transactions ([`TransparentAddress`], [`TxIn`], [`TxOut`])
31//! - **Sapling**: Improved shielded protocol ([`sapling`] module, [`sapling::SaplingSentOutput`], etc.)
32//! - **Orchard**: Latest shielded protocol ([`orchard`] module, [`orchard::OrchardSentOutput`], etc.)
33//!
34//! ## Integration Path
35//!
36//! This crate is part of a larger ecosystem:
37//!
38//! - `zewif`: Core library defining the interchange format (this crate)
39//! - `zmigrate`: Command-line tool for wallet migrations
40//! - `zewif-zcashd`: ZCashd-specific integration for migration
41//! - `zewif-zingo`: Zingo-specific integration for migration (future)
42//!
43//! ## Usage Examples
44//!
45//! ```no_run
46//! use zewif::{Zewif, ZewifWallet, Network, Account, Address, BlockHeight};
47//!
48//! // Create a new ZeWIF container
49//! let mut zewif = Zewif::new(BlockHeight::from_u32(2000000));
50//!
51//! // Create a new wallet for the main network
52//! let mut wallet = ZewifWallet::new(Network::Main);
53//!
54//! // Add a new account to the wallet
55//! let mut account = Account::new();
56//! account.set_name("Default Account");
57//!
58//! // Add the account to the wallet and the wallet to the ZeWIF container
59//! wallet.add_account(account);
60//! zewif.add_wallet(wallet);
61//! ```
62
63// Macros
64mod blob_macro;
65mod data_macro;
66mod envelope_macros;
67mod mod_use_macro;
68mod string_macro;
69mod test_roundtrip_macros;
70
71// Test utilities
72#[cfg(any(test, feature = "test-dependencies"))]
73mod_use!(test_utils);
74
75// Modules requiring qualified paths
76pub mod orchard;
77pub mod sapling;
78pub mod transparent;
79
80// Modules that can use unqualified paths
81mod_use!(account);
82mod_use!(address);
83mod_use!(amount);
84mod_use!(anchor);
85mod_use!(bip_39_mnemonic);
86mod_use!(blob);
87mod_use!(block_hash);
88mod_use!(block_height);
89mod_use!(data);
90mod_use!(derivation_info);
91mod_use!(incremental_witness);
92mod_use!(indexed);
93mod_use!(memo);
94mod_use!(mnemonic_language);
95mod_use!(network);
96mod_use!(non_hardened_child_index);
97mod_use!(protocol_address);
98mod_use!(script);
99mod_use!(legacy_seed);
100mod_use!(seed_material);
101mod_use!(seed_fingerprint);
102mod_use!(string_utils);
103mod_use!(transaction);
104mod_use!(tx_block_position);
105mod_use!(txid);
106mod_use!(unified_address);
107mod_use!(zewif_envelope);
108mod_use!(zewif_impl);
109mod_use!(zewif_wallet);
110
111pub use blob::HexParseError;
112use std::fmt::{self, Debug, Display, Formatter};
113
114#[doc(hidden)]
115pub struct NoQuotesDebugOption<'a, T>(pub &'a Option<T>);
116
117impl<T: Display> Debug for NoQuotesDebugOption<'_, T> {
118 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
119 match self.0 {
120 Some(val) => write!(f, "Some({})", val),
121 None => write!(f, "None"),
122 }
123 }
124}
125
126#[doc(hidden)]
127pub struct DebugOption<'a, T>(&'a Option<T>);
128
129impl<T: Debug> Debug for DebugOption<'_, T> {
130 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
131 match self.0 {
132 Some(val) => write!(f, "Some({:?})", val),
133 None => write!(f, "None"),
134 }
135 }
136}