From 33cb2e9779708d42e26c0b33bb8a640162ed7ac6 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 17 Apr 2024 17:45:05 -0400 Subject: [PATCH 1/2] fix: type hints on base conn mgr methods Signed-off-by: Daniel Bluhm --- aries_cloudagent/connections/base_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/connections/base_manager.py b/aries_cloudagent/connections/base_manager.py index 200f6c1c00..a35a44bfaf 100644 --- a/aries_cloudagent/connections/base_manager.py +++ b/aries_cloudagent/connections/base_manager.py @@ -89,13 +89,13 @@ def _key_info_to_multikey(key_info: KeyInfo) -> str: multicodec.wrap("ed25519-pub", b58decode(key_info.verkey)), "base58btc" ) - def long_did_peer_to_short(self, long_did: str) -> DIDInfo: + def long_did_peer_to_short(self, long_did: str) -> str: """Convert did:peer:4 long format to short format and return.""" short_did_peer = long_to_short(long_did) return short_did_peer - async def long_did_peer_4_to_short(self, long_dp4: str) -> DIDInfo: + async def long_did_peer_4_to_short(self, long_dp4: str) -> str: """Convert did:peer:4 long format to short format and store in wallet.""" async with self._profile.session() as session: From 17ea7f576013cb447a6fb3caabc5cf51b8aaf997 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 17 Apr 2024 17:45:38 -0400 Subject: [PATCH 2/2] fix: consider all resolvable dids in invites "public" Signed-off-by: Daniel Bluhm --- .../connections/models/conn_record.py | 5 +---- .../protocols/out_of_band/v1_0/manager.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/aries_cloudagent/connections/models/conn_record.py b/aries_cloudagent/connections/models/conn_record.py index da556ed4ab..116a91568f 100644 --- a/aries_cloudagent/connections/models/conn_record.py +++ b/aries_cloudagent/connections/models/conn_record.py @@ -345,10 +345,7 @@ async def find_existing_connection( session: The active profile session their_public_did: Inviter public DID (or did:peer) """ - if their_public_did.startswith("did:peer"): - tag_filter = {"their_did": their_public_did} - else: - tag_filter = {"their_public_did": their_public_did} + tag_filter = {"their_public_did": their_public_did} conn_records = await cls.query( session, tag_filter=tag_filter, 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 b55e492615..b5e011dcab 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -705,14 +705,16 @@ async def receive_invitation( if ( public_did is not None and use_existing_connection ): # invite has public DID: seek existing connection - LOGGER.debug( - "Trying to find existing connection for oob invitation with " - f"did {public_did}" - ) if public_did.startswith("did:peer:4"): search_public_did = self.long_did_peer_to_short(public_did) else: search_public_did = public_did + + LOGGER.debug( + "Trying to find existing connection for oob invitation with " + f"did {search_public_did}" + ) + async with self._profile.session() as session: conn_rec = await ConnRecord.find_existing_connection( session=session, their_public_did=search_public_did @@ -1046,7 +1048,11 @@ async def _perform_handshake( # in an out-of-band message (RFC 0434). # OR did:peer:2 or did:peer:4. - if not service.startswith("did:peer"): + if service.startswith("did:peer"): + public_did = service + if public_did.startswith("did:peer:4"): + public_did = self.long_did_peer_to_short(public_did) + else: public_did = service.split(":")[-1] # TODO: resolve_invitation should resolve key_info objects