def test_proof_request_from_to_dict(): proofRequest = ProofRequest( "proof1", "1.0", 1, verifiableAttributes={'attr_uuid': AttributeInfo(name='name')}, predicates={'predicate_uuid': PredicateGE('age', 18)}) proof_input_serialized = { 'name': 'proof1', 'version': '1.0', 'nonce': '1', 'requested_attrs': { 'attr_uuid': { 'name': 'name', 'schema_seq_no': None, 'issuer_did': None } }, 'requested_predicates': { 'predicate_uuid': { 'p_type': 'GE', 'value': 18, 'attr_name': 'age', 'schema_seq_no': None, 'issuer_did': None } } } assert proofRequest.to_str_dict() == proof_input_serialized assert proofRequest == ProofRequest.from_str_dict(proof_input_serialized) assert proofRequest == ProofRequest.from_str_dict( proofRequest.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))
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))
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 create_proof(conn, proof_request): proof_request = ProofRequest.from_str_dict(proof_request) proof = await global_dict['prover'].presentProof(proof_request) conn.send(json.dumps(proof.to_str_dict()).encode())