pub trait DerivedKey {
    // Required method
    fn derivation(&self) -> &KeyDerivation;

    // Provided methods
    fn same_root<K: DerivedKey>(&self, other: &K) -> bool { ... }
    fn is_possible_ancestor_of<K: DerivedKey>(&self, other: &K) -> bool { ... }
    fn path_to_descendant<K: DerivedKey>(
        &self,
        other: &K
    ) -> Option<DerivationPath> { ... }
}
Expand description

Derived keys are keys coupled with their derivation. We use this trait to check ancestry relationships between keys.

Required Methods§

source

fn derivation(&self) -> &KeyDerivation

Return this key’s derivation

Provided Methods§

source

fn same_root<K: DerivedKey>(&self, other: &K) -> bool

true if the keys share a root fingerprint, false otherwise. Note that on key fingerprints, which may collide accidentally, or be intentionally collided.

source

fn is_possible_ancestor_of<K: DerivedKey>(&self, other: &K) -> bool

true if this key is a possible ancestor of the argument, false otherwise.

Warning: this check is cheap, but imprecise. It simply compares the root fingerprints (which may collide) and checks that self.path is a prefix of other.path. This may be deliberately foold by an attacker. For a precise check, use DerivedXPriv::is_private_ancestor_of() or DerivedXPub::is_public_ancestor_of()

source

fn path_to_descendant<K: DerivedKey>(&self, other: &K) -> Option<DerivationPath>

Returns the path to the descendant, or None if the argument is definitely not a descendant.

This is useful for determining the path to reach some descendant from some ancestor.

Implementors§