Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the keystore and override the account by the one in the key file after decoding the key from the mnemonic #810

Merged
merged 23 commits into from
Apr 9, 2021

Conversation

romac
Copy link
Member

@romac romac commented Apr 8, 2021

Closes: #751
Closes: #636

Description

  • Refactor the keystore
  • Override the account by the one in the key file after decoding the key from the mnemonic
  • Allow importing a key either from a key file or directly from a mnemonic
  • Add key restore command

Note: This PR is best reviewed one commit at the time.

New interface of keys add

USAGE:
    hermes keys add <OPTIONS>

DESCRIPTION:
    Adds a key to a configured chain

POSITIONAL ARGUMENTS:
    chain_id                  identifier of the chain

FLAGS:
    -f, --file FILE           the path to the key file (conflicts with --mnemonic)

New interface of keys restore

USAGE:
    hermes keys restore <OPTIONS>

DESCRIPTION:
    restore a key to a configured chain using a mnemonic

POSITIONAL ARGUMENTS:
    chain_id                  identifier of the chain

FLAGS:
    -m, --mnemonic MNEMONIC   mnemonic to restore the key from

For contributor use:

  • Updated the Unreleased section of CHANGELOG.md with the issue.
  • If applicable: Unit tests written, added test to CI.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Updated relevant documentation (docs/) and code comments.
  • Re-reviewed Files changed in the Github PR explorer.

@romac romac requested a review from andynog April 8, 2021 19:38
@romac romac requested a review from ancazamfir as a code owner April 8, 2021 19:38
Copy link
Contributor

@andynog andynog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these changes are good for now. If it's working on the tests and transactions are signed then should be OK. But probably for the next release we should look into the whole key support (keyring, sign_tx with cosmos_tx, allow to import keys with mnemonic).

@romac romac marked this pull request as draft April 9, 2021 08:36
@codecov-io

This comment has been minimized.

Copy link
Contributor

@andynog andynog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overall the changes are good, but just thinking if we should have the mnemonics under keys restore

@romac romac mentioned this pull request Apr 9, 2021
15 tasks
@romac romac marked this pull request as ready for review April 9, 2021 21:05
@andynog
Copy link
Contributor

andynog commented Apr 9, 2021

I've did a quick test, keys add and keys restore works fine, but a couple of observations:

  1. The keys add command you don't need to specify the name parameter. It takes from the config, while the keys restore you have a name required parameter. Should we remove that and also pick from the config ? Or implement the name for keys add ? If the parameter is required, then the key_name in the config is to specify which key will sign the tx (since the name allows multiple keys)?

  2. When I try to list an existing key (added with a previous hermes version) I got an error. So we might need to ensure users re-import keys if they are not compatible between versions, might be just an observation on the guide or changelog

hermes keys list ibc-1
Error: key store error: cannot ready key file

@romac
Copy link
Member Author

romac commented Apr 9, 2021

  1. Right! I think we should remove the --name parameter since at the moment we always sign txs with the key from the config, no?

  2. Oh good point, I hadn't thought of that. If you think it's best, I believe I can ensure that we stay backward compatible, by keeping the store key file format the same as the input key file?

@andynog
Copy link
Contributor

andynog commented Apr 9, 2021

  1. Right! I think we should remove the --name parameter since at the moment we always sign txs with the key from the config, no?

I think we should remove that for now. If one day we allow passing the account to sign the tx then we can allow that.

  1. Oh good point, I hadn't thought of that. If you think it's best, I believe I can ensure that we stay backward compatible, by keeping the store key file format the same as the input key file?

I don't think we need to ensure backward compatibility. I think the format is OK, in the end most people will just use the mnemonic option and only the relayer uses that imported key, there's no export functionality. So I think this is good. We just add a message to breaking changes in the changelog.

@romac romac merged commit d5ba86d into master Apr 9, 2021
@romac romac deleted the romac/fix-751 branch April 9, 2021 22:21
hu55a1n1 pushed a commit to hu55a1n1/hermes that referenced this pull request Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commands keys add and keys list don't output the right address Add a private key using the 24 word mnemonic
3 participants