DerivationStandard

Trait DerivationStandard 

Source
pub trait DerivationStandard: Eq + Clone {
    // Required methods
    fn deduce(derivation: &DerivationPath) -> Option<Self>
       where Self: Sized;
    fn purpose(&self) -> Option<HardenedIndex>;
    fn account_depth(&self) -> Option<u8>;
    fn coin_type_depth(&self) -> Option<u8>;
    fn is_account_last_hardened(&self) -> Option<bool>;
    fn is_testnet(
        &self,
        path: &DerivationPath,
    ) -> Result<bool, Option<DerivationIndex>>;
    fn account_template_string(&self, testnet: bool) -> String;
    fn to_origin_derivation(
        &self,
        testnet: bool,
    ) -> DerivationPath<HardenedIndex>;
    fn to_account_derivation(
        &self,
        account_index: HardenedIndex,
        testnet: bool,
    ) -> DerivationPath<HardenedIndex>;
    fn to_key_derivation(
        &self,
        account_index: HardenedIndex,
        testnet: bool,
        keychain: NormalIndex,
        index: NormalIndex,
    ) -> DerivationPath;

    // Provided methods
    fn extract_coin_type(
        &self,
        path: &DerivationPath,
    ) -> Result<HardenedIndex, Option<NormalIndex>> { ... }
    fn extract_account_index(
        &self,
        path: &DerivationPath,
    ) -> Result<HardenedIndex, Option<NormalIndex>> { ... }
}
Expand description

Methods for derivation standard enumeration types.

Required Methods§

Source

fn deduce(derivation: &DerivationPath) -> Option<Self>
where Self: Sized,

Deduces derivation standard used by the provided derivation path, if possible.

Source

fn purpose(&self) -> Option<HardenedIndex>

Get hardened index matching BIP-43 purpose value, if any.

Source

fn account_depth(&self) -> Option<u8>

Depth of the account extended public key according to the given standard.

Returns None if the standard does not provide information on account-level xpubs.

Source

fn coin_type_depth(&self) -> Option<u8>

Depth of the derivation path defining coin_type key, i.e. the used blockchain.

Returns None if the standard does not provide information on blockchain/coin type.

Source

fn is_account_last_hardened(&self) -> Option<bool>

Returns information whether the account xpub in this standard is the last hardened derivation path step, or there might be more hardened steps (like script_type in BIP-48).

Returns None if the standard does not provide information on account-level xpubs.

Source

fn is_testnet( &self, path: &DerivationPath, ) -> Result<bool, Option<DerivationIndex>>

Checks which bitcoin network corresponds to a given derivation path according to the used standard requirements.

Source

fn account_template_string(&self, testnet: bool) -> String

Returns string representation of the template derivation path for an account-level keys. Account key is represented by * wildcard fragment.

Source

fn to_origin_derivation(&self, testnet: bool) -> DerivationPath<HardenedIndex>

Construct derivation path for the account xpub.

Source

fn to_account_derivation( &self, account_index: HardenedIndex, testnet: bool, ) -> DerivationPath<HardenedIndex>

Construct derivation path up to the provided account index segment.

Source

fn to_key_derivation( &self, account_index: HardenedIndex, testnet: bool, keychain: NormalIndex, index: NormalIndex, ) -> DerivationPath

Construct full derivation path including address index and case (main, change etc).

Provided Methods§

Source

fn extract_coin_type( &self, path: &DerivationPath, ) -> Result<HardenedIndex, Option<NormalIndex>>

Extracts hardened index from a derivation path position defining coin type information (used blockchain), if present.

§Returns
  • Err(None) error if the path doesn’t contain any coin index information;
  • Err(NormalIndex) error if the coin type in the derivation path was an unhardened index.
  • Ok(HardenedIndex) with the coin type index otherwise.
Source

fn extract_account_index( &self, path: &DerivationPath, ) -> Result<HardenedIndex, Option<NormalIndex>>

Extracts hardened index from a derivation path position defining account number, if present.

§Returns
  • Err(None) error if the path doesn’t contain any account number information;
  • Err(NormalIndex) error if the account number in the derivation path was an unhardened index.
  • Ok(HardenedIndex) with the account number otherwise.

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.

Implementors§