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: SeedThe seed used to create the master node
derivation_path: HDPathThe derivation path of the HDKey
derivation_purpose: HDPurposeThe derivation purpose associated with the HDKey
chain_code: [u8; 32]The chain code
depth: u8The 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: u32The child index value
network: HDNetworkTypeThe network type
Implementations§
Source§impl HDKey
impl HDKey
Sourcepub fn new_master(
seed: Seed,
network_type: HDNetworkType,
) -> Result<HDKey, Error>
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
Sourcepub fn new(
seed: Seed,
network_type: HDNetworkType,
derivation_path: &str,
) -> Result<HDKey, Error>
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
Sourcepub fn to_wif(&self) -> Result<String, Error>
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.
Sourcepub fn extended_private_key(&self) -> Result<ExtendedPrivateKey, Error>
pub fn extended_private_key(&self) -> Result<ExtendedPrivateKey, Error>
Returns the extended private key
Returns an error if the extended private key is missing
Sourcepub fn extended_public_key(&self) -> Result<ExtendedPublicKey, Error>
pub fn extended_public_key(&self) -> Result<ExtendedPublicKey, Error>
Returns the extended public key
Returns an error if the extended public key is missing
Sourcepub fn master_seed(&self) -> Seed
pub fn master_seed(&self) -> Seed
Returns the master seed
Sourcepub fn derivation_path(&self) -> HDPath
pub fn derivation_path(&self) -> HDPath
Returns the derivation path
Sourcepub fn chain_code(&self) -> [u8; 32]
pub fn chain_code(&self) -> [u8; 32]
Returns the chain code
Sourcepub fn parent_fingerprint(&self) -> [u8; 4]
pub fn parent_fingerprint(&self) -> [u8; 4]
Returns the parent fingerprint
Sourcepub fn child_index(&self) -> u32
pub fn child_index(&self) -> u32
Returns the child index
Sourcepub fn network(&self) -> HDNetworkType
pub fn network(&self) -> HDNetworkType
Returns the network associated with the HD Key
Sourcepub fn extended_private_key_serialized(&self) -> Result<String, Error>
pub fn extended_private_key_serialized(&self) -> Result<String, Error>
Extended Private Key Serialization
Sourcepub fn extended_public_key_serialized(&self) -> Result<String, Error>
pub fn extended_public_key_serialized(&self) -> Result<String, Error>
Extended Public Key Serialization
Trait Implementations§
impl Eq for HDKey
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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