2018-10-18 05:44:00 +00:00
|
|
|
// Package bls implements a go-wrapper around a C BLS library leveraging
|
|
|
|
// the BLS12-381 curve. This package exposes a public API for verifying and
|
2018-11-01 11:02:01 +00:00
|
|
|
// aggregating BLS signatures used by Ethereum Serenity.
|
2018-10-18 05:44:00 +00:00
|
|
|
package bls
|
|
|
|
|
2018-11-08 03:22:31 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
)
|
2018-10-18 05:44:00 +00:00
|
|
|
|
|
|
|
// Signature used in the BLS signature scheme.
|
|
|
|
type Signature struct{}
|
|
|
|
|
|
|
|
// SecretKey used in the BLS scheme.
|
2018-11-08 03:22:31 +00:00
|
|
|
type SecretKey struct {
|
|
|
|
K *big.Int
|
|
|
|
}
|
2018-10-18 05:44:00 +00:00
|
|
|
|
|
|
|
// PublicKey corresponding to secret key used in the BLS scheme.
|
|
|
|
type PublicKey struct{}
|
|
|
|
|
2018-11-08 03:22:31 +00:00
|
|
|
// PublicKey returns the corresponding public key for the
|
|
|
|
// Secret Key
|
|
|
|
func (s *SecretKey) PublicKey() (*PublicKey, error) {
|
|
|
|
return &PublicKey{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// BufferedSecretKey returns the secret key in a byte format.
|
|
|
|
func (s *SecretKey) BufferedSecretKey() []byte {
|
|
|
|
return s.K.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
// BufferedPublicKey returns the public key in a byte format.
|
|
|
|
func (p *PublicKey) BufferedPublicKey() []byte {
|
|
|
|
return []byte{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnBufferSecretKey takes the byte representation of a secret key
|
|
|
|
// and sets it to a big int of the underlying secret key object.
|
|
|
|
func (s *SecretKey) UnBufferSecretKey(bufferedKey []byte) {
|
|
|
|
s.K = big.NewInt(0).SetBytes(bufferedKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnBufferPublicKey takes the byte representation of a public key
|
|
|
|
// and sets it to a big int of the underlying public key object.
|
|
|
|
func (p *PublicKey) UnBufferPublicKey(bufferedKey []byte) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenerateKey generates a new secret key using a seed.
|
|
|
|
func GenerateKey(seed []byte) *SecretKey {
|
|
|
|
return &SecretKey{
|
|
|
|
K: big.NewInt(0).SetBytes(seed),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 05:44:00 +00:00
|
|
|
// Sign a message using a secret key - in a beacon/validator client,
|
|
|
|
// this key will come from and be unlocked from the account keystore.
|
|
|
|
func Sign(sec *SecretKey, msg []byte) (*Signature, error) {
|
|
|
|
return &Signature{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifySig against a public key.
|
|
|
|
func VerifySig(pub *PublicKey, msg []byte, sig *Signature) (bool, error) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyAggregateSig created using the underlying BLS signature
|
|
|
|
// aggregation scheme.
|
|
|
|
func VerifyAggregateSig(pubs []*PublicKey, msg []byte, asig *Signature) (bool, error) {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// BatchVerify a list of individual signatures by aggregating them.
|
|
|
|
func BatchVerify(pubs []*PublicKey, msg []byte, sigs []*Signature) (bool, error) {
|
|
|
|
asigs, err := AggregateSigs(sigs)
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("could not aggregate signatures: %v", err)
|
|
|
|
}
|
|
|
|
return VerifyAggregateSig(pubs, msg, asigs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AggregateSigs puts multiple signatures into one using the underlying
|
|
|
|
// BLS sum functions.
|
|
|
|
func AggregateSigs(sigs []*Signature) (*Signature, error) {
|
|
|
|
return &Signature{}, nil
|
|
|
|
}
|