crypto/keys: move keybase and keyring to crypto/keyring/ dir (#5866)
* crypto/keys: move keybase and keyring to crypto/keyring/ dir * Update client/keys/root.go * Update crypto/keyring/errors.go * Update crypto/keyring/keybase.go * Update crypto/keyring/options.go * format * changelog * fix build * format * lint
This commit is contained in:
parent
206a511fa9
commit
9cce836c08
@ -64,15 +64,16 @@ heights are kept after pruning. The `IsValid` method should be called whenever u
|
||||
`SnapshotVersion` and `FlushVersion` accept a version arugment and determine if the version should be
|
||||
flushed to disk or kept as a snapshot. Note, `KeepRecent` is automatically inferred from the options
|
||||
and provided directly the IAVL store.
|
||||
* (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move x/auth/client/utils/ types and functions to x/auth/client/.
|
||||
* (modules) [\#5555](https://github.com/cosmos/cosmos-sdk/pull/5555) Move `x/auth/client/utils/` types and functions to `x/auth/client/`.
|
||||
* (modules) [\#5572](https://github.com/cosmos/cosmos-sdk/pull/5572) Move account balance logic and APIs from `x/auth` to `x/bank`.
|
||||
* (types) [\#5533](https://github.com/cosmos/cosmos-sdk/pull/5533) Refactored `AppModuleBasic` and `AppModuleGenesis`
|
||||
to now accept a `codec.JSONMarshaler` for modular serialization of genesis state.
|
||||
* (crypto/keys) [\#5735](https://github.com/cosmos/cosmos-sdk/pull/5735) Keyring's Update() function is now no-op.
|
||||
* (crypto/keys) [\#5735](https://github.com/cosmos/cosmos-sdk/pull/5735) Keyring's `Update()` function is now no-op.
|
||||
* (types/rest) [\#5779](https://github.com/cosmos/cosmos-sdk/pull/5779) Drop unused Parse{Int64OrReturnBadRequest,QueryParamBool}() functions.
|
||||
* (keys) [\#5820](https://github.com/cosmos/cosmos-sdk/pull/5820/) Removed method CloseDB from Keybase interface.
|
||||
* (baseapp) [\#5837](https://github.com/cosmos/cosmos-sdk/issues/5837) Transaction simulation now returns a `SimulationResponse` which contains the `GasInfo` and
|
||||
`Result` from the execution.
|
||||
* (crypto/keys) [\#5866](https://github.com/cosmos/cosmos-sdk/pull/5866) Move `Keyring` and `Keybase` implementations and their associated types from `crypto/keys/` to `crypto/keybase/`.
|
||||
|
||||
### Features
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clientx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@ -28,7 +28,7 @@ type CLIContext struct {
|
||||
ChainID string
|
||||
TxGenerator clientx.Generator
|
||||
Marshaler codec.Marshaler
|
||||
Keybase keys.Keybase
|
||||
Keybase keyring.Keybase
|
||||
Input io.Reader
|
||||
Output io.Writer
|
||||
OutputFormat string
|
||||
@ -295,13 +295,13 @@ func GetFromFields(input io.Reader, from string, genOnly bool) (sdk.AccAddress,
|
||||
return addr, "", nil
|
||||
}
|
||||
|
||||
keybase, err := keys.NewKeyring(sdk.KeyringServiceName(),
|
||||
keybase, err := keyring.NewKeyring(sdk.KeyringServiceName(),
|
||||
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
var info keys.Info
|
||||
var info keyring.Info
|
||||
if addr, err := sdk.AccAddressFromBech32(from); err == nil {
|
||||
info, err = keybase.GetByAddress(addr)
|
||||
if err != nil {
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
// nolint
|
||||
@ -23,7 +23,7 @@ const (
|
||||
GasFlagAuto = "auto"
|
||||
|
||||
// DefaultKeyringBackend
|
||||
DefaultKeyringBackend = keys.BackendOS
|
||||
DefaultKeyringBackend = keyring.BackendOS
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -77,16 +77,16 @@ the flag --nosort is set.
|
||||
cmd.Flags().Uint32(flagAccount, 0, "Account number for HD derivation")
|
||||
cmd.Flags().Uint32(flagIndex, 0, "Address index number for HD derivation")
|
||||
cmd.Flags().Bool(flags.FlagIndentResponse, false, "Add indent to JSON response")
|
||||
cmd.Flags().String(flagKeyAlgo, string(keys.Secp256k1), "Key signing algorithm to generate keys for")
|
||||
cmd.Flags().String(flagKeyAlgo, string(keyring.Secp256k1), "Key signing algorithm to generate keys for")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func getKeybase(transient bool, buf io.Reader) (keys.Keybase, error) {
|
||||
func getKeybase(transient bool, buf io.Reader) (keyring.Keybase, error) {
|
||||
if transient {
|
||||
return keys.NewInMemory(), nil
|
||||
return keyring.NewInMemory(), nil
|
||||
}
|
||||
|
||||
return keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
return keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
}
|
||||
|
||||
func runAddCmd(cmd *cobra.Command, args []string) error {
|
||||
@ -108,7 +108,7 @@ input
|
||||
output
|
||||
- armor encrypted private key (saved to file)
|
||||
*/
|
||||
func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.Reader) error {
|
||||
func RunAddCmd(cmd *cobra.Command, args []string, kb keyring.Keybase, inBuf *bufio.Reader) error {
|
||||
var err error
|
||||
|
||||
name := args[0]
|
||||
@ -116,12 +116,12 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.
|
||||
interactive := viper.GetBool(flagInteractive)
|
||||
showMnemonic := !viper.GetBool(flagNoBackup)
|
||||
|
||||
algo := keys.SigningAlgo(viper.GetString(flagKeyAlgo))
|
||||
if algo == keys.SigningAlgo("") {
|
||||
algo = keys.Secp256k1
|
||||
algo := keyring.SigningAlgo(viper.GetString(flagKeyAlgo))
|
||||
if algo == keyring.SigningAlgo("") {
|
||||
algo = keyring.Secp256k1
|
||||
}
|
||||
if !keys.IsSupportedAlgorithm(kb.SupportedAlgos(), algo) {
|
||||
return keys.ErrUnsupportedSigningAlgo
|
||||
if !keyring.IsSupportedAlgorithm(kb.SupportedAlgos(), algo) {
|
||||
return keyring.ErrUnsupportedSigningAlgo
|
||||
}
|
||||
|
||||
if !viper.GetBool(flagDryRun) {
|
||||
@ -190,7 +190,7 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.
|
||||
var hdPath string
|
||||
|
||||
if useBIP44 {
|
||||
hdPath = keys.CreateHDPath(account, index).String()
|
||||
hdPath = keyring.CreateHDPath(account, index).String()
|
||||
} else {
|
||||
hdPath = viper.GetString(flagHDPath)
|
||||
}
|
||||
@ -202,12 +202,12 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.
|
||||
return errors.New("cannot set custom bip32 path with ledger")
|
||||
}
|
||||
|
||||
if !keys.IsSupportedAlgorithm(kb.SupportedAlgosLedger(), algo) {
|
||||
return keys.ErrUnsupportedSigningAlgo
|
||||
if !keyring.IsSupportedAlgorithm(kb.SupportedAlgosLedger(), algo) {
|
||||
return keyring.ErrUnsupportedSigningAlgo
|
||||
}
|
||||
|
||||
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()
|
||||
info, err := kb.CreateLedger(name, keys.Secp256k1, bech32PrefixAccAddr, account, index)
|
||||
info, err := kb.CreateLedger(name, keyring.Secp256k1, bech32PrefixAccAddr, account, index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -285,13 +285,13 @@ func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.
|
||||
return printCreate(cmd, info, showMnemonic, mnemonic)
|
||||
}
|
||||
|
||||
func printCreate(cmd *cobra.Command, info keys.Info, showMnemonic bool, mnemonic string) error {
|
||||
func printCreate(cmd *cobra.Command, info keyring.Info, showMnemonic bool, mnemonic string) error {
|
||||
output := viper.Get(cli.OutputFlag)
|
||||
|
||||
switch output {
|
||||
case OutputFormatText:
|
||||
cmd.PrintErrln()
|
||||
printKeyInfo(info, keys.Bech32KeyOutput)
|
||||
printKeyInfo(info, keyring.Bech32KeyOutput)
|
||||
|
||||
// print mnemonic unless requested not to.
|
||||
if showMnemonic {
|
||||
@ -301,7 +301,7 @@ func printCreate(cmd *cobra.Command, info keys.Info, showMnemonic bool, mnemonic
|
||||
cmd.PrintErrln(mnemonic)
|
||||
}
|
||||
case OutputFormatJSON:
|
||||
out, err := keys.Bech32KeyOutput(info)
|
||||
out, err := keyring.Bech32KeyOutput(info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -51,7 +51,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
require.NoError(t, runAddCmd(cmd, []string{"keyname1"}))
|
||||
|
||||
// Now check that it has been stored properly
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, kb)
|
||||
t.Cleanup(func() {
|
||||
@ -66,7 +66,7 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) {
|
||||
require.NotNil(t, key1)
|
||||
|
||||
require.Equal(t, "keyname1", key1.GetName())
|
||||
require.Equal(t, keys.TypeLedger, key1.GetType())
|
||||
require.Equal(t, keyring.TypeLedger, key1.GetType())
|
||||
require.Equal(t,
|
||||
"terrapub1addwnpepqvpg7r26nl2pvqqern00m6s9uaax3hauu2rzg8qpjzq9hy6xve7sw0d84m6",
|
||||
sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, key1.GetPubKey()))
|
||||
@ -98,7 +98,7 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
require.NoError(t, runAddCmd(cmd, []string{"keyname1"}))
|
||||
|
||||
// Now check that it has been stored properly
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, kb)
|
||||
t.Cleanup(func() {
|
||||
@ -113,7 +113,7 @@ func Test_runAddCmdLedger(t *testing.T) {
|
||||
require.NotNil(t, key1)
|
||||
|
||||
require.Equal(t, "keyname1", key1.GetName())
|
||||
require.Equal(t, keys.TypeLedger, key1.GetType())
|
||||
require.Equal(t, keyring.TypeLedger, key1.GetType())
|
||||
require.Equal(t,
|
||||
"cosmospub1addwnpepqd87l8xhcnrrtzxnkql7k55ph8fr9jarf4hn6udwukfprlalu8lgw0urza0",
|
||||
sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, key1.GetPubKey()))
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -31,7 +31,7 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
} else {
|
||||
mockIn.Reset("y\n")
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1", "", false) // nolint:errcheck
|
||||
|
||||
@ -7,25 +7,25 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
type testCases struct {
|
||||
Keys []keys.KeyOutput
|
||||
Answers []keys.KeyOutput
|
||||
Keys []keyring.KeyOutput
|
||||
Answers []keyring.KeyOutput
|
||||
JSON [][]byte
|
||||
}
|
||||
|
||||
func getTestCases() testCases {
|
||||
return testCases{
|
||||
// nolint:govet
|
||||
[]keys.KeyOutput{
|
||||
[]keyring.KeyOutput{
|
||||
{"A", "B", "C", "D", "E", 0, nil},
|
||||
{"A", "B", "C", "D", "", 0, nil},
|
||||
{"", "B", "C", "D", "", 0, nil},
|
||||
{"", "", "", "", "", 0, nil},
|
||||
},
|
||||
make([]keys.KeyOutput, 4),
|
||||
make([]keyring.KeyOutput, 4),
|
||||
[][]byte{
|
||||
[]byte(`{"name":"A","type":"B","address":"C","pubkey":"D","mnemonic":"E"}`),
|
||||
[]byte(`{"name":"A","type":"B","address":"C","pubkey":"D"}`),
|
||||
@ -37,7 +37,7 @@ func getTestCases() testCases {
|
||||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
type args struct {
|
||||
o keys.KeyOutput
|
||||
o keyring.KeyOutput
|
||||
}
|
||||
|
||||
data := getTestCases()
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -43,7 +43,7 @@ private keys stored in a ledger device cannot be deleted with the CLI.
|
||||
func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||
buf := bufio.NewReader(cmd.InOrStdin())
|
||||
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -54,7 +54,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.GetType() == keys.TypeLedger || info.GetType() == keys.TypeOffline {
|
||||
if info.GetType() == keyring.TypeLedger || info.GetType() == keyring.TypeOffline {
|
||||
// confirm deletion, unless -y is passed
|
||||
if !viper.GetBool(flagYes) {
|
||||
if err := confirmDeletion(buf); err != nil {
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -27,7 +27,7 @@ func Test_runDeleteCmd(t *testing.T) {
|
||||
fakeKeyName1 := "runDeleteCmd_Key1"
|
||||
fakeKeyName2 := "runDeleteCmd_Key2"
|
||||
if !runningUnattended {
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("runDeleteCmd_Key1", "", false) // nolint:errcheck
|
||||
@ -41,18 +41,18 @@ func Test_runDeleteCmd(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
// Now
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), kbHome, mockIn)
|
||||
require.NoError(t, err)
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
}
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
}
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
if runningUnattended {
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@ -25,7 +25,7 @@ func ExportKeyCommand() *cobra.Command {
|
||||
|
||||
func runExportCmd(cmd *cobra.Command, args []string) error {
|
||||
buf := bufio.NewReader(cmd.InOrStdin())
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -23,7 +23,7 @@ func Test_runExportCmd(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
// create a key
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
if !runningUnattended {
|
||||
t.Cleanup(func() {
|
||||
@ -34,7 +34,7 @@ func Test_runExportCmd(t *testing.T) {
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
}
|
||||
_, err = kb.CreateAccount("keyname1", tests.TestMnemonic, "", "123456789", "", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount("keyname1", tests.TestMnemonic, "", "123456789", "", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now enter password
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ func ImportKeyCommand() *cobra.Command {
|
||||
|
||||
func runImportCmd(cmd *cobra.Command, args []string) error {
|
||||
buf := bufio.NewReader(cmd.InOrStdin())
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -25,7 +25,7 @@ func Test_runImportCmd(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
if !runningUnattended {
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("keyname1", "", false) // nolint:errcheck
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ along with their associated name and address.`,
|
||||
}
|
||||
|
||||
func runListCmd(cmd *cobra.Command, _ []string) error {
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -32,13 +32,13 @@ func Test_runListCmd(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome2)
|
||||
|
||||
mockIn, _, _ := tests.ApplyMockIO(cmdBasic)
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
}
|
||||
|
||||
_, err = kb.CreateAccount("something", tests.TestMnemonic, "", "", "", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount("something", tests.TestMnemonic, "", "", "", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@ -59,7 +59,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
var (
|
||||
tmpDir string
|
||||
keybase keys.Keybase
|
||||
keybase keyring.Keybase
|
||||
)
|
||||
|
||||
if viper.GetBool(flags.FlagDryRun) {
|
||||
@ -70,9 +70,9 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
|
||||
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
keybase, err = keys.NewKeyring(keyringServiceName, "test", tmpDir, buf)
|
||||
keybase, err = keyring.NewKeyring(keyringServiceName, "test", tmpDir, buf)
|
||||
} else {
|
||||
keybase, err = keys.NewKeyring(keyringServiceName, viper.GetString(flags.FlagKeyringBackend), rootDir, buf)
|
||||
keybase, err = keyring.NewKeyring(keyringServiceName, viper.GetString(flags.FlagKeyringBackend), rootDir, buf)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, fmt.Sprintf(
|
||||
@ -107,7 +107,7 @@ func runMigrateCmd(cmd *cobra.Command, args []string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if keyType != keys.TypeLocal {
|
||||
if keyType != keyring.TypeLocal {
|
||||
if err := keybase.Import(keyName, legKeyInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
func TestCommands(t *testing.T) {
|
||||
@ -20,6 +20,6 @@ func TestCommands(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
viper.Set(flags.FlagKeyringBackend, keys.BackendTest)
|
||||
viper.Set(flags.FlagKeyringBackend, keyring.BackendTest)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
@ -55,9 +55,9 @@ consisting of all the keys provided by name and multisig threshold.`,
|
||||
}
|
||||
|
||||
func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
var info keys.Info
|
||||
var info keyring.Info
|
||||
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -84,7 +84,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
}
|
||||
|
||||
multikey := multisig.NewPubKeyMultisigThreshold(multisigThreshold, pks)
|
||||
info = keys.NewMultiInfo(defaultMultiSigKeyName, multikey)
|
||||
info = keyring.NewMultiInfo(defaultMultiSigKeyName, multikey)
|
||||
}
|
||||
|
||||
isShowAddr := viper.GetBool(FlagAddress)
|
||||
@ -127,7 +127,7 @@ func runShowCmd(cmd *cobra.Command, args []string) (err error) {
|
||||
return fmt.Errorf("the device flag (-d) can only be used for accounts")
|
||||
}
|
||||
// Override and show in the device
|
||||
if info.GetType() != keys.TypeLedger {
|
||||
if info.GetType() != keyring.TypeLedger {
|
||||
return fmt.Errorf("the device flag (-d) can only be used for accounts stored in devices")
|
||||
}
|
||||
|
||||
@ -156,11 +156,11 @@ func validateMultisigThreshold(k, nKeys int) error {
|
||||
func getBechKeyOut(bechPrefix string) (bechKeyOutFn, error) {
|
||||
switch bechPrefix {
|
||||
case sdk.PrefixAccount:
|
||||
return keys.Bech32KeyOutput, nil
|
||||
return keyring.Bech32KeyOutput, nil
|
||||
case sdk.PrefixValidator:
|
||||
return keys.Bech32ValKeyOutput, nil
|
||||
return keyring.Bech32ValKeyOutput, nil
|
||||
case sdk.PrefixConsensus:
|
||||
return keys.Bech32ConsKeyOutput, nil
|
||||
return keyring.Bech32ConsKeyOutput, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid Bech32 prefix encoding provided: %s", bechPrefix)
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -19,10 +19,10 @@ import (
|
||||
func Test_multiSigKey_Properties(t *testing.T) {
|
||||
tmpKey1 := secp256k1.GenPrivKeySecp256k1([]byte("mySecret"))
|
||||
pk := multisig.NewPubKeyMultisigThreshold(1, []crypto.PubKey{tmpKey1.PubKey()})
|
||||
tmp := keys.NewMultiInfo("myMultisig", pk)
|
||||
tmp := keyring.NewMultiInfo("myMultisig", pk)
|
||||
|
||||
require.Equal(t, "myMultisig", tmp.GetName())
|
||||
require.Equal(t, keys.TypeMulti, tmp.GetType())
|
||||
require.Equal(t, keyring.TypeMulti, tmp.GetType())
|
||||
require.Equal(t, "D3923267FA8A3DD367BB768FA8BDC8FF7F89DA3F", tmp.GetPubKey().Address().String())
|
||||
require.Equal(t, "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc", tmp.GetAddress().String())
|
||||
}
|
||||
@ -49,7 +49,7 @@ func Test_runShowCmd(t *testing.T) {
|
||||
|
||||
fakeKeyName1 := "runShowCmd_Key1"
|
||||
fakeKeyName2 := "runShowCmd_Key2"
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), mockIn)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
kb.Delete("runShowCmd_Key1", "", false)
|
||||
@ -58,13 +58,13 @@ func Test_runShowCmd(t *testing.T) {
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\ntestpass1\n")
|
||||
}
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
if runningUnattended {
|
||||
mockIn.Reset("testpass1\n")
|
||||
}
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keys.Secp256k1)
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Now try single key
|
||||
@ -161,9 +161,9 @@ func Test_getBechKeyOut(t *testing.T) {
|
||||
}{
|
||||
{"empty", args{""}, nil, true},
|
||||
{"wrong", args{"???"}, nil, true},
|
||||
{"acc", args{sdk.PrefixAccount}, keys.Bech32KeyOutput, false},
|
||||
{"val", args{sdk.PrefixValidator}, keys.Bech32ValKeyOutput, false},
|
||||
{"cons", args{sdk.PrefixConsensus}, keys.Bech32ConsKeyOutput, false},
|
||||
{"acc", args{sdk.PrefixAccount}, keyring.Bech32KeyOutput, false},
|
||||
{"val", args{sdk.PrefixValidator}, keyring.Bech32ValKeyOutput, false},
|
||||
{"cons", args{sdk.PrefixConsensus}, keyring.Bech32ConsKeyOutput, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package keys
|
||||
|
||||
// used for outputting keys.Info over REST
|
||||
// used for outputting keyring.Info over REST
|
||||
|
||||
// AddNewKey request a new key
|
||||
type AddNewKey struct {
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
package keys
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
func Test_updateKeyCommand(t *testing.T) {
|
||||
assert.NotNil(t, UpdateKeyCommand())
|
||||
require.NotNil(t, UpdateKeyCommand())
|
||||
// No flags or defaults to validate
|
||||
}
|
||||
|
||||
@ -23,12 +25,15 @@ func Test_runUpdateCmd(t *testing.T) {
|
||||
cmd := UpdateKeyCommand()
|
||||
|
||||
// fails because it requests a password
|
||||
assert.EqualError(t, runUpdateCmd(cmd, []string{fakeKeyName1}), "EOF")
|
||||
err := runUpdateCmd(cmd, []string{fakeKeyName1})
|
||||
|
||||
require.EqualError(t, err, "EOF")
|
||||
|
||||
// try again
|
||||
mockIn, _, _ := tests.ApplyMockIO(cmd)
|
||||
mockIn.Reset("pass1234\n")
|
||||
assert.EqualError(t, runUpdateCmd(cmd, []string{fakeKeyName1}), "Key runUpdateCmd_Key1 not found")
|
||||
err = runUpdateCmd(cmd, []string{fakeKeyName1})
|
||||
require.True(t, errors.Is(err, sdkerrors.ErrKeyNotFound))
|
||||
|
||||
// Prepare a key base
|
||||
// Now add a temporary keybase
|
||||
@ -37,17 +42,17 @@ func Test_runUpdateCmd(t *testing.T) {
|
||||
viper.Set(flags.FlagHome, kbHome)
|
||||
|
||||
kb, err := NewKeyBaseFromDir(viper.GetString(flags.FlagHome))
|
||||
assert.NoError(t, err)
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keys.Secp256k1)
|
||||
assert.NoError(t, err)
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keys.Secp256k1)
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
_, err = kb.CreateAccount(fakeKeyName1, tests.TestMnemonic, "", "", "0", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
_, err = kb.CreateAccount(fakeKeyName2, tests.TestMnemonic, "", "", "1", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Try again now that we have keys
|
||||
// Incorrect key type
|
||||
mockIn.Reset("pass1234\nNew1234\nNew1234")
|
||||
err = runUpdateCmd(cmd, []string{fakeKeyName1})
|
||||
assert.EqualError(t, err, "locally stored key required. Received: keys.offlineInfo")
|
||||
require.EqualError(t, err, "locally stored key required. Received: keyring.offlineInfo")
|
||||
|
||||
// TODO: Check for other type types?
|
||||
}
|
||||
|
||||
@ -7,10 +7,10 @@ import (
|
||||
"github.com/99designs/keyring"
|
||||
"github.com/spf13/viper"
|
||||
"github.com/tendermint/tendermint/libs/cli"
|
||||
"gopkg.in/yaml.v2"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
cryptokeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
)
|
||||
|
||||
// available output formats.
|
||||
@ -22,22 +22,22 @@ const (
|
||||
defaultKeyDBName = "keys"
|
||||
)
|
||||
|
||||
type bechKeyOutFn func(keyInfo keys.Info) (keys.KeyOutput, error)
|
||||
type bechKeyOutFn func(keyInfo cryptokeyring.Info) (cryptokeyring.KeyOutput, error)
|
||||
|
||||
// NewKeyBaseFromDir initializes a keybase at the rootDir directory. Keybase
|
||||
// options can be applied when generating this new Keybase.
|
||||
func NewKeyBaseFromDir(rootDir string, opts ...keys.KeybaseOption) (keys.Keybase, error) {
|
||||
func NewKeyBaseFromDir(rootDir string, opts ...cryptokeyring.KeybaseOption) (cryptokeyring.Keybase, error) {
|
||||
return getLazyKeyBaseFromDir(rootDir, opts...)
|
||||
}
|
||||
|
||||
// NewInMemoryKeyBase returns a storage-less keybase.
|
||||
func NewInMemoryKeyBase() keys.Keybase { return keys.NewInMemory() }
|
||||
func NewInMemoryKeyBase() cryptokeyring.Keybase { return cryptokeyring.NewInMemory() }
|
||||
|
||||
func getLazyKeyBaseFromDir(rootDir string, opts ...keys.KeybaseOption) (keys.Keybase, error) {
|
||||
return keys.New(defaultKeyDBName, filepath.Join(rootDir, "keys"), opts...), nil
|
||||
func getLazyKeyBaseFromDir(rootDir string, opts ...cryptokeyring.KeybaseOption) (cryptokeyring.Keybase, error) {
|
||||
return cryptokeyring.New(defaultKeyDBName, filepath.Join(rootDir, "keys"), opts...), nil
|
||||
}
|
||||
|
||||
func printKeyInfo(keyInfo keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
func printKeyInfo(keyInfo cryptokeyring.Info, bechKeyOut bechKeyOutFn) {
|
||||
ko, err := bechKeyOut(keyInfo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -45,7 +45,7 @@ func printKeyInfo(keyInfo keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
|
||||
switch viper.Get(cli.OutputFlag) {
|
||||
case OutputFormatText:
|
||||
printTextInfos([]keys.KeyOutput{ko})
|
||||
printTextInfos([]cryptokeyring.KeyOutput{ko})
|
||||
|
||||
case OutputFormatJSON:
|
||||
var out []byte
|
||||
@ -63,8 +63,8 @@ func printKeyInfo(keyInfo keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
}
|
||||
}
|
||||
|
||||
func printInfos(infos []keys.Info) {
|
||||
kos, err := keys.Bech32KeysOutput(infos)
|
||||
func printInfos(infos []cryptokeyring.Info) {
|
||||
kos, err := cryptokeyring.Bech32KeysOutput(infos)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -90,7 +90,7 @@ func printInfos(infos []keys.Info) {
|
||||
}
|
||||
}
|
||||
|
||||
func printTextInfos(kos []keys.KeyOutput) {
|
||||
func printTextInfos(kos []cryptokeyring.KeyOutput) {
|
||||
out, err := yaml.Marshal(&kos)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -98,7 +98,7 @@ func printTextInfos(kos []keys.KeyOutput) {
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func printKeyAddress(info keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
func printKeyAddress(info cryptokeyring.Info, bechKeyOut bechKeyOutFn) {
|
||||
ko, err := bechKeyOut(info)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -107,7 +107,7 @@ func printKeyAddress(info keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
fmt.Println(ko.Address)
|
||||
}
|
||||
|
||||
func printPubKey(info keys.Info, bechKeyOut bechKeyOutFn) {
|
||||
func printPubKey(info cryptokeyring.Info, bechKeyOut bechKeyOutFn) {
|
||||
ko, err := bechKeyOut(info)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -1,24 +1,18 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"github.com/cosmos/go-bip39"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
tmcrypto "github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
bip39 "github.com/cosmos/go-bip39"
|
||||
)
|
||||
|
||||
type (
|
||||
kbOptions struct {
|
||||
keygenFunc PrivKeyGenFunc
|
||||
deriveFunc DeriveKeyFunc
|
||||
supportedAlgos []SigningAlgo
|
||||
supportedAlgosLedger []SigningAlgo
|
||||
}
|
||||
|
||||
// baseKeybase is an auxiliary type that groups Keybase storage agnostic features
|
||||
// together.
|
||||
baseKeybase struct {
|
||||
@ -39,34 +33,6 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// WithKeygenFunc applies an overridden key generation function to generate the private key.
|
||||
func WithKeygenFunc(f PrivKeyGenFunc) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.keygenFunc = f
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeriveFunc applies an overridden key derivation function to generate the private key.
|
||||
func WithDeriveFunc(f DeriveKeyFunc) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.deriveFunc = f
|
||||
}
|
||||
}
|
||||
|
||||
// WithSupportedAlgos defines the list of accepted SigningAlgos.
|
||||
func WithSupportedAlgos(algos []SigningAlgo) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.supportedAlgos = algos
|
||||
}
|
||||
}
|
||||
|
||||
// WithSupportedAlgosLedger defines the list of accepted SigningAlgos compatible with Ledger.
|
||||
func WithSupportedAlgosLedger(algos []SigningAlgo) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.supportedAlgosLedger = algos
|
||||
}
|
||||
}
|
||||
|
||||
// newBaseKeybase generates the base keybase with defaulting to tendermint SECP256K1 key type
|
||||
func newBaseKeybase(optionsFns ...KeybaseOption) baseKeybase {
|
||||
// Default options for keybase
|
||||
@ -238,16 +204,6 @@ func (kb baseKeybase) SupportedAlgosLedger() []SigningAlgo {
|
||||
return kb.options.supportedAlgosLedger
|
||||
}
|
||||
|
||||
// IsSupportedAlgorithm returns whether the signing algorithm is in the passed-in list of supported algorithms.
|
||||
func IsSupportedAlgorithm(supported []SigningAlgo, algo SigningAlgo) bool {
|
||||
for _, supportedAlgo := range supported {
|
||||
if algo == supportedAlgo {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SignWithLedger signs a binary message with the ledger device referenced by an Info object
|
||||
// and returns the signed bytes and the public key. It returns an error if the device could
|
||||
// not be queried or it returned an error.
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,59 +10,13 @@ import (
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
var _ Keybase = dbKeybase{}
|
||||
|
||||
// Language is a language to create the BIP 39 mnemonic in.
|
||||
// Currently, only english is supported though.
|
||||
// Find a list of all supported languages in the BIP 39 spec (word lists).
|
||||
type Language int
|
||||
|
||||
//noinspection ALL
|
||||
const (
|
||||
// English is the default language to create a mnemonic.
|
||||
// It is the only supported language by this package.
|
||||
English Language = iota + 1
|
||||
// Japanese is currently not supported.
|
||||
Japanese
|
||||
// Korean is currently not supported.
|
||||
Korean
|
||||
// Spanish is currently not supported.
|
||||
Spanish
|
||||
// ChineseSimplified is currently not supported.
|
||||
ChineseSimplified
|
||||
// ChineseTraditional is currently not supported.
|
||||
ChineseTraditional
|
||||
// French is currently not supported.
|
||||
French
|
||||
// Italian is currently not supported.
|
||||
Italian
|
||||
addressSuffix = "address"
|
||||
infoSuffix = "info"
|
||||
)
|
||||
|
||||
const (
|
||||
// used for deriving seed from mnemonic
|
||||
DefaultBIP39Passphrase = ""
|
||||
|
||||
// bits of entropy to draw when creating a mnemonic
|
||||
defaultEntropySize = 256
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUnsupportedSigningAlgo is raised when the caller tries to use a
|
||||
// different signing scheme than secp256k1.
|
||||
ErrUnsupportedSigningAlgo = errors.New("unsupported signing algo")
|
||||
|
||||
// ErrUnsupportedLanguage is raised when the caller tries to use a
|
||||
// different language than english for creating a mnemonic sentence.
|
||||
ErrUnsupportedLanguage = errors.New("unsupported language: only english is supported")
|
||||
)
|
||||
|
||||
// dbKeybase combines encryption and storage implementation to provide a
|
||||
// full-featured key manager.
|
||||
//
|
||||
@ -163,7 +117,7 @@ func (kb dbKeybase) Get(name string) (Info, error) {
|
||||
}
|
||||
|
||||
if len(bs) == 0 {
|
||||
return nil, keyerror.NewErrKeyNotFound(name)
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, name)
|
||||
}
|
||||
|
||||
return unmarshalInfo(bs)
|
||||
@ -42,4 +42,4 @@
|
||||
// https://www.passwordstore.org/
|
||||
// test This backend stores keys insecurely to disk. It does not prompt for a password to
|
||||
// be unlocked and it should be use only for testing purposes.
|
||||
package keys
|
||||
package keyring
|
||||
13
crypto/keyring/errors.go
Normal file
13
crypto/keyring/errors.go
Normal file
@ -0,0 +1,13 @@
|
||||
package keyring
|
||||
|
||||
import "github.com/pkg/errors"
|
||||
|
||||
var (
|
||||
// ErrUnsupportedSigningAlgo is raised when the caller tries to use a
|
||||
// different signing scheme than secp256k1.
|
||||
ErrUnsupportedSigningAlgo = errors.New("unsupported signing algo")
|
||||
|
||||
// ErrUnsupportedLanguage is raised when the caller tries to use a
|
||||
// different language than english for creating a mnemonic sentence.
|
||||
ErrUnsupportedLanguage = errors.New("unsupported language: only english is supported")
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -10,101 +10,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Keybase exposes operations on a generic keystore
|
||||
type Keybase interface {
|
||||
// CRUD on the keystore
|
||||
List() ([]Info, error)
|
||||
// Get returns the public information about one key.
|
||||
Get(name string) (Info, error)
|
||||
// Get performs a by-address lookup and returns the public
|
||||
// information about one key if there's any.
|
||||
GetByAddress(address types.AccAddress) (Info, error)
|
||||
// Delete removes a key.
|
||||
Delete(name, passphrase string, skipPass bool) error
|
||||
// Sign bytes, looking up the private key to use.
|
||||
Sign(name, passphrase string, msg []byte) ([]byte, crypto.PubKey, error)
|
||||
|
||||
// CreateMnemonic generates a new mnemonic, derives a hierarchical deterministic
|
||||
// key from that. and persists it to storage, encrypted using the provided password.
|
||||
// It returns the generated mnemonic and the key Info. It returns an error if it fails to
|
||||
// generate a key for the given algo type, or if another key is already stored under the
|
||||
// same name.
|
||||
CreateMnemonic(name string, language Language, passwd string, algo SigningAlgo) (info Info, seed string, err error)
|
||||
|
||||
// CreateAccount converts a mnemonic to a private key and BIP 32 HD Path
|
||||
// and persists it, encrypted with the given password.
|
||||
CreateAccount(name, mnemonic, bip39Passwd, encryptPasswd, hdPath string, algo SigningAlgo) (Info, error)
|
||||
|
||||
// CreateLedger creates, stores, and returns a new Ledger key reference
|
||||
CreateLedger(name string, algo SigningAlgo, hrp string, account, index uint32) (info Info, err error)
|
||||
|
||||
// CreateOffline creates, stores, and returns a new offline key reference
|
||||
CreateOffline(name string, pubkey crypto.PubKey, algo SigningAlgo) (info Info, err error)
|
||||
|
||||
// CreateMulti creates, stores, and returns a new multsig (offline) key reference
|
||||
CreateMulti(name string, pubkey crypto.PubKey) (info Info, err error)
|
||||
|
||||
// The following operations will *only* work on locally-stored keys
|
||||
Update(name, oldpass string, getNewpass func() (string, error)) error
|
||||
|
||||
// Import imports ASCII armored Info objects.
|
||||
Import(name string, armor string) (err error)
|
||||
|
||||
// ImportPrivKey imports a private key in ASCII armor format.
|
||||
// It returns an error if a key with the same name exists or a wrong encryption passphrase is
|
||||
// supplied.
|
||||
ImportPrivKey(name, armor, passphrase string) error
|
||||
|
||||
// ImportPubKey imports ASCII-armored public keys.
|
||||
// Store a new Info object holding a public key only, i.e. it will
|
||||
// not be possible to sign with it as it lacks the secret key.
|
||||
ImportPubKey(name string, armor string) (err error)
|
||||
|
||||
// Export exports an Info object in ASCII armored format.
|
||||
Export(name string) (armor string, err error)
|
||||
|
||||
// ExportPubKey returns public keys in ASCII armored format.
|
||||
// Retrieve a Info object by its name and return the public key in
|
||||
// a portable format.
|
||||
ExportPubKey(name string) (armor string, err error)
|
||||
|
||||
// ExportPrivKey returns a private key in ASCII armored format.
|
||||
// It returns an error if the key does not exist or a wrong encryption passphrase is supplied.
|
||||
ExportPrivKey(name, decryptPassphrase, encryptPassphrase string) (armor string, err error)
|
||||
|
||||
// ExportPrivateKeyObject *only* works on locally-stored keys. Temporary method until we redo the exporting API
|
||||
ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)
|
||||
|
||||
// SupportedAlgos returns a list of signing algorithms supported by the keybase
|
||||
SupportedAlgos() []SigningAlgo
|
||||
|
||||
// SupportedAlgosLedger returns a list of signing algorithms supported by the keybase's ledger integration
|
||||
SupportedAlgosLedger() []SigningAlgo
|
||||
}
|
||||
|
||||
// KeyType reflects a human-readable type for key listing.
|
||||
type KeyType uint
|
||||
|
||||
// Info KeyTypes
|
||||
const (
|
||||
TypeLocal KeyType = 0
|
||||
TypeLedger KeyType = 1
|
||||
TypeOffline KeyType = 2
|
||||
TypeMulti KeyType = 3
|
||||
)
|
||||
|
||||
var keyTypes = map[KeyType]string{
|
||||
TypeLocal: "local",
|
||||
TypeLedger: "ledger",
|
||||
TypeOffline: "offline",
|
||||
TypeMulti: "multi",
|
||||
}
|
||||
|
||||
// String implements the stringer interface for KeyType.
|
||||
func (kt KeyType) String() string {
|
||||
return keyTypes[kt]
|
||||
}
|
||||
|
||||
// Info is the publicly exposed information about a keypair
|
||||
type Info interface {
|
||||
// Human-readable type for key listing
|
||||
@ -342,13 +247,3 @@ func unmarshalInfo(bz []byte) (info Info, err error) {
|
||||
err = CryptoCdc.UnmarshalBinaryLengthPrefixed(bz, &info)
|
||||
return
|
||||
}
|
||||
|
||||
type (
|
||||
// DeriveKeyFunc defines the function to derive a new key from a seed and hd path
|
||||
DeriveKeyFunc func(mnemonic string, bip39Passphrase, hdPath string, algo SigningAlgo) ([]byte, error)
|
||||
// PrivKeyGenFunc defines the function to convert derived key bytes to a tendermint private key
|
||||
PrivKeyGenFunc func(bz []byte, algo SigningAlgo) (crypto.PrivKey, error)
|
||||
|
||||
// KeybaseOption overrides options for the db
|
||||
KeybaseOption func(*kbOptions)
|
||||
)
|
||||
79
crypto/keyring/keybase.go
Normal file
79
crypto/keyring/keybase.go
Normal file
@ -0,0 +1,79 @@
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Keybase exposes operations on a generic keystore
|
||||
type Keybase interface {
|
||||
// CRUD on the keystore
|
||||
List() ([]Info, error)
|
||||
// Get returns the public information about one key.
|
||||
Get(name string) (Info, error)
|
||||
// Get performs a by-address lookup and returns the public
|
||||
// information about one key if there's any.
|
||||
GetByAddress(address types.AccAddress) (Info, error)
|
||||
// Delete removes a key.
|
||||
Delete(name, passphrase string, skipPass bool) error
|
||||
// Sign bytes, looking up the private key to use.
|
||||
Sign(name, passphrase string, msg []byte) ([]byte, crypto.PubKey, error)
|
||||
|
||||
// CreateMnemonic generates a new mnemonic, derives a hierarchical deterministic
|
||||
// key from that. and persists it to storage, encrypted using the provided password.
|
||||
// It returns the generated mnemonic and the key Info. It returns an error if it fails to
|
||||
// generate a key for the given algo type, or if another key is already stored under the
|
||||
// same name.
|
||||
CreateMnemonic(name string, language Language, passwd string, algo SigningAlgo) (info Info, seed string, err error)
|
||||
|
||||
// CreateAccount converts a mnemonic to a private key and BIP 32 HD Path
|
||||
// and persists it, encrypted with the given password.
|
||||
CreateAccount(name, mnemonic, bip39Passwd, encryptPasswd, hdPath string, algo SigningAlgo) (Info, error)
|
||||
|
||||
// CreateLedger creates, stores, and returns a new Ledger key reference
|
||||
CreateLedger(name string, algo SigningAlgo, hrp string, account, index uint32) (info Info, err error)
|
||||
|
||||
// CreateOffline creates, stores, and returns a new offline key reference
|
||||
CreateOffline(name string, pubkey crypto.PubKey, algo SigningAlgo) (info Info, err error)
|
||||
|
||||
// CreateMulti creates, stores, and returns a new multsig (offline) key reference
|
||||
CreateMulti(name string, pubkey crypto.PubKey) (info Info, err error)
|
||||
|
||||
// The following operations will *only* work on locally-stored keys
|
||||
Update(name, oldpass string, getNewpass func() (string, error)) error
|
||||
|
||||
// Import imports ASCII armored Info objects.
|
||||
Import(name string, armor string) (err error)
|
||||
|
||||
// ImportPrivKey imports a private key in ASCII armor format.
|
||||
// It returns an error if a key with the same name exists or a wrong encryption passphrase is
|
||||
// supplied.
|
||||
ImportPrivKey(name, armor, passphrase string) error
|
||||
|
||||
// ImportPubKey imports ASCII-armored public keys.
|
||||
// Store a new Info object holding a public key only, i.e. it will
|
||||
// not be possible to sign with it as it lacks the secret key.
|
||||
ImportPubKey(name string, armor string) (err error)
|
||||
|
||||
// Export exports an Info object in ASCII armored format.
|
||||
Export(name string) (armor string, err error)
|
||||
|
||||
// ExportPubKey returns public keys in ASCII armored format.
|
||||
// Retrieve a Info object by its name and return the public key in
|
||||
// a portable format.
|
||||
ExportPubKey(name string) (armor string, err error)
|
||||
|
||||
// ExportPrivKey returns a private key in ASCII armored format.
|
||||
// It returns an error if the key does not exist or a wrong encryption passphrase is supplied.
|
||||
ExportPrivKey(name, decryptPassphrase, encryptPassphrase string) (armor string, err error)
|
||||
|
||||
// ExportPrivateKeyObject *only* works on locally-stored keys. Temporary method until we redo the exporting API
|
||||
ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)
|
||||
|
||||
// SupportedAlgos returns a list of signing algorithms supported by the keybase
|
||||
SupportedAlgos() []SigningAlgo
|
||||
|
||||
// SupportedAlgosLedger returns a list of signing algorithms supported by the keybase's ledger integration
|
||||
SupportedAlgosLedger() []SigningAlgo
|
||||
}
|
||||
@ -1,5 +1,4 @@
|
||||
//nolint: goconst
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -18,9 +18,9 @@ import (
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/input"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey"
|
||||
"github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -145,7 +145,7 @@ func (kb keyringKeybase) List() ([]Info, error) {
|
||||
}
|
||||
|
||||
if len(rawInfo.Data) == 0 {
|
||||
return nil, keyerror.NewErrKeyNotFound(key)
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, key)
|
||||
}
|
||||
|
||||
info, err := unmarshalInfo(rawInfo.Data)
|
||||
@ -170,7 +170,7 @@ func (kb keyringKeybase) Get(name string) (Info, error) {
|
||||
}
|
||||
|
||||
if len(bs.Data) == 0 {
|
||||
return nil, keyerror.NewErrKeyNotFound(name)
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrKeyNotFound, name)
|
||||
}
|
||||
|
||||
return unmarshalInfo(bs.Data)
|
||||
@ -1,5 +1,4 @@
|
||||
// nolint: goconst
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"testing"
|
||||
39
crypto/keyring/options.go
Normal file
39
crypto/keyring/options.go
Normal file
@ -0,0 +1,39 @@
|
||||
package keyring
|
||||
|
||||
// KeybaseOption overrides options for the db
|
||||
type KeybaseOption func(*kbOptions)
|
||||
|
||||
type kbOptions struct {
|
||||
keygenFunc PrivKeyGenFunc
|
||||
deriveFunc DeriveKeyFunc
|
||||
supportedAlgos []SigningAlgo
|
||||
supportedAlgosLedger []SigningAlgo
|
||||
}
|
||||
|
||||
// WithKeygenFunc applies an overridden key generation function to generate the private key.
|
||||
func WithKeygenFunc(f PrivKeyGenFunc) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.keygenFunc = f
|
||||
}
|
||||
}
|
||||
|
||||
// WithDeriveFunc applies an overridden key derivation function to generate the private key.
|
||||
func WithDeriveFunc(f DeriveKeyFunc) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.deriveFunc = f
|
||||
}
|
||||
}
|
||||
|
||||
// WithSupportedAlgos defines the list of accepted SigningAlgos.
|
||||
func WithSupportedAlgos(algos []SigningAlgo) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.supportedAlgos = algos
|
||||
}
|
||||
}
|
||||
|
||||
// WithSupportedAlgosLedger defines the list of accepted SigningAlgos compatible with Ledger.
|
||||
func WithSupportedAlgosLedger(algos []SigningAlgo) KeybaseOption {
|
||||
return func(o *kbOptions) {
|
||||
o.supportedAlgosLedger = algos
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
// SigningAlgo defines an algorithm to derive key-pairs which can be used for cryptographic signing.
|
||||
type SigningAlgo string
|
||||
@ -14,3 +14,13 @@ const (
|
||||
// Sr25519 represents the Sr25519 signature system.
|
||||
Sr25519 = SigningAlgo("sr25519")
|
||||
)
|
||||
|
||||
// IsSupportedAlgorithm returns whether the signing algorithm is in the passed-in list of supported algorithms.
|
||||
func IsSupportedAlgorithm(supported []SigningAlgo, algo SigningAlgo) bool {
|
||||
for _, supportedAlgo := range supported {
|
||||
if algo == supportedAlgo {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
68
crypto/keyring/types.go
Normal file
68
crypto/keyring/types.go
Normal file
@ -0,0 +1,68 @@
|
||||
package keyring
|
||||
|
||||
import "github.com/tendermint/tendermint/crypto"
|
||||
|
||||
// Language is a language to create the BIP 39 mnemonic in.
|
||||
// Currently, only english is supported though.
|
||||
// Find a list of all supported languages in the BIP 39 spec (word lists).
|
||||
type Language int
|
||||
|
||||
const (
|
||||
// English is the default language to create a mnemonic.
|
||||
// It is the only supported language by this package.
|
||||
English Language = iota + 1
|
||||
// Japanese is currently not supported.
|
||||
Japanese
|
||||
// Korean is currently not supported.
|
||||
Korean
|
||||
// Spanish is currently not supported.
|
||||
Spanish
|
||||
// ChineseSimplified is currently not supported.
|
||||
ChineseSimplified
|
||||
// ChineseTraditional is currently not supported.
|
||||
ChineseTraditional
|
||||
// French is currently not supported.
|
||||
French
|
||||
// Italian is currently not supported.
|
||||
Italian
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultBIP39Passphrase used for deriving seed from mnemonic
|
||||
DefaultBIP39Passphrase = ""
|
||||
|
||||
// bits of entropy to draw when creating a mnemonic
|
||||
defaultEntropySize = 256
|
||||
addressSuffix = "address"
|
||||
infoSuffix = "info"
|
||||
)
|
||||
|
||||
// KeyType reflects a human-readable type for key listing.
|
||||
type KeyType uint
|
||||
|
||||
// Info KeyTypes
|
||||
const (
|
||||
TypeLocal KeyType = 0
|
||||
TypeLedger KeyType = 1
|
||||
TypeOffline KeyType = 2
|
||||
TypeMulti KeyType = 3
|
||||
)
|
||||
|
||||
var keyTypes = map[KeyType]string{
|
||||
TypeLocal: "local",
|
||||
TypeLedger: "ledger",
|
||||
TypeOffline: "offline",
|
||||
TypeMulti: "multi",
|
||||
}
|
||||
|
||||
// String implements the stringer interface for KeyType.
|
||||
func (kt KeyType) String() string {
|
||||
return keyTypes[kt]
|
||||
}
|
||||
|
||||
type (
|
||||
// DeriveKeyFunc defines the function to derive a new key from a seed and hd path
|
||||
DeriveKeyFunc func(mnemonic string, bip39Passphrase, hdPath string, algo SigningAlgo) ([]byte, error)
|
||||
// PrivKeyGenFunc defines the function to convert derived key bytes to a tendermint private key
|
||||
PrivKeyGenFunc func(bz []byte, algo SigningAlgo) (crypto.PrivKey, error)
|
||||
)
|
||||
@ -1,4 +1,4 @@
|
||||
package keys
|
||||
package keyring
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
@ -1,81 +0,0 @@
|
||||
package keyerror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
codeKeyNotFound = 1
|
||||
codeWrongPassword = 2
|
||||
)
|
||||
|
||||
type keybaseError interface {
|
||||
error
|
||||
Code() int
|
||||
}
|
||||
|
||||
type errKeyNotFound struct {
|
||||
code int
|
||||
name string
|
||||
}
|
||||
|
||||
func (e errKeyNotFound) Code() int {
|
||||
return e.code
|
||||
}
|
||||
|
||||
func (e errKeyNotFound) Error() string {
|
||||
return fmt.Sprintf("Key %s not found", e.name)
|
||||
}
|
||||
|
||||
// NewErrKeyNotFound returns a standardized error reflecting that the specified key doesn't exist
|
||||
func NewErrKeyNotFound(name string) error {
|
||||
return errKeyNotFound{
|
||||
code: codeKeyNotFound,
|
||||
name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// IsErrKeyNotFound returns true if the given error is errKeyNotFound
|
||||
func IsErrKeyNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if keyErr, ok := err.(keybaseError); ok {
|
||||
if keyErr.Code() == codeKeyNotFound {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type errWrongPassword struct {
|
||||
code int
|
||||
}
|
||||
|
||||
func (e errWrongPassword) Code() int {
|
||||
return e.code
|
||||
}
|
||||
|
||||
func (e errWrongPassword) Error() string {
|
||||
return "invalid account password"
|
||||
}
|
||||
|
||||
// NewErrWrongPassword returns a standardized error reflecting that the specified password is wrong
|
||||
func NewErrWrongPassword() error {
|
||||
return errWrongPassword{
|
||||
code: codeWrongPassword,
|
||||
}
|
||||
}
|
||||
|
||||
// IsErrWrongPassword returns true if the given error is errWrongPassword
|
||||
func IsErrWrongPassword(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if keyErr, ok := err.(keybaseError); ok {
|
||||
if keyErr.Code() == codeWrongPassword {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
package keyerror_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
|
||||
)
|
||||
|
||||
func TestErrors(t *testing.T) {
|
||||
err := keyerror.NewErrKeyNotFound("test")
|
||||
require.True(t, keyerror.IsErrKeyNotFound(err))
|
||||
require.Equal(t, "Key test not found", err.Error())
|
||||
require.False(t, keyerror.IsErrKeyNotFound(errors.New("test")))
|
||||
require.False(t, keyerror.IsErrKeyNotFound(nil))
|
||||
|
||||
err = keyerror.NewErrWrongPassword()
|
||||
require.True(t, keyerror.IsErrWrongPassword(err))
|
||||
require.Equal(t, "invalid account password", err.Error())
|
||||
require.False(t, keyerror.IsErrWrongPassword(errors.New("test")))
|
||||
require.False(t, keyerror.IsErrWrongPassword(nil))
|
||||
}
|
||||
@ -11,8 +11,7 @@ import (
|
||||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
|
||||
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/keyerror"
|
||||
"github.com/cosmos/cosmos-sdk/types/errors"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -139,7 +138,7 @@ func encryptPrivKey(privKey crypto.PrivKey, passphrase string) (saltBytes []byte
|
||||
saltBytes = crypto.CRandBytes(16)
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "error generating bcrypt key from passphrase"))
|
||||
panic(sdkerrors.Wrap(err, "error generating bcrypt key from passphrase"))
|
||||
}
|
||||
key = crypto.Sha256(key) // get 32 bytes
|
||||
privKeyBytes := privKey.Bytes()
|
||||
@ -176,12 +175,12 @@ func UnarmorDecryptPrivKey(armorStr string, passphrase string) (privKey crypto.P
|
||||
func decryptPrivKey(saltBytes []byte, encBytes []byte, passphrase string) (privKey crypto.PrivKey, err error) {
|
||||
key, err := bcrypt.GenerateFromPassword(saltBytes, []byte(passphrase), BcryptSecurityParameter)
|
||||
if err != nil {
|
||||
return privKey, errors.Wrap(err, "error generating bcrypt key from passphrase")
|
||||
return privKey, sdkerrors.Wrap(err, "error generating bcrypt key from passphrase")
|
||||
}
|
||||
key = crypto.Sha256(key) // Get 32 bytes
|
||||
privKeyBytes, err := xsalsa20symmetric.DecryptSymmetric(encBytes, key)
|
||||
if err != nil && err.Error() == "Ciphertext decryption failed" {
|
||||
return privKey, keyerror.NewErrWrongPassword()
|
||||
return privKey, sdkerrors.ErrWrongPassword
|
||||
} else if err != nil {
|
||||
return privKey, err
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||
"github.com/tendermint/tendermint/crypto/xsalsa20symmetric"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/mintkey"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ func TestArmorUnarmorPrivKey(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
decrypted, algo, err := mintkey.UnarmorDecryptPrivKey(armored, "passphrase")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(keys.Secp256k1), algo)
|
||||
require.Equal(t, string(keyring.Secp256k1), algo)
|
||||
require.True(t, priv.Equals(decrypted))
|
||||
|
||||
// empty string
|
||||
@ -67,17 +67,17 @@ func TestArmorUnarmorPrivKey(t *testing.T) {
|
||||
|
||||
func TestArmorUnarmorPubKey(t *testing.T) {
|
||||
// Select the encryption and storage for your cryptostore
|
||||
cstore := keys.NewInMemory()
|
||||
cstore := keyring.NewInMemory()
|
||||
|
||||
// Add keys and see they return in alphabetical order
|
||||
info, _, err := cstore.CreateMnemonic("Bob", keys.English, "passphrase", keys.Secp256k1)
|
||||
info, _, err := cstore.CreateMnemonic("Bob", keyring.English, "passphrase", keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
armored := mintkey.ArmorPubKeyBytes(info.GetPubKey().Bytes(), "")
|
||||
pubBytes, algo, err := mintkey.UnarmorPubKeyBytes(armored)
|
||||
require.NoError(t, err)
|
||||
pub, err := cryptoAmino.PubKeyFromBytes(pubBytes)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, string(keys.Secp256k1), algo)
|
||||
require.Equal(t, string(keyring.Secp256k1), algo)
|
||||
require.True(t, pub.Equals(info.GetPubKey()))
|
||||
|
||||
armored = mintkey.ArmorPubKeyBytes(info.GetPubKey().Bytes(), "unknown")
|
||||
|
||||
@ -3,7 +3,7 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
|
||||
clkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -15,7 +15,7 @@ func GenerateCoinKey() (sdk.AccAddress, string, error) {
|
||||
|
||||
// generate a private key, with recovery phrase
|
||||
info, secret, err := clkeys.NewInMemoryKeyBase().CreateMnemonic(
|
||||
"name", keys.English, "pass", keys.Secp256k1)
|
||||
"name", keyring.English, "pass", keyring.Secp256k1)
|
||||
if err != nil {
|
||||
return sdk.AccAddress([]byte{}), "", err
|
||||
}
|
||||
@ -25,7 +25,7 @@ func GenerateCoinKey() (sdk.AccAddress, string, error) {
|
||||
|
||||
// GenerateSaveCoinKey returns the address of a public key, along with the secret
|
||||
// phrase to recover the private key.
|
||||
func GenerateSaveCoinKey(keybase keys.Keybase, keyName, keyPass string, overwrite bool) (sdk.AccAddress, string, error) {
|
||||
func GenerateSaveCoinKey(keybase keyring.Keybase, keyName, keyPass string, overwrite bool) (sdk.AccAddress, string, error) {
|
||||
// ensure no overwrite
|
||||
if !overwrite {
|
||||
_, err := keybase.Get(keyName)
|
||||
@ -36,7 +36,7 @@ func GenerateSaveCoinKey(keybase keys.Keybase, keyName, keyPass string, overwrit
|
||||
}
|
||||
|
||||
// generate a private key, with recovery phrase
|
||||
info, secret, err := keybase.CreateMnemonic(keyName, keys.English, keyPass, keys.Secp256k1)
|
||||
info, secret, err := keybase.CreateMnemonic(keyName, keyring.English, keyPass, keyring.Secp256k1)
|
||||
if err != nil {
|
||||
return sdk.AccAddress([]byte{}), "", err
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||
crkeys "github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
"github.com/cosmos/cosmos-sdk/tests"
|
||||
)
|
||||
@ -17,7 +17,7 @@ func TestGenerateCoinKey(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test creation
|
||||
info, err := keys.NewInMemoryKeyBase().CreateAccount("xxx", mnemonic, "", "012345678", crkeys.CreateHDPath(0, 0).String(), crkeys.Secp256k1)
|
||||
info, err := keys.NewInMemoryKeyBase().CreateAccount("xxx", mnemonic, "", "012345678", keyring.CreateHDPath(0, 0).String(), keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, addr, info.GetAddress())
|
||||
}
|
||||
@ -27,7 +27,7 @@ func TestGenerateSaveCoinKey(t *testing.T) {
|
||||
dir, cleanup := tests.NewTestCaseDir(t)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
kb, err := crkeys.NewKeyring(t.Name(), "test", dir, nil)
|
||||
kb, err := keyring.NewKeyring(t.Name(), "test", dir, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
addr, mnemonic, err := server.GenerateSaveCoinKey(kb, "keyname", "012345678", false)
|
||||
@ -39,7 +39,7 @@ func TestGenerateSaveCoinKey(t *testing.T) {
|
||||
require.Equal(t, addr, info.GetAddress())
|
||||
|
||||
// Test in-memory recovery
|
||||
info, err = keys.NewInMemoryKeyBase().CreateAccount("xxx", mnemonic, "", "012345678", crkeys.CreateHDPath(0, 0).String(), crkeys.Secp256k1)
|
||||
info, err = keys.NewInMemoryKeyBase().CreateAccount("xxx", mnemonic, "", "012345678", keyring.CreateHDPath(0, 0).String(), keyring.Secp256k1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, addr, info.GetAddress())
|
||||
}
|
||||
@ -49,7 +49,7 @@ func TestGenerateSaveCoinKeyOverwriteFlag(t *testing.T) {
|
||||
dir, cleanup := tests.NewTestCaseDir(t)
|
||||
t.Cleanup(cleanup)
|
||||
|
||||
kb, err := crkeys.NewKeyring(t.Name(), "test", dir, nil)
|
||||
kb, err := keyring.NewKeyring(t.Name(), "test", dir, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
keyname := "justakey"
|
||||
|
||||
@ -82,6 +82,12 @@ var (
|
||||
// ErrTxTooLarge defines an ABCI typed error where tx is too large.
|
||||
ErrTxTooLarge = Register(RootCodespace, 21, "tx too large")
|
||||
|
||||
// ErrKeyNotFound defines an error when the key doesn't exist
|
||||
ErrKeyNotFound = Register(RootCodespace, 22, "key not found")
|
||||
|
||||
// ErrWrongPassword defines an error when the key password is invalid.
|
||||
ErrWrongPassword = Register(RootCodespace, 23, "invalid account password")
|
||||
|
||||
// ErrPanic is only set when we recover from a panic, so we know to
|
||||
// redact potentially sensitive system info
|
||||
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
@ -65,7 +65,7 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
|
||||
}
|
||||
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(),
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(),
|
||||
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), inBuf)
|
||||
if err != nil {
|
||||
return
|
||||
@ -75,8 +75,8 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if multisigInfo.GetType() != keys.TypeMulti {
|
||||
return fmt.Errorf("%q must be of type %s: %s", args[1], keys.TypeMulti, multisigInfo.GetType())
|
||||
if multisigInfo.GetType() != keyring.TypeMulti {
|
||||
return fmt.Errorf("%q must be of type %s: %s", args[1], keyring.TypeMulti, multisigInfo.GetType())
|
||||
}
|
||||
|
||||
multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold)
|
||||
|
||||
@ -10,14 +10,14 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// TxBuilder implements a transaction context created in SDK modules.
|
||||
type TxBuilder struct {
|
||||
txEncoder sdk.TxEncoder
|
||||
keybase keys.Keybase
|
||||
keybase keyring.Keybase
|
||||
accountNumber uint64
|
||||
sequence uint64
|
||||
gas uint64
|
||||
@ -53,7 +53,7 @@ func NewTxBuilder(
|
||||
// NewTxBuilderFromCLI returns a new initialized TxBuilder with parameters from
|
||||
// the command line using Viper.
|
||||
func NewTxBuilderFromCLI(input io.Reader) TxBuilder {
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), input)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -90,7 +90,7 @@ func (bldr TxBuilder) Gas() uint64 { return bldr.gas }
|
||||
func (bldr TxBuilder) GasAdjustment() float64 { return bldr.gasAdjustment }
|
||||
|
||||
// Keybase returns the keybase
|
||||
func (bldr TxBuilder) Keybase() keys.Keybase { return bldr.keybase }
|
||||
func (bldr TxBuilder) Keybase() keyring.Keybase { return bldr.keybase }
|
||||
|
||||
// SimulateAndExecute returns the option to simulate and then execute the transaction
|
||||
// using the gas from the simulation results
|
||||
@ -149,7 +149,7 @@ func (bldr TxBuilder) WithGasPrices(gasPrices string) TxBuilder {
|
||||
}
|
||||
|
||||
// WithKeybase returns a copy of the context with updated keybase.
|
||||
func (bldr TxBuilder) WithKeybase(keybase keys.Keybase) TxBuilder {
|
||||
func (bldr TxBuilder) WithKeybase(keybase keyring.Keybase) TxBuilder {
|
||||
bldr.keybase = keybase
|
||||
return bldr
|
||||
}
|
||||
@ -272,11 +272,11 @@ func (bldr TxBuilder) SignStdTx(name, passphrase string, stdTx StdTx, appendSig
|
||||
}
|
||||
|
||||
// MakeSignature builds a StdSignature given keybase, key name, passphrase, and a StdSignMsg.
|
||||
func MakeSignature(keybase keys.Keybase, name, passphrase string,
|
||||
func MakeSignature(keybase keyring.Keybase, name, passphrase string,
|
||||
msg StdSignMsg) (sig StdSignature, err error) {
|
||||
|
||||
if keybase == nil {
|
||||
keybase, err = keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), os.Stdin)
|
||||
keybase, err = keyring.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), os.Stdin)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
@ -93,7 +93,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm
|
||||
}
|
||||
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(),
|
||||
kb, err := keyring.NewKeyring(sdk.KeyringServiceName(),
|
||||
viper.GetString(flags.FlagKeyringBackend), viper.GetString(flagClientHome), inBuf)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to initialize keybase")
|
||||
@ -137,7 +137,7 @@ func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, sm
|
||||
return errors.Wrap(err, "failed to build create-validator message")
|
||||
}
|
||||
|
||||
if key.GetType() == keys.TypeOffline || key.GetType() == keys.TypeMulti {
|
||||
if key.GetType() == keyring.TypeOffline || key.GetType() == keyring.TypeMulti {
|
||||
fmt.Println("Offline key passed in. Use `tx sign` command to sign:")
|
||||
return authclient.PrintUnsignedStdTx(txBldr, cliCtx, []sdk.Msg{msg})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user