pub struct Bip39 { /* private fields */ }
Expand description

Tool for generating, validating and parsing BIP39 phrases in different supported languages.

Implementations

Number of words in the BIP39 mnemonics we accept and generate

Creates the right sized entropy using the CSPRNG available on the platform.

Creates a new English BIP39 phrase handler

Creates a new BIP39 phrase handler with the given language

Creates a new BIP39 phrase handler with the given language code

Example
let bip39 = Bip39::language_code("fr").unwrap();
assert!(bip39.check_word("aménager"));

Creates a new phrase from hardware entropy. Cannot be used from WASM because it uses the system random generator.

Example
let phrase: &str = Bip39::language_code("fr").unwrap().generate().as_phrase();
let seed: Seed = Bip39::new().generate().password("");

Checks if a word is present in the BIP39 dictionary

Example
let bip39 = Bip39::new();
assert!(bip39.check_word("abandon"));
assert!(!bip39.check_word("Abandon"));
assert!(!bip39.check_word("avalon"));

Lists all words in the BIP39 dictionary, which start with the given prefix.

Can be used in 3 different ways:

  • When the prefix is empty, the sorted list of all words are returned
  • When the prefix is a partial word, the returned list can be used for auto-completion
  • When the returned list is empty, the prefix is not a valid word in the dictionary
Example
let bip39 = Bip39::language(Bip39Language::English);
assert_eq!(bip39.list_words("").len(), 2048);
assert_eq!(bip39.list_words("woo"), ["wood", "wool"]);
assert!(bip39.list_words("woof").is_empty());

Validates a whole BIP39 mnemonic phrase. Because the phrase contains some checksum, the whole phrase can be invalid even when each word itself is valid.

Example
let bip39 = Bip39::new();
assert!(bip39.validate("type shield target dream feature surface search flee tenant cake taxi shrug").is_ok());
assert!(bip39.validate("abandon abandon about").unwrap_err().to_string().contains("invalid number of words"));

Validates a whole BIP39 mnemonic phrase and returns an intermediate object that can be later converted into a Seed with an optional password.

Use the Self::phrase() method whenever possible. This method allows some legacy use-cases to provide mnemonics shorter than Self::MNEMONIC_WORDS words.

Creates a BIP39 phrase based on the 256 bits of entropy provided. This method is needed from WASM because Self::generate() uses system resources unavailable from WASM.

Use the [‘entropy()’] method whenever possible. This method allows some legacy use-cases to provide mnemonics with low entropy.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. 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

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

Uses borrowed data to replace owned data, usually by cloning. 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.