-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: register pubkey type cometbft/PubKeyBls12_381 (#73)
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 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,55 @@ | ||
package crypto | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/cometbft/cometbft/crypto" | ||
"github.com/cometbft/cometbft/crypto/tmhash" | ||
cmtjson "github.com/cometbft/cometbft/libs/json" | ||
) | ||
|
||
const ( | ||
PubKeyName = "cometbft/PubKeyBls12_381" | ||
) | ||
|
||
func init() { | ||
cmtjson.RegisterType(Bls12PubKey{}, PubKeyName) | ||
} | ||
|
||
var _ crypto.PubKey = Bls12PubKey{} | ||
|
||
type Bls12PubKey []byte | ||
|
||
// Address is the SHA256-20 of the raw pubkey bytes. | ||
func (pubKey Bls12PubKey) Address() crypto.Address { | ||
// if len(pubKey) != PubKeySize { | ||
// panic("pubkey is incorrect size") | ||
// } | ||
return crypto.Address(tmhash.SumTruncated(pubKey)) | ||
} | ||
|
||
// Bytes returns the PubKey byte format. | ||
func (pubKey Bls12PubKey) Bytes() []byte { | ||
return []byte(pubKey) | ||
} | ||
|
||
func (pubKey Bls12PubKey) VerifySignature(msg []byte, sig []byte) bool { | ||
return false | ||
} | ||
|
||
func (pubKey Bls12PubKey) String() string { | ||
return fmt.Sprintf("PubKeyBls12_381{%X}", []byte(pubKey)) | ||
} | ||
|
||
func (Bls12PubKey) Type() string { | ||
return "bls12_381" | ||
} | ||
|
||
func (pubKey Bls12PubKey) Equals(other crypto.PubKey) bool { | ||
if otherEd, ok := other.(Bls12PubKey); ok { | ||
return bytes.Equal(pubKey[:], otherEd[:]) | ||
} | ||
|
||
return false | ||
} |