Esempio n. 1
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. 2
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. 3
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. 4
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. 5
0
async def testEmpty(prover1):
    proofRequest = ProofRequest("proof1",
                                "1.0",
                                1,
                                verifiableAttributes={},
                                predicates={})
    assert ({}, RequestedProof([], [], [],
                               [])) == await prover1._findClaims(proofRequest)
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. 7
0
    async def _findClaims(self, proofRequest: ProofRequest) -> (
            Dict[SchemaKey, ProofClaims], Dict[str, Any]):
        revealedAttrs, predicates = proofRequest.verifiableAttributes, proofRequest.predicates

        foundRevealedAttrs = {}
        foundPredicates = {}
        proofClaims = {}
        schemas = {}
        allClaimsAttributes = await self.wallet.getAllClaimsAttributes()

        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

        for schemaKey, c in allClaimsAttributes.items():
            schemas[schemaKey] = (await self.wallet.getSchema(ID(schemaKey)))

        for uuid, revealedAttr in revealedAttrs.items():
            matches = [(schemas[key].seqId, c) for key, c in allClaimsAttributes.items() if revealedAttr.name in c
                       and (schemas[key].seqId == revealedAttr.schema_seq_no if revealedAttr.schema_seq_no else True)
                       and (schemas[key].issuerId == revealedAttr.issuer_did if revealedAttr.issuer_did else True)]

            if len(matches) == 0:
                raise ValueError("A claim isn't found for the following attributes: {}", revealedAttr.name)

            schemaId, claim = matches[0]
            foundRevealedAttrs[uuid] = [str(schemaId), str(claim[revealedAttr.name].raw),
                                        str(claim[revealedAttr.name].encoded)]

            if schemaId not in proofClaims:
                await addProof()

        for uuid, predicate in predicates.items():
            matches = [(schemas[key].seqId, c) for key, c in allClaimsAttributes.items() if predicate.attrName in c
                       and (schemas[key].seqId == predicate.schema_seq_no if predicate.schema_seq_no else True)
                       and (schemas[key].issuerId == predicate.issuer_did if predicate.issuer_did else True)]

            if len(matches) == 0:
                raise ValueError("A claim isn't found for the following predicate: {}", predicate)

            schemaId, claim = matches[0]
            foundPredicates[uuid] = str(schemaId)

            if schemaId not in proofClaims:
                await addProof()

        requestedProof = RequestedProof(revealed_attrs=foundRevealedAttrs, predicates=foundPredicates)

        return proofClaims, requestedProof
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)