Skip to content
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

feat: realign service with DID Core spec #75

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions pydid/service.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
"""DID Doc Service."""

from typing import List, Optional, Union

from pydantic import Extra, AnyUrl
from typing import Any, List, Mapping, Optional, Union
from typing_extensions import Literal

from pydantic import AnyUrl, Extra, StrictStr

from .did import DID
from .did_url import DIDUrl
from .resource import Resource


class ServiceEndpoint(Resource):
"""List of Service Endpoints."""

uri: Union[DIDUrl, AnyUrl]
EndpointStrings = Union[DID, DIDUrl, AnyUrl, StrictStr]


class Service(Resource):
"""Representation of DID Document Services."""

id: DIDUrl
type: str
service_endpoint: Union[DIDUrl, AnyUrl, Literal[""], List[ServiceEndpoint]]
service_endpoint: Union[
EndpointStrings,
List[Union[EndpointStrings, Mapping[str, Any]]],
Mapping[str, Any],
]


class DIDCommV1Service(Service):
Expand All @@ -34,6 +36,7 @@ class Config:
type: Literal[
"IndyAgent", "did-communication", "DIDCommMessaging"
] = "did-communication"
service_endpoint: EndpointStrings
recipient_keys: List[DIDUrl]
routing_keys: List[DIDUrl] = []
accept: Optional[List[str]] = None
Expand All @@ -43,10 +46,10 @@ class Config:
DIDCommService = DIDCommV1Service


class DIDCommV2ServiceEndpoint(ServiceEndpoint):
class DIDCommV2ServiceEndpoint(Resource):
"""DID Communication Service Endpoint."""

uri: Union[DIDUrl, AnyUrl]
uri: EndpointStrings
accept: Optional[List[str]] = None
routing_keys: List[DIDUrl] = []

Expand Down
44 changes: 39 additions & 5 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
"routingKeys": ["did:example:somemediator#somekey1"],
"accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"],
},
{
"id": "did:example:123#didcomm-1",
"type": "did-communication",
"serviceEndpoint": "didcomm:transport/queue",
"recipientKeys": ["did:example:123#keys-1"],
"routingKeys": [],
"accept": ["didcomm/aip2;env=rfc587"],
},
{
"id": "did:example:123456789abcdefghi#didcomm-1",
"type": "DIDCommMessaging",
Expand Down Expand Up @@ -64,11 +72,6 @@
"type": "LinkedDomains",
"serviceEndpoint": True,
},
{
"id": "did:example:123456789abcdefghi#didcomm-1",
"type": "DIDCommMessaging",
"serviceEndpoint": ["http://example.com"],
},
]


Expand Down Expand Up @@ -127,6 +130,15 @@ def test_serialization(service_raw):
"priority": 0,
"accept": ["didcomm/v2", "didcomm/aip2;env=rfc587"],
},
{
"id": "did:example:123#didcomm-1",
"type": "did-communication",
"serviceEndpoint": "didcomm:transport/queue",
"recipientKeys": ["did:example:123#keys-1"],
"routingKeys": [],
"priority": 0,
"accept": ["didcomm/aip2;env=rfc587"],
},
{
"id": "did:example:123456789abcdefghi#didcomm-1",
"type": "DIDCommMessaging",
Expand All @@ -138,6 +150,28 @@ def test_serialization(service_raw):
}
],
},
{
"id": "did:example:123456789abcdefghi#didcomm-1",
"type": "DIDCommMessaging",
"serviceEndpoint": [
{
"uri": "didcomm:transport/queue",
"accept": ["didcomm/v2"],
"routingKeys": [],
}
],
},
{
"id": "did:example:123456789abcdefghi#didcomm-1",
"type": "DIDCommMessaging",
"serviceEndpoint": [
{
"uri": "did:example:mediator",
"accept": ["didcomm/v2"],
"routingKeys": [],
}
],
},
]

DIDCOMM_INVALID_SERVICES = [
Expand Down