pub struct Mnemonic { /* private fields */ }
keys-bip39
only.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
sourceimpl 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>where
R: RngCore + CryptoRng,
pub fn generate_in_with<R>(
rng: &mut R,
language: Language,
word_count: usize
) -> Result<Mnemonic, Error>where
R: RngCore + CryptoRng,
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>(mnemonic: S) -> Result<Language, Error>where
S: AsRef<str>,
pub fn language_of<S>(mnemonic: S) -> Result<Language, Error>where
S: AsRef<str>,
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>(language: Language, s: S) -> Result<Mnemonic, Error>where
S: Into<Cow<'a, str>>,
pub fn parse_in<'a, S>(language: Language, s: S) -> Result<Mnemonic, Error>where
S: Into<Cow<'a, str>>,
Parse a mnemonic in the given language.
sourcepub fn parse<'a, S>(s: S) -> Result<Mnemonic, Error>where
S: Into<Cow<'a, str>>,
pub fn parse<'a, S>(s: S) -> Result<Mnemonic, Error>where
S: Into<Cow<'a, str>>,
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>(&self, passphrase: P) -> [u8; 64]where
P: Into<Cow<'a, str>>,
pub fn to_seed<'a, P>(&self, passphrase: P) -> [u8; 64]where
P: Into<Cow<'a, str>>,
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
Trait Implementations
sourceimpl<Ctx: ScriptContext> DerivableKey<Ctx> for Mnemonic
impl<Ctx: ScriptContext> DerivableKey<Ctx> for Mnemonic
sourcefn into_extended_key(self) -> Result<ExtendedKey<Ctx>, KeyError>
fn into_extended_key(self) -> Result<ExtendedKey<Ctx>, KeyError>
sourcefn into_descriptor_key(
self,
source: Option<KeySource>,
derivation_path: DerivationPath
) -> Result<DescriptorKey<Ctx>, KeyError>
fn into_descriptor_key(
self,
source: Option<KeySource>,
derivation_path: DerivationPath
) -> Result<DescriptorKey<Ctx>, KeyError>
self
and turn it into a DescriptorKey
by adding the extra metadata, such as
key origin and derivation path Read moresourceimpl<'de> Deserialize<'de> for Mnemonic
impl<'de> Deserialize<'de> for Mnemonic
sourcefn deserialize<D>(
deserializer: D
) -> Result<Mnemonic, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Mnemonic, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
sourceimpl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic
impl<Ctx: ScriptContext> GeneratableKey<Ctx> for Mnemonic
sourcefn generate_with_entropy(
(word_count, language): Self::Options,
entropy: Self::Entropy
) -> Result<GeneratedKey<Self, Ctx>, Self::Error>
fn generate_with_entropy(
(word_count, language): Self::Options,
entropy: Self::Entropy
) -> Result<GeneratedKey<Self, Ctx>, Self::Error>
sourceimpl Ord for Mnemonic
impl Ord for Mnemonic
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Mnemonic> for Mnemonic
impl PartialOrd<Mnemonic> for Mnemonic
sourcefn partial_cmp(&self, other: &Mnemonic) -> Option<Ordering>
fn partial_cmp(&self, other: &Mnemonic) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more