(cherry picked from commit b874441a47)
			
			
This commit is contained in:
		
				
					committed by
					
						 Michael Vines
						Michael Vines
					
				
			
			
				
	
			
			
			
						parent
						
							a8d32103d1
						
					
				
				
					commit
					9eded7a227
				
			| @@ -41,6 +41,18 @@ impl KeypairWithSource { | ||||
|     } | ||||
| } | ||||
|  | ||||
| /// Prompts user for a passphrase and then asks for confirmirmation to check for mistakes | ||||
| pub fn prompt_passphrase(prompt: &str) -> Result<String, Box<dyn error::Error>> { | ||||
|     let passphrase = prompt_password_stderr(&prompt)?; | ||||
|     if !passphrase.is_empty() { | ||||
|         let confirmed = rpassword::prompt_password_stderr("Enter same passphrase again: ")?; | ||||
|         if confirmed != passphrase { | ||||
|             return Err("Passphrases did not match".into()); | ||||
|         } | ||||
|     } | ||||
|     Ok(passphrase) | ||||
| } | ||||
|  | ||||
| /// Reads user input from stdin to retrieve a seed phrase and passphrase for keypair derivation | ||||
| pub fn keypair_from_seed_phrase( | ||||
|     keypair_name: &str, | ||||
| @@ -54,11 +66,11 @@ pub fn keypair_from_seed_phrase( | ||||
|     ); | ||||
|  | ||||
|     if skip_validation { | ||||
|         let passphrase = prompt_password_stderr(&passphrase_prompt)?; | ||||
|         let passphrase = prompt_passphrase(&passphrase_prompt)?; | ||||
|         keypair_from_seed_phrase_and_passphrase(&seed_phrase, &passphrase) | ||||
|     } else { | ||||
|         let mnemonic = Mnemonic::from_phrase(seed_phrase, Language::English)?; | ||||
|         let passphrase = prompt_password_stderr(&passphrase_prompt)?; | ||||
|         let passphrase = prompt_passphrase(&passphrase_prompt)?; | ||||
|         let seed = Seed::new(&mnemonic, &passphrase); | ||||
|         keypair_from_seed(seed.as_bytes()) | ||||
|     } | ||||
|   | ||||
| @@ -5,7 +5,7 @@ use clap::{ | ||||
| }; | ||||
| use num_cpus; | ||||
| use solana_clap_utils::keypair::{ | ||||
|     keypair_from_seed_phrase, ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG, | ||||
|     keypair_from_seed_phrase, prompt_passphrase, ASK_KEYWORD, SKIP_SEED_PHRASE_VALIDATION_ARG, | ||||
| }; | ||||
| use solana_sdk::{ | ||||
|     pubkey::write_pubkey_file, | ||||
| @@ -236,8 +236,8 @@ fn main() -> Result<(), Box<dyn error::Error>> { | ||||
|                 NO_PASSPHRASE.to_string() | ||||
|             } else { | ||||
|                 eprintln!("Generating a new keypair"); | ||||
|                 rpassword::prompt_password_stderr( | ||||
|                     "For added security, enter a passphrase (empty for no passphrase):", | ||||
|                 prompt_passphrase( | ||||
|                     "For added security, enter a passphrase (empty for no passphrase): ", | ||||
|                 )? | ||||
|             }; | ||||
|             let seed = Seed::new(&mnemonic, &passphrase); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user