github.com/trustbloc/kms-go@v1.1.2/crypto/tinkcrypto/primitive/bbs/subtle/bls12381g2_verifier.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package subtle
     8  
     9  import "github.com/trustbloc/bbs-signature-go/bbs12381g2pub"
    10  
    11  // BLS12381G2Verifier is the BBS+ signature/proof verifier for keys on BLS12-381 curve with a point in the G2 group.
    12  // Currently this is the only available BBS+ verifier in aries-framework-go (see `pkg/doc/bbs/bbs12381g2pub/bbs.go`).
    13  // Other BBS+ verifiers can be added later if needed.
    14  type BLS12381G2Verifier struct {
    15  	signerPubKeyBytes []byte
    16  	bbsPrimitive      *bbs12381g2pub.BBSG2Pub
    17  }
    18  
    19  // NewBLS12381G2Verifier creates a new instance of BLS12381G2Verifier with the provided signerPublicKey.
    20  func NewBLS12381G2Verifier(signerPublicKey []byte) *BLS12381G2Verifier {
    21  	return &BLS12381G2Verifier{
    22  		signerPubKeyBytes: signerPublicKey,
    23  		bbsPrimitive:      bbs12381g2pub.New(),
    24  	}
    25  }
    26  
    27  // Verify will verify an aggregated signature of one or more messages against the signer's public key.
    28  // returns:
    29  //
    30  //	error in case of errors or nil if signature verification was successful
    31  func (v *BLS12381G2Verifier) Verify(messages [][]byte, signature []byte) error {
    32  	return v.bbsPrimitive.Verify(messages, signature, v.signerPubKeyBytes)
    33  }
    34  
    35  // VerifyProof will verify a BBS+ signature proof (generated e.g. by DeriveProof()) with the signer's public key.
    36  // returns:
    37  //
    38  //	error in case of errors or nil if signature proof verification was successful
    39  func (v *BLS12381G2Verifier) VerifyProof(messages [][]byte, proof, nonce []byte) error {
    40  	return v.bbsPrimitive.VerifyProof(messages, proof, nonce, v.signerPubKeyBytes)
    41  }
    42  
    43  // DeriveProof will create a BBS+ signature proof for a list of revealed messages using BBS signature
    44  // (can be built using a Signer's Sign() call) and the signer's public key.
    45  // returns:
    46  //
    47  //	signature proof in []byte
    48  //	error in case of errors
    49  func (v *BLS12381G2Verifier) DeriveProof(messages [][]byte, signature, nonce []byte,
    50  	revealedIndexes []int) ([]byte, error) {
    51  	return v.bbsPrimitive.DeriveProof(messages, signature, nonce, v.signerPubKeyBytes, revealedIndexes)
    52  }