2024-08-11 23:25:25 +00:00
|
|
|
#![allow(missing_docs)]
|
2024-01-16 02:44:48 +00:00
|
|
|
|
2024-01-10 20:13:42 +00:00
|
|
|
use std::io::{stdin, stdout};
|
2023-12-21 17:04:35 +00:00
|
|
|
|
2024-01-10 20:13:42 +00:00
|
|
|
use keyfork_prompt::{
|
|
|
|
validators::{mnemonic, Validator},
|
2024-01-11 04:28:56 +00:00
|
|
|
Terminal, PromptHandler,
|
2024-01-10 20:13:42 +00:00
|
|
|
};
|
2023-12-21 17:04:35 +00:00
|
|
|
|
2024-08-01 13:50:30 +00:00
|
|
|
use keyfork_mnemonic::English;
|
2024-02-19 10:20:33 +00:00
|
|
|
|
2024-01-07 04:23:41 +00:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2024-01-11 03:35:31 +00:00
|
|
|
let mut mgr = Terminal::new(stdin(), stdout())?;
|
2024-01-10 20:13:42 +00:00
|
|
|
let transport_validator = mnemonic::MnemonicSetValidator {
|
|
|
|
word_lengths: [9, 24],
|
|
|
|
};
|
|
|
|
let combine_validator = mnemonic::MnemonicSetValidator {
|
|
|
|
word_lengths: [24, 48],
|
|
|
|
};
|
|
|
|
|
2024-02-19 10:32:24 +00:00
|
|
|
let mnemonics = mgr.prompt_validated_wordlist::<English, _>(
|
2024-01-10 20:13:42 +00:00
|
|
|
"Enter a 9-word and 24-word mnemonic: ",
|
|
|
|
3,
|
|
|
|
transport_validator.to_fn(),
|
|
|
|
)?;
|
2024-02-12 05:02:59 +00:00
|
|
|
assert_eq!(mnemonics[0].as_bytes().len(), 12);
|
|
|
|
assert_eq!(mnemonics[1].as_bytes().len(), 32);
|
2024-01-10 20:13:42 +00:00
|
|
|
|
2024-02-19 10:32:24 +00:00
|
|
|
let mnemonics = mgr.prompt_validated_wordlist::<English, _>(
|
2024-01-10 20:13:42 +00:00
|
|
|
"Enter a 24 and 48-word mnemonic: ",
|
|
|
|
3,
|
|
|
|
combine_validator.to_fn(),
|
|
|
|
)?;
|
2024-02-12 05:02:59 +00:00
|
|
|
assert_eq!(mnemonics[0].as_bytes().len(), 32);
|
|
|
|
assert_eq!(mnemonics[1].as_bytes().len(), 64);
|
2024-01-10 20:13:42 +00:00
|
|
|
|
2023-12-21 17:04:35 +00:00
|
|
|
Ok(())
|
|
|
|
}
|