Exemple #1
0
def step_impl(context, prover, presentation):
    # Open the presentation json file
    try:
        presentation_json_file = open('features/data/' + presentation +
                                      '.json')
        presentation_json = json.load(presentation_json_file)
        context.presentation = presentation_json["presentation"]

    except FileNotFoundError:
        print(FileNotFoundError + ': features/data/' + presentation + '.json')

    prover_url = context.prover_url

    if "presentation" in context:
        presentation = context.presentation

        if context.current_cred_format == "indy":
            # Find the cred ids and add the actual cred id into the presentation
            # TODO: There is probably a better way to get access to the specific requested attributes and predicates. Revisit this later.
            try:
                for i in range(
                        json.dumps(presentation["requested_attributes"]).count(
                            "cred_id")):
                    # Get the schema name from the loaded presentation for each requested attributes
                    cred_type_name = presentation["requested_attributes"][list(
                        presentation["requested_attributes"]
                    )[i]]["cred_type_name"]
                    presentation["requested_attributes"][list(
                        presentation["requested_attributes"]
                    )[i]]["cred_id"] = context.credential_id_dict[
                        cred_type_name][
                            len(context.credential_id_dict[cred_type_name]) -
                            1]
                    # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                    if ("timestamp"
                            in presentation["requested_attributes"][list(
                                presentation["requested_attributes"])[i]]):
                        relative_timestamp = presentation[
                            "requested_attributes"][list(
                                presentation["requested_attributes"])
                                                    [i]]["timestamp"]
                        presentation["requested_attributes"][list(
                            presentation["requested_attributes"]
                        )[i]]["timestamp"] = get_relative_timestamp_to_epoch(
                            relative_timestamp)
                    # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                    presentation["requested_attributes"][list(
                        presentation["requested_attributes"])[i]].pop(
                            "cred_type_name")
            except KeyError:
                pass

            try:
                for i in range(
                        json.dumps(presentation["requested_predicates"]).count(
                            "cred_id")):
                    # Get the schema name from the loaded presentation for each requested predicates
                    cred_type_name = presentation["requested_predicates"][list(
                        presentation["requested_predicates"]
                    )[i]]["cred_type_name"]
                    presentation["requested_predicates"][list(
                        presentation["requested_predicates"]
                    )[i]]["cred_id"] = context.credential_id_dict[
                        cred_type_name][
                            len(context.credential_id_dict[cred_type_name]) -
                            1]
                    # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                    if ("timestamp"
                            in presentation["requested_predicates"][list(
                                presentation["requested_predicates"])[i]]):
                        relative_timestamp = presentation[
                            "requested_predicates"][list(
                                presentation["requested_predicates"])
                                                    [i]]["timestamp"]
                        presentation["requested_predicates"][list(
                            presentation["requested_predicates"]
                        )[i]]["timestamp"] = get_relative_timestamp_to_epoch(
                            relative_timestamp)
                    # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                    presentation["requested_predicates"][list(
                        presentation["requested_predicates"])[i]].pop(
                            "cred_type_name")
            except KeyError:
                pass

        elif context.current_cred_format == "json-ld":
            # All good
            cred_type_name = presentation.get("cred_type_name")
            record_ids = presentation.get("record_ids", {})

            new_record_ids = {}
            for (input_descriptor_id, record_ids) in record_ids.items():
                new_record_ids[input_descriptor_id] = [
                    context.credential_id_dict[cred_type_name][-1]
                    for cred_type_name in record_ids
                ]

            presentation["record_ids"] = new_record_ids
        else:
            raise Exception(f"Unknown format {context.current_cred_format}")

        presentation["format"] = context.current_cred_format

    # if this is happening connectionless, then add the service decorator to the presentation
    if ('connectionless' in context) and (context.connectionless == True):
        presentation["~service"] = {
            "recipientKeys": [context.presentation_exchange_id],
            "routingKeys": None,
            "serviceEndpoint": context.verifier_url
        }

    (resp_status,
     resp_text) = agent_backchannel_POST(prover_url + "/agent/command/",
                                         "proof-v2",
                                         operation="send-presentation",
                                         id=context.presentation_thread_id,
                                         data=presentation)
    assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}'
    resp_json = json.loads(resp_text)
    assert resp_json["state"] == "presentation-sent"

    # check the state of the presentation from the verifier's perspective
    assert expected_agent_state(context.verifier_url, "proof-v2",
                                context.presentation_thread_id,
                                "presentation-received")
Exemple #2
0
def step_impl(context, prover):
    prover_url = context.prover_url

    if "presentation" in context:
        presentation = context.presentation
        # Find the cred ids and add the actual cred id into the presentation
        # TODO: There is probably a better way to get access to the specific requested attributes and predicates. Revisit this later.
        try:
            for i in range(json.dumps(presentation["requested_attributes"]).count("cred_id")):
                # Get the schema name from the loaded presentation for each requested attributes
                cred_type_name = presentation["requested_attributes"][list(presentation["requested_attributes"])[i]]["cred_type_name"]
                presentation["requested_attributes"][list(presentation["requested_attributes"])[i]]["cred_id"] = context.credential_id_dict[cred_type_name][len(context.credential_id_dict[cred_type_name])-1]
                # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                if ("timestamp" in presentation["requested_attributes"][list(presentation["requested_attributes"])[i]]):
                    relative_timestamp = presentation["requested_attributes"][list(presentation["requested_attributes"])[i]]["timestamp"]
                    presentation["requested_attributes"][list(presentation["requested_attributes"])[i]]["timestamp"] = get_relative_timestamp_to_epoch(relative_timestamp)
                # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                presentation["requested_attributes"][list(presentation["requested_attributes"])[i]].pop("cred_type_name")
        except KeyError:
            pass
        
        try:
            for i in range(json.dumps(presentation["requested_predicates"]).count("cred_id")):
                # Get the schema name from the loaded presentation for each requested predicates
                cred_type_name = presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["cred_type_name"]
                presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["cred_id"] = context.credential_id_dict[cred_type_name][len(context.credential_id_dict[cred_type_name])-1] 
                # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                if ("timestamp" in presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]):
                    relative_timestamp = presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["timestamp"]
                    presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["timestamp"] = get_relative_timestamp_to_epoch(relative_timestamp)
                # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                presentation["requested_predicates"][list(presentation["requested_predicates"])[i]].pop("cred_type_name")
        except KeyError:
            pass

    else:   
        presentation = {
            "comment": "This is a comment for the send presentation.",
            "requested_attributes": {
                "attr_1": {
                    "revealed": True,
                    "cred_id": context.credential_id_dict[context.schema['schema_name']][len(context.credential_id_dict[context.schema['schema_name']])-1]
                }
            }
        }

    # if this is happening connectionless, then add the service decorator to the presentation
    if ('connectionless' in context) and (context.connectionless == True):
        presentation["~service"] = {
                "recipientKeys": [
                    context.presentation_exchange_id
                ],
                "routingKeys": None,
                "serviceEndpoint": context.verifier_url
            }

    (resp_status, resp_text) = agent_backchannel_POST(prover_url + "/agent/command/", "proof", operation="send-presentation", id=context.presentation_thread_id, data=presentation)
    assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}'
    resp_json = json.loads(resp_text)
    assert resp_json["state"] == "presentation-sent"

    # check the state of the presentation from the verifier's perspective
    assert expected_agent_state(context.verifier_url, "proof", context.presentation_thread_id, "presentation-received", wait_time=60.0)
Exemple #3
0
def step_impl(context, prover, presentation):
    # Open the presentation json file
    try:
        presentation_json_file = open("features/data/" + presentation + ".json")
        presentation_json = json.load(presentation_json_file)
        context.presentation = presentation_json["presentation"]

    except FileNotFoundError:
        print(FileNotFoundError + ": features/data/" + presentation + ".json")

    prover_url = context.prover_url

    if context.presentation:
        presentation = context.presentation

        if context.current_cred_format == "indy":
            # Find the cred ids and add the actual cred id into the presentation
            try:
                for requested_attribute in presentation[
                    "requested_attributes"
                ].values():
                    cred_type_name = requested_attribute["cred_type_name"]
                    requested_attribute["cred_id"] = context.credential_id_dict[
                        cred_type_name
                    ][-1]

                    # Update timestamp in requested attribute
                    if "timestamp" in requested_attribute:
                        relative_timestamp = requested_attribute["timestamp"]
                        requested_attribute[
                            "timestamp"
                        ] = get_relative_timestamp_to_epoch(relative_timestamp)

                    # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                    requested_attribute.pop("cred_type_name")
            except KeyError:
                pass

            try:
                for requested_predicate in presentation[
                    "requested_predicates"
                ].values():
                    # Get the schema name from the loaded presentation for each requested predicates
                    cred_type_name = requested_predicate["cred_type_name"]
                    requested_predicate["cred_id"] = context.credential_id_dict[
                        cred_type_name
                    ][-1]

                    # Update timestamp in requested attribute
                    if "timestamp" in requested_predicate:
                        relative_timestamp = requested_predicate["timestamp"]
                        requested_predicate[
                            "timestamp"
                        ] = get_relative_timestamp_to_epoch(relative_timestamp)

                    # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                    requested_predicate.pop("cred_type_name")
            except KeyError:
                pass

        elif context.current_cred_format == "json-ld":
            # All good
            cred_type_name = presentation.get("cred_type_name")
            record_ids = presentation.get("record_ids", {})

            new_record_ids = {}
            for (input_descriptor_id, record_ids) in record_ids.items():
                new_record_ids[input_descriptor_id] = [
                    context.credential_id_dict[cred_type_name][-1]
                    for cred_type_name in record_ids
                ]

            presentation["record_ids"] = new_record_ids
        else:
            raise Exception(f"Unknown format {context.current_cred_format}")

        presentation["format"] = context.current_cred_format

    # if this is happening connectionless, then add the service decorator to the presentation
    if context.connectionless:
        presentation["~service"] = {
            "recipientKeys": [context.presentation_exchange_id],
            "routingKeys": None,
            "serviceEndpoint": context.verifier_url,
        }

    use_v3 = "PresentProofV3" in context.tags

    if use_v3:
        proof_endpoint = "proof-v3"
    else:
        proof_endpoint = "proof-v2"

    (resp_status, resp_text) = agent_backchannel_POST(
        prover_url + "/agent/command/",
        proof_endpoint,
        operation="send-presentation",
        id=context.presentation_thread_id,
        data=presentation,
    )
    assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}"
def step_impl(context, prover):
    prover_url = context.prover_url

    if context.presentation:
        presentation = context.presentation
        # Find the cred ids and add the actual cred id into the presentation
        # TODO: There is probably a better way to get access to the specific requested attributes and predicates. Revisit this later.
        try:
            for requested_attribute in presentation[
                    "requested_attributes"].values():
                # Get the schema name from the loaded presentation for each requested attributes
                cred_type_name = requested_attribute["cred_type_name"]
                requested_attribute["cred_id"] = context.credential_id_dict[
                    cred_type_name][-1]

                # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                if "timestamp" in requested_attribute:
                    relative_timestamp = requested_attribute["timestamp"]
                    requested_attribute[
                        "timestamp"] = get_relative_timestamp_to_epoch(
                            relative_timestamp)

                # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                requested_attribute.pop("cred_type_name")
        except KeyError:
            pass

        try:
            for requested_predicate in presentation[
                    "requested_predicates"].values():
                # Get the schema name from the loaded presentation for each requested predicates
                cred_type_name = requested_predicate["cred_type_name"]
                requested_predicate["cred_id"] = context.credential_id_dict[
                    cred_type_name][-1]

                # If there is a timestamp, calculate it from the instruction in the file. Can be 'now' or + - relative to now.
                if "timestamp" in requested_predicate:
                    relative_timestamp = requested_predicate["timestamp"]
                    requested_predicate[
                        "timestamp"] = get_relative_timestamp_to_epoch(
                            relative_timestamp)

                # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request.
                requested_predicate.pop("cred_type_name")
        except KeyError:
            pass

    else:
        presentation = {
            "comment": "This is a comment for the send presentation.",
            "requested_attributes": {
                "attr_1": {
                    "revealed":
                    True,
                    "cred_id":
                    context.credential_id_dict[context.schema["schema_name"]]
                    [-1],
                }
            },
        }

    # if this is happening connectionless, then add the service decorator to the presentation
    if context.connectionless:
        presentation["~service"] = {
            "recipientKeys": [context.presentation_exchange_id],
            "routingKeys": None,
            "serviceEndpoint": context.verifier_url,
        }

    (resp_status, resp_text) = agent_backchannel_POST(
        prover_url + "/agent/command/",
        "proof",
        operation="send-presentation",
        id=context.presentation_thread_id,
        data=presentation,
    )
    assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}"