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;
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];
rand::rng().fill_bytes(&mut entropy);
let other_wallet = HDNode::build().seed(entropy).build().expect("Must be buildable");Implementations§
Source§impl<'a> HDNodeBuilder<'a>
impl<'a> HDNodeBuilder<'a>
Sourcepub fn path(self, path: DerivationPath) -> Self
pub fn path(self, path: DerivationPath) -> Self
Set a derivation path to use.
If not called, defaults to VET_EXTERNAL_PATH.
Sourcepub fn mnemonic(self, mnemonic: Mnemonic) -> Self
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).
Sourcepub fn mnemonic_with_password(
self,
mnemonic: Mnemonic,
password: &'a str,
) -> Self
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.
Sourcepub fn master_private_key_bytes<T: Into<ChainCode>>(
self,
key: [u8; 33],
chain_code: T,
) -> Self
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.
Sourcepub fn private_key(self, ext_key: ExtendedKey) -> Self
pub fn private_key(self, ext_key: ExtendedKey) -> Self
Create an HDNode from extended private key structure.
Sourcepub fn master_public_key_bytes<T: Into<ChainCode>>(
self,
key: [u8; 33],
chain_code: T,
) -> Self
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.
Sourcepub fn public_key(self, ext_key: ExtendedKey) -> Self
pub fn public_key(self, ext_key: ExtendedKey) -> Self
Create an HDNode from extended public key structure.
Sourcepub fn build(self) -> Result<HDNode, HDNodeError>
pub fn build(self) -> Result<HDNode, HDNodeError>
Create an HDNode from given arguments.
Trait Implementations§
Source§impl<'a> Clone for HDNodeBuilder<'a>
impl<'a> Clone for HDNodeBuilder<'a>
Source§fn clone(&self) -> HDNodeBuilder<'a>
fn clone(&self) -> HDNodeBuilder<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Default for HDNodeBuilder<'a>
impl<'a> Default for HDNodeBuilder<'a>
Source§fn default() -> HDNodeBuilder<'a>
fn default() -> HDNodeBuilder<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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