Struct thor_devkit::hdnode::HDNodeBuilder

source ·
pub struct HDNodeBuilder<'a> { /* private fields */ }
Expand description

Builder for HDNode: use this to construct a node from different sources.

The following sources are supported:

  • Binary seed. 64 bytes of raw entropy to use for key generation.
  • BIP39 mnemonic with optional password. This method is compatible with derivation in Sync2 wallet.
  • Master private key bytes and chain code
  • Extended private key
  • Master public key bytes and chain code
  • Extended public key

First two methods accept a derivation path to use (defaults to VeChain path).

For example, here’s what you could do:

use thor_devkit::hdnode::{Mnemonic, Language, HDNode};
use rand::RngCore;
use rand::rngs::OsRng;

let mnemonic = Mnemonic::from_phrase(
    "ignore empty bird silly journey junior ripple have guard waste between tenant",
    Language::English,
)
.expect("Should be constructible");
let wallet = HDNode::build().mnemonic(mnemonic).build().expect("Must be buildable");
// OR
let mut entropy = [0u8; 64];
OsRng.fill_bytes(&mut entropy);
let other_wallet = HDNode::build().seed(entropy).build().expect("Must be buildable");

Implementations§

source§

impl<'a> HDNodeBuilder<'a>

source

pub fn path(self, path: DerivationPath) -> Self

Set a derivation path to use.

If not called, defaults to VET_EXTERNAL_PATH.

source

pub fn seed(self, seed: [u8; 64]) -> Self

Set a seed to use.

source

pub fn mnemonic(self, mnemonic: Mnemonic) -> Self

Set a mnemonic to use. You may optionally provide a password as well.

Derivation from mnemonic is compatible with Sync2 wallet (with empty password).

source

pub fn mnemonic_with_password( self, mnemonic: Mnemonic, password: &'a str ) -> Self

Set a password for the mnemonic to use.

Replaces previous mnemonic, if any.

source

pub fn master_private_key_bytes<T: Into<ChainCode>>( self, key: [u8; 33], chain_code: T ) -> Self

Create an HDNode from private key bytes and chain code.

source

pub fn private_key(self, ext_key: ExtendedKey) -> Self

Create an HDNode from extended private key structure.

source

pub fn master_public_key_bytes<T: Into<ChainCode>>( self, key: [u8; 33], chain_code: T ) -> Self

Create an HDNode from private key bytes and chain code.

Beware that this node cannot be used to derive new private keys.
source

pub fn public_key(self, ext_key: ExtendedKey) -> Self

Create an HDNode from extended public key structure.

Beware that this node cannot be used to derive new private keys.
source

pub fn build(self) -> Result<HDNode, HDNodeError>

Create an HDNode from given arguments.

Trait Implementations§

source§

impl<'a> Clone for HDNodeBuilder<'a>

source§

fn clone(&self) -> HDNodeBuilder<'a>

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<'a> Default for HDNodeBuilder<'a>

source§

fn default() -> HDNodeBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for HDNodeBuilder<'a>

§

impl<'a> RefUnwindSafe for HDNodeBuilder<'a>

§

impl<'a> Send for HDNodeBuilder<'a>

§

impl<'a> Sync for HDNodeBuilder<'a>

§

impl<'a> Unpin for HDNodeBuilder<'a>

§

impl<'a> UnwindSafe for HDNodeBuilder<'a>

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> JsonSchemaMaybe for T