Skip to content

Commit 47c119f

Browse files
committed
fix: register key type PubKeySecp256k1eth
1 parent 85bf55d commit 47c119f

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

pkg/crypto/secp256k1_eth.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package crypto
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
7+
"github.com/cometbft/cometbft/crypto"
8+
"github.com/cometbft/cometbft/crypto/tmhash"
9+
cmtjson "github.com/cometbft/cometbft/libs/json"
10+
)
11+
12+
const (
13+
Secp256k1ethPubKeyName = "cometbft/PubKeySecp256k1eth"
14+
)
15+
16+
func init() {
17+
cmtjson.RegisterType(Secp256k1ethPubKey{}, Secp256k1ethPubKeyName)
18+
}
19+
20+
var _ crypto.PubKey = Secp256k1ethPubKey{}
21+
22+
type Secp256k1ethPubKey []byte
23+
24+
// Address is the SHA256-20 of the raw pubkey bytes.
25+
func (pubKey Secp256k1ethPubKey) Address() crypto.Address {
26+
// if len(pubKey) != PubKeySize {
27+
// panic("pubkey is incorrect size")
28+
// }
29+
return crypto.Address(tmhash.SumTruncated(pubKey))
30+
}
31+
32+
// Bytes returns the PubKey byte format.
33+
func (pubKey Secp256k1ethPubKey) Bytes() []byte {
34+
return []byte(pubKey)
35+
}
36+
37+
func (pubKey Secp256k1ethPubKey) VerifySignature(msg []byte, sig []byte) bool {
38+
return false
39+
}
40+
41+
func (pubKey Secp256k1ethPubKey) String() string {
42+
return fmt.Sprintf("PubKeySecp256k1eth_381{%X}", []byte(pubKey))
43+
}
44+
45+
func (Secp256k1ethPubKey) Type() string {
46+
return "Secp256k1eth_381"
47+
}
48+
49+
func (pubKey Secp256k1ethPubKey) Equals(other crypto.PubKey) bool {
50+
if otherEd, ok := other.(Secp256k1ethPubKey); ok {
51+
return bytes.Equal(pubKey[:], otherEd[:])
52+
}
53+
54+
return false
55+
}

0 commit comments

Comments
 (0)