コード例 #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)
コード例 #2
0
ファイル: test_types.py プロジェクト: aigoncharov/anoncreds
async def test_proof_from_to_dict(prover1, nonce, claimsProver1Gvt, schemaGvt):
    n = (await prover1.wallet.getPublicKey(ID(schemaId=schemaGvt.seqId))).N
    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        nonce,
        verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
        predicates={'predicate_uuid': PredicateGE('age', 18)})

    proof = await prover1.presentProof(proofRequest)

    proofInfo = proof.proofs[str(schemaGvt.seqId)]
    proof = ProofInfo(Proof(primaryProof=proofInfo.proof.primaryProof),
                      issuer_did=schemaGvt.issuerId,
                      schema_seq_no=proofInfo.schema_seq_no)

    assert proof == ProofInfo.from_str_dict(proof.to_str_dict(), n)
コード例 #3
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)
コード例 #4
0
async def testUParamShouldBeSame(prover1, verifier, issuerGvt, schemaGvtId,
                                 attrsProver1Gvt, keysGvt,
                                 issueAccumulatorGvt):
    claimsReq = await prover1.createClaimRequest(schemaGvtId)

    claimsReq = claimsReq._replace(U=claimsReq.U**2)
    claim_signature, claim_attributes = await issuerGvt.issueClaim(
        schemaGvtId, claimsReq)
    await prover1.processClaim(schemaGvtId, claim_attributes, claim_signature)

    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        verifier.generateNonce(),
        verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
        predicates={})
    assert not await presentProofAndVerify(verifier, proofRequest, prover1)
コード例 #5
0
ファイル: test_types.py プロジェクト: sunilake/indy-anoncreds
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())
コード例 #6
0
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)
コード例 #7
0
async def testOneRevealedOnly(prover1, allClaims, schemaGvtId, attrRepo,
                              schemaGvt):
    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        1,
        verifiableAttributes={'uuid': AttributeInfo(name='name')})
    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)
コード例 #8
0
    def sendProofReq(self, link: Connection, proofReqSchemaKey):
        if self._proofRequestsSchema and (proofReqSchemaKey
                                          in self._proofRequestsSchema):
            proofRequest = self._proofRequestsSchema[proofReqSchemaKey]

            proofRequest = ProofRequest(
                proofRequest[NAME], proofRequest[VERSION],
                getNonceForProof(link.request_nonce), proofRequest[ATTRIBUTES],
                proofRequest[VERIFIABLE_ATTRIBUTES]
                if VERIFIABLE_ATTRIBUTES in proofRequest else [],
                proofRequest[PREDICATES] if PREDICATES in proofRequest else [])

            op = {
                TYPE: PROOF_REQUEST,
                PROOF_REQUEST_FIELD: proofRequest.to_str_dict()
            }

            self.signAndSendToLink(msg=op, linkName=link.name)
        else:
            return ERR_NO_PROOF_REQUEST_SCHEMA_FOUND
コード例 #9
0
ファイル: test_types.py プロジェクト: aigoncharov/anoncreds
async def testClaimProofFromToDictPrimaryOnly(prover1, nonce, claimsProver1Gvt,
                                              schemaGvt):
    proofRequest = ProofRequest(
        "proof1",
        "1.0",
        1,
        verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
        predicates={'predicate_uuid': PredicateGE('age', 18)})

    proof = await prover1.presentProof(proofRequest)

    proofInfo = proof.proofs[str(schemaGvt.seqId)]
    proofs = {
        schemaGvt.seqId:
        ProofInfo(Proof(primaryProof=proofInfo.proof.primaryProof),
                  issuer_did=schemaGvt.issuerId,
                  schema_seq_no=proofInfo.schema_seq_no)
    }
    proof = proof._replace(proofs=proofs)
    assert proof == FullProof.fromStrDict(proof.toStrDict())
コード例 #10
0
ファイル: test_types.py プロジェクト: sunilake/indy-anoncreds
async def test_requested_proof_from_to_dict(prover1, nonce, claimsProver1Gvt):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                verifiableAttributes={
                                    'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid': PredicateGE('age', 18)})

    proof = await prover1.presentProof(proofRequest)

    requested_proof_serialized = {
        'revealed_attrs': {'attr_uuid': ['1', 'Alex', '1139481716457488690172217916278103335']},
        'predicates': {'predicate_uuid': '1'},
        'self_attested_attrs': {},
        'unrevealed_attrs': {}
    }

    assert proof.requestedProof.to_str_dict() == requested_proof_serialized
    assert proof.requestedProof == RequestedProof.from_str_dict(
        requested_proof_serialized)
    assert proof.requestedProof == RequestedProof.from_str_dict(
        proof.requestedProof.to_str_dict())
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
    def _merge_request(self, request_data):
        link_request = request_data.get('connection-request')
        linkName = link_request['name']
        link = self.wallet.getConnection(linkName)
        request_proof_requests = request_data.get('proof-requests', None)
        nonce = link_request.get(NONCE)
        if request_proof_requests:
            for icr in request_proof_requests:
                # match is found if name and version are same
                matchedProofRequest = next(
                    (cr for cr in link.proofRequests
                     if (cr.name == icr[NAME] and cr.version == icr[VERSION])),
                    None)

                # if link.requestedProofs contains any claim request
                if matchedProofRequest:
                    # merge 'attributes' and 'verifiableAttributes'
                    matchedProofRequest.attributes = {
                        **matchedProofRequest.attributes,
                        **icr[ATTRIBUTES]
                    }
                    matchedProofRequest.verifiableAttributes = dict(
                        matchedProofRequest.verifiableAttributes,
                        **icr[VERIFIABLE_ATTRIBUTES])

                else:
                    # otherwise append proof request to link
                    link.proofRequests.append(
                        ProofRequest(
                            icr[NAME],
                            icr[VERSION],
                            getNonceForProof(nonce),
                            attributes=icr[ATTRIBUTES],
                            verifiableAttributes=icr[VERIFIABLE_ATTRIBUTES]))

            return link
        else:
            raise ConnectionAlreadyExists
コード例 #14
0
    def load_request(self, request_data):
        link_request = request_data["connection-request"]
        remoteIdentifier = link_request[f.IDENTIFIER.nm]
        # TODO signature should be validated!
        # signature = request_data["sig"]
        link_request_name = link_request[NAME]
        remoteEndPoint = link_request.get("endpoint", None)
        remote_verkey = link_request.get("verkey", None)
        linkNonce = link_request[NONCE]
        proofRequestsJson = request_data.get("proof-requests", None)

        proofRequests = []
        if proofRequestsJson:
            for cr in proofRequestsJson:
                proofRequests.append(
                    ProofRequest(
                        cr[NAME], cr[VERSION], getNonceForProof(linkNonce),
                        cr[ATTRIBUTES], cr[VERIFIABLE_ATTRIBUTES]
                        if VERIFIABLE_ATTRIBUTES in cr else [],
                        cr[PREDICATES] if PREDICATES in cr else []))

        self.notifyMsgListener(
            "1 connection request found for {}.".format(link_request_name))

        self.notifyMsgListener(
            "Creating connection for {}.".format(link_request_name))
        # TODO: Would we always have a trust anchor corresponding to a link?

        li = Connection(name=link_request_name,
                        trustAnchor=link_request_name,
                        remoteIdentifier=remoteIdentifier,
                        remoteEndPoint=remoteEndPoint,
                        request_nonce=linkNonce,
                        proofRequests=proofRequests,
                        remote_verkey=remote_verkey)

        self.wallet.addConnection(li)
        return li
コード例 #15
0
    async def doTestAnonCredsPrimaryOnly():
        # 1. Create a Schema
        schema = await issuer.genSchema('GVT', '1.0', GVT.attribNames())
        schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId)

        # 2. Create keys for the Schema
        await issuer.genKeys(schemaId, **primes1)

        # 3. Issue accumulator
        #TODO: Not implemented yet
        #await issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5)

        # 4. set attributes for user1
        attrs = GVT.attribs(name='Alex', age=28, height=175, sex='male')
        proverId = str(prover.proverId)
        attrRepo.addAttributes(schema.getKey(), proverId, attrs)

        # 5. request Claims
        claimsReq = await prover.createClaimRequest(schemaId, proverId, False)
        (claim_signature,
         claim_attributes) = await issuer.issueClaim(schemaId, claimsReq)
        await prover.processClaim(schemaId, claim_attributes, claim_signature)

        # 6. proof Claims
        proofRequest = ProofRequest(
            "proof1",
            "1.0",
            verifier.generateNonce(),
            verifiableAttributes={
                'attr_uuid': AttributeInfo('name', schema.seqId)
            },
            predicates={'predicate_uuid': PredicateGE('age', 18)})

        proof = await prover.presentProof(proofRequest)
        assert proof.requestedProof.revealed_attrs['attr_uuid'][1] == 'Alex'
        assert await verifier.verify(proofRequest, proof)
コード例 #16
0
async def testGePredicateForEqual(prover1, verifier, claimsProver1):
    proofRequest = ProofRequest("proof1", "1.0", verifier.generateNonce(),
                                verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid': PredicateGE('period', 8)})
    assert await presentProofAndVerify(verifier, proofRequest, prover1)
コード例 #17
0
async def testEmpty(prover1, verifier, claimsProver1Gvt):
    assert await presentProofAndVerify(
        verifier, ProofRequest("proof1", "1.0", verifier.generateNonce()),
        prover1)
コード例 #18
0
async def testPredicateNotFound(prover1, allClaims):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                predicates={'predicate_uuid1': PredicateGE('age', 18),
                                            'predicate_uuid2': PredicateGE('aaaa', 8)})
    with pytest.raises(ValueError):
        await prover1._findClaims(proofRequest)
コード例 #19
0
async def testEmpty(prover1):
    proofRequest = ProofRequest("proof1", "1.0", 1, verifiableAttributes={}, predicates={})
    assert ({}, RequestedProof([], [], [], [])) == await prover1._findClaims(proofRequest)
コード例 #20
0
async def testAttrNotFound(prover1, allClaims):
    proofRequest = ProofRequest("proof1", "1.0", 1,
                                verifiableAttributes={'attr_uuid1': AttributeInfo(name='name'),
                                                      'attr_uuid2': AttributeInfo(name='aaa')})
    with pytest.raises(ValueError):
        await prover1._findClaims(proofRequest)
コード例 #21
0
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)
    (claim1_signature,
     claim1_attributes) = await issuer1.issueClaim(schemaId1, claimsReq1)
    (claim2_signature,
     claim2_attributes) = await issuer2.issueClaim(schemaId2, claimsReq2)
    await prover.processClaim(schemaId1, claim1_attributes, claim1_signature)
    await prover.processClaim(schemaId2, claim2_attributes, claim2_signature)

    # 6. proof Claims
    verifier = Verifier(WalletInMemory('verifier1', publicRepo))

    proofRequest = ProofRequest("proof1",
                                "1.0",
                                verifier.generateNonce(),
                                verifiableAttributes={
                                    'attr_uuid1':
                                    AttributeInfo('name', schema1.seqId),
                                    'attr_uuid2':
                                    AttributeInfo('status', schema2.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 proof.requestedProof.revealed_attrs['attr_uuid2'][1] == 'FULL'

    assert await verifier.verify(proofRequest, proof)
コード例 #22
0
async def testNoPredicates(prover1, verifier, claimsProver1):
    proofRequest = ProofRequest("proof1", "1.0", verifier.generateNonce(),
                                verifiableAttributes={'uuid1': AttributeInfo(name='name'), 'uuid2': AttributeInfo(name='status')},
                                predicates={})

    assert await presentProofAndVerify(verifier, proofRequest, prover1)
コード例 #23
0
async def testMultipleGePredicate(prover1, verifier, claimsProver1):
    proofRequest = ProofRequest("proof1", "1.0", verifier.generateNonce(),
                                verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid1': PredicateGE('age', 18),
                                            'predicate_uuid2': PredicateGE('period', 5)})
    await presentProofAndVerify(verifier, proofRequest, prover1)
コード例 #24
0
async def testGePredicateNegative(prover1, verifier, claimsProver1):
    proofRequest = ProofRequest("proof1", "1.0", verifier.generateNonce(),
                                verifiableAttributes={'attr_uuid': AttributeInfo(name='name')},
                                predicates={'predicate_uuid': PredicateGE('period', 9)})
    with pytest.raises(ValueError):
        await presentProofAndVerify(verifier, proofRequest, prover1)