pub trait HdWallet<E: Curve>: DeriveShift<E> {
// Provided methods
fn derive_child_public_key(
parent_public_key: &ExtendedPublicKey<E>,
child_index: NonHardenedIndex,
) -> ExtendedPublicKey<E> { ... }
fn derive_child_key_pair(
parent_key: &ExtendedKeyPair<E>,
child_index: impl Into<ChildIndex>,
) -> ExtendedKeyPair<E> { ... }
fn try_derive_child_key_pair_with_path<Err>(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = Result<impl Into<ChildIndex>, Err>>,
) -> Result<ExtendedKeyPair<E>, Err> { ... }
fn derive_child_key_pair_with_path(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = impl Into<ChildIndex>>,
) -> ExtendedKeyPair<E> { ... }
fn try_derive_child_public_key_with_path<Err>(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = Result<NonHardenedIndex, Err>>,
) -> Result<ExtendedPublicKey<E>, Err> { ... }
fn derive_child_public_key_with_path(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = NonHardenedIndex>,
) -> ExtendedPublicKey<E> { ... }
}
Expand description
HD derivation
Provided Methods§
Sourcefn derive_child_public_key(
parent_public_key: &ExtendedPublicKey<E>,
child_index: NonHardenedIndex,
) -> ExtendedPublicKey<E>
fn derive_child_public_key( parent_public_key: &ExtendedPublicKey<E>, child_index: NonHardenedIndex, ) -> ExtendedPublicKey<E>
Derives child extended public key from parent extended public key
§Example
Derive a master public key m/1
use hd_wallet::HdWallet;
let derived_key = hd_wallet::Slip10::derive_child_public_key(
&master_public_key,
1.try_into()?,
);
Sourcefn derive_child_key_pair(
parent_key: &ExtendedKeyPair<E>,
child_index: impl Into<ChildIndex>,
) -> ExtendedKeyPair<E>
fn derive_child_key_pair( parent_key: &ExtendedKeyPair<E>, child_index: impl Into<ChildIndex>, ) -> ExtendedKeyPair<E>
Derives child key pair (extended secret key + public key) from parent key pair
§Example
Derive child key m/1H from master key
use hd_wallet::HdWallet;
let derived_key = hd_wallet::Slip10::derive_child_key_pair(
&master_key_pair,
1 + hd_wallet::H,
);
Sourcefn try_derive_child_key_pair_with_path<Err>(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = Result<impl Into<ChildIndex>, Err>>,
) -> Result<ExtendedKeyPair<E>, Err>
fn try_derive_child_key_pair_with_path<Err>( parent_key: &ExtendedKeyPair<E>, path: impl IntoIterator<Item = Result<impl Into<ChildIndex>, Err>>, ) -> Result<ExtendedKeyPair<E>, Err>
Derives a child key pair with specified derivation path from parent key pair
Derivation path is a fallible iterator that yields child indexes. If iterator yields an error, it’s propagated to the caller.
Returns:
Ok(child_key_pair)
if derivation was successfulErr(index_err)
if path containedErr(index_err)
§Example
Parse a path from the string and derive a child without extra allocations:
use hd_wallet::HdWallet;
let path = "1/10/2";
let child_indexes = path.split('/').map(str::parse::<u32>);
let child_key = hd_wallet::Slip10::try_derive_child_key_pair_with_path(
&master_key_pair,
child_indexes,
)?;
Sourcefn derive_child_key_pair_with_path(
parent_key: &ExtendedKeyPair<E>,
path: impl IntoIterator<Item = impl Into<ChildIndex>>,
) -> ExtendedKeyPair<E>
fn derive_child_key_pair_with_path( parent_key: &ExtendedKeyPair<E>, path: impl IntoIterator<Item = impl Into<ChildIndex>>, ) -> ExtendedKeyPair<E>
Derives a child key pair with specified derivation path from parent key pair
Derivation path is an iterator that yields child indexes.
If derivation path is empty, parent_key
is returned
§Example
Derive a child key with path m/1/10/1H
use hd_wallet::HdWallet;
let child_key = hd_wallet::Slip10::derive_child_key_pair_with_path(
&master_key_pair,
[1, 10, 1 + hd_wallet::H],
);
Sourcefn try_derive_child_public_key_with_path<Err>(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = Result<NonHardenedIndex, Err>>,
) -> Result<ExtendedPublicKey<E>, Err>
fn try_derive_child_public_key_with_path<Err>( parent_public_key: &ExtendedPublicKey<E>, path: impl IntoIterator<Item = Result<NonHardenedIndex, Err>>, ) -> Result<ExtendedPublicKey<E>, Err>
Derives a child public key with specified derivation path
Derivation path is a fallible iterator that yields child indexes. If iterator yields an error, it’s propagated to the caller.
Returns:
Ok(child_pk)
if derivation was successfulErr(index_err)
if path containedErr(index_err)
§Example
Parse a path from the string and derive a child without extra allocations:
use hd_wallet::HdWallet;
let path = "1/10/2";
let child_indexes = path.split('/').map(str::parse);
let child_key = hd_wallet::Slip10::try_derive_child_public_key_with_path(
&master_public_key,
child_indexes,
)?;
Sourcefn derive_child_public_key_with_path(
parent_public_key: &ExtendedPublicKey<E>,
path: impl IntoIterator<Item = NonHardenedIndex>,
) -> ExtendedPublicKey<E>
fn derive_child_public_key_with_path( parent_public_key: &ExtendedPublicKey<E>, path: impl IntoIterator<Item = NonHardenedIndex>, ) -> ExtendedPublicKey<E>
Derives a child public key with specified derivation path
Derivation path is an iterator that yields child indexes.
If derivation path is empty, parent_public_key
is returned
§Example
Derive a child key with path m/1/10
use hd_wallet::HdWallet;
let child_key = hd_wallet::Slip10::derive_child_public_key_with_path(
&master_public_key,
[1.try_into()?, 10.try_into()?],
);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.