Skip to content

Commit

Permalink
Merge pull request #2900 from dbluhm/fix/connection-reuse-did-peer
Browse files Browse the repository at this point in the history
fix: consider all resolvable dids in invites "public"
  • Loading branch information
ianco committed Apr 17, 2024
2 parents 7fd5cab + 0015fee commit dab9468
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions aries_cloudagent/connections/base_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions aries_cloudagent/connections/models/conn_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions aries_cloudagent/protocols/out_of_band/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dab9468

Please sign in to comment.