rustywallet-hd
BIP32/BIP44 Hierarchical Deterministic wallet implementation for cryptocurrency key derivation in Rust.
Features
- BIP32 Compliance: Full implementation of BIP32 hierarchical deterministic key derivation
- BIP44 Support: Standard derivation paths for multiple cryptocurrencies
- Master Key Generation: Create master keys from 64-byte seeds (typically from mnemonics)
- Child Key Derivation: Derive child keys using both normal and hardened derivation
- Extended Keys: Export/import extended keys (xprv/xpub, tprv/tpub) with Base58Check encoding
- Public Key Derivation: Derive public keys from extended public keys (non-hardened paths only)
- Network Support: Mainnet and testnet key generation
- Security: Secure memory handling with automatic zeroization on drop
- No-std Compatible: Works in embedded environments (with
no-stdfeature)
Installation
Add this to your Cargo.toml:
[]
= "0.1"
For no-std environments:
[]
= { = "0.1", = false }
Quick Start
use *;
// Create master key from seed (64 bytes, typically from mnemonic)
let seed = ;
let master = from_seed?;
// Derive BIP44 Bitcoin path: m/44'/0'/0'/0/0
let path = bip44_bitcoin;
let child = master.derive_path?;
// Get keys
let private_key = child.private_key?;
let public_key = child.public_key;
// Export as xprv/xpub
let xprv = child.to_xprv;
let xpub = child.extended_public_key.to_xpub;
Master Key Derivation
Create master keys from seeds generated by mnemonic phrases:
use *;
// From 64-byte seed (typically from BIP39 mnemonic)
let seed = ; // Replace with actual seed
let master = from_seed?;
// Master key properties
println!;
println!;
Child Key Derivation
Derive child keys using BIP32 derivation:
use *;
let master = from_seed?;
// Single derivation step
let child = master.derive_child?;
// Multi-step derivation
let path = from_str?;
let account_key = master.derive_path?;
// Hardened vs normal derivation
let hardened = master.derive_child?; // m/0'
let normal = master.derive_child?; // m/0
Derivation Paths (BIP32/BIP44)
BIP32 Path Format
m / level1 / level2 / level3 / level4 / level5
m: Master key'(apostrophe): Indicates hardened derivation- Numbers: Child key indices
BIP44 Standard Paths
m / purpose' / coin_type' / account' / change / address_index
Purpose: 44' (BIP44)
Coin Types:
- Bitcoin: 0'
- Ethereum: 60'
- Litecoin: 2'
Helper Methods
use *;
// Bitcoin paths
let btc_account = bip44_bitcoin; // m/44'/0'/0'/0/0
let btc_change = bip44_bitcoin; // m/44'/0'/0'/1/0
// Ethereum paths
let eth_path = bip44_ethereum; // m/44'/60'/0'/0/0
// Custom paths
let custom = from_str?;
Extended Keys (xpub/xprv)
Private Extended Keys (xprv)
use *;
let master = from_seed?;
// Export as xprv string
let xprv_string = master.to_xprv;
println!;
// Import from xprv string
let imported = from_xprv?;
Public Extended Keys (xpub)
use *;
let master = from_seed?;
let xpub = master.extended_public_key;
// Export as xpub string
let xpub_string = xpub.to_xpub;
println!;
// Import from xpub string
let imported_xpub = from_xpub?;
// Derive public keys (non-hardened only)
let child_pubkey = imported_xpub.derive_child?;
Testnet Keys (tprv/tpub)
use *;
let master = from_seed?;
// Testnet keys use tprv/tpub prefixes
let tprv = master.to_xprv; // Returns tprv... for testnet
let tpub = master.extended_public_key.to_xpub; // Returns tpub... for testnet
API Reference
Core Types
ExtendedPrivateKey
ExtendedPublicKey
DerivationPath
ChildNumber
Integration with rustywallet-mnemonic
use *;
use *;
// Generate mnemonic
let mnemonic = generate;
// Get seed with optional passphrase
let seed = mnemonic.to_seed;
// Create HD wallet
let master = from_seed?;
// Derive Bitcoin account keys
let account_path = bip44_bitcoin;
let account_key = master.derive_path?;
// Generate multiple addresses
for i in 0..10
Security Considerations
- Memory Safety: Private keys and chain codes are automatically zeroized when dropped
- Debug Protection: Sensitive data is masked in debug output
- Hardened Derivation: Use hardened paths for account-level keys to prevent key leakage
- Seed Entropy: Always use cryptographically secure random seeds (64 bytes from BIP39)
- Key Storage: Never store private keys in plain text; use secure key management
License
Licensed under the MIT License. See LICENSE for details.