keygen: Improve messaging around BIP39 passphrase usage
This commit is contained in:
parent
3abb39c04f
commit
53423c99aa
|
@ -248,7 +248,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("new")
|
SubCommand::with_name("new")
|
||||||
.about("Generate new keypair file from a passphrase and random seed phrase")
|
.about("Generate new keypair file from a random seed phrase and optional BIP39 passphrase")
|
||||||
.setting(AppSettings::DisableVersion)
|
.setting(AppSettings::DisableVersion)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("outfile")
|
Arg::with_name("outfile")
|
||||||
|
@ -284,8 +284,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("no_passphrase")
|
Arg::with_name("no_passphrase")
|
||||||
.long("no-passphrase")
|
.long("no-bip39-passphrase")
|
||||||
.help("Do not prompt for a passphrase"),
|
.alias("no-passphrase")
|
||||||
|
.help("Do not prompt for a BIP39 passphrase"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("no_outfile")
|
Arg::with_name("no_outfile")
|
||||||
|
@ -382,7 +383,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("recover")
|
SubCommand::with_name("recover")
|
||||||
.about("Recover keypair from seed phrase and passphrase")
|
.about("Recover keypair from seed phrase and optional BIP39 passphrase")
|
||||||
.setting(AppSettings::DisableVersion)
|
.setting(AppSettings::DisableVersion)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("outfile")
|
Arg::with_name("outfile")
|
||||||
|
@ -462,15 +463,31 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
|
||||||
"italian" => Language::Italian,
|
"italian" => Language::Italian,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let silent = matches.is_present("silent");
|
||||||
|
if !silent {
|
||||||
|
println!("Generating a new keypair");
|
||||||
|
}
|
||||||
let mnemonic = Mnemonic::new(mnemonic_type, language);
|
let mnemonic = Mnemonic::new(mnemonic_type, language);
|
||||||
let passphrase = if matches.is_present("no_passphrase") {
|
let passphrase = if matches.is_present("no_passphrase") {
|
||||||
NO_PASSPHRASE.to_string()
|
NO_PASSPHRASE.to_string()
|
||||||
} else {
|
} else {
|
||||||
println!("Generating a new keypair");
|
let passphrase = prompt_passphrase(
|
||||||
prompt_passphrase(
|
"\nFor added security, enter a BIP39 passphrase\n\
|
||||||
"For added security, enter a passphrase (empty for no passphrase): ",
|
\nNOTE! This passphrase improves security of the recovery seed phrase NOT the\n\
|
||||||
)?
|
keypair file itself, which is stored as insecure plain text\n\
|
||||||
|
\nBIP39 Passphrase (empty for none): ",
|
||||||
|
)?;
|
||||||
|
println!();
|
||||||
|
passphrase
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let passphrase_message = if passphrase == NO_PASSPHRASE {
|
||||||
|
"".to_string()
|
||||||
|
} else {
|
||||||
|
" and your BIP39 passphrase".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
let seed = Seed::new(&mnemonic, &passphrase);
|
let seed = Seed::new(&mnemonic, &passphrase);
|
||||||
let keypair = keypair_from_seed(seed.as_bytes())?;
|
let keypair = keypair_from_seed(seed.as_bytes())?;
|
||||||
|
|
||||||
|
@ -479,13 +496,12 @@ fn do_main(matches: &ArgMatches<'_>) -> Result<(), Box<dyn error::Error>> {
|
||||||
.map_err(|err| format!("Unable to write {}: {}", outfile, err))?;
|
.map_err(|err| format!("Unable to write {}: {}", outfile, err))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let silent = matches.is_present("silent");
|
|
||||||
if !silent {
|
if !silent {
|
||||||
let phrase: &str = mnemonic.phrase();
|
let phrase: &str = mnemonic.phrase();
|
||||||
let divider = String::from_utf8(vec![b'='; phrase.len()]).unwrap();
|
let divider = String::from_utf8(vec![b'='; phrase.len()]).unwrap();
|
||||||
println!(
|
println!(
|
||||||
"{}\npubkey: {}\n{}\nSave this seed phrase to recover your new keypair:\n{}\n{}",
|
"{}\npubkey: {}\n{}\nSave this seed phrase{} to recover your new keypair:\n{}\n{}",
|
||||||
÷r, keypair.pubkey(), ÷r, phrase, ÷r
|
÷r, keypair.pubkey(), ÷r, passphrase_message, phrase, ÷r
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue