Skip to content

Commit 766278c

Browse files
authored
fix: partial support for pubkey Bn254 (#99)
Related to #98
1 parent ea2e85a commit 766278c

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

pkg/crypto/bls12_318.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
)
1111

1212
const (
13-
PubKeyName = "cometbft/PubKeyBls12_381"
13+
Bls12PubKeyName = "cometbft/PubKeyBls12_381"
1414
)
1515

1616
func init() {
17-
cmtjson.RegisterType(Bls12PubKey{}, PubKeyName)
17+
cmtjson.RegisterType(Bls12PubKey{}, Bls12PubKeyName)
1818
}
1919

2020
var _ crypto.PubKey = Bls12PubKey{}

pkg/crypto/bn254.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+
Bn254PubKeyName = "cometbft/PubKeyBn254"
14+
)
15+
16+
func init() {
17+
cmtjson.RegisterType(Bn254PubKey{}, Bn254PubKeyName)
18+
}
19+
20+
var _ crypto.PubKey = Bn254PubKey{}
21+
22+
type Bn254PubKey []byte
23+
24+
// Address is the SHA256-20 of the raw pubkey bytes.
25+
func (pubKey Bn254PubKey) 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 Bn254PubKey) Bytes() []byte {
34+
return []byte(pubKey)
35+
}
36+
37+
func (pubKey Bn254PubKey) VerifySignature(msg []byte, sig []byte) bool {
38+
return false
39+
}
40+
41+
func (pubKey Bn254PubKey) String() string {
42+
return fmt.Sprintf("PubKeyBn254{%X}", []byte(pubKey))
43+
}
44+
45+
func (Bn254PubKey) Type() string {
46+
return "Bn254"
47+
}
48+
49+
func (pubKey Bn254PubKey) Equals(other crypto.PubKey) bool {
50+
if otherEd, ok := other.(Bn254PubKey); ok {
51+
return bytes.Equal(pubKey[:], otherEd[:])
52+
}
53+
54+
return false
55+
}

0 commit comments

Comments
 (0)