def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    # get the required revocation info from the last credential exchange
    cred_exchange = context.cred_exchange

    cred_exchange = agent_container_GET(
        agent["agent"], "/issue-credential-2.0/records/" + cred_exchange["cred_ex_id"]
    )
    context.cred_exchange = cred_exchange

    # revoke the credential
    agent_container_POST(
        agent["agent"],
        "/revocation/revoke",
        data={
            "rev_reg_id": cred_exchange["indy"]["rev_reg_id"],
            "cred_rev_id": cred_exchange["indy"]["cred_rev_id"],
            "publish": False,
            "connection_id": cred_exchange["cred_ex_record"]["connection_id"],
        },
    )

    # pause for a few seconds
    async_sleep(3.0)
def step_impl(context, issuer, holder, credential_data):
    # initiate a cred exchange with a json-ld credential
    agent = context.active_agents[issuer]
    holder_agent = context.active_agents[holder]

    offer_request = {
        "connection_id": agent["agent"].agent.connection_id,
        "filter": {
            "ld_proof": {
                "credential": {
                    "@context": [
                        "https://www.w3.org/2018/credentials/v1",
                        "https://w3id.org/citizenship/v1",
                    ],
                    "type": [
                        "VerifiableCredential",
                        "PermanentResident",
                    ],
                    "id":
                    "https://credential.example.com/residents/1234567890",
                    "issuer":
                    agent["agent"].agent.did,
                    "issuanceDate":
                    "2020-01-01T12:00:00Z",
                    "credentialSubject": {
                        "type": ["PermanentResident"],
                        # let the holder set this
                        # "id": holder_agent["agent"].agent.did,
                        "givenName": "ALICE",
                        "familyName": "SMITH",
                        "gender": "Female",
                        "birthCountry": "Bahamas",
                        "birthDate": "1958-07-17",
                    },
                },
                "options": {
                    "proofType": SIG_TYPE_BLS
                },
            }
        },
    }

    agent_container_POST(
        agent["agent"],
        "/issue-credential-2.0/send-offer",
        offer_request,
    )

    # TODO test for goodness
    pass
예제 #3
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    connection_id = agent["agent"].agent.connection_id

    # create rev_reg entry transaction
    created_txn = agent_container_POST(
        agent["agent"],
        f"/revocation/publish-revocations",
        data={
            "rrid2crid": {
                context.cred_exchange["indy"]["rev_reg_id"]:
                [context.cred_exchange["indy"]["cred_rev_id"]]
            }
        },
        params={
            "conn_id": connection_id,
            "create_transaction_for_endorser": "true",
        },
    )

    if agent["agent"].endorser_role and agent[
            "agent"].endorser_role == "author":
        assert created_txn["txn"]["state"] == "request_sent"
    else:
        assert created_txn["txn"]["state"] == "transaction_created"
    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["txn"]["transaction_id"]
예제 #4
0
def step_impl(context, agent_name, schema_name):
    agent = context.active_agents[agent_name]

    connection_id = agent["agent"].agent.connection_id

    # TODO for now assume there is a single schema; should find the schema based on the supplied name
    schemas = agent_container_GET(agent["agent"], "/schemas/created")
    assert len(schemas["schema_ids"]) == 1

    schema_id = schemas["schema_ids"][0]
    created_txn = agent_container_POST(
        agent["agent"],
        "/credential-definitions",
        data={
            "schema_id": schema_id,
            "tag": "test_cred_def_with_endorsement",
            "support_revocation": True,
            "revocation_registry_size": 1000,
        },
        params={
            "conn_id": connection_id,
            "create_transaction_for_endorser": "true"
        },
    )

    # assert goodness
    if agent["agent"].endorser_role and agent[
            "agent"].endorser_role == "author":
        assert created_txn["txn"]["state"] == "request_sent"
    else:
        assert created_txn["txn"]["state"] == "transaction_created"
    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["txn"]["transaction_id"]
def step_impl(context, holder):
    agent = context.active_agents[holder]

    # get the required revocation info from the last credential exchange
    cred_exchange = context.cred_exchange

    cred_exchange = agent_container_GET(
        agent["agent"],
        "/issue-credential-2.0/records/" + cred_exchange["cred_ex_id"])
    context.cred_exchange = cred_exchange
    print("rev_reg_id:", cred_exchange["indy"]["rev_reg_id"])
    print("cred_rev_id:", cred_exchange["indy"]["cred_rev_id"])
    print("connection_id:", cred_exchange["cred_ex_record"]["connection_id"])

    # revoke the credential
    revoke_status = agent_container_POST(
        agent["agent"],
        "/revocation/revoke",
        data={
            "rev_reg_id": cred_exchange["indy"]["rev_reg_id"],
            "cred_rev_id": cred_exchange["indy"]["cred_rev_id"],
            "publish": "Y",
            "connection_id": cred_exchange["cred_ex_record"]["connection_id"],
        },
    )

    # pause for a few seconds
    async_sleep(3.0)
예제 #6
0
def step_impl(context, agent_name, schema_name):
    agent = context.active_agents[agent_name]

    schema_info = read_schema_data(schema_name)
    connection_id = agent["agent"].agent.connection_id

    created_txn = agent_container_POST(
        agent["agent"],
        "/schemas",
        data=schema_info["schema"],
        params={
            "conn_id": connection_id,
            "create_transaction_for_endorser": "true"
        },
    )

    # assert goodness
    if agent["agent"].endorser_role and agent[
            "agent"].endorser_role == "author":
        assert created_txn["txn"]["state"] == "request_sent"
    else:
        assert created_txn["txn"]["state"] == "transaction_created"

    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["txn"]["transaction_id"]
예제 #7
0
def step_impl(context, agent_name, schema_name):
    agent = context.active_agents[agent_name]

    connection_id = agent["agent"].agent.connection_id

    # generate revocation registry transaction
    rev_reg = agent_container_POST(
        agent["agent"],
        "/revocation/create-registry",
        data={
            "credential_definition_id": context.cred_def_id,
            "max_cred_num": 1000
        },
        params={},
    )
    rev_reg_id = rev_reg["result"]["revoc_reg_id"]
    assert rev_reg_id is not None

    # update revocation registry
    agent_container_PATCH(
        agent["agent"],
        f"/revocation/registry/{rev_reg_id}",
        data={
            "tails_public_uri":
            f"http://host.docker.internal:6543/revocation/registry/{rev_reg_id}/tails-file"
        },
        params={},
    )

    # create rev_reg transaction
    created_txn = agent_container_POST(
        agent["agent"],
        f"/revocation/registry/{rev_reg_id}/definition",
        data={},
        params={
            "conn_id": connection_id,
            "create_transaction_for_endorser": "true",
        },
    )
    assert created_txn["txn"]["state"] == "transaction_created"
    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["txn"]["transaction_id"]
예제 #8
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]
    txn_id = context.txn_ids["AUTHOR"]

    async_sleep(1.0)
    txn = agent_container_GET(agent["agent"], "/transactions/" + txn_id)
    requested_txn = txn
    assert requested_txn["state"] == "transaction_endorsed"

    written_txn = agent_container_POST(agent["agent"],
                                       "/transactions/" + txn_id + "/write")

    assert written_txn["state"] == "transaction_acked"
def step_impl(context, issuer, schema_name):
    # create a "did:key" to use as issuer
    agent = context.active_agents[issuer]

    data = {"method": DID_METHOD_KEY, "options": {"key_type": KEY_TYPE_BLS}}
    new_did = agent_container_POST(
        agent["agent"],
        "/wallet/did/create",
        data=data,
    )
    agent["agent"].agent.did = new_did["result"]["did"]
    # TODO test for goodness
    pass
예제 #10
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    async_sleep(1.0)
    txns = agent_container_GET(agent["agent"], "/transactions")
    requested_txn = txns["results"][0]
    assert requested_txn["state"] == "transaction_endorsed"
    txn_id = requested_txn["_id"]

    written_txn = agent_container_POST(agent["agent"],
                                       "/transactions/" + txn_id + "/write")

    assert written_txn["state"] == "transaction_completed"
예제 #11
0
def step_impl(context, agent_name, did_role):
    agent = context.active_agents[agent_name]

    # create a new DID in the current wallet
    created_did = agent_container_POST(agent["agent"], "/wallet/did/create")

    # publish to the ledger with did_role
    registered_did = agent_container_register_did(
        agent["agent"],
        created_did["result"]["did"],
        created_did["result"]["verkey"],
        "ENDORSER" if did_role == "ENDORSER" else "",
    )

    # make the new did the wallet's public did
    created_did = agent_container_POST(
        agent["agent"],
        "/wallet/did/public",
        params={"did": created_did["result"]["did"]},
    )

    if not "public_dids" in context:
        context.public_dids = {}
    context.public_dids[did_role] = created_did["result"]["did"]
def step_impl(context, holder):
    # verify the holder has a w3c credential
    agent = context.active_agents[holder]

    for i in range(10):
        async_sleep(1.0)
        w3c_creds = agent_container_POST(
            agent["agent"],
            "/credentials/w3c",
            {},
        )
        if 0 < len(w3c_creds["results"]):
            return

    assert False
예제 #13
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    # current connection_id for the selected agent
    connection_id = agent["agent"].agent.connection_id
    endorser_did = context.public_dids["ENDORSER"]

    updated_connection = agent_container_POST(
        agent["agent"],
        "/transactions/" + connection_id + "/set-endorser-info",
        params={"endorser_did": endorser_did},
    )

    # assert goodness
    assert updated_connection["endorser_did"] == endorser_did
    async_sleep(1.0)
예제 #14
0
def step_impl(context, agent_name, connection_job_role):
    agent = context.active_agents[agent_name]

    # current connection_id for the selected agent
    connection_id = agent["agent"].agent.connection_id

    # set role for agent's connection
    print("Updating role for connection:", connection_id, connection_job_role)
    updated_connection = agent_container_POST(
        agent["agent"],
        "/transactions/" + connection_id + "/set-endorser-role",
        params={"transaction_my_job": connection_job_role},
    )

    # assert goodness
    assert updated_connection["transaction_my_job"] == connection_job_role
    async_sleep(1.0)
예제 #15
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    txns = {"results": []}
    i = 5
    while 0 == len(txns["results"]) and i > 0:
        async_sleep(1.0)
        txns = agent_container_GET(agent["agent"], "/transactions")
        i = i - 1
    requested_txn = txns["results"][0]
    assert requested_txn["state"] == "request_received"
    txn_id = requested_txn["_id"]

    endorsed_txn = agent_container_POST(agent["agent"],
                                        "/transactions/" + txn_id + "/endorse")

    assert endorsed_txn["state"] == "transaction_endorsed"
예제 #16
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    async_sleep(1.0)
    txn_id = context.txn_ids["AUTHOR"]

    data = read_json_data("expires_time.json")

    requested_txn = agent_container_POST(
        agent["agent"],
        "/transactions/create-request",
        data=data,
        params={"tran_id": txn_id},
    )

    # assert goodness
    assert requested_txn["state"] == "request_sent"
예제 #17
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    async_sleep(1.0)
    txn_id = context.txn_ids["AUTHOR"]
    connection_id = agent["agent"].agent.connection_id
    print("Requesting endorsement for connection:", connection_id)
    requested_txn = agent_container_POST(
        agent["agent"],
        "/transactions/create-request",
        params={
            "conn_id": connection_id,
            "tran_id": txn_id
        },
    )

    # assert goodness
    assert requested_txn["state"] == "request_sent"
예제 #18
0
def step_impl(context, agent_name, schema_name):
    agent = context.active_agents[agent_name]

    schema_info = read_schema_data(schema_name)
    endorser_did = context.public_dids["ENDORSER"]
    created_txn = agent_container_POST(
        agent["agent"],
        "/schemas",
        data=schema_info["schema"],
        params={
            "auto_endorse": "false",
            "endorser_did": endorser_did
        },
    )

    # assert goodness
    assert created_txn["state"] == "transaction_created"
    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["_id"]
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    connection_id = agent["agent"].agent.connection_id

    # create rev_reg entry transaction
    created_rev_reg = agent_container_POST(
        agent["agent"],
        f"/revocation/publish-revocations",
        data={
            "rrid2crid": {
                context.cred_exchange["indy"]["rev_reg_id"]: [
                    context.cred_exchange["indy"]["cred_rev_id"]
                ]
            }
        },
    )

    # check that rev reg entry was written
    assert "rrid2crid" in created_rev_reg
예제 #20
0
def step_impl(context, agent_name, schema_name):
    agent = context.active_agents[agent_name]

    connection_id = agent["agent"].agent.connection_id

    # generate revocation registry entry transaction
    # create rev_reg transaction
    created_txn = agent_container_POST(
        agent["agent"],
        f"/revocation/registry/{context.rev_reg_id}/entry",
        data={},
        params={
            "conn_id": connection_id,
            "create_transaction_for_endorser": "true",
        },
    )
    assert created_txn["txn"]["state"] == "transaction_created"
    if not "txn_ids" in context:
        context.txn_ids = {}
    context.txn_ids["AUTHOR"] = created_txn["txn"]["transaction_id"]
예제 #21
0
def step_impl(context, agent_name):
    agent = context.active_agents[agent_name]

    # find the transaction with state "request_received"
    txns = {"results": []}
    i = 5
    while 0 == len(txns["results"]) and i > 0:
        async_sleep(1.0)
        txns_queued = agent_container_GET(agent["agent"], "/transactions")
        for j in range(len(txns_queued["results"])):
            if txns_queued["results"][j]["state"] == "request_received":
                txns["results"].append(txns_queued["results"][j])
        i = i - 1
    requested_txn = txns["results"][0]
    assert requested_txn["state"] == "request_received"
    txn_id = requested_txn["transaction_id"]

    endorsed_txn = agent_container_POST(agent["agent"],
                                        "/transactions/" + txn_id + "/endorse")

    assert endorsed_txn["state"] == "transaction_endorsed"
def step_impl(context, verifier, request_for_proof, prover):
    agent = context.active_agents[verifier]
    prover_agent = context.active_agents[prover]

    proof_request_info = {
        "comment": "test proof request for json-ld",
        "connection_id": agent["agent"].agent.connection_id,
        "presentation_request": {
            "dif": {
                "options": {
                    "challenge": "3fa85f64-5717-4562-b3fc-2c963f66afa7",
                    "domain": "4jt78h47fh47",
                },
                "presentation_definition": {
                    "id": "32f54163-7166-48f1-93d8-ff217bdb0654",
                    "format": {"ldp_vp": {"proof_type": [SIG_TYPE_BLS]}},
                    "input_descriptors": [
                        {
                            "id": "citizenship_input_1",
                            "name": "EU Driver's License",
                            "schema": [
                                {
                                    "uri": "https://www.w3.org/2018/credentials#VerifiableCredential"
                                },
                                {
                                    "uri": "https://w3id.org/citizenship#PermanentResident"
                                },
                            ],
                            "constraints": {
                                "limit_disclosure": "required",
                                "is_holder": [
                                    {
                                        "directive": "required",
                                        "field_id": [
                                            "1f44d55f-f161-4938-a659-f8026467f126"
                                        ],
                                    }
                                ],
                                "fields": [
                                    {
                                        "id": "1f44d55f-f161-4938-a659-f8026467f126",
                                        "path": ["$.credentialSubject.familyName"],
                                        "purpose": "The claim must be from one of the specified person",
                                        "filter": {"const": "SMITH"},
                                    },
                                    {
                                        "path": ["$.credentialSubject.givenName"],
                                        "purpose": "The claim must be from one of the specified person",
                                    },
                                ],
                            },
                        }
                    ],
                },
            }
        },
    }

    proof_exchange = agent_container_POST(
        agent["agent"],
        "/present-proof-2.0/send-request",
        proof_request_info,
    )

    context.proof_request = proof_request_info
    context.proof_exchange = proof_exchange