From 67ab3df6d06ecd57d87a5ffd0bb99290b0b37863 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 21 Dec 2021 15:58:31 -0800 Subject: [PATCH 1/5] Allow public invites for alice/faber demo Signed-off-by: Ian Costanzo --- demo/runners/support/agent.py | 1 + 1 file changed, 1 insertion(+) diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index 145ae7a1dd..ca2fd0f4b6 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -333,6 +333,7 @@ def get_agent_args(self): ("--wallet-key", self.wallet_key), "--preserve-exchange-records", "--auto-provision", + "--public-invites", ] if self.aip == 20: result.append("--emit-new-didcomm-prefix") From 946dec494e8f8f60626886aad6e67d8f0e3c5aec Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Thu, 23 Dec 2021 14:25:34 -0800 Subject: [PATCH 2/5] Add connection reuse option to alice/faber Signed-off-by: Ian Costanzo --- demo/runners/agent_container.py | 36 ++++++++++++++++++++++++++++++--- demo/runners/faber.py | 10 +++++++-- demo/runners/support/agent.py | 29 +++++++++++++++++++++----- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index a5433088d4..020eb5833a 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -96,6 +96,7 @@ def connection_ready(self): return self._connection_ready.done() and self._connection_ready.result() async def handle_oob_invitation(self, message): + print("handle_oob_invitation():", json.dumps(message)) pass async def handle_connections(self, message): @@ -506,6 +507,7 @@ async def generate_invitation( use_did_exchange: bool, auto_accept: bool = True, display_qr: bool = False, + reuse_connections: bool = False, wait: bool = False, ): self._connection_ready = asyncio.Future() @@ -514,7 +516,11 @@ async def generate_invitation( log_status( "#7 Create a connection to alice and print out the invite details" ) - invi_rec = await self.get_invite(use_did_exchange, auto_accept) + invi_rec = await self.get_invite( + use_did_exchange, + auto_accept=auto_accept, + reuse_connections=reuse_connections, + ) if display_qr: qr = QRCode(border=1) @@ -589,6 +595,7 @@ def __init__( aip: int = 20, arg_file: str = None, endorser_role: str = None, + reuse_connections: bool = False, ): # configuration parameters self.genesis_txns = genesis_txns @@ -616,6 +623,7 @@ def __init__( self.public_did = True self.cred_type = CRED_FORMAT_INDY + self.reuse_connections = reuse_connections self.exchange_tracing = False # local agent(s) @@ -897,10 +905,18 @@ async def terminate(self): return terminated async def generate_invitation( - self, auto_accept: bool = True, display_qr: bool = False, wait: bool = False + self, + auto_accept: bool = True, + display_qr: bool = False, + reuse_connections: bool = False, + wait: bool = False, ): return await self.agent.generate_invitation( - self.use_did_exchange, auto_accept, display_qr, wait + self.use_did_exchange, + auto_accept=auto_accept, + display_qr=display_qr, + reuse_connections=reuse_connections, + wait=wait, ) async def input_invitation(self, invite_details: dict, wait: bool = False): @@ -1087,6 +1103,15 @@ def arg_parser(ident: str = None, port: int = 8020): "directly." ), ) + if (not ident) or (ident != "alice"): + parser.add_argument( + "--reuse-connections", + action="store_true", + help=( + "Reuse connections by using Faber public key in the invite. " + "Only applicable for AIP 2.0 (OOB) connections." + ), + ) parser.add_argument( "--arg-file", type=str, @@ -1169,6 +1194,10 @@ async def create_agent_with_args(args, ident: str = None): f"Initializing demo agent {agent_ident} with AIP {aip} and credential type {cred_type}" ) + reuse_connections = "reuse_connections" in args and args.reuse_connections + if reuse_connections and aip != 20: + raise Exception("Can only specify `--reuse-connections` with AIP 2.0") + agent = AgentContainer( genesis_txns=genesis, genesis_txn_list=multi_ledger_config_path, @@ -1188,6 +1217,7 @@ async def create_agent_with_args(args, ident: str = None): arg_file=arg_file, aip=aip, endorser_role=args.endorser_role, + reuse_connections=reuse_connections, ) return agent diff --git a/demo/runners/faber.py b/demo/runners/faber.py index 2f42a8938a..d7e7ce6ab5 100644 --- a/demo/runners/faber.py +++ b/demo/runners/faber.py @@ -427,7 +427,9 @@ async def main(args): raise Exception("Invalid credential type:" + faber_agent.cred_type) # generate an invitation for Alice - await faber_agent.generate_invitation(display_qr=True, wait=True) + await faber_agent.generate_invitation( + display_qr=True, reuse_connections=faber_agent.reuse_connections, wait=True + ) exchange_tracing = False options = ( @@ -683,7 +685,11 @@ async def main(args): "Creating a new invitation, please receive " "and accept this invitation using Alice agent" ) - await faber_agent.generate_invitation(display_qr=True, wait=True) + await faber_agent.generate_invitation( + display_qr=True, + reuse_connections=faber_agent.reuse_connections, + wait=True, + ) elif option == "5" and faber_agent.revocation: rev_reg_id = (await prompt("Enter revocation registry ID: ")).strip() diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index ca2fd0f4b6..b8f9ef252b 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -775,6 +775,7 @@ async def handle_webhook(self, topic: str, payload, headers: dict): handler = f"handle_{topic}" wallet_id = headers.get("x-wallet-id") method = getattr(self, handler, None) + print("Handling:", handler, payload) if method: EVENT_LOGGER.debug( "Agent called controller webhook: %s%s%s%s", @@ -1145,21 +1146,36 @@ def _postgres_tables(self): def reset_postgres_stats(self): self.wallet_stats.clear() - async def get_invite(self, use_did_exchange: bool, auto_accept: bool = True): + async def get_invite( + self, + use_did_exchange: bool, + auto_accept: bool = True, + reuse_connections: bool = False, + ): self.connection_id = None if use_did_exchange: # TODO can mediation be used with DID exchange connections? + invi_params = { + "auto_accept": json.dumps(auto_accept), + } + payload = { + "handshake_protocols": ["rfc23"], + "use_public_did": reuse_connections, + } invi_rec = await self.admin_POST( "/out-of-band/create-invitation", - {"handshake_protocols": ["rfc23"]}, - params={"auto_accept": json.dumps(auto_accept)}, + payload, + params=invi_params, ) else: if self.mediation: + invi_params = { + "auto_accept": json.dumps(auto_accept), + } invi_rec = await self.admin_POST( "/connections/create-invitation", {"mediation_id": self.mediator_request_id}, - params={"auto_accept": json.dumps(auto_accept)}, + params=invi_params, ) else: invi_rec = await self.admin_POST("/connections/create-invitation") @@ -1170,13 +1186,16 @@ async def receive_invite(self, invite, auto_accept: bool = True): if self.endorser_role and self.endorser_role == "author": params = {"alias": "endorser"} else: - params = None + params = {} if "/out-of-band/" in invite.get("@type", ""): + # always reuse connections if possible + params["use_existing_connection"] = "true" connection = await self.admin_POST( "/out-of-band/receive-invitation", invite, params=params, ) + print("Received invite connection:", json.dumps(connection)) else: connection = await self.admin_POST( "/connections/receive-invitation", From 23b24fa651841c3663e2f238655bb9446919316f Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Thu, 6 Jan 2022 06:17:50 -0800 Subject: [PATCH 3/5] Add webhooks for OOB connections Signed-off-by: Ian Costanzo --- aries_cloudagent/core/dispatcher.py | 1 + demo/runners/agent_container.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/aries_cloudagent/core/dispatcher.py b/aries_cloudagent/core/dispatcher.py index 98df420472..123d33abba 100644 --- a/aries_cloudagent/core/dispatcher.py +++ b/aries_cloudagent/core/dispatcher.py @@ -321,4 +321,5 @@ async def send_webhook(self, topic: str, payload: dict): "responder.send_webhook is deprecated; please use the event bus instead.", DeprecationWarning, ) + print("Sending webhook for topic:", topic) await self._context.profile.notify("acapy::webhook::" + topic, payload) diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index 020eb5833a..52ccf5ef5e 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -99,6 +99,16 @@ async def handle_oob_invitation(self, message): print("handle_oob_invitation():", json.dumps(message)) pass + async def handle_connection_reuse(self, message): + print("handle_connection_reuse():", json.dumps(message)) + # TODO we are reusing an existing connection, set our status to the existing connection + pass + + async def handle_connection_reuse_accepted(self, message): + print("handle_connection_reuse_accepted():", json.dumps(message)) + # TODO we are reusing an existing connection, set our status to the existing connection + pass + async def handle_connections(self, message): # a bit of a hack, but for the mediator connection self._connection_ready # will be None From 7fcdfaf070ea2ff2ff45b8bcb9732a09d667a9db Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Fri, 7 Jan 2022 07:40:36 -0800 Subject: [PATCH 4/5] Add webhooks for OOB connection reuse Signed-off-by: Ian Costanzo --- .../protocols/out_of_band/v1_0/manager.py | 2 +- demo/runners/agent_container.py | 16 ++++++++++------ demo/runners/support/agent.py | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index ee9c4386d4..7b8478e258 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -54,7 +54,7 @@ LOGGER = logging.getLogger(__name__) REUSE_WEBHOOK_TOPIC = "acapy::webhook::connection_reuse" -REUSE_ACCEPTED_WEBHOOK_TOPIC = "acapy::webhook:connection_reuse_accepted" +REUSE_ACCEPTED_WEBHOOK_TOPIC = "acapy::webhook::connection_reuse_accepted" class OutOfBandManagerError(BaseError): diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index 52ccf5ef5e..665189d913 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -100,14 +100,18 @@ async def handle_oob_invitation(self, message): pass async def handle_connection_reuse(self, message): - print("handle_connection_reuse():", json.dumps(message)) - # TODO we are reusing an existing connection, set our status to the existing connection - pass + # we are reusing an existing connection, set our status to the existing connection + if not self._connection_ready.done(): + self.connection_id = message["connection_id"] + self.log("Connected") + self._connection_ready.set_result(True) async def handle_connection_reuse_accepted(self, message): - print("handle_connection_reuse_accepted():", json.dumps(message)) - # TODO we are reusing an existing connection, set our status to the existing connection - pass + # we are reusing an existing connection, set our status to the existing connection + if not self._connection_ready.done(): + self.connection_id = message["connection_id"] + self.log("Connected") + self._connection_ready.set_result(True) async def handle_connections(self, message): # a bit of a hack, but for the mediator connection self._connection_ready diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index b8f9ef252b..04d78b4b52 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -775,7 +775,6 @@ async def handle_webhook(self, topic: str, payload, headers: dict): handler = f"handle_{topic}" wallet_id = headers.get("x-wallet-id") method = getattr(self, handler, None) - print("Handling:", handler, payload) if method: EVENT_LOGGER.debug( "Agent called controller webhook: %s%s%s%s", From ff020209c0a7250d6a1a4a66d3b0d8f430115a8b Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Fri, 7 Jan 2022 07:51:28 -0800 Subject: [PATCH 5/5] Cleanup debugging Signed-off-by: Ian Costanzo --- aries_cloudagent/core/dispatcher.py | 1 - demo/runners/agent_container.py | 8 +------- demo/runners/support/agent.py | 1 - 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/aries_cloudagent/core/dispatcher.py b/aries_cloudagent/core/dispatcher.py index 123d33abba..98df420472 100644 --- a/aries_cloudagent/core/dispatcher.py +++ b/aries_cloudagent/core/dispatcher.py @@ -321,5 +321,4 @@ async def send_webhook(self, topic: str, payload: dict): "responder.send_webhook is deprecated; please use the event bus instead.", DeprecationWarning, ) - print("Sending webhook for topic:", topic) await self._context.profile.notify("acapy::webhook::" + topic, payload) diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index 665189d913..922bcd51d2 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -96,7 +96,7 @@ def connection_ready(self): return self._connection_ready.done() and self._connection_ready.result() async def handle_oob_invitation(self, message): - print("handle_oob_invitation():", json.dumps(message)) + print("handle_oob_invitation()") pass async def handle_connection_reuse(self, message): @@ -624,7 +624,6 @@ def __init__( self.multitenant = multitenant self.mediation = mediation self.use_did_exchange = use_did_exchange - print("Setting use_did_exchange:", self.use_did_exchange) self.wallet_type = wallet_type self.public_did = public_did self.seed = seed @@ -827,13 +826,10 @@ async def receive_credential( for cred_attr in cred_attrs: if cred_attr["name"] in wallet_attrs: if wallet_attrs[cred_attr["name"]] != cred_attr["value"]: - print("Value doesn't match for:", cred_attr["name"]) matched = False else: - print("Attribute not found for:", cred_attr["name"]) matched = False - print("Matching credential received") return matched async def request_proof(self, proof_request): @@ -885,12 +881,10 @@ async def verify_proof(self, proof_request): if self.cred_type == CRED_FORMAT_INDY: # return verified status - print("Received proof:", self.agent.last_proof_received["verified"]) return self.agent.last_proof_received["verified"] elif self.cred_type == CRED_FORMAT_JSON_LD: # return verified status - print("Received proof:", self.agent.last_proof_received["verified"]) return self.agent.last_proof_received["verified"] else: diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index 04d78b4b52..b8f7c33ffd 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -1194,7 +1194,6 @@ async def receive_invite(self, invite, auto_accept: bool = True): invite, params=params, ) - print("Received invite connection:", json.dumps(connection)) else: connection = await self.admin_POST( "/connections/receive-invitation",