rustywallet_hd/lib.rs
1//! # rustywallet-hd
2//!
3//! BIP32/BIP44/BIP85 Hierarchical Deterministic wallet for cryptocurrency key derivation.
4//!
5//! This crate provides functionality to:
6//! - Create master keys from seeds
7//! - Derive child keys using BIP32 derivation
8//! - Support BIP44 standard paths
9//! - Export/import extended keys (xprv/xpub)
10//! - BIP85 deterministic entropy derivation
11//!
12//! ## Example
13//!
14//! ```
15//! use rustywallet_hd::prelude::*;
16//!
17//! // Create master key from seed (64 bytes, typically from mnemonic)
18//! let seed = [0u8; 64];
19//! let master = ExtendedPrivateKey::from_seed(&seed, Network::Mainnet).unwrap();
20//!
21//! // Derive BIP44 Bitcoin path: m/44'/0'/0'/0/0
22//! let path = DerivationPath::bip44_bitcoin(0, 0, 0);
23//! let child = master.derive_path(&path).unwrap();
24//!
25//! // Get keys
26//! let private_key = child.private_key().unwrap();
27//! let public_key = child.public_key();
28//!
29//! // Export as xprv/xpub
30//! let xprv = child.to_xprv();
31//! let xpub = child.extended_public_key().to_xpub();
32//! ```
33//!
34//! ## BIP85 - Deterministic Entropy
35//!
36//! ```
37//! use rustywallet_hd::{ExtendedPrivateKey, Network, Bip85, derive_bip85_mnemonic};
38//!
39//! let seed = [0u8; 64];
40//! let master = ExtendedPrivateKey::from_seed(&seed, Network::Mainnet).unwrap();
41//!
42//! // Derive child mnemonic entropy (12 words, index 0)
43//! let entropy = derive_bip85_mnemonic(&master, 12, 0).unwrap();
44//! assert_eq!(entropy.len(), 16); // 128 bits for 12 words
45//!
46//! // Or use Bip85 struct for more options
47//! let bip85 = Bip85::new(master.clone());
48//! let child_master = bip85.derive_child_master(0, Network::Mainnet).unwrap();
49//! ```
50//!
51//! ## BIP44 Paths
52//!
53//! ```text
54//! m / purpose' / coin_type' / account' / change / address_index
55//!
56//! Bitcoin: m/44'/0'/0'/0/0
57//! Ethereum: m/44'/60'/0'/0/0
58//! ```
59//!
60//! ## Security
61//!
62//! - Private keys and chain codes are zeroized on drop
63//! - Debug output masks sensitive data
64//! - Hardened derivation prevents public key derivation
65
66pub mod error;
67pub mod extended_key;
68pub mod network;
69pub mod path;
70pub mod prelude;
71pub mod bip85;
72
73pub use error::HdError;
74pub use extended_key::{ExtendedPrivateKey, ExtendedPublicKey};
75pub use network::Network;
76pub use path::{ChildNumber, DerivationPath};
77pub use bip85::{Bip85, derive_bip85_mnemonic, derive_bip85_master, app as bip85_app, language as bip85_language};