Implement mnemonic retry #8

Closed
opened 2024-01-01 18:27:21 +00:00 by ryan · 1 comment
Owner

This could probably be done in the prompt_wordlist method. I think I could change it to be a method with the following type signature:

pub fn prompt_wordlist<F, R, E>(prompt: Message, wordlist: &Wordlist, retries: u8, validator_fn: F) -> Result<R, Error>
    where F: Fn(str) -> Result<R, E>,
        E: std::error::Error

Could then be called as:

let mnemonic = pm.prompt_wordlist(Message::Text("Wordlist: ", &wordlist, 3, Mnemonic::from_str)?;

Or:

let (nonce, key) = pm.prompt_wordlist(Message::Text("Wordlist: ", &wordlist, 3, |s| {
    let (nonce_mnemonic, key_mnemonic) = split_after_word(s, 9);
    let nonce = Mnemonic::from_str(nonce_mnemonic)?;
    let key = Mnemonic::from_str(key_mnemonic)?;
    (nonce, key)
})?;
This could probably be done in the prompt_wordlist method. I think I could change it to be a method with the following type signature: ```rust pub fn prompt_wordlist<F, R, E>(prompt: Message, wordlist: &Wordlist, retries: u8, validator_fn: F) -> Result<R, Error> where F: Fn(str) -> Result<R, E>, E: std::error::Error ``` Could then be called as: ```rust let mnemonic = pm.prompt_wordlist(Message::Text("Wordlist: ", &wordlist, 3, Mnemonic::from_str)?; ``` Or: ```rust let (nonce, key) = pm.prompt_wordlist(Message::Text("Wordlist: ", &wordlist, 3, |s| { let (nonce_mnemonic, key_mnemonic) = split_after_word(s, 9); let nonce = Mnemonic::from_str(nonce_mnemonic)?; let key = Mnemonic::from_str(key_mnemonic)?; (nonce, key) })?; ```
Author
Owner

somewhat added, need to work on a Mnemonic parser and MnemonicSet parser.

somewhat added, need to work on a `Mnemonic` parser and `MnemonicSet` parser.
ryan closed this issue 2024-01-10 20:38:00 +00:00
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: public/keyfork#8
No description provided.