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