Struct zcash_primitives::zip339::Mnemonic[]

pub struct Mnemonic { /* fields omitted */ }
Expand description

A mnemonic representation.

First, an initial entropy of ENT bits is generated. A checksum is generated by taking the first ENT/32 bits of its SHA256 hash. This checksum is appended to the end of the initial entropy.

Next, these concatenated bits are split into groups of 11 bits, each encoding a number from 0-2047, serving as an index into a wordlist.

Finally, we convert these numbers into words and use the joined words as a mnemonic sentence.

  • ENT: the initial entropy length
  • CS: the checksum length
  • MS: the length of the generated mnemonic sentence in words

CS = ENT / 32

MS = (ENT + CS) / 11

ENTCSENT+CSMS
128413212
160516515
192619818
224723121
256826424

For example, a 12 word mnemonic phrase is essentially a friendly representation of a 128-bit key, while a 24 word mnemonic phrase is essentially a 256-bit key.

Implementations

Generates a new English Mnemonic randomly in the specified word count.

Example

use bip0039::{Count, Mnemonic};

let mnemonic = Mnemonic::generate(Count::Words12);
let phrase = mnemonic.phrase();

Generates a new Mnemonic randomly in the specified language and word count.

Example

use bip0039::{Count, Language, Mnemonic};

let mnemonic = Mnemonic::generate_in(Language::SimplifiedChinese, Count::Words24);
let phrase = mnemonic.phrase();

Creates a new English Mnemonic from the given entropy.

Example

use bip0039::Mnemonic;

let entropy = vec![0x1a, 0x48, 0x6a, 0x5f, 0xbe, 0x53, 0x63, 0x99, 0x84, 0xcb, 0x64, 0xb0, 0x70, 0x75, 0x5f, 0x7b];
let mnemonic = Mnemonic::from_entropy(entropy).unwrap();
assert_eq!(mnemonic.phrase(), "bottom drive obey lake curtain smoke basket hold race lonely fit walk");

Creates a new Mnemonic in the specified language from the given entropy.

Example

use bip0039::{Language, Mnemonic};

let entropy = vec![0x1a, 0x48, 0x6a, 0x5f, 0xbe, 0x53, 0x63, 0x99, 0x84, 0xcb, 0x64, 0xb0, 0x70, 0x75, 0x5f, 0x7b];
let mnemonic = Mnemonic::from_entropy_in(Language::English, entropy).unwrap();
assert_eq!(mnemonic.phrase(), "bottom drive obey lake curtain smoke basket hold race lonely fit walk");

Creates a Mnemonic from an existing mnemonic phrase.

Example

use bip0039::Mnemonic;

let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
let mnemonic = Mnemonic::from_phrase(phrase).unwrap();
assert_eq!(mnemonic.phrase(), phrase);

Creates a Mnemonic from an existing mnemonic phrase in the given language.

Example

use bip0039::{Error, Mnemonic, Language};

let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
let mnemonic = Mnemonic::from_phrase_in(Language::English, phrase).unwrap();
assert_eq!(mnemonic.phrase(), phrase);

let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit shit";
let mnemonic = Mnemonic::from_phrase_in(Language::English, phrase);
assert_eq!(mnemonic.unwrap_err(), Error::UnknownWord("shit".into()));

Validates the word count and checksum of an English mnemonic phrase.

Example

use bip0039::Mnemonic;

let result = Mnemonic::validate("bottom drive obey lake curtain smoke basket hold race lonely fit walk");
assert!(result.is_ok());

Validates the word count and checksum of a mnemonic phrase in the given language.

Example

use bip0039::{Error, Language, Mnemonic};
use unicode_normalization::UnicodeNormalization;

let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
let result = Mnemonic::validate_in(Language::English, phrase);
assert!(result.is_ok());
let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit shit";
let result = Mnemonic::validate_in(Language::English, phrase);
assert_eq!(result.unwrap_err(), Error::UnknownWord("shit".into()));

let phrase = "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかめ";
let result = Mnemonic::validate_in(Language::Japanese, phrase);
assert!(result.is_ok());
let phrase = "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく ばか";
let result = Mnemonic::validate_in(Language::Japanese, phrase);
assert_eq!(result.unwrap_err(), Error::UnknownWord("ばか".nfkd().to_string()));

Generates the seed from the Mnemonic and the passphrase.

If a passphrase is not present, an empty string "" is used instead.

Example

use bip0039::Mnemonic;

let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
let mnemonic = Mnemonic::from_phrase(phrase).unwrap();
assert_eq!(
    mnemonic.to_seed("").to_vec(),
    hex::decode("02d5cd1db85b4d1397d78978062a1160e76e94cc5aaad3089644846865bb18fc68ddf383059d3fe82902a203d60790a8c8ab488de5013d10a8a8bded8d9174b9").unwrap()
);

Returns the Language of the mnemonic.

Returns the mnemonic phrase as a string slice.

Consumes the Mnemonic and return the phrase as a String.

Returns the original entropy of the mnemonic phrase.

Consumes the Mnemonic and return the entropy as a Vec<u8>.

Trait Implementations

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.