Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit cfac906

Browse files
authored
Ethermint key generation (#78)
* WIP setting up Ethereum key CLI commands * Functional key gen and showing Ethereum address * Cleaned up changes * WIP setting up Ethereum key CLI commands * Functional key gen and showing Ethereum address * Cleaned up changes * Changed address to cosmos specific address * Remove default bech32 prefixes and add basic add command test * Changed Private key type to slice of bytes for compatibility and storability * switch back to using cosmos crypto Keybase interfaces * Changed key output to ethereum addressing instead of bitcoin and key generation to allow seeding from mnemonic and bip39 password * Updated show command and added test * Remove prefix requirement for showing keys and added existing keys commands to CLI temporarily * Removed unnecessary duplicate code * Readd prefixes for accounts temporarily * Fix linting issue * Remove TODO for setting PK to specific length of bytes (all functions use slice) * Cleaned up descriptions to remove multi-sigs
1 parent 92dc7d9 commit cfac906

File tree

22 files changed

+1742
-18
lines changed

22 files changed

+1742
-18
lines changed

app/test_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func newTestStdFee() auth.StdFee {
9090
// GenerateAddress generates an Ethereum address.
9191
func newTestAddrKey() (sdk.AccAddress, tmcrypto.PrivKey) {
9292
privkey, _ := crypto.GenerateKey()
93-
addr := ethcrypto.PubkeyToAddress(privkey.PublicKey)
93+
addr := ethcrypto.PubkeyToAddress(privkey.ToECDSA().PublicKey)
9494

9595
return sdk.AccAddress(addr.Bytes()), privkey
9696
}

cmd/emintcli/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package main
22

33
import (
4-
"github.com/cosmos/ethermint/rpc"
5-
"github.com/tendermint/go-amino"
64
"os"
75
"path"
86

9-
"github.com/cosmos/cosmos-sdk/client"
107
"github.com/cosmos/cosmos-sdk/client/keys"
8+
"github.com/cosmos/ethermint/rpc"
9+
"github.com/tendermint/go-amino"
10+
11+
"github.com/cosmos/cosmos-sdk/client"
1112
sdkrpc "github.com/cosmos/cosmos-sdk/client/rpc"
1213
sdk "github.com/cosmos/cosmos-sdk/types"
14+
emintkeys "github.com/cosmos/ethermint/keys"
1315

1416
emintapp "github.com/cosmos/ethermint/app"
1517
"github.com/spf13/cobra"
@@ -24,6 +26,7 @@ func main() {
2426

2527
// Read in the configuration file for the sdk
2628
config := sdk.GetConfig()
29+
// TODO: Remove or change prefix if usable to generate Ethereum address
2730
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
2831
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
2932
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
@@ -49,7 +52,9 @@ func main() {
4952
// TODO: Set up rest routes (if included, different from web3 api)
5053
rpc.Web3RpcCmd(cdc),
5154
client.LineBreak,
55+
// TODO: Remove these commands once ethermint keys and genesis set up
5256
keys.Commands(),
57+
emintkeys.Commands(),
5358
client.LineBreak,
5459
)
5560

cmd/emintd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func main() {
2828
cdc := emintapp.MakeCodec()
2929

3030
config := sdk.GetConfig()
31+
// TODO: Remove or change prefix if usable to generate Ethereum address
3132
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
3233
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
3334
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)

crypto/codec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package crypto
22

3-
import "github.com/cosmos/cosmos-sdk/codec"
3+
import (
4+
"github.com/cosmos/cosmos-sdk/codec"
5+
)
46

57
var cryptoCodec = codec.New()
68

crypto/keys/codec.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package keys
2+
3+
import (
4+
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino"
5+
6+
"github.com/cosmos/cosmos-sdk/codec"
7+
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
8+
emintCrypto "github.com/cosmos/ethermint/crypto"
9+
cosmosKeys "github.com/cosmos/cosmos-sdk/crypto/keys"
10+
)
11+
12+
var cdc *codec.Codec
13+
14+
func init() {
15+
cdc = codec.New()
16+
cryptoAmino.RegisterAmino(cdc)
17+
cdc.RegisterInterface((*cosmosKeys.Info)(nil), nil)
18+
emintCrypto.RegisterCodec(cdc)
19+
cdc.RegisterConcrete(hd.BIP44Params{}, "crypto/keys/hd/BIP44Params", nil)
20+
cdc.RegisterConcrete(localInfo{}, "crypto/keys/localInfo", nil)
21+
cdc.RegisterConcrete(ledgerInfo{}, "crypto/keys/ledgerInfo", nil)
22+
cdc.RegisterConcrete(offlineInfo{}, "crypto/keys/offlineInfo", nil)
23+
// cdc.RegisterConcrete(multiInfo{}, "crypto/keys/multiInfo", nil)
24+
cdc.Seal()
25+
}

0 commit comments

Comments
 (0)