github.com/amazechain/amc@v0.1.3/common/crypto/bls/bls.go (about)

     1  // Package bls implements a go-wrapper around a library implementing the
     2  // the BLS12-381 curve and signature scheme. This package exposes a public API for
     3  // verifying and aggregating BLS signatures used by Ethereum.
     4  package bls
     5  
     6  import (
     7  	"github.com/amazechain/amc/common/crypto/bls/blst"
     8  	"github.com/amazechain/amc/common/crypto/bls/common"
     9  )
    10  
    11  // Initialize herumi temporarily while we transition to blst for ethdo.
    12  func init() {
    13  }
    14  
    15  // SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.
    16  func SecretKeyFromBytes(privKey []byte) (SecretKey, error) {
    17  	return blst.SecretKeyFromBytes(privKey)
    18  }
    19  
    20  // PublicKeyFromBytes creates a BLS public key from a  BigEndian byte slice.
    21  func PublicKeyFromBytes(pubKey []byte) (PublicKey, error) {
    22  	return blst.PublicKeyFromBytes(pubKey)
    23  }
    24  
    25  // SignatureFromBytes creates a BLS signature from a LittleEndian byte slice.
    26  func SignatureFromBytes(sig []byte) (Signature, error) {
    27  	return blst.SignatureFromBytes(sig)
    28  }
    29  
    30  // MultipleSignaturesFromBytes creates a slice of BLS signatures from a LittleEndian 2d-byte slice.
    31  func MultipleSignaturesFromBytes(sigs [][]byte) ([]Signature, error) {
    32  	return blst.MultipleSignaturesFromBytes(sigs)
    33  }
    34  
    35  // AggregatePublicKeys aggregates the provided raw public keys into a single key.
    36  func AggregatePublicKeys(pubs [][]byte) (PublicKey, error) {
    37  	return blst.AggregatePublicKeys(pubs)
    38  }
    39  
    40  // AggregateMultiplePubkeys aggregates the provided decompressed keys into a single key.
    41  func AggregateMultiplePubkeys(pubs []PublicKey) PublicKey {
    42  	return blst.AggregateMultiplePubkeys(pubs)
    43  }
    44  
    45  // AggregateSignatures converts a list of signatures into a single, aggregated sig.
    46  func AggregateSignatures(sigs []common.Signature) common.Signature {
    47  	return blst.AggregateSignatures(sigs)
    48  }
    49  
    50  // AggregateCompressedSignatures converts a list of compressed signatures into a single, aggregated sig.
    51  func AggregateCompressedSignatures(multiSigs [][]byte) (common.Signature, error) {
    52  	return blst.AggregateCompressedSignatures(multiSigs)
    53  }
    54  
    55  // VerifyMultipleSignatures verifies multiple signatures for distinct messages securely.
    56  func VerifyMultipleSignatures(sigs [][]byte, msgs [][32]byte, pubKeys []common.PublicKey) (bool, error) {
    57  	return blst.VerifyMultipleSignatures(sigs, msgs, pubKeys)
    58  }
    59  
    60  // NewAggregateSignature creates a blank aggregate signature.
    61  func NewAggregateSignature() common.Signature {
    62  	return blst.NewAggregateSignature()
    63  }
    64  
    65  // RandKey creates a new private key using a random input.
    66  func RandKey() (common.SecretKey, error) {
    67  	return blst.RandKey()
    68  }
    69  
    70  // SecretKeyFromRandom32Byte creates a new private key using random 32 bytes
    71  func SecretKeyFromRandom32Byte(ikm [32]byte) (common.SecretKey, error) {
    72  	return blst.SecretKeyFromRandom32Byte(ikm)
    73  }