-
Notifications
You must be signed in to change notification settings - Fork 511
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
did:tdw resolver #3237
base: main
Are you sure you want to change the base?
did:tdw resolver #3237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""TDW DID Resolver. | ||
|
||
Resolution is performed by the did_tdw library. | ||
""" | ||
|
||
from re import Pattern | ||
from typing import Optional, Sequence, Text | ||
|
||
from did_tdw.resolver import ResolutionResult, resolve_did | ||
|
||
from ...config.injection_context import InjectionContext | ||
from ...core.profile import Profile | ||
from ...messaging.valid import DIDTdw | ||
from ..base import BaseDIDResolver, ResolverType | ||
|
||
|
||
class TdwDIDResolver(BaseDIDResolver): | ||
"""TDW DID Resolver.""" | ||
|
||
def __init__(self): | ||
"""Initialize the TDW DID Resolver.""" | ||
super().__init__(ResolverType.NATIVE) | ||
|
||
async def setup(self, context: InjectionContext): | ||
"""Perform required setup for TDW DID resolution.""" | ||
|
||
@property | ||
def supported_did_regex(self) -> Pattern: | ||
"""Return supported DID regex of TDW DID Resolver.""" | ||
return DIDTdw.PATTERN | ||
|
||
async def _resolve( | ||
self, profile: Profile, did: str, service_accept: Optional[Sequence[Text]] = None | ||
) -> dict: | ||
"""Resolve DID using TDW.""" | ||
response: ResolutionResult = await resolve_did(did) | ||
if response.resolution_metadata and response.resolution_metadata.get("error"): | ||
return response.resolution_metadata | ||
|
||
return response.document |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from ....core.in_memory import InMemoryProfile | ||
from ....core.profile import Profile | ||
from ....messaging.valid import DIDTdw | ||
from ..tdw import TdwDIDResolver | ||
|
||
TEST_DID = "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example" | ||
|
||
|
||
@pytest.fixture | ||
def resolver(): | ||
"""Resolver fixture.""" | ||
yield TdwDIDResolver() | ||
|
||
|
||
@pytest.fixture | ||
def profile(): | ||
"""Profile fixture.""" | ||
profile = InMemoryProfile.test_profile() | ||
yield profile | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_supported_did_regex(profile, resolver: TdwDIDResolver): | ||
"""Test the supported_did_regex.""" | ||
assert resolver.supported_did_regex == DIDTdw.PATTERN | ||
assert await resolver.supports( | ||
profile, | ||
TEST_DID, | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_resolve(resolver: TdwDIDResolver, profile: Profile): | ||
"""Test resolve method.""" | ||
assert await resolver.resolve(profile, TEST_DID) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
"""Resolve did document admin routes.""" | ||
|
||
import re | ||
|
||
from aiohttp import web | ||
from aiohttp_apispec import docs, match_info_schema, response_schema | ||
from marshmallow import fields, validate | ||
from pydid.common import DID_PATTERN | ||
|
||
from ..admin.decorators.auth import tenant_authentication | ||
from ..admin.request_context import AdminRequestContext | ||
|
@@ -23,7 +24,10 @@ class W3cDID(validate.Regexp): | |
"""Validate value against w3c DID.""" | ||
|
||
EXAMPLE = "did:ted:WgWxqztrNooG92RXvxSTWv" | ||
PATTERN = DID_PATTERN | ||
# Did or DidUrl regex | ||
PATTERN = re.compile( | ||
"^did:([a-z0-9]+):((?:[a-zA-Z0-9._%-]*:)*[a-zA-Z0-9._%-]+)(#\w+)?$" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes the pattern to allow did url pattern. Couldn't figure out how to do it with the pydid library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused why we're doing this. A DID is distinct from a DID URL? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect it is because a DID resolves to a DIDDoc, and a DID URL, resolves to whatever the resource is pointed to by the URL (AnonCreds object, OCA bundle, status list VC, etc). The DID still needs to be resolved (perhaps from a cache) before getting the resource, but the resolution result object will be different. |
||
|
||
def __init__(self): | ||
"""Initialize the instance.""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows for the DIDUrl to be resolved. I admittedly don't have a lot of knowledge here.