async def test_accept_proof_request(mock_agent_controller: AcaPyClient):
    when(mock_agent_controller.present_proof_v1_0).send_presentation(
        ...).thenReturn(get(v10_presentation_exchange_records[0]))

    accepted_proof_request = await VerifierV1.accept_proof_request(
        mock_agent_controller,
        proof_request=AcceptProofRequest(
            proof_id="v1-123",
            presentation_spec=IndyPresSpec(
                requested_attributes={},
                requested_predicates={},
                self_attested_attributes={},
            ),
        ),
    )

    assert isinstance(accepted_proof_request, PresentationExchange)
Ejemplo n.º 2
0
async def test_get_schema_ids(mock_agent_controller: AcaPyClient):
    first_cred_record = IndyCredInfo(
        schema_id="NR6Y28AiZ893utPSfoQRrz:2:test_schema:0.3"
    )
    second_cred_record = IndyCredInfo(
        schema_id="NR6Y28AiZ893utPSfoQRrz:2:another_schema:0.3"
    )

    presentation = IndyPresSpec(
        self_attested_attributes={},
        requested_attributes={
            "group_name": IndyRequestedCredsRequestedAttr(
                revealed=False, cred_id="first-unrevealed-cred-id"
            ),
            "another_group_name": IndyRequestedCredsRequestedAttr(
                revealed=True, cred_id="first-revealed-cred-id"
            ),
        },
        requested_predicates={
            "pred_group_name": IndyRequestedCredsRequestedPred(
                cred_id="first-revealed-pred-cred-id"
            )
        },
    )

    with when(mock_agent_controller.credentials).get_record(
        credential_id="first-revealed-cred-id"
    ).thenReturn(get(first_cred_record)), when(
        mock_agent_controller.credentials
    ).get_record(
        credential_id="first-revealed-pred-cred-id"
    ).thenReturn(
        get(second_cred_record)
    ):
        got_schema_ids = await get_schema_ids(
            aries_controller=mock_agent_controller, presentation=presentation
        )

        assert_that(got_schema_ids).contains_only(
            "NR6Y28AiZ893utPSfoQRrz:2:test_schema:0.3",
            "NR6Y28AiZ893utPSfoQRrz:2:another_schema:0.3",
        )
Ejemplo n.º 3
0
async def test_assert_valid_prover_public_did(mock_agent_controller: AcaPyClient):

    pres_exchange = PresentationExchange(
        connection_id="3fa85f64-5717-4562-b3fc-2c963f66afa6",
        created_at="2021-09-15 13:49:47Z",
        proof_id="v1-abcd",
        presentation=None,
        presentation_request=indy_proof_request,
        role="prover",
        state="proposal-sent",
        protocol_version="v1",
        updated_at=None,
        verified="false",
    )
    conn_record = ConnRecord(
        connection_id=pres_exchange.connection_id, their_public_did="did:sov:123"
    )

    presentation = IndyPresSpec(
        self_attested_attributes={},
        requested_attributes={
            "group_name": IndyRequestedCredsRequestedAttr(
                revealed=False, cred_id="first-unrevealed-cred-id"
            ),
            "another_group_name": IndyRequestedCredsRequestedAttr(
                revealed=True, cred_id="first-revealed-cred-id"
            ),
        },
        requested_predicates={
            "pred_group_name": IndyRequestedCredsRequestedPred(
                cred_id="first-revealed-pred-cred-id"
            )
        },
    )

    prover = mock(Verifier)

    when(prover).get_proof_record(
        controller=mock_agent_controller, proof_id=pres_exchange.proof_id
    ).thenReturn(get(pres_exchange))
    when(mock_agent_controller.connection).get_connection(
        conn_id=pres_exchange.connection_id
    ).thenReturn(get(conn_record))

    with patch(
        "app.generic.verifier.verifier_utils.get_actor", return_value=actor
    ), patch(
        "app.generic.verifier.verifier_utils.get_schema_ids",
        return_value=["did:schema:123"],
    ), patch(
        "app.generic.verifier.verifier_utils.get_trust_registry_schemas",
        return_value=["did:schema:123"],
    ):
        # Should not throw
        await assert_valid_prover(
            aries_controller=mock_agent_controller,
            presentation=AcceptProofRequest(
                proof_id=pres_exchange.proof_id, presentation_spec=presentation
            ),
            prover=prover,
        )
Ejemplo n.º 4
0
        pres_request=None,
        role="prover",
        state="proposal-sent",
        thread_id=None,
        trace=None,
        updated_at=None,
        verified="false",
    ),
]


indy_pres_spec = IndyPresSpec(
    requested_attributes={
        "0_string_uuid": IndyRequestedCredsRequestedAttr(cred_id="0_string_uuid")
    },
    requested_predicates={
        "0_string_GE_uuid": IndyRequestedCredsRequestedPred(cred_id="0_string_GE_uuid")
    },
    self_attested_attributes={"sth": "sth_else"},
)


@pytest.mark.asyncio
async def test_are_valid_schemas():
    # schemas are valid
    schemas = {
        "schemas": [
            "NR6Y28AiZ893utPSfoQRrz:2:test_schema:0.3",
            "U8BpHgzm5H5WbmDqeQRnxh:2:test_schema:0.3",
            "WoWSMfxTHA14GR2FdJJcHk:2:test_schema:0.3",
        ]
Ejemplo n.º 5
0
async def test_accept_proof_request_v1(
    issue_credential_to_alice: CredentialExchange,
    alice_member_client: AsyncClient,
    acme_client: AsyncClient,
    acme_and_alice_connection: AcmeAliceConnect,
):
    response = await acme_client.post(
        BASE_PATH + "/send-request",
        json={
            "connection_id": acme_and_alice_connection["acme_connection_id"],
            "protocol_version": "v1",
            "proof_request": indy_proof_request.dict(),
        },
    )
    response.raise_for_status()
    acme_exchange = response.json()
    acme_proof_id = acme_exchange["proof_id"]

    assert check_webhook_state(
        client=alice_member_client,
        filter_map={"state": "request-received"},
        topic="proofs",
        max_duration=120,
    )
    proof_records_alice = await alice_member_client.get(BASE_PATH + "/proofs")
    alice_proof_id = proof_records_alice.json()[0]["proof_id"]

    requested_credentials = await alice_member_client.get(
        f"/generic/verifier/proofs/{alice_proof_id}/credentials")

    referent = requested_credentials.json()[0]["cred_info"]["referent"]
    indy_request_attrs = IndyRequestedCredsRequestedAttr(cred_id=referent,
                                                         revealed=True)
    proof_accept = AcceptProofRequest(
        proof_id=alice_proof_id,
        presentation_spec=IndyPresSpec(
            requested_attributes={"0_speed_uuid": indy_request_attrs},
            requested_predicates={},
            self_attested_attributes={},
        ),
    )

    response = await alice_member_client.post(
        BASE_PATH + "/accept-request",
        json=proof_accept.dict(),
    )
    assert check_webhook_state(
        client=alice_member_client,
        filter_map={
            "state": "done",
            "proof_id": alice_proof_id
        },
        topic="proofs",
        max_duration=120,
    )
    assert check_webhook_state(
        client=acme_client,
        filter_map={
            "state": "done",
            "proof_id": acme_proof_id
        },
        topic="proofs",
        max_duration=120,
    )

    result = response.json()

    pres_exchange_result = PresentationExchange(**result)
    assert isinstance(pres_exchange_result, PresentationExchange)
    assert response.status_code == 200
Ejemplo n.º 6
0
async def test_accept_proof_request_v2(
    issue_credential_to_alice: CredentialExchange,
    alice_member_client: AsyncClient,
    acme_client: AsyncClient,
    alice_tenant: Any,
    acme_tenant: Any,
    credential_definition_id: str,
    acme_and_alice_connection: AcmeAliceConnect,
):
    wait_for_event, _ = await start_listener(
        topic="proofs", wallet_id=alice_tenant["tenant_id"])

    response = await acme_client.post(
        BASE_PATH + "/send-request",
        json={
            "connection_id": acme_and_alice_connection["acme_connection_id"],
            "protocol_version": "v2",
            # Custom proof request because v2 doesn't support proof request without restrictions
            # see: https://github.com/hyperledger/aries-cloudagent-python/issues/1755
            "proof_request": {
                "name": "Proof Request",
                "version": "1.0.0",
                "requested_attributes": {
                    "0_speed_uuid": {
                        "name":
                        "speed",
                        "restrictions": [{
                            "cred_def_id":
                            credential_definition_id
                        }],
                    }
                },
                "requested_predicates": {},
            },
        },
    )
    response.raise_for_status()
    acme_exchange = response.json()
    acme_proof_id = acme_exchange["proof_id"]

    payload = await wait_for_event(
        filter_map={
            "state": "request-received",
            "connection_id": acme_and_alice_connection["alice_connection_id"],
        })

    alice_proof_id = payload["proof_id"]

    requested_credentials = await alice_member_client.get(
        f"/generic/verifier/proofs/{alice_proof_id}/credentials")

    referent = requested_credentials.json()[0]["cred_info"]["referent"]
    indy_request_attrs = IndyRequestedCredsRequestedAttr(cred_id=referent,
                                                         revealed=True)
    proof_accept = AcceptProofRequest(
        proof_id=alice_proof_id,
        presentation_spec=IndyPresSpec(
            requested_attributes={"0_speed_uuid": indy_request_attrs},
            requested_predicates={},
            self_attested_attributes={},
        ),
    )

    wait_for_event, _ = await start_listener(
        topic="proofs", wallet_id=acme_tenant["tenant_id"])

    response = await alice_member_client.post(
        BASE_PATH + "/accept-request",
        json=proof_accept.dict(),
    )

    await wait_for_event(filter_map={
        "proof_id": acme_proof_id,
        "state": "done",
        "verified": True
    })

    result = response.json()

    pres_exchange_result = PresentationExchange(**result)
    assert isinstance(pres_exchange_result, PresentationExchange)
    assert response.status_code == 200