func (bbs *BBSG2Pub) SignWithKey(messages [][]byte, privKey *PrivateKey) ([]byte, error) {
	var err error
	pubKey := privKey.PublicKey()
	messagesCount := len(messages)
	pubKeyWithGenerators, err := pubKey.ToPublicKeyWithGenerators(messagesCount)
	if err != nil {
		return nil, fmt.Errorf("build generators from public key: %w", err)
	}
	messagesFr := make([]*SignatureMessage, len(messages))
	for i := range messages {
		messagesFr[i] = ParseSignatureMessage(messages[i])
	}
	e, s := createRandSignatureFr(), createRandSignatureFr()
	exp := bls12381.NewFr().Set(privKey.FR)
	exp.Add(exp, e)
	exp.Inverse(exp)
	sig := g1.New()
	b := computeB(s, messagesFr, pubKeyWithGenerators)
	g1.MulScalar(sig, b, frToRepr(exp))
	signature := &Signature{
		A: sig,
		E: e,
		S: s,
	}
	return signature.ToBytes()
}
SignWithKey signs the one or more messages using BBS+ key pair.
package bbs12381g2pub
import (
	"errors"
	"fmt"
	"sort"
	bls12381 "github.com/kilic/bls12-381"
)
var (
	g1 = bls12381.NewG1()
	g2 = bls12381.NewG2()
)
type BBSG2Pub struct{}
func New() *BBSG2Pub {
	return &BBSG2Pub{}
}
const (
	bls12381SignatureLen = 112
	bls12381G2PublicKeyLen = 96
	g1CompressedSize = 48
	g1UncompressedSize = 96
	g2UncompressedSize = 192
	frCompressedSize = 32
	frUncompressedSize = 48
)
func (bbs *BBSG2Pub) Verify(messages [][]byte, sigBytes, pubKeyBytes []byte) error {
	signature, err := ParseSignature(sigBytes)
	if err != nil {
		return fmt.Errorf("parse signature: %w", err)
	}
	pubKey, err := UnmarshalPublicKey(pubKeyBytes)
	if err != nil {
		return fmt.Errorf("parse public key: %w", err)
	}
	messagesCount := len(messages)
	publicKeyWithGenerators, err := pubKey.ToPublicKeyWithGenerators(messagesCount)
	if err != nil {
		return fmt.Errorf("build generators from public key: %w", err)
	}
	messagesFr := messagesToFr(messages)
	return signature.Verify(messagesFr, publicKeyWithGenerators)
}
func (bbs *BBSG2Pub) Sign(messages [][]byte, privKeyBytes []byte) ([]byte, error) {
	privKey, err := UnmarshalPrivateKey(privKeyBytes)
	if err != nil {
		return nil, fmt.Errorf("unmarshal private key: %w", err)
	}
	if len(messages) == 0 {
		return nil, errors.New("messages are not defined")
	}
	return bbs.SignWithKey(messages, privKey)
}
func (bbs *BBSG2Pub) VerifyProof(messagesBytes [][]byte, proof, nonce, pubKeyBytes []byte) error {
	payload, err := parsePoKPayload(proof)
	if err != nil {
		return fmt.Errorf("parse signature proof: %w", err)
	}
	signatureProof, err := ParseSignatureProof(proof[payload.lenInBytes():])
	if err != nil {
		return fmt.Errorf("parse signature proof: %w", err)
	}
	messages := messagesToFr(messagesBytes)
	pubKey, err := UnmarshalPublicKey(pubKeyBytes)
	if err != nil {
		return fmt.Errorf("parse public key: %w", err)
	}
	publicKeyWithGenerators, err := pubKey.ToPublicKeyWithGenerators(payload.messagesCount)
	if err != nil {
		return fmt.Errorf("build generators from public key: %w", err)
	}
	if len(payload.revealed) > len(messages) {
		return fmt.Errorf("payload revealed bigger from messages")
	}
	revealedMessages := make(map[int]*SignatureMessage)
	for i := range payload.revealed {
		revealedMessages[payload.revealed[i]] = messages[i]
	}
	challengeBytes := signatureProof.GetBytesForChallenge(revealedMessages, publicKeyWithGenerators)
	proofNonce := ParseProofNonce(nonce)
	proofNonceBytes := proofNonce.ToBytes()
	challengeBytes = append(challengeBytes, proofNonceBytes...)
	proofChallenge := frFromOKM(challengeBytes)
	return signatureProof.Verify(proofChallenge, publicKeyWithGenerators, revealedMessages, messages)
}
func (bbs *BBSG2Pub) DeriveProof(messages [][]byte, sigBytes, nonce, pubKeyBytes []byte,
	revealedIndexes []int) ([]byte, error) {
	if len(revealedIndexes) == 0 {
		return nil, errors.New("no message to reveal")
	}
	sort.Ints(revealedIndexes)
	messagesCount := len(messages)
	messagesFr := messagesToFr(messages)
	pubKey, err := UnmarshalPublicKey(pubKeyBytes)
	if err != nil {
		return nil, fmt.Errorf("parse public key: %w", err)
	}
	publicKeyWithGenerators, err := pubKey.ToPublicKeyWithGenerators(messagesCount)
	if err != nil {
		return nil, fmt.Errorf("build generators from public key: %w", err)
	}
	signature, err := ParseSignature(sigBytes)
	if err != nil {
		return nil, fmt.Errorf("parse signature: %w", err)
	}
	pokSignature, err := NewPoKOfSignature(signature, messagesFr, revealedIndexes, publicKeyWithGenerators)
	if err != nil {
		return nil, fmt.Errorf("init proof of knowledge signature: %w", err)
	}
	challengeBytes := pokSignature.ToBytes()
	proofNonce := ParseProofNonce(nonce)
	proofNonceBytes := proofNonce.ToBytes()
	challengeBytes = append(challengeBytes, proofNonceBytes...)
	proofChallenge := frFromOKM(challengeBytes)
	proof := pokSignature.GenerateProof(proofChallenge)
	payload := newPoKPayload(messagesCount, revealedIndexes)
	payloadBytes, err := payload.toBytes()
	if err != nil {
		return nil, fmt.Errorf("derive proof: paylod to bytes: %w", err)
	}
	signatureProofBytes := append(payloadBytes, proof.ToBytes()...)
	return signatureProofBytes, nil
}