def step_impl(context, holder): holder_url = context.holder_url sleep(1) # If @indy then we can be sure we cannot start the protocol from this command. We can be sure that we have previously # received the thread_id. # if "Indy" in context.tags: if context.cred_thread_id: (resp_status, resp_text) = agent_backchannel_POST( holder_url + "/agent/command/", "issue-credential", 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", 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) # If the protocol starts with a request we need a thread_id to call the issue command if "cred_thread_id" not in context: context.cred_thread_id = resp_json["thread_id"]
def step_impl(context, holder): 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", 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", 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", context.cred_thread_id, "request-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, responder): responder_url = context.config.userdata.get(responder) (resp_status, resp_text) = agent_backchannel_POST( responder_url + "/agent/command/", "did-exchange", operation="receive-request-resolvable-did", data=context.requester_public_did_doc) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) responder_did = resp_json # setup the initial connection id dictionary if one doesn't exist. if not hasattr(context, 'connection_id_dict'): context.connection_id_dict = {} # Check for responder key existing in dict if responder not in context.connection_id_dict: context.connection_id_dict[responder] = {} # If it is not here, skip this and check for one later in the process and add it then. if "connection_id" in resp_text: context.connection_id_dict[responder][ context.requester_name] = resp_json["connection_id"]
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) #if not "issuer_schema_id_dict" in context: # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. if "schema" in context: schema = context.schema else: schema = SCHEMA_TEMPLATE.copy() schema["schema_name"] = schema["schema_name"] + issuer (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "schema", data=schema) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) #context.issuer_schema_id = resp_json["schema_id"] if 'issuer_schema_id_dict' in context: context.issuer_schema_id_dict[ context.schema['schema_name']] = resp_json["schema_id"] else: context.issuer_schema_id_dict = { context.schema['schema_name']: resp_json["schema_id"] }
def step_impl(context, issuer: str, cred_format: str = CRED_FORMAT_INDY): if cred_format == CRED_FORMAT_INDY: # Call legacy indy ready to issue credential step context.execute_steps(f''' Given '"{issuer}" is ready to issue a credential' ''') elif cred_format == CRED_FORMAT_JSON_LD: issuer_url = context.config.userdata.get(issuer) data = { "did_method": context.did_method, "proof_type": context.proof_type } (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential-v2", operation="prepare-json-ld", data=data) assert resp_status == 200, f'issue-credential-v2/prepare-json-ld: resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) # TODO: it would be nice to not depend on the schema name for the issuer did dict if 'issuer_did_dict' in context: context.issuer_did_dict[ context.schema['schema_name']] = resp_json["did"] else: context.issuer_did_dict = { context.schema['schema_name']: resp_json["did"] } else: raise Exception(f"Unknown credential format {cred_format}")
def step_impl(context, holder, issuer): holder_url = context.config.userdata.get(holder) # check for a schema template already loaded in the context. If it is, it was loaded from an external Schema, so use it. if "credential_data" in context: cred_data = context.credential_data else: cred_data = CREDENTIAL_ATTR_TEMPLATE.copy() credential_offer = { "schema_issuer_did": context.issuer_did_dict[context.schema['schema_name']], "issuer_did": context.issuer_did_dict[context.schema['schema_name']], "schema_name": context.issuer_schema_dict[context.schema['schema_name']]["name"], "cred_def_id": context.issuer_credential_definition_dict[context.schema['schema_name']]["id"], "schema_version": context.issuer_schema_dict[context.schema['schema_name']]["version"], "credential_proposal": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview", "attributes": cred_data, }, "connection_id": context.connection_id_dict[holder][issuer], "schema_id": context.issuer_schema_dict[context.schema['schema_name']]["id"], } #(resp_status, resp_text) = agent_backchannel_POST(holder_url + "/agent/command/", "issue-credential", operation="send-proposal", id=holder_connection_id, data=credential_offer) (resp_status, resp_text) = agent_backchannel_POST(holder_url + "/agent/command/", "issue-credential", operation="send-proposal", data=credential_offer) 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 credential assert resp_json["state"] == "proposal-sent" # Get the thread ID from the response text. context.cred_thread_id = resp_json["thread_id"]
def step_impl(context, inviter): inviter_url = context.config.userdata.get(inviter) (resp_status, resp_text) = agent_backchannel_POST(inviter_url + "/agent/command/", "connection", operation="create-invitation") assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) context.inviter_invitation = resp_json["invitation"] # check and see if the connection_id_dict exists # if it does, it was probably used to create another connection in a 3+ agent scenario # so that means we need to keep the connection ids around for use in the scenario # so we will not create a new dict which will reset the dict. # Also, check that the connection_id actually exists in the reponse. Some aries frameworks do not have a connection_id # at this point. If it doesn't exist, it will be aquired in the receive invitation. if "connection_id" in resp_json: if hasattr(context, 'temp_connection_id_dict'): context.temp_connection_id_dict[inviter] = resp_json[ "connection_id"] else: context.temp_connection_id_dict = { inviter: resp_json["connection_id"] } # Check to see if the inviter_name exists in context. If not, antother suite is using it so set the inviter name and url if not hasattr(context, 'inviter_name') or context.inviter_name != inviter: context.inviter_url = inviter_url context.inviter_name = inviter
def step_impl(context, inviter, invitee): inviter_url = context.config.userdata.get(inviter) #inviter_connection_id = context.connection_id_dict[inviter] inviter_connection_id = context.connection_id_dict[inviter][invitee] invitee_url = context.config.userdata.get(invitee) invitee_connection_id = context.connection_id_dict[invitee][inviter] # get connection and verify status assert expected_agent_state(inviter_url, "connection", inviter_connection_id, "requested", wait_time=60.0) assert expected_agent_state(invitee_url, "connection", invitee_connection_id, "requested", wait_time=60.0) (resp_status, resp_text) = agent_backchannel_POST(inviter_url + "/agent/command/", "connection", operation="accept-request", id=inviter_connection_id) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # get connection and verify status assert expected_agent_state(inviter_url, "connection", inviter_connection_id, "responded")
def step_impl(context, requester, responder): requester_url = context.config.userdata.get(requester) requester_did = context.requester_did data = { "their_public_did": requester_did } (resp_status, resp_text) = agent_backchannel_POST(requester_url + "/agent/command/", "did-exchange", operation="create-request-resolvable-did", data=data) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) requester_did_doc = resp_json context.requester_public_did_doc = requester_did_doc # get the requesters connection id request_id = context.requester_public_did_doc["@id"] (resp_status, resp_text) = agent_backchannel_GET(requester_url + "/agent/response/", "did-exchange", id=request_id) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) # setup the initial connection id dictionary if one doesn't exist. if not hasattr(context, 'connection_id_dict'): context.connection_id_dict = {} # Check for responder key existing in dict if requester not in context.connection_id_dict: context.connection_id_dict[requester] = {} # Some agents (afgo) do not have a webhook that give a connection id at this point in the protocol. # If it is not here, skip this and check for one later in the process and add it then. if "connection_id" in resp_text: context.connection_id_dict[requester][context.responder_name] = resp_json["connection_id"]
def step_impl(context, requester): requester_url: str = context.config.userdata.get(requester) # if feature is DID Exchange or MIME Types then set use existing connection to false if "0023" in context.feature.name or "0044" in context.feature.name: context.use_existing_connection = False data = context.responder_invitation data["use_existing_connection"] = context.use_existing_connection # If mediator is set for the current connection, set the mediator_connection_id mediator = context.mediator_dict.get(requester) if mediator: data["mediator_connection_id"] = context.connection_id_dict[requester][ mediator] (resp_status, resp_text) = agent_backchannel_POST( requester_url + "/agent/command/", "out-of-band", operation="receive-invitation", data=data, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) if context.use_existing_connection and resp_json["state"] == "completed": context.use_existing_connection_successful = True setup_already_connected(context, resp_json, requester, context.responder_name) else: assert resp_json["state"] == "invitation-received" context.connection_id_dict[requester][ context.responder_name] = resp_json["connection_id"]
def step_impl(context, requester: str, responder: str): requester_url = context.config.userdata.get(requester) requester_did = context.requester_did data = {"their_public_did": requester_did, "their_did": requester_did} (resp_status, resp_text) = agent_backchannel_POST( requester_url + "/agent/command/", "did-exchange", operation="create-request-resolvable-did", data=data, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) requester_did_doc = resp_json context.requester_public_did_doc = requester_did_doc if "connection_id" not in resp_json: # get the requesters connection id request_id = context.requester_public_did_doc["@id"] (resp_status, resp_text) = agent_backchannel_GET(requester_url + "/agent/response/", "did-exchange", id=request_id) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) # Some agents (afgo) do not have a webhook that give a connection id at this point in the protocol. # If it is not here, skip this and check for one later in the process and add it then. if "connection_id" in resp_text: context.connection_id_dict[requester][responder] = resp_json[ "connection_id"]
def step_impl(context, inviteinterceptor, inviter): context.execute_steps(f""" When "{inviteinterceptor}" receives the connection invitation """) inviteinterceptor_url = context.config.userdata.get(inviteinterceptor) inviteinterceptor_connection_id = context.connection_id_dict[ inviteinterceptor][inviter] # get connection and verify status before call assert expected_agent_state(inviteinterceptor_url, "connection", inviteinterceptor_connection_id, "invited") (resp_status, resp_text) = agent_backchannel_POST( inviteinterceptor_url + "/agent/command/", "connection", operation="accept-invitation", id=inviteinterceptor_connection_id, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" # get connection and verify status assert expected_agent_state( inviteinterceptor_url, "connection", inviteinterceptor_connection_id, "requested", )
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) issuer_did = context.issuer_did issuer_connection_id = context.connection_id_dict[issuer][context.holder_name] issuer_schema_id = context.issuer_schema_id issuer_schema = context.issuer_schema issuer_credential_definition_id = context.credential_definition_id issuer_credential_definition = context.issuer_credential_definition credential_offer = { "schema_issuer_did": issuer_did, "issuer_did": issuer_did, "schema_name": issuer_schema["name"], "cred_def_id": issuer_credential_definition["id"], "schema_version": issuer_schema["version"], "credential_proposal": { "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/issue-credential/1.0/credential-preview", "attributes": CREDENTIAL_ATTR_TEMPLATE.copy(), }, "connection_id": issuer_connection_id, "schema_id": issuer_schema["id"], } (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential", operation="send", data=credential_offer) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) issuer_credential_definition = resp_json
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) #if not "credential_definition_id_dict" in context: cred_def = CRED_DEF_TEMPLATE.copy() cred_def["schema_id"] = context.issuer_schema_id_dict[ context.schema['schema_name']] if "support_revocation" in context: cred_def["support_revocation"] = context.support_revocation (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "credential-definition", data=cred_def) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) if "support_revocation" in context: # Could make a call to get the rev reg creation time for calculating non revocation intervals #context.cred_rev_creation_time = resp_json["created"] context.cred_rev_creation_time = time.time() if 'credential_definition_id_dict' in context: context.credential_definition_id_dict[context.schema[ 'schema_name']] = resp_json["credential_definition_id"] else: context.credential_definition_id_dict = { context.schema['schema_name']: resp_json["credential_definition_id"] }
def step_impl(context, inviter): inviter_url = context.config.userdata.get(inviter) (resp_status, resp_text) = agent_backchannel_POST(inviter_url + "/agent/command/", "connection", operation="create-invitation") assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' resp_json = json.loads(resp_text) context.inviter_invitation = resp_json["invitation"] # check and see if the connection_id_dict exists # if it does, it was probably used to create another connection in a 3+ agent scenario # so that means we need to keep the connection ids around for use in the scenario # so we will not create a new dict which will reset the dict if hasattr(context, 'temp_connection_id_dict'): context.temp_connection_id_dict[inviter] = resp_json["connection_id"] else: context.temp_connection_id_dict = {inviter: resp_json["connection_id"]} # Check to see if the inviter_name exists in context. If not, antother suite is using it so set the inviter name and url if not hasattr(context, 'inviter_name') or context.inviter_name != inviter: context.inviter_url = inviter_url context.inviter_name = inviter # get connection and verify status assert expected_agent_state(inviter_url, "connection", context.temp_connection_id_dict[inviter], "invited")
def step_impl(context, verifier): verifier_url = 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( verifier_url + "/agent/command/", proof_endpoint, operation="verify-presentation", id=context.presentation_thread_id, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) assert resp_json["state"] == "done" if context.support_revocation: # Add the verified property returned to the credential verification dictionary to check in subsequent steps. Key by presentation thread id context.credential_verification_dict[ context.presentation_thread_id ] = strtobool(resp_json["verified"])
def step_impl(context, inviter): inviter_url = context.config.userdata.get(inviter) data = {} # If mediator is set for the current connection, set the mediator_connection_id mediator = context.mediator_dict.get(inviter) if mediator: data["mediator_connection_id"] = context.connection_id_dict[inviter][ mediator] (resp_status, resp_text) = agent_backchannel_POST( inviter_url + "/agent/command/", "connection", operation="create-invitation", data=data, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) context.inviter_invitation = resp_json["invitation"] # check and see if the connection_id_dict exists # if it does, it was probably used to create another connection in a 3+ agent scenario # so that means we need to keep the connection ids around for use in the scenario # so we will not create a new dict which will reset the dict # Also, check that the connection_id actually exists in the response. Some aries frameworks do not have a connection_id # at this point. If it doesn't exist, it will be acquired in the receive invitation. if "connection_id" in resp_json: context.temp_connection_id_dict[inviter] = resp_json["connection_id"] # Check to see if the inviter_name exists in context. If not, antother suite is using it so set the inviter name and url if context.inviter_name != inviter: context.inviter_url = inviter_url context.inviter_name = inviter
def step_impl(context, verifier: str, prover: str): presentation_proposal = { "presentation_proposal": { "comment": "This is a comment for the proposed presentation.", "connection_id": context.connection_id_dict[prover][verifier] } } if "PresentProofV3" in context.tags: proof_endpoint = "proof-v3" else: proof_endpoint = "proof-v2" # send presentation proposal (resp_status, resp_text) = agent_backchannel_POST( context.prover_url + "/agent/command/", proof_endpoint, 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) context.presentation_thread_id = resp_json["thread_id"]
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) credential_revocation = { "cred_rev_id": context.cred_rev_id, "rev_registry_id": context.rev_reg_id, "publish_immediately": True, } (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "revocation", operation="revoke", data=credential_revocation) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' #resp_json = json.loads(resp_text) # Check the Holder wallet for the credential # Should be a 200 since the revoke doesn't remove the cred from the holders wallet. # What else to check? (resp_status, resp_text) = agent_backchannel_GET(context.config.userdata.get(context.holder_name) + "/agent/command/", "credential", id=context.credential_id_dict[context.schema['schema_name']][len(context.credential_id_dict[context.schema['schema_name']])-1]) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # if this is ACA-py then there is provision for the holder to check the revocation status of the cred then they can take action, # like delete it from thier wallet. This should be done, since the algorithm that if "delete_cred_from_wallet" in context.tags: # Call the revocation status api #(resp_status, resp_text) = agent_backchannel_GET(context.prover_url + "/agent/command/", "revocation", operation="credential-record", data=credential_revocation) (resp_status, resp_text) = agent_backchannel_GET(context.prover_url + "/agent/command/", "credential", operation="revoked", id=context.credential_id_dict[context.schema['schema_name']][len(context.credential_id_dict[context.schema['schema_name']])-1]) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # get the credential status verified out of the response # Could also add the cred status to the cred id dict. Maybe later if needed. resp_json = json.loads(resp_text) revoked = resp_json["revoked"] if revoked == True: # Call the delete on the credential in the wallet (resp_status, resp_text) = agent_backchannel_DELETE(context.prover_url + "/agent/command/", "credential", id=context.credential_id_dict[context.schema['schema_name']][len(context.credential_id_dict[context.schema['schema_name']])-1]) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}'
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) cred_data = context.credential_data or 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 sleep(1.0)
def step_impl(context, issuer): issuer_url = context.config.userdata.get(issuer) # If context has the credential thread id then the proposal was done. if context.cred_thread_id: (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) # if context does not have the credential thread id then the proposal was not the starting point for the protocol. else: cred_data = context.credential_data or 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) if "thread_id" in resp_json: context.cred_thread_id = resp_json["thread_id"] # Check the state of the holder after issuers call of send-offer # TODO Removing this line causes too many failures in Acapy-Dotnet Acapy-Afgo. sleep(3) assert expected_agent_state(context.holder_url, "issue-credential", context.cred_thread_id, "offer-received")
def step_impl(context, requester, responder): requester_connection_id = context.connection_id_dict[requester][responder] (resp_status, resp_text) = agent_backchannel_POST(context.requester_url + "/agent/command/", "did-exchange", operation="send-request", id=requester_connection_id) 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"
def step_impl(context, inviter): inviter_url = context.config.userdata.get(inviter) inviter_connection_id = context.connection_id_dict[inviter] # TODO It is expected that accept-request should send a request not accepted error, not a 500 (resp_status, resp_text) = agent_backchannel_POST(inviter_url + "/agent/command/", "connection", operation="accept-request", id=inviter_connection_id) # TODO once bug 418 has been fixed change this assert to the proper response code. # bug reference URL: https://app.zenhub.com/workspaces/von---verifiable-organization-network-5adf53987ccbaa70597dbec0/issues/hyperledger/aries-cloudagent-python/418 assert resp_status == 406, f'resp_status {resp_status} is not 406; {resp_text}'
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")
def step_impl(context, invitee): invitee_url = context.config.userdata.get(invitee) data = context.inviter_invitation # If mediator is set for the current connection, set the mediator_connection_id mediator = context.mediator_dict.get(invitee) if mediator: data["mediator_connection_id"] = context.connection_id_dict[invitee][ mediator] (resp_status, resp_text) = agent_backchannel_POST( invitee_url + "/agent/command/", "connection", operation="receive-invitation", data=data, ) assert resp_status == 200, f"resp_status {resp_status} is not 200; {resp_text}" resp_json = json.loads(resp_text) context.connection_id_dict[invitee][ context.inviter_name] = resp_json["connection_id"] # Also add the inviter into the main connection_id_dict. if the len is 0 that means its already been cleared and this may be Mallory. if len(context.temp_connection_id_dict) != 0: context.connection_id_dict[context.inviter_name][ invitee] = context.temp_connection_id_dict[context.inviter_name] # clear the temp connection id dict used in the initial step. We don't need it anymore. context.temp_connection_id_dict.clear() else: # This means the connection id was not retreived for the inviter in the create invitation step # Get the connection id for the inviter given the invitation_id (alt_resp_status, alt_resp_text) = agent_backchannel_GET( context.inviter_url + "/agent/response/", "connection", id=context.inviter_invitation["@id"], ) assert (alt_resp_status == 200 ), f"resp_status {alt_resp_status} is not 200; {alt_resp_text}" alt_resp_json = json.loads(alt_resp_text) context.connection_id_dict[ context.inviter_name][invitee] = alt_resp_json["connection_id"] # Check to see if the invitee_name exists in context. If not, antother suite is using it so set the invitee name and url if not context.invitee_name: context.invitee_url = invitee_url context.invitee_name = invitee # get connection and verify status assert expected_agent_state( invitee_url, "connection", context.connection_id_dict[invitee][context.inviter_name], "invited", )
def step_impl(context, responder, requester): responder_connection_id = context.connection_id_dict[responder][requester] responder_url = context.config.userdata.get(responder) (resp_status, resp_text) = agent_backchannel_POST(responder_url + "/agent/command/", "did-exchange", operation="send-response", id=responder_connection_id) assert resp_status == 400, f'resp_status {resp_status} is not 400; {resp_text}'
def step_impl(context, issuer, cred_format): 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 # We only want to send data for the cred format being used assert cred_format in context.filters, f"credential data has no filter for cred format {cred_format}" filters = {cred_format: context.filters[cred_format]} credential_offer = format_cred_proposal_by_aip_version( context, "AIP20", cred_data, context.connection_id_dict[issuer][context.holder_name], filters) (resp_status, resp_text) = agent_backchannel_POST(issuer_url + "/agent/command/", "issue-credential-v2", 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-v2", 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-v2", context.cred_thread_id, "offer-received")
def step_impl(context, sender, receiver): sender_url = context.config.userdata.get(sender) sender_connection_id = context.connection_id_dict[sender] # get connection and verify status of the reciever # no need to do this here, a trust pint may be called at any point, can't check for state. #assert connection_status(sender_url, sender_connection_id, "response") data = {"comment": "acknowledgement from " + sender} (resp_status, resp_text) = agent_backchannel_POST(sender_url + "/agent/command/", "connection", operation="send-ping", id=sender_connection_id, data=data) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}'
def step_impl(context, inviter): # extra step to force status to 'active' for VCX inviter_url = context.config.userdata.get(inviter) inviter_connection_id = context.connection_id_dict[inviter] data = {"comment": "Hello from " + inviter} (resp_status, resp_text) = agent_backchannel_POST(inviter_url + "/agent/command/", "connection", operation="send-ping", id=inviter_connection_id, data=data) assert resp_status == 200, f'resp_status {resp_status} is not 200; {resp_text}' # get connection and verify status assert connection_status(inviter_url, inviter_connection_id, "active")