diff --git a/account/account.go b/account/account.go index 0e7af2f..abdf6b3 100644 --- a/account/account.go +++ b/account/account.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptoTypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/go-bip39" "github.com/evmos/ethermint/crypto/ethsecp256k1" ethermintHd "github.com/evmos/ethermint/crypto/hd" ethermintTypes "github.com/evmos/ethermint/types" @@ -25,7 +24,7 @@ func NewAccount(coinType uint32) *Account { return &Account{coinType: coinType} } -func Pubkey(pk string) (*ethsecp256k1.PubKey, error) { +func importPubkey(pk string) (*ethsecp256k1.PubKey, error) { if strings.ContainsAny(pk, "{") { pk = strings.Split(strings.Split(pk, "{")[1], "}")[0] diff --git a/account/pubkey.go b/account/pubkey.go new file mode 100755 index 0000000..27d914a --- /dev/null +++ b/account/pubkey.go @@ -0,0 +1,38 @@ +package account + +import ( + "encoding/hex" + "strings" + + cryptoTypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" +) + +type PKAccount struct { + publicKey ethsecp256k1.PubKey +} + +func NewPKAccount(pubkey string) *PKAccount { + pubkey = strings.Split(strings.Split(pubkey, "{")[1], "}")[0] + key, err := hex.DecodeString(pubkey) + if err != nil { + panic(err) + } + return &PKAccount{ + publicKey: ethsecp256k1.PubKey{ + Key: key, + }, + } +} + +func (pka *PKAccount) PublicKey() cryptoTypes.PubKey { + return &pka.publicKey +} + +func (pka *PKAccount) AccAddress() types.AccAddress { + pub := pka.PublicKey() + addr := types.AccAddress(pub.Address()) + + return addr +}