Skip to content

Commit 2c263af

Browse files
Embed strkey CLI command for encoding and decoding address strings (#2324)
### What Upgrade stellar-strkey from 0.0.13 to 0.0.15, enable the cli feature, and add a new `strkey` subcommand to the CLI. ### Why Expose strkey encoding and decoding functionality directly in the CLI, matching the existing pattern used for XDR. For advanced use cases it is helpful to be able to extract components out of addresses. The use cases this is most relevant is cross-chain protocols who prefer to work with the raw payloads within the addresses.
1 parent 861af9b commit 2c263af

File tree

6 files changed

+60
-6
lines changed

6 files changed

+60
-6
lines changed

Cargo.lock

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ version = "23.2.1"
7878

7979
# Dependencies from elsewhere shared by crates:
8080
[workspace.dependencies]
81-
stellar-strkey = "0.0.13"
81+
stellar-strkey = "0.0.15"
8282
sep5 = "0.0.4"
8383
base64 = "0.21.2"
8484
thiserror = "1.0.46"

cmd/crates/soroban-test/tests/it/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ mod integration;
99
mod log;
1010
mod plugin;
1111
mod rpc_provider;
12+
mod strkey;
1213
mod util;
1314
mod version;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use soroban_test::TestEnv;
2+
3+
#[test]
4+
fn decode() {
5+
let sandbox = TestEnv::default();
6+
sandbox
7+
.new_assert_cmd("strkey")
8+
.args([
9+
"decode",
10+
"GAZTAML6YJA5PGKDXONKPSHKL6FYT6OG5I2R7YB7R3B5CETRG7KIJONK",
11+
])
12+
.assert()
13+
.success()
14+
.stdout(
15+
r#"{
16+
"public_key_ed25519": "3330317ec241d79943bb9aa7c8ea5f8b89f9c6ea351fe03f8ec3d1127137d484"
17+
}
18+
"#,
19+
);
20+
}
21+
22+
#[test]
23+
fn encode() {
24+
let sandbox = TestEnv::default();
25+
sandbox
26+
.new_assert_cmd("strkey")
27+
.args(["encode", r#"{"public_key_ed25519":"3330317ec241d79943bb9aa7c8ea5f8b89f9c6ea351fe03f8ec3d1127137d484"}"#])
28+
.assert()
29+
.success()
30+
.stdout("GAZTAML6YJA5PGKDXONKPSHKL6FYT6OG5I2R7YB7R3B5CETRG7KIJONK\n");
31+
}

cmd/soroban-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ soroban-spec-rust = { workspace = true }
4242
soroban-spec-tools = { workspace = true }
4343
soroban-spec-typescript = { workspace = true }
4444
soroban-ledger-snapshot = { workspace = true }
45-
stellar-strkey = { workspace = true }
45+
stellar-strkey = { workspace = true, features = ["cli"] }
4646
soroban-sdk = { workspace = true }
4747
stellar-asset-spec = { workspace = true }
4848
soroban-rpc = { workspace = true }

cmd/soroban-cli/src/commands/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl Root {
130130
Cmd::Config(config) => config.run()?,
131131
Cmd::Events(events) => events.run().await?,
132132
Cmd::Xdr(xdr) => xdr.run()?,
133+
Cmd::Strkey(strkey) => strkey.run()?,
133134
Cmd::Network(network) => network.run(&self.global_args).await?,
134135
Cmd::Container(container) => container.run(&self.global_args).await?,
135136
Cmd::Snapshot(snapshot) => snapshot.run(&self.global_args).await?,
@@ -202,6 +203,9 @@ pub enum Cmd {
202203
/// Decode and encode XDR
203204
Xdr(stellar_xdr::cli::Root),
204205

206+
/// Decode and encode strkey
207+
Strkey(stellar_strkey::cli::Root),
208+
205209
/// Print shell completion code for the specified shell.
206210
#[command(long_about = completion::LONG_ABOUT)]
207211
Completion(completion::Cmd),
@@ -243,6 +247,9 @@ pub enum Error {
243247
#[error(transparent)]
244248
Xdr(#[from] stellar_xdr::cli::Error),
245249

250+
#[error(transparent)]
251+
Strkey(#[from] stellar_strkey::cli::Error),
252+
246253
#[error(transparent)]
247254
Clap(#[from] clap::error::Error),
248255

0 commit comments

Comments
 (0)