def handleProofRequest(self, msg): body, _ = msg link = self._getLinkByTarget(getCryptonym(body.get(IDENTIFIER))) proofRequest = body.get(PROOF_REQUEST_FIELD) proofRequest = ProofRequest.from_str_dict(proofRequest) proofReqExist = False for request in link.proofRequests: if request.name == proofRequest.name: proofReqExist = True break self.notifyMsgListener( ' Proof request {} received from {}.\n'.format( proofRequest.name, link.name)) if not proofReqExist: link.proofRequests.append(proofRequest) else: self.notifyMsgListener( ' Proof request {} already exist.\n'.format( proofRequest.name))
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'])) proofInput = ProofInput( nonce=int(proofRequest.nonce), revealedAttrs=proofRequest.verifiableAttributes, predicates=proofRequest.predicates) result = await self.verifier.verify(proofInput, 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 proofInput.revealedAttrs.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))