def executeWhenResponseRcvd(self, startTime, maxCheckForMillis, loop, reqId, respType, checkIfLinkExists, clbk, *args): if isMaxCheckTimeExpired(startTime, maxCheckForMillis): clbk( None, "No response received within specified time ({} mills). " "Retry the command and see if that works.\n". format(maxCheckForMillis)) else: found = False rcvdResponses = self.rcvdMsgStore.get(reqId) if rcvdResponses: for msg in rcvdResponses: body, frm = msg if body.get(TYPE) == respType: if checkIfLinkExists: identifier = body.get(IDENTIFIER) li = self._getLinkByTarget( getCryptonym(identifier)) linkCheckOk = li is not None else: linkCheckOk = True if linkCheckOk: found = True break if found: clbk(*args) else: loop.call_later(.2, self.executeWhenResponseRcvd, startTime, maxCheckForMillis, loop, reqId, respType, checkIfLinkExists, clbk, *args)
def handleProofStatusResponse(self, msg: Any): body, _ = msg data = body.get(DATA) identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(data)
def _handleAcceptInviteResponse(self, msg): body, _ = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: # TODO: Show seconds took to respond self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(" Trust established.") alreadyAccepted = body[DATA].get(ALREADY_ACCEPTED_FIELD) if alreadyAccepted: self.notifyMsgListener(" Already accepted.") else: self.notifyMsgListener(" DID created in Sovrin.") li.connection_status = constant.CONNECTION_STATUS_ACCEPTED rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] newAvailableClaims = self._getNewAvailableClaims( li, rcvdAvailableClaims) if newAvailableClaims: li.availableClaims.extend(newAvailableClaims) self.notifyMsgListener(" Available Claim(s): {}".format( ",".join([rc.get(NAME) for rc in rcvdAvailableClaims]))) try: self._checkIfLinkIdentifierWrittenToSovrin( li, newAvailableClaims) except NotConnectedToAny: self.notifyEventListeners( EVENT_NOT_CONNECTED_TO_ANY_ENV, msg="Cannot check if identifier is written to Sovrin.") else: self.notifyMsgListener("No matching connection found")
def _handleAcceptInviteResponse(self, msg): body, _ = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: # TODO: Show seconds took to respond self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(" Trust established.") alreadyAccepted = body[DATA].get(ALREADY_ACCEPTED_FIELD) if alreadyAccepted: self.notifyMsgListener(" Already accepted.") else: self.notifyMsgListener(" Identifier created in Sovrin.") li.linkStatus = constant.LINK_STATUS_ACCEPTED # li.targetVerkey = constant.TARGET_VER_KEY_SAME_AS_ID rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] newAvailableClaims = self._getNewAvailableClaims( li, rcvdAvailableClaims) if newAvailableClaims: li.availableClaims.extend(newAvailableClaims) self.notifyMsgListener(" Available Claim(s): {}".format( ",".join([n for n, _, _ in newAvailableClaims]))) self._checkIfLinkIdentifierWrittenToSovrin( li, newAvailableClaims) else: self.notifyMsgListener("No matching link found")
def executeWhenResponseRcvd(self, startTime, maxCheckForMillis, loop, reqId, respType, checkIfLinkExists, clbk, *args): if isMaxCheckTimeExpired(startTime, maxCheckForMillis): clbk( None, "No response received within specified time ({} mills). " "Retry the command and see if that works.\n".format( maxCheckForMillis)) else: found = False rcvdResponses = self.rcvdMsgStore.get(reqId) if rcvdResponses: for msg in rcvdResponses: body, frm = msg if body.get(TYPE) == respType: if checkIfLinkExists: identifier = body.get(IDENTIFIER) li = self._getLinkByTarget( getCryptonym(identifier)) linkCheckOk = li is not None else: linkCheckOk = True if linkCheckOk: found = True break if found: clbk(*args) else: loop.call_later(.2, self.executeWhenResponseRcvd, startTime, maxCheckForMillis, loop, reqId, respType, checkIfLinkExists, clbk, *args)
def sync(self, linkName, doneCallback=None): if not self.client.isReady(): raise NotConnectedToNetwork link = self.wallet.getLink(linkName, required=True) nym = getCryptonym(link.remoteIdentifier) # identity = Identity(identifier=nym) # req = self.wallet.requestIdentity(identity, # sender=self.wallet.defaultId) # self.client.submitReqs(req) # # if doneCallback: # self.loop.call_later(.2, # ensureReqCompleted, # self.loop, # req.key, # self.client, # self._handleSyncNymResp(link, doneCallback)) attrib = Attribute(name=ENDPOINT, value=None, dest=nym, ledgerStore=LedgerStore.RAW) req = self.wallet.requestAttribute(attrib, sender=self.wallet.defaultId) self.client.submitReqs(req) if doneCallback: self.loop.call_later(.2, ensureReqCompleted, self.loop, req.key, self.client, self._handleSyncResp(link, doneCallback))
def handleProofRequest(self, msg): body, _ = msg link = self._getLinkByTarget(getCryptonym(body.get(IDENTIFIER))) proofReqName = body.get(NAME) proofReqExist = False for request in link.proofRequests: if request.name == proofReqName: proofReqExist = True break self.notifyMsgListener( ' Proof request {} received from {}.\n'.format( proofReqName, link.name)) if not proofReqExist: link.proofRequests.append( ProofRequest( name=proofReqName, version=body.get(VERSION), attributes=body.get(ATTRIBUTES), verifiableAttributes=body.get(VERIFIABLE_ATTRIBUTES))) else: self.notifyMsgListener( ' Proof request {} already exist.\n'.format(proofReqName))
async def handleReqClaimResponse(self, msg): body, _ = msg issuerId = body.get(IDENTIFIER) claim = body[DATA] li = self._getLinkByTarget(getCryptonym(issuerId)) if li: schemaId = ID(schemaId=claim[SCHEMA_SEQ_NO]) schema = await self.prover.wallet.getSchema(schemaId) self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(' Received claim "{}".\n'.format( schema.name)) pk = await self.prover.wallet.getPublicKey(schemaId) claim_attributes = { k: ClaimAttributeValues.from_str_dict(v) for k, v in json.loads(claim[CLAIM_FIELD]).items() } claim_signature = Claims.from_str_dict(claim[f.SIG.nm], pk.N) await self.prover.processClaim(schemaId, claim_attributes, claim_signature) else: self.notifyMsgListener("No matching connection found")
def handleProofRequest(self, msg): body, _ = msg link = self._getLinkByTarget(getCryptonym(body.get(IDENTIFIER))) proofReqName = body.get(NAME) proofReqExist = False for request in link.proofRequests: if request.name == proofReqName: proofReqExist = True break self.notifyMsgListener(' Proof request {} received from {}.\n' .format(proofReqName, link.name)) if not proofReqExist: link.proofRequests.append( ProofRequest( name=proofReqName, version=body.get(VERSION), attributes=body.get(ATTRIBUTES), verifiableAttributes=body.get(VERIFIABLE_ATTRIBUTES) ) ) else: self.notifyMsgListener(' Proof request {} already exist.\n' .format(proofReqName))
def _handleAcceptInviteResponse(self, msg): body, _ = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: # TODO: Show seconds took to respond self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(" Trust established.") alreadyAccepted = body[DATA].get(ALREADY_ACCEPTED_FIELD) if alreadyAccepted: self.notifyMsgListener(" Already accepted.") else: self.notifyMsgListener(" DID created in Indy.") li.connection_status = constant.CONNECTION_STATUS_ACCEPTED rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] newAvailableClaims = self._getNewAvailableClaims( li, rcvdAvailableClaims) if newAvailableClaims: li.availableClaims.extend(newAvailableClaims) self.notifyMsgListener(" Available Claim(s): {}". format( ",".join([rc.get(NAME) for rc in rcvdAvailableClaims]))) try: self._checkIfLinkIdentifierWrittenToIndy( li, newAvailableClaims) except NotConnectedToAny: self.notifyEventListeners( EVENT_NOT_CONNECTED_TO_ANY_ENV, msg="Cannot check if identifier is written to Indy.") else: self.notifyMsgListener("No matching connection found")
def _handlePong(self, msg): body, (frm, ha) = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: self.notifyMsgListener(" Pong received.") else: self.notifyMsgListener(" Pong received from unknown endpoint.")
def _handleAvailableClaimsResponse(self, msg): body, _ = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] if len(rcvdAvailableClaims) > 0: self.notifyMsgListener(" Available Claim(s): {}". format( ",".join([rc.get(NAME) for rc in rcvdAvailableClaims]))) else: self.notifyMsgListener(" Available Claim(s): " "No available claims found")
def _handleAvailableClaimsResponse(self, msg): body, _ = msg identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] if len(rcvdAvailableClaims) > 0: self.notifyMsgListener(" Available Claim(s): {}".format( ",".join([rc.get(NAME) for rc in rcvdAvailableClaims]))) else: self.notifyMsgListener(" Available Claim(s): " "No available claims found")
def _handlePong(self, msg): body, (frm, ha) = msg identifier = body.get(IDENTIFIER) if identifier: li = self._getLinkByTarget(getCryptonym(identifier)) if li: self.logger.info('Pong received from %s', li.remoteIdentifier) self.notifyMsgListener(" Pong received.") else: self.notifyMsgListener(" Pong received from unknown endpoint.") else: self.notifyMsgListener(' Identifier is not yet set.')
def _handleAcceptInviteResponse(self, msg): body, (frm, ha) = msg isVerified = self._isVerified(body) if isVerified: identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: # TODO: Show seconds took to respond self.notifyObservers("Response from {}:".format(li.name)) self.notifyObservers(" Signature accepted.") self.notifyObservers(" Trust established.") alreadyAccepted = body[DATA].get(ALREADY_ACCEPTED_FIELD) if alreadyAccepted: self.notifyObservers(" Already accepted.") else: self.notifyObservers(" Identifier created in Sovrin.") availableClaims = [] for cl in body[DATA][CLAIMS_LIST_FIELD]: name, version, claimDefSeqNo = cl[NAME], cl[VERSION], \ cl['claimDefSeqNo'] claimDefKey = ClaimDefKey(name, version, claimDefSeqNo, li.remoteIdentifier) availableClaims.append(AvailableClaimData(claimDefKey)) if cl.get('definition', None): self.wallet.addClaimDef( ClaimDef(claimDefKey, cl['definition'])) else: # TODO: Go and get definition from Sovrin and store # it in wallet's claim def store raise NotImplementedError li.linkStatus = constant.LINK_STATUS_ACCEPTED li.targetVerkey = constant.TARGET_VER_KEY_SAME_AS_ID li.updateAvailableClaims(availableClaims) self.wallet.addLinkInvitation(li) if len(availableClaims) > 0: self.notifyObservers(" Available claims: {}".format( ",".join( [cl.claimDefKey.name for cl in availableClaims]))) self._syncLinkPostAvailableClaimsRcvd(li, availableClaims) else: self.notifyObservers("No matching link found")
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)) schemaId = ID(schemaId=claim[SCHEMA_SEQ_NO]) pk = await self.prover.wallet.getPublicKey(schemaId) claims = json.loads(claim[CLAIM_FIELD]) signature = Claims.from_str_dict(claim[CLAIMS_SIGNATURE_FIELD], pk.N) await self.prover.processClaim(schemaId, claims, signature) else: self.notifyMsgListener("No matching link found")
def handleProofRequest(self, msg): body, _ = msg link = self._getLinkByTarget(getCryptonym(body.get(IDENTIFIER))) proofRequest = body.get(PROOF_REQUEST_FIELD) proofRequest = ProofRequest.from_str_dict(proofRequest) proofReqExist = False for request in link.proofRequests: if request.name == proofRequest.name: proofReqExist = True break self.notifyMsgListener(' Proof request {} received from {}.\n' .format(proofRequest.name, link.name)) if not proofReqExist: link.proofRequests.append(proofRequest) else: self.notifyMsgListener(' Proof request {} already exist.\n' .format(proofRequest.name))
async def handleReqClaimResponse(self, msg): body, _ = msg issuerId = body.get(IDENTIFIER) claim = body[DATA] li = self._getLinkByTarget(getCryptonym(issuerId)) if li: schemaId = ID(schemaId=claim[SCHEMA_SEQ_NO]) schema = await self.prover.wallet.getSchema(schemaId) self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) self.notifyMsgListener(' Received claim "{}".\n'.format(schema.name)) pk = await self.prover.wallet.getPublicKey(schemaId) claim_attributes = {k: ClaimAttributeValues.from_str_dict(v) for k, v in json.loads(claim[CLAIM_FIELD]).items()} claim_signature = Claims.from_str_dict(claim[f.SIG.nm], pk.N) await self.prover.processClaim(schemaId, claim_attributes, claim_signature) else: self.notifyMsgListener("No matching link found")
def _handleNewAvailableClaimsDataResponse(self, msg): body, _ = msg isVerified = self.verifySignature(body) if isVerified: identifier = body.get(IDENTIFIER) li = self._getLinkByTarget(getCryptonym(identifier)) if li: self.notifyResponseFromMsg(li.name, body.get(f.REQ_ID.nm)) rcvdAvailableClaims = body[DATA][CLAIMS_LIST_FIELD] newAvailableClaims = self._getNewAvailableClaims( li, rcvdAvailableClaims) if newAvailableClaims: li.availableClaims.extend(newAvailableClaims) claimNames = ", ".join( [n for n, _, _ in newAvailableClaims]) self.notifyMsgListener( " Available Claim(s): {}\n".format(claimNames)) else: self.notifyMsgListener("No matching connection found")
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] claimDefKey = ClaimDefinitionKey(name, version, claimAuthor) claimDef = await self.prover.wallet.getClaimDef(ID(claimDefKey)) claimDefId = ID(claimDefKey=claimDefKey, claimDefId=claimDef.seqId) claim = Claims.fromStrDict(claim[CLAIM_FIELD]) await self.prover.processClaim(claimDefId, claim) else: self.notifyMsgListener("No matching link found")
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")
def handleProofRequest(self, msg): body, _ = msg link = self._getLinkByTarget(getCryptonym(body.get(IDENTIFIER))) proofRequest = body.get(PROOF_REQUEST_FIELD) proofRequest = ProofRequest.from_str_dict(proofRequest) proofReqExist = False for request in link.proofRequests: if request.name == proofRequest.name: proofReqExist = True break self.notifyMsgListener( ' Proof request {} received from {}.\n'.format( proofRequest.name, link.name)) if not proofReqExist: link.proofRequests.append(proofRequest) else: self.notifyMsgListener( ' Proof request {} already exist.\n'.format( proofRequest.name))
def _handleClaimAttrs(self, msg): body, (frm, ha) = msg isVerified = self._isVerified(body) if isVerified: self.notifyObservers("Signature accepted.") identifier = body.get(IDENTIFIER) claim = body[DATA] # for claim in body[CLAIMS_FIELD]: self.notifyObservers("Received {}.".format(claim[NAME])) li = self._getLinkByTarget(getCryptonym(identifier)) if li: name, version, claimDefSeqNo, idr = \ claim[NAME], claim[VERSION], \ claim['claimDefSeqNo'], claim[f.IDENTIFIER.nm] issuerKeys = {} # TODO: Need to decide how/where to get it attributes = claim['attributes'] # TODO: Need to finalize this rc = ReceivedClaim( ClaimDefKey(name, version, claimDefSeqNo, idr), issuerKeys, attributes) rc.dateOfIssue = datetime.now() li.updateReceivedClaims([rc]) self.wallet.addLinkInvitation(li) else: self.notifyObservers("No matching link found")