コード例 #1
0
async def test_update_pairwise_metadata(test_suite: ServerTestSuite):
    inviter = test_suite.get_agent_params('agent1')
    invitee = test_suite.get_agent_params('agent2')

    # Get endpoints
    async with sirius_sdk.context(inviter['server_address'], inviter['credentials'], inviter['p2p']):
        inviter_endpoint_address = [e for e in await sirius_sdk.endpoints() if e.routing_keys == []][0].address
        connection_key = await sirius_sdk.Crypto.create_key()
        invitation = Invitation(label='Inviter', endpoint=inviter_endpoint_address, recipient_keys=[connection_key])
    async with sirius_sdk.context(invitee['server_address'], invitee['credentials'], invitee['p2p']):
        invitee_endpoint_address = [e for e in await sirius_sdk.endpoints() if e.routing_keys == []][0].address

    # Init Me
    async with sirius_sdk.context(inviter['server_address'], inviter['credentials'], inviter['p2p']):
        did, verkey = await sirius_sdk.DID.create_and_store_my_did()
        inviter_side = sirius_sdk.Pairwise.Me(did, verkey)
    async with sirius_sdk.context(invitee['server_address'], invitee['credentials'], invitee['p2p']):
        did, verkey = await sirius_sdk.DID.create_and_store_my_did()
        invitee_side = sirius_sdk.Pairwise.Me(did, verkey)
    # Manually set pairwise list
    async with sirius_sdk.context(inviter['server_address'], inviter['credentials'], inviter['p2p']):
        await sirius_sdk.DID.store_their_did(invitee_side.did, invitee_side.verkey)
        p = sirius_sdk.Pairwise(
            me=inviter_side,
            their=sirius_sdk.Pairwise.Their(
                invitee_side.did, 'Invitee', invitee_endpoint_address, invitee_side.verkey
            )
        )
        await sirius_sdk.PairwiseList.create(p)
    async with sirius_sdk.context(invitee['server_address'], invitee['credentials'], invitee['p2p']):
        await sirius_sdk.DID.store_their_did(inviter_side.did, inviter_side.verkey)
        p = sirius_sdk.Pairwise(
            me=invitee_side,
            their=sirius_sdk.Pairwise.Their(
                inviter_side.did, 'Inviter', inviter_endpoint_address, inviter_side.verkey
            )
        )
        await sirius_sdk.PairwiseList.create(p)

    await run_coroutines(
        run_inviter(
            inviter['server_address'], inviter['credentials'], inviter['p2p'], connection_key, inviter_side
        ),
        run_invitee(
            invitee['server_address'], invitee['credentials'], invitee['p2p'], invitation, 'Invitee', invitee_side
        )
    )

    # Check for Inviter
    async with sirius_sdk.context(inviter['server_address'], inviter['credentials'], inviter['p2p']):
        pairwise = await sirius_sdk.PairwiseList.load_for_did(invitee_side.did)
        assert pairwise.metadata != {}
        assert pairwise.metadata is not None

    # Check for Invitee
    async with sirius_sdk.context(invitee['server_address'], invitee['credentials'], invitee['p2p']):
        pairwise = await sirius_sdk.PairwiseList.load_for_did(inviter_side.did)
        assert pairwise.metadata != {}
        assert pairwise.metadata is not None
コード例 #2
0
async def test_issuer_back_compatibility(indy_agent: IndyAgent, test_suite: ServerTestSuite, agent1: sirius_sdk.Agent):
    issuer = agent1
    await issuer.open()
    try:
        endpoint_issuer = [e for e in issuer.endpoints if e.routing_keys == []][0].address
        did_issuer, verkey_issuer = await issuer.wallet.did.create_and_store_my_did()
        did_holder, verkey_holder = await indy_agent.create_and_store_my_did()
        pairwise_for_issuer = sirius_sdk.Pairwise(
            me=sirius_sdk.Pairwise.Me(did_issuer, verkey_issuer),
            their=sirius_sdk.Pairwise.Their(did_holder, 'Holder', indy_agent.endpoint['url'], verkey_holder)
        )
        pairwise_for_holder = sirius_sdk.Pairwise(
            me=sirius_sdk.Pairwise.Me(did_holder, verkey_holder),
            their=sirius_sdk.Pairwise.Their(did_issuer, 'Issuer', endpoint_issuer, verkey_issuer)
        )
        pairwise_for_issuer.their.netloc = pytest.old_agent_overlay_address.replace('http://', '')
        pairwise_for_holder.their.netloc = pytest.test_suite_overlay_address.replace('http://', '')
        await indy_agent.create_pairwise_statically(pairwise_for_holder)
        await issuer.wallet.did.store_their_did(did_holder, verkey_holder)
        await issuer.pairwise_list.ensure_exists(pairwise_for_issuer)

        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, anoncred_schema = await agent1.wallet.anoncreds.issuer_create_schema(
            did_issuer, schema_name, '1.0', ['attr1', 'attr2', 'attr3']
        )
        ledger = issuer.ledger('default')
        ok, resp = await issuer.wallet.ledger.write_nym(
            'default', 'Th7MpTaRZVRYnPiabds81Y', did_issuer, verkey_issuer, 'Issuer', NYMRole.TRUST_ANCHOR
        )
        assert ok is True
        ok, schema = await ledger.register_schema(schema=anoncred_schema, submitter_did=did_issuer)
        assert ok is True

        ok, cred_def = await ledger.register_cred_def(
            cred_def=CredentialDefinition(tag='TAG', schema=schema),
            submitter_did=did_issuer
        )
        assert ok is True
    finally:
        await issuer.close()

    issuer = test_suite.get_agent_params('agent1')
    cred_id = 'cred-id-' + uuid.uuid4().hex
    coro_issuer = run_issuer(
        issuer['server_address'], issuer['credentials'], issuer['p2p'],
        holder=pairwise_for_issuer,
        values={'attr1': 'Value-1', 'attr2': 567, 'attr3': 5.7},
        schema=schema, cred_def=cred_def, cred_id=cred_id
    )
    results = await run_coroutines(coro_issuer, timeout=60)
    assert len(results) == 1
    assert results[0] is True
コード例 #3
0
 async def runner():
     nonlocal pairwise
     # Theirs
     async with sirius_sdk.context(**their_context):
         metadata = await sirius_sdk.DID.get_my_did_with_meta(their_did)
         endpoints = await sirius_sdk.endpoints()
         their_endpoint = [e for e in endpoints if e.routing_keys == []][0]
         their = sirius_sdk.Pairwise.Their(their_did, 'Their',
                                           their_endpoint.address,
                                           metadata['verkey'])
     # Mine
     async with sirius_sdk.context(**my_context):
         already_exists = await sirius_sdk.PairwiseList.is_exists(their_did)
         metadata = await sirius_sdk.DID.get_my_did_with_meta(my_did)
         if already_exists:
             pairwise = await sirius_sdk.PairwiseList.load_for_did(their_did
                                                                   )
         else:
             pairwise = sirius_sdk.Pairwise(me=sirius_sdk.Pairwise.Me(
                 my_did, metadata['verkey']),
                                            their=their)
             await sirius_sdk.PairwiseList.create(pairwise)
コード例 #4
0
 async def runner():
     nonlocal pairwise
     # Theirs
     async with sirius_sdk.context(**their_context):
         did, verkey = await sirius_sdk.DID.create_and_store_my_did(
             seed=their_seed)
         endpoints = await sirius_sdk.endpoints()
         simple_endpoint = [e for e in endpoints if e.routing_keys == []][0]
         their = sirius_sdk.Pairwise.Their(did, 'Label',
                                           simple_endpoint.address, verkey)
     # Mine
     async with sirius_sdk.context(**my_context):
         already_exists = await sirius_sdk.PairwiseList.is_exists(their.did)
         if already_exists:
             pairwise = await sirius_sdk.PairwiseList.load_for_did(their.did
                                                                   )
         else:
             did, verkey = await sirius_sdk.DID.create_and_store_my_did(
                 seed=my_seed)
             pairwise = sirius_sdk.Pairwise(me=sirius_sdk.Pairwise.Me(
                 did, verkey),
                                            their=their)
             await sirius_sdk.PairwiseList.create(pairwise)
コード例 #5
0
async def test_holder_back_compatibility(indy_agent: IndyAgent,
                                         agent1: sirius_sdk.Agent,
                                         test_suite: ServerTestSuite,
                                         prover_master_secret_name: str):
    holder = agent1
    await holder.open()
    try:
        endpoint_holder = [
            e for e in holder.endpoints if e.routing_keys == []
        ][0].address
        did_issuer, verkey_issuer = await indy_agent.create_and_store_my_did()
        did_holder, verkey_holder = await holder.wallet.did.create_and_store_my_did(
        )
        pairwise_for_issuer = sirius_sdk.Pairwise(
            me=sirius_sdk.Pairwise.Me(did_issuer, verkey_issuer),
            their=sirius_sdk.Pairwise.Their(did_holder, 'Holder',
                                            endpoint_holder, verkey_holder))
        pairwise_for_holder = sirius_sdk.Pairwise(
            me=sirius_sdk.Pairwise.Me(did_holder, verkey_holder),
            their=sirius_sdk.Pairwise.Their(did_issuer, 'Issuer',
                                            indy_agent.endpoint['url'],
                                            verkey_issuer))
        pairwise_for_issuer.their.netloc = pytest.test_suite_overlay_address.replace(
            'http://', '')
        pairwise_for_holder.their.netloc = pytest.old_agent_overlay_address.replace(
            'http://', '')
        await indy_agent.create_pairwise_statically(pairwise_for_issuer)
        await holder.wallet.did.store_their_did(did_issuer, verkey_issuer)
        await holder.pairwise_list.ensure_exists(pairwise_for_holder)

        ok, resp = await agent1.wallet.ledger.write_nym(
            'default', 'Th7MpTaRZVRYnPiabds81Y', did_issuer, verkey_issuer,
            'Issuer', NYMRole.TRUST_ANCHOR)
        assert ok is True
        # Register schema
        schema_name = 'schema_' + uuid.uuid4().hex
        schema_id, schema = await indy_agent.register_schema(
            did_issuer, schema_name, '1.0', ['attr1', 'attr2', 'attr3'])
        cred_def_id, cred_def = await indy_agent.register_cred_def(
            did_issuer, schema_id, 'TAG')

        print('Prepare Holder')
        try:
            await holder.wallet.anoncreds.prover_create_master_secret(
                prover_master_secret_name)
        except AnoncredsMasterSecretDuplicateNameError:
            pass
    finally:
        await holder.close()

    holder = test_suite.get_agent_params('agent1')
    holder_secret_id = prover_master_secret_name
    cred_id = 'cred-id-' + uuid.uuid4().hex

    coro_issuer = run_issuer_indy_agent(
        indy_agent=indy_agent,
        cred_def_id=cred_def_id,
        cred_def=cred_def,
        values={
            'attr1': 'Value-1',
            'attr2': 567,
            'attr3': 5.7
        },
        their_did=pairwise_for_issuer.their.did,
        issuer_schema=schema,
        rev_reg_id=None,
        cred_id=cred_id)
    coro_holder = run_holder(holder['server_address'],
                             holder['credentials'],
                             holder['p2p'],
                             issuer=pairwise_for_holder,
                             master_secret_id=holder_secret_id)

    results = await run_coroutines(coro_issuer, coro_holder, timeout=60)
    assert len(results) == 2

    for res in results:
        if type(res) is tuple:
            ok, cred_id = res
        else:
            ok = res
        assert ok is True

    assert cred_id is not None
    async with sirius_sdk.context(holder['server_address'],
                                  holder['credentials'], holder['p2p']):
        cred = await sirius_sdk.AnonCreds.prover_get_credential(cred_id)
    assert cred