forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e2a1c3
commit dfd0f01
Showing
19 changed files
with
1,868 additions
and
543 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package batch | ||
|
||
import ( | ||
"github.com/cometbft/cometbft/crypto" | ||
"github.com/cometbft/cometbft/crypto/ed25519" | ||
"github.com/cometbft/cometbft/crypto/sr25519" | ||
) | ||
|
||
// CreateBatchVerifier checks if a key type implements the batch verifier interface. | ||
// Currently only ed25519 & sr25519 supports batch verification. | ||
func CreateBatchVerifier(pk crypto.PubKey) (crypto.BatchVerifier, bool) { | ||
switch pk.Type() { | ||
case ed25519.KeyType: | ||
return ed25519.NewBatchVerifier(), true | ||
case sr25519.KeyType: | ||
return sr25519.NewBatchVerifier(), true | ||
} | ||
|
||
// case where the key does not support batch verification | ||
return nil, false | ||
} | ||
|
||
// SupportsBatchVerifier checks if a key type implements the batch verifier | ||
// interface. | ||
func SupportsBatchVerifier(pk crypto.PubKey) bool { | ||
switch pk.Type() { | ||
case ed25519.KeyType, sr25519.KeyType: | ||
return true | ||
} | ||
|
||
return false | ||
} |
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
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
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,46 @@ | ||
package sr25519 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/oasisprotocol/curve25519-voi/primitives/sr25519" | ||
|
||
"github.com/cometbft/cometbft/crypto" | ||
) | ||
|
||
var _ crypto.BatchVerifier = &BatchVerifier{} | ||
|
||
// BatchVerifier implements batch verification for sr25519. | ||
type BatchVerifier struct { | ||
*sr25519.BatchVerifier | ||
} | ||
|
||
func NewBatchVerifier() crypto.BatchVerifier { | ||
return &BatchVerifier{sr25519.NewBatchVerifier()} | ||
} | ||
|
||
func (b *BatchVerifier) Add(key crypto.PubKey, msg, signature []byte) error { | ||
pk, ok := key.(PubKey) | ||
if !ok { | ||
return fmt.Errorf("sr25519: pubkey is not sr25519") | ||
} | ||
|
||
var srpk sr25519.PublicKey | ||
if err := srpk.UnmarshalBinary(pk); err != nil { | ||
return fmt.Errorf("sr25519: invalid public key: %w", err) | ||
} | ||
|
||
var sig sr25519.Signature | ||
if err := sig.UnmarshalBinary(signature); err != nil { | ||
return fmt.Errorf("sr25519: unable to decode signature: %w", err) | ||
} | ||
|
||
st := signingCtx.NewTranscriptBytes(msg) | ||
b.BatchVerifier.Add(&srpk, st, &sig) | ||
|
||
return nil | ||
} | ||
|
||
func (b *BatchVerifier) Verify() (bool, []bool) { | ||
return b.BatchVerifier.Verify(crypto.CReader()) | ||
} |
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 |
---|---|---|
@@ -1,23 +1,13 @@ | ||
package sr25519 | ||
|
||
import ( | ||
"github.com/cometbft/cometbft/crypto" | ||
cmtjson "github.com/cometbft/cometbft/libs/json" | ||
) | ||
|
||
var _ crypto.PrivKey = PrivKey{} | ||
import tmjson "github.com/tendermint/tendermint/libs/json" | ||
|
||
const ( | ||
PrivKeyName = "tendermint/PrivKeySr25519" | ||
PubKeyName = "tendermint/PubKeySr25519" | ||
|
||
// SignatureSize is the size of an Edwards25519 signature. Namely the size of a compressed | ||
// Sr25519 point, and a field element. Both of which are 32 bytes. | ||
SignatureSize = 64 | ||
) | ||
|
||
func init() { | ||
|
||
cmtjson.RegisterType(PubKey{}, PubKeyName) | ||
cmtjson.RegisterType(PrivKey{}, PrivKeyName) | ||
tmjson.RegisterType(PubKey{}, PubKeyName) | ||
tmjson.RegisterType(PrivKey{}, PrivKeyName) | ||
} |
Oops, something went wrong.