Skip to content

Commit

Permalink
add pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
dungtt-astra committed Feb 24, 2023
1 parent a9b8f1e commit 7a95f40
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
38 changes: 38 additions & 0 deletions account/pubkey.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7a95f40

Please sign in to comment.