def step_impl(context, holder, cred_format): holder_url = context.holder_url # # If @indy then we can be sure we cannot start the protocol from this command. We can be sure that we have previously # # reveived the thread_id. # if "Indy" in context.tags: # sleep(1) (resp_status, resp_text) = agent_backchannel_POST(holder_url + "/agent/command/", "issue-credential-v2", operation="send-request", id=context.cred_thread_id) # # If we are starting from here in the protocol you won't have the cred_ex_id or the thread_id # else: # (resp_status, resp_text) = agent_backchannel_POST(holder_url + "/agent/command/", "issue-credential-v2", operation="send-request", id=context.connection_id_dict[holder][context.issuer_name]) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) assert resp_json["state"] == "request-sent" # Verify issuer status assert expected_agent_state(context.issuer_url, "issue-credential-v2", context.cred_thread_id, "request-received")
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) if "credential_data" in context: cred_data = context.credential_data else: cred_data = CREDENTIAL_ATTR_TEMPLATE.copy() # a credential preview shouldn't have to be here with a cred_ex_id being passed credential_preview = { "credential_preview": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview", "attributes": cred_data, }, "comment": "issuing credential", } (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential", operation="issue", id=context.cred_thread_id, data=credential_preview) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) assert resp_json["state"] == "credential-issued" # Verify holder status assert expected_agent_state(context.holder_url, "issue-credential", context.cred_thread_id, "credential-received")
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) # if context does not have the credential thread id then the proposal was not the starting point for the protocol. if not "cred_thread_id" in context: if "credential_data" in context: cred_data = context.credential_data else: cred_data = CREDENTIAL_ATTR_TEMPLATE.copy() credential_offer = { "cred_def_id": context.issuer_credential_definition_dict[context.schema['schema_name']]["id"], "credential_preview": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview", "attributes": cred_data, }, "connection_id": context.connection_id_dict[issuer][context.holder_name], } (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential", operation="send-offer", data=credential_offer) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) context.cred_thread_id = resp_json["thread_id"] else: # If context has the credential thread id then the proposal was done. (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential", operation="send-offer", id=context.cred_thread_id) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) # Check the issuers State assert resp_json["state"] == "offer-sent" # Check the state of the holder after issuers call of send-offer assert expected_agent_state(context.holder_url, "issue-credential", context.cred_thread_id, "offer-received")
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")
def step_impl(context, verifier, request_for_proof, prover): try: request_for_proof_json_file = open('features/data/' + request_for_proof + '.json') request_for_proof_json = json.load(request_for_proof_json_file) context.request_for_proof = request_for_proof_json[ "presentation_proposal"] except FileNotFoundError: print(FileNotFoundError + ': features/data/' + request_for_proof + '.json') # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. if "request_for_proof" in context: data = context.request_for_proof if context.current_cred_format == "indy": if "non_revoked_timeframe" in context: data["non_revoked"] = context.non_revoked_timeframe[ "non_revoked"] elif context.current_cred_format == "json-ld": data = amend_presentation_definition_with_runtime_data( context, data) else: raise Exception( f"Unknown cred format {context.current_cred_format}") presentation_proposal = { "presentation_proposal": { "format": context.current_cred_format, "comment": "This is a comment for the request for presentation.", "data": data } } if ('connectionless' in context) and (context.connectionless == True): (resp_status, resp_text) = agent_backchannel_POST( context.verifier_url + "/agent/command/", "proof-v2", operation="create-send-connectionless-request", data=presentation_proposal) else: presentation_proposal["presentation_proposal"][ "connection_id"] = context.connection_id_dict[verifier][prover] # send presentation request (resp_status, resp_text) = agent_backchannel_POST( context.verifier_url + "/agent/command/", "proof-v2", operation="send-request", data=presentation_proposal) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) # check the state of the presentation from the verifiers perspective assert resp_json["state"] == "request-sent" # save off anything that is returned in the response to use later? context.presentation_thread_id = resp_json["thread_id"] # check the state of the presentation from the provers perspective # if the protocol is connectionless then don't do this, the prover has not recieved anything yet. if ('connectionless' not in context) or (context.connectionless == False): assert expected_agent_state(context.prover_url, "proof-v2", context.presentation_thread_id, "request-received") else: # save off the presentation exchange id for use when the prover sends the presentation with a service decorator context.presentation_exchange_id = resp_json[ "presentation_exchange_id"]
def step_impl(context, inviter): # get connection and verify status assert expected_agent_state( context.config.userdata.get(inviter), "connection", context.connection_id_dict[inviter][context.invitee_name], "complete")
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)
def step_impl(context, verifier, prover): # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. if "request_for_proof" in context: data = context.request_for_proof if "non_revoked_timeframe" in context: data["non_revoked"] = context.non_revoked_timeframe["non_revoked"] else: data = { "requested_attributes": { "attr_1": { "name": "attr_1", "restrictions": [ { "schema_name": "test_schema." + context.issuer_name, "schema_version": "1.0.0" } ] } } } if ('connectionless' in context) and (context.connectionless == True): presentation_proposal = { "presentation_proposal": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", "comment": "This is a comment for the request for presentation.", "request_presentations~attach": { "@id": "libindy-request-presentation-0", "mime-type": "application/json", "data": data } } } (resp_status, resp_text) = agent_backchannel_POST(context.verifier_url + "/agent/command/", "proof", operation="create-send-connectionless-request", data=presentation_proposal) else: presentation_proposal = { "connection_id": context.connection_id_dict[verifier][prover], "presentation_proposal": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", "comment": "This is a comment for the request for presentation.", "request_presentations~attach": { "@id": "libindy-request-presentation-0", "mime-type": "application/json", "data": data } } } # if ('connectionless' in context) and (context.connectionless == True): # resp_json = json.loads(resp_text) # presentation_proposal["~service"] = { # "recipientKeys": [ # resp_json["presentation_exchange_id"] # ], # "routingKeys": None, # "serviceEndpoint": context.verifier_url # } # send presentation request (resp_status, resp_text) = agent_backchannel_POST(context.verifier_url + "/agent/command/", "proof", operation="send-request", data=presentation_proposal) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) # check the state of the presentation from the verifiers perspective assert resp_json["state"] == "request-sent" # save off anything that is returned in the response to use later? context.presentation_thread_id = resp_json["thread_id"] # check the state of the presentation from the provers perspective # if the protocol is connectionless then don't do this, the prover has not recieved anything yet. if ('connectionless' not in context) or (context.connectionless == False): assert expected_agent_state(context.prover_url, "proof", context.presentation_thread_id, "request-received") else: # save off the presentation exchange id for use when the prover sends the presentation with a service decorator context.presentation_exchange_id = resp_json["presentation_exchange_id"]
def step_impl(context, prover): # check the state of the presentation from the prover's perspective assert expected_agent_state(context.prover_url, "proof-v2", context.presentation_thread_id, "done") # Check the status of the verification in the verify-presentation call. Should be True if 'credential_verification_dict' in context: assert context.credential_verification_dict[ context.presentation_thread_id] == "true" # @given('"{verifier}" and "{prover}" do not have a connection') # def step_impl(context, verifier, prover): # context.connectionless = True # @when('"{prover}" doesn’t want to reveal what was requested so makes a presentation proposal') # def step_impl(context, prover): # # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. # if "presentation_proposal" in context: # data = context.presentation_proposal # else: # data = { # "requested_attributes": [ # { # "name": "attr_2", # "cred_def_id": context.credential_definition_id_dict[context.schema["schema_name"]], # } # ] # } # if data.get("requested_attributes") == None: # requested_attributes = [] # else: # requested_attributes = data["requested_attributes"] # if data.get("requested_predicates") == None: # requested_predicates = [] # else: # requested_predicates = data["requested_predicates"] # presentation_proposal = { # "presentation_proposal": { # "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/presentation-preview", # "comment": "This is a comment for the presentation proposal.", # "requested_attributes": requested_attributes, # "requested_predicates": requested_predicates # } # } # if ('connectionless' not in context) or (context.connectionless != True): # presentation_proposal["connection_id"] = context.connection_id_dict[prover][context.verifier_name] # # send presentation proposal # (resp_status, resp_text) = agent_backchannel_POST(context.prover_url + "/agent/command/", "proof", operation="send-proposal", data=presentation_proposal) # assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # resp_json = json.loads(resp_text) # # check the state of the presentation from the verifiers perspective # assert resp_json["state"] == "proposal-sent" # # save off anything that is returned in the response to use later? # context.presentation_thread_id = resp_json["thread_id"] # # check the state of the presentation from the provers perspective # assert expected_agent_state(context.verifier_url, "proof", context.presentation_thread_id, "proposal-received") # @when(u'"{verifier}" agrees to continue so sends a request for proof presentation') # def step_impl(context, verifier): # # Construct the presentation request from the presention proposal. # # This should be removed in V2.0 since data is not required with a thread id. # data = { # "requested_attributes": { # "attr_2": { # "name": "attr_2", # "restrictions": [ # { # "schema_name": "test_schema." + context.issuer_name, # "schema_version": "1.0.0" # } # ] # } # } # } # presentation_request = { # "presentation_proposal": { # "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/present-proof/1.0/request-presentation", # "comment": "This is a comment for the request for presentation.", # "request_presentations~attach": { # "@id": "libindy-request-presentation-0", # "mime-type": "application/json", # "data": data # } # } # } # if ('connectionless' not in context) or (context.connectionless != True): # presentation_request["connection_id"] = context.connection_id_dict[verifier][context.prover_name] # # send presentation request # (resp_status, resp_text) = agent_backchannel_POST(context.verifier_url + "/agent/command/", "proof", operation="send-request", id=context.presentation_thread_id, data=presentation_request) # assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # resp_json = json.loads(resp_text) # # check the state of the presentation from the verifiers perspective # assert resp_json["state"] == "request-sent" # # save off anything that is returned in the response to use later? # #context.presentation_thread_id = resp_json["thread_id"] # # check the state of the presentation from the provers perspective # assert expected_agent_state(context.prover_url, "proof", context.presentation_thread_id, "request-received") # #assert present_proof_status(context.prover_url, context.presentation_thread_id, "request-received") # @when('"{prover}" doesn’t want to reveal what was requested so makes a {proposal}') # @when('"{prover}" makes a {proposal} to "{verifier}"') # def step_impl(context, prover, proposal, verifier=None): # try: # proposal_json_file = open('features/data/' + proposal + '.json') # proposal_json = json.load(proposal_json_file) # context.presentation_proposal = proposal_json["presentation_proposal"] # # replace the cred_def_id with the actual id based on the cred type name # try: # for i in range(json.dumps(context.presentation_proposal["requested_attributes"]).count("cred_def_id")): # # Get the cred type name from the loaded presentation for each requested attributes # cred_type_name = context.presentation_proposal["requested_attributes"][i]["cred_type_name"] # context.presentation_proposal["requested_attributes"][i]["cred_def_id"] = context.credential_definition_id_dict[cred_type_name] # # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request. # context.presentation_proposal["requested_attributes"][i].pop("cred_type_name") # except KeyError: # pass # try: # for i in range(json.dumps(context.presentation_proposal["requested_predicates"]).count("cred_def_id")): # # Get the schema name from the loaded presentation for each requested predicates # cred_type_name = context.presentation_proposal["requested_predicates"][i]["cred_type_name"] # context.presentation_proposal["requested_predicates"][i]["cred_def_id"] = context.credential_definition_id_dict[cred_type_name] # # Remove the cred_type_name from this part of the presentation since it won't be needed in the actual request. # context.presentation_proposal["requested_predicates"][i].pop("cred_type_name") # except KeyError: # pass # except FileNotFoundError: # print(FileNotFoundError + ': features/data/' + proposal + '.json') # # Call the existing proposal step to make the proposal. # context.execute_steps(''' # When "''' + prover + '''" doesn’t want to reveal what was requested so makes a presentation proposal # ''') # # # # Step Definitions to complete the presentation rejection test scenario - T005-AIP10-RFC0037 # # # @when(u'"{prover}" makes the {presentation} of the proof incorrectly so "{verifier}" rejects the proof') # def step_impl(context, prover, presentation, verifier): # 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') # presentation = context.presentation # # Find the cred ids and add the actual cred id into the presentation # # 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] # # presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["cred_id"] = '0' # # # 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] # # presentation["requested_predicates"][list(presentation["requested_predicates"])[i]]["cred_id"] = '1' # # # 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 # # Change something in the presentation data to cause a problem report # (resp_status, resp_text) = agent_backchannel_POST(context.prover_url + "/agent/command/", "proof", operation="send-presentation", id=context.presentation_thread_id, data=presentation) # assert resp_status == 400, f'resp_status {resp_status} is not 400; {resp_text}' # # 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") # # context.execute_steps(''' # # When "''' + prover + '''" makes the ''' + presentation + ''' of the proof # # ''') # # @when(u'"{verifier}" rejects the proof so sends a presentation rejection') # # def step_impl(context, verifier): # # pass # # #raise NotImplementedError(u'STEP: When "Faber" rejects the proof so sends a presentation rejection') # # @then(u'"{prover}" has the proof unverified') # # def step_impl(context, prover): # # check the state of the presentation from the prover's perspective # # in the unacknowledged case, the state of the prover is still done. There probably should be something else to check. # # like having the verified: false in the repsonse. Change this if agents start to report the verified state. # assert expected_agent_state(context.prover_url, "proof", context.presentation_thread_id, "done") # # Check the status of the verification in the verify-presentation call. Should be False # if 'credential_verification_dict' in context: # assert context.credential_verification_dict[context.presentation_thread_id] == "false"
def step_impl(context, prover): # check the state of the presentation from the prover's perspective assert expected_agent_state(context.prover_url, "proof", context.presentation_thread_id, "done")
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] # 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] # 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']] } } } (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")
def step_impl(context, requester): requester_connection_id = context.connection_id_dict[requester][context.responder_name] # This should be response-received but is completed. Chat with SKlump on this issue. #assert expected_agent_state(context.requester_url, "connection", requester_connection_id, "completed") assert expected_agent_state(context.requester_url, "did-exchange", requester_connection_id, "completed")
def step_impl(context, verifier, prover): # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. if context.request_for_proof: data = context.request_for_proof if context.non_revoked_timeframe: data["non_revoked"] = context.non_revoked_timeframe["non_revoked"] else: data = { "requested_attributes": { "attr_1": { "name": "attr_1", "restrictions": [{ "schema_name": "test_schema." + context.issuer_name, "schema_version": "1.0.0", }], } } } presentation_request = { "presentation_request": { "comment": "This is a comment for the request for presentation.", "proof_request": { "data": data }, } } if context.connectionless: (resp_status, resp_text) = agent_backchannel_POST( context.verifier_url + "/agent/command/", "proof", operation="create-send-connectionless-request", data=presentation_request, ) else: presentation_request["connection_id"] = context.connection_id_dict[ verifier][prover] # send presentation request (resp_status, resp_text) = agent_backchannel_POST( context.verifier_url + "/agent/command/", "proof", operation="send-request", data=presentation_request, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) # check the state of the presentation from the verifiers perspective # assert resp_json["state"] == "request-sent" # save off anything that is returned in the response to use later? context.presentation_thread_id = resp_json["thread_id"] if context.connectionless: # save off the presentation exchange id for use when the prover sends the presentation with a service decorator context.presentation_exchange_id = resp_json[ "presentation_exchange_id"] else: # TODO Removing this line causes too many failures in Acapy-Dotnet Acapy-Afgo. assert expected_agent_state( context.prover_url, "proof", context.presentation_thread_id, "request-received", )