pub enum MnemonicType {
Words9 = 24_579,
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 dup_crypto::mnemonic::{MnemonicType};
let mnemonic_type = MnemonicType::for_key_size(128).unwrap();
Variants§
Words9 = 24_579
Mnemonic with 9 words
Words12 = 32_772
Mnemonic with 12 words
Words15 = 40_965
Mnemonic with 15 words
Words18 = 49_158
Mnemonic with 18 words
Words21 = 57_351
Mnemonic with 21 words
Words24 = 65_544
Mnemonic with 24 words
Implementations§
Source§impl MnemonicType
impl MnemonicType
Sourcepub fn for_word_count(size: usize) -> Result<MnemonicType, MnemonicError>
pub fn for_word_count(size: usize) -> Result<MnemonicType, MnemonicError>
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 dup_crypto::mnemonic::{MnemonicType};
let mnemonic_type = MnemonicType::for_word_count(12).unwrap();
Sourcepub fn for_key_size(size: usize) -> Result<MnemonicType, MnemonicError>
pub fn for_key_size(size: usize) -> Result<MnemonicType, MnemonicError>
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 dup_crypto::mnemonic::{MnemonicType};
let mnemonic_type = MnemonicType::for_key_size(128).unwrap();
Sourcepub fn for_phrase(phrase: &str) -> Result<MnemonicType, MnemonicError>
pub fn for_phrase(phrase: &str) -> Result<MnemonicType, MnemonicError>
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 dup_crypto::mnemonic::{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();
Sourcepub fn total_bits(self) -> usize
pub fn total_bits(self) -> usize
Return the number of entropy+checksum bits
§Example
use dup_crypto::mnemonic::{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();
Sourcepub fn entropy_bits(self) -> usize
pub fn entropy_bits(self) -> usize
Return the number of entropy bits
§Example
use dup_crypto::mnemonic::{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();
Sourcepub fn checksum_bits(self) -> u8
pub fn checksum_bits(self) -> u8
Return the number of checksum bits
§Example
use dup_crypto::mnemonic::{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();
Sourcepub fn word_count(self) -> usize
pub fn word_count(self) -> usize
Return the number of words
§Example
use dup_crypto::mnemonic::{MnemonicType};
let mnemonic_type = MnemonicType::Words12;
let word_count = mnemonic_type.word_count();
Trait Implementations§
Source§impl Clone for MnemonicType
impl Clone for MnemonicType
Source§fn clone(&self) -> MnemonicType
fn clone(&self) -> MnemonicType
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MnemonicType
impl Debug for MnemonicType
Source§impl Default for MnemonicType
impl Default for MnemonicType
Source§fn default() -> MnemonicType
fn default() -> MnemonicType
Source§impl Display for MnemonicType
impl Display for MnemonicType
impl Copy for MnemonicType
Auto Trait Implementations§
impl Freeze for MnemonicType
impl RefUnwindSafe for MnemonicType
impl Send for MnemonicType
impl Sync for MnemonicType
impl Unpin for MnemonicType
impl UnwindSafe for MnemonicType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more