Skip to content

Commit

Permalink
Change did:tdw resolver naming to did:webvh
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Jan 7, 2025
1 parent b7e1805 commit a10c940
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 51 deletions.
24 changes: 12 additions & 12 deletions acapy_agent/messaging/tests/test_valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
CREDENTIAL_TYPE_VALIDATE,
DID_KEY_VALIDATE,
DID_POSTURE_VALIDATE,
DID_TDW_VALIDATE,
DID_WEBVH_VALIDATE,
ENDPOINT_TYPE_VALIDATE,
ENDPOINT_VALIDATE,
INDY_CRED_DEF_ID_VALIDATE,
Expand Down Expand Up @@ -115,23 +115,23 @@ def test_indy_did(self):
INDY_DID_VALIDATE("Q4zqM7aXqm7gDQkUVLng9h")
INDY_DID_VALIDATE("did:sov:Q4zqM7aXqm7gDQkUVLng9h")

def test_tdw_did(self):
valid_tdw_dids = [
"did:tdw:QmUchSB5f5DJQks9CeyLJjhAy4iKJcYzRyiuYq3sjV13px:example.com",
"did:tdw:QmZiKXwQVfyZVuvCsuHpQh4arSUpEmeVVRvSfv3uiEycSr:example.com%3A5000",
def test_webvh_did(self):
valid_webvh_dids = [
"did:webvh:QmUchSB5f5DJQks9CeyLJjhAy4iKJcYzRyiuYq3sjV13px:example.com",
"did:webvh:QmZiKXwQVfyZVuvCsuHpQh4arSUpEmeVVRvSfv3uiEycSr:example.com%3A5000",
]
for valid_tdw_did in valid_tdw_dids:
DID_TDW_VALIDATE(valid_tdw_did)
for valid_webvh_did in valid_webvh_dids:
DID_WEBVH_VALIDATE(valid_webvh_did)

non_valid_tdw_dids = [
non_valid_webvh_dids = [
"did:web:QmUchSB5f5DJQks9CeyLJjhAy4iKJcYzRyiuYq3sjV13px",
# Did urls are not allowed
"did:tdw:QmP9VWaTCHcyztDpRj9XSHvZbmYe3m9HZ61KoDtZgWaXVU:example.com%3A5000#z6MkkzY9skorPaoEbCJFKUo7thD8Yb8MBs28aJRopf1TUo9V",
"did:tdw:QmZiKXwQVfyZVuvCsuHpQh4arSUpEmeVVRvSfv3uiEycSr:example.com%3A5000/whois",
"did:webvh:QmP9VWaTCHcyztDpRj9XSHvZbmYe3m9HZ61KoDtZgWaXVU:example.com%3A5000#z6MkkzY9skorPaoEbCJFKUo7thD8Yb8MBs28aJRopf1TUo9V",
"did:webvh:QmZiKXwQVfyZVuvCsuHpQh4arSUpEmeVVRvSfv3uiEycSr:example.com%3A5000/whois",
]
for non_valid_tdw_did in non_valid_tdw_dids:
for non_valid_webvh_did in non_valid_webvh_dids:
with self.assertRaises(ValidationError):
DID_TDW_VALIDATE(non_valid_tdw_did)
DID_WEBVH_VALIDATE(non_valid_webvh_did)

def test_indy_raw_public_key(self):
non_indy_raw_public_keys = [
Expand Down
16 changes: 9 additions & 7 deletions acapy_agent/messaging/valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,19 @@ def __init__(self):
)


class DIDTdw(Regexp):
"""Validate value against did:tdw specification."""
class DIDWebvh(Regexp):
"""Validate value against did:webvh specification."""

EXAMPLE = "did:tdw:QmP9VWaTCHcyztDpRj9XSHvZbmYe3m9HZ61KoDtZgWaXVU:example.com%3A5000"
PATTERN = re.compile(r"^(did:tdw:)([a-zA-Z0-9%._-]*:)*[a-zA-Z0-9%._-]+$")
EXAMPLE = (
"did:webvh:QmP9VWaTCHcyztDpRj9XSHvZbmYe3m9HZ61KoDtZgWaXVU:example.com%3A5000"
)
PATTERN = re.compile(r"^(did:webvh:)([a-zA-Z0-9%._-]*:)*[a-zA-Z0-9%._-]+$")

def __init__(self):
"""Initialize the instance."""

super().__init__(
DIDTdw.PATTERN, error="Value {input} is not in W3C did:tdw format"
DIDWebvh.PATTERN, error="Value {input} is not in W3C did:webvh format"
)


Expand Down Expand Up @@ -1017,8 +1019,8 @@ def __init__(
DID_WEB_VALIDATE = DIDWeb()
DID_WEB_EXAMPLE = DIDWeb.EXAMPLE

DID_TDW_VALIDATE = DIDTdw()
DID_TDW_EXAMPLE = DIDTdw.EXAMPLE
DID_WEBVH_VALIDATE = DIDWebvh()
DID_WEBVH_EXAMPLE = DIDWebvh.EXAMPLE

ROUTING_KEY_VALIDATE = RoutingKey()
ROUTING_KEY_EXAMPLE = RoutingKey.EXAMPLE
Expand Down
8 changes: 4 additions & 4 deletions acapy_agent/resolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ async def setup(context: InjectionContext):
await web_resolver.setup(context)
registry.register_resolver(web_resolver)

tdw_resolver = ClassProvider(
"acapy_agent.resolver.default.tdw.TdwDIDResolver"
webvh_resolver = ClassProvider(
"acapy_agent.resolver.default.webvh.WebvhDIDResolver"
).provide(context.settings, context.injector)
await tdw_resolver.setup(context)
registry.register_resolver(tdw_resolver)
await webvh_resolver.setup(context)
registry.register_resolver(webvh_resolver)

if context.settings.get("resolver.universal"):
universal_resolver = ClassProvider(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import pytest

from ....core.profile import Profile
from ....messaging.valid import DIDTdw
from ....messaging.valid import DIDWebvh
from ....utils.testing import create_test_profile
from ..tdw import TdwDIDResolver
from ..webvh import WebvhDIDResolver

TEST_DID = "did:tdw:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example"
TEST_DID = "did:webvh:Qma6mc1qZw3NqxwX6SB5GPQYzP4pGN2nXD15Jwi4bcDBKu:domain.example"


@pytest.fixture
def resolver():
"""Resolver fixture."""
yield TdwDIDResolver()
yield WebvhDIDResolver()


@pytest.fixture
Expand All @@ -21,16 +21,16 @@ async def profile():


@pytest.mark.asyncio
async def test_supported_did_regex(profile, resolver: TdwDIDResolver):
async def test_supported_did_regex(profile, resolver: WebvhDIDResolver):
"""Test the supported_did_regex."""
assert resolver.supported_did_regex == DIDTdw.PATTERN
assert resolver.supported_did_regex == DIDWebvh.PATTERN
assert await resolver.supports(
profile,
TEST_DID,
)


@pytest.mark.asyncio
async def test_resolve(resolver: TdwDIDResolver, profile: Profile):
async def test_resolve(resolver: WebvhDIDResolver, profile: Profile):
"""Test resolve method."""
assert await resolver.resolve(profile, TEST_DID)
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
"""TDW DID Resolver.
"""WEBVH DID Resolver.
Resolution is performed by the did_tdw library.
Resolution is performed by the did_webvh library.
"""

from re import Pattern
from typing import Optional, Sequence, Text

from did_tdw.resolver import ResolutionResult, resolve_did
from did_webvh.resolver import ResolutionResult, resolve_did

from ...config.injection_context import InjectionContext
from ...core.profile import Profile
from ...messaging.valid import DIDTdw
from ...messaging.valid import DIDWebvh
from ..base import BaseDIDResolver, ResolverType


class TdwDIDResolver(BaseDIDResolver):
"""TDW DID Resolver."""
class WebvhDIDResolver(BaseDIDResolver):
"""WEBVH DID Resolver."""

def __init__(self):
"""Initialize the TDW DID Resolver."""
"""Initialize the WEBVH DID Resolver."""
super().__init__(ResolverType.NATIVE)

async def setup(self, context: InjectionContext):
"""Perform required setup for TDW DID resolution."""
"""Perform required setup for WEBVH DID resolution."""

@property
def supported_did_regex(self) -> Pattern:
"""Return supported DID regex of TDW DID Resolver."""
return DIDTdw.PATTERN
"""Return supported DID regex of WEBVH DID Resolver."""
return DIDWebvh.PATTERN

async def _resolve(
self, profile: Profile, did: str, service_accept: Optional[Sequence[Text]] = None
) -> dict:
"""Resolve DID using TDW."""
"""Resolve DID using WEBVH."""
response: ResolutionResult = await resolve_did(did)
if response.resolution_metadata and response.resolution_metadata.get("error"):
return response.resolution_metadata
Expand Down
6 changes: 3 additions & 3 deletions acapy_agent/wallet/did_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def holder_defined_did(self) -> HolderDefinedDid:
holder_defined_did=HolderDefinedDid.NO,
)

TDW = DIDMethod(
name="tdw",
WEBVH = DIDMethod(
name="webvh",
key_types=[ED25519, X25519],
rotation=False,
holder_defined_did=HolderDefinedDid.NO,
Expand All @@ -109,7 +109,7 @@ def __init__(self) -> None:
WEB.method_name: WEB,
PEER2.method_name: PEER2,
PEER4.method_name: PEER4,
TDW.method_name: TDW,
WEBVH.method_name: WEBVH,
}

def registered(self, method: str) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uuid_utils = "^0.10.0"
# did libraries
did-peer-2 = "^0.1.2"
did-peer-4 = "^0.1.4"
did-tdw = "^0.2.1"
did-webvh-jamie-testing = "^0.2.1"

# Verifiable Credentials
indy-credx = "~1.1.1"
Expand Down

0 comments on commit a10c940

Please sign in to comment.