async def test_requested_proof_from_to_dict(prover1, nonce, claimsProver1Gvt): proofRequest = ProofRequest( "proof1", "1.0", 1, verifiableAttributes={'attr_uuid': AttributeInfo(name='name')}, predicates={'predicate_uuid': PredicateGE('age', 18)}) proof = await prover1.presentProof(proofRequest) requested_proof_serialized = { 'revealed_attrs': { 'attr_uuid': ['1', 'Alex', '1139481716457488690172217916278103335'] }, 'predicates': { 'predicate_uuid': '1' }, 'self_attested_attrs': {}, 'unrevealed_attrs': {} } assert proof.requestedProof.to_str_dict() == requested_proof_serialized assert proof.requestedProof == RequestedProof.from_str_dict( requested_proof_serialized) assert proof.requestedProof == RequestedProof.from_str_dict( proof.requestedProof.to_str_dict())
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 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))