Skip to content

Commit

Permalink
Merge pull request #46 from Indicio-tech/fix/normalize-authentication
Browse files Browse the repository at this point in the history
fix: normalization of authentication refs
  • Loading branch information
dbluhm authored Feb 23, 2024
2 parents 8662200 + d75fc40 commit e5dea0b
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 e5dea0b

Please sign in to comment.