Skip to content

Commit

Permalink
fix: normalization of authentication refs
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <dbluhm@pm.me>
  • Loading branch information
dbluhm committed Feb 23, 2024
1 parent 8662200 commit d75fc40
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions proxy_mediator/doc_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ def remove_routing_keys_from_verification_method(cls, value: dict) -> dict:
value["verificationMethod"] = vms
return value

@classmethod
def ensure_authentication_is_a_ref(cls, value: dict) -> dict:
"""Ensure authentication is a reference."""
if "authentication" in value:
authn = value["authentication"]
if isinstance(authn, list) and authn and isinstance(authn[0], str):
if "#" not in authn[0]:
vms = value.get("verificationMethod", [])
if not vms:
raise ValueError("No verification methods to reference")
authn[0] = vms[0].get("id")
return value

@classmethod
def apply(cls, value: dict) -> dict:
"""Apply all corrections to the given DID document."""
Expand All @@ -232,6 +245,7 @@ def apply(cls, value: dict) -> dict:
cls.didcomm_services_use_updated_conventions,
cls.remove_routing_keys_from_verification_method,
cls.didcomm_services_recip_keys_are_refs_routing_keys_are_did_key_ref,
cls.ensure_authentication_is_a_ref,
):
value = correction(value)

Expand Down

0 comments on commit d75fc40

Please sign in to comment.