Struct slip132::KeyVersion

source ·
pub struct KeyVersion(/* private fields */);
Expand description

Structure holding 4 version bytes with magical numbers representing different versions of extended public and private keys according to BIP-32. Key version stores raw bytes without their check, interpretation or verification; for these purposes special helpers structures implementing VersionResolver are used.

Implementations§

source§

impl KeyVersion

source

pub fn is_pub<R: VersionResolver>(&self) -> Option<bool>

Detects whether provided version corresponds to an extended public key. Returns None if the version is not recognized/unknown to the resolver.

source

pub fn is_prv<R: VersionResolver>(&self) -> Option<bool>

Detects whether provided version corresponds to an extended private key. Returns None if the version is not recognized/unknown to the resolver.

source

pub fn network<R: VersionResolver>(&self) -> Option<R::Network>

Detects network used by the provided key version bytes. Returns None if the version is not recognized/unknown to the resolver.

source

pub fn application<R: VersionResolver>(&self) -> Option<R::Application>

Detects application scope defined by the provided key version bytes. Application scope is a types of scriptPubkey descriptors in which given extended public/private keys can be used. Returns None if the version is not recognized/unknown to the resolver.

source

pub fn derivation_path<R: VersionResolver>( &self, account: Option<ChildNumber> ) -> Option<DerivationPath>

Returns BIP 32 derivation path for the provided key version. Returns None if the version is not recognized/unknown to the resolver.

source

pub fn try_to_pub<R: VersionResolver>(&self) -> Option<KeyVersion>

Converts version into version corresponding to an extended public key. Returns None if the resolver does not know how to perform conversion.

source

pub fn try_to_prv<R: VersionResolver>(&self) -> Option<KeyVersion>

Converts version into version corresponding to an extended private key. Returns None if the resolver does not know how to perform conversion.

source§

impl KeyVersion

source

pub fn from_slice(version_slice: &[u8]) -> Option<KeyVersion>

Tries to construct KeyVersion object from a byte slice. If byte slice length is not equal to 4, returns None

source

pub fn from_xkey_str(key: &str) -> Result<KeyVersion, Error>

Constructs KeyVersion from a Base58-encoded extended key string.

§Panics

If the string does not contain at least 5 characters.

source

pub fn from_bytes(version_bytes: [u8; 4]) -> KeyVersion

Constructs KeyVersion from a fixed 4 bytes values

source

pub fn from_u32(version: u32) -> KeyVersion

Constructs KeyVersion from a u32-representation of the version bytes (the representation must be in bing endian format)

source

pub fn to_u32(&self) -> u32

Converts version bytes into u32 representation in big endian format

source

pub fn as_slice(&self) -> &[u8]

Returns slice representing internal version bytes

source

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

Returns internal representation of version bytes

source

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

Constructs 4-byte array containing version byte values

source

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

Converts into 4-byte array containing version byte values

Trait Implementations§

source§

impl Clone for KeyVersion

source§

fn clone(&self) -> KeyVersion

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for KeyVersion

source§

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

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

impl Hash for KeyVersion

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for KeyVersion

source§

fn cmp(&self, other: &KeyVersion) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for KeyVersion

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for KeyVersion

source§

fn partial_cmp(&self, other: &KeyVersion) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for KeyVersion

source§

impl Eq for KeyVersion

source§

impl StructuralPartialEq for KeyVersion

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.