Struct HDKey

Source
pub struct HDKey {
    pub master_seed: Seed,
    pub derivation_path: HDPath,
    pub derivation_purpose: HDPurpose,
    pub chain_code: [u8; 32],
    pub depth: u8,
    pub parent_fingerprint: [u8; 4],
    pub extended_private_key: Option<ExtendedPrivateKey>,
    pub extended_public_key: Option<ExtendedPublicKey>,
    pub child_index: u32,
    pub network: HDNetworkType,
}
Expand description

Represents a master or a derived child HD (Hierarchical Deterministic) key.

The HDKey struct contains detailed information about a master node or derived child node HD key and provides methods to create and derive HD keys.

HDKey follows the BIP32 scheme: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki HDKey also follows the purpose scheme described in BIP43: https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki The HDPurpose enum supports the following purpose types: BIP32, BIP44, BIP49, and BIP84.

Fields§

§master_seed: Seed

The seed used to create the master node

§derivation_path: HDPath

The derivation path of the HDKey

§derivation_purpose: HDPurpose

The derivation purpose associated with the HDKey

§chain_code: [u8; 32]

The chain code

§depth: u8

The depth used

§parent_fingerprint: [u8; 4]

The fingerprint of the parent key

§extended_private_key: Option<ExtendedPrivateKey>

The extended private key

§extended_public_key: Option<ExtendedPublicKey>

The extended public key

§child_index: u32

The child index value

§network: HDNetworkType

The network type

Implementations§

Source§

impl HDKey

Source

pub fn new_master( seed: Seed, network_type: HDNetworkType, ) -> Result<HDKey, Error>

Create new master node for a HD wallet based on a seed

Follows the method described in BIP32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki to convert the seed to the master node extended private and public keys Multiple purpose types can be derived from the master node using the HDPurpose type

If this function encounters an error, it will return an Error type. this can happen if the seed is invalid or an error is encountered when specifying the extended private key and extended public key

Source

pub fn new( seed: Seed, network_type: HDNetworkType, derivation_path: &str, ) -> Result<HDKey, Error>

Returns a new HDKey from a seed (Seed), network type (HDNetworkType) and derivation path string.

The HDKey returned will be the child key derived from the master node specified from the seed using the derivation path.

Returns an Error with further details if the seed is invalid or the derivation path is invalid

Source

pub fn derive(&self, derivation_path: &str) -> Result<HDKey, Error>

Derives and returns a HDKey following the specified derivation path from the HDKey given as the self parameter as the parent key.

Source

pub fn to_wif(&self) -> Result<String, Error>

Convert the ExtendedPrivateKey associated with the HDKey to a Wallet Import Format (WIF). Using wallet import format: https://en.bitcoin.it/wiki/Wallet_import_format Returns an Error if the extended private key is missing or another error is encountered.

Source

pub fn extended_private_key(&self) -> Result<ExtendedPrivateKey, Error>

Returns the extended private key

Returns an error if the extended private key is missing

Source

pub fn extended_public_key(&self) -> Result<ExtendedPublicKey, Error>

Returns the extended public key

Returns an error if the extended public key is missing

Source

pub fn master_seed(&self) -> Seed

Returns the master seed

Source

pub fn derivation_path(&self) -> HDPath

Returns the derivation path

Source

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

Returns the chain code

Source

pub fn depth(&self) -> u8

Returns the depth

Source

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

Returns the parent fingerprint

Source

pub fn child_index(&self) -> u32

Returns the child index

Source

pub fn network(&self) -> HDNetworkType

Returns the network associated with the HD Key

Source

pub fn extended_private_key_serialized(&self) -> Result<String, Error>

Extended Private Key Serialization

Source

pub fn extended_public_key_serialized(&self) -> Result<String, Error>

Extended Public Key Serialization

Trait Implementations§

Source§

impl Clone for HDKey

Source§

fn clone(&self) -> HDKey

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for HDKey

Source§

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

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

impl PartialEq for HDKey

Source§

fn eq(&self, other: &HDKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for HDKey

Source§

impl StructuralPartialEq for HDKey

Auto Trait Implementations§

§

impl Freeze for HDKey

§

impl RefUnwindSafe for HDKey

§

impl Send for HDKey

§

impl Sync for HDKey

§

impl Unpin for HDKey

§

impl UnwindSafe for HDKey

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,