keyfork/crates/util/keyfork-prompt/examples/test-basic-prompt.rs

39 lines
1022 B
Rust
Raw Normal View History

2024-01-16 02:44:48 +00:00
//!
use std::io::{stdin, stdout};
use keyfork_prompt::{
validators::{mnemonic, Validator},
2024-01-11 04:28:56 +00:00
Terminal, PromptHandler,
};
2024-01-07 04:23:41 +00:00
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut mgr = Terminal::new(stdin(), stdout())?;
let transport_validator = mnemonic::MnemonicSetValidator {
word_lengths: [9, 24],
};
let combine_validator = mnemonic::MnemonicSetValidator {
word_lengths: [24, 48],
};
let mnemonics = mgr.prompt_validated_wordlist(
"Enter a 9-word and 24-word mnemonic: ",
&Default::default(),
3,
transport_validator.to_fn(),
)?;
assert_eq!(mnemonics[0].as_bytes().len(), 12);
assert_eq!(mnemonics[1].as_bytes().len(), 32);
let mnemonics = mgr.prompt_validated_wordlist(
"Enter a 24 and 48-word mnemonic: ",
&Default::default(),
3,
combine_validator.to_fn(),
)?;
assert_eq!(mnemonics[0].as_bytes().len(), 32);
assert_eq!(mnemonics[1].as_bytes().len(), 64);
Ok(())
}