github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/cl/ursa/verifier.go (about) 1 //go:build ursa 2 // +build ursa 3 4 /* 5 Copyright Avast Software. All Rights Reserved. 6 7 SPDX-License-Identifier: Apache-2.0 8 */ 9 10 package ursa 11 12 import ( 13 "fmt" 14 15 "github.com/hyperledger/aries-framework-go/pkg/doc/cl" 16 ) 17 18 // Verifier is an ursa implementation of the CL Verifier API. 19 type Verifier struct{} 20 21 // NewVerifier insaniates Verifier service. 22 func NewVerifier() (*Verifier, error) { 23 return &Verifier{}, nil 24 } 25 26 // RequestPresentation generates PresentationRequest with unique nonce and provided list of attrs and predicates 27 // returns: 28 // request as *PresentationRequest 29 // error in case of errors 30 func (s *Verifier) RequestPresentation(items []*cl.PresentationRequestItem) (*cl.PresentationRequest, error) { 31 nonce, err := newNonce() 32 if err != nil { 33 return nil, err 34 } 35 36 return &cl.PresentationRequest{Items: items, Nonce: nonce}, nil 37 } 38 39 // VerifyProof verifies given Proof according to PresentationRequest and CredDefs 40 // returns: 41 // error in case of errors or nil if proof verification was successful 42 func (s *Verifier) VerifyProof(proof *cl.Proof, 43 presentationRequest *cl.PresentationRequest, 44 credDefs []*cl.CredentialDefinition, 45 ) error { 46 if len(presentationRequest.Items) != len(credDefs) { 47 return fmt.Errorf("not enough credential definitions provided to fulfill the presentsation request") 48 } 49 50 var subProofItems []*subProofItem 51 52 for i, item := range presentationRequest.Items { 53 subProofItem := &subProofItem{ 54 CredentialDefinition: credDefs[i], 55 Item: item, 56 } 57 58 subProofItems = append(subProofItems, subProofItem) 59 } 60 61 err := verifyProof(proof, subProofItems, presentationRequest.Nonce) 62 63 return err 64 }