Files
tendermint/crypto/sr25519/batch.go
Marko 6ffdf181f2 crypto: ed25519 & sr25519 batch verification (#6120)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
2021-03-15 10:58:49 +00:00

43 lines
1.0 KiB
Go

package sr25519
import (
"fmt"
schnorrkel "github.com/ChainSafe/go-schnorrkel"
"github.com/tendermint/tendermint/crypto"
)
var _ crypto.BatchVerifier = BatchVerifier{}
// BatchVerifier implements batch verification for sr25519.
// https://github.com/ChainSafe/go-schnorrkel is used for batch verification
type BatchVerifier struct {
*schnorrkel.BatchVerifier
}
func NewBatchVerifier() crypto.BatchVerifier {
return BatchVerifier{schnorrkel.NewBatchVerifier()}
}
func (b BatchVerifier) Add(key crypto.PubKey, msg, sig []byte) error {
var sig64 [SignatureSize]byte
copy(sig64[:], sig)
signature := new(schnorrkel.Signature)
err := signature.Decode(sig64)
if err != nil {
return fmt.Errorf("unable to decode signature: %w", err)
}
signingContext := schnorrkel.NewSigningContext([]byte{}, msg)
var pk [PubKeySize]byte
copy(pk[:], key.Bytes())
return b.BatchVerifier.Add(signingContext, signature, schnorrkel.NewPublicKey(pk))
}
func (b BatchVerifier) Verify() bool {
return b.BatchVerifier.Verify()
}