Skip to content

Commit

Permalink
Document how to read keys from stdin in keys add command
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Oct 2, 2023
1 parent 69074c1 commit 194ac25
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 34 deletions.
4 changes: 2 additions & 2 deletions crates/relayer-cli/src/commands/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ mod list;
/// `keys` subcommand
#[derive(Command, Debug, Parser, Runnable)]
pub enum KeysCmd {
/// Adds key to a configured chain or restores a key to a configured chain using a mnemonic
/// Add a key to a chain from its keyring file or restore a key using its mnemonic
Add(add::KeysAddCmd),

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

/// List keys configured on a chain
/// List keys configured for a chain
List(list::KeysListCmd),

/// Query balance for a key from a configured chain. If no key is given, the key is retrieved from the configuration file.
Expand Down
23 changes: 14 additions & 9 deletions crates/relayer-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ use crate::conclude::Output;
///
/// `keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>`
///
/// The command to restore a key from a file containing mnemonic:
/// The command to restore a key from a file containing its mnemonic:
///
/// `keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>`
///
/// The key-file and mnemonic-file flags can't be given at the same time, this will cause a terminating error.
/// On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.
///
/// The `--key-file` and `--mnemonic-file` flags cannot both be provided at the same time, this will cause a terminating error.
///
/// If successful the key will be created or restored, depending on which flag was given.
#[derive(Clone, Command, Debug, Parser, PartialEq, Eq)]
#[clap(
override_usage = "hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>"
)]
#[clap(override_usage = "Add a key from a Comet keyring file:
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>
Add a key from a file containing its mnemonic:
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>
On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.")]
pub struct KeysAddCmd {
#[clap(
long = "chain",
Expand All @@ -56,7 +61,7 @@ pub struct KeysAddCmd {
required = true,
value_name = "KEY_FILE",
help_heading = "FLAGS",
help = "Path to the key file",
help = "Path to the key file, or /dev/stdin to read the content from stdin",
group = "add-restore"
)]
key_file: Option<PathBuf>,
Expand All @@ -66,7 +71,7 @@ pub struct KeysAddCmd {
required = true,
value_name = "MNEMONIC_FILE",
help_heading = "FLAGS",
help = "Path to file containing mnemonic to restore the key from",
help = "Path to file containing the mnemonic to restore the key from, or /dev/stdin to read the mnemonic from stdin",
group = "add-restore"
)]
mnemonic_file: Option<PathBuf>,
Expand Down
12 changes: 6 additions & 6 deletions guide/src/documentation/commands/keys/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The command outputs a JSON similar to the one below.
}
```

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.
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.

### Adding and restoring Keys

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

```shell
{{#template ../../../templates/commands/hermes/keys/add_1.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE>}}
{{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> KEY_FILE=<PRIVATE_KEY_FILE>}}
```

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

```shell
{{#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"}}
{{#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"}}
```

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:
Expand All @@ -123,7 +123,7 @@ Success: Restore key testkey (<ADDRESS>) on <CHAIN_ID> chain
> To use a different key name, specify the `--key-name` option when invoking `keys add`.
>
> ```
> {{#template ../../../templates/commands/hermes/keys/add_2.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --key-name <KEY_NAME>}}
> {{#template ../../../templates/commands/hermes/keys/add_4.md CHAIN_ID=<CHAIN_ID> MNEMONIC_FILE=<MNEMONIC_FILE> OPTIONS= --key-name <KEY_NAME>}}
> ```
### Delete keys
Expand Down
2 changes: 1 addition & 1 deletion guide/src/templates/commands/hermes/keys/add_1.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --key-file [[#KEY_FILE]]
Add a key from a Comet keyring file:
2 changes: 1 addition & 1 deletion guide/src/templates/commands/hermes/keys/add_2.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --mnemonic-file [[#MNEMONIC_FILE]]
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --key-file [[#KEY_FILE]]
1 change: 1 addition & 0 deletions guide/src/templates/commands/hermes/keys/add_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a key from a file containing its mnemonic:
1 change: 1 addition & 0 deletions guide/src/templates/commands/hermes/keys/add_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[#BINARY hermes]][[#GLOBALOPTIONS]] keys add[[#OPTIONS]] --chain [[#CHAIN_ID]] --mnemonic-file [[#MNEMONIC_FILE]]
1 change: 1 addition & 0 deletions guide/src/templates/commands/hermes/keys/add_5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
On flake.nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.
5 changes: 2 additions & 3 deletions guide/src/templates/help_templates/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ OPTIONS:
-h, --help Print help information

SUBCOMMANDS:
add Adds key to a configured chain or restores a key to a configured chain using a
mnemonic
add Add a key to a chain from its keyring file or restore a key using its mnemonic
balance Query balance for a key from a configured chain. If no key is given, the key is
retrieved from the configuration file
delete Delete key(s) from a configured chain
help Print this message or the help of the given subcommand(s)
list List keys configured on a chain
list List keys configured for a chain
24 changes: 17 additions & 7 deletions guide/src/templates/help_templates/keys/add.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
DESCRIPTION:
Adds key to a configured chain or restores a key to a configured chain using a mnemonic
Add a key to a chain from its keyring file or restore a key using its mnemonic

USAGE:
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>

hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>
Add a key from a Comet keyring file:
hermes keys add [OPTIONS] --chain <CHAIN_ID> --key-file <KEY_FILE>

Add a key from a file containing its mnemonic:
hermes keys add [OPTIONS] --chain <CHAIN_ID> --mnemonic-file <MNEMONIC_FILE>

On *nix platforms, both flags also accept `/dev/stdin` as a value, which will read the key or the mnemonic from stdin.

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

FLAGS:
--chain <CHAIN_ID> Identifier of the chain
--key-file <KEY_FILE> Path to the key file
--mnemonic-file <MNEMONIC_FILE> Path to file containing mnemonic to restore the key from
--chain <CHAIN_ID>
Identifier of the chain

--key-file <KEY_FILE>
Path to the key file, or /dev/stdin to read the content from stdin

--mnemonic-file <MNEMONIC_FILE>
Path to file containing the mnemonic to restore the key from, or /dev/stdin to read the
mnemonic from stdin
2 changes: 1 addition & 1 deletion guide/src/templates/help_templates/keys/list.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DESCRIPTION:
List keys configured on a chain
List keys configured for a chain

USAGE:
hermes keys list --chain <CHAIN_ID>
Expand Down
8 changes: 4 additions & 4 deletions guide/src/tutorials/production/setup-hermes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ You can add a private key using one of two different ways:

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

- 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` :
```shell
echo word1 ... word12or24 > mnemonic_file_hub
{{#template ../../templates/commands/hermes/keys/add_2.md CHAIN_ID=cosmoshub-4 MNEMONIC_FILE=mnemonic_file_hub.json OPTIONS= --key-name keyhub}}
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=cosmoshub-4 MNEMONIC_FILE=mnemonic_file_hub.json OPTIONS= --key-name keyhub}}
rm mnemonic_file_hub
echo word1 ... word12or24 > mnemonic_file_osmosis
{{#template ../../templates/commands/hermes/keys/add_2.md CHAIN_ID=osmosis-1 MNEMONIC_FILE=mnemonic_file_osmosis.json OPTIONS= --key-name keyosmosis}}
{{#template ../../templates/commands/hermes/keys/add_4.md CHAIN_ID=osmosis-1 MNEMONIC_FILE=mnemonic_file_osmosis.json OPTIONS= --key-name keyosmosis}}
rm mnemonic_file_osmosis
```

Expand Down
89 changes: 89 additions & 0 deletions injective.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[global]
log_level = "info"

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = false
auto_register_counterparty_payee = false

[rest]
enabled = false
host = "127.0.0.1"
port = 3000

[telemetry]
enabled = false
host = "127.0.0.1"
port = 3001

[telemetry.buckets.latency_submitted]
start = 500
end = 20000
buckets = 10

[telemetry.buckets.latency_confirmed]
start = 1000
end = 30000
buckets = 10

[[chains]]
id = "injective-1"
type = "CosmosSdk"
rpc_addr = "https://injective-rpc.lavenderfive.com/"
grpc_addr = "https://injective-grpc.lavenderfive.com/"
rpc_timeout = "10s"
trusted_node = false
account_prefix = "inj"
key_name = ""
key_store_type = "Test"
store_prefix = "ibc"
default_gas = 100000
max_gas = 400000
gas_multiplier = 1.1
max_msg_num = 30
max_tx_size = 180000
max_grpc_decoding_size = 33554432
clock_drift = "5s"
max_block_time = "10s"
ccv_consumer_chain = false
memo_prefix = ""
sequential_batch_tx = false

[chains.event_source]
mode = "push"
url = "wss://injective-rpc.lavenderfive.com/websocket"
batch_delay = "100ms"

[chains.trust_threshold]
numerator = "1"
denominator = "3"

[chains.gas_price]
price = 700000000.0
denom = "inj"

[chains.packet_filter]
policy = "allowall"

[chains.packet_filter.min_fees]

[chains.address_type]
derivation = "cosmos"

[tracing_server]
enabled = false
port = 5555

0 comments on commit 194ac25

Please sign in to comment.