Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: register pubkey type cometbft/PubKeyBls12_381 #73

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading