Skip to main content

ExtendedKey

Struct ExtendedKey 

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

A BIP32 extended key (private or public) with chain code and derivation metadata.

Supports key derivation, serialization to/from Base58Check xprv/xpub strings, and conversion between private and public extended keys.

Implementations§

Source§

impl ExtendedKey

Source

pub fn from_seed(seed: &[u8]) -> Result<Self, CompatError>

Derive a master extended key from a seed.

Uses HMAC-SHA512 with key “Bitcoin seed” per BIP32 specification. Seed must be between 16 and 64 bytes (128-512 bits).

Source

pub fn derive(&self, path: &str) -> Result<Self, CompatError>

Derive a child extended key by path string.

Path format: “m/0’/1/2’” where apostrophe or “h” suffix means hardened. Leading “m/” or “m” prefix is stripped.

Source

pub fn derive_child(&self, index: u32) -> Result<Self, CompatError>

Derive a single child key by index.

Index >= 0x80000000 is hardened derivation (requires private key). Index < 0x80000000 is normal derivation (works with public key).

Source

pub fn to_public(&self) -> Result<Self, CompatError>

Convert a private extended key to its public counterpart.

Returns a new ExtendedKey with the public key and xpub version bytes.

Source

pub fn to_base58(&self) -> String

Serialize to a Base58Check string (xprv or xpub).

78-byte payload: version(4) || depth(1) || fingerprint(4) || child_index(4) || chain_code(32) || key(33, with 0x00 prefix for private).

Source

pub fn from_string(s: &str) -> Result<Self, CompatError>

Parse an extended key from a Base58Check string (xprv or xpub).

Source

pub fn public_key(&self) -> Result<PublicKey, CompatError>

Get the public key for this extended key.

If private, derives the public key. If public, parses the stored key.

Source

pub fn is_private(&self) -> bool

Whether this is a private extended key.

Source

pub fn depth(&self) -> u8

Get the derivation depth.

Trait Implementations§

Source§

impl Clone for ExtendedKey

Source§

fn clone(&self) -> ExtendedKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExtendedKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ExtendedKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.