Allow generation of longer seed phrases with keygen (#7210)

This commit is contained in:
Justin Starry 2019-12-03 23:39:45 -05:00 committed by GitHub
parent 94dcd3fe12
commit e1b7f40c2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -1,7 +1,8 @@
use bip39::{Language, Mnemonic, MnemonicType, Seed};
use bs58;
use clap::{
crate_description, crate_name, values_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
crate_description, crate_name, value_t, values_t_or_exit, App, AppSettings, Arg, ArgMatches,
SubCommand,
};
use num_cpus;
use solana_clap_utils::keypair::{
@ -75,6 +76,15 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("force")
.help("Overwrite the output file if it exists"),
)
.arg(
Arg::with_name("word_count")
.long("word-count")
.possible_values(&["12", "15", "18", "21", "24"])
.default_value("12")
.value_name("NUM")
.takes_value(true)
.help("Specify the number of words that will be present in the generated seed phrase"),
)
.arg(
Arg::with_name("no_passphrase")
.long("no-passphrase")
@ -231,7 +241,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
None => (),
}
let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English);
let word_count = value_t!(matches.value_of("word_count"), usize).unwrap();
let mnemonic_type = MnemonicType::for_word_count(word_count)?;
let mnemonic = Mnemonic::new(mnemonic_type, Language::English);
let passphrase = if matches.is_present("no_passphrase") {
NO_PASSPHRASE.to_string()
} else {