tba-provider-did-controller 0.4.0.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
|
|
4
|
+
from tba_concrete_did import validate_did_document
|
|
5
|
+
from tba_contracts_identity.did import Did, DidDocument
|
|
6
|
+
|
|
7
|
+
ControlProofVerifier = Callable[[DidDocument | None, DidDocument, bytes | str], bool]
|
|
8
|
+
DocumentPublisher = Callable[[DidDocument, str], object]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True)
|
|
12
|
+
class DidControllerResult:
|
|
13
|
+
identifier: Did
|
|
14
|
+
version_id: str
|
|
15
|
+
created: bool
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class DidControllerProvider:
|
|
19
|
+
def __init__(
|
|
20
|
+
self, proof_verifier: ControlProofVerifier, publisher: DocumentPublisher
|
|
21
|
+
):
|
|
22
|
+
self._proof_verifier = proof_verifier
|
|
23
|
+
self._publisher = publisher
|
|
24
|
+
self._current: dict[Did, DidDocument] = {}
|
|
25
|
+
|
|
26
|
+
def apply(
|
|
27
|
+
self, document: DidDocument, version_id: str, proof: bytes | str
|
|
28
|
+
) -> DidControllerResult:
|
|
29
|
+
validate_did_document(document)
|
|
30
|
+
if not version_id or not proof:
|
|
31
|
+
raise ValueError("DID update requires version ID and control proof")
|
|
32
|
+
current = self._current.get(document.identifier)
|
|
33
|
+
if current is not None and current.identifier != document.identifier:
|
|
34
|
+
raise ValueError("DID update cannot change the identifier")
|
|
35
|
+
if not self._proof_verifier(current, document, proof):
|
|
36
|
+
raise PermissionError("DID control proof was not authorized")
|
|
37
|
+
self._publisher(document, version_id)
|
|
38
|
+
self._current[document.identifier] = document
|
|
39
|
+
return DidControllerResult(document.identifier, version_id, current is None)
|
|
40
|
+
|
|
41
|
+
def current(self, identifier: Did) -> DidDocument:
|
|
42
|
+
try:
|
|
43
|
+
return self._current[identifier]
|
|
44
|
+
except KeyError as exc:
|
|
45
|
+
raise LookupError(str(identifier)) from exc
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"ControlProofVerifier",
|
|
50
|
+
"DidControllerProvider",
|
|
51
|
+
"DidControllerResult",
|
|
52
|
+
"DocumentPublisher",
|
|
53
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-provider-did-controller
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Authorization-checked DID document controller provider.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10,<3.15
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
|
+
Requires-Dist: tba-concrete-did (==0.4.0.dev2)
|
|
14
|
+
Requires-Dist: tba-contracts-identity (==0.4.0.dev2)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
tba_provider_did_controller/__init__.py,sha256=PnJ6UF2mFdLV4Cph7mxj35XZr1EU6q7tYOEkRfvvRWo,1852
|
|
2
|
+
tba_provider_did_controller/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
tba_provider_did_controller-0.4.0.dev2.dist-info/METADATA,sha256=JiTGGQ6F9QdCqD-eDjZBZdUhQ5WRB5S9KEKhsYh_0S4,605
|
|
4
|
+
tba_provider_did_controller-0.4.0.dev2.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
5
|
+
tba_provider_did_controller-0.4.0.dev2.dist-info/RECORD,,
|