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
impl KeyVersion
sourcepub fn is_pub<R: VersionResolver>(&self) -> Option<bool>
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.
sourcepub fn is_prv<R: VersionResolver>(&self) -> Option<bool>
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.
sourcepub fn network<R: VersionResolver>(&self) -> Option<R::Network>
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.
sourcepub fn application<R: VersionResolver>(&self) -> Option<R::Application>
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.
sourcepub fn derivation_path<R: VersionResolver>(
&self,
account: Option<ChildNumber>
) -> Option<DerivationPath>
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.
sourcepub fn try_to_pub<R: VersionResolver>(&self) -> Option<KeyVersion>
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.
sourcepub fn try_to_prv<R: VersionResolver>(&self) -> Option<KeyVersion>
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
impl KeyVersion
sourcepub fn from_slice(version_slice: &[u8]) -> Option<KeyVersion>
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
sourcepub fn from_xkey_str(key: &str) -> Result<KeyVersion, Error>
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.
sourcepub fn from_bytes(version_bytes: [u8; 4]) -> KeyVersion
pub fn from_bytes(version_bytes: [u8; 4]) -> KeyVersion
Constructs KeyVersion
from a fixed 4 bytes values
sourcepub fn from_u32(version: u32) -> KeyVersion
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)
sourcepub fn to_u32(&self) -> u32
pub fn to_u32(&self) -> u32
Converts version bytes into u32
representation in big endian format
sourcepub fn into_bytes(self) -> [u8; 4]
pub fn into_bytes(self) -> [u8; 4]
Converts into 4-byte array containing version byte values
Trait Implementations§
source§impl Clone for KeyVersion
impl Clone for KeyVersion
source§fn clone(&self) -> KeyVersion
fn clone(&self) -> KeyVersion
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for KeyVersion
impl Debug for KeyVersion
source§impl Hash for KeyVersion
impl Hash for KeyVersion
source§impl Ord for KeyVersion
impl Ord for KeyVersion
source§fn cmp(&self, other: &KeyVersion) -> Ordering
fn cmp(&self, other: &KeyVersion) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for KeyVersion
impl PartialEq for KeyVersion
source§fn eq(&self, other: &KeyVersion) -> bool
fn eq(&self, other: &KeyVersion) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for KeyVersion
impl PartialOrd for KeyVersion
source§fn partial_cmp(&self, other: &KeyVersion) -> Option<Ordering>
fn partial_cmp(&self, other: &KeyVersion) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more