Skip to content

Commit

Permalink
Merge pull request hyperledger#3260 from dbluhm/fix/refresh-did-endpoint
Browse files Browse the repository at this point in the history
fix: enable refreshing did endpoint using mediator info
  • Loading branch information
dbluhm committed Sep 27, 2024
2 parents cf15b3b + 8a20bfc commit 7305ca0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
26 changes: 25 additions & 1 deletion aries_cloudagent/wallet/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
NON_SD_LIST_VALIDATE,
SD_JWT_EXAMPLE,
SD_JWT_VALIDATE,
UUID4_EXAMPLE,
UUID4_VALIDATE,
IndyDID,
StrOrDictField,
Uri,
Expand Down Expand Up @@ -172,6 +174,14 @@ class DIDEndpointWithTypeSchema(OpenAPISchema):
"example": ENDPOINT_TYPE_EXAMPLE,
},
)
mediation_id = fields.Str(
required=False,
validate=UUID4_VALIDATE,
metadata={
"description": "Medation ID to use for endpoint information.",
"example": UUID4_EXAMPLE,
},
)


class JWSCreateSchema(OpenAPISchema):
Expand Down Expand Up @@ -896,7 +906,7 @@ async def promote_wallet_public_did(
async with (
context.session() if is_ctx_admin_request else profile.session()
) as session:
wallet = session.inject_or(BaseWallet)
wallet = session.inject(BaseWallet)
did_info = await wallet.get_local_did(did)
info = await wallet.set_public_did(did_info)

Expand Down Expand Up @@ -951,6 +961,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest):
did = body["did"]
endpoint = body.get("endpoint")
endpoint_type = EndpointType.get(body.get("endpoint_type", EndpointType.ENDPOINT.w3c))
mediation_id = body.get("mediation_id")

create_transaction_for_endorser = json.loads(
request.query.get("create_transaction_for_endorser", "false")
Expand All @@ -960,6 +971,17 @@ async def wallet_set_did_endpoint(request: web.BaseRequest):
connection_id = request.query.get("conn_id")
attrib_def = None

profile = context.profile
route_manager = profile.inject(RouteManager)
mediation_record = await route_manager.mediation_record_if_id(
profile=profile, mediation_id=mediation_id, or_default=True
)
routing_keys, mediator_endpoint = await route_manager.routing_info(
profile,
mediation_record,
)
LOGGER.debug("Mediation info: %s, %s", routing_keys, mediator_endpoint)

# check if we need to endorse
if is_author_role(context.profile):
# authors cannot write to the ledger
Expand Down Expand Up @@ -1005,6 +1027,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest):
if not wallet:
raise web.HTTPForbidden(reason="No wallet available")
try:
endpoint = mediator_endpoint or endpoint
ledger = context.profile.inject_or(BaseLedger)
attrib_def = await wallet.set_did_endpoint(
did,
Expand All @@ -1013,6 +1036,7 @@ async def wallet_set_did_endpoint(request: web.BaseRequest):
endpoint_type,
write_ledger=write_ledger,
endorser_did=endorser_did,
routing_keys=routing_keys,
)
except WalletNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
Expand Down
7 changes: 5 additions & 2 deletions aries_cloudagent/wallet/tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ class TestWalletRoutes(IsolatedAsyncioTestCase):
def setUp(self):
self.wallet = mock.create_autospec(BaseWallet)
self.session_inject = {BaseWallet: self.wallet}
self.route_mgr = mock.MagicMock()
self.route_mgr.mediation_record_if_id = mock.CoroutineMock(return_value=None)
self.route_mgr.routing_info = mock.CoroutineMock(return_value=(None, None))
self.profile = InMemoryProfile.test_profile(
settings={"admin.admin_api_key": "secret-key"}
settings={"admin.admin_api_key": "secret-key"},
bind={KeyTypes: KeyTypes(), RouteManager: self.route_mgr},
)
self.context = AdminRequestContext.test_context(self.session_inject, self.profile)
self.context.injector.bind_instance(KeyTypes, KeyTypes())
self.request_dict = {
"context": self.context,
"outbound_message_router": mock.CoroutineMock(),
Expand Down

0 comments on commit 7305ca0

Please sign in to comment.