pub struct Mnemonic { /* private fields */ }Expand description
A mnemonic code.
The core::str::FromStr implementation will try to determine the language of the mnemonic from all the supported languages. (Languages have to be explicitly enabled using the Cargo features.)
Supported number of words are 12, 18 and 24.
Implementations§
Source§impl Mnemonic
impl Mnemonic
Sourcepub fn from_entropy_in(
language: Language,
entropy: &[u8],
) -> Result<Mnemonic, Error>
pub fn from_entropy_in( language: Language, entropy: &[u8], ) -> Result<Mnemonic, Error>
Create a new Mnemonic in the specified language from the given entropy. Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
Sourcepub fn from_entropy(entropy: &[u8]) -> Result<Mnemonic, Error>
pub fn from_entropy(entropy: &[u8]) -> Result<Mnemonic, Error>
Create a new English Mnemonic from the given entropy. Entropy must be a multiple of 32 bits (4 bytes) and 128-256 bits in length.
Sourcepub fn generate_in_with<R>(
rng: &mut R,
language: Language,
word_count: usize,
) -> Result<Mnemonic, Error>
pub fn generate_in_with<R>( rng: &mut R, language: Language, word_count: usize, ) -> Result<Mnemonic, Error>
Generate a new Mnemonic in the given language with the given randomness source. For the different supported word counts, see documentation on Mnemonic.
Example:
extern crate rand;
extern crate bip39;
use bip39::{Mnemonic, Language};
let mut rng = rand::thread_rng();
let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();Sourcepub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone + '_
pub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone + '_
Get an iterator over the words.
Sourcepub fn language_of<S: AsRef<str>>(mnemonic: S) -> Result<Language, Error>
pub fn language_of<S: AsRef<str>>(mnemonic: S) -> Result<Language, Error>
Determine the language of the mnemonic.
NOTE: This method only guarantees that the returned language is the correct language on the assumption that the mnemonic is valid. It does not itself validate the mnemonic.
Some word lists don’t guarantee that their words don’t occur in other word lists. In the extremely unlikely case that a word list can be interpreted in multiple languages, an Error::AmbiguousLanguages is returned, containing the possible languages.
Sourcepub fn parse_in_normalized(
language: Language,
s: &str,
) -> Result<Mnemonic, Error>
pub fn parse_in_normalized( language: Language, s: &str, ) -> Result<Mnemonic, Error>
Parse a mnemonic in normalized UTF8 in the given language.
Sourcepub fn parse_normalized(s: &str) -> Result<Mnemonic, Error>
pub fn parse_normalized(s: &str) -> Result<Mnemonic, Error>
Parse a mnemonic in normalized UTF8.
Sourcepub fn parse_in<'a, S: Into<Cow<'a, str>>>(
language: Language,
s: S,
) -> Result<Mnemonic, Error>
pub fn parse_in<'a, S: Into<Cow<'a, str>>>( language: Language, s: S, ) -> Result<Mnemonic, Error>
Parse a mnemonic in the given language.
Sourcepub fn parse<'a, S: Into<Cow<'a, str>>>(s: S) -> Result<Mnemonic, Error>
pub fn parse<'a, S: Into<Cow<'a, str>>>(s: S) -> Result<Mnemonic, Error>
Parse a mnemonic and detect the language from the enabled languages.
Sourcepub fn word_count(&self) -> usize
pub fn word_count(&self) -> usize
Get the number of words in the mnemonic.
Sourcepub fn to_seed_normalized(&self, normalized_passphrase: &str) -> [u8; 64]
pub fn to_seed_normalized(&self, normalized_passphrase: &str) -> [u8; 64]
Convert to seed bytes with a passphrase in normalized UTF8.
Sourcepub fn to_seed<'a, P: Into<Cow<'a, str>>>(&self, passphrase: P) -> [u8; 64]
pub fn to_seed<'a, P: Into<Cow<'a, str>>>(&self, passphrase: P) -> [u8; 64]
Convert to seed bytes.
Sourcepub fn to_entropy_array(&self) -> ([u8; 33], usize)
pub fn to_entropy_array(&self) -> ([u8; 33], usize)
Convert the mnemonic back to the entropy used to generate it.
The return value is a byte array and the size.
Use Mnemonic::to_entropy (needs std) to get a Vec
Sourcepub fn to_entropy(&self) -> Vec<u8> ⓘ
pub fn to_entropy(&self) -> Vec<u8> ⓘ
Convert the mnemonic back to the entropy used to generate it.