-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jamie Hale <[email protected]>
- Loading branch information
Showing
11 changed files
with
579 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""TDW DID Resolver. | ||
Resolution is performed by the did_tdw library. | ||
""" | ||
|
||
from re import Pattern | ||
from typing import Optional, Sequence, Text | ||
|
||
from did_history.resolver import ResolutionResult | ||
from did_tdw.resolver import 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.