예제 #1
0
    def __init__(self, schemaId, repo: PublicRepo):
        WalletInMemory.__init__(self, schemaId, repo)

        # other dicts with key=schemaKey
        self._sks = {}
        self._skRs = {}
        self._accumSks = {}
        self._m2s = {}
        self._attributes = {}
예제 #2
0
    def __init__(self, schemaId, repo: PublicRepo):
        WalletInMemory.__init__(self, schemaId, repo)

        # other dicts with key=schemaKey
        self._m1s = {}
        self._m2s = {}

        self._c1s = {}
        self._c2s = {}

        self._primaryInitData = {}
        self._nonRevocInitData = {}
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())
예제 #4
0
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)
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)
예제 #6
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)
    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)
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)
예제 #8
0
def verifier(publicRepo):
    return Verifier(WalletInMemory('verifier1', publicRepo))
예제 #9
0
 def __init__(self, client, wallet: Wallet, publicRepo: PublicRepo = None):
     publicRepo = publicRepo or SovrinPublicRepo(client=client,
                                                 wallet=wallet)
     verifierWallet = WalletInMemory(wallet.defaultId, publicRepo)
     super().__init__(verifierWallet)