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

automerge
This commit is contained in:
mergify[bot]
2019-12-03 21:56:06 -08:00
committed by Grimes
parent 9596e7772c
commit 905428bee6

View File

@ -1,7 +1,8 @@
use bip39::{Language, Mnemonic, MnemonicType, Seed}; use bip39::{Language, Mnemonic, MnemonicType, Seed};
use bs58; use bs58;
use clap::{ 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 num_cpus;
use solana_clap_utils::keypair::{ use solana_clap_utils::keypair::{
@ -75,6 +76,15 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.long("force") .long("force")
.help("Overwrite the output file if it exists"), .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(
Arg::with_name("no_passphrase") Arg::with_name("no_passphrase")
.long("no-passphrase") .long("no-passphrase")
@ -231,7 +241,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
None => (), 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") { let passphrase = if matches.is_present("no_passphrase") {
NO_PASSPHRASE.to_string() NO_PASSPHRASE.to_string()
} else { } else {