Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: did exchange multiuse invites respond in kind #2850

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions aries_cloudagent/protocols/didexchange/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,30 +459,22 @@ async def receive_request(
their_role=ConnRecord.Role.REQUESTER.rfc23,
)

save_reason = None
if conn_rec: # invitation was explicit
connection_key = conn_rec.invitation_key
if conn_rec.is_multiuse_invitation:
async with self.profile.session() as session:
wallet = session.inject(BaseWallet)
my_info = await wallet.create_local_did(
method=SOV,
key_type=ED25519,
)

new_conn_rec = ConnRecord(
invitation_key=connection_key,
my_did=my_info.did,
state=ConnRecord.State.REQUEST.rfc160,
state=ConnRecord.State.INIT.rfc160,
accept=conn_rec.accept,
their_role=conn_rec.their_role,
connection_protocol=DIDX_PROTO,
)
async with self.profile.session() as session:
# TODO: Suppress the event that gets emitted here?
await new_conn_rec.save(
session,
reason=(
"Received connection request from multi-use invitation DID"
),
reason="Created new connection record from multi-use invitation",
)

# Transfer metadata from multi-use to new connection
Expand Down Expand Up @@ -537,10 +529,7 @@ async def receive_request(
conn_rec.their_did = request.did
conn_rec.state = ConnRecord.State.REQUEST.rfc160
conn_rec.request_id = request._id
async with self.profile.session() as session:
await conn_rec.save(
session, reason="Received connection request from invitation"
)
save_reason = "Received connection request from invitation"
else:
# request is against implicit invitation on public DID
if not self.profile.settings.get("requests_through_public_did"):
Expand Down Expand Up @@ -571,14 +560,13 @@ async def receive_request(
state=ConnRecord.State.REQUEST.rfc160,
connection_protocol=DIDX_PROTO,
)
async with self.profile.session() as session:
await conn_rec.save(
session, reason="Received connection request from public DID"
)
save_reason = "Received connection request from public DID"

async with self.profile.session() as session:
async with self.profile.transaction() as txn:
# Attach the connection request so it can be found and responded to
await conn_rec.attach_request(session, request)
await conn_rec.save(txn, reason=save_reason)
await conn_rec.attach_request(txn, request)
await txn.commit()

# Clean associated oob record if not needed anymore
oob_processor = self.profile.inject(OobMessageProcessor)
Expand Down Expand Up @@ -677,7 +665,7 @@ async def create_response(
self.profile, conn_rec, mediation_records
)

if use_public_did or respond_with_did_peer_2 or respond_with_did_peer_4:
if did.startswith("did:"): # It's a "real" resolvable did
# Omit DID Doc attachment if we're using a public DID or peer did
attach = AttachDecorator.data_base64_string(did)
async with self.profile.session() as session:
Expand Down