pub struct ExtendedPrivateKey { /* private fields */ }Expand description
Extended private key (BIP32).
Contains a private key and chain code for hierarchical derivation.
§Example
use rustywallet_hd::{ExtendedPrivateKey, DerivationPath, Network};
// Create from seed (typically from mnemonic)
let seed = [0u8; 64];
let master = ExtendedPrivateKey::from_seed(&seed, Network::Mainnet).unwrap();
// Derive child key
let path = DerivationPath::parse("m/44'/0'/0'/0/0").unwrap();
let child = master.derive_path(&path).unwrap();
// Export as xprv
let xprv = child.to_xprv();Implementations§
Source§impl ExtendedPrivateKey
impl ExtendedPrivateKey
Sourcepub fn from_seed(seed: &[u8], network: Network) -> Result<Self, HdError>
pub fn from_seed(seed: &[u8], network: Network) -> Result<Self, HdError>
Create master extended private key from seed.
The seed should be 64 bytes (typically from BIP39 mnemonic).
Sourcepub fn derive_child(&self, index: u32) -> Result<Self, HdError>
pub fn derive_child(&self, index: u32) -> Result<Self, HdError>
Derive child extended private key at index.
For hardened derivation, use index >= 0x80000000 or use derive_hardened.
Sourcepub fn derive_hardened(&self, index: u32) -> Result<Self, HdError>
pub fn derive_hardened(&self, index: u32) -> Result<Self, HdError>
Derive hardened child at index (adds 0x80000000 to index).
Sourcepub fn derive_path(&self, path: &DerivationPath) -> Result<Self, HdError>
pub fn derive_path(&self, path: &DerivationPath) -> Result<Self, HdError>
Derive key at derivation path.
Sourcepub fn extended_public_key(&self) -> ExtendedPublicKey
pub fn extended_public_key(&self) -> ExtendedPublicKey
Get the extended public key.
Sourcepub fn private_key(&self) -> Result<PrivateKey, HdError>
pub fn private_key(&self) -> Result<PrivateKey, HdError>
Get the underlying private key.
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Get the underlying public key.
Sourcepub fn fingerprint(&self) -> [u8; 4]
pub fn fingerprint(&self) -> [u8; 4]
Get fingerprint (first 4 bytes of HASH160 of public key).
Sourcepub fn chain_code(&self) -> &[u8; 32]
pub fn chain_code(&self) -> &[u8; 32]
Get chain code.
Trait Implementations§
Source§impl Clone for ExtendedPrivateKey
impl Clone for ExtendedPrivateKey
Source§impl Debug for ExtendedPrivateKey
impl Debug for ExtendedPrivateKey
Source§impl Display for ExtendedPrivateKey
impl Display for ExtendedPrivateKey
Auto Trait Implementations§
impl Freeze for ExtendedPrivateKey
impl RefUnwindSafe for ExtendedPrivateKey
impl Send for ExtendedPrivateKey
impl Sync for ExtendedPrivateKey
impl Unpin for ExtendedPrivateKey
impl UnwindSafe for ExtendedPrivateKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more