bump SDK commit (#324)

* bump SDK commit

* crypto: Secp256k1 algorithm

* crypto: fix codec and derivation issues

* lint
This commit is contained in:
Federico Kunze
2020-06-08 12:19:26 -04:00
committed by GitHub
parent a745e66f3e
commit 5614adc933
11 changed files with 323 additions and 53 deletions
+11 -5
View File
@@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -33,7 +34,7 @@ func unsafeExportEthKeyCommand() *cobra.Command {
func runExportCmd(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := keyring.NewKeyring(
keystore, err := keyring.New(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flags.FlagHome),
@@ -54,14 +55,19 @@ func runExportCmd(cmd *cobra.Command, args []string) error {
case keyring.BackendOS:
conf, err = input.GetConfirmation(
"**WARNING** this is an unsafe way to export your unencrypted private key, are you sure?",
inBuf)
inBuf, cmd.ErrOrStderr())
}
if err != nil || !conf {
return err
}
// Exports private key from keybase using password
privKey, err := kb.ExportPrivateKeyObject(args[0], decryptPassword)
// Exports private key from keyring using password
armored, err := keystore.ExportPrivKeyArmor(args[0], decryptPassword)
if err != nil {
return err
}
privKey, _, err := crypto.UnarmorDecryptPrivKey(armored, decryptPassword)
if err != nil {
return err
}
@@ -69,7 +75,7 @@ func runExportCmd(cmd *cobra.Command, args []string) error {
// Converts key to Ethermint secp256 implementation
emintKey, ok := privKey.(emintcrypto.PrivKeySecp256k1)
if !ok {
return fmt.Errorf("invalid private key type, must be Ethereum key: %T", privKey)
return fmt.Errorf("invalid private key type %T, must be Ethereum key PrivKeySecp256k1", privKey)
}
// Formats key for output
+8 -13
View File
@@ -4,14 +4,12 @@ import (
"bufio"
"io"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client/flags"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
emintCrypto "github.com/cosmos/ethermint/crypto"
ethermintcrypto "github.com/cosmos/ethermint/crypto"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -52,29 +50,26 @@ func keyCommands() *cobra.Command {
return cmd
}
func getKeybase(transient bool, buf io.Reader) (keyring.Keybase, error) {
func getKeyring(transient bool, buf io.Reader) (keyring.Keyring, error) {
if transient {
return keyring.NewInMemory(keyring.WithKeygenFunc(ethermintKeygenFunc)), nil
return keyring.NewInMemory(ethermintcrypto.EthSeckp256k1Option), nil
}
return keyring.NewKeyring(
return keyring.New(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flags.FlagHome),
buf,
keyring.WithKeygenFunc(ethermintKeygenFunc))
keyring.Option(ethermintcrypto.EthSeckp256k1Option),
)
}
func runAddCmd(cmd *cobra.Command, args []string) error {
inBuf := bufio.NewReader(cmd.InOrStdin())
kb, err := getKeybase(viper.GetBool(flagDryRun), inBuf)
keystore, err := getKeyring(viper.GetBool(flagDryRun), inBuf)
if err != nil {
return err
}
return clientkeys.RunAddCmd(cmd, args, kb, inBuf)
}
func ethermintKeygenFunc(bz []byte, algo keyring.SigningAlgo) (crypto.PrivKey, error) {
return emintCrypto.PrivKeySecp256k1(bz), nil
return clientkeys.RunAddCmd(cmd, args, keystore, inBuf)
}
+6 -6
View File
@@ -43,19 +43,19 @@ func AddGenesisAccountCmd(
Short: "Add a genesis account to genesis.json",
Long: `Add a genesis account to genesis.json. The provided account must specify
the account address or key name and a list of initial coins. If a key name is given,
the address will be looked up in the local Keybase. The list of initial tokens must
the address will be looked up in the local Keyring. The list of initial tokens must
contain valid denominations. Accounts may optionally be supplied with vesting parameters.
`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))
inBuf := bufio.NewReader(cmd.InOrStdin())
addr, err := sdk.AccAddressFromBech32(args[0])
inBuf := bufio.NewReader(cmd.InOrStdin())
if err != nil {
// attempt to lookup address from Keybase if no address was provided
kb, err := keyring.NewKeyring(
// attempt to lookup address from keyring if no address was provided
keystore, err := keyring.New(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flagClientHome),
@@ -65,9 +65,9 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
return err
}
info, err := kb.Get(args[0])
info, err := keystore.Key(args[0])
if err != nil {
return fmt.Errorf("failed to get address from Keybase: %w", err)
return fmt.Errorf("failed to get address from Keyring: %w", err)
}
addr = info.GetAddress()