prysm-pulse/shared/bls/bls.go
Nishant Das f0e2f561d5
Make BLST The Permanent Default (#8710)
* remove herumi

* gaz

* deprecate flag

* remove source builds of herumi

* remove

* Revert "remove source builds of herumi"

This reverts commit ac7dd133eddcd9ab27d7d75e19efabd994b89d3c.

* disable blst

* remove herumi hard requirement from fuzz

* restrict viz, ensure all deps removed from fuzz

* remove source builds

* add back opts

* add back herumi initialization

* Revert "add back opts"

This reverts commit ad9b409b8ad2410142efba92e71c555fedb2a29e.

* Revert "remove source builds"

This reverts commit b78ee30dba1befad24262648e2fde1583263c87d.

* Revert "restrict viz, ensure all deps removed from fuzz"

This reverts commit 65d951da93103eb327643c3c167ae7498955d244.

* Revert "remove herumi hard requirement from fuzz"

This reverts commit ad92191d8146bf7fea4508fb99a1ae9267683f6d.

* redundant

* add lock for rand generation

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
2021-04-07 10:18:19 -05:00

75 lines
2.4 KiB
Go

// Package bls implements a go-wrapper around a library implementing the
// the BLS12-381 curve and signature scheme. This package exposes a public API for
// verifying and aggregating BLS signatures used by Ethereum 2.0.
package bls
import (
"math/big"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/bls/blst"
"github.com/prysmaticlabs/prysm/shared/bls/common"
"github.com/prysmaticlabs/prysm/shared/bls/herumi"
)
// Initialize herumi temporarily while we transition to blst for ethdo.
func init() {
herumi.HerumiInit()
}
// SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.
func SecretKeyFromBytes(privKey []byte) (SecretKey, error) {
return blst.SecretKeyFromBytes(privKey)
}
// SecretKeyFromBigNum takes in a big number string and creates a BLS private key.
func SecretKeyFromBigNum(s string) (SecretKey, error) {
num := new(big.Int)
num, ok := num.SetString(s, 10)
if !ok {
return nil, errors.New("could not set big int from string")
}
bts := num.Bytes()
// Pad key at the start with zero bytes to make it into a 32 byte key.
if len(bts) < 32 {
emptyBytes := make([]byte, 32-len(bts))
bts = append(emptyBytes, bts...)
}
return SecretKeyFromBytes(bts)
}
// PublicKeyFromBytes creates a BLS public key from a BigEndian byte slice.
func PublicKeyFromBytes(pubKey []byte) (PublicKey, error) {
return blst.PublicKeyFromBytes(pubKey)
}
// SignatureFromBytes creates a BLS signature from a LittleEndian byte slice.
func SignatureFromBytes(sig []byte) (Signature, error) {
return blst.SignatureFromBytes(sig)
}
// AggregatePublicKeys aggregates the provided raw public keys into a single key.
func AggregatePublicKeys(pubs [][]byte) (PublicKey, error) {
return blst.AggregatePublicKeys(pubs)
}
// AggregateSignatures converts a list of signatures into a single, aggregated sig.
func AggregateSignatures(sigs []common.Signature) common.Signature {
return blst.AggregateSignatures(sigs)
}
// VerifyMultipleSignatures verifies multiple signatures for distinct messages securely.
func VerifyMultipleSignatures(sigs [][]byte, msgs [][32]byte, pubKeys []common.PublicKey) (bool, error) {
return blst.VerifyMultipleSignatures(sigs, msgs, pubKeys)
}
// NewAggregateSignature creates a blank aggregate signature.
func NewAggregateSignature() common.Signature {
return blst.NewAggregateSignature()
}
// RandKey creates a new private key using a random input.
func RandKey() (common.SecretKey, error) {
return blst.RandKey()
}