Skip to content

Commit

Permalink
#150 Handle import of ethereum privkeys with 0x. #151 Trust node
Browse files Browse the repository at this point in the history
  • Loading branch information
arturalbov committed Jan 10, 2019
1 parent b61bbef commit 5b31eb2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cli/commands/keys/importprivate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const hashPrefix = "0x"

func importPrivateKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "import_private <name>",
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions util/strings.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5b31eb2

Please sign in to comment.