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: enable refreshing did endpoint using mediator info #3260

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
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
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
Loading