refactor!: Keyring migration (#9695)

<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

The draft PR #9222 
Closes: #7108

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

- implement proto definition for `Record` 
- rename `Info.go` to `legacyInfo.go` within `keyring` package
- implement CLI `migrate` command that migrates all keys from  legacyInfo to proto according to @robert-zaremba migration [algorithm](https://github.com/cosmos/cosmos-sdk/pull/9222/#discussion_r624683839)
- remove legacy keybase entirely.
- add `Migrate` and `MigrateAll` functions  in `keyring.go` for single key and all keys migration
- add tests
- fix tests

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Andrei Ivasko
2021-09-20 12:02:15 +00:00
committed by GitHub
parent a0ecfe54ea
commit 6cbbd6da75
80 changed files with 4118 additions and 1320 deletions
+133
View File
@@ -225,6 +225,16 @@
- [PrivKey](#cosmos.crypto.ed25519.PrivKey)
- [PubKey](#cosmos.crypto.ed25519.PubKey)
- [cosmos/crypto/hd/v1/hd.proto](#cosmos/crypto/hd/v1/hd.proto)
- [BIP44Params](#cosmos.crypto.hd.v1.BIP44Params)
- [cosmos/crypto/keyring/v1/record.proto](#cosmos/crypto/keyring/v1/record.proto)
- [Record](#cosmos.crypto.keyring.v1.Record)
- [Record.Ledger](#cosmos.crypto.keyring.v1.Record.Ledger)
- [Record.Local](#cosmos.crypto.keyring.v1.Record.Local)
- [Record.Multi](#cosmos.crypto.keyring.v1.Record.Multi)
- [Record.Offline](#cosmos.crypto.keyring.v1.Record.Offline)
- [cosmos/crypto/multisig/keys.proto](#cosmos/crypto/multisig/keys.proto)
- [LegacyAminoPubKey](#cosmos.crypto.multisig.LegacyAminoPubKey)
@@ -3579,6 +3589,129 @@ then you must create a new proto message and follow ADR-28 for Address construct
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<!-- end services -->
<a name="cosmos/crypto/hd/v1/hd.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## cosmos/crypto/hd/v1/hd.proto
<a name="cosmos.crypto.hd.v1.BIP44Params"></a>
### BIP44Params
BIP44Params is used as path field in ledger item in Record.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `purpose` | [uint32](#uint32) | | purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation |
| `coin_type` | [uint32](#uint32) | | coin_type is a constant that improves privacy |
| `account` | [uint32](#uint32) | | account splits the key space into independent user identities |
| `change` | [bool](#bool) | | change is a constant used for public derivation. Constant 0 is used for external chain and constant 1 for internal chain. |
| `address_index` | [uint32](#uint32) | | address_index is used as child index in BIP32 derivation |
<!-- end messages -->
<!-- end enums -->
<!-- end HasExtensions -->
<!-- end services -->
<a name="cosmos/crypto/keyring/v1/record.proto"></a>
<p align="right"><a href="#top">Top</a></p>
## cosmos/crypto/keyring/v1/record.proto
<a name="cosmos.crypto.keyring.v1.Record"></a>
### Record
Record is used for representing a key in the keyring.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `name` | [string](#string) | | name represents a name of Record |
| `pub_key` | [google.protobuf.Any](#google.protobuf.Any) | | pub_key represents a public key in any format |
| `local` | [Record.Local](#cosmos.crypto.keyring.v1.Record.Local) | | local stores the public information about a locally stored key |
| `ledger` | [Record.Ledger](#cosmos.crypto.keyring.v1.Record.Ledger) | | ledger stores the public information about a Ledger key |
| `multi` | [Record.Multi](#cosmos.crypto.keyring.v1.Record.Multi) | | Multi does not store any information. |
| `offline` | [Record.Offline](#cosmos.crypto.keyring.v1.Record.Offline) | | Offline does not store any information. |
<a name="cosmos.crypto.keyring.v1.Record.Ledger"></a>
### Record.Ledger
Ledger item
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `path` | [cosmos.crypto.hd.v1.BIP44Params](#cosmos.crypto.hd.v1.BIP44Params) | | |
<a name="cosmos.crypto.keyring.v1.Record.Local"></a>
### Record.Local
Item is a keyring item stored in a keyring backend.
Local item
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `priv_key` | [google.protobuf.Any](#google.protobuf.Any) | | |
| `priv_key_type` | [string](#string) | | |
<a name="cosmos.crypto.keyring.v1.Record.Multi"></a>
### Record.Multi
Multi item
<a name="cosmos.crypto.keyring.v1.Record.Offline"></a>
### Record.Offline
Offline item
<!-- end messages -->
<!-- end enums -->