async def checkJobCertWritten():
        acmeId = acmeAgent.wallet.defaultId
        schemaId = ID(SchemaKey("Job-Certificate", "0.2", acmeId))
        schema = await acmeAgent.issuer.wallet.getSchema(schemaId)
        assert schema
        assert schema.seqId

        issuerPublicKey = await acmeAgent.issuer.wallet.getPublicKey(schemaId)
        assert issuerPublicKey
        assert issuerPublicKey.seqId
def test_claim_request_from_libsovrin_works(aliceAgent, aliceAcceptedFaber,
                                            aliceAcceptedAcme, acmeAgent,
                                            emptyLooper):
    faberLink = aliceAgent.wallet.getLink('Faber College')
    name, version, origin = faberLink.availableClaims[0]
    schemaKey = SchemaKey(name, version, origin)
    timeout = waits.expectedClaimsReceived()

    async def create_claim_init_data_and_send_msg():
        claimReq = await aliceAgent.prover.createClaimRequest(
            schemaId=ID(schemaKey),
            proverId='b1134a647eb818069c089e7694f63e6d',
            reqNonRevoc=False)

        assert claimReq

        msg = ({
            'issuer_did': 'FuN98eH2eZybECWkofW6A9BKJxxnTatBCopfUiNxo6ZB',
            'claim_def_seq_no': 14,
            'blinded_ms': {
                'prover_did': 'b1134a647eb818069c089e7694f63e6d',
                'u': str(crypto_int_to_str(claimReq.U)),
                'ur': None
            },
            'type': 'CLAIM_REQUEST',
            'schema_seq_no': 13,
            'nonce': 'b1134a647eb818069c089e7694f63e6d',
        })

        aliceAgent.signAndSendToLink(msg=msg, linkName=faberLink.name)

    emptyLooper.run(
        eventually(create_claim_init_data_and_send_msg, timeout=timeout))

    # 2. check that claim is received from Faber
    async def chkClaims():
        claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
        assert claim.primaryClaim

    emptyLooper.run(eventually(chkClaims, timeout=timeout))

    # 3. send proof to Acme
    acme_link, acme_proof_req = aliceAgent.wallet.getMatchingLinksWithProofReq(
        "Job-Application", "Acme Corp")[0]
    aliceAgent.sendProof(acme_link, acme_proof_req)

    # 4. check that proof is verified by Acme
    def chkProof():
        internalId = acmeAgent.get_internal_id_by_nonce(
            acme_link.invitationNonce)
        link = acmeAgent.wallet.getLinkBy(internalId=internalId)
        assert "Job-Application" in link.verifiedClaimProofs

    timeout = waits.expectedClaimsReceived()
    emptyLooper.run(eventually(chkProof, timeout=timeout))
def test_claim_from_libsovrin_works(aliceAgent, aliceAcceptedFaber,
                                    aliceAcceptedAcme, acmeAgent, emptyLooper,
                                    faberAgent):
    faberLink = aliceAgent.wallet.getConnection('Faber College')
    name, version, origin = faberLink.availableClaims[0]
    schemaKey = SchemaKey(name, version, origin)
    timeout = waits.expectedClaimsReceived()

    schema = faberAgent.issuer.wallet._schemasByKey[schemaKey]

    async def create_claim_and_send_to_prover():
        claimReq = await aliceAgent.prover.createClaimRequest(
            schemaId=ID(schemaKey),
            proverId='b1134a647eb818069c089e7694f63e6d',
            reqNonRevoc=False)

        assert claimReq

        attr = faberAgent.issuer_backend.get_record_by_internal_id(1)
        faberAgent.issuer._attrRepo.addAttributes(schemaKey=schemaKey,
                                                  userId=claimReq.userId,
                                                  attributes=attr)
        claim_signature, claim_attributes = await faberAgent.issuer.issueClaim(
            ID(schemaKey=schemaKey), claimReq)

        msg = get_claim_libsovrin_msg(claim_signature, schema.seqId)

        await aliceAgent.handleReqClaimResponse(msg)

    emptyLooper.run(
        eventually(create_claim_and_send_to_prover, timeout=timeout))

    # 2. check that claim is received from Faber
    async def chkClaims():
        claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
        assert claim.primaryClaim

    emptyLooper.run(eventually(chkClaims, timeout=timeout))

    # 3. send proof to Acme
    acme_link, acme_proof_req = aliceAgent.wallet.getMatchingConnectionsWithProofReq(
        "Job-Application", "Acme Corp")[0]
    aliceAgent.sendProof(acme_link, acme_proof_req)

    # 4. check that proof is verified by Acme
    def chkProof():
        internalId = acmeAgent.get_internal_id_by_nonce(
            acme_link.request_nonce)
        link = acmeAgent.wallet.getConnectionBy(internalId=internalId)
        assert "Job-Application" in link.verifiedClaimProofs

    timeout = waits.expectedClaimsReceived()
    emptyLooper.run(eventually(chkProof, timeout=timeout))
def test_proof_from_libindy_works(
        aliceAgent,
        aliceAcceptedFaber,
        aliceAcceptedAcme,
        acmeAgent,
        emptyLooper,
        faberAgent):
    # 1. request Claims from Faber
    faberLink = aliceAgent.wallet.getConnection('Faber College')
    name, version, origin = faberLink.availableClaims[0]
    schemaKey = SchemaKey(name, version, origin)
    aliceAgent.sendReqClaim(faberLink, schemaKey)

    schema = faberAgent.issuer.wallet._schemasByKey[schemaKey]

    # 2. check that claim is received from Faber
    async def chkClaims():
        claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
        assert claim.primaryClaim

    timeout = waits.expectedClaimsReceived()
    emptyLooper.run(eventually(chkClaims, timeout=timeout))

    # 3. send proof to Acme
    acme_link, acme_proof_req = aliceAgent.wallet.getMatchingConnectionsWithProofReq(
        "Job-Application", "Acme Corp")[0]

    async def create_proof():
        proofRequest = ProofRequest("proof1",
                                    "1.0",
                                    int(acme_proof_req.nonce),
                                    verifiableAttributes=acme_proof_req.verifiableAttributes,
                                    predicates=acme_proof_req.predicates)

        proof = await  aliceAgent.prover.presentProof(proofRequest)

        msg = get_proof_libindy_msg(
            acme_link, acme_proof_req, proof, str(schema.seqId), schema.seqId)

        aliceAgent.signAndSendToLink(msg=msg, linkName=acme_link.name)

    emptyLooper.run(eventually(create_proof, timeout=timeout))

    # 4. check that proof is verified by Acme
    def chkProof():
        internalId = acmeAgent.get_internal_id_by_nonce(
            acme_link.request_nonce)
        link = acmeAgent.wallet.getConnectionBy(internalId=internalId)
        assert "Job-Application" in link.verifiedClaimProofs

    emptyLooper.run(eventually(chkProof, timeout=timeout))
Example #5
0
async def bootstrap_faber(agent):
    schema_id = ID(
        SchemaKey("Transcript", "1.9",
                  "FuN98eH2eZybECWkofW6A9BKJxxnTatBCopfUiNxo6ZB"))

    try:
        schema = await agent.issuer.wallet.getSchema(schema_id)
    except SchemaNotFoundError:
        schema_id = await bootstrap_schema(agent, 'Transcript', 'Transcript',
                                           '1.9', primes["prime1"][0],
                                           primes["prime1"][1])

    await agent._set_available_claim_by_internal_id(1, schema_id)
    await agent._set_available_claim_by_internal_id(2, schema_id)
    await agent._set_available_claim_by_internal_id(3, schema_id)
    await agent._set_available_claim_by_internal_id(4, schema_id)
Example #6
0
def test_claim_request_from_libsovrin_works(aliceAgent, aliceAcceptedFaber,
                                            aliceAcceptedAcme, acmeAgent,
                                            emptyLooper, faberAgent):
    faberLink = aliceAgent.wallet.getLink('Faber College')
    name, version, origin = faberLink.availableClaims[0]
    schemaKey = SchemaKey(name, version, origin)
    timeout = waits.expectedClaimsReceived()

    schema = faberAgent.issuer.wallet._schemasByKey[schemaKey]

    async def create_claim_init_data_and_send_msg():
        claimReq = await aliceAgent.prover.createClaimRequest(
            schemaId=ID(schemaKey),
            proverId='b1134a647eb818069c089e7694f63e6d',
            reqNonRevoc=False)

        assert claimReq

        msg = get_claim_request_libsovrin_msg(claimReq, schema.seqId)

        aliceAgent.signAndSendToLink(msg=msg, linkName=faberLink.name)

    emptyLooper.run(
        eventually(create_claim_init_data_and_send_msg, timeout=timeout))

    # 2. check that claim is received from Faber
    async def chkClaims():
        claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
        assert claim.primaryClaim

    emptyLooper.run(eventually(chkClaims, timeout=timeout))

    # 3. send proof to Acme
    acme_link, acme_proof_req = aliceAgent.wallet.getMatchingLinksWithProofReq(
        "Job-Application", "Acme Corp")[0]
    aliceAgent.sendProof(acme_link, acme_proof_req)

    # 4. check that proof is verified by Acme
    def chkProof():
        internalId = acmeAgent.get_internal_id_by_nonce(
            acme_link.invitationNonce)
        link = acmeAgent.wallet.getLinkBy(internalId=internalId)
        assert "Job-Application" in link.verifiedClaimProofs

    timeout = waits.expectedClaimsReceived()
    emptyLooper.run(eventually(chkProof, timeout=timeout))
    async def sendReqClaimAsync(self, link: Link, schemaKey):
        name, version, origin = schemaKey
        schemaKey = SchemaKey(name, version, origin)

        claimReq = await self.prover.createClaimRequest(
            schemaId=ID(schemaKey),
            proverId=link.invitationNonce,
            reqNonRevoc=False)

        op = {
            NONCE: link.invitationNonce,
            TYPE: CLAIM_REQUEST,
            NAME: name,
            VERSION: version,
            ORIGIN: origin,
            CLAIM_REQ_FIELD: claimReq.toStrDict()
        }

        self.signAndSend(msg=op, linkName=link.name)
Example #8
0
    async def processReqClaim(self, msg):
        body, (frm, _) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError

        schemaId = ID(schemaId=body[SCHEMA_SEQ_NO])
        schema = await self.issuer.wallet.getSchema(schemaId)

        if not self.is_claim_available(link, schema.name):
            self.notifyToRemoteCaller(EVENT_NOTIFY_MSG,
                                      "This claim is not yet available.",
                                      self.wallet.defaultId,
                                      frm,
                                      origReqId=body.get(f.REQ_ID.nm))
            return

        public_key = await self.issuer.wallet.getPublicKey(schemaId)
        claimReq = ClaimRequest.from_str_dict(body[CLAIM_REQ_FIELD],
                                              public_key.N)

        schemaKey = SchemaKey(schema.name, schema.version, schema.issuerId)
        self._add_attribute(schemaKey=schemaKey,
                            proverId=claimReq.userId,
                            link=link)

        (signature, claim) = await self.issuer.issueClaim(schemaId, claimReq)

        claimDetails = {
            CLAIMS_SIGNATURE_FIELD: signature.to_str_dict(),
            f.IDENTIFIER.nm: schema.issuerId,
            CLAIM_FIELD: json.dumps(claim),
            CLAIM_DEF_SEQ_NO: public_key.seqId,
            REVOC_REG_SEQ_NO: 0,
            SCHEMA_SEQ_NO: body[SCHEMA_SEQ_NO]
        }

        resp = self.getCommonMsg(CLAIM, claimDetails)
        self.signAndSend(resp,
                         link.localIdentifier,
                         frm,
                         origReqId=body.get(f.REQ_ID.nm))
def test_send_proof_works(aliceAgent, aliceAcceptedFaber, aliceAcceptedAcme,
                          acmeAgent, emptyLooper):
    # 1. request Claims from Faber
    faberLink = aliceAgent.wallet.getConnection('Faber College')
    name, version, origin = faberLink.availableClaims[0]
    schemaKey = SchemaKey(name, version, origin)
    aliceAgent.sendReqClaim(faberLink, schemaKey)

    # 2. check that claim is received from Faber
    async def chkClaims():
        claim = await aliceAgent.prover.wallet.getClaimSignature(ID(schemaKey))
        assert claim.primaryClaim

    emptyLooper.run(
        eventually(chkClaims, timeout=waits.expectedClaimsReceived()))

    # 3. send Proof Request to Alice
    alice_link = acmeAgent.wallet.getConnection('Alice')
    acmeAgent.sendProofReq(alice_link, 'Job-Application-v0.3')

    def chkProofRequest():
        assert len(
            aliceAgent.wallet.getMatchingConnectionsWithProofReq(
                "Job-Application-2", "Acme Corp")) > 0

    emptyLooper.run(
        eventually(chkProofRequest, timeout=waits.expectedClaimsReceived()))

    # 4. send proof to Acme
    acme_link, acme_proof_req = aliceAgent.wallet.getMatchingConnectionsWithProofReq(
        "Job-Application-2", "Acme Corp")[0]
    aliceAgent.sendProof(acme_link, acme_proof_req)

    # 5. check that proof is verified by Acme
    def chkProof():
        internalId = acmeAgent.get_internal_id_by_nonce(
            acme_link.request_nonce)
        link = acmeAgent.wallet.getConnectionBy(internalId=internalId)
        assert "Job-Application-2" in link.verifiedClaimProofs

    emptyLooper.run(
        eventually(chkProof, timeout=waits.expectedClaimsReceived()))
Example #10
0
    async def handleReqClaimResponse(self, msg):
        body, _ = msg
        issuerId = body.get(IDENTIFIER)
        claim = body[DATA]
        li = self._getLinkByTarget(getCryptonym(issuerId))
        if li:
            self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm))
            self.notifyMsgListener('    Received claim "{}".\n'.format(
                claim[NAME]))
            name, version, claimAuthor = \
                claim[NAME], claim[VERSION], claim[f.IDENTIFIER.nm]

            schemaKey = SchemaKey(name, version, claimAuthor)
            schema = await self.prover.wallet.getSchema(ID(schemaKey))
            schemaId = ID(schemaKey=schemaKey, schemaId=schema.seqId)

            claim = Claims.fromStrDict(claim[CLAIM_FIELD])

            await self.prover.processClaim(schemaId, claim)
        else:
            self.notifyMsgListener("No matching link found")
Example #11
0
    async def send_claim(self, link: Link, schema_key):
        name, version, origin = schema_key
        schema_key = SchemaKey(name, version, origin)

        claimReq = await self.prover.createClaimRequest(
            schemaId=ID(schema_key),
            proverId=link.invitationNonce,
            reqNonRevoc=False)

        # TODO link.invitationNonce should not be used here.
        # It has served its purpose by this point. Claim Requests do not need a nonce.
        op = {
            NONCE: link.invitationNonce,
            TYPE: CLAIM_REQUEST,
            NAME: name,
            VERSION: version,
            ORIGIN: origin,
            CLAIM_REQ_FIELD: claimReq.toStrDict()
        }

        self.signAndSendToLink(msg=op, linkName=link.name)
Example #12
0
    async def processReqClaim(self, msg):
        body, (frm, ha) = msg
        link = self.verifyAndGetLink(msg)
        if not link:
            raise NotImplementedError
        name = body[NAME]
        if not self.isClaimAvailable(link, name):
            self.notifyToRemoteCaller(EVENT_NOTIFY_MSG,
                                      "This claim is not yet available",
                                      self.issuer.wallet.defaultId,
                                      frm,
                                      origReqId=body.get(f.REQ_ID.nm))
            return

        version = body[VERSION]
        origin = body[ORIGIN]
        claimReq = ClaimRequest.fromStrDict(body[CLAIM_REQ_FIELD])

        schemaKey = SchemaKey(name, version, origin)
        schema = await self.issuer.wallet.getSchema(ID(schemaKey))
        schemaId = ID(schemaKey=schemaKey, schemaId=schema.seqId)

        self._addAtrribute(schemaKey=schemaKey,
                           proverId=claimReq.userId,
                           link=link)

        claim = await self.issuer.issueClaim(schemaId, claimReq)

        claimDetails = {
            NAME: schema.name,
            VERSION: schema.version,
            CLAIM_FIELD: claim.toStrDict(),
            f.IDENTIFIER.nm: schema.issuerId
        }

        resp = self.getCommonMsg(CLAIM, claimDetails)
        self.signAndSend(resp,
                         link.localIdentifier,
                         frm,
                         origReqId=body.get(f.REQ_ID.nm))
Example #13
0
 async def getMatchingLinksWithReceivedClaimAsync(self, claimName=None):
     matchingLinkAndAvailableClaim = self.wallet.getMatchingLinksWithAvailableClaim(
         claimName)
     matchingLinkAndReceivedClaim = []
     for li, cl in matchingLinkAndAvailableClaim:
         name, version, origin = cl
         schemaKeyId = ID(
             SchemaKey(name=name, version=version, issuerId=origin))
         schema = await self.prover.wallet.getSchema(schemaKeyId)
         claimAttrs = set(schema.attrNames)
         claim = None
         try:
             claim = await self.prover.wallet.getClaims(schemaKeyId)
         except ValueError:
             pass  # it means no claim was issued
         attrs = {k: None for k in claimAttrs}
         if claim:
             issuedAttributes = claim.primaryClaim.attrs
             if claimAttrs.intersection(issuedAttributes.keys()):
                 attrs = {k: issuedAttributes[k] for k in claimAttrs}
         matchingLinkAndReceivedClaim.append((li, cl, attrs))
     return matchingLinkAndReceivedClaim
Example #14
0
    async def getMatchingLinksWithReceivedClaimAsync(self, claimName=None):
        matchingLinkAndAvailableClaim = self.wallet.getMatchingLinksWithAvailableClaim(
            claimName)
        matchingLinkAndReceivedClaim = []
        for li, cl in matchingLinkAndAvailableClaim:
            name, version, origin = cl
            schemaKeyId = ID(
                SchemaKey(name=name, version=version, issuerId=origin))
            schema = await self.prover.wallet.getSchema(schemaKeyId)
            claimAttrs = OrderedDict()
            for attr in schema.attrNames:
                claimAttrs[attr] = None
            attrs = None
            try:
                attrs = await self.prover.wallet.getClaim(schemaKeyId)
            except ValueError:
                pass  # it means no claim was issued

            if attrs:
                if set(claimAttrs.keys()).intersection(attrs.keys()):
                    for k in claimAttrs.keys():
                        claimAttrs[k] = attrs[k].raw
            matchingLinkAndReceivedClaim.append((li, cl, claimAttrs))
        return matchingLinkAndReceivedClaim
Example #15
0
    async def send_claim(self, link: Link, schema_key):
        name, version, origin = schema_key
        schema_key = SchemaKey(name, version, origin)

        claimReq = await self.prover.createClaimRequest(
            schemaId=ID(schema_key),
            proverId=link.invitationNonce,
            reqNonRevoc=False)

        # TODO link.invitationNonce should not be used here.
        # It has served its purpose by this point. Claim Requests do not need a nonce.
        public_key = await self.prover.wallet.getPublicKey(ID(schema_key))
        schema = await self.prover.wallet.getSchema(ID(schema_key))

        op = {
            TYPE: CLAIM_REQUEST,
            NONCE: link.invitationNonce,
            SCHEMA_SEQ_NO: schema.seqId,
            ISSUER_DID: origin,
            CLAIM_REQ_FIELD: claimReq.to_str_dict(),
            CLAIM_DEF_SEQ_NO: public_key.seqId
        }

        self.signAndSendToLink(msg=op, linkName=link.name)
    def executeGstFlow(name, userCLI, userMap, be, connectedToTest, do, fMap,
                       aMap, jobCertificateClaimMap, newKeyringOut,
                       reqClaimOut, reqClaimOut1, syncLinkOutWithEndpoint,
                       syncedInviteAcceptedOutWithoutClaims, tMap,
                       transcriptClaimMap):
        async def getPublicKey(wallet, schemaId):
            return await wallet.getPublicKey(schemaId)

        async def getClaim(schemaId):
            return await userCLI.agent.prover.wallet.getClaimSignature(schemaId
                                                                       )

        # Start User cli

        be(userCLI)
        setPromptAndKeyring(do, name, newKeyringOut, userMap)
        do('connect test', within=3, expect=connectedToTest)
        # Accept faber
        do('load sample/faber-invitation.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, fMap)
        do('show link faber')
        acceptInvitation(be, do, userCLI, fMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Request claim
        do('show claim Transcript')
        aliceRequestedTranscriptClaim(
            be,
            do,
            userCLI,
            transcriptClaimMap,
            reqClaimOut,
            None,  # Passing None since its not used
            None)  # Passing None since its not used

        faberSchemaId = ID(SchemaKey('Transcript', '1.2', fMap['remote']))
        faberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(faberAgent.issuer.wallet, faberSchemaId))
        userFaberIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, faberSchemaId))
        assert faberIssuerPublicKey == userFaberIssuerPublicKey

        do('show claim Transcript')
        assert userCLI.looper.run(getClaim(faberSchemaId))

        # Accept acme
        do('load sample/acme-job-application.sovrin')
        syncInvite(be, do, userCLI, syncLinkOutWithEndpoint, aMap)
        acceptInvitation(be, do, userCLI, aMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send claim
        do('show claim request Job-Application')
        do('set first_name to Alice')
        do('set last_name to Garcia')
        do('set phone_number to 123-45-6789')
        do('show claim request Job-Application')
        # Passing some args as None since they are not used in the method
        jobApplicationProofSent(be, do, userCLI, aMap, None, None, None)
        do('show claim Job-Certificate')
        # Request new available claims Job-Certificate
        jobCertClaimRequested(be, do, userCLI, None, jobCertificateClaimMap,
                              reqClaimOut1, None)

        acmeSchemaId = ID(SchemaKey('Job-Certificate', '0.2', aMap['remote']))
        acmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(acmeAgent.issuer.wallet, acmeSchemaId))
        userAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(userCLI.agent.prover.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == userAcmeIssuerPublicKey

        do('show claim Job-Certificate')
        assert userCLI.looper.run(getClaim(acmeSchemaId))

        # Accept thrift
        do('load sample/thrift-loan-application.sovrin')
        acceptInvitation(be, do, userCLI, tMap,
                         syncedInviteAcceptedOutWithoutClaims)
        # Send proofs
        bankBasicProofSent(be, do, userCLI, tMap, None)

        thriftAcmeIssuerPublicKey = userCLI.looper.run(
            getPublicKey(thriftAgent.issuer.wallet, acmeSchemaId))
        assert acmeIssuerPublicKey == thriftAcmeIssuerPublicKey
        passed = False
        try:
            bankKYCProofSent(be, do, userCLI, tMap, None)
            passed = True
        except:
            thriftFaberIssuerPublicKey = userCLI.looper.run(
                getPublicKey(thriftAgent.issuer.wallet, faberSchemaId))
            assert faberIssuerPublicKey == thriftFaberIssuerPublicKey
        assert passed
Example #17
0
    def __init__(self,
                 basedirpath: str,
                 client: Client = None,
                 wallet: Wallet = None,
                 port: int = None,
                 loop=None):
        if not basedirpath:
            config = getConfig()
            basedirpath = basedirpath or os.path.expanduser(config.baseDir)

        portParam, = self.getPassedArgs()

        super().__init__('Acme Corp',
                         basedirpath,
                         client,
                         wallet,
                         portParam or port,
                         loop=loop)

        self.availableClaims = []

        # maps invitation nonces to internal ids
        self._invites = {
            "57fbf9dc8c8e6acde33de98c6d747b28c": 1,
            "3a2eb72eca8b404e8d412c5bf79f2640": 2,
            "8513d1397e87cada4214e2a650f603eb": 3,
            "810b78be79f29fc81335abaa4ee1c5e8": 4
        }

        self._attrDefJobCert = AttribDef('Acme Job Certificat', [
            AttribType('first_name', encode=True),
            AttribType('last_name', encode=True),
            AttribType('employee_status', encode=True),
            AttribType('experience', encode=True),
            AttribType('salary_bracket', encode=True)
        ])

        self._attrDefJobApp = AttribDef('Acme Job Application', [
            AttribType('first_name', encode=True),
            AttribType('last_name', encode=True),
            AttribType('phone_number', encode=True),
            AttribType('degree', encode=True),
            AttribType('status', encode=True),
            AttribType('ssn', encode=True)
        ])

        # maps internal ids to attributes
        self._attrsJobCert = {
            1:
            self._attrDefJobCert.attribs(
                first_name="Alice",
                last_name="Garcia",
                employee_status="Permanent",
                experience="3 years",
                salary_bracket="between $50,000 to $100,000"),
            2:
            self._attrDefJobCert.attribs(
                first_name="Carol",
                last_name="Atkinson",
                employee_status="Permanent",
                experience="2 years",
                salary_bracket="between $60,000 to $90,000"),
            3:
            self._attrDefJobCert.attribs(
                first_name="Frank",
                last_name="Jeffrey",
                employee_status="Temporary",
                experience="4 years",
                salary_bracket="between $40,000 to $80,000"),
            4:
            self._attrDefJobCert.attribs(
                first_name="Craig",
                last_name="Richards",
                employee_status="On Contract",
                experience="3 years",
                salary_bracket="between $50,000 to $70,000")
        }

        self._schemaJobCertKey = SchemaKey("Job-Certificate", "0.2",
                                           self.wallet.defaultId)
        self._schemaJobAppKey = SchemaKey("Job-Application", "0.2",
                                          self.wallet.defaultId)
Example #18
0
    def __init__(self,
                 basedirpath: str,
                 client: Client = None,
                 wallet: Wallet = None,
                 port: int = None,
                 loop=None):
        if not basedirpath:
            config = getConfig()
            basedirpath = basedirpath or os.path.expanduser(config.baseDir)

        portParam, = self.getPassedArgs()
        agentLogger = getBulldogLogger(basedirpath)

        super().__init__('Bulldog',
                         basedirpath,
                         client,
                         wallet,
                         portParam or port,
                         loop=loop,
                         agentLogger=agentLogger)

        self.availableClaims = []

        # mapping between requester identifier and corresponding available claims
        self.requesterAvailClaims = {}

        # maps invitation nonces to internal ids
        self._invites = {'2e9882ea71976ddf9': 1, "2d03828a7383ea3ad": 2}

        self._attrDef = AttribDef('bulldog', [
            AttribType('title', encode=True),
            AttribType('first_name', encode=True),
            AttribType('last_name', encode=True),
            AttribType('address_1', encode=True),
            AttribType('address_2', encode=True),
            AttribType('address_3', encode=True),
            AttribType('postcode_zip', encode=True),
            AttribType('date_of_birth', encode=True),
            AttribType('account_type', encode=True),
            AttribType('year_opened', encode=True),
            AttribType('account_status', encode=True)
        ])

        # maps internal ids to attributes
        self._attrs = {
            1:
            self._attrDef.attribs(title='Mrs.',
                                  first_name='Alicia',
                                  last_name='Garcia',
                                  address_1='H-301',
                                  address_2='Street 1',
                                  address_3='UK',
                                  postcode_zip='G61 3NR',
                                  date_of_birth='December 28, 1990',
                                  account_type='savings',
                                  year_opened='2000',
                                  account_status='active'),
            2:
            self._attrDef.attribs(title='Mrs.',
                                  first_name='Jay',
                                  last_name='Raj',
                                  address_1='222',
                                  address_2='Baker Street',
                                  address_3='UK',
                                  postcode_zip='G61 3NR',
                                  date_of_birth='January 15, 1980',
                                  account_type='savings',
                                  year_opened='1999',
                                  account_status='active')
        }

        claimVersionFileName = 'bulldog-schema-version.txt'
        claimVersionNumber = 0.8
        claimVersionFilePath = '{}/{}'.format(basedirpath,
                                              claimVersionFileName)
        # get version number from file
        if os.path.isfile(claimVersionFilePath):
            try:
                with open(claimVersionFilePath, mode='r+') as file:
                    claimVersionNumber = float(file.read()) + 0.1
                    file.seek(0)
                    # increment version and update file
                    file.write(str(claimVersionNumber))
                    file.truncate()
            except OSError as e:
                agentLogger.warn('Error occurred while reading version file:'
                                 'error:{}'.format(e))
                raise e
            except ValueError as e:
                agentLogger.warn('Invalid version number')
                raise e
        else:
            try:
                with open(claimVersionFilePath, mode='w') as file:
                    file.write(str(claimVersionNumber))
            except OSError as e:
                agentLogger.warn('Error creating version file {}'.format(e))
                raise e

        self._schemaKey = SchemaKey('Banking-Relationship',
                                    str(claimVersionNumber),
                                    self.wallet.defaultId)
Example #19
0
    def __init__(self,
                 basedirpath: str,
                 client: Client = None,
                 wallet: Wallet = None,
                 port: int = None,
                 loop=None):
        if not basedirpath:
            config = getConfig()
            basedirpath = basedirpath or os.path.expanduser(config.baseDir)

        portParam, = self.getPassedArgs()

        super().__init__('Faber College',
                         basedirpath,
                         client,
                         wallet,
                         portParam or port,
                         loop=loop)

        self.availableClaims = []

        # maps invitation nonces to internal ids
        self._invites = {
            "b1134a647eb818069c089e7694f63e6d": 1,
            "2a2eb72eca8b404e8d412c5bf79f2640": 2,
            "7513d1397e87cada4214e2a650f603eb": 3,
            "710b78be79f29fc81335abaa4ee1c5e8": 4
        }

        self._attrDef = AttribDef('faber', [
            AttribType('student_name', encode=True),
            AttribType('ssn', encode=True),
            AttribType('degree', encode=True),
            AttribType('year', encode=True),
            AttribType('status', encode=True)
        ])

        # maps internal ids to attributes
        self._attrs = {
            1:
            self._attrDef.attribs(student_name="Alice Garcia",
                                  ssn="123-45-6789",
                                  degree="Bachelor of Science, Marketing",
                                  year="2015",
                                  status="graduated"),
            2:
            self._attrDef.attribs(student_name="Carol Atkinson",
                                  ssn="783-41-2695",
                                  degree="Bachelor of Science, Physics",
                                  year="2012",
                                  status="graduated"),
            3:
            self._attrDef.attribs(student_name="Frank Jeffrey",
                                  ssn="996-54-1211",
                                  degree="Bachelor of Arts, History",
                                  year="2013",
                                  status="dropped"),
            4:
            self._attrDef.attribs(student_name="Craig Richards",
                                  ssn="151-44-5876",
                                  degree="MBA, Finance",
                                  year="2015",
                                  status="graduated")
        }

        self._schema = SchemaKey("Transcript", "1.2", self.wallet.defaultId)
Example #20
0
 def getSchemaKeysToBeGenerated(self):
     return [
         SchemaKey("Job-Certificate", "0.2", self.wallet.defaultId),
         SchemaKey("Job-Application", "0.2", self.wallet.defaultId)
     ]
Example #21
0
 def getSchemaKeysToBeGenerated(self):
     return [SchemaKey("Transcript", "1.2", self.wallet.defaultId)]
Example #22
0
def testSchemaKeyFromToDict():
    schemaKey = SchemaKey(name='schemaName', version='1.0', issuerId='issuer1')
    assert schemaKey == SchemaKey.fromStrDict(schemaKey.toStrDict())