Skip to content

Commit 3f3fde4

Browse files
Merge remote-tracking branch 'origin/main' into ledger-entry-get
2 parents 51213fd + 197fcc0 commit 3f3fde4

File tree

4 files changed

+205
-78
lines changed

4 files changed

+205
-78
lines changed

FULL_HELP_DOCS.md

Lines changed: 12 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ Add a new identity (keypair, ledger, OS specific secure store)
11071107
* `--global` — ⚠️ Deprecated: global config is always on
11081108
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
11091109
* `--public-key <PUBLIC_KEY>` — Add a public key, ed25519, or muxed account, e.g. G1.., M2..
1110+
* `--overwrite` — Overwrite existing identity if it already exists
11101111

11111112

11121113

@@ -4007,7 +4008,6 @@ Fetch ledger entries. This command supports all types of ledger entries supporte
40074008

40084009
* `account` — Fetch account entry by public key or alias
40094010
* `contract-data` — Fetch contract ledger entry by address or alias and storage key
4010-
* `config` — Fetch the current network config by `ConfigSettingId`. All config settings are returned if no id is provided
40114011
* `claimable-balance` — Fetch a claimable balance ledger entry by id
40124012
* `liquidity-pool` — Fetch a liquidity pool ledger entry by id
40134013
* `contract-code` — Fetch a Contract's WASM bytecode by WASM hash
@@ -4021,14 +4021,11 @@ Fetch ledger entries. This command supports all types of ledger entries supporte
40214021

40224022
Fetch account entry by public key or alias
40234023

4024-
**Usage:** `stellar ledger entry fetch account [OPTIONS] <ACCOUNT>`
4025-
4026-
###### **Arguments:**
4027-
4028-
* `<ACCOUNT>` — Account alias or address to lookup
4024+
**Usage:** `stellar ledger entry fetch account [OPTIONS] --account <ACCOUNT>`
40294025

40304026
###### **Options:**
40314027

4028+
* `--account <ACCOUNT>` — Account alias or address to lookup
40324029
* `--rpc-url <RPC_URL>` — RPC server endpoint
40334030
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
40344031
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
@@ -4047,7 +4044,6 @@ Fetch account entry by public key or alias
40474044
- `xdr`:
40484045
Original RPC output (containing XDRs)
40494046

4050-
* `--hide-account` — Hide the account ledger entry from the output
40514047
* `--hd-path <HD_PATH>` — If identity is a seed phrase use this hd path, default is 0
40524048

40534049

@@ -4056,14 +4052,11 @@ Fetch account entry by public key or alias
40564052

40574053
Fetch contract ledger entry by address or alias and storage key
40584054

4059-
**Usage:** `stellar ledger entry fetch contract-data [OPTIONS] <CONTRACT>`
4060-
4061-
###### **Arguments:**
4062-
4063-
* `<CONTRACT>` — Contract alias or address to fetch
4055+
**Usage:** `stellar ledger entry fetch contract-data [OPTIONS] --contract <CONTRACT>`
40644056

40654057
###### **Options:**
40664058

4059+
* `--contract <CONTRACT>` — Contract alias or address to fetch
40674060
* `--rpc-url <RPC_URL>` — RPC server endpoint
40684061
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
40694062
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
@@ -4097,68 +4090,15 @@ Fetch contract ledger entry by address or alias and storage key
40974090

40984091

40994092

4100-
## `stellar ledger entry fetch config`
4101-
4102-
Fetch the current network config by `ConfigSettingId`. All config settings are returned if no id is provided
4103-
4104-
**Usage:** `stellar ledger entry fetch config [OPTIONS] [CONFIG_SETTING_IDS]...`
4105-
4106-
###### **Arguments:**
4107-
4108-
* `<CONFIG_SETTING_IDS>` — Valid config setting IDs (Config Setting ID => Name):
4109-
0 => ContractMaxSizeBytes
4110-
1 => ContractComputeV0
4111-
2 => ContractLedgerCostV0
4112-
3 => ContractHistoricalDataV0
4113-
4 => ContractEventsV0
4114-
5 => ContractBandwidthV0
4115-
6 => ContractCostParamsCpuInstructions
4116-
7 => ContractCostParamsMemoryBytes
4117-
8 => ContractDataKeySizeBytes
4118-
9 => ContractDataEntrySizeBytes
4119-
10 => StateArchival
4120-
11 => ContractExecutionLanes
4121-
12 => LiveSorobanStateSizeWindow
4122-
13 => EvictionIterator
4123-
14 => ContractParallelComputeV0
4124-
15 => ContractLedgerCostExtV0
4125-
16 => ScpTiming
4126-
4127-
###### **Options:**
4128-
4129-
* `--rpc-url <RPC_URL>` — RPC server endpoint
4130-
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
4131-
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
4132-
* `-n`, `--network <NETWORK>` — Name of network to use from config
4133-
* `--global` — ⚠️ Deprecated: global config is always on
4134-
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
4135-
* `--output <OUTPUT>` — Format of the output
4136-
4137-
Default value: `json`
4138-
4139-
Possible values:
4140-
- `json`:
4141-
JSON output of the ledger entry with parsed XDRs (one line, not formatted)
4142-
- `json-formatted`:
4143-
Formatted (multiline) JSON output of the ledger entry with parsed XDRs
4144-
- `xdr`:
4145-
Original RPC output (containing XDRs)
4146-
4147-
4148-
4149-
41504093
## `stellar ledger entry fetch claimable-balance`
41514094

41524095
Fetch a claimable balance ledger entry by id
41534096

4154-
**Usage:** `stellar ledger entry fetch claimable-balance [OPTIONS] [IDS]...`
4155-
4156-
###### **Arguments:**
4157-
4158-
* `<IDS>` — Claimable Balance Ids to fetch an entry for
4097+
**Usage:** `stellar ledger entry fetch claimable-balance [OPTIONS]`
41594098

41604099
###### **Options:**
41614100

4101+
* `--id <ID>` — Claimable Balance Ids to fetch an entry for
41624102
* `--rpc-url <RPC_URL>` — RPC server endpoint
41634103
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
41644104
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
@@ -4184,14 +4124,11 @@ Fetch a claimable balance ledger entry by id
41844124

41854125
Fetch a liquidity pool ledger entry by id
41864126

4187-
**Usage:** `stellar ledger entry fetch liquidity-pool [OPTIONS] [IDS]...`
4188-
4189-
###### **Arguments:**
4190-
4191-
* `<IDS>` — Liquidity pool ids
4127+
**Usage:** `stellar ledger entry fetch liquidity-pool [OPTIONS]`
41924128

41934129
###### **Options:**
41944130

4131+
* `--id <ID>` — Liquidity pool ids
41954132
* `--rpc-url <RPC_URL>` — RPC server endpoint
41964133
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
41974134
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
@@ -4217,14 +4154,11 @@ Fetch a liquidity pool ledger entry by id
42174154

42184155
Fetch a Contract's WASM bytecode by WASM hash
42194156

4220-
**Usage:** `stellar ledger entry fetch contract-code [OPTIONS] [WASM_HASHES]...`
4221-
4222-
###### **Arguments:**
4223-
4224-
* `<WASM_HASHES>` — Get WASM bytecode by hash
4157+
**Usage:** `stellar ledger entry fetch contract-code [OPTIONS]`
42254158

42264159
###### **Options:**
42274160

4161+
* `--wasm-hash <WASM_HASH>` — Get WASM bytecode by hash
42284162
* `--rpc-url <RPC_URL>` — RPC server endpoint
42294163
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
42304164
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
@@ -4274,7 +4208,7 @@ Fetch a trustline by account and asset
42744208

42754209
* `--account <ACCOUNT>` — Account alias or address to lookup
42764210
* `--asset <ASSET>` — Assets to get trustline info for
4277-
* `--hd-path <HD_PATH>` — If identity is a seed phrase use this hd path, default is 0
4211+
* `--hd-path <HD_PATH>` — If account is a seed phrase use this hd path, default is 0
42784212

42794213

42804214

cmd/crates/soroban-test/tests/it/integration/keys.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,56 @@ async fn overwrite_identity() {
9090

9191
assert_ne!(initial_pubkey, pubkey_for_identity(sandbox, "test2"));
9292
}
93+
94+
#[tokio::test]
95+
#[allow(clippy::too_many_lines)]
96+
async fn overwrite_identity_with_add() {
97+
let sandbox = &TestEnv::new();
98+
sandbox
99+
.new_assert_cmd("keys")
100+
.arg("generate")
101+
.arg("test3")
102+
.assert()
103+
.success();
104+
105+
let initial_pubkey = sandbox
106+
.new_assert_cmd("keys")
107+
.arg("address")
108+
.arg("test3")
109+
.assert()
110+
.stdout_as_str();
111+
112+
// Try to add a key with the same name, should fail
113+
sandbox
114+
.new_assert_cmd("keys")
115+
.arg("add")
116+
.arg("test3")
117+
.arg("--public-key")
118+
.arg("GAKSH6AD2IPJQELTHIOWDAPYX74YELUOWJLI2L4RIPIPZH6YQIFNUSDC")
119+
.assert()
120+
.stderr(predicate::str::contains(
121+
"error: An identity with the name 'test3' already exists",
122+
));
123+
124+
// Verify the key wasn't changed
125+
assert_eq!(initial_pubkey, pubkey_for_identity(sandbox, "test3"));
126+
127+
// Try again with --overwrite flag, should succeed
128+
sandbox
129+
.new_assert_cmd("keys")
130+
.arg("add")
131+
.arg("test3")
132+
.arg("--public-key")
133+
.arg("GAKSH6AD2IPJQELTHIOWDAPYX74YELUOWJLI2L4RIPIPZH6YQIFNUSDC")
134+
.arg("--overwrite")
135+
.assert()
136+
.stderr(predicate::str::contains("Overwriting identity 'test3'"))
137+
.success();
138+
139+
// Verify the key was changed
140+
assert_ne!(initial_pubkey, pubkey_for_identity(sandbox, "test3"));
141+
assert_eq!(
142+
"GAKSH6AD2IPJQELTHIOWDAPYX74YELUOWJLI2L4RIPIPZH6YQIFNUSDC",
143+
pubkey_for_identity(sandbox, "test3").trim()
144+
);
145+
}

cmd/soroban-cli/src/commands/keys/add.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub enum Error {
3131

3232
#[error("secret input error")]
3333
PasswordRead,
34+
35+
#[error("An identity with the name '{0}' already exists")]
36+
IdentityAlreadyExists(String),
3437
}
3538

3639
#[derive(Debug, clap::Parser, Clone)]
@@ -48,11 +51,24 @@ pub struct Cmd {
4851
/// Add a public key, ed25519, or muxed account, e.g. G1.., M2..
4952
#[arg(long, conflicts_with = "seed_phrase", conflicts_with = "secret_key")]
5053
pub public_key: Option<String>,
54+
55+
/// Overwrite existing identity if it already exists.
56+
#[arg(long)]
57+
pub overwrite: bool,
5158
}
5259

5360
impl Cmd {
5461
pub fn run(&self, global_args: &global::Args) -> Result<(), Error> {
5562
let print = Print::new(global_args.quiet);
63+
64+
if self.config_locator.read_identity(&self.name).is_ok() {
65+
if !self.overwrite {
66+
return Err(Error::IdentityAlreadyExists(self.name.to_string()));
67+
}
68+
69+
print.exclaimln(format!("Overwriting identity '{}'", &self.name.to_string()));
70+
}
71+
5672
let key = if let Some(key) = self.public_key.as_ref() {
5773
key.parse()?
5874
} else {

cookbook/stellar-keys.mdx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
title: Stellar Keys
3+
hide_table_of_contents: true
4+
description: Manage stellar keys
5+
custom_edit_url: https://github.com/stellar/stellar-cli/edit/main/cookbook/stellar-keys.mdx
6+
---
7+
8+
This guide walks you through generating, inspecting, and removing a Stellar identity using the CLI.
9+
10+
### 1. Generate a New Identity
11+
12+
Run the following command to create a new keypair and save it under the alias named `carol`:
13+
14+
```bash
15+
stellar keys generate carol
16+
```
17+
18+
Output:
19+
20+
```
21+
✅ Key saved with alias carol in ".config/soroban/identity/carol.toml"
22+
```
23+
24+
The CLI stores this identity in a TOML file.
25+
26+
### 2. Verify the Identity File
27+
28+
Navigate to the configuration directory and list the contents:
29+
30+
```bash cookbooktest.ignore
31+
cd .config/soroban/identity && ls
32+
```
33+
34+
Output:
35+
36+
```
37+
carol.toml
38+
```
39+
40+
The file carol.toml contains the seed phrase for your identity.
41+
42+
### 3. View the Seed Phrase
43+
44+
```bash cookbooktest.ignore
45+
cat carol.toml
46+
```
47+
48+
Output:
49+
50+
```
51+
seed_phrase = "patrol clean public grocery roof aim have valve cherry dismiss lunar tail duty license capable little version banana amount often cover dice couple party"
52+
```
53+
54+
:::danger
55+
56+
Note: The seed phrase is sensitive information. Handle it with care and never expose it publicly.
57+
58+
:::
59+
60+
### 4. Derive the Secret Key
61+
62+
To display the secret key for the carol identity:
63+
64+
```bash
65+
stellar keys secret carol
66+
```
67+
68+
Output:
69+
70+
```
71+
SCJP663VYFZPYN75H2DYJA3FYUBP5UR23HZ4ZDHDMDY6TXVYUYMWNKTI
72+
```
73+
74+
:::danger
75+
76+
Note: The secret key is sensitive information. Handle it with care and never expose it publicly.
77+
78+
:::
79+
80+
### 5. Derive the Public Key
81+
82+
To display the corresponding public key for the carol identity:
83+
84+
```bash
85+
stellar keys public-key carol
86+
```
87+
88+
Output:
89+
90+
```
91+
GD3BFFX7DTNJAGDVVM5RYGGQQNURZTH4VSBLWF55YXY3L6T2WWZK57EI
92+
```
93+
94+
This is the public address of your key.
95+
96+
### 6. Fund this account
97+
98+
```bash
99+
stellar keys fund carol
100+
```
101+
102+
Output:
103+
104+
```
105+
✅ Account carol funded on "Test SDF Network ; September 2015"
106+
```
107+
108+
You can also fund the account while creating the key by using `stellar keys generate --fund`.
109+
110+
### 7. Remove the Identity
111+
112+
When you no longer need this identity, remove it using:
113+
114+
```bash
115+
stellar keys rm carol
116+
```
117+
118+
Output:
119+
120+
```
121+
ℹ️ Removing the key's cli config file
122+
```
123+
124+
At this point, the identity file carol.toml is deleted, and the alias is no longer available in the CLI.

0 commit comments

Comments
 (0)