Skip to main content

Wallet

Struct Wallet 

Source
pub struct Wallet { /* private fields */ }
Expand description

A unified HD wallet that can derive keys for multiple cryptocurrencies.

This wallet holds a BIP39 mnemonic and derives a seed that can be used to generate addresses for Bitcoin, Ethereum, and other coins following BIP32/44/49/84 standards.

§Passphrase Support

The wallet supports an optional BIP39 passphrase (sometimes called “25th word”). This provides an extra layer of security - the same mnemonic with different passphrases will produce completely different wallets.

Implementations§

Source§

impl Wallet

Source

pub fn generate( word_count: usize, passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Generate a new wallet with a random mnemonic.

§Arguments
  • word_count - Number of words (12, 15, 18, 21, or 24)
  • passphrase - Optional BIP39 passphrase for additional security
§Errors

Returns an error if the word count is invalid.

§Note

This function requires the rand feature to be enabled.

Source

pub fn generate_in( language: Language, word_count: usize, passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Generate a new wallet with a random mnemonic in the specified language.

§Arguments
  • language - Language for the mnemonic word list
  • word_count - Number of words (12, 15, 18, 21, or 24)
  • passphrase - Optional BIP39 passphrase for additional security
§Errors

Returns an error if the word count is invalid.

§Note

This function requires the rand feature to be enabled.

Source

pub fn generate_in_with<R>( rng: &mut R, language: Language, word_count: usize, passphrase: Option<&str>, ) -> Result<Self, DeriveError>
where R: RngCore + CryptoRng,

Generate a new wallet with a custom random number generator.

This is useful in no_std environments where you provide your own cryptographically secure RNG instead of relying on the system RNG.

§Arguments
  • rng - A cryptographically secure random number generator
  • language - Language for the mnemonic word list
  • word_count - Number of words (12, 15, 18, 21, or 24)
  • passphrase - Optional BIP39 passphrase for additional security
§Errors

Returns an error if the word count is invalid.

§Note

This function requires the rand_core feature to be enabled.

Source

pub fn from_entropy( entropy: &[u8], passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Create a wallet from raw entropy bytes (English by default).

This is useful in no_std environments where you provide your own entropy source instead of relying on the system RNG.

§Arguments
  • entropy - Raw entropy bytes (16, 20, 24, 28, or 32 bytes for 12-24 words)
  • passphrase - Optional BIP39 passphrase for additional security
§Errors

Returns an error if the entropy length is invalid.

Source

pub fn from_entropy_in( language: Language, entropy: &[u8], passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Create a wallet from raw entropy bytes in the specified language.

This is useful in no_std environments where you provide your own entropy source instead of relying on the system RNG.

§Arguments
  • language - Language for the mnemonic word list
  • entropy - Raw entropy bytes (16, 20, 24, 28, or 32 bytes for 12-24 words)
  • passphrase - Optional BIP39 passphrase for additional security
§Errors

Returns an error if the entropy length is invalid.

Source

pub fn from_mnemonic( phrase: &str, passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Create a wallet from an existing mnemonic phrase.

The language will be automatically detected from the phrase.

§Arguments
  • phrase - BIP39 mnemonic phrase
  • passphrase - Optional BIP39 passphrase
§Errors

Returns an error if the mnemonic is invalid.

Source

pub fn from_mnemonic_in( language: Language, phrase: &str, passphrase: Option<&str>, ) -> Result<Self, DeriveError>

Create a wallet from an existing mnemonic phrase in the specified language.

§Arguments
  • language - Language for the mnemonic word list
  • phrase - BIP39 mnemonic phrase
  • passphrase - Optional BIP39 passphrase
§Errors

Returns an error if the mnemonic is invalid.

Source

pub fn mnemonic(&self) -> &str

Get the mnemonic phrase.

Security Warning: Handle this value carefully as it can reconstruct all derived keys.

Source

pub const fn seed(&self) -> &Zeroizing<[u8; 64]>

Get the 64-byte seed for key derivation, still wrapped in Zeroizing.

The returned reference makes the wallet’s sensitivity explicit at the type level: callers must keep the result borrowed or copy it into another Zeroizing container to avoid leaking unsealed seed bytes on the stack.

Most chain derivers should prefer the feature-gated derive_secp256k1 and derive_ed25519 shortcuts over reaching for the raw seed.

Source

pub fn derive_secp256k1( &self, path: &str, ) -> Result<DerivedSecp256k1Key, DeriveError>

Derive a secp256k1 key pair at the given BIP-32 path.

Preferred entry point for chains that derive secp256k1 keys (EVM, BTC fallback, Cosmos, Tron, Spark, Filecoin, XRP Ledger, Nostr). Keeps the underlying seed encapsulated within Wallet.

§Errors

Returns an error if the path is malformed or derivation fails.

Source

pub fn derive_ed25519( &self, path: &str, ) -> Result<DerivedEd25519Key, DeriveError>

Derive an Ed25519 key pair at the given SLIP-10 path.

Preferred entry point for chains that derive Ed25519 keys (Solana, Sui, Aptos, TON). Keeps the underlying seed encapsulated within Wallet.

§Errors

Returns an error if the path is malformed or derivation fails.

Source

pub const fn has_passphrase(&self) -> bool

Check if a passphrase was supplied at construction time.

Returns true whenever the caller passed Some(_) to the constructor, even if the passphrase string itself was empty. Callers relying on “non-empty passphrase” semantics must check the passphrase string before constructing the wallet.

Source

pub const fn language(&self) -> Language

Get the language of the mnemonic.

Source

pub fn word_count(&self) -> usize

Get the word count of the mnemonic.

Trait Implementations§

Source§

impl Debug for Wallet

Source§

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

Formats the value using the given formatter. Read more

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

Source§

type Output = T

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

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

Source§

fn vzip(self) -> V