async def verifyProof(self, msg: Any): body, (frm, _) = msg link = self.verifyAndGetLink(msg) if not link: raise NotImplementedError proof = body[PROOF_FIELD] proofRequest = ProofRequest.from_str_dict(body[PROOF_REQUEST_FIELD]) nonce = getNonceForProof(body[NONCE]) proofName = proofRequest.name proofs = {} for key, p in proof['proofs'].items(): schema = await self.verifier.wallet.getSchema( ID(schemaId=int(p['schema_seq_no']))) pk = await self.verifier.wallet.getPublicKey( ID(schemaKey=schema.getKey())) proofs[key] = ProofInfo.from_str_dict(p, str(pk.N)) proof = FullProof( proofs, AggregatedProof.from_str_dict(proof['aggregated_proof']), RequestedProof.from_str_dict(proof['requested_proof'])) result = await self.verifier.verify(proofRequest, proof) self.logger.info('Proof "{}" accepted with nonce {}'.format( proofName, nonce)) self.logger.info('Verifying proof "{}" from {}'.format( proofName, link.name)) status = 'verified' if result else 'failed verification' resp = { TYPE: PROOF_STATUS, DATA: ' Your Proof {} {} was received and {}\n'.format( proofRequest.name, proofRequest.version, status), } self.signAndSend(resp, link.localIdentifier, frm, origReqId=body.get(f.REQ_ID.nm)) if result: for uuid, attribute in proofRequest.verifiableAttributes.items(): # Log attributes that were verified self.logger.info('verified {}: {}'.format( attribute.name, proof.requestedProof.revealed_attrs[uuid][1])) self.logger.info( 'Verified that proof "{}" contains attributes ' 'from claim(s) issued by: {}'.format( proofName, ", ".join( sorted([v.issuer_did for k, v in proof.proofs.items()])))) await self._postProofVerif(proofName, link, frm) else: self.logger.info( 'Verification failed for proof {} from {} '.format( proofName, link.name))
async def _prepareProof(self, claims: Dict[SchemaKey, ProofClaims], nonce, requestedProof) -> FullProof: m1Tilde = cmod.integer(cmod.randomBits(LARGE_M2_TILDE)) initProofs = {} CList = [] TauList = [] # 1. init proofs for schemaId, val in claims.items(): c1, c2, revealedAttrs, predicates = val.claims.primaryClaim, val.claims.nonRevocClaim, val.revealedAttrs, val.predicates claim = await self.wallet.getClaimAttributes(ID(schemaId=schemaId)) nonRevocInitProof = None if c2: nonRevocInitProof = await self._nonRevocProofBuilder.initProof( schemaId, c2) CList += nonRevocInitProof.asCList() TauList += nonRevocInitProof.asTauList() primaryInitProof = None if c1: m2Tilde = cmod.integer(int(nonRevocInitProof.TauListParams.m2) ) if nonRevocInitProof else None primaryInitProof = await self._primaryProofBuilder.initProof( schemaId, c1, revealedAttrs, predicates, m1Tilde, m2Tilde, claim) CList += primaryInitProof.asCList() TauList += primaryInitProof.asTauList() initProof = InitProof(nonRevocInitProof, primaryInitProof) initProofs[schemaId] = initProof # 2. hash cH = self._get_hash(self._prepare_collection(CList), self._prepare_collection(TauList), nonce) # 3. finalize proofs proofs = {} for schemaId, initProof in initProofs.items(): nonRevocProof = None if initProof.nonRevocInitProof: nonRevocProof = await self._nonRevocProofBuilder.finalizeProof( schemaId, cH, initProof.nonRevocInitProof) primaryProof = await self._primaryProofBuilder.finalizeProof( schemaId, cH, initProof.primaryInitProof) schema = await self.wallet.getSchema(ID(schemaId=schemaId)) proof = Proof(primaryProof, nonRevocProof) proofInfo = ProofInfo(proof=proof, schema_seq_no=schemaId, issuer_did=schema.issuerId) proofs[str(schemaId)] = proofInfo aggregatedProof = AggregatedProof(cH, self._prepare_collection(CList)) return FullProof(proofs, aggregatedProof, requestedProof)
async def testSingleIssuerMultipleCredDefsSingleProver(primes1, primes2): # 1. Init entities publicRepo = PublicRepoInMemory() attrRepo = AttributeRepoInMemory() issuer = Issuer(IssuerWalletInMemory('issuer1', publicRepo), attrRepo) # 2. Create a Schema schema1 = await issuer.genSchema('GVT', '1.0', GVT.attribNames()) schemaId1 = ID(schema1.getKey()) schema2 = await issuer.genSchema('XYZCorp', '1.0', XYZCorp.attribNames()) schemaId2 = ID(schema2.getKey()) # 3. Create keys for the Schema await issuer.genKeys(schemaId1, **primes1) await issuer.genKeys(schemaId2, **primes2) # 4. Issue accumulator await issuer.issueAccumulator(schemaId=schemaId1, iA='110', L=5) await issuer.issueAccumulator(schemaId=schemaId2, iA=9999999, L=5) # 4. set attributes for user1 userId = '111' attrs1 = GVT.attribs(name='Alex', age=28, height=175, sex='male') attrs2 = XYZCorp.attribs(status='FULL', period=8) attrRepo.addAttributes(schema1.getKey(), userId, attrs1) attrRepo.addAttributes(schema2.getKey(), userId, attrs2) # 5. request Claims prover = Prover(ProverWalletInMemory(userId, publicRepo)) claimsReqs = await prover.createClaimRequests([schemaId1, schemaId2]) claims = await issuer.issueClaims(claimsReqs) await prover.processClaims(claims) # 6. proof Claims verifier = Verifier(WalletInMemory('verifier1', publicRepo)) proofRequest = ProofRequest("proof1", "1.0", verifier.generateNonce(), verifiableAttributes={ 'attr_uuid1': AttributeInfo('name', schema1.seqId) }, predicates={ 'predicate_uuid1': PredicateGE('age', 18), 'predicate_uuid2': PredicateGE('period', 5) }) proof = await prover.presentProof(proofRequest) assert proof.requestedProof.revealed_attrs['attr_uuid1'][1] == 'Alex' assert await verifier.verify(proofRequest, proof)
async def testMultiplIssuersSingleProver(primes1, primes2): # 1. Init entities publicRepo = PublicRepoInMemory() attrRepo = AttributeRepoInMemory() issuer1 = Issuer(IssuerWalletInMemory('issuer1', publicRepo), attrRepo) issuer2 = Issuer(IssuerWalletInMemory('issuer2', publicRepo), attrRepo) # 2. Create a Schema schema1 = await issuer1.genSchema('GVT', '1.0', GVT.attribNames()) schemaId1 = ID(schema1.getKey()) schema2 = await issuer2.genSchema('XYZCorp', '1.0', XYZCorp.attribNames()) schemaId2 = ID(schema2.getKey()) # 3. Create keys for the Schema await issuer1.genKeys(schemaId1, **primes1) await issuer2.genKeys(schemaId2, **primes2) # 4. Issue accumulator await issuer1.issueAccumulator(schemaId=schemaId1, iA='110', L=5) await issuer2.issueAccumulator(schemaId=schemaId2, iA=9999999, L=5) # 4. set attributes for user1 userId = '111' attrs1 = GVT.attribs(name='Alex', age=28, height=175, sex='male') attrs2 = XYZCorp.attribs(status='FULL', period=8) attrRepo.addAttributes(schema1.getKey(), userId, attrs1) attrRepo.addAttributes(schema2.getKey(), userId, attrs2) # 5. request Claims prover = Prover(ProverWalletInMemory(userId, publicRepo)) claimsReq1 = await prover.createClaimRequest(schemaId1) claimsReq2 = await prover.createClaimRequest(schemaId2) claims1 = await issuer1.issueClaim(schemaId1, claimsReq1) claims2 = await issuer2.issueClaim(schemaId2, claimsReq2) await prover.processClaim(schemaId1, claims1) await prover.processClaim(schemaId2, claims2) # 6. proof Claims proofInput = ProofInput(['name', 'status'], [PredicateGE('age', 18), PredicateGE('period', 5)]) verifier = Verifier(WalletInMemory('verifier1', publicRepo)) nonce = verifier.generateNonce() proof, revealedAttrs = await prover.presentProof(proofInput, nonce) assert revealedAttrs['name'] == 'Alex' assert revealedAttrs['status'] == 'FULL' assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
async def testSingleIssuerSingleProver(primes1): # 1. Init entities publicRepo = PublicRepoInMemory() attrRepo = AttributeRepoInMemory() issuer = Issuer(IssuerWalletInMemory('issuer1', publicRepo), attrRepo) # 2. Create a Schema schema = await issuer.genSchema('GVT', '1.0', GVT.attribNames()) schemaId = ID(schema.getKey()) # 3. Create keys for the Schema await issuer.genKeys(schemaId, **primes1) # 4. Issue accumulator await issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) # 4. set attributes for user1 userId = '111' attrs = GVT.attribs(name='Alex', age=28, height=175, sex='male') attrRepo.addAttributes(schema.getKey(), userId, attrs) # 5. request Claims prover = Prover(ProverWalletInMemory(userId, publicRepo)) claimsReq = await prover.createClaimRequest(schemaId) claims = await issuer.issueClaim(schemaId, claimsReq) await prover.processClaim(schemaId, claims) # 6. proof Claims proofInput = ProofInput(['name'], [PredicateGE('age', 18)]) verifier = Verifier(WalletInMemory('verifier1', publicRepo)) nonce = verifier.generateNonce() proof, revealedAttrs = await prover.presentProof(proofInput, nonce) assert revealedAttrs['name'] == 'Alex' assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
async def publish_schema(self, attrib_def_name, schema_name, schema_version): attribDef = self._attribDefs[attrib_def_name] schema = await self.issuer.genSchema(schema_name, schema_version, attribDef.attribNames()) schema_id = ID(schemaKey=schema.getKey(), schemaId=schema.seqId) return schema_id
async def create_proof_request(conn): # 1. Init entities public_repo = PublicRepoInMemory() attr_repo = AttributeRepoInMemory() issuer = Issuer(IssuerWalletInMemory('issuer1', public_repo), attr_repo) # 2. Create a Schema schema = await issuer.genSchema('GVT', '1.0', GVT.attribNames()) schema_id = ID(schema.getKey()) # 3. Create keys for the Schema global global_dict await issuer.wallet.submitPublicKeys(schema_id, global_dict['public_key']) # 4. set attributes for user1 prover_id = 'BzfFCYk' attributes = GVT.attribs(name='Alex', age=28, height=175, sex='male') attr_repo.addAttributes(schema.getKey(), prover_id, attributes) verifier = Verifier(WalletInMemory('verifier1', public_repo)) proof_request = ProofRequest( name='Test_proof', version='1.0', nonce=verifier.generateNonce(), verifiableAttributes={ 'attr_uuid': AttributeInfo('name', schema.seqId)}, predicates={'predicate_uuid': PredicateGE('age', 18)}) global_dict['verifier'] = verifier global_dict['proof_request'] = proof_request conn.send(json.dumps(proof_request.to_str_dict()).encode())
async def getMatchingConnectionsWithReceivedClaimAsync( self, claimName=None): matchingLinkAndAvailableClaim = self.wallet.getMatchingConnectionsWithAvailableClaim( claimName) matchingLinkAndReceivedClaim = [] for li, cl in matchingLinkAndAvailableClaim: name, version, origin = cl schemaKeyId = ID( SchemaKey(name=name, version=version, issuerId=origin)) schema = await self.prover.wallet.getSchema(schemaKeyId) claimAttrs = OrderedDict() for attr in schema.attrNames: claimAttrs[attr] = None attrs = None try: attrs = await self.prover.wallet.getClaimAttributes(schemaKeyId ) except ValueError: pass # it means no claim was issued if attrs: if set(claimAttrs.keys()).intersection(attrs.keys()): for k in claimAttrs.keys(): claimAttrs[k] = attrs[k].raw matchingLinkAndReceivedClaim.append((li, cl, claimAttrs)) return matchingLinkAndReceivedClaim
async def getSchema(schemaKey): schema = await self.issuer.wallet.getSchema(ID(schemaKey)) return { NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }
async def getJobCertAvailableClaimList(self): schema = await self.issuer.wallet.getSchema(ID(self._schemaJobCertKey)) return [{ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }]
async def doTestAnonCredsPrimaryOnly(): # 1. Create a Schema schema = await issuer.genSchema('GVT', '1.0', GVT.attribNames()) schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId) # 2. Create keys for the Schema await issuer.genKeys(schemaId, **primes1) # 3. Issue accumulator #TODO: Not implemented yet #await issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) # 4. set attributes for user1 attrs = GVT.attribs(name='Alex', age=28, height=175, sex='male') proverId = str(prover.proverId) attrRepo.addAttributes(schema.getKey(), proverId, attrs) # 5. request Claims claimsReq = await prover.createClaimRequest(schemaId, proverId, False) claims = await issuer.issueClaim(schemaId, claimsReq) await prover.processClaim(schemaId, claims) # 6. proof Claims proofInput = ProofInput( ['name'], [PredicateGE('age', 18)]) nonce = verifier.generateNonce() proof, revealedAttrs = await prover.presentProof(proofInput, nonce) assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
async def issuer_init(primes, conn): # 1. Init entities public_repo = PublicRepoInMemory() attr_repo = AttributeRepoInMemory() issuer = Issuer(IssuerWalletInMemory('issuer1', public_repo), attr_repo) # 2. Create a Schema schema = await issuer.genSchema('GVT', '1.0', GVT.attribNames()) schema_id = ID(schema.getKey()) # 3. Create keys for the Schema await issuer.genKeys(schema_id, **primes) # 4. Issue accumulator await issuer.issueAccumulator(schemaId=schema_id, iA='110', L=5) # 4. set attributes for user1 prover_id = 'BzfFCYk' attributes = GVT.attribs(name='Alex', age=28, height=175, sex='male') attr_repo.addAttributes(schema.getKey(), prover_id, attributes) public_key = await issuer.wallet.getPublicKey(schema_id) global global_dict global_dict = { 'schema_id': schema_id, 'public_key': public_key, 'issuer': issuer } conn.send( json.dumps({ 'primary': public_key.to_str_dict(), 'revocation': None }).encode())
async def handleReqClaimResponse(self, msg): body, _ = msg issuerId = body.get(IDENTIFIER) claim = body[DATA] li = self._getLinkByTarget(getCryptonym(issuerId)) if li: schemaId = ID(schemaId=claim[SCHEMA_SEQ_NO]) schema = await self.prover.wallet.getSchema(schemaId) self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(' Received claim "{}".\n'.format( schema.name)) pk = await self.prover.wallet.getPublicKey(schemaId) claim_attributes = { k: ClaimAttributeValues.from_str_dict(v) for k, v in json.loads(claim[CLAIM_FIELD]).items() } claim_signature = Claims.from_str_dict(claim[f.SIG.nm], pk.N) await self.prover.processClaim(schemaId, claim_attributes, claim_signature) else: self.notifyMsgListener("No matching connection found")
async def initAvailableClaimList(self): claimDef = await self.issuer.wallet.getClaimDef(ID(self._claimDefKey)) self.availableClaims.append({ NAME: claimDef.name, VERSION: claimDef.version, "claimDefSeqNo": claimDef.seqId })
async def _initEqProof(self, schemaId, c1: PrimaryClaim, revealedAttrs: Sequence[str], m1Tilde, m2Tilde, claimAttributes: Dict[str, ClaimAttributeValues]) \ -> PrimaryEqualInitProof: m2Tilde = m2Tilde if m2Tilde else cmod.integer( cmod.randomBits(LARGE_MVECT)) revealedAttrs, unrevealedAttrs = splitRevealedAttrs( claimAttributes, [a.name for a in revealedAttrs]) mtilde = self._getMTilde(unrevealedAttrs) Ra = cmod.integer(cmod.randomBits(LARGE_VPRIME)) pk = await self._wallet.getPublicKey(ID(schemaId=schemaId)) A, e, v = c1.A, c1.e, c1.v Aprime = A * (pk.S**Ra) % pk.N vprime = (v - e * Ra) eprime = e - (2**LARGE_E_START) etilde = cmod.integer(cmod.randomBits(LARGE_ETILDE)) vtilde = cmod.integer(cmod.randomBits(LARGE_VTILDE)) Rur = 1 % pk.N for k, value in unrevealedAttrs.items(): if k in claimAttributes: Rur = Rur * (pk.R[k]**mtilde[k]) Rur *= pk.Rms**m1Tilde Rur *= pk.Rctxt**m2Tilde # T = ((Aprime ** etilde) * Rur * (pk.S ** vtilde)) % pk.N T = calcTeq(pk, Aprime, etilde, vtilde, mtilde, m1Tilde, m2Tilde, unrevealedAttrs.keys()) return PrimaryEqualInitProof(c1, Aprime, T, etilde, eprime, vtilde, vprime, mtilde, m1Tilde, m2Tilde, unrevealedAttrs.keys(), revealedAttrs)
async def initAvailableClaimList(self): schema = await self.issuer.wallet.getSchema(ID(self._schema)) self.availableClaims.append({ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId })
async def testUpdateRevocedWitness(claimsProver1Gvt, issuerGvt, schemaGvt, prover1): nonRevocClaimGvtProver1 = claimsProver1Gvt.nonRevocClaim await issuerGvt.revoke(ID(schemaId=schemaGvt.seqId), 1) with pytest.raises(ValueError): await prover1._nonRevocProofBuilder.updateNonRevocationClaim( schemaGvt.seqId, nonRevocClaimGvtProver1)
async def addSchemasToWallet(self): for schemaKey in self.getSchemaKeysToBeGenerated(): matchedAttrDefs = list( filter(lambda ad: ad.name == schemaKey.name, self.getAttrDefs())) assert len(matchedAttrDefs) == 1, \ "check if agent has attrib def and it's name is equivalent " \ "to it's corresponding schema key name" attrDef = matchedAttrDefs[0] if not self.issuer.isSchemaExists(schemaKey): self.logger.info("schema not found in wallet, will go and " "get id from repo: {}".format(str(schemaKey))) schema = await self.issuer.genSchema(schemaKey.name, schemaKey.version, attrDef.attribNames()) if schema: schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId, seqId=schema.seqId) p_prime, q_prime = primes["prime2"] await self.issuer.genKeys(schemaId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) else: self.logger.info( "schema is already loaded in wallet: {}".format( str(schemaKey))) await self.initAvailableClaimList()
async def getJobCertAvailableClaimList(self): claimDef = await self.issuer.wallet.getClaimDef( ID(self._claimDefJobCertKey)) return [{ NAME: claimDef.name, VERSION: claimDef.version, "claimDefSeqNo": claimDef.seqId }]
async def testProof(self, schemaId, c2: NonRevocationClaim): pkR = await self._wallet.getPublicKeyRevocation(ID(schemaId=schemaId)) accum = await self._wallet.getAccumulator(ID(schemaId=schemaId)) accumPk = await self._wallet.getPublicKeyAccumulator( ID(schemaId=schemaId)) cListParams = self._genCListParams(schemaId, c2) proofCList = self._createCListValues(schemaId, c2, cListParams, pkR) proofTauList = createTauListValues(pkR, accum, cListParams, proofCList) proofTauListCalc = createTauListExpectedValues(pkR, accum, accumPk, proofCList) if proofTauListCalc.asList() != proofTauList.asList(): raise ValueError("revocation proof is incorrect") return True
async def create_claim_and_send_to_prover(): claimReq = await aliceAgent.prover.createClaimRequest( schemaId=ID(schemaKey), proverId='b1134a647eb818069c089e7694f63e6d', reqNonRevoc=False) assert claimReq attr = faberAgent.issuer_backend.get_record_by_internal_id(1) faberAgent.issuer._attrRepo.addAttributes(schemaKey=schemaKey, userId=claimReq.userId, attributes=attr) claim_signature, claim_attributes = await faberAgent.issuer.issueClaim(ID(schemaKey=schemaKey), claimReq) msg = get_claim_libsovrin_msg(claim_signature, schema.seqId) await aliceAgent.handleReqClaimResponse(msg)
async def checkTranscriptWritten(): faberId = faberAgent.wallet.defaultId claimDefId = ID(ClaimDefinitionKey("Transcript", "1.2", faberId)) claimDef = await faberAgent.issuer.wallet.getClaimDef(claimDefId) assert claimDef assert claimDef.seqId issuerKey = faberAgent.issuer.wallet.getPublicKey(claimDefId) assert issuerKey
async def addProof(): revealedAttrsForClaim = [a for a in revealedAttrs.values() if a.name in claim.keys()] revealedPredicatesForClaim = [p for p in predicates.values() if p.attrName in claim.keys()] claims = await self.wallet.getClaimSignature(ID(schemaId=schemaId)) proofClaim = ProofClaims(claims=claims, revealedAttrs=revealedAttrsForClaim, predicates=revealedPredicatesForClaim) proofClaims[schemaId] = proofClaim
async def checkTranscriptWritten(): faberId = faberAgent.wallet.defaultId schemaId = ID(SchemaKey("Transcript", "1.2", faberId)) schema = await faberAgent.issuer.wallet.getSchema(schemaId) assert schema assert schema.seqId issuerPublicKey = await faberAgent.issuer.wallet.getPublicKey(schemaId) assert issuerPublicKey # TODO isinstance(issuerPublicKey, PublicKey)
async def addSchemasToWallet(self): schema = await self.issuer.genSchema(self._schema.name, self._schema.version, self._attrDef.attribNames(), 'CL') schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId) p_prime, q_prime = primes["prime2"] await self.issuer.genKeys(schemaId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) await self.initAvailableClaimList()
async def checkJobCertWritten(): acmeId = acmeAgent.wallet.defaultId schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId)) schema = await acmeAgent.issuer.wallet.getSchema(schemaId) assert schema assert schema.seqId issuerPublicKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId) assert issuerPublicKey assert issuerPublicKey.seqId
async def addClaimDefsToWallet(self): claimDef = await self.issuer.genClaimDef(self._claimDefKey.name, self._claimDefKey.version, self._attrDef.attribNames(), 'CL') claimDefId = ID(claimDefKey=claimDef.getKey(), claimDefId=claimDef.seqId) p_prime, q_prime = primes["prime2"] await self.issuer.genKeys(claimDefId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(claimDefId=claimDefId, iA='110', L=5) await self.initAvailableClaimList()
async def checkJobCertWritten(): acmeId = acmeAgent.wallet.defaultId claimDefId = ID(ClaimDefinitionKey("Job-Certificate", "0.2", acmeId)) claimDef = await acmeAgent.issuer.wallet.getClaimDef(claimDefId) assert claimDef assert claimDef.seqId issuerKey = await acmeAgent.issuer.wallet.getPublicKey(claimDefId) assert issuerKey assert issuerKey.seqId
async def _verifyEquality(self, schemaKey, cH, proof: PrimaryEqualProof, allRevealedAttrs): THat = [] pk = await self._wallet.getPublicKey(ID(schemaKey)) attrNames = (await self._wallet.getSchema(ID(schemaKey))).attrNames unrevealedAttrNames = set(attrNames) - set(proof.revealedAttrNames) T1 = calcTeq(pk, proof.Aprime, proof.e, proof.v, proof.m, proof.m1, proof.m2, unrevealedAttrNames) Rar = 1 % pk.N for attrName in proof.revealedAttrNames: Rar *= pk.R[str(attrName)]**allRevealedAttrs[attrName] Rar *= proof.Aprime**(2**LARGE_E_START) T2 = (pk.Z / Rar)**(-1 * cH) % pk.N T = T1 * T2 % pk.N THat.append(T) return THat
async def _findClaims(self, proofRequest: ProofRequest) -> ( Dict[SchemaKey, ProofClaims], Dict[str, Any]): revealedAttrs, predicates = proofRequest.verifiableAttributes, proofRequest.predicates foundRevealedAttrs = {} foundPredicates = {} proofClaims = {} schemas = {} allClaimsAttributes = await self.wallet.getAllClaimsAttributes() async def addProof(): revealedAttrsForClaim = [a for a in revealedAttrs.values() if a.name in claim.keys()] revealedPredicatesForClaim = [p for p in predicates.values() if p.attrName in claim.keys()] claims = await self.wallet.getClaimSignature(ID(schemaId=schemaId)) proofClaim = ProofClaims(claims=claims, revealedAttrs=revealedAttrsForClaim, predicates=revealedPredicatesForClaim) proofClaims[schemaId] = proofClaim for schemaKey, c in allClaimsAttributes.items(): schemas[schemaKey] = (await self.wallet.getSchema(ID(schemaKey))) for uuid, revealedAttr in revealedAttrs.items(): matches = [(schemas[key].seqId, c) for key, c in allClaimsAttributes.items() if revealedAttr.name in c and (schemas[key].seqId == revealedAttr.schema_seq_no if revealedAttr.schema_seq_no else True) and (schemas[key].issuerId == revealedAttr.issuer_did if revealedAttr.issuer_did else True)] if len(matches) == 0: raise ValueError("A claim isn't found for the following attributes: {}", revealedAttr.name) schemaId, claim = matches[0] foundRevealedAttrs[uuid] = [str(schemaId), str(claim[revealedAttr.name].raw), str(claim[revealedAttr.name].encoded)] if schemaId not in proofClaims: await addProof() for uuid, predicate in predicates.items(): matches = [(schemas[key].seqId, c) for key, c in allClaimsAttributes.items() if predicate.attrName in c and (schemas[key].seqId == predicate.schema_seq_no if predicate.schema_seq_no else True) and (schemas[key].issuerId == predicate.issuer_did if predicate.issuer_did else True)] if len(matches) == 0: raise ValueError("A claim isn't found for the following predicate: {}", predicate) schemaId, claim = matches[0] foundPredicates[uuid] = str(schemaId) if schemaId not in proofClaims: await addProof() requestedProof = RequestedProof(revealed_attrs=foundRevealedAttrs, predicates=foundPredicates) return proofClaims, requestedProof