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)
Ejemplo n.º 2
0
def getProofBuilderAndAttribs(attribs, credDefs, issuerPks):
    uid = str(uuid.uuid4())
    mcds = MemoryCredDefStore()
    for cd in credDefs.values():
        mcds.publishCredDef(cd)
    miks = MemoryIssuerKeyStore()
    for ipk in issuerPks.values():
        miks.publishIssuerKey(ipk)
    prover = Prover(id=uid, cds=mcds, iks=miks)
    vprime = prover.getVPrimes(*tuple(issuerPks.keys()))
    proofBuilder = ProofBuilder(issuerPks, masterSecret=prover.masterSecret,
                                vprime=vprime)
    return proofBuilder, attribs
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def prover(gvtCredDef, gvtIssuerPk):
    uid = str(uuid.uuid4())
    mcds = MemoryCredDefStore()
    mcds.publishCredDef(gvtCredDef)
    miks = MemoryIssuerKeyStore()
    for ipk in gvtIssuerPk.values():
        miks.publishIssuerKey(ipk)
    return Prover(id=uid, cds=mcds, iks=miks)
Ejemplo n.º 5
0
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)
Ejemplo n.º 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)
Ejemplo n.º 7
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)
async def init(primes, 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
    await issuer.genKeys(schema_id, **primes)

    # 4. Issue accumulator
    await issuer.issueAccumulator(schemaId=schema_id, iA='110', L=5)

    # 5. 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)

    # 6. request Claims
    prover = Prover(ProverWalletInMemory(prover_id, public_repo))
    claims_req = await prover.createClaimRequest(schema_id, reqNonRevoc=False)
    (claim_signature,
     claim_attributes) = await issuer.issueClaim(schema_id, claims_req)

    await prover.processClaim(schema_id, claim_attributes, claim_signature)

    global global_dict
    global_dict = {'prover': prover}

    public_key = await issuer.wallet.getPublicKey(schema_id)

    conn.send(
        json.dumps({
            'primary': public_key.to_str_dict(),
            'revocation': None
        }).encode())
Ejemplo n.º 9
0
def prover2(proverWallet2):
    return Prover(proverWallet2)
Ejemplo n.º 10
0
def prover1(proverWallet1):
    return Prover(proverWallet1)