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

Remove Info Importer from legacy keybase #8500

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 0 additions & 44 deletions crypto/keyring/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keyring

import (
"fmt"
"io"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 0 additions & 12 deletions crypto/keyring/legacy_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keyring_test

import (
"io"
"path/filepath"
"testing"

Expand Down Expand Up @@ -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())
}