From 7a95f401b125ec78be72c66e2e282fae3c6667a3 Mon Sep 17 00:00:00 2001 From: LAP02459 Date: Fri, 24 Feb 2023 09:56:34 +0700 Subject: [PATCH] add pubkey --- account/account.go | 3 +-- account/pubkey.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 account/pubkey.go 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 +}