-
Notifications
You must be signed in to change notification settings - Fork 515
/
Copy pathresponse_handler.py
61 lines (52 loc) · 2.15 KB
/
response_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""DID exchange response handler under RFC 23."""
from aries_cloudagent.protocols.didexchange.v1_0.messages.problem_report import (
DIDXProblemReport,
)
from .....messaging.base_handler import (
BaseHandler,
BaseResponder,
RequestContext,
)
from ....trustping.v1_0.messages.ping import Ping
from ..manager import DIDXManager, DIDXManagerError
from ..messages.response import DIDXResponse
class DIDXResponseHandler(BaseHandler):
"""Handler class for DID exchange response message under RFC 23."""
async def handle(self, context: RequestContext, responder: BaseResponder):
"""Handle DID exchange response under RFC 23.
Args:
context: Request context
responder: Responder callback
"""
self._logger.debug(f"DIDXResponseHandler called with context {context}")
assert isinstance(context.message, DIDXResponse)
profile = context.profile
mgr = DIDXManager(profile)
try:
conn_rec = await mgr.accept_response(
context.message, context.message_receipt
)
except DIDXManagerError as e:
self._logger.exception("Error receiving DID exchange response")
if e.error_code:
targets = None
if context.message.did_doc_attach:
try:
targets = mgr.diddoc_connection_targets(
context.message.did_doc_attach,
context.message_receipt.recipient_verkey,
)
except DIDXManagerError:
self._logger.exception(
"Error parsing DIDDoc for problem report"
)
await responder.send_reply(
DIDXProblemReport(
description={"en": e.message, "code": e.error_code}
),
target_list=targets,
)
return
# send trust ping in response
if context.settings.get("auto_ping_connection"):
await responder.send(Ping(), connection_id=conn_rec.connection_id)