Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v2
with:
version: 0.8.2
version: 0.15.1
src: "./pydid"
- uses: astral-sh/ruff-action@v2
with:
version: 0.8.2
version: 0.15.1
src: "./pydid"
args: format --check

Expand All @@ -27,7 +27,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Upload PyDID To PyPI

on:
release:
types: [created]
types: [ created ]

jobs:
deploy:
Expand All @@ -12,10 +12,10 @@ jobs:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.10
cache: poetry
- name: Install dependencies
run: poetry install
Expand Down
21 changes: 21 additions & 0 deletions docker/Dockerfile.python3.12
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.12-slim

# Install poetry
RUN pip install --no-cache-dir poetry

WORKDIR /usr/src/app

ADD pydid pydid
ADD pyproject.toml .
ADD poetry.lock .
ADD README.md .
ADD tests tests

# Install dependencies in the container virtualenv created by poetry
RUN poetry install --no-root --no-interaction --no-ansi || poetry install --no-interaction --no-ansi

# Make site packages location more accessible (for use with volumes)
# Adjust the path for Python 3.12
RUN ln -s $(poetry env info -p)/lib/python3.12/site-packages site-packages || true

ENTRYPOINT ["/bin/sh", "-c", "poetry run pytest tests \"$@\"", "--"]
17 changes: 0 additions & 17 deletions docker/Dockerfile.python3.9

This file was deleted.

1,327 changes: 872 additions & 455 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion pydid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
NonconformantDocument,
)
from .resource import Resource
from .service import DIDCommService, Service
from .service import (
DIDCommService,
DIDCommV1Service,
DIDCommV2Service,
DIDCommV2ServiceEndpoint,
Service,
)
from .verification_method import (
VerificationMaterial,
VerificationMaterialUnknown,
Expand All @@ -27,6 +33,9 @@
"BasicDIDDocument",
"DID",
"DIDCommService",
"DIDCommV1Service",
"DIDCommV2Service",
"DIDCommV2ServiceEndpoint",
"DIDDocument",
"DIDDocumentBuilder",
"DIDDocumentError",
Expand Down
127 changes: 112 additions & 15 deletions pydid/doc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

from ..did import DID
from ..did_url import DIDUrl
from ..service import DIDCommService, Service
from ..service import (
DIDCommV1Service,
DIDCommV2Service,
DIDCommV2ServiceEndpoint,
Service,
)
from ..verification_method import VerificationMethod
import warnings
from .doc import DIDDocument


Expand Down Expand Up @@ -115,7 +121,7 @@ def _determine_next_priority(self):
[
service.priority
for service in self.services
if isinstance(service, DIDCommService)
if isinstance(service, DIDCommV1Service)
]
)
+ 1
Expand All @@ -137,39 +143,130 @@ def add(
self.services.append(service)
return service

def add_didcomm(
def add_didcomm_v1(
self,
service_endpoint: str,
recipient_keys: List[Union[VerificationMethod, DIDUrl, str]],
routing_keys: Optional[List[Union[VerificationMethod, DIDUrl, str]]] = None,
*,
priority: Optional[int] = None,
type_: Optional[str] = None,
type_: Optional[Union[str, List[str]]] = None,
ident: Optional[str] = None,
accept: Optional[List[str]] = None,
):
"""Add DIDComm Service."""
"""Add DIDComm V1 (did-communication) service."""
ident = ident or next(self._id_generator)
routing_keys = routing_keys or []
priority = priority or self._determine_next_priority()
service = DIDCommService.make(

routing_key_ids = [
vmethod.id if isinstance(vmethod, VerificationMethod) else vmethod
for vmethod in routing_keys
]
recipient_key_ids = [
vmethod.id if isinstance(vmethod, VerificationMethod) else vmethod
for vmethod in recipient_keys
]

svc_type = type_
service = DIDCommV1Service.make(
id=self._did.ref(ident),
service_endpoint=service_endpoint,
recipient_keys=[
vmethod.id if isinstance(vmethod, VerificationMethod) else vmethod
for vmethod in recipient_keys
],
routing_keys=[
vmethod.id if isinstance(vmethod, VerificationMethod) else vmethod
for vmethod in routing_keys
],
type=type_,
recipient_keys=recipient_key_ids,
routing_keys=routing_key_ids,
type=svc_type,
priority=priority,
accept=accept,
)
self.services.append(service)
return service

def add_didcomm_v2(
self,
service_endpoint: str,
recipient_keys: List[Union[VerificationMethod, DIDUrl, str]],
routing_keys: Optional[List[Union[VerificationMethod, DIDUrl, str]]] = None,
*,
type_: Optional[Union[str, List[str]]] = None,
ident: Optional[str] = None,
accept: Optional[List[str]] = None,
):
"""Add DIDComm V2 (DIDCommMessaging) service."""
ident = ident or next(self._id_generator)
routing_keys = routing_keys or []

routing_key_ids = [
vmethod.id if isinstance(vmethod, VerificationMethod) else vmethod
for vmethod in routing_keys
]

endpoint = DIDCommV2ServiceEndpoint.make(
uri=service_endpoint, accept=accept, routing_keys=routing_key_ids
)
svc_type = type_ or "DIDCommMessaging"
service = DIDCommV2Service.make(
id=self._did.ref(ident), service_endpoint=endpoint, type=svc_type
)
self.services.append(service)
return service

def add_didcomm(
self,
service_endpoint: str,
recipient_keys: List[Union[VerificationMethod, DIDUrl, str]],
routing_keys: Optional[List[Union[VerificationMethod, DIDUrl, str]]] = None,
*,
priority: Optional[int] = None,
type_: Optional[str] = None,
ident: Optional[str] = None,
accept: Optional[List[str]] = None,
version: Optional[int] = None,
):
"""Autodetect DIDComm version and delegate to the appropriate helper.

DEPRECATION: This convenience wrapper should get deprecated. Call
`add_didcomm_v1` or `add_didcomm_v2` explicitly to construct the
desired service type. This wrapper will be removed in a future
release.
"""
warnings.warn(
"ServiceBuilder.add_didcomm will be deprecated; use "
+ "ServiceBuilder.add_didcomm_v1 or ServiceBuilder.add_didcomm_v2",
DeprecationWarning,
stacklevel=2,
)
# Autodetect when version not provided
if version is None:
if accept and any(
a for a in accept if isinstance(a, str) and a.startswith("didcomm/v2")
):
version = 2
else:
version = 1

# Match DIDComm version
if version == 1:
return self.add_didcomm_v1(
service_endpoint,
recipient_keys,
routing_keys,
priority=priority,
type_=type_,
ident=ident,
accept=accept,
)
elif version == 2:
return self.add_didcomm_v2(
service_endpoint,
recipient_keys,
routing_keys,
type_=type_,
ident=ident,
accept=accept,
)
else:
raise NotImplementedError(f"DIDComm version {version} not supported.")

def remove(self, service: Service):
"""Remove service from builder."""
self.services.remove(service)
Expand Down
11 changes: 7 additions & 4 deletions pydid/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

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

DIDCOMM_V1_TYPE_STRINGS = Literal["IndyAgent", "did-communication", "DIDCommMessaging"]
DIDCOMM_V2_TYPE_STRINGS = Literal["DIDCommMessaging"]


class Service(Resource):
"""Representation of DID Document Services."""
Expand All @@ -28,8 +31,7 @@ class DIDCommV1Service(Service):
"""DID Communication Service."""

model_config = ConfigDict(extra="forbid")

type: Literal["IndyAgent", "did-communication", "DIDCommMessaging"] = (
type: Union[DIDCOMM_V1_TYPE_STRINGS, List[DIDCOMM_V1_TYPE_STRINGS]] = (
"did-communication"
)
service_endpoint: EndpointStrings
Expand All @@ -54,8 +56,9 @@ class DIDCommV2Service(Service):
"""DID Communication V2 Service."""

model_config = ConfigDict(extra="forbid")

type: Literal["DIDCommMessaging"] = "DIDCommMessaging"
type: Union[DIDCOMM_V2_TYPE_STRINGS, List[DIDCOMM_V2_TYPE_STRINGS]] = (
"DIDCommMessaging"
)
service_endpoint: Union[List[DIDCommV2ServiceEndpoint], DIDCommV2ServiceEndpoint]


Expand Down
24 changes: 13 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydid"
version = "0.5.2"
version = "0.5.3"
description = "Python library for validating, constructing, and representing DIDs and DID Documents"
authors = ["Daniel Bluhm <dbluhm@pm.me>"]
license = "Apache 2.0"
Expand All @@ -11,24 +11,26 @@ keywords = [
"decentralized", "identity", "ssi", "DID", "DID Document"
]


[build-system]
requires = ["setuptools", "poetry-core>=1.0.0"]
requires = ["setuptools", "poetry-core>=2.3.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = "^3.9.0"
python = "^3.10.0"
pydantic = "^2.7.0"
typing-extensions = "^4.7.0"
inflection = "^0.5.1"

[tool.poetry.dev-dependencies]
pytest = "^8.3.4"
poetry = "^1.8.5"
typing-extensions = "^4.12.0"
inflection = "^0.5.0"

[tool.poetry.group.dev.dependencies]
aiohttp = "^3.13.3"
pytest = "^9.0.2"
pytest-asyncio = "^1.3.0"
poetry = "^2.3.0"
pre-commit = "^4.0.1"
ruff = "^0.8.4"
rapidfuzz = "^3.14.3"
pytest-coverage = "^0.0"
aiohttp = "^3.11.11"
pytest-asyncio = "^0.25.0"
coverage = {extras = ["toml"], version = "^7.6.10"}

[tool.pytest.ini_options]
Expand Down
Loading