Skip to content

Commit

Permalink
feat: register pubkey type cometbft/PubKeyBls12_381 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
MattKetmo authored Jun 7, 2024
1 parent 715fe4d commit 8ae35b5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/query"
staking "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/fatih/color"
_ "github.com/kilnfi/cosmos-validator-watcher/pkg/crypto"
"github.com/kilnfi/cosmos-validator-watcher/pkg/metrics"
"github.com/kilnfi/cosmos-validator-watcher/pkg/rpc"
"github.com/kilnfi/cosmos-validator-watcher/pkg/watcher"
Expand Down
55 changes: 55 additions & 0 deletions pkg/crypto/bls12_318.go
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
}

0 comments on commit 8ae35b5

Please sign in to comment.