forked from cerc-io/laconicd-deprecated
+5
-11
@@ -13,7 +13,6 @@ 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"
|
||||
|
||||
@@ -34,7 +33,7 @@ func unsafeExportEthKeyCommand() *cobra.Command {
|
||||
func runExportCmd(cmd *cobra.Command, args []string) error {
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
|
||||
keystore, err := keyring.New(
|
||||
kb, err := keyring.NewKeyring(
|
||||
sdk.KeyringServiceName(),
|
||||
viper.GetString(flags.FlagKeyringBackend),
|
||||
viper.GetString(flags.FlagHome),
|
||||
@@ -55,19 +54,14 @@ 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, cmd.ErrOrStderr())
|
||||
inBuf)
|
||||
}
|
||||
if err != nil || !conf {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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)
|
||||
// Exports private key from keybase using password
|
||||
privKey, err := kb.ExportPrivateKeyObject(args[0], decryptPassword)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -75,7 +69,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 %T, must be Ethereum key PrivKeySecp256k1", privKey)
|
||||
return fmt.Errorf("invalid private key type, must be Ethereum key: %T", privKey)
|
||||
}
|
||||
|
||||
// Formats key for output
|
||||
|
||||
+13
-8
@@ -4,12 +4,14 @@ 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"
|
||||
|
||||
ethermintcrypto "github.com/cosmos/ethermint/crypto"
|
||||
emintCrypto "github.com/cosmos/ethermint/crypto"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
@@ -50,26 +52,29 @@ func keyCommands() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func getKeyring(transient bool, buf io.Reader) (keyring.Keyring, error) {
|
||||
func getKeybase(transient bool, buf io.Reader) (keyring.Keybase, error) {
|
||||
if transient {
|
||||
return keyring.NewInMemory(ethermintcrypto.EthSeckp256k1Option), nil
|
||||
return keyring.NewInMemory(keyring.WithKeygenFunc(ethermintKeygenFunc)), nil
|
||||
}
|
||||
|
||||
return keyring.New(
|
||||
return keyring.NewKeyring(
|
||||
sdk.KeyringServiceName(),
|
||||
viper.GetString(flags.FlagKeyringBackend),
|
||||
viper.GetString(flags.FlagHome),
|
||||
buf,
|
||||
keyring.Option(ethermintcrypto.EthSeckp256k1Option),
|
||||
)
|
||||
keyring.WithKeygenFunc(ethermintKeygenFunc))
|
||||
}
|
||||
|
||||
func runAddCmd(cmd *cobra.Command, args []string) error {
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
keystore, err := getKeyring(viper.GetBool(flagDryRun), inBuf)
|
||||
kb, err := getKeybase(viper.GetBool(flagDryRun), inBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return clientkeys.RunAddCmd(cmd, args, keystore, inBuf)
|
||||
return clientkeys.RunAddCmd(cmd, args, kb, inBuf)
|
||||
}
|
||||
|
||||
func ethermintKeygenFunc(bz []byte, algo keyring.SigningAlgo) (crypto.PrivKey, error) {
|
||||
return emintCrypto.PrivKeySecp256k1(bz), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user