Skip to main content

ExtendedPrivateKey

Struct ExtendedPrivateKey 

Source
pub struct ExtendedPrivateKey { /* private fields */ }
Expand description

A BIP-32 extended private key (key + chain code).

Implementations§

Source§

impl ExtendedPrivateKey

Source

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.

Source

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).

Source

pub fn derive_path(&self, path: &DerivationPath) -> Result<Self, SignerError>

Derive a child key following a full derivation path.

Source

pub fn private_key_bytes(&self) -> Zeroizing<Vec<u8>>

Get the raw 32-byte private key.

Source

pub fn public_key_bytes(&self) -> Result<Vec<u8>, SignerError>

Get the compressed public key (33 bytes).

Source

pub fn depth(&self) -> u8

Get the current derivation depth (0 = master).

Source

pub fn chain_code(&self) -> &[u8; 32]

Get the chain code (useful for extended public key export).

Source

pub fn parent_fingerprint(&self) -> &[u8; 4]

Get the parent key fingerprint (4 bytes).

Source

pub fn child_index(&self) -> u32

Get the child index used in this key’s derivation.

Source

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.

Source

pub fn to_xpub(&self) -> Result<String, SignerError>

Serialize the public key as an xpub Base58Check string (BIP-32).

Source

pub fn from_xprv(xprv: &str) -> Result<Self, SignerError>

Deserialize an xprv Base58Check string back into an extended private key.

Source

pub fn to_extended_public_key(&self) -> Result<ExtendedPublicKey, SignerError>

Convert to an ExtendedPublicKey for watch-only derivation.

Trait Implementations§

Source§

impl Drop for ExtendedPrivateKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.