Enum MnemonicType

Source
pub enum MnemonicType {
    Words12 = 32_772,
    Words15 = 40_965,
    Words18 = 49_158,
    Words21 = 57_351,
    Words24 = 65_544,
}
Expand description

Determines the number of words that will be present in a Mnemonic phrase

Also directly affects the amount of entropy that will be used to create a Mnemonic, and therefore the cryptographic strength of the HD wallet keys/addresses that can be derived from it using the Seed.

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.

If you know you want a specific phrase length, you can use the enum variant directly, for example MnemonicType::Words12.

You can also get a MnemonicType that corresponds to one of the standard BIP39 key sizes by passing arbitrary usize values:

use bip39::{MnemonicType};

let mnemonic_type = MnemonicType::for_key_size(128).unwrap();

Variants§

§

Words12 = 32_772

§

Words15 = 40_965

§

Words18 = 49_158

§

Words21 = 57_351

§

Words24 = 65_544

Implementations§

Source§

impl MnemonicType

Source

pub fn for_word_count(size: usize) -> Result<MnemonicType, Error>

Get a MnemonicType for a mnemonic phrase with a specific number of words

Specifying a word count not provided for by the BIP39 standard will return an Error of kind ErrorKind::InvalidWordLength.

§Example
use bip39::{MnemonicType};

let mnemonic_type = MnemonicType::for_word_count(12).unwrap();
Source

pub fn for_key_size(size: usize) -> Result<MnemonicType, Error>

Get a MnemonicType for a mnemonic phrase representing the given key size as bits

Specifying a key size not provided for by the BIP39 standard will return an Error of kind ErrorKind::InvalidKeysize.

§Example
use bip39::{MnemonicType};

let mnemonic_type = MnemonicType::for_key_size(128).unwrap();
Source

pub fn for_phrase(phrase: &str) -> Result<MnemonicType, Error>

Get a MnemonicType for an existing mnemonic phrase

This can be used when you need information about a mnemonic phrase based on the number of words, for example you can get the entropy value using MnemonicType::entropy_bits.

Specifying a phrase that does not match one of the standard BIP39 phrase lengths will return an Error of kind ErrorKind::InvalidWordLength. The phrase will not be validated in any other way.

§Example
use bip39::{MnemonicType};

let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle";

let mnemonic_type = MnemonicType::for_phrase(test_mnemonic).unwrap();

let entropy_bits = mnemonic_type.entropy_bits();
Source

pub fn total_bits(&self) -> usize

Return the number of entropy+checksum bits

§Example
use bip39::{MnemonicType};

let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle";

let mnemonic_type = MnemonicType::for_phrase(test_mnemonic).unwrap();

let total_bits = mnemonic_type.total_bits();
Source

pub fn entropy_bits(&self) -> usize

Return the number of entropy bits

§Example
use bip39::{MnemonicType};

let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle";

let mnemonic_type = MnemonicType::for_phrase(test_mnemonic).unwrap();

let entropy_bits = mnemonic_type.entropy_bits();
Source

pub fn checksum_bits(&self) -> u8

Return the number of checksum bits

§Example
use bip39::{MnemonicType};

let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle";

let mnemonic_type = MnemonicType::for_phrase(test_mnemonic).unwrap();

let checksum_bits = mnemonic_type.checksum_bits();
Source

pub fn word_count(&self) -> usize

Return the number of words

§Example
use bip39::{MnemonicType};

let mnemonic_type = MnemonicType::Words12;

let word_count = mnemonic_type.word_count();

Trait Implementations§

Source§

impl Clone for MnemonicType

Source§

fn clone(&self) -> MnemonicType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MnemonicType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MnemonicType

Source§

fn default() -> MnemonicType

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for MnemonicType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for MnemonicType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MnemonicType

Source§

fn eq(&self, other: &MnemonicType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MnemonicType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for MnemonicType

Source§

impl Eq for MnemonicType

Source§

impl StructuralPartialEq for MnemonicType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,