def verifyPredicateProof(credDefs, credDefPks, issuerSecretKeys, proofBuilderWithAttribs, revealedAttrs, predicate, verifier: Verifier): proofBuilder, attrs = proofBuilderWithAttribs presentationToken = getPresentationToken(credDefs, credDefPks, issuerSecretKeys, proofBuilder, attrs.encoded()) nonce = verifier.generateNonce(interactionId=1) proof = proofBuilder.preparePredicateProof(creds=presentationToken, attrs=attrs.encoded(), revealedAttrs=revealedAttrs, nonce=nonce, predicate=predicate) return verifier.verifyPredicateProof(proof=proof, credDefPks=credDefPks, nonce=nonce, attrs=attrs.encoded(), revealedAttrs=revealedAttrs, predicate=predicate)
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 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)
def testInteraction(gvtSecretKey): mcds = MemoryCredDefStore() miks = MemoryIssuerKeyStore() attrRepo = InMemoryAttrRepo() attrs = GVT.attribs(name='John Anthony White', age=41, sex='male') attrNames = tuple(attrs.keys()) revealedAttrs = ["age", ] encodedAttrs = attrs.encoded() credName = "Profile" credVersion = "1.0" attrRepo.addAttributes(proverId, attrs) misks = MemoryIssuerSecretKeyStore() issuer = Issuer(issuerId, attrRepo, credDefStore=mcds, issuerSecretKeyStore=misks) credDefId = 1 cd = CredentialDefinition(credDefId, attrNames, credName, credVersion) mcds.publish(cd) # Issuer Key set up issuerKeyId = 1 issuerSecretKey = IssuerSecretKey(cd, sk=gvtSecretKey, uid=issuerKeyId) misks.put(issuerSecretKey) issuerKey = issuerSecretKey.PK miks.publish(issuerKey) # issuer.addNewCredDef(cd) prover = Prover(proverId, mcds, miks) verifier = Verifier(verifierId, mcds, miks) proofBuilder = prover.createProofBuilder(cduid=credDefId, ikuid=issuerKeyId, issuer=issuer, attrNames=attrNames, interactionId=interactionId, verifier=verifier, revealedAttrs=revealedAttrs) proof = proofBuilder.prepareProof(proofBuilder.credDefPks, proofBuilder.masterSecret, proofBuilder.credential, encodedAttrs, proofBuilder.revealedAttrs, proofBuilder.nonce) assert verifier.verify(issuer=issuer, name=credName, version=credVersion, proof=proof, nonce=proofBuilder.nonce, attrs=encodedAttrs, revealedAttrs=proofBuilder.revealedAttrs, credDefId=credDefId, issuerKeyId=issuerKeyId)
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)
def prepareProofAndVerify(credDefs, credDefPks, issuerSecretKeys, proofBuilder, attrs, revealedAttrs, proofNonce=None, verifyNonce=None): encodedAttrs = attrs.encoded() presentationToken = getPresentationToken( credDefs, credDefPks, issuerSecretKeys, proofBuilder, encodedAttrs) proof = ProofBuilder.prepareProof(issuerPks=proofBuilder.issuerPks, masterSecret=proofBuilder.masterSecret, creds=presentationToken, encodedAttrs=encodedAttrs, revealedAttrs=revealedAttrs, nonce=proofNonce) vNonce = proofNonce if not verifyNonce else verifyNonce return Verifier.verifyProof(proof=proof, nonce=vNonce, credDefPks=credDefPks, encodedAttrs=encodedAttrs, revealedAttrs=revealedAttrs)
async def testSingleIssuerSingleProverPrimaryOnly(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, None, False) (claim_signature, claim_attributes) = await issuer.issueClaim(schemaId, claimsReq) await prover.processClaim(schemaId, claim_attributes, claim_signature) # 6. proof Claims verifier = Verifier(WalletInMemory('verifier1', publicRepo)) proofRequest = ProofRequest( "proof1", "1.0", verifier.generateNonce(), verifiableAttributes={ 'attr_uuid1': AttributeInfo('name', schema.seqId) }, predicates={'predicate_uuid1': PredicateGE('age', 18)}) proof = await prover.presentProof(proofRequest) assert proof.requestedProof.revealed_attrs['attr_uuid1'][1] == 'Alex' assert await verifier.verify(proofRequest, proof)
async def presentProofAndVerify(verifier: Verifier, proofInput: ProofInput, prover): nonce = verifier.generateNonce() proof, revealedAttrs = await prover.presentProof(proofInput, nonce) return await verifier.verify(proofInput, proof, revealedAttrs, nonce)
def verifier(publicRepo): return Verifier(WalletInMemory('verifier1', publicRepo))
def fetchNonce(self, interactionId, verifier: Verifier): return verifier.generateNonce(interactionId)
def verifierMulti2(credDefStore, issuerKeyStore): return Verifier('verifierMulti2', credDefStore=credDefStore, issuerKeyStore=issuerKeyStore)
def verifier1(credDefStore, issuerKeyStore): return Verifier('verifier1', credDefStore=credDefStore, issuerKeyStore=issuerKeyStore)