Struct bip39::bip39::Bip39
[−]
[src]
pub struct Bip39 {
pub mnemonic: String,
pub seed: Vec<u8>,
pub lang: Language,
}Fields
mnemonic: String
seed: Vec<u8>
lang: Language
Methods
impl Bip39[src]
fn new(key_type: &KeyType,
lang: Language,
password: &str)
-> Result<Bip39, Bip39Error>
lang: Language,
password: &str)
-> Result<Bip39, Bip39Error>
Generates a new Bip39 struct
When returned, the struct will be filled in with the phrase and the seed value as 64 bytes raw
Example
use bip39::{Bip39, KeyType, Language}; let kt = KeyType::for_word_length(12).unwrap(); let bip39 = match Bip39::new(&kt, Language::English, "") { Ok(b) => b, Err(e) => { println!("e: {:?}", e); return } }; let phrase = &bip39.mnemonic; let seed = &bip39.seed; println!("phrase: {}", phrase);
fn from_mnemonic(mnemonic: String,
lang: Language,
password: String)
-> Result<Bip39, Bip39Error>
lang: Language,
password: String)
-> Result<Bip39, Bip39Error>
Create a Bip39 struct 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::{Bip39, KeyType, Language}; let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle"; let b = Bip39::from_mnemonic(test_mnemonic.to_string(), Language::English, "".to_string()).unwrap();
fn validate(mnemonic: &str, lang: &Language) -> Result<(), Bip39Error>
Validate a mnemonic phrase
The phrase supplied will be checked for word length and validated according to the checksum specified in BIP0039
Example
use bip39::{Bip39, KeyType, Language}; let test_mnemonic = "park remain person kitchen mule spell knee armed position rail grid ankle"; match Bip39::validate(test_mnemonic, &Language::English) { Ok(_) => {}, Err(e) => {} }