-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9b8f1e
commit 7a95f40
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |