forked from openwallet-foundation/acapy
-
Notifications
You must be signed in to change notification settings - Fork 0
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: DaevMithran <[email protected]>
- Loading branch information
1 parent
68e7f88
commit b653306
Showing
2 changed files
with
49 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,51 @@ | ||
"""Key DID Resolver. | ||
Resolution is performed using the IndyLedger class. | ||
""" | ||
"""Cheqd DID Resolver.""" | ||
|
||
from aiohttp import ClientSession | ||
from typing import Optional, Pattern, Sequence, Text | ||
|
||
from ...messaging.valid import CheqdDID | ||
from ...config.injection_context import InjectionContext | ||
from ...core.profile import Profile | ||
from ...did.did_key import DIDKey | ||
from ...messaging.valid import DIDKey as DIDKeyType | ||
from ..base import BaseDIDResolver, DIDNotFound, ResolverType | ||
|
||
|
||
class KeyDIDResolver(BaseDIDResolver): | ||
class CheqdDIDResolver(BaseDIDResolver): | ||
"""Key DID Resolver.""" | ||
|
||
DID_RESOLVER_BASE_URL = "https://resolver.cheqd.net/1.0/identifiers/" | ||
|
||
def __init__(self): | ||
"""Initialize Key Resolver.""" | ||
"""Initialize Cheqd Resolver.""" | ||
super().__init__(ResolverType.NATIVE) | ||
|
||
async def setup(self, context: InjectionContext): | ||
"""Perform required setup for Key DID resolution.""" | ||
"""Perform required setup for Cheqd DID resolution.""" | ||
|
||
@property | ||
def supported_did_regex(self) -> Pattern: | ||
"""Return supported_did_regex of Key DID Resolver.""" | ||
return DIDKeyType.PATTERN | ||
"""Return supported_did_regex of Cheqd DID Resolver.""" | ||
return CheqdDID.PATTERN | ||
|
||
async def _resolve( | ||
self, | ||
profile: Profile, | ||
did: str, | ||
service_accept: Optional[Sequence[Text]] = None, | ||
) -> dict: | ||
"""Resolve a Key DID.""" | ||
"""Resolve a Cheqd DID.""" | ||
try: | ||
did_key = DIDKey.from_did(did) | ||
async with ClientSession() as session: | ||
try: | ||
async with session.get( | ||
self.DID_RESOLVER_BASE_URL + did, | ||
) as response: | ||
if response.status == 200: | ||
did_cheqd = await response.json() | ||
else: | ||
raise Exception(response) | ||
except Exception: | ||
raise | ||
|
||
except Exception as e: | ||
raise DIDNotFound(f"Unable to resolve did: {did}") from e | ||
|
||
return did_key.did_doc | ||
return did_cheqd.did_doc |