Struct bip39::Mnemonic [] [src]

pub struct Mnemonic { /* fields omitted */ }

The primary type in this crate, most tasks require creating or using one.

To create a new Mnemonic from a randomly generated key, call Mnemonic::new().

To get a Mnemonic instance for an existing mnemonic phrase, including those generated by other software or hardware wallets, use Mnemonic::from_string().

You can get the HD wallet Seed from a Mnemonic by calling Mnemonic::get_seed(), from there you can either get the raw byte value with Seed::as_bytes(), or the hex representation with Seed::as_hex().

You can also get the original entropy value back from a Mnemonic with Mnemonic::to_entropy(), but beware that the entropy value is not the same thing as an HD wallet seed, and should never be used that way.

Methods

impl Mnemonic
[src]

[src]

Generates a new Mnemonic

Can be used to get the Seed using Mnemonic::get_seed().

Can also be used to get the original entropy value. Use Mnemonic::as_entropy() for a slice, or Mnemonic::get_entropy() for an owned Vec<u8>.

Example

use bip39::{Mnemonic, MnemonicType, Language};

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

let mnemonic = match Mnemonic::new(mnemonic_type, Language::English, "") {
    Ok(b) => b,
    Err(e) => { println!("e: {}", e); return }
};

let phrase = mnemonic.get_string();
let seed = mnemonic.get_seed();
let seed_bytes: &[u8] = seed.as_bytes();
let seed_hex: &str = seed.as_hex();
println!("phrase: {}", phrase);

[src]

Create a Mnemonic from generated entropy

Example

use bip39::{Mnemonic, MnemonicType, Language};

let entropy = &[0x33, 0xE4, 0x6B, 0xB1, 0x3A, 0x74, 0x6E, 0xA4, 0x1C, 0xDD, 0xE4, 0x5C, 0x90, 0x84, 0x6A, 0x79];
let mnemonic = Mnemonic::from_entropy(entropy, MnemonicType::for_key_size(128).unwrap(), Language::English, "").unwrap();

assert_eq!("crop cash unable insane eight faith inflict route frame loud box vibrant", mnemonic.as_str());

[src]

Create a Mnemonic from generated entropy hexadecimal representation

Example

use bip39::{Mnemonic, MnemonicType, Language};

let entropy = "33E46BB13A746EA41CDDE45C90846A79";
let mnemonic = Mnemonic::from_entropy_hex(entropy, MnemonicType::for_key_size(128).unwrap(), Language::English, "").unwrap();

assert_eq!("crop cash unable insane eight faith inflict route frame loud box vibrant", mnemonic.as_str());

[src]

Create a Mnemonic from an existing mnemonic phrase

The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039

Example

use bip39::{Mnemonic, Language};

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

let mnemonic = Mnemonic::from_string(test_mnemonic, Language::English, "").unwrap();

[src]

Validate a mnemonic phrase

The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039

Note: you cannot use this function to determine anything more than whether the mnemonic phrase itself is intact, it does not check the password or compute the seed value. For that, you should use Mnemonic::from_string().

Example

use bip39::{Mnemonic, Language};

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

match Mnemonic::validate(test_mnemonic, Language::English) {
    Ok(_) => { println!("valid: {}", test_mnemonic); },
    Err(e) => { println!("e: {}", e); return }
}

[src]

Get the original entropy value of the mnemonic phrase as an owned Vec

Example

use bip39::{Mnemonic, Language};

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

let mnemonic = Mnemonic::from_string(test_mnemonic, Language::English, "").unwrap();

let entropy: Vec<u8> = mnemonic.get_entropy();

Note: this function clones the internal entropy bytes

[src]

Get the mnemonic phrase as a string reference

[src]

Get the mnemonic phrase as an owned string

Note: this clones the internal Mnemonic String instance

[src]

Get the Language

[src]

Get a reference to the internal Seed

[src]

Get an owned Seed.

Note: this clones the internal Seed instance

[src]

Get the original entropy used to create the Mnemonic as a hex string

Note: this allocates a new String

[src]

Get the original entropy value of the mnemonic phrase as a slice

Example

use bip39::{Mnemonic, Language};

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

let mnemonic = Mnemonic::from_string(test_mnemonic, Language::English, "").unwrap();

let entropy: &[u8] = mnemonic.as_entropy();

Note: this function clones the internal entropy bytes

Trait Implementations

impl Debug for Mnemonic
[src]

[src]

Formats the value using the given formatter.

impl Clone for Mnemonic
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl AsRef<str> for Mnemonic
[src]

[src]

Performs the conversion.