tba-contracts-replay 0.4.0.dev2__tar.gz
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.
- tba_contracts_replay-0.4.0.dev2/PKG-INFO +18 -0
- tba_contracts_replay-0.4.0.dev2/README.md +3 -0
- tba_contracts_replay-0.4.0.dev2/pyproject.toml +15 -0
- tba_contracts_replay-0.4.0.dev2/src/tba_contracts_replay/__init__.py +4 -0
- tba_contracts_replay-0.4.0.dev2/src/tba_contracts_replay/py.typed +1 -0
- tba_contracts_replay-0.4.0.dev2/src/tba_contracts_replay/reservations.py +89 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-contracts-replay
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Protocol-neutral replay protection contracts.
|
|
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
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# tba-contracts-replay
|
|
16
|
+
|
|
17
|
+
Owns replay keys, atomic reservations, single-use nonces, and replay-check ports.
|
|
18
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tba-contracts-replay"
|
|
3
|
+
version = "0.4.0.dev2"
|
|
4
|
+
description = "Protocol-neutral replay protection contracts."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.15"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = []
|
|
9
|
+
|
|
10
|
+
[build-system]
|
|
11
|
+
requires = ["poetry-core>=1.0.0"]
|
|
12
|
+
build-backend = "poetry.core.masonry.api"
|
|
13
|
+
|
|
14
|
+
[tool.poetry]
|
|
15
|
+
packages = [{ include = "tba_contracts_replay", from = "src" }]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Canonical protocol-neutral replay reservation contracts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Mapping, Protocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class ReplayKey:
|
|
12
|
+
namespace: str
|
|
13
|
+
value: str
|
|
14
|
+
tenant_id: str | None = None
|
|
15
|
+
issuer: str | None = None
|
|
16
|
+
|
|
17
|
+
def __post_init__(self) -> None:
|
|
18
|
+
if not self.namespace.strip() or not self.value:
|
|
19
|
+
raise ValueError("replay namespace and key value are required")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class ReplayReservationRequest:
|
|
24
|
+
key: ReplayKey
|
|
25
|
+
expires_at: datetime
|
|
26
|
+
context: Mapping[str, str] = field(default_factory=dict)
|
|
27
|
+
|
|
28
|
+
def __post_init__(self) -> None:
|
|
29
|
+
if self.expires_at.tzinfo is None:
|
|
30
|
+
raise ValueError("replay reservation expiry must be timezone-aware")
|
|
31
|
+
object.__setattr__(self, "context", dict(self.context))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, slots=True)
|
|
35
|
+
class ReplayReservationResult:
|
|
36
|
+
accepted: bool
|
|
37
|
+
key_digest: str
|
|
38
|
+
expires_at: datetime
|
|
39
|
+
duplicate: bool = False
|
|
40
|
+
provider_id: str = ""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True, slots=True)
|
|
44
|
+
class ReplayStoreDescriptor:
|
|
45
|
+
provider_id: str
|
|
46
|
+
persistence: str
|
|
47
|
+
atomic_reservation: bool
|
|
48
|
+
namespaces: tuple[str, ...]
|
|
49
|
+
tenant_isolation: str
|
|
50
|
+
expiry: str
|
|
51
|
+
retention: str
|
|
52
|
+
purge: str
|
|
53
|
+
audit: str
|
|
54
|
+
availability: str
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ReplayReservationPort(Protocol):
|
|
58
|
+
async def check_and_reserve(
|
|
59
|
+
self, request: ReplayReservationRequest, /
|
|
60
|
+
) -> ReplayReservationResult: ...
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ReplayCheckPort(Protocol):
|
|
64
|
+
"""Synchronous atomic replay boundary for synchronous protocol decoders."""
|
|
65
|
+
|
|
66
|
+
def check_and_store(self, key: str, *, now: int | None = None, ttl_s: int) -> bool: ...
|
|
67
|
+
def snapshot(self) -> Mapping[str, int]: ...
|
|
68
|
+
def clear(self) -> None: ...
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class SingleUseNoncePort(Protocol):
|
|
72
|
+
"""Synchronous single-use nonce boundary."""
|
|
73
|
+
|
|
74
|
+
def issue(self, *, ttl_s: int) -> str: ...
|
|
75
|
+
def register(self, nonce: str, *, ttl_s: int) -> str: ...
|
|
76
|
+
def consume(self, nonce: str, *, now: int | None = None) -> bool: ...
|
|
77
|
+
def snapshot(self) -> Mapping[str, object]: ...
|
|
78
|
+
def clear(self) -> None: ...
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
__all__ = [
|
|
82
|
+
"ReplayKey",
|
|
83
|
+
"ReplayCheckPort",
|
|
84
|
+
"ReplayReservationPort",
|
|
85
|
+
"ReplayReservationRequest",
|
|
86
|
+
"ReplayReservationResult",
|
|
87
|
+
"ReplayStoreDescriptor",
|
|
88
|
+
"SingleUseNoncePort",
|
|
89
|
+
]
|