Struct XPrv

Source
pub struct XPrv(/* private fields */);
Expand description

HDWallet extended private key

Effectively this is an ed25519 extended secret key (64 bytes) followed by a chain code (32 bytes).

Implementations§

Source§

impl XPrv

Source

pub fn normalize_bytes_force3rd(bytes: [u8; 96]) -> Self

takes the given raw bytes and perform some modifications to normalize to a valid Ed25519 extended key, but it does also force the 3rd highest bit to be cleared too.

Source

pub fn normalize_bytes_ed25519(bytes: [u8; 96]) -> Self

Takes the given raw bytes and perform some modifications to normalize to a valid Ed25519 extended key. It doesn’t touch the 3rd highest bit as expected in the ed25519-bip32 paper.

Source

pub fn is_3rd_highest_bit_clear(&self) -> bool

Check if the 3rd highest bit is clear as expected from the paper

Source

pub fn clear_3rd_highest_bit(self) -> Self

Clear the 3rd highest bit as expected from the paper setting

Source

pub fn from_nonextended_force(bytes: &[u8; 32], chain_code: &[u8; 32]) -> Self

Takes a non-extended Ed25519 secret key and hash through SHA512 it in the same way the standard Ed25519 signature system make extended key, but also force clear the 3rd highest bit of the key instead of returning an error

Source

pub fn from_nonextended_noforce( bytes: &[u8; 32], chain_code: &[u8; 32], ) -> Result<Self, ()>

Takes a non-extended Ed25519 secret key and hash through SHA512 it in the same way the standard Ed25519 signature system make extended key. If the 3rd highest bit is set, then return an error

bip32-ed25519 paper:

“2) We admit only those ~k such that the third highest bit of the last byte of kL is zero.”

Source

pub fn from_extended_and_chaincode(sk: &[u8; 64], chain_code: &[u8; 32]) -> Self

create a XPrv by its components (a 64 bytes extended secret key, and a 32 bytes chain code)

No verification is done on the extended secret key

Source

pub fn from_bytes_verified(bytes: [u8; 96]) -> Result<Self, PrivateKeyError>

Create a XPrv by taking ownership of the given array

This function may returns an error if it does not have the expected format.

This function allow the 3rd highest bit to not be clear (to handle potential derived valid xprv), but self.is_3rd_highest_bit_clear() can be called to check if the 3rd highest bit is assumed to be clear or not.

Source

pub fn from_slice_verified(bytes: &[u8]) -> Result<Self, PrivateKeyError>

Source

pub fn public(&self) -> XPub

Get the associated XPub

Source

pub fn sign<T>(&self, message: &[u8]) -> Signature<T>

sign the given message with the XPrv.

Source

pub fn verify<T>(&self, message: &[u8], signature: &Signature<T>) -> bool

verify a given signature

Source

pub fn derive(&self, scheme: DerivationScheme, index: DerivationIndex) -> Self

Source

pub fn get_extended_mut(&self, out: &mut [u8; 64])

Source

pub fn extended_secret_key_bytes(&self) -> &[u8; 64]

Source

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

Source

pub fn chain_code(&self) -> &[u8; 32]

Source

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

Source

pub fn extended_secret_key(&self) -> [u8; 64]

Trait Implementations§

Source§

impl AsRef<[u8]> for XPrv

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for XPrv

Source§

fn clone(&self) -> Self

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 XPrv

Source§

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

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

impl Display for XPrv

Source§

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

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

impl Drop for XPrv

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<XPrv> for [u8; 96]

Source§

fn from(v: XPrv) -> [u8; 96]

Converts to this type from the input type.
Source§

impl PartialEq for XPrv

Source§

fn eq(&self, rhs: &XPrv) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for XPrv

Auto Trait Implementations§

§

impl Freeze for XPrv

§

impl RefUnwindSafe for XPrv

§

impl Send for XPrv

§

impl Sync for XPrv

§

impl Unpin for XPrv

§

impl UnwindSafe for XPrv

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.