From f189a6af2ef6e25ac6618b6c15656dd9ddfe4d99 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Wed, 22 Jan 2025 12:05:43 -0800 Subject: [PATCH] Check seed phrase entropy and warn user when using a 12-word seed. (#1846) --- cmd/soroban-cli/src/commands/keys/add.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/soroban-cli/src/commands/keys/add.rs b/cmd/soroban-cli/src/commands/keys/add.rs index 265b090f6..a0494b4d9 100644 --- a/cmd/soroban-cli/src/commands/keys/add.rs +++ b/cmd/soroban-cli/src/commands/keys/add.rs @@ -2,7 +2,12 @@ use clap::command; use crate::{ commands::global, - config::{address::KeyName, key, locator, secret}, + config::{ + address::KeyName, + key::{self, Key}, + locator, + secret::{self, Secret}, + }, print::Print, }; @@ -40,9 +45,21 @@ impl Cmd { } else { self.secrets.read_secret()?.into() }; + let print = Print::new(global_args.quiet); let path = self.config_locator.write_key(&self.name, &key)?; + + if let Key::Secret(Secret::SeedPhrase { seed_phrase }) = key { + if seed_phrase.split_whitespace().count() < 24 { + print.warnln("The provided seed phrase lacks sufficient entropy and should be avoided. Using a 24-word seed phrase is a safer option.".to_string()); + print.warnln( + "To generate a new key, use the `stellar keys generate` command.".to_string(), + ); + } + } + print.checkln(format!("Key saved with alias {:?} in {path:?}", self.name)); + Ok(()) } }