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
impl Wallet
Sourcepub fn generate_in(
language: Language,
word_count: usize,
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
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 listword_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.
Sourcepub fn generate_in_with<R>(
rng: &mut R,
language: Language,
word_count: usize,
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
pub fn generate_in_with<R>( rng: &mut R, language: Language, word_count: usize, passphrase: Option<&str>, ) -> Result<Self, DeriveError>
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 generatorlanguage- Language for the mnemonic word listword_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.
Sourcepub fn from_entropy(
entropy: &[u8],
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
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.
Sourcepub fn from_entropy_in(
language: Language,
entropy: &[u8],
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
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 listentropy- 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.
Sourcepub fn from_mnemonic(
phrase: &str,
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
pub fn from_mnemonic( phrase: &str, passphrase: Option<&str>, ) -> Result<Self, DeriveError>
Sourcepub fn from_mnemonic_in(
language: Language,
phrase: &str,
passphrase: Option<&str>,
) -> Result<Self, DeriveError>
pub fn from_mnemonic_in( language: Language, phrase: &str, passphrase: Option<&str>, ) -> Result<Self, DeriveError>
Sourcepub fn mnemonic(&self) -> &str
pub fn mnemonic(&self) -> &str
Get the mnemonic phrase.
Security Warning: Handle this value carefully as it can reconstruct all derived keys.
Sourcepub const fn seed(&self) -> &Zeroizing<[u8; 64]>
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.
Sourcepub fn derive_secp256k1(
&self,
path: &str,
) -> Result<DerivedSecp256k1Key, DeriveError>
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.
Sourcepub fn derive_ed25519(
&self,
path: &str,
) -> Result<DerivedEd25519Key, DeriveError>
pub fn derive_ed25519( &self, path: &str, ) -> Result<DerivedEd25519Key, DeriveError>
Sourcepub const fn has_passphrase(&self) -> bool
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.
Sourcepub fn word_count(&self) -> usize
pub fn word_count(&self) -> usize
Get the word count of the mnemonic.