def nymsAddedInQuickSuccession(nodeSet, addedSponsor, looper, sponsor, sponsorWallet): usigner = SimpleSigner() nym = usigner.verkey idy = Identity(identifier=nym) sponsorWallet.addSponsoredIdentity(idy) # Creating a NYM request with same nym again req = idy.ledgerRequest() sponsorWallet._pending.appendleft((req, idy.identifier)) reqs = sponsorWallet.preparePending() sponsor.submitReqs(*reqs) def check(): assert sponsorWallet._sponsored[nym].seqNo looper.run(eventually(check, timeout=2)) looper.run( eventually(checkNacks, sponsor, req.reqId, "is already added", retryWait=1, timeout=15)) count = 0 for node in nodeSet: txns = node.domainLedger.getAllTxn() for seq, txn in txns.items(): if txn[TXN_TYPE] == NYM and txn[TARGET_NYM] == usigner.identifier: count += 1 assert (count == len(nodeSet))
def _addNym(self, nym, role, other_client_name=None): idy = Identity(nym, role=role) requestMade = False try: self.activeWallet.addSponsoredIdentity(idy) requestMade = True except Exception as e: if e.args[0] == 'identifier already added': pass else: raise e if requestMade: reqs = self.activeWallet.preparePending() req, = self.activeClient.submitReqs(*reqs) printStr = "Adding nym {}".format(nym) if other_client_name: printStr = printStr + " for " + other_client_name self.print(printStr) def out(reply, error, *args, **kwargs): self.print("Nym {} added".format(reply[TARGET_NYM]), Token.BoldBlue) self.looper.loop.call_later(.2, self._ensureReqCompleted, req.key, self.activeClient, out) else: self._printRequestAlreadyMade( extra=" Request made to add {}".format(nym)) return True
def _acceptInvite(self, msg): body, (frm, ha) = msg link = self.verifyAndGetLink(msg) if link: identifier = body.get(f.IDENTIFIER.nm) idy = Identity(identifier) try: pendingCount = self.wallet.addSponsoredIdentity(idy) logger.debug("pending request count {}".format(pendingCount)) alreadyAdded = False except Exception as e: if e.args[0] == 'identifier already added': alreadyAdded = True else: raise e def sendClaimList(reply=None, error=None): logger.debug("sent to sovrin {}".format(identifier)) resp = self.createAvailClaimListMsg( self.getAvailableClaimList()) self.signAndSendToCaller(resp, link.localIdentifier, frm) if alreadyAdded: sendClaimList() self.notifyToRemoteCaller(EVENT_NOTIFY_MSG, " Already accepted", link.verkey, frm) else: reqs = self.wallet.preparePending() logger.debug("pending requests {}".format(reqs)) # Assuming there was only one pending request logger.debug("sending to sovrin {}".format(reqs[0])) self._sendToSovrinAndDo(reqs[0], clbk=sendClaimList)
def createNym(looper, nym, creatorClient, creatorWallet: Wallet, role=None): idy = Identity(identifier=nym, role=role) creatorWallet.addSponsoredIdentity(idy) reqs = creatorWallet.preparePending() creatorClient.submitReqs(*reqs) def check(): assert creatorWallet._sponsored[nym].seqNo looper.run(eventually(check, timeout=2))
def _handleAcceptance(self, msg): body, (frm, ha) = msg link = self.verifyAndGetLink(msg) # TODO this is really kludgy code... needs refactoring # exception handling, separation of concerns, etc. if not link: return logger.debug("proceeding with link: {}".format(link.name)) identifier = body.get(f.IDENTIFIER.nm) verkey = body.get(VERKEY) idy = Identity(identifier, verkey=verkey) link.targetVerkey = verkey try: pendingCount = self.wallet.addSponsoredIdentity(idy) logger.debug("pending request count {}".format(pendingCount)) alreadyAdded = False except Exception as e: if e.args[0] in ['identifier already added']: alreadyAdded = True else: logger.warning("Exception raised while adding nym, " "error was: {}".format(e.args[0])) raise e def sendClaimList(reply=None, error=None): logger.debug("sent to sovrin {}".format(identifier)) resp = self.createAvailClaimListMsg( self.getAvailableClaimList(), alreadyAccepted=alreadyAdded) self.signAndSend(resp, link.localIdentifier, frm, origReqId=body.get(f.REQ_ID.nm)) if alreadyAdded: sendClaimList() logger.debug("already accepted, " "so directly sending available claims") self.agentLogger.info('Already added identifier [{}] in sovrin' .format(identifier)) # self.notifyToRemoteCaller(EVENT_NOTIFY_MSG, # " Already accepted", # link.verkey, frm) else: logger.debug( "not added to the ledger, so add nym to the ledger " "and then will send available claims") reqs = self.wallet.preparePending() # Assuming there was only one pending request logger.debug("sending to sovrin {}".format(reqs[0])) # Specifically for bulldog POC, need to think through # how to provide separate logging for each agent # anyhow this class should be implemented by each agent # so we might not even need to add it as a separate logic self.agentLogger.info('Creating identifier [{}] in sovrin' .format(identifier)) self._sendToSovrinAndDo(reqs[0], clbk=sendClaimList)
def fetchFullVerkeyFromSovrin(looper, senderWallet, senderClient, ownerWallet, idr): identity = Identity(identifier=idr) req = senderWallet.requestIdentity(identity, sender=senderWallet.defaultId) senderClient.submitReqs(req) def chk(): retrievedVerkey = senderWallet.getIdentity(idr).verkey assertEquality(retrievedVerkey, ownerWallet.getVerkey(idr)) checkFullVerkeySize(retrievedVerkey) looper.run(eventually(chk, retryWait=1, timeout=5))
def testRetrieveEmptyVerkey(didAddedWithoutVerkey, looper, sponsor, sponsorWallet, noKeyIdr): """{ type: GET_NYM, dest: <id1> }""" identity = Identity(identifier=noKeyIdr) req = sponsorWallet.requestIdentity(identity, sender=sponsorWallet.defaultId) sponsor.submitReqs(req) def chk(): assert sponsorWallet.getIdentity(noKeyIdr).verkey is None looper.run(eventually(chk, retryWait=1, timeout=5))
def _checkIfLinkIdentifierWrittenToSovrin(self, li: Link, availableClaims): identity = Identity(identifier=li.localIdentifier) req = self.wallet.requestIdentity(identity, sender=self.wallet.defaultId) # self.client.submitReqs(req) # self.notifyObservers("Synchronizing...") def getNymReply(reply, err, availableClaims, li): self.notifyObservers("Confirmed identifier written to Sovrin.") self.notifyEventListeners(EVENT_POST_ACCEPT_INVITE, availableClaims)
def verkeyFetched(didUpdatedWithVerkey, looper, sponsor, sponsorWallet, noKeyIdr, wallet): """{ type: GET_NYM, dest: <id1> }""" identity = Identity(identifier=noKeyIdr) req = sponsorWallet.requestIdentity(identity, sender=sponsorWallet.defaultId) sponsor.submitReqs(req) def chk(): assert sponsorWallet.getIdentity(noKeyIdr).verkey == wallet.getVerkey( noKeyIdr) looper.run(eventually(chk, retryWait=1, timeout=5))
def suspendRole(looper, actingClient, actingWallet, did): idy = Identity(identifier=did, role=None) if actingWallet.getSponsoredIdentity(did): actingWallet.updateSponsoredIdentity(idy) else: actingWallet.addSponsoredIdentity(idy) reqs = actingWallet.preparePending() actingClient.submitReqs(*reqs) def chk(): assert actingWallet.getSponsoredIdentity(did).seqNo is not None looper.run(eventually(chk, retryWait=1, timeout=5))
def addSponsoredIdentity(self, idy: Identity): assert isinstance(self, Wallet) if idy.role and idy.role not in (SPONSOR, STEWARD): raise AttributeError("invalid role: {}".format(idy.role)) if idy.identifier in self._sponsored: raise RuntimeError("identifier already added") self._sponsored[idy.identifier] = idy req = idy.ledgerRequest() if req: if not req.identifier: req.identifier = self.defaultId self.pendRequest(req, idy.identifier) return len(self._pending)
def updateSovrinIdrWithFullKey(looper, senderWallet, senderClient, ownerWallet, idr, fullKey): idy = Identity(identifier=idr, verkey=fullKey) senderWallet.updateSponsoredIdentity(idy) # TODO: What if the request fails, there must be some rollback mechanism assert senderWallet.getSponsoredIdentity(idr).seqNo is None reqs = senderWallet.preparePending() senderClient.submitReqs(*reqs) def chk(): assert senderWallet.getSponsoredIdentity(idr).seqNo is not None looper.run(eventually(chk, retryWait=1, timeout=5)) return ownerWallet
def _getNym(self, nym): identity = Identity(identifier=nym) req = self.activeWallet.requestIdentity( identity, sender=self.activeWallet.defaultId) self.activeClient.submitReqs(req) self.print("Getting nym {}".format(nym)) def getNymReply(reply, err, *args): self.print( "Transaction id for NYM {} is {}".format(nym, reply[TXN_ID]), Token.BoldBlue) self.looper.loop.call_later(.2, self._ensureReqCompleted, req.key, self.activeClient, getNymReply)
def testRetrieveAbbrvVerkey(didAddedWithAbbrvVerkey, looper, sponsor, sponsorWallet, wallet, abbrevIdr): """{ type: GET_NYM, dest: <id1> }""" identity = Identity(identifier=abbrevIdr) req = sponsorWallet.requestIdentity(identity, sender=sponsorWallet.defaultId) sponsor.submitReqs(req) def chk(): retrievedVerkey = sponsorWallet.getIdentity(abbrevIdr).verkey assertEquality(retrievedVerkey, wallet.getVerkey(abbrevIdr)) checkAbbrVerkeySize(retrievedVerkey) looper.run(eventually(chk, retryWait=1, timeout=5)) chkVerifyForRetrievedIdentity(wallet, sponsorWallet, abbrevIdr)
def getIdentity(self, identifier): identity = Identity(identifier=identifier) req = self.wallet.requestIdentity(identity, sender=self.wallet.defaultId) self.client.submitReqs(req) return req
def requestIdentity(self, identity: Identity, sender): # Used to get a nym from Sovrin self.knownIds[identity.identifier] = identity req = identity.getRequest(sender) if req: return self.prepReq(req)
def requestIdentity(self, identity: Identity, sender): self.knownIds[identity.identifier] = identity req = identity.getRequest(sender) if req: return self.prepReq(req)