diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index 46d59553a4..f34bc4686d 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -6675,6 +6675,7 @@ dependencies = [ "pallet-transaction-payment 2.0.0", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rpassword 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-runtime 2.0.0", diff --git a/substrate/bin/utils/subkey/Cargo.toml b/substrate/bin/utils/subkey/Cargo.toml index ca3519ae27..2fcd2aa473 100644 --- a/substrate/bin/utils/subkey/Cargo.toml +++ b/substrate/bin/utils/subkey/Cargo.toml @@ -20,6 +20,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0" } frame-system = { version = "2.0.0", path = "../../../frame/system" } pallet-balances = { version = "2.0.0", path = "../../../frame/balances" } pallet-transaction-payment = { version = "2.0.0", path = "../../../frame/transaction-payment" } +rpassword = "4.0.1" [features] bench = [] diff --git a/substrate/bin/utils/subkey/src/main.rs b/substrate/bin/utils/subkey/src/main.rs index 10a2e13170..e89e0466ea 100644 --- a/substrate/bin/utils/subkey/src/main.rs +++ b/substrate/bin/utils/subkey/src/main.rs @@ -167,6 +167,7 @@ fn get_app<'a, 'b>() -> App<'a, 'b> { [network] -n, --network 'Specify a network. One of substrate \ (default), polkadot, kusama, dothereum, edgeware, or kulupu' [password] -p, --password 'The password for the key' + --password-interactive 'You will be prompted for the password for the key.' ") .subcommands(vec![ SubCommand::with_name("generate") @@ -177,8 +178,9 @@ fn get_app<'a, 'b>() -> App<'a, 'b> { "), SubCommand::with_name("inspect") .about("Gets a public key and a SS58 address from the provided Secret URI") - .args_from_usage(" 'A Key URI to be inspected. May be a secret seed, \ - secret URI (with derivation paths and password), SS58 or public URI.' + .args_from_usage("[uri] 'A Key URI to be inspected. May be a secret seed, \ + secret URI (with derivation paths and password), SS58 or public URI. \ + If not given, you will be prompted for the URI.' "), SubCommand::with_name("sign") .about("Sign a message, provided on STDIN, with a given (secret) key") @@ -240,7 +242,21 @@ where SignatureOf: SignatureT, PublicOf: PublicT, { + let password_interactive = matches.is_present("password-interactive"); let password = matches.value_of("password"); + + let password = if password.is_some() && password_interactive { + panic!("`--password` given and `--password-interactive` selected!"); + } else if password_interactive { + Some( + rpassword::read_password_from_tty(Some("Key password: ")) + .expect("Reads password from tty") + ) + } else { + password.map(Into::into) + }; + let password = password.as_ref().map(String::as_str); + let maybe_network: Option = matches.value_of("network").map(|network| { network .try_into() @@ -255,10 +271,13 @@ where C::print_from_uri(mnemonic.phrase(), password, maybe_network); } ("inspect", Some(matches)) => { - let uri = matches - .value_of("uri") - .expect("URI parameter is required; thus it can't be None; qed"); - C::print_from_uri(uri, password, maybe_network); + let uri = match matches.value_of("uri") { + Some(uri) => uri.into(), + None => rpassword::read_password_from_tty(Some("URI: ")) + .expect("Failed to read URI"), + }; + + C::print_from_uri(&uri, password, maybe_network); } ("sign", Some(matches)) => { let should_decode = matches.is_present("hex"); diff --git a/substrate/client/cli/Cargo.toml b/substrate/client/cli/Cargo.toml index 937135a8c3..49f327405b 100644 --- a/substrate/client/cli/Cargo.toml +++ b/substrate/client/cli/Cargo.toml @@ -42,5 +42,5 @@ tempfile = "3.1.0" [features] wasmtime = [ - "sc-service/wasmtime", + "sc-service/wasmtime", ]