pub struct ExtendedPrivateKey { /* private fields */ }Expand description
A BIP-32 extended private key (key + chain code).
Implementations§
Source§impl ExtendedPrivateKey
impl ExtendedPrivateKey
Sourcepub fn from_seed(seed: &[u8]) -> Result<Self, SignerError>
pub fn from_seed(seed: &[u8]) -> Result<Self, SignerError>
Derive the master key from a BIP-39 seed (typically 16–64 bytes).
Computes HMAC-SHA512("Bitcoin seed", seed).
Left 32 bytes = private key, right 32 bytes = chain code.
Sourcepub fn derive_child(
&self,
index: u32,
hardened: bool,
) -> Result<Self, SignerError>
pub fn derive_child( &self, index: u32, hardened: bool, ) -> Result<Self, SignerError>
Derive a child key at the given index.
If hardened is true, uses hardened derivation (index + 0x80000000).
Sourcepub fn derive_path(&self, path: &DerivationPath) -> Result<Self, SignerError>
pub fn derive_path(&self, path: &DerivationPath) -> Result<Self, SignerError>
Derive a child key following a full derivation path.
Sourcepub fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
pub fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>
Get the raw 32-byte private key.
Sourcepub fn public_key_bytes(&self) -> Result<Vec<u8>, SignerError>
pub fn public_key_bytes(&self) -> Result<Vec<u8>, SignerError>
Get the compressed public key (33 bytes).
Sourcepub fn chain_code(&self) -> &[u8; 32]
pub fn chain_code(&self) -> &[u8; 32]
Get the chain code (useful for extended public key export).
Sourcepub fn parent_fingerprint(&self) -> &[u8; 4]
pub fn parent_fingerprint(&self) -> &[u8; 4]
Get the parent key fingerprint (4 bytes).
Sourcepub fn child_index(&self) -> u32
pub fn child_index(&self) -> u32
Get the child index used in this key’s derivation.
Sourcepub fn to_xprv(&self) -> Zeroizing<String>
pub fn to_xprv(&self) -> Zeroizing<String>
Serialize as an xprv Base58Check string (BIP-32).
Format: 4 bytes version || 1 byte depth || 4 bytes fingerprint || 4 bytes child index || 32 bytes chain code || 1 byte 0x00 || 32 bytes key
§Security
The returned String contains the private key — handle with care.
Sourcepub fn to_xpub(&self) -> Result<String, SignerError>
pub fn to_xpub(&self) -> Result<String, SignerError>
Serialize the public key as an xpub Base58Check string (BIP-32).
Sourcepub fn from_xprv(xprv: &str) -> Result<Self, SignerError>
pub fn from_xprv(xprv: &str) -> Result<Self, SignerError>
Deserialize an xprv Base58Check string back into an extended private key.
Sourcepub fn to_extended_public_key(&self) -> Result<ExtendedPublicKey, SignerError>
pub fn to_extended_public_key(&self) -> Result<ExtendedPublicKey, SignerError>
Convert to an ExtendedPublicKey for watch-only derivation.