Remove Info Importer from legacy keybase (#8500)
This commit is contained in:
parent
d37c590e90
commit
2e9fd04020
|
@ -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.
|
* [\#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
|
### 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.
|
* (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.
|
||||||
|
|
|
@ -2,7 +2,6 @@ package keyring
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"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)) }
|
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.
|
// KeybaseOption overrides options for the db.
|
||||||
type KeybaseOption func(*kbOptions)
|
type KeybaseOption func(*kbOptions)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package keyring_test
|
package keyring_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -43,15 +42,4 @@ func TestLegacyKeybase(t *testing.T) {
|
||||||
armoredInfo, err := kb.Export(keys[0].GetName())
|
armoredInfo, err := kb.Export(keys[0].GetName())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEmpty(t, armoredInfo)
|
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())
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue