From 5b31eb23d64efee3b9c945c50a441cae3b20e972 Mon Sep 17 00:00:00 2001 From: Artur Albov Date: Thu, 10 Jan 2019 15:52:33 +0300 Subject: [PATCH] #150 Handle import of ethereum privkeys with 0x. #151 Trust node --- cli/commands/keys/importprivate.go | 7 +++++++ cli/main.go | 4 ++++ util/strings.go | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 util/strings.go diff --git a/cli/commands/keys/importprivate.go b/cli/commands/keys/importprivate.go index 49fd8098..aeff1f98 100644 --- a/cli/commands/keys/importprivate.go +++ b/cli/commands/keys/importprivate.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/crypto/keys/mintkey" + "github.com/cybercongress/cyberd/util" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/tendermint/btcd/btcec" @@ -15,6 +16,8 @@ import ( "github.com/tendermint/tendermint/libs/cli" ) +const hashPrefix = "0x" + func importPrivateKeyCmd() *cobra.Command { cmd := &cobra.Command{ Use: "import_private ", @@ -45,6 +48,10 @@ func importPrivateKeyCmd() *cobra.Command { return err } + if util.HasPrefixIgnoreCase(privateKey, hashPrefix) { + privateKey = privateKey[len(hashPrefix):] + } + b, _ := hex.DecodeString(privateKey) privKey, pubKey := btcec.PrivKeyFromBytes(btcec.S256(), b) diff --git a/cli/main.go b/cli/main.go index 02820048..dd8b7527 100644 --- a/cli/main.go +++ b/cli/main.go @@ -3,6 +3,7 @@ package main import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cybercongress/cyberd/cli/commands/keys" + "github.com/spf13/viper" "github.com/tendermint/go-amino" "os" @@ -67,6 +68,9 @@ func main() { cyberdcmd.LinkTxCmd(cdc), )...) + // todo: hack till we don't handle with all merkle proofs + viper.SetDefault(client.FlagTrustNode, true) + executor := cli.PrepareMainCmd(cyberdcli, "CBD", os.ExpandEnv("$HOME/.cyberdcli")) err := executor.Execute() if err != nil { diff --git a/util/strings.go b/util/strings.go new file mode 100644 index 00000000..4b508d73 --- /dev/null +++ b/util/strings.go @@ -0,0 +1,10 @@ +package util + +import "strings" + +func HasPrefixIgnoreCase(s, prefix string) bool { + lowerCaseS := strings.ToLower(s) + lowerCasePrefix := strings.ToLower(prefix) + + return strings.HasPrefix(lowerCaseS, lowerCasePrefix) +}