Пример #1
0
def checkAcceptInvitation(emptyLooper,
                          nonce,
                          inviteeAgent: WalletedAgent,
                          inviterAgentAndWallet,
                          linkName):
    """
    Assumes link identified by linkName is already created
    """
    assert nonce
    inviterAgent, inviterWallet = inviterAgentAndWallet  # type: WalletedAgent, Wallet

    inviteeAgent.connectTo(linkName)
    inviteeAcceptanceLink = inviteeAgent.wallet.getLink(linkName,
                                                required=True)
    ensureAgentConnected(emptyLooper, inviteeAgent, inviteeAcceptanceLink)

    inviteeAgent.accept_invitation(linkName)
    internalId = inviterAgent.get_internal_id_by_nonce(nonce)

    def chk():
        assert inviteeAcceptanceLink.remoteEndPoint[1] == inviterAgent.endpoint.ha[1]
        assert inviteeAcceptanceLink.isAccepted

        link = inviterAgent.wallet.getLinkBy(internalId=internalId)
        assert link
        assert link.remoteIdentifier == inviteeAcceptanceLink.localIdentifier

    timeout = waits.expectedAcceptInvitation()
    emptyLooper.run(eventually(chk, timeout=timeout))
Пример #2
0
    def _(wallet, basedir=None):
        basedir = basedir or tdirWithPoolTxns
        _, port = genHa()
        _, clientPort = genHa()
        client = TestClient(randomString(6),
                            ha=("0.0.0.0", clientPort),
                            basedirpath=basedir)

        agent = WalletedAgent(name=wallet.name,
                              basedirpath=basedir,
                              client=client,
                              wallet=wallet,
                              port=port)

        return agent
Пример #3
0
    def __init__(self,
                 genesis_txns,
                 base_dir,
                 config=None,
                 loop=None,
                 steward: Steward = None):
        super().__init__(loop=loop)
        self.base_dir = base_dir
        self.genesis_txns = genesis_txns
        self.config = config or getConfig(self.base_dir)
        self._generate_genesis_files()
        self._steward = steward

        if steward is not None:
            self._steward_agent = WalletedAgent(
                name="steward1",
                basedirpath=self.base_dir,
                client=self.create_client(5005),
                wallet=steward.wallet,
                port=8781)
            self.add(self._steward_agent)
Пример #4
0
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=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=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, Marketing",
                       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
Пример #5
0
def test_merge_invitation():
    nonce = "12345"
    wallet1 = Wallet('wallet1')
    connection_1 = Connection('connection1')
    walleted_agent = WalletedAgent(name='wallet1')

    wallet1.addConnection(connection_1)
    walleted_agent.wallet = wallet1
    connection = walleted_agent._wallet.getConnection('connection1')
    assert len(connection.proofRequests) == 0
    request_data = {
        'connection-request': {
            NAME: 'connection1',
            NONCE: nonce
        },
        'proof-requests': [{
            NAME: 'proof1',
            VERSION: '1',
            ATTRIBUTES: {
                'att_key1': 'att_value1',
                'att_key2': 'att_value2'
            },
            VERIFIABLE_ATTRIBUTES: {
                'ver_att_key1': 'ver_att_value1'
            }
        }]
    }

    # test that a proof request with attributes can be merged into a connection
    # that already exists but has no proof requests.
    walleted_agent._merge_request(request_data)
    assert len(connection.proofRequests) == 1
    assert len(connection.proofRequests[0].attributes.keys()) == 2
    assert connection.proofRequests[0].attributes['att_key1'] == 'att_value1'

    request_data2 = {
        'connection-request': {
            NAME: 'connection1',
            NONCE: nonce
        },
        'proof-requests': [{
            NAME: 'proof1',
            VERSION: '1',
            ATTRIBUTES: {
                'att_key1': 'att_value1',
                'att_key2': 'att_value2',
                'att_key3': 'att_value3'
            },
            VERIFIABLE_ATTRIBUTES: {
                'ver_att_key1': 'ver_att_value1',
                'ver_att_key2': 'ver_att_value2'
            },
        }]
    }

    # test that additional attributes and verifiable attributes can be
    # merged into an already existing proof request
    walleted_agent._merge_request(request_data2)
    assert len(connection.proofRequests) == 1
    assert len(connection.proofRequests[0].attributes.keys()) == 3
    assert connection.proofRequests[0].attributes['att_key3'] == 'att_value3'
    assert len(connection.proofRequests[0].verifiableAttributes.keys()) == 2

    request_data3 = {
        'connection-request': {
            NAME: 'connection1',
            NONCE: nonce
        },
        'proof-requests': [{
            NAME: 'proof2',
            VERSION: '1',
            ATTRIBUTES: {
                'att_key1': 'att_value1',
                'att_key2': 'att_value2',
                'att_key3': 'att_value3'
            },
            VERIFIABLE_ATTRIBUTES: {
                'ver_att_key1': 'ver_att_value1',
                'ver_att_key2': 'ver_att_value2'
            },
        }]
    }

    # test that a second proof from the same connection can be merged
    walleted_agent._merge_request(request_data3)
    assert len(connection.proofRequests) == 2
    assert len(connection.proofRequests[1].attributes.keys()) == 3
    assert connection.proofRequests[1].attributes['att_key3'] == 'att_value3'
    assert len(connection.proofRequests[1].verifiableAttributes.keys()) == 2
Пример #6
0
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=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=SimpleSigner(seed=FABER_SEED))
        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, Marketing",
                       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