Mnemonics

In the context of cryptocurrency, a mnemonic is a group of words that are created at the same time a new cryptowallet is created. The group of words in a mnemonic phrase encode in some way the bytes specific to the keys to a new wallet. This resource provides documentation related to mnemonics in WalletD.


BIP39 Mnemonic

A BIP39 Mnemonic follows the BIP39 standard for HD wallet mnemonic phrases.

Bip39Mnemonic Struct

Represents a mnemonic which follows the BIP39 standard.

Bip39Mnemonic Struct Methods

Bip39Mnemonic's Implementation of the Mnemonic Trait

  • new() -> Self

    • Generates a new mnemonic given the language, length of mnemonic, and optional passphrase
  • from_phrase() -> Result<Self, Error>

    • Restores a mnemonic from a mnemonic phrase and optional passphrase, requires specifying the language
  • detect_language() -> Result<Self::Mnemonic, Self::ErrorType>

    • Restores a mnemonic from a mnemonic phrase and optional passphrase, automatically detects the language
  • to_seed(&self) -> Seed

    • Provides the Seed object
  • phrase(&self) -> String

    • Gets the phrase
  • language(&self) -> Bip39Language

    • Gets the lang field data
  • mnemonic_type(&self) -> Bip39MnemonicType

    • Gets the mnemonic_type data
  • builder() -> Self::MnemonicBuilder

    • Returns the default builder Bip39MnemonicBuilder

Bip39MnemonicType Enum

Represents the different number of words that can be used for a valid Bip39Mnemonic

Bip39MnemonicType Enum Variants

  • Words12 12 word mnemonic phrase (128 bits of entropy)
    • The default mnemonic type is 12 words
  • Words15 15 word mnemonic phrase (160 bits of entropy)
  • Words18 18 word mnemonic phrase (192 bits of entropy)
  • Words21 21 word mnemonic phrase (224 bits of entropy)
  • Words24 24 word mnemonic phrase (256 bits of entropy)

Bip39MnemonicType Enum Methods

  • from_word_count(size: usize) -> Result<Self, Error>

    • Creates the MnemonicType based on the word count

    Specifying a word count not provided for by the BIP39 standard will return an Error

  • from_key_size(size: usize) -> Result<Self, Error>

    • Creates the MnemonicType based on the length of the key size in bits

    Specifying a key size not provided for by the BIP39 standard will return an Error

  • from_phrase(phrase: &str) -> Result<Self, Error>

    • Get a Bip39MnemonicType 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 number of entropy bits used by the mnemonic using Bip39MnemonicType::entropy_bits.

  • entropy_bits(&self) -> usize

    • Return the number of entropy bits

Bip39Language Enum

The language of a Bip39 mnemonic phrase. English is the default language.

The choice of language for a mnemonic phrase not only determines the words used, but also has an impact on the binary value of each word when the Bip39Mnemonic is converted into a `Seed.

English is the only officially supported language, the rest are provided for convenience.

The wordlists for each language are taken from the BIP39 repo

Bip39Language Enum Variants

  • ChineseSimplified
  • ChineseTraditional
  • Czech
  • French
  • Italian
  • Japanese
  • Korean
  • Portuguese
  • Spanish
  • English
    • English is the default language, this is the only officially supported language

WordList Struct

Represents a wordlist for a language for the BIP39 Mnemonic

WordList Struct Methods

  • new(language: Bip39Language) -> WordList

    • Creates a new WordList for a specified language
  • get_index(&self, word: &str) -> Result<usize, Error>

    • Gets the index of a word in a language's wordlist, returns Error if word is not found in wordlist for a language
  • detect_language(phrase: Vec<&str>) -> Result<Bip39Language, Error>

    • If all words in the phrase are present in a language's wordlist, the language of the phrase is detected
  • language(&self) -> Bip39Language

    • Returns the language of the WordList
  • inner(&self) -> Vec<&'static str>

    • Returns the inner wordlist