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<S>(
key_type: &KeyType,
lang: Language,
password: S
) -> Result<Bip39, Bip39Error> where
S: Into<String>,
key_type: &KeyType,
lang: Language,
password: S
) -> Result<Bip39, Bip39Error> where
S: Into<String>,
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<S>(
mnemonic: S,
lang: Language,
password: S
) -> Result<Bip39, Bip39Error> where
S: Into<String>,
mnemonic: S,
lang: Language,
password: S
) -> Result<Bip39, Bip39Error> where
S: Into<String>,
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, Language::English, "").unwrap();
fn validate<S>(mnemonic: S, lang: &Language) -> Result<(), Bip39Error> where
S: Into<String>,
S: Into<String>,
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(_) => { println!("valid: {}", test_mnemonic); }, Err(e) => { println!("e: {}", e); return } }