Exemplo n.º 1
0
def nymsAddedInQuickSuccession(looper, nodeSet, sdk_added_raw_attribute,
                               trustAnchor, trustAnchorWallet):
    usigner = DidSigner()
    nym = usigner.verkey
    idy = Identity(identifier=nym)
    trustAnchorWallet.addTrustAnchoredIdentity(idy)
    # Creating a NYM request with same nym again
    req = idy.ledgerRequest()
    trustAnchorWallet._pending.appendleft((req, idy.identifier))
    reqs = trustAnchorWallet.preparePending()
    trustAnchor.submitReqs(*reqs)

    def check():
        assert trustAnchorWallet._trustAnchored[nym].seqNo

    timeout = waits.expectedTransactionExecutionTime(len(nodeSet))
    looper.run(eventually(check, timeout=timeout))

    timeout = waits.expectedReqNAckQuorumTime()
    looper.run(eventually(checkNacks,
                          trustAnchor,
                          req.reqId,
                          "is already added",
                          retryWait=1, timeout=timeout))
    count = 0
    for node in nodeSet:
        for seq, txn in node.domainLedger.getAllTxn():
            if get_type(txn) == NYM and get_payload_data(txn)[TARGET_NYM] == usigner.identifier:
                count += 1

    assert (count == len(nodeSet))
Exemplo n.º 2
0
def nymsAddedInQuickSuccession(looper, nodeSet, sdk_added_raw_attribute,
                               trustAnchor, trustAnchorWallet):
    usigner = DidSigner()
    nym = usigner.verkey
    idy = Identity(identifier=nym)
    trustAnchorWallet.addTrustAnchoredIdentity(idy)
    # Creating a NYM request with same nym again
    req = idy.ledgerRequest()
    trustAnchorWallet._pending.appendleft((req, idy.identifier))
    reqs = trustAnchorWallet.preparePending()
    trustAnchor.submitReqs(*reqs)

    def check():
        assert trustAnchorWallet._trustAnchored[nym].seqNo

    timeout = waits.expectedTransactionExecutionTime(len(nodeSet))
    looper.run(eventually(check, timeout=timeout))

    timeout = waits.expectedReqNAckQuorumTime()
    looper.run(
        eventually(checkNacks,
                   trustAnchor,
                   req.reqId,
                   "is already added",
                   retryWait=1,
                   timeout=timeout))
    count = 0
    for node in nodeSet:
        for seq, txn in node.domainLedger.getAllTxn():
            if txn[TXN_TYPE] == NYM and txn[TARGET_NYM] == usigner.identifier:
                count += 1

    assert (count == len(nodeSet))
 def new_identity():
     wallet = Wallet(randomString(5))
     signer = DidSigner()
     new_idr, _ = wallet.addIdentifier(signer=signer)
     verkey = wallet.getVerkey(new_idr)
     idy = Identity(identifier=new_idr, verkey=verkey, role=None)
     return idy, wallet
Exemplo n.º 4
0
    def sync(self, linkName, doneCallback=None):
        if not self.client.isReady():
            raise NotConnectedToNetwork
        link = self.wallet.getConnection(linkName, required=True)
        identifier = link.remoteIdentifier
        identity = Identity(identifier=identifier)
        req = self.wallet.requestIdentity(identity,
                                          sender=self.wallet.defaultId)

        self.client.submitReqs(req)

        self.loop.call_later(.2, ensureReqCompleted, self.loop,
                             (req.identifier, req.reqId), self.client,
                             self._handleSyncResp(link, None))

        attrib = Attribute(name=ENDPOINT,
                           value=None,
                           dest=identifier,
                           ledgerStore=LedgerStore.RAW)

        req = self.wallet.requestAttribute(attrib,
                                           sender=self.wallet.defaultId)
        self.client.submitReqs(req)

        self.loop.call_later(.2, ensureReqCompleted, self.loop,
                             (req.identifier, req.reqId), self.client,
                             self._handleSyncResp(link, doneCallback))
Exemplo n.º 5
0
def sendRandomRequests(wallet: Wallet, client: Client, count: int):
    print('{} random requests will be sent'.format(count))
    for i in range(count):
        idr, signer = wallet.addIdentifier()
        idy = Identity(identifier=idr, verkey=signer.verkey)
        wallet.addTrustAnchoredIdentity(idy)
    reqs = wallet.preparePending()
    return client.submitReqs(*reqs)[0]
Exemplo n.º 6
0
    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 connection: {}".format(link.name))
        identifier = body.get(f.IDENTIFIER.nm)
        verkey = body.get(VERKEY)
        idy = Identity(identifier, verkey=verkey)
        link.remoteVerkey = verkey
        try:
            pendingCount = self.wallet.addTrustAnchoredIdentity(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 send_claims(reply=None, error=None):
            return self.sendClaimList(link=link,
                                      alreadyAdded=alreadyAdded,
                                      sender=frm,
                                      reqId=body.get(f.REQ_ID.nm),
                                      reply=reply,
                                      error=error)

        if alreadyAdded:
            send_claims()
            logger.debug("already accepted, "
                         "so directly sending available claims")
            self.logger.info(
                'Already added identifier [{}] in indy'.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 indy {}".format(reqs[0]))
            # 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.logger.info(
                'Creating identifier [{}] in indy'.format(identifier))
            self._sendToIndyAndDo(reqs[0], clbk=send_claims)
Exemplo n.º 7
0
def fetchFullVerkeyFromIndy(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)

    timeout = plenumWaits.expectedReqAckQuorumTime()
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
Exemplo n.º 8
0
def updateIndyIdrWithVerkey(looper, senderWallet, senderClient, idr, fullKey):
    idy = Identity(identifier=idr, verkey=fullKey)
    senderWallet.updateTrustAnchoredIdentity(idy)
    # TODO: What if the request fails, there must be some rollback mechanism
    assert senderWallet.getTrustAnchoredIdentity(idr).seqNo is None
    reqs = senderWallet.preparePending()
    senderClient.submitReqs(*reqs)

    def chk():
        assert senderWallet.getTrustAnchoredIdentity(idr).seqNo is not None

    timeout = plenumWaits.expectedReqAckQuorumTime()
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
Exemplo n.º 9
0
def testRetrieveEmptyVerkey(didAddedWithoutVerkey, looper, trustAnchor,
                            trustAnchorWallet, noKeyIdr):
    """{ type: GET_NYM, dest: <id1> }"""
    identity = Identity(identifier=noKeyIdr)
    req = trustAnchorWallet.requestIdentity(identity,
                                            sender=trustAnchorWallet.defaultId)
    trustAnchor.submitReqs(req)

    def chk():
        assert trustAnchorWallet.getIdentity(noKeyIdr).verkey is None

    timeout = plenumWaits.expectedReqAckQuorumTime()
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
Exemplo n.º 10
0
def verkeyFetched(didUpdatedWithVerkey, looper, trustAnchor, trustAnchorWallet,
                  noKeyIdr, wallet):
    """{ type: GET_NYM, dest: <id1> }"""
    identity = Identity(identifier=noKeyIdr)
    req = trustAnchorWallet.requestIdentity(identity,
                                            sender=trustAnchorWallet.defaultId)
    trustAnchor.submitReqs(req)

    def chk():
        assert trustAnchorWallet.getIdentity(
            noKeyIdr).verkey == wallet.getVerkey(noKeyIdr)

    timeout = plenumWaits.expectedReqAckQuorumTime()
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
Exemplo n.º 11
0
def createNym(looper, nym, creatorClient, creatorWallet: Wallet, role=None,
              verkey=None):
    idy = Identity(identifier=nym,
                   verkey=verkey,
                   role=role)
    creatorWallet.addTrustAnchoredIdentity(idy)
    reqs = creatorWallet.preparePending()
    creatorClient.submitReqs(*reqs)

    def check():
        assert creatorWallet._trustAnchored[nym].seqNo

    timeout = waits.expectedTransactionExecutionTime(
        len(creatorClient.nodeReg)
    )
    looper.run(eventually(check, retryWait=1, timeout=timeout))
Exemplo n.º 12
0
def testRetrieveAbbrvVerkey(didAddedWithAbbrvVerkey, looper, trustAnchor,
                            trustAnchorWallet, wallet, abbrevIdr):
    """{ type: GET_NYM, dest: <id1> }"""
    identity = Identity(identifier=abbrevIdr)
    req = trustAnchorWallet.requestIdentity(identity,
                                            sender=trustAnchorWallet.defaultId)
    trustAnchor.submitReqs(req)

    def chk():
        retrievedVerkey = trustAnchorWallet.getIdentity(abbrevIdr).verkey
        assertEquality(retrievedVerkey, wallet.getVerkey(abbrevIdr))
        checkAbbrVerkeySize(retrievedVerkey)

    timeout = plenumWaits.expectedReqAckQuorumTime()
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
    chkVerifyForRetrievedIdentity(wallet, trustAnchorWallet, abbrevIdr)
Exemplo n.º 13
0
def demo_start_agent(base_dir, create_func, bootstrap_func, client, looper,
                     steward):
    looper.runFor(2)
    agent = create_func(base_dir_path=base_dir, client=client)

    steward.publish_trust_anchor(
        Identity(identifier=agent.wallet.defaultId,
                 verkey=agent.wallet.getVerkey(agent.wallet.defaultId),
                 role=TRUST_ANCHOR))
    looper.runFor(4)

    raw = '{"endpoint": {"ha": "127.0.0.1:' + str(agent.port) + '"}}'
    endpointAttrib = agent.wallet.build_attrib(agent.wallet.defaultId, raw=raw)
    agent.publish_trust_anchor_attribute(endpointAttrib)

    looper.runFor(4)

    looper.add(agent)

    looper.runFor(2)

    looper.run(bootstrap_func(agent))
Exemplo n.º 14
0
 def requestIdentity(self, identity: Identity, sender):
     # Used to get a nym from Indy
     self.knownIds[identity.identifier] = identity
     req = identity.getRequest(sender)
     if req:
         return self.prepReq(req)
Exemplo n.º 15
0
 def requestIdentity(self, identity: Identity, sender):
     # Used to get a nym from Indy
     self.knownIds[identity.identifier] = identity
     req = identity.getRequest(sender)
     if req:
         return self.prepReq(req)
Exemplo n.º 16
0
def test_end_to_end(tconf):
    base_dir = tconf.CLI_BASE_DIR

    print('*' * 20)
    print(base_dir)
    print('*' * 20)

    with create_local_pool(base_dir) as network:

        print(network.genesis_transactions)

        network.runFor(5)

        client = network.create_client(5555)

        bank_wallet = Wallet()
        bank_agent = RefAgent(name="bank",
                              basedirpath=base_dir,
                              client=client,
                              wallet=bank_wallet,
                              port=8787,
                              endpointArgs={'seed': BANK_SEED,
                                            'onlyListener': True})

        network.add(bank_agent)

        bank_id, bank_verkey = bank_agent.new_identifier(seed=BANK_SEED)

        print(bank_id)
        print(bank_verkey)

        s1_agent = network.steward_agent()

        s1_agent.publish_trust_anchor(Identity(identifier=bank_id,
                                               verkey=bank_verkey,
                                               role=TRUST_ANCHOR))
        network.runFor(5)

        # this allows calling asynchronous functions from a synchronous context
        run_async = network.run

        bank_attribute_definition = anoncreds.protocol.types.AttribDef(
            'basic', [
                anoncreds.protocol.types.AttribType(
                    'title', encode=True), anoncreds.protocol.types.AttribType(
                    'first_name', encode=True), anoncreds.protocol.types.AttribType(
                    'last_name', encode=True), anoncreds.protocol.types.AttribType(
                        'address_1', encode=True), anoncreds.protocol.types.AttribType(
                            'address_2', encode=True), anoncreds.protocol.types.AttribType(
                                'address_3', encode=True), anoncreds.protocol.types.AttribType(
                                    'postcode_zip', encode=True), anoncreds.protocol.types.AttribType(
                                        'date_of_birth', encode=True), anoncreds.protocol.types.AttribType(
                                            'account_type', encode=True), anoncreds.protocol.types.AttribType(
                                                'year_opened', encode=True), anoncreds.protocol.types.AttribType(
                                                    'account_status', encode=True)])

        bank_agent.add_attribute_definition(bank_attribute_definition)

        backend = MockBackendSystem(bank_attribute_definition)

        alices_id_in_banks_system = 1999891343
        bobs_id_in_banks_system = 2911891343

        backend.add_record(alices_id_in_banks_system,
                           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')
        backend.add_record(bobs_id_in_banks_system,
                           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')

        bank_agent.set_issuer_backend(backend)

        schema_id = run_async(
            bank_agent.publish_schema('basic',
                                      schema_name='Bank Membership',
                                      schema_version='1.0'))

        # NOTE: do NOT use known primes in a non-test environment

        issuer_pub_key, revocation_pub_key = run_async(
            bank_agent.publish_issuer_keys(schema_id,
                                           p_prime=primes["prime1"][0],
                                           q_prime=primes["prime1"][1]))
        print(issuer_pub_key)
        print(revocation_pub_key)

        # TODO: Not implemented yet
        # accPK = run_async(bank_agent.publish_revocation_registry(
        #     schema_id=schema_id))

        # print(accPK)

        run_async(bank_agent._set_available_claim_by_internal_id(
            alices_id_in_banks_system, schema_id))
        run_async(bank_agent._set_available_claim_by_internal_id(
            bobs_id_in_banks_system, schema_id))

        alice_wallet = Wallet()
        alice_agent = RefAgent(name="Alice",
                               basedirpath=base_dir,
                               client=client,
                               wallet=alice_wallet,
                               port=8786)

        network.add(alice_agent)

        network.runFor(1)

        request = bank_agent.create_connection_request(
            alices_id_in_banks_system, "Alice")

        # Transfer of this request happens out-of-band (website, QR code, etc)

        alices_link_to_bank = alice_agent.load_request_str(request)

        # notice the link is not accepted
        print(alices_link_to_bank)

        alice_agent.accept_request(alices_link_to_bank)

        network.runFor(10)

        # notice that the link is accepted
        print(alices_link_to_bank)

        banks_link_to_alice = bank_agent.get_link_by_name(
            alices_id_in_banks_system)

        # note the available claims are now there
        print(banks_link_to_alice)

        claim_to_request = alices_link_to_bank.find_available_claim(
            name='Bank Membership')

        print(claim_to_request)

        run_async(alice_agent.send_claim(alices_link_to_bank,
                                         claim_to_request))
        network.runFor(5)

        claim = run_async(alice_agent.get_claim(schema_id))
        print(claim)
Exemplo n.º 17
0
def sendSuspendRole(actingClient, actingWallet, did):
    idy = Identity(identifier=did, role=NULL)
    return sendIdentityRequest(actingClient, actingWallet, idy)
Exemplo n.º 18
0
def sendChangeVerkey(actingClient, actingWallet, idr, verkey):
    idy = Identity(identifier=idr, verkey=verkey)
    return sendIdentityRequest(actingClient, actingWallet, idy)
Exemplo n.º 19
0
        def makeRequest(cli, wallet):
            signer = newSigner()
            idy = Identity(identifier=signer.identifier, verkey=signer.verkey)

            wallet.addTrustAnchoredIdentity(idy)