Skip to content

Commit 194ac25

Browse files
committed
Document how to read keys from stdin in keys add command
1 parent 69074c1 commit 194ac25

File tree

13 files changed

+140
-34
lines changed

13 files changed

+140
-34
lines changed

crates/relayer-cli/src/commands/keys.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ mod list;
1010
/// `keys` subcommand
1111
#[derive(Command, Debug, Parser, Runnable)]
1212
pub enum KeysCmd {
13-
/// Adds key to a configured chain or restores a key to a configured chain using a mnemonic
13+
/// Add a key to a chain from its keyring file or restore a key using its mnemonic
1414
Add(add::KeysAddCmd),
1515

1616
/// Delete key(s) from a configured chain
1717
Delete(delete::KeysDeleteCmd),
1818

19-
/// List keys configured on a chain
19+
/// List keys configured for a chain
2020
List(list::KeysListCmd),
2121

2222
/// Query balance for a key from a configured chain. If no key is given, the key is retrieved from the configuration file.

crates/relayer-cli/src/commands/keys/add.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,23 @@ use crate::conclude::Output;
3030
///
3131
/// `keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>`
3232
///
33-
/// The command to restore a key from a file containing mnemonic:
33+
/// The command to restore a key from a file containing its mnemonic:
3434
///
3535
/// `keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>`
3636
///
37-
/// The key-file and mnemonic-file flags can't be given at the same time, this will cause a terminating error.
37+
/// On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.
38+
///
39+
/// The `--key-file` and `--mnemonic-file` flags cannot both be provided at the same time, this will cause a terminating error.
40+
///
3841
/// If successful the key will be created or restored, depending on which flag was given.
3942
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)]
40-
#[clap(
41-
override_usage = "hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
42-
43-
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>"
44-
)]
43+
#[clap(override_usage = "Add a key from a Comet keyring file:
44+
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
45+
46+
Add a key from a file containing its mnemonic:
47+
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>
48+
49+
On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.")]
4550
pub struct KeysAddCmd {
4651
#[clap(
4752
long = "chain",
@@ -56,7 +61,7 @@ pub struct KeysAddCmd {
5661
required = true,
5762
value_name = "KEY_FILE",
5863
help_heading = "FLAGS",
59-
help = "Path to the key file",
64+
help = "Path to the key file, or /dev/stdin to read the content from stdin",
6065
group = "add-restore"
6166
)]
6267
key_file: Option<PathBuf>,
@@ -66,7 +71,7 @@ pub struct KeysAddCmd {
6671
required = true,
6772
value_name = "MNEMONIC_FILE",
6873
help_heading = "FLAGS",
69-
help = "Path to file containing mnemonic to restore the key from",
74+
help = "Path to file containing the mnemonic to restore the key from, or /dev/stdin to read the mnemonic from stdin",
7075
group = "add-restore"
7176
)]
7277
mnemonic_file: Option<PathBuf>,

guide/src/documentation/commands/keys/index.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The command outputs a JSON similar to the one below.
5050
}
5151
```
5252

53-
You can save this to a file (e.g. `key_seed.json`) and use it to add to Hermes with `{{#template ../../../templates/commands/hermes/keys/add_1.md CHAIN_ID=<CHAIN_ID> KEY_FILE=key_seed.json}}`. See the `Adding Keys` section for more details.
53+
You can save this to a file (e.g. `key_seed.json`) and use it to add to Hermes with `{{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> KEY_FILE=key_seed.json}}`. See the `Adding Keys` section for more details.
5454

5555
### Adding and restoring Keys
5656

@@ -64,7 +64,7 @@ If a key with the same `key_name` already exists, the flag `--overwrite` must be
6464
#### Add a private key to a chain from a key file
6565

6666
```shell
67-
{{#template ../../../templates/commands/hermes/keys/add_1.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE>}}
67+
{{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE>}}
6868
```
6969

7070
The content of the file key should have the same format as the output of the `gaiad keys add` command:
@@ -90,21 +90,21 @@ Success: Added key testkey (<ADDRESS>) on <CHAIN_ID> chain
9090
> To use a different key name, specify the `--key-name` option when invoking `keys add`.
9191
>
9292
> ```
93-
> {{#template ../../../templates/commands/hermes/keys/add_1.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE> OPTIONS= --key-name [KEY_NAME]}}
93+
> {{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE> OPTIONS= --key-name [KEY_NAME]}}
9494
> ```
9595
9696
#### Restore a private key to a chain from a mnemonic
9797
9898
```shell
99-
{{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE>}}
99+
{{#template ../../../templates/commands/hermes/keys/add_4.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE>}}
100100
```
101101
102102
or using an explicit [derivation path](https://github.com/satoshilabs/slips/blob/master/slip-0044.md), for example
103103
an Ethereum coin type (used for Evmos, Injective, Umee, Cronos, and
104104
possibly other networks):
105105

106106
```shell
107-
{{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --hd-path "m/44'/60'/0'/0/0"}}
107+
{{#template ../../../templates/commands/hermes/keys/add_4.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --hd-path "m/44'/60'/0'/0/0"}}
108108
```
109109

110110
The mnemonic file needs to have the 24 mnemonic words on the same line, separated by a white space. So the content should have the following format:
@@ -123,7 +123,7 @@ Success: Restore key testkey (<ADDRESS>) on <CHAIN_ID> chain
123123
> To use a different key name, specify the `--key-name` option when invoking `keys add`.
124124
>
125125
> ```
126-
> {{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --key-name <KEY_NAME>}}
126+
> {{#template ../../../templates/commands/hermes/keys/add_4.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --key-name <KEY_NAME>}}
127127
> ```
128128
129129
### Delete keys
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --key-file [[#KEY_FILE]]
1+
Add a key from a Comet keyring file:
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --mnemonic-file [[#MNEMONIC_FILE]]
1+
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --key-file [[#KEY_FILE]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a key from a file containing its mnemonic:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --mnemonic-file [[#MNEMONIC_FILE]]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
On flake.nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.

guide/src/templates/help_templates/keys.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ OPTIONS:
88
-h, --help Print help information
99

1010
SUBCOMMANDS:
11-
add Adds key to a configured chain or restores a key to a configured chain using a
12-
mnemonic
11+
add Add a key to a chain from its keyring file or restore a key using its mnemonic
1312
balance Query balance for a key from a configured chain. If no key is given, the key is
1413
retrieved from the configuration file
1514
delete Delete key(s) from a configured chain
1615
help Print this message or the help of the given subcommand(s)
17-
list List keys configured on a chain
16+
list List keys configured for a chain
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
DESCRIPTION:
2-
Adds key to a configured chain or restores a key to a configured chain using a mnemonic
2+
Add a key to a chain from its keyring file or restore a key using its mnemonic
33

44
USAGE:
5-
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
6-
7-
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>
5+
Add a key from a Comet keyring file:
6+
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
7+
8+
Add a key from a file containing its mnemonic:
9+
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>
10+
11+
On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.
812

913
OPTIONS:
1014
-h, --help Print help information
@@ -13,6 +17,12 @@ OPTIONS:
1317
--overwrite Overwrite the key if there is already one with the same key name
1418

1519
FLAGS:
16-
--chain <CHAIN_ID> Identifier of the chain
17-
--key-file <KEY_FILE> Path to the key file
18-
--mnemonic-file <MNEMONIC_FILE> Path to file containing mnemonic to restore the key from
20+
--chain <CHAIN_ID>
21+
Identifier of the chain
22+
23+
--key-file <KEY_FILE>
24+
Path to the key file, or /dev/stdin to read the content from stdin
25+
26+
--mnemonic-file <MNEMONIC_FILE>
27+
Path to file containing the mnemonic to restore the key from, or /dev/stdin to read the
28+
mnemonic from stdin

guide/src/templates/help_templates/keys/list.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
DESCRIPTION:
2-
List keys configured on a chain
2+
List keys configured for a chain
33

44
USAGE:
55
hermes keys list --chain <CHAIN_ID>

guide/src/tutorials/production/setup-hermes.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ You can add a private key using one of two different ways:
1414

1515
- If you have a [key-seed file](../../documentation/commands/keys/index.md#key-seed-file-private-key), use the commands :
1616
```shell
17-
{{#template ../../templates/commands/hermes/keys/add_1.md CHAIN_ID=cosmoshub-4 KEY_FILE=key_file_hub.json}}
18-
{{#template ../../templates/commands/hermes/keys/add_1.md CHAIN_ID=osmosis-1 KEY_FILE=key_file_osmosis.json}}
17+
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=cosmoshub-4 KEY_FILE=key_file_hub.json}}
18+
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=osmosis-1 KEY_FILE=key_file_osmosis.json}}
1919
```
2020
>__NOTE__: Do not confuse the `chain-name` and the `chain-id` which follows the format `chain_name-version`.
2121

2222
- If you have a `mnemonic`, you can restore a private key from a [mnemonic-file](../../documentation/commands/keys/index.md#restore-a-private-key-to-A_CHAIN_ID-from-a-mnemonic). The following steps create a `mnemonic-file` and restore its key for each chain under names `keyhub` and `keyosmosis` :
2323
```shell
2424
echo word1 ... word12or24 > mnemonic_file_hub
25-
{{#template ../../templates/commands/hermes/keys/add_2.md CHAIN_ID=cosmoshub-4 MNEMONIC_FILE=mnemonic_file_hub.json OPTIONS= --key-name keyhub}}
25+
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=cosmoshub-4 MNEMONIC_FILE=mnemonic_file_hub.json OPTIONS= --key-name keyhub}}
2626
rm mnemonic_file_hub
2727
echo word1 ... word12or24 > mnemonic_file_osmosis
28-
{{#template ../../templates/commands/hermes/keys/add_2.md CHAIN_ID=osmosis-1 MNEMONIC_FILE=mnemonic_file_osmosis.json OPTIONS= --key-name keyosmosis}}
28+
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=osmosis-1 MNEMONIC_FILE=mnemonic_file_osmosis.json OPTIONS= --key-name keyosmosis}}
2929
rm mnemonic_file_osmosis
3030
```
3131

injective.toml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[global]
2+
log_level = "info"
3+
4+
[mode.clients]
5+
enabled = true
6+
refresh = true
7+
misbehaviour = true
8+
9+
[mode.connections]
10+
enabled = false
11+
12+
[mode.channels]
13+
enabled = false
14+
15+
[mode.packets]
16+
enabled = true
17+
clear_interval = 100
18+
clear_on_start = true
19+
tx_confirmation = false
20+
auto_register_counterparty_payee = false
21+
22+
[rest]
23+
enabled = false
24+
host = "127.0.0.1"
25+
port = 3000
26+
27+
[telemetry]
28+
enabled = false
29+
host = "127.0.0.1"
30+
port = 3001
31+
32+
[telemetry.buckets.latency_submitted]
33+
start = 500
34+
end = 20000
35+
buckets = 10
36+
37+
[telemetry.buckets.latency_confirmed]
38+
start = 1000
39+
end = 30000
40+
buckets = 10
41+
42+
[[chains]]
43+
id = "injective-1"
44+
type = "CosmosSdk"
45+
rpc_addr = "https://injective-rpc.lavenderfive.com/"
46+
grpc_addr = "https://injective-grpc.lavenderfive.com/"
47+
rpc_timeout = "10s"
48+
trusted_node = false
49+
account_prefix = "inj"
50+
key_name = ""
51+
key_store_type = "Test"
52+
store_prefix = "ibc"
53+
default_gas = 100000
54+
max_gas = 400000
55+
gas_multiplier = 1.1
56+
max_msg_num = 30
57+
max_tx_size = 180000
58+
max_grpc_decoding_size = 33554432
59+
clock_drift = "5s"
60+
max_block_time = "10s"
61+
ccv_consumer_chain = false
62+
memo_prefix = ""
63+
sequential_batch_tx = false
64+
65+
[chains.event_source]
66+
mode = "push"
67+
url = "wss://injective-rpc.lavenderfive.com/websocket"
68+
batch_delay = "100ms"
69+
70+
[chains.trust_threshold]
71+
numerator = "1"
72+
denominator = "3"
73+
74+
[chains.gas_price]
75+
price = 700000000.0
76+
denom = "inj"
77+
78+
[chains.packet_filter]
79+
policy = "allowall"
80+
81+
[chains.packet_filter.min_fees]
82+
83+
[chains.address_type]
84+
derivation = "cosmos"
85+
86+
[tracing_server]
87+
enabled = false
88+
port = 5555
89+

0 commit comments

Comments
 (0)