diff --git a/Cargo.lock b/Cargo.lock index 9d44e32e1..abd0f54aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1904,7 +1904,7 @@ dependencies = [ "embedded-io-async", "futures-sink", "futures-util", - "heapless", + "heapless 0.8.0", ] [[package]] @@ -2023,7 +2023,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.52.0", ] [[package]] @@ -2483,6 +2483,17 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "heapless" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ba4bd83f9415b58b4ed8dc5714c76e626a105be4646c02630ad730ad3b5aa4" +dependencies = [ + "hash32", + "stable_deref_trait", + "zeroize", +] + [[package]] name = "heck" version = "0.3.3" @@ -4344,7 +4355,7 @@ dependencies = [ "once_cell", "socket2 0.5.10", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.52.0", ] [[package]] @@ -4712,7 +4723,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.60.2", + "windows-sys 0.52.0", ] [[package]] @@ -5445,7 +5456,7 @@ dependencies = [ "stellar-asset-spec", "stellar-ledger", "stellar-rpc-client", - "stellar-strkey 0.0.16", + "stellar-strkey 0.0.18", "stellar-xdr", "strsim", "strum 0.17.1", @@ -5657,7 +5668,7 @@ dependencies = [ "serde", "serde_json", "soroban-spec", - "stellar-strkey 0.0.16", + "stellar-strkey 0.0.18", "stellar-xdr", "thiserror 1.0.69", "tokio", @@ -5712,7 +5723,7 @@ dependencies = [ "soroban-spec-tools", "stellar-ledger", "stellar-rpc-client", - "stellar-strkey 0.0.16", + "stellar-strkey 0.0.18", "test-case", "testcontainers", "thiserror 1.0.69", @@ -5833,7 +5844,7 @@ dependencies = [ "serde_json", "serial_test", "sha2 0.10.9", - "stellar-strkey 0.0.16", + "stellar-strkey 0.0.18", "stellar-xdr", "test-case", "testcontainers", @@ -5883,14 +5894,26 @@ version = "0.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "084afcb0d458c3d5d5baa2d294b18f881e62cc258ef539d8fdf68be7dbe45520" dependencies = [ - "clap", "crate-git-revision 0.0.6", "data-encoding", - "heapless", + "heapless 0.8.0", +] + +[[package]] +name = "stellar-strkey" +version = "0.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f34ff61c0ca6f1c2b4169e8d1633417bd9225f58b6175e4e317204565d16277" +dependencies = [ + "clap", + "crate-git-revision 0.0.9", + "data-encoding", + "heapless 0.9.3", "serde", "serde_json", "serde_with", "thiserror 1.0.69", + "zeroize", ] [[package]] @@ -6105,7 +6128,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.0.8", - "windows-sys 0.60.2", + "windows-sys 0.52.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 90664eb5d..faee724ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ version = "27.0.0" # Dependencies from elsewhere shared by crates: [workspace.dependencies] -stellar-strkey = "0.0.16" +stellar-strkey = "0.0.18" sep5 = "0.1.0" base64 = "0.21.2" thiserror = "1.0.46" diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index fb58fc4f8..3cb670b30 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -4396,7 +4396,7 @@ Print version information Decode and encode strkey -**Usage:** `stellar strkey ` +**Usage:** `stellar strkey [OPTIONS] ` ###### **Subcommands:** @@ -4405,25 +4405,25 @@ Decode and encode strkey - `zero` — Generate the zero strkey - `version` — Print version information +###### **Options:** + +- `-q`, `--quiet` — Suppress stderr log and warning output + ## `stellar strkey decode` Decode strkey -**Usage:** `stellar strkey decode ` +Reads the strkey from stdin. -###### **Arguments:** - -- `` — Strkey to decode +**Usage:** `stellar strkey decode` ## `stellar strkey encode` Encode strkey -**Usage:** `stellar strkey encode ` - -###### **Arguments:** +Reads the JSON from stdin. -- `` — JSON for Strkey to encode +**Usage:** `stellar strkey encode` ## `stellar strkey zero` diff --git a/cmd/crates/soroban-spec-tools/src/utils.rs b/cmd/crates/soroban-spec-tools/src/utils.rs index f030cc0f8..744063f7d 100644 --- a/cmd/crates/soroban-spec-tools/src/utils.rs +++ b/cmd/crates/soroban-spec-tools/src/utils.rs @@ -22,9 +22,9 @@ pub fn contract_id_from_str(contract_id: &str) -> Result<[u8; 32], stellar_strke .or_else(|_| { // strkey failed, try to parse it as a hex string, for backwards compatibility. padded_hex_from_str(contract_id, 32) - .map_err(|_| stellar_strkey::DecodeError::Invalid)? + .map_err(|_| stellar_strkey::DecodeError::InvalidPayloadLength)? .try_into() - .map_err(|_| stellar_strkey::DecodeError::Invalid) + .map_err(|_| stellar_strkey::DecodeError::InvalidPayloadLength) }) - .map_err(|_| stellar_strkey::DecodeError::Invalid) + .map_err(|_| stellar_strkey::DecodeError::InvalidPayloadLength) } diff --git a/cmd/crates/soroban-test/src/lib.rs b/cmd/crates/soroban-test/src/lib.rs index 55921de18..4c6a8c762 100644 --- a/cmd/crates/soroban-test/src/lib.rs +++ b/cmd/crates/soroban-test/src/lib.rs @@ -297,6 +297,7 @@ impl TestEnv { self.cmd::(&format!("--hd-path={hd_path}")) .private_key() .unwrap() + .as_unredacted() ) } diff --git a/cmd/crates/soroban-test/tests/it/strkey.rs b/cmd/crates/soroban-test/tests/it/strkey.rs index 77e594848..785fe803c 100644 --- a/cmd/crates/soroban-test/tests/it/strkey.rs +++ b/cmd/crates/soroban-test/tests/it/strkey.rs @@ -5,10 +5,8 @@ fn decode() { let sandbox = TestEnv::default(); sandbox .new_assert_cmd("strkey") - .args([ - "decode", - "GAZTAML6YJA5PGKDXONKPSHKL6FYT6OG5I2R7YB7R3B5CETRG7KIJONK", - ]) + .args(["decode"]) + .write_stdin("GAZTAML6YJA5PGKDXONKPSHKL6FYT6OG5I2R7YB7R3B5CETRG7KIJONK") .assert() .success() .stdout( @@ -24,7 +22,8 @@ fn encode() { let sandbox = TestEnv::default(); sandbox .new_assert_cmd("strkey") - .args(["encode", r#"{"public_key_ed25519":"3330317ec241d79943bb9aa7c8ea5f8b89f9c6ea351fe03f8ec3d1127137d484"}"#]) + .args(["encode"]) + .write_stdin(r#"{"public_key_ed25519":"3330317ec241d79943bb9aa7c8ea5f8b89f9c6ea351fe03f8ec3d1127137d484"}"#) .assert() .success() .stdout("GAZTAML6YJA5PGKDXONKPSHKL6FYT6OG5I2R7YB7R3B5CETRG7KIJONK\n"); diff --git a/cmd/soroban-cli/src/commands/keys/secret.rs b/cmd/soroban-cli/src/commands/keys/secret.rs index 9fc00279c..b2a97395f 100644 --- a/cmd/soroban-cli/src/commands/keys/secret.rs +++ b/cmd/soroban-cli/src/commands/keys/secret.rs @@ -40,7 +40,7 @@ impl Cmd { if self.phrase { println!("{}", self.seed_phrase()?); } else { - println!("{}", self.private_key()?); + println!("{}", self.private_key()?.as_unredacted()); } Ok(()) diff --git a/cmd/soroban-cli/src/commands/network/root_account/secret.rs b/cmd/soroban-cli/src/commands/network/root_account/secret.rs index a99ab8d45..36cb7800d 100644 --- a/cmd/soroban-cli/src/commands/network/root_account/secret.rs +++ b/cmd/soroban-cli/src/commands/network/root_account/secret.rs @@ -13,7 +13,7 @@ impl Cmd { pub fn run(&self) -> Result<(), Error> { let root_key = self.args.root_key()?; let private_key = PrivateKey::from_payload(&root_key)?; - println!("{private_key}"); + println!("{}", private_key.as_unredacted()); Ok(()) } } diff --git a/cmd/soroban-cli/src/config/key.rs b/cmd/soroban-cli/src/config/key.rs index 6180e2ed5..5f281f3ed 100644 --- a/cmd/soroban-cli/src/config/key.rs +++ b/cmd/soroban-cli/src/config/key.rs @@ -177,7 +177,10 @@ mod test { } #[test] fn secret_key() { - let secret_key = format!("{}", stellar_strkey::ed25519::PrivateKey([0; 32])); + let secret_key = format!( + "{}", + stellar_strkey::ed25519::PrivateKey([0; 32]).as_unredacted() + ); let secret = Secret::SecretKey { secret_key }; let key = Key::Secret(secret); round_trip(&key); diff --git a/cmd/soroban-cli/src/config/secret.rs b/cmd/soroban-cli/src/config/secret.rs index 754097dd6..93630d545 100644 --- a/cmd/soroban-cli/src/config/secret.rs +++ b/cmd/soroban-cli/src/config/secret.rs @@ -130,7 +130,7 @@ impl FromStr for Secret { impl From for Secret { fn from(value: PrivateKey) -> Self { Secret::SecretKey { - secret_key: format!("{value}"), + secret_key: format!("{}", value.as_unredacted()), } } } @@ -285,7 +285,7 @@ mod tests { assert!(matches!(secret, Secret::SecretKey { .. })); assert_eq!(public_key.to_string(), TEST_PUBLIC_KEY); - assert_eq!(private_key.to_string(), TEST_SECRET_KEY); + assert_eq!(private_key.as_unredacted().to_string(), TEST_SECRET_KEY); } #[test] @@ -296,7 +296,7 @@ mod tests { assert!(matches!(secret, Secret::SeedPhrase { .. })); assert_eq!(public_key.to_string(), TEST_PUBLIC_KEY); - assert_eq!(private_key.to_string(), TEST_SECRET_KEY); + assert_eq!(private_key.as_unredacted().to_string(), TEST_SECRET_KEY); } #[test] @@ -463,7 +463,7 @@ mod tests { let pk = secret.public_key(Some(0)).unwrap(); let sk = secret.private_key(Some(0)).unwrap(); assert_eq!(pk.to_string(), TEST_PUBLIC_KEY); - assert_eq!(sk.to_string(), TEST_SECRET_KEY); + assert_eq!(sk.as_unredacted().to_string(), TEST_SECRET_KEY); } #[test] diff --git a/cmd/soroban-cli/src/utils.rs b/cmd/soroban-cli/src/utils.rs index 3a103fbad..9d8da982b 100644 --- a/cmd/soroban-cli/src/utils.rs +++ b/cmd/soroban-cli/src/utils.rs @@ -109,9 +109,9 @@ pub fn contract_id_from_str( // strkey failed, try to parse it as a hex string, for backwards compatibility. stellar_strkey::Contract( soroban_spec_tools::utils::padded_hex_from_str(contract_id, 32) - .map_err(|_| stellar_strkey::DecodeError::Invalid)? + .map_err(|_| stellar_strkey::DecodeError::InvalidPayloadLength)? .try_into() - .map_err(|_| stellar_strkey::DecodeError::Invalid)?, + .map_err(|_| stellar_strkey::DecodeError::InvalidPayloadLength)?, ) }, )