async def verifyClaimProof(self, msg: Any): body, (frm, ha) = msg link = self.verifyAndGetLink(msg) if not link: raise NotImplementedError claimName = body[NAME] nonce = getNonceForProof(body[NONCE]) proof = FullProof.fromStrDict(body[PROOF_FIELD]) proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD]) revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD]) result = await self.verifier.verify(proofInput, proof, revealedAttrs, nonce) status = 'verified' if result else 'failed verification' resp = { TYPE: CLAIM_PROOF_STATUS, DATA: ' Your claim {} {} was received and {}\n'.format( body[NAME], body[VERSION], status), } self.signAndSend(resp, link.localIdentifier, frm, origReqId=body.get(f.REQ_ID.nm)) if result: await self._postClaimVerif(claimName, link, frm)
def testToFromDictWithStrValuesDictInList(): dictionary = OrderedDict((('2', [ OrderedDict((('33', OrderedDict((('45', 45), ('11', 11)))), ('23', OrderedDict((('47', 47), ('34', 34)))))), OrderedDict((('63', OrderedDict((('65', 45), ('61', 11)))), ('63', OrderedDict((('67', 47), ('64', 34)))))) ]), ('3', 3))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
def testToFromDictWithStrValuesSets(): dictionary = OrderedDict(( ('44', {'aaa', 'bbb'}), ('4', {111, 2222}), ('1', {}), ('3', 3), )) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
def fromStrDict(cls, d): d = fromDictWithStrValues(d) aggregatedProof = AggregatedProof.fromStrDict(d['aggregatedProof']) requestedProof = RequestedProof.fromStrDict(d['requestedProof']) proofs = {k: ProofInfo.fromStrDict(v) for k, v in d['proofs'].items()} return FullProof(aggregatedProof=aggregatedProof, proofs=proofs, requestedProof=requestedProof)
def testToFromDictWithStrValuesSubDicts(): cmod.PairingGroup(PAIRING_GROUP) dictionary = OrderedDict( (('4', {'aaa', 'bbb'}), ('2', OrderedDict( (('33', OrderedDict((('45', 45), ('11', 11)))), ('23', OrderedDict( (('47', 47), ('34', 34))))))), ('3', 3))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
def testToFromDictWithStrValuesLists(): group = cmod.PairingGroup(PAIRING_GROUP) dictionary = OrderedDict( (('47', []), ('7', [cmod.integer(111) % 11, cmod.integer(222), cmod.integer(333) % 45]), ('6', [ group.init(cmod.ZR, 555), group.random(cmod.G1), group.random(cmod.G1) ]))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
async def verifyProof(self, msg: Any): body, (frm, _) = msg link = self.verifyAndGetLink(msg) if not link: raise NotImplementedError proofName = body[NAME] nonce = getNonceForProof(body[NONCE]) proof = FullProof.fromStrDict(body[PROOF_FIELD]) proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD]) revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD]) result = await self.verifier.verify(proofInput, proof, revealedAttrs, nonce) 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( body[NAME], body[VERSION], status), } self.signAndSend(resp, link.localIdentifier, frm, origReqId=body.get(f.REQ_ID.nm)) if result: for attribute in proofInput.revealedAttrs: # Log attributes that were verified self.logger.info('verified {}: {}'.format( attribute, revealedAttrs[attribute])) self.logger.info( 'Verified that proof "{}" contains attributes ' 'from claim(s) issued by: {}'.format( proofName, ", ".join(sorted([sk.issuerId for sk in proof.schemaKeys])))) await self._postProofVerif(proofName, link, frm) else: self.logger.info( 'Verification failed for proof {} from {} '.format( proofName, link.name))
def testToFromDictWithStrValuesMixed(): group = cmod.PairingGroup(PAIRING_GROUP) dictionary = OrderedDict( (('4', {'aaa', 'bbb'}), ('2', OrderedDict( (('33', OrderedDict((('45', 45), ('11', 11)))), ('23', OrderedDict( (('47', 47), ('34', 34))))))), ('1', {}), ('3', 3), ('5', cmod.integer(111) % 11), ('7', [cmod.integer(111) % 11, cmod.integer(222), cmod.integer(333) % 45]), ('6', [ group.init(cmod.ZR, 555), group.random(cmod.G1), group.random(cmod.G1) ]), ('10', group.random(cmod.G1)))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
async def verifyProof(self, msg: Any): body, (frm, _) = msg link = self.verifyAndGetLink(msg) if not link: raise NotImplementedError proofName = body[NAME] nonce = getNonceForProof(body[NONCE]) proof = FullProof.fromStrDict(body[PROOF_FIELD]) proofInput = ProofInput.fromStrDict(body[PROOF_INPUT_FIELD]) revealedAttrs = fromDictWithStrValues(body[REVEALED_ATTRS_FIELD]) result = await self.verifier.verify(proofInput, proof, revealedAttrs, nonce) 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(body[NAME], body[VERSION], status), } self.signAndSend(resp, link.localIdentifier, frm, origReqId=body.get(f.REQ_ID.nm)) if result: for attribute in proofInput.revealedAttrs: # Log attributes that were verified self.logger.info('verified {}: {}'. format(attribute, revealedAttrs[attribute])) self.logger.info('Verified that proof "{}" contains attributes ' 'from claim(s) issued by: {}'.format( proofName, ", ".join( sorted([sk.issuerId for sk in proof.schemaKeys])))) await self._postProofVerif(proofName, link, frm) else: self.logger.info('Verification failed for proof {} from {} ' .format(proofName, link.name))
def testToFromDictWithStrValues(): group = cmod.PairingGroup(PAIRING_GROUP) dictionary = OrderedDict( (('43', '43'), ('3', 3), ('5', cmod.integer(111) % 11), ('10', group.random(cmod.G1)))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))
def fromStrDict(cls, d): d = fromDictWithStrValues(d) proof = Proof.fromStrDict(d['proof']) result = cls(**d) return result._replace(proof=proof)
def fromStrDict(cls, d): d = fromDictWithStrValues(d) predicate = PredicateGE(**d['predicate']) result = cls(**d) return result._replace(predicate=predicate)
def fromStrDict(cls, d): d = fromDictWithStrValues(d) witness = Witness(**d['witness']) result = cls(**d) return result._replace(witness=witness)
def fromStrDict(cls, d): d = fromDictWithStrValues(d) return cls(**d)
def fromStrDict(cls, d): d = fromDictWithStrValues(d) predicates = [Predicate.fromStrDict(v) for v in d['predicates']] result = cls(**d) return result._replace(predicates=predicates)
async def testRevealedAttrsFromToDict(prover1, nonce, claimsProver1Gvt): proofInput = ProofInput(['name'], [PredicateGE('age', 18)]) _, revealedAttrs = await prover1.presentProof(proofInput, nonce) assert revealedAttrs == fromDictWithStrValues( toDictWithStrValues(revealedAttrs))
def testToFromDictWithStrValuesInteKeys(): dictionary = OrderedDict(((11, '43'), (12, 3))) assert dictionary == fromDictWithStrValues(toDictWithStrValues(dictionary))