From 2e9fd0402063a0d606dd266f9d72d275e69e95c0 Mon Sep 17 00:00:00 2001 From: SaReN Date: Wed, 3 Feb 2021 18:41:42 +0530 Subject: [PATCH] Remove Info Importer from legacy keybase (#8500) --- CHANGELOG.md | 4 ++++ crypto/keyring/legacy.go | 44 ----------------------------------- crypto/keyring/legacy_test.go | 12 ---------- 3 files changed, 4 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73b4ff3ecd3..12a2d94b31d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address. +### API Breaking Changes + +* (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase. + ### State Machine Breaking * (x/{bank,distrib,gov,slashing,staking}) [\#8363](https://github.com/cosmos/cosmos-sdk/issues/8363) Store keys have been modified to allow for variable-length addresses. diff --git a/crypto/keyring/legacy.go b/crypto/keyring/legacy.go index 59bdc3fc5da..d6653e95615 100644 --- a/crypto/keyring/legacy.go +++ b/crypto/keyring/legacy.go @@ -2,7 +2,6 @@ package keyring import ( "fmt" - "io" "strings" "github.com/pkg/errors" @@ -185,49 +184,6 @@ func (kb dbKeybase) Close() error { return kb.db.Close() } func infoKey(name string) []byte { return []byte(fmt.Sprintf("%s.%s", name, infoSuffix)) } -// InfoImporter is implemented by those types that want to provide functions necessary -// to migrate keys from LegacyKeybase types to Keyring types. -type InfoImporter interface { - // Import imports ASCII-armored private keys. - Import(uid string, armor string) error -} - -type keyringMigrator struct { - kr keystore -} - -func NewInfoImporter( - appName, backend, rootDir string, userInput io.Reader, opts ...Option, -) (InfoImporter, error) { - keyring, err := New(appName, backend, rootDir, userInput, opts...) - if err != nil { - return keyringMigrator{}, err - } - - kr := keyring.(keystore) - - return keyringMigrator{kr}, nil -} - -func (m keyringMigrator) Import(uid string, armor string) error { - _, err := m.kr.Key(uid) - if err == nil { - return fmt.Errorf("cannot overwrite key %q", uid) - } - - infoBytes, err := crypto.UnarmorInfoBytes(armor) - if err != nil { - return err - } - - info, err := unmarshalInfo(infoBytes) - if err != nil { - return err - } - - return m.kr.writeInfo(info) -} - // KeybaseOption overrides options for the db. type KeybaseOption func(*kbOptions) diff --git a/crypto/keyring/legacy_test.go b/crypto/keyring/legacy_test.go index 27503bdea05..d1b0dbf3e68 100644 --- a/crypto/keyring/legacy_test.go +++ b/crypto/keyring/legacy_test.go @@ -1,7 +1,6 @@ package keyring_test import ( - "io" "path/filepath" "testing" @@ -43,15 +42,4 @@ func TestLegacyKeybase(t *testing.T) { armoredInfo, err := kb.Export(keys[0].GetName()) require.NoError(t, err) require.NotEmpty(t, armoredInfo) - - importer, err := keyring.NewInfoImporter("cosmos", "memory", "", nil) - require.NoError(t, err) - err = importer.Import("test", "") - require.Error(t, err) - require.Equal(t, io.EOF, err) - require.NoError(t, importer.Import("test", armoredInfo)) - - err = importer.Import("test", armoredInfo) - require.Error(t, err) - require.Equal(t, `public key already exist in keybase`, err.Error()) }