Esempio n. 1
0
async def testMultipledRevealed(prover1, allClaims, schemaGvtId, schemaXyzId,
                                attrRepo, schemaGvt):
    proofRequest = ProofRequest("proof1",
                                "1.0",
                                1,
                                verifiableAttributes={
                                    'attr_uuid1': AttributeInfo(name='status'),
                                    'attr_uuid2': AttributeInfo(name='name')
                                })

    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaimSignature(schemaXyzId)
    proofClaims = {
        schemaGvt.seqId: ProofClaims(claimsGvt, ['name'], []),
        schemaGvt.seqId: ProofClaims(claimsXyz, ['status'], [])
    }

    attr1 = attrRepo.getAttributes(schemaXyzId.schemaKey,
                                   prover1.proverId)['status']
    attr2 = attrRepo.getAttributes(schemaGvtId.schemaKey,
                                   prover1.proverId)['name']
    requestedProof = RequestedProof(
        revealed_attrs={
            'attr_uuid1': [schemaGvt.seqId, attr1,
                           str(encodeAttr(attr1))],
            'attr_uuid2': [schemaGvt.seqId, attr2,
                           str(encodeAttr(attr2))]
        })

    assert proofClaims, requestedProof == await prover1._findClaims(
        proofRequest)
Esempio n. 2
0
async def testRevealedAndPredicateDifferentIssuers(prover1, allClaims,
                                                   schemaGvtId, schemaXyzId,
                                                   attrRepo, schemaGvt):
    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        1,
        verifiableAttributes={'attr_uuid': AttributeInfo(name='status')},
        predicates={'predicate_uuid': PredicateGE('age', 18)})

    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaimSignature(schemaXyzId)
    proofClaims = {
        schemaGvt.seqId: ProofClaims(claimsGvt, [], [PredicateGE('age', 18)]),
        schemaGvt.seqId: ProofClaims(claimsXyz, ['status'], [])
    }

    attr = attrRepo.getAttributes(schemaXyzId.schemaKey,
                                  prover1.proverId)['status']
    requestedProof = RequestedProof(
        revealed_attrs={
            'attr_uuid': [schemaGvt.seqId, attr,
                          str(encodeAttr(attr))]
        },
        predicates={'predicate_uuid': schemaGvt.seqId})

    assert proofClaims, requestedProof == await prover1._findClaims(
        proofRequest)
Esempio n. 3
0
async def testMultipledPredicates(prover1, allClaims, schemaGvtId, schemaXyzId,
                                  schemaGvt):
    proofRequest = ProofRequest("proof1",
                                "1.0",
                                1,
                                predicates={
                                    'predicate_uuid1': PredicateGE('age', 18),
                                    'predicate_uuid2':
                                    PredicateGE('period', 8)
                                })

    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaimSignature(schemaXyzId)
    proofClaims = {
        schemaGvt.seqId: ProofClaims(claimsGvt, [], [PredicateGE('age', 18)]),
        schemaGvt.seqId: ProofClaims(claimsXyz, [], [PredicateGE('period', 8)])
    }

    requestedProof = RequestedProof(predicates={
        'predicate_uuid1': schemaGvt.seqId,
        'predicate_uuid2': schemaGvt.seqId
    })

    assert proofClaims, requestedProof == await prover1._findClaims(
        proofRequest)
Esempio n. 4
0
async def testOneRevealedFromSpecificSchemaAndIssuer(prover1, allClaims,
                                                     schemaGvt, schemaGvtId,
                                                     attrRepo, keysGvt):
    proofRequest = ProofRequest("proof1",
                                "1.0",
                                1,
                                verifiableAttributes={
                                    'uuid':
                                    AttributeInfo(
                                        name='name',
                                        schema_seq_no=schemaGvt.seqId,
                                        issuer_did=schemaGvt.issuerId)
                                })
    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)

    proofClaims = {schemaGvt.seqId: ProofClaims(claimsGvt, ['name'], [])}
    attr = attrRepo.getAttributes(schemaGvtId.schemaKey,
                                  prover1.proverId)['name']
    requestedProof = RequestedProof(revealed_attrs={
        'uuid': [str(schemaGvt.seqId), attr,
                 str(encodeAttr(attr))]
    })

    assert proofClaims, requestedProof == await prover1._findClaims(
        proofRequest)

    assert proofClaims, requestedProof == await prover1._findClaims(
        proofRequest)
Esempio n. 5
0
async def testMultipledPredicates(prover1, allClaims, schemaGvtId,
                                  schemaXyzId):
    proofInput = ProofInput([],
                            [PredicateGE('age', 18),
                             PredicateGE('period', 8)])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaims(schemaXyzId)
    proofClaims = {
        schemaGvtId.schemaKey:
        ProofClaims(claimsGvt, [], [PredicateGE('age', 18)]),
        schemaXyzId.schemaKey:
        ProofClaims(claimsXyz, [], [PredicateGE('period', 8)])
    }
    revealedAttrs = {}
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
async def testPrimaryClaimOnlyEmpty(prover1, verifier, claimsProver1Gvt, nonce):
    proofInput = ProofInput([])
    claims, revealedAttrs = await prover1._findClaims(proofInput)
    claims = {schemaKey: ProofClaims(
        Claims(primaryClaim=proofClaim.claims.primaryClaim))
              for schemaKey, proofClaim in claims.items()}
    proof = await prover1._prepareProof(claims, nonce)
    assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
Esempio n. 7
0
        async def addProof():
            revealedAttrsForClaim = [a for a in revealedAttrs.values() if a.name in claim.keys()]
            revealedPredicatesForClaim = [p for p in predicates.values() if p.attrName in claim.keys()]

            claims = await self.wallet.getClaimSignature(ID(schemaId=schemaId))
            proofClaim = ProofClaims(claims=claims, revealedAttrs=revealedAttrsForClaim,
                                     predicates=revealedPredicatesForClaim)

            proofClaims[schemaId] = proofClaim
Esempio n. 8
0
async def testRevealedAndPredicateDifferentIssuers(prover1, allClaims,
                                                   schemaGvtId, schemaXyzId,
                                                   attrRepo):
    proofInput = ProofInput(['status'], [PredicateGE('age', 18)])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaims(schemaXyzId)
    proofClaims = {
        schemaGvtId.schemaKey: ProofClaims(claimsGvt, [],
                                           [PredicateGE('age', 18)]),
        schemaXyzId.schemaKey: ProofClaims(claimsXyz, ['status'], [])
    }
    revealedAttrs = {
        'status':
        attrRepo.getAttributes(schemaXyzId.schemaKey,
                               prover1.proverId)['status']
    }
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
async def testOnePredicateOnly(prover1, allClaims, schemaGvtId, schemaGvt):
    proofRequest = ProofRequest("proof1", "1.0", 1, predicates={'uuid': PredicateGE('age', 18)})

    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)
    proofClaims = {schemaGvt.seqId:
                       ProofClaims(claimsGvt, [], [PredicateGE('age', 18)])}

    requestedProof = RequestedProof(predicates={'uuid': schemaGvt.seqId})

    assert proofClaims, requestedProof == await prover1._findClaims(proofRequest)
Esempio n. 10
0
async def testPredicatesEmpty(prover1, allClaims, schemaGvtId, attrRepo):
    proofInput = ProofInput(['name'], [])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    proofClaims = {schemaGvtId.schemaKey: ProofClaims(claimsGvt, ['name'], [])}
    revealedAttrs = {
        'name':
        attrRepo.getAttributes(schemaGvtId.schemaKey, prover1.proverId)['name']
    }
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
Esempio n. 11
0
async def testRevealedEmpty(prover1, allClaims, schemaGvtId):
    proofInput = ProofInput([], [PredicateGE('age', 18)])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    proofClaims = {
        schemaGvtId.schemaKey: ProofClaims(claimsGvt, [],
                                           [PredicateGE('age', 18)])
    }
    revealedAttrs = {}
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
Esempio n. 12
0
async def testMultipledRevealed(prover1, allClaims, schemaGvtId, schemaXyzId,
                                attrRepo):
    proofInput = ProofInput(['status', 'name'], [])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaims(schemaXyzId)
    proofClaims = {
        schemaGvtId.schemaKey: ProofClaims(claimsGvt, ['name'], []),
        schemaXyzId.schemaKey: ProofClaims(claimsXyz, ['status'], [])
    }
    revealedAttrs = {
        'name':
        attrRepo.getAttributes(schemaGvtId.schemaKey,
                               prover1.proverId)['name'],
        'status':
        attrRepo.getAttributes(schemaXyzId.schemaKey,
                               prover1.proverId)['status'],
    }
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
Esempio n. 13
0
async def testPrimaryClaimPredicatesOnly(prover1, verifier, claimsProver1Gvt,
                                         nonce, schemaGvtId):
    predicates = [PredicateGE('age', 18)]
    proofInput = ProofInput(predicates=predicates)
    claims, revealedAttrs = await prover1._findClaims(proofInput)
    claims = {schemaKey: ProofClaims(
        Claims(primaryClaim=proofClaim.claims.primaryClaim),
        predicates=predicates)
              for schemaKey, proofClaim in claims.items()}
    proof = await prover1._prepareProof(claims, nonce)
    assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
async def testPredicatesEmpty(prover1, allClaims, schemaGvtId, attrRepo, schemaGvt):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                verifiableAttributes={'uuid': AttributeInfo(name='name')}, predicates={})

    claimsGvt = await prover1.wallet.getClaimSignature(schemaGvtId)

    proofClaims = {schemaGvt.seqId: ProofClaims(claimsGvt, ['name'], [])}

    attr = attrRepo.getAttributes(schemaGvtId.schemaKey, prover1.proverId)['name']
    requestedProof = RequestedProof(revealed_attrs={'uuid': [schemaGvt.seqId, attr, str(encodeAttr(attr))]})

    assert proofClaims, requestedProof == await prover1._findClaims(proofRequest)
async def testPrimaryClaimNoPredicates(prover1, verifier, claimsProver1Gvt,
                                       nonce, schemaGvtId,
                                       attrRepo):
    revealledAttrs = ['name']
    proofInput = ProofInput(revealledAttrs)
    claims, revealedAttrs = await prover1._findClaims(proofInput)
    claims = {
        schemaKey: ProofClaims(
            Claims(primaryClaim=proofClaim.claims.primaryClaim),
            revealedAttrs=revealledAttrs)
        for schemaKey, proofClaim in claims.items()}
    proof = await prover1._prepareProof(claims, nonce)
    assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)
async def testPrimaryClaimOnlyEmpty(prover1, verifier, claimsProver1Gvt,
                                    nonce):
    proofRequest = ProofRequest("proof1", "1.0", nonce)
    claims, requestedProof = await prover1._findClaims(proofRequest)
    claims = {
        schemaId:
        ProofClaims(Claims(primaryClaim=proofClaim.claims.primaryClaim))
        for schemaId, proofClaim in claims.items()
    }

    proof = await prover1._prepareProof(claims, proofRequest.nonce,
                                        requestedProof)

    assert await verifier.verify(proofRequest, proof)
async def testMultipleAll(prover1, allClaims, schemaGvtId, schemaXyzId,
                          attrRepo):
    proofInput = ProofInput(['status', 'name'],
                            [PredicateGE('age', 18),
                             PredicateGE('period', 8)])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    claimsXyz = await prover1.wallet.getClaims(schemaXyzId)
    proofClaims = {
        schemaGvtId.schemaKey:
        ProofClaims(claimsGvt, ['name'], [PredicateGE('age', 18)]),
        schemaXyzId.schemaKey:
        ProofClaims(claimsXyz, ['status'], [PredicateGE('period', 8)])
    }
    revealedAttrs = {
        'name':
        attrRepo.getAttributes(schemaGvtId.schemaKey,
                               prover1.proverId).encoded()['name'],
        'status':
        attrRepo.getAttributes(schemaXyzId.schemaKey,
                               prover1.proverId).encoded()['status'],
    }
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
async def testRevealedAndPredicateSameIssuer(prover1, allClaims, schemaGvtId,
                                             attrRepo):
    proofInput = ProofInput(['name'], [PredicateGE('age', 18)])
    claimsGvt = await prover1.wallet.getClaims(schemaGvtId)
    proofClaims = {
        schemaGvtId.schemaKey:
        ProofClaims(claimsGvt, ['name'], [PredicateGE('age', 18)])
    }
    revealedAttrs = {
        'name':
        attrRepo.getAttributes(schemaGvtId.schemaKey,
                               prover1.proverId).encoded()['name']
    }
    assert (proofClaims,
            revealedAttrs) == await prover1._findClaims(proofInput)
Esempio n. 19
0
    async def _findClaims(
        self, proofInput: ProofInput
    ) -> (Dict[SchemaKey, ProofClaims], Dict[str, Any]):
        revealedAttrs, predicates = set(proofInput.revealedAttrs), set(
            proofInput.predicates)

        proofClaims = {}
        foundRevealedAttrs = set()
        foundPredicates = set()
        revealedAttrsWithValues = {}

        allClaims = await self.wallet.getAllClaims()
        for schemaKey, claim in allClaims.items():
            revealedAttrsForClaim = []
            predicatesForClaim = []

            for revealedAttr in revealedAttrs:
                if revealedAttr in claim.primaryClaim.encodedAttrs:
                    revealedAttrsForClaim.append(revealedAttr)
                    foundRevealedAttrs.add(revealedAttr)
                    revealedAttrsWithValues[revealedAttr] = \
                        claim.primaryClaim.attrs[revealedAttr]

            for predicate in predicates:
                if predicate.attrName in claim.primaryClaim.encodedAttrs:
                    predicatesForClaim.append(predicate)
                    foundPredicates.add(predicate)

            if revealedAttrsForClaim or predicatesForClaim:
                proofClaims[schemaKey] = ProofClaims(claim,
                                                     revealedAttrsForClaim,
                                                     predicatesForClaim)

        if foundRevealedAttrs != revealedAttrs:
            raise ValueError(
                "A claim isn't found for the following attributes: {}",
                revealedAttrs - foundRevealedAttrs)
        if foundPredicates != predicates:
            raise ValueError(
                "A claim isn't found for the following predicates: {}",
                predicates - foundPredicates)

        return proofClaims, revealedAttrsWithValues
async def testPrimaryClaimNoPredicates(prover1, verifier, claimsProver1Gvt,
                                       nonce, schemaGvtId):
    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        nonce,
        verifiableAttributes={'uuid1': AttributeInfo(name='name')},
        predicates={})

    claims, requestedProof = await prover1._findClaims(proofRequest)
    claims = {
        schemaId:
        ProofClaims(Claims(primaryClaim=proofClaim.claims.primaryClaim),
                    [AttributeInfo(name='name')], [])
        for schemaId, proofClaim in claims.items()
    }
    proof = await prover1._prepareProof(claims, proofRequest.nonce,
                                        requestedProof)

    assert await verifier.verify(proofRequest, proof)
async def testPrimaryClaimPredicatesOnly(prover1, verifier, claimsProver1Gvt,
                                         nonce, schemaGvtId):
    predicate = PredicateGE('age', 18)
    proofRequest = ProofRequest("proof1",
                                "1.0",
                                nonce,
                                verifiableAttributes={},
                                predicates={'predicate_uuid1': predicate})

    claims, requestedProof = await prover1._findClaims(proofRequest)
    claims = {
        schemaId:
        ProofClaims(Claims(primaryClaim=proofClaim.claims.primaryClaim),
                    predicates=[predicate])
        for schemaId, proofClaim in claims.items()
    }

    proof = await prover1._prepareProof(claims, proofRequest.nonce,
                                        requestedProof)

    assert await verifier.verify(proofRequest, proof)