def __init__(self, basedirpath: str = None, client: Client = None, wallet: Wallet = None, port: int = None, loop=None, config=None): super().__init__('Faber College', basedirpath, client, wallet, port=port, loop=loop, config=config, endpointArgs=self.getEndpointArgs(wallet)) # maps invitation nonces to internal ids self._invites = { "b1134a647eb818069c089e7694f63e6d": 1, "2a2eb72eca8b404e8d412c5bf79f2640": 2, "7513d1397e87cada4214e2a650f603eb": 3, "710b78be79f29fc81335abaa4ee1c5e8": 4 } self._attrDef = AttribDef('Transcript', [ 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") }
def getAttributes(self, nonce): attrs = self._attributes.get(nonce) if not attrs: attrs = { "student_name": random.choice(randomData.NAMES), "ssn": random.choice(randomData.SSN), "degree": random.choice(randomData.DEGREE), "year": random.choice(randomData.YEAR), "status": random.choice(randomData.STATUS) } attribTypes = [] for name in attrs: attribTypes.append(AttribType(name, encode=True)) attribsDef = AttribDef("Transcript", attribTypes) attribs = attribsDef.attribs(**attrs) return attribs
def faberAddedAttributesForAlice(aliceAcceptedFaberInvitation, aliceCli, faberMap, faberIsRunning): faber, faberWallet = faberIsRunning aliceIdrForFaber = aliceCli.activeWallet.getLinkInvitationByTarget( faberMap['target']).verkey attrs = { "student_name": "Alice Garcia", "ssn": "123456789", "degree": "Bachelor of Science, Marketing", "year": "2015", "status": "graduated" } attribTypes = [] for name in attrs: attribTypes.append(AttribType(name, encode=True)) attribsDef = AttribDef("Transcript", attribTypes) attribs = attribsDef.attribs(**attrs) faber.attributeRepo.addAttributes(aliceIdrForFaber, attribs)
class ThriftAgent(BaseAgent): def __init__(self, basedirpath: str, client: Client = None, wallet: Wallet = None, port: int = None, loop=None, config=None): super().__init__('Thrift Bank', basedirpath, client, wallet, port=port, loop=loop, config=config, endpointArgs=self.getEndpointArgs(wallet)) # maps invitation nonces to internal ids self._invites = {"77fbf9dc8c8e6acde33de98c6d747b28c": 1} self._attrDef = AttribDef('Thrift', [ 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) ]) 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') } def getLinkNameByInternalId(self, internalId): return self._attrs[internalId]._vals["first_name"] async def postClaimVerif(self, claimName, link, frm): if claimName == "Loan-Application-Basic": self.notifyToRemoteCaller( EVENT_NOTIFY_MSG, " Loan eligibility criteria satisfied," " please send another claim " "'Loan-Application-KYC'\n", self.wallet.defaultId, frm) async def bootstrap(self): pass
def __init__(self, basedirpath: str, client: Client = None, wallet: Wallet = None, port: int = None, loop=None, config=None): super().__init__('Thrift Bank', basedirpath, client, wallet, port=port, loop=loop, config=config, endpointArgs=self.getEndpointArgs(wallet)) # maps invitation nonces to internal ids self._invites = {"77fbf9dc8c8e6acde33de98c6d747b28c": 1} self._attrDef = AttribDef('Thrift', [ 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) ]) 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') }
), cmod.integer( 151323892648373196579515752826519683836764873607632072057591837216698622729557534035138587276594156320800768525825023728398410073692081011811496168877166664537052088207068061172594879398773872352920912390983199416927388688319207946493810449203702100559271439586753256728900713990097168484829574000438573295723 )), "prime2": (cmod.integer( 150619677884468353208058156632953891431975271416620955614548039937246769610622017033385394658879484186852231469238992217246264205570458379437126692055331206248530723117202131739966737760399755490935589223401123762051823602343810554978803032803606907761937587101969193241921351011430750970746500680609001799529 ), cmod.integer( 171590857568436644992359347719703764048501078398666061921719064395827496970696879481740311141148273607392657321103691543916274965279072000206208571551864201305434022165176563363954921183576230072812635744629337290242954699427160362586102068962285076213200828451838142959637006048439307273563604553818326766703 )) } GVT = AttribDef('gvt', [ AttribType('name', encode=True), AttribType('age', encode=False), AttribType('height', encode=False), AttribType('sex', encode=True) ]) XYZCorp = AttribDef( 'xyz', [AttribType('status', encode=True), AttribType('period', encode=False)]) # NASEMP = GVT + XYZCorp # iA1 = 100 iA2 = 101 # proverId1 = 222 proverId2 = 333 # # verifierId1 = 555
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)
class AcmeAgent(TestWalletedAgent): 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) def _addAtrribute(self, schemaKey, proverId, link): attr = self._attrsJobCert[self.getInternalIdByInvitedNonce(proverId)] self.issuer._attrRepo.addAttributes(schemaKey=schemaKey, userId=proverId, attributes=attr) def getInternalIdByInvitedNonce(self, nonce): if nonce in self._invites: return self._invites[nonce] else: raise NonceNotFound def isClaimAvailable(self, link, claimName): return claimName == "Job-Certificate" and \ "Job-Application" in link.verifiedClaimProofs def getAvailableClaimList(self): return self.availableClaims async def postClaimVerif(self, claimName, link, frm): nac = await self.newAvailableClaimsPostClaimVerif(claimName) self.sendNewAvailableClaimsData(nac, frm, link) async def newAvailableClaimsPostClaimVerif(self, claimName): if claimName == "Job-Application": return await self.getJobCertAvailableClaimList() async def getJobCertAvailableClaimList(self): schema = await self.issuer.wallet.getSchema(ID(self._schemaJobCertKey)) return [{ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }] async def addSchemasToWallet(self): schemaJobCert = await self.issuer.genSchema( self._schemaJobCertKey.name, self._schemaJobCertKey.version, self._attrDefJobCert.attribNames(), 'CL') schemaJobCertId = ID(schemaKey=schemaJobCert.getKey(), schemaId=schemaJobCert.seqId) p_prime, q_prime = primes["prime1"] await self.issuer.genKeys(schemaJobCertId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(schemaId=schemaJobCertId, iA='110', L=5) async def bootstrap(self): await self.addSchemasToWallet()
def create_faber(name=None, wallet=None, base_dir_path=None, port=5555, client=None): if client is None: client = create_client(base_dir_path=base_dir_path, client_class=TestClient) endpoint_args = {'onlyListener': True} if wallet: endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed else: wallet = Wallet(name) wallet.addIdentifier(signer=FABER_SIGNER) endpoint_args['seed'] = FABER_SEED agent = WalletedAgent(name=name or "Faber College", basedirpath=base_dir_path, client=client, wallet=wallet, port=port, endpointArgs=endpoint_args) agent._invites = { "b1134a647eb818069c089e7694f63e6d": (1, "Alice"), "2a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"), "7513d1397e87cada4214e2a650f603eb": (3, "Frank"), "710b78be79f29fc81335abaa4ee1c5e8": (4, "Bob") } transcript_def = AttribDef('Transcript', [ AttribType('student_name', encode=True), AttribType('ssn', encode=True), AttribType('degree', encode=True), AttribType('year', encode=True), AttribType('status', encode=True) ]) agent.add_attribute_definition(transcript_def) backend = MockBackendSystem(transcript_def) backend.add_record(1, student_name="Alice Garcia", ssn="123-45-6789", degree="Bachelor of Science, Comp Sci", year="2015", status="graduated") backend.add_record(2, student_name="Carol Atkinson", ssn="783-41-2695", degree="Bachelor of Science, Physics", year="2012", status="graduated") backend.add_record(3, student_name="Frank Jeffrey", ssn="996-54-1211", degree="Bachelor of Arts, History", year="2013", status="dropped") backend.add_record(4, student_name="Bob Richards", ssn="151-44-5876", degree="MBA, Finance", year="2015", status="graduated") agent.set_issuer_backend(backend) return agent
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)
class FaberAgent(TestWalletedAgent): 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) def getInternalIdByInvitedNonce(self, nonce): if nonce in self._invites: return self._invites[nonce] else: raise NonceNotFound def isClaimAvailable(self, link, claimName): return claimName == "Transcript" def getAvailableClaimList(self): return self.availableClaims async def postClaimVerif(self, claimName, link, frm): pass async def initAvailableClaimList(self): schema = await self.issuer.wallet.getSchema(ID(self._schema)) self.availableClaims.append({ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }) def _addAtrribute(self, schemaKey, proverId, link): attr = self._attrs[self.getInternalIdByInvitedNonce(proverId)] self.issuer._attrRepo.addAttributes(schemaKey=schemaKey, userId=proverId, attributes=attr) async def addSchemasToWallet(self): schema = await self.issuer.genSchema(self._schema.name, self._schema.version, self._attrDef.attribNames(), 'CL') schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId) p_prime, q_prime = primes["prime2"] await self.issuer.genKeys(schemaId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) await self.initAvailableClaimList() async def bootstrap(self): await self.addSchemasToWallet()
def create_acme(name=None, wallet=None, base_dir_path=None, port=6666, client=None): if client is None: client = create_client(base_dir_path=None, client_class=TestClient) endpoint_args = {'onlyListener': True} if wallet: endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed else: wallet = Wallet(name) wallet.addIdentifier(signer=ACME_SIGNER) endpoint_args['seed'] = ACME_SEED agent = AcmeAgent(name=name or "Acme Corp", basedirpath=base_dir_path, client=client, wallet=wallet, port=port, endpointArgs=endpoint_args) # maps request nonces to internal ids agent._invites = { "57fbf9dc8c8e6acde33de98c6d747b28c": (1, "Alice"), "3a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"), "8513d1397e87cada4214e2a650f603eb": (3, "Frank"), "810b78be79f29fc81335abaa4ee1c5e8": (4, "Bob") } job_cert_def = AttribDef('Job-Certificate', [ AttribType('first_name', encode=True), AttribType('last_name', encode=True), AttribType('employee_status', encode=True), AttribType('experience', encode=True), AttribType('salary_bracket', encode=True) ]) job_appl_def = AttribDef('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) ]) agent.add_attribute_definition(job_cert_def) agent.add_attribute_definition(job_appl_def) backend = MockBackendSystem(job_cert_def) backend.add_record(1, first_name="Alice", last_name="Garcia", employee_status="Permanent", experience="3 years", salary_bracket="between $50,000 to $100,000") backend.add_record(2, first_name="Carol", last_name="Atkinson", employee_status="Permanent", experience="2 years", salary_bracket="between $60,000 to $90,000") backend.add_record(3, first_name="Frank", last_name="Jeffrey", employee_status="Temporary", experience="4 years", salary_bracket="between $40,000 to $80,000") backend.add_record(4, first_name="Bob", last_name="Richards", employee_status="On Contract", experience="3 years", salary_bracket="between $50,000 to $70,000") agent.set_issuer_backend(backend) agent._proofRequestsSchema = { "Job-Application-v0.2": { "name": "Job-Application", "version": "0.2", "attributes": { "first_name": "string", "last_name": "string", "phone_number": "string", "degree": "string", "status": "string", "ssn": "string" }, "verifiableAttributes": ["degree", "status", "ssn"] }, "Job-Application-v0.3": { "name": "Job-Application-2", "version": "0.3", "attributes": { "first_name": "string", "last_name": "string", "phone_number": "string", "degree": "string", "status": "string", "ssn": "string" }, "verifiableAttributes": ["degree", "status"] } } return agent
import pytest from anoncreds.protocol.issuer import Issuer from anoncreds.protocol.repo.attributes_repo import AttributeRepoInMemory from anoncreds.protocol.types import AttribType, AttribDef, Schema, ID from anoncreds.protocol.wallet.issuer_wallet import IssuerWalletInMemory from indy_client.anon_creds.indy_public_repo import IndyPublicRepo GVT = AttribDef('gvt', [ AttribType('name', encode=True), AttribType('age', encode=False), AttribType('height', encode=False), AttribType('sex', encode=True) ]) # We perform all tests twice: # - no revocation case (primary key only) # - revocation case (both primary and revocation keys) # There are two Schemas generated (one for each branch of tests) revoc_params = ['revocation', 'no_revocation'] @pytest.fixture(scope="module") def public_repo(steward, stewardWallet): return IndyPublicRepo(steward, stewardWallet) @pytest.fixture(scope="module") def public_repo_2(trustee, trusteeWallet): return IndyPublicRepo(trustee, trusteeWallet)
def __init__(self, basedirpath: str, client: Client = None, wallet: Wallet = None, port: int = None, loop=None, config=None): super().__init__('Acme Corp', basedirpath, client, wallet, port=port, loop=loop, config=config, endpointArgs=self.getEndpointArgs(wallet)) # maps invitation nonces to internal ids self._invites = { "57fbf9dc8c8e6acde33de98c6d747b28c": 1, "3a2eb72eca8b404e8d412c5bf79f2640": 2, "8513d1397e87cada4214e2a650f603eb": 3, "810b78be79f29fc81335abaa4ee1c5e8": 4 } self._attrDefJobCert = AttribDef('Job-Certificate', [ 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('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._attrs = { 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._proofRequestsSchema = { "Job-Application-v0.2": { "name": "Job-Application", "version": "0.2", "attributes": { "first_name": "string", "last_name": "string", "phone_number": "string", "degree": "string", "status": "string", "ssn": "string" }, "verifiableAttributes": ["degree", "status", "ssn"] } }
class AcmeAgent(BaseAgent): def __init__(self, basedirpath: str, client: Client = None, wallet: Wallet = None, port: int = None, loop=None, config=None): super().__init__('Acme Corp', basedirpath, client, wallet, port=port, loop=loop, config=config, endpointArgs=self.getEndpointArgs(wallet)) # maps invitation nonces to internal ids self._invites = { "57fbf9dc8c8e6acde33de98c6d747b28c": 1, "3a2eb72eca8b404e8d412c5bf79f2640": 2, "8513d1397e87cada4214e2a650f603eb": 3, "810b78be79f29fc81335abaa4ee1c5e8": 4 } self._attrDefJobCert = AttribDef('Job-Certificate', [ 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('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._attrs = { 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._proofRequestsSchema = { "Job-Application-v0.2": { "name": "Job-Application", "version": "0.2", "attributes": { "first_name": "string", "last_name": "string", "phone_number": "string", "degree": "string", "status": "string", "ssn": "string" }, "verifiableAttributes": ["degree", "status", "ssn"] } } def getAttrDefs(self): return [self._attrDefJobCert, self._attrDefJobApp] def getAttrs(self): return self._attrs def getLinkNameByInternalId(self, internalId): return self._attrs[internalId]._vals["first_name"] def getSchemaKeysToBeGenerated(self): return [ SchemaKey("Job-Certificate", "0.2", self.wallet.defaultId), SchemaKey("Job-Application", "0.2", self.wallet.defaultId) ] def getSchemaKeysForClaimsAvailableToAll(self): return [] async def postClaimVerif(self, claimName, link, frm): nac = await self.newAvailableClaimsPostClaimVerif(claimName) oldClaims = self.availableClaimsByIdentifier.get(link.remoteIdentifier) if not oldClaims: oldClaims = [] oldClaims.extend(nac) self.availableClaimsByIdentifier[link.remoteIdentifier] = oldClaims self.sendNewAvailableClaimsData(nac, frm, link) async def newAvailableClaimsPostClaimVerif(self, claimName): if claimName == "Job-Application": return await self.getNewAvailableClaimList("Job-Certificate") async def getNewAvailableClaimList(self, claimName): availClaims = [] for sk in [ sk for sk in self.getSchemaKeysToBeGenerated() if sk.name == claimName ]: schema = await self.issuer.wallet.getSchema(ID(sk)) availClaims.append({ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }) return availClaims
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)
class BulldogAgent(TestWalletedAgent): 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) def getInternalIdByInvitedNonce(self, nonce): if nonce in self._invites: return self._invites[nonce] else: raise NonceNotFound def isClaimAvailable(self, link, claimName): return claimName == 'Banking-Relationship' def getAvailableClaimList(self, requesterId): return self.availableClaims + \ self.requesterAvailClaims.get(requesterId, []) async def postClaimVerif(self, claimName, link, frm): pass async def initAvailableClaimList(self): schema = await self.issuer.wallet.getSchema(ID(self._schemaKey)) self.availableClaims.append({ NAME: schema.name, VERSION: schema.version, "schemaSeqNo": schema.seqId }) def _addAtrribute(self, schemaKey, proverId, link): attr = self._attrs[self.getInternalIdByInvitedNonce(proverId)] self.issuer._attrRepo.addAttributes(schemaKey=schemaKey, userId=proverId, attributes=attr) async def addSchemasToWallet(self): schema = await self.issuer.genSchema(self._schemaKey.name, self._schemaKey.version, self._attrDef.attribNames(), 'CL') schemaId = ID(schemaKey=schema.getKey(), schemaId=schema.seqId) p_prime, q_prime = primes["prime2"] await self.issuer.genKeys(schemaId, p_prime=p_prime, q_prime=q_prime) await self.issuer.issueAccumulator(schemaId=schemaId, iA='110', L=5) await self.initAvailableClaimList() async def bootstrap(self): await self.addSchemasToWallet()