Struct bip39::Mnemonic [−][src]
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.
Implementations
impl Mnemonic
[src]
pub fn new(mtype: MnemonicType, lang: Language) -> Mnemonic
[src]
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);
pub fn from_entropy(entropy: &[u8], lang: Language) -> Result<Mnemonic, Error>
[src]
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));
pub fn from_phrase<S>(phrase: S, lang: Language) -> Result<Mnemonic, Error> where
S: Into<String>,
[src]
S: Into<String>,
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());
pub fn validate(phrase: &str, lang: Language) -> Result<(), Error>
[src]
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());
pub fn phrase(&self) -> &str
[src]
Get the mnemonic phrase as a string reference.
pub fn into_phrase(self) -> String
[src]
Consume the Mnemonic
and return the phrase as a String
.
This operation doesn’t perform any allocations.
pub fn entropy(&self) -> &[u8]
[src]
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
.
pub fn language(&self) -> Language
[src]
Get the Language
Trait Implementations
impl AsRef<str> for Mnemonic
[src]
impl Clone for Mnemonic
[src]
impl Debug for Mnemonic
[src]
impl Display for Mnemonic
[src]
impl LowerHex for Mnemonic
[src]
impl UpperHex for Mnemonic
[src]
Auto Trait Implementations
impl RefUnwindSafe for Mnemonic
impl Send for Mnemonic
impl Sync for Mnemonic
impl Unpin for Mnemonic
impl UnwindSafe for Mnemonic
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,