Struct bdk::keys::bip39::Mnemonic [−][src]
pub struct Mnemonic { /* fields omitted */ }
keys-bip39
only.Expand description
The primary type in this crate, most tasks require creating or using one.
To create a new Mnemonic
from a randomly generated key, call Mnemonic::new()
.
To get a Mnemonic
instance for an existing mnemonic phrase, including
those generated by other software or hardware wallets, use Mnemonic::from_phrase()
.
You can get the HD wallet Seed
from a Mnemonic
by calling Seed::new()
.
From there you can either get the raw byte value with Seed::as_bytes()
, or the hex
representation using Rust formatting: format!("{:X}", seed)
.
You can also get the original entropy value back from a Mnemonic
with Mnemonic::entropy()
,
but beware that the entropy value is not the same thing as an HD wallet seed, and should
never be used that way.
Mnemonic
implements Zeroize
, so it’s bytes will be zeroed when it’s dropped.
Implementations
Generates a new Mnemonic
Use Mnemonic::phrase()
to get an str
slice of the generated phrase.
Example
use bip39::{Mnemonic, MnemonicType, Language}; let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English); let phrase = mnemonic.phrase(); println!("phrase: {}", phrase); assert_eq!(phrase.split(" ").count(), 12);
Create a Mnemonic
from pre-generated entropy
Example
use bip39::{Mnemonic, MnemonicType, Language}; let entropy = &[0x33, 0xE4, 0x6B, 0xB1, 0x3A, 0x74, 0x6E, 0xA4, 0x1C, 0xDD, 0xE4, 0x5C, 0x90, 0x84, 0x6A, 0x79]; let mnemonic = Mnemonic::from_entropy(entropy, Language::English).unwrap(); assert_eq!("crop cash unable insane eight faith inflict route frame loud box vibrant", mnemonic.phrase()); assert_eq!("33E46BB13A746EA41CDDE45C90846A79", format!("{:X}", mnemonic));
Create a Mnemonic
from an existing mnemonic phrase
The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039
Example
use bip39::{Mnemonic, Language}; let phrase = "park remain person kitchen mule spell knee armed position rail grid ankle"; let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap(); assert_eq!(phrase, mnemonic.phrase());
Validate a mnemonic phrase
The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039.
Example
use bip39::{Mnemonic, Language}; let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle"; assert!(Mnemonic::validate(test_mnemonic, Language::English).is_ok());
Consume the Mnemonic
and return the phrase as a String
.
Get the original entropy value of the mnemonic phrase as a slice.
Example
use bip39::{Mnemonic, Language}; let phrase = "park remain person kitchen mule spell knee armed position rail grid ankle"; let mnemonic = Mnemonic::from_phrase(phrase, Language::English).unwrap(); let entropy: &[u8] = mnemonic.entropy();
Note: You shouldn’t use the generated entropy as secrets, for that generate a new
Seed
from the Mnemonic
.
Trait Implementations
Consume self
and turn it into an ExtendedKey
Read more
fn into_descriptor_key(
self,
source: Option<KeySource>,
derivation_path: DerivationPath
) -> Result<DescriptorKey<Ctx>, KeyError>
[src]
fn into_descriptor_key(
self,
source: Option<KeySource>,
derivation_path: DerivationPath
) -> Result<DescriptorKey<Ctx>, KeyError>
[src]Consume self
and turn it into a DescriptorKey
by adding the extra metadata, such as
key origin and derivation path Read more
type Options = (MnemonicType, Language)
type Options = (MnemonicType, Language)
Extra options required by the generate_with_entropy
fn generate_with_entropy(
(mnemonic_type, language): Self::Options,
entropy: Self::Entropy
) -> Result<GeneratedKey<Self, Ctx>, Self::Error>
[src]
fn generate_with_entropy(
(mnemonic_type, language): Self::Options,
entropy: Self::Entropy
) -> Result<GeneratedKey<Self, Ctx>, Self::Error>
[src]Generate a key given the extra options and the entropy
Auto Trait Implementations
impl RefUnwindSafe for Mnemonic
impl UnwindSafe for Mnemonic
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self
impl<T> ToHex for T where
T: LowerHex,
impl<T> ToHex for T where
T: LowerHex,
pub fn vzip(self) -> V