-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* did:tdw resolver Signed-off-by: jamshale <[email protected]> * Update unit tests Signed-off-by: jamshale <[email protected]> * Update poetry.lock Signed-off-by: jamshale <[email protected]> --------- Signed-off-by: jamshale <[email protected]>
- Loading branch information
Showing
8 changed files
with
246 additions
and
5 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
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 |
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,36 @@ | ||
import pytest | ||
|
||
from ....core.profile import Profile | ||
from ....messaging.valid import DIDTdw | ||
from ....utils.testing import create_test_profile | ||
from ..tdw import TdwDIDResolver | ||
|
||
TEST_DID = "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example" | ||
|
||
|
||
@pytest.fixture | ||
def resolver(): | ||
"""Resolver fixture.""" | ||
yield TdwDIDResolver() | ||
|
||
|
||
@pytest.fixture | ||
async def profile(): | ||
"""Profile fixture.""" | ||
yield await create_test_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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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