Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle import of ethereum privkeys with 0x. Trust node by default #167

Merged
merged 1 commit into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}