diff --git a/aries_cloudagent/wallet/routes.py b/aries_cloudagent/wallet/routes.py index 9e2045dc95..1f9f0b46e6 100644 --- a/aries_cloudagent/wallet/routes.py +++ b/aries_cloudagent/wallet/routes.py @@ -43,6 +43,8 @@ NON_SD_LIST_VALIDATE, SD_JWT_EXAMPLE, SD_JWT_VALIDATE, + UUID4_EXAMPLE, + UUID4_VALIDATE, IndyDID, StrOrDictField, Uri, @@ -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): @@ -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) @@ -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") @@ -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 @@ -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, @@ -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 diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 7fb75df617..1e4a272ae7 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -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(),