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, 15, 18, 21, and 24.
Implementations§
Source§impl Mnemonic
impl Mnemonic
Sourcepub fn normalize_utf8_cow<'a>(cow: &mut Cow<'a, str>)
pub fn normalize_utf8_cow<'a>(cow: &mut Cow<'a, str>)
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 word_iter(&self) -> impl Iterator<Item = &'static str> + Clone
👎Deprecated since 2.1.0: Use Mnemonic::words instead
pub fn word_iter(&self) -> impl Iterator<Item = &'static str> + Clone
Use Mnemonic::words instead
Returns an iterator over the words of the Mnemonic.
Sourcepub fn word_indices(&self) -> impl Iterator<Item = usize> + Clone
pub fn word_indices(&self) -> impl Iterator<Item = usize> + Clone
Sourcepub fn language_of<S>(mnemonic: S) -> Result<Language, Error>
pub fn language_of<S>(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_in_normalized_without_checksum_check(
language: Language,
s: &str,
) -> Result<Mnemonic, Error>
pub fn parse_in_normalized_without_checksum_check( language: Language, s: &str, ) -> Result<Mnemonic, Error>
Parse a mnemonic in normalized UTF8 in the given language without checksum check.
It is advised to use this method together with the utility methods
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>
pub fn parse_in<'a, S>(language: Language, s: S) -> Result<Mnemonic, Error>
Parse a mnemonic in the given language.
Sourcepub fn parse<'a, S>(s: S) -> Result<Mnemonic, Error>
pub fn parse<'a, S>(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_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<u8>.
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.
Sourcepub fn checksum(&self) -> u8
pub fn checksum(&self) -> u8
Return checksum value for the Mnemonic.
The checksum value is the numerical value of the first self.word_count() / 3 bits of the
SHA256 digest of the Mnemonic’s entropy, and is
encoded by the last word of the mnemonic sentence.
This is useful for validating the integrity of a mnemonic: For a valid mnemonic m, the
following assertion should hold:
let checksum_width = m.word_count() / 3;
let shift_width = 8 - checksum_width;
assert_eq!(sha256::Hash::hash(&m.to_entropy())[0] >> shift_width, m.checksum());Note that since this library constrains initialization of Mnemonic instances through an
API that guarantees validity, all Mnemonic instances should be valid and the above
condition should hold.
Trait Implementations§
impl Eq for Mnemonic
Source§impl Ord for Mnemonic
impl Ord for Mnemonic
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Mnemonic
impl PartialOrd for Mnemonic
impl StructuralPartialEq for Mnemonic
Auto Trait Implementations§
impl Freeze for Mnemonic
impl RefUnwindSafe for Mnemonic
impl Send for Mnemonic
impl Sync for Mnemonic
impl Unpin for Mnemonic
impl UnsafeUnpin for Mnemonic
impl UnwindSafe for Mnemonic
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.