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()
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()
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()