x402-warden 1.0.0__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.
Files changed (40) hide show
  1. x402_warden-1.0.0/LICENSE +21 -0
  2. x402_warden-1.0.0/NOTICE +7 -0
  3. x402_warden-1.0.0/PKG-INFO +67 -0
  4. x402_warden-1.0.0/README.md +31 -0
  5. x402_warden-1.0.0/pyproject.toml +61 -0
  6. x402_warden-1.0.0/setup.cfg +4 -0
  7. x402_warden-1.0.0/src/x402_warden/__init__.py +19 -0
  8. x402_warden-1.0.0/src/x402_warden/_freeze.py +53 -0
  9. x402_warden-1.0.0/src/x402_warden/guard.py +602 -0
  10. x402_warden-1.0.0/src/x402_warden/policy.py +571 -0
  11. x402_warden-1.0.0/src/x402_warden/provider.py +2 -0
  12. x402_warden-1.0.0/src/x402_warden/py.typed +0 -0
  13. x402_warden-1.0.0/src/x402_warden/reasons.py +5 -0
  14. x402_warden-1.0.0/src/x402_warden/spec.py +9 -0
  15. x402_warden-1.0.0/src/x402_warden/store.py +357 -0
  16. x402_warden-1.0.0/src/x402_warden/transport.py +80 -0
  17. x402_warden-1.0.0/src/x402_warden/types.py +128 -0
  18. x402_warden-1.0.0/src/x402_warden/vectors.py +151 -0
  19. x402_warden-1.0.0/src/x402_warden.egg-info/PKG-INFO +67 -0
  20. x402_warden-1.0.0/src/x402_warden.egg-info/SOURCES.txt +38 -0
  21. x402_warden-1.0.0/src/x402_warden.egg-info/dependency_links.txt +1 -0
  22. x402_warden-1.0.0/src/x402_warden.egg-info/requires.txt +16 -0
  23. x402_warden-1.0.0/src/x402_warden.egg-info/top_level.txt +1 -0
  24. x402_warden-1.0.0/tests/test_authorization.py +275 -0
  25. x402_warden-1.0.0/tests/test_cancel.py +55 -0
  26. x402_warden-1.0.0/tests/test_freeze.py +79 -0
  27. x402_warden-1.0.0/tests/test_gaps.py +253 -0
  28. x402_warden-1.0.0/tests/test_lifecycle.py +362 -0
  29. x402_warden-1.0.0/tests/test_loopback.py +150 -0
  30. x402_warden-1.0.0/tests/test_packaging.py +41 -0
  31. x402_warden-1.0.0/tests/test_policy.py +75 -0
  32. x402_warden-1.0.0/tests/test_process_crash.py +61 -0
  33. x402_warden-1.0.0/tests/test_properties.py +174 -0
  34. x402_warden-1.0.0/tests/test_round2.py +477 -0
  35. x402_warden-1.0.0/tests/test_round3.py +257 -0
  36. x402_warden-1.0.0/tests/test_sdk.py +327 -0
  37. x402_warden-1.0.0/tests/test_store_lock.py +75 -0
  38. x402_warden-1.0.0/tests/test_url_normalization.py +213 -0
  39. x402_warden-1.0.0/tests/test_v3.py +342 -0
  40. x402_warden-1.0.0/tests/test_vectors.py +51 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) x402-warden contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,7 @@
1
+ x402-warden
2
+ Copyright (c) x402-warden contributors
3
+
4
+ Licensed under the MIT License. See LICENSE.
5
+
6
+ Third-party dependencies are distributed under their own licenses.
7
+ This package does not bundle the official x402 SDK source.
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: x402-warden
3
+ Version: 1.0.0
4
+ Summary: Local payment policy and reservation accounting for the official x402 Python SDK
5
+ Author: x402-warden contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/x402-warden/x402-warden
8
+ Project-URL: Repository, https://github.com/x402-warden/x402-warden
9
+ Project-URL: Issues, https://github.com/x402-warden/x402-warden/issues
10
+ Keywords: x402,payments,policy,security
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: idna==3.20
23
+ Provides-Extra: sdk
24
+ Requires-Dist: x402[httpx,requests]<3,>=2.20; extra == "sdk"
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=8; extra == "test"
27
+ Requires-Dist: hypothesis==6.170.15; extra == "test"
28
+ Requires-Dist: coverage==7.17.3; extra == "test"
29
+ Requires-Dist: x402-warden[sdk]; extra == "test"
30
+ Requires-Dist: eth-keys>=0.5; extra == "test"
31
+ Requires-Dist: eth-hash[pycryptodome]>=0.7; extra == "test"
32
+ Provides-Extra: crypto
33
+ Requires-Dist: eth-keys>=0.5; extra == "crypto"
34
+ Requires-Dist: eth-hash[pycryptodome]>=0.7; extra == "crypto"
35
+ Dynamic: license-file
36
+
37
+ # x402-warden for Python
38
+
39
+ Attach local payment policy and reservation accounting to the official x402 buyer
40
+ client. Blocks quotes when configured limits, recipient pins or observed URL
41
+ checks reject the proposed payment; retains capacity for unresolved authorizations.
42
+
43
+ Install `x402-warden[sdk]` for SDK attachment. The SDK dependency is optional;
44
+ pure policy evaluation needs no x402 SDK. Use `x402[httpx]` for the HTTP adapter.
45
+ Policy dictionary keys are camelCase; guard keyword arguments use snake_case.
46
+ Everything after `policy` is passed by keyword.
47
+
48
+ Start with the [runnable Python httpx guide](../../docs/quickstart-python.md).
49
+ Supported SDK versions checked 2026-11-14: Python 2.20, 2.27, 2.28.
50
+
51
+ Use one shared payer ledger and explicit per-call and daily caps. `MemoryStore`
52
+ is the default ephemeral store; `FileStore` uses a cooperating local filesystem
53
+ protocol. Capture the request URL on the HTTP client supplied to the adapter.
54
+ The observed URL is required by default. Transport settings belong in guard
55
+ options, separate from the payment policy.
56
+
57
+ Read [options and defaults](../../docs/options.md), [reason codes](../../docs/reason-codes.md),
58
+ [hold resolution](../../docs/holds.md), [trust boundary](../../docs/trust-boundary.md),
59
+ [limitations](../../docs/limitations.md) and [threat model](../../docs/threat-model.md).
60
+ The [SDK integration notes](../../docs/compared-with-sdk.md) describe responsibilities.
61
+
62
+ Source: [shared policy specification](../../spec/policy/README.md),
63
+ [TypeScript implementation](../x402-warden/src/index.ts),
64
+ [Python implementation](../x402-warden-py/src/x402_warden/guard.py).
65
+
66
+ The `Provider` interface accepts any signed audit provider. A reference signed
67
+ provider lives in the tests.
@@ -0,0 +1,31 @@
1
+ # x402-warden for Python
2
+
3
+ Attach local payment policy and reservation accounting to the official x402 buyer
4
+ client. Blocks quotes when configured limits, recipient pins or observed URL
5
+ checks reject the proposed payment; retains capacity for unresolved authorizations.
6
+
7
+ Install `x402-warden[sdk]` for SDK attachment. The SDK dependency is optional;
8
+ pure policy evaluation needs no x402 SDK. Use `x402[httpx]` for the HTTP adapter.
9
+ Policy dictionary keys are camelCase; guard keyword arguments use snake_case.
10
+ Everything after `policy` is passed by keyword.
11
+
12
+ Start with the [runnable Python httpx guide](../../docs/quickstart-python.md).
13
+ Supported SDK versions checked 2026-11-14: Python 2.20, 2.27, 2.28.
14
+
15
+ Use one shared payer ledger and explicit per-call and daily caps. `MemoryStore`
16
+ is the default ephemeral store; `FileStore` uses a cooperating local filesystem
17
+ protocol. Capture the request URL on the HTTP client supplied to the adapter.
18
+ The observed URL is required by default. Transport settings belong in guard
19
+ options, separate from the payment policy.
20
+
21
+ Read [options and defaults](../../docs/options.md), [reason codes](../../docs/reason-codes.md),
22
+ [hold resolution](../../docs/holds.md), [trust boundary](../../docs/trust-boundary.md),
23
+ [limitations](../../docs/limitations.md) and [threat model](../../docs/threat-model.md).
24
+ The [SDK integration notes](../../docs/compared-with-sdk.md) describe responsibilities.
25
+
26
+ Source: [shared policy specification](../../spec/policy/README.md),
27
+ [TypeScript implementation](../x402-warden/src/index.ts),
28
+ [Python implementation](../x402-warden-py/src/x402_warden/guard.py).
29
+
30
+ The `Provider` interface accepts any signed audit provider. A reference signed
31
+ provider lives in the tests.
@@ -0,0 +1,61 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "x402-warden"
7
+ version = "1.0.0"
8
+ description = "Local payment policy and reservation accounting for the official x402 Python SDK"
9
+ license = "MIT"
10
+ license-files = ["LICENSE", "NOTICE"]
11
+ readme = "README.md"
12
+ authors = [{name = "x402-warden contributors"}]
13
+ keywords = ["x402", "payments", "policy", "security"]
14
+ classifiers = [
15
+ "Development Status :: 5 - Production/Stable",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ "Typing :: Typed",
22
+ ]
23
+ requires-python = ">=3.11"
24
+ dependencies = ["idna==3.20"]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/x402-warden/x402-warden"
28
+ Repository = "https://github.com/x402-warden/x402-warden"
29
+ Issues = "https://github.com/x402-warden/x402-warden/issues"
30
+
31
+ [project.optional-dependencies]
32
+ sdk = ["x402[httpx,requests]>=2.20,<3"]
33
+ test = ["pytest>=8", "hypothesis==6.170.15", "coverage==7.17.3", "x402-warden[sdk]", "eth-keys>=0.5", "eth-hash[pycryptodome]>=0.7"]
34
+ crypto = ["eth-keys>=0.5", "eth-hash[pycryptodome]>=0.7"]
35
+
36
+ [tool.setuptools.package-data]
37
+ x402_warden = ["py.typed"]
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.pytest.ini_options]
43
+ testpaths = ["tests"]
44
+ addopts = "--basetemp=.tmp/pytest"
45
+
46
+ [tool.coverage.run]
47
+ branch = true
48
+ source = ["x402_warden.policy"]
49
+
50
+ [tool.coverage.report]
51
+ show_missing = true
52
+
53
+ [tool.coverage.json]
54
+ output = "coverage/policy.json"
55
+
56
+ [tool.coverage.html]
57
+ directory = "coverage/html"
58
+
59
+ [tool.coverage.xml]
60
+ output = "coverage/policy.xml"
61
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ """Local x402 payment policy. Importing pure policy needs no SDK."""
2
+ from .guard import ProviderValidationError, guard
3
+ from .policy import authorization_id, evaluate, quote_id
4
+ from .store import (FileStore, MemoryStore, list_unresolved_reservations,
5
+ reconcile_reservations, record_settlement, resolve_reservation, record_payment_failure)
6
+ from .transport import ObservedUrls, capture_request_url
7
+ from .provider import ProviderError
8
+
9
+ __all__ = ["guard", "evaluate", "MemoryStore", "FileStore", "ProviderValidationError", "ProviderError", "quote_id", "authorization_id", "reconcile_reservations", "record_settlement", "ObservedUrls", "capture_request_url"]
10
+ __all__ += ["list_unresolved_reservations", "resolve_reservation"]
11
+
12
+ from .types import (Policy, State, Reservation, Decision, Diagnostic, Provider,
13
+ AuditResult, AuditChallenge, Options, Store, CreationContext,
14
+ ResponseContext, ResolutionEvidence, Resolution)
15
+ __all__ += ['Policy', 'State', 'Reservation', 'Decision', 'Diagnostic', 'Provider',
16
+ 'AuditResult', 'AuditChallenge', 'Options', 'Store', 'CreationContext',
17
+ 'ResponseContext', 'ResolutionEvidence', 'Resolution']
18
+
19
+ __all__ += ["record_payment_failure"]
@@ -0,0 +1,53 @@
1
+ """Recursive immutability for SDK dataclasses/models and JSON containers."""
2
+ from dataclasses import fields, is_dataclass
3
+ import threading
4
+
5
+
6
+ def _deny(*args, **kwargs):
7
+ raise TypeError("approved payment context is immutable")
8
+
9
+
10
+ class FrozenDict(dict):
11
+ __setitem__ = __delitem__ = clear = pop = popitem = setdefault = update = __ior__ = _deny
12
+
13
+ def __deepcopy__(self, memo):
14
+ from copy import deepcopy
15
+ return {deepcopy(k, memo): deepcopy(v, memo) for k, v in self.items()}
16
+
17
+
18
+ class FrozenList(list):
19
+ __setitem__ = __delitem__ = append = clear = extend = insert = pop = remove = reverse = sort = __iadd__ = __imul__ = _deny
20
+
21
+ def __deepcopy__(self, memo):
22
+ from copy import deepcopy
23
+ return [deepcopy(v, memo) for v in self]
24
+
25
+
26
+ _classes = {}
27
+ _lock = threading.RLock()
28
+
29
+
30
+ def freeze(value):
31
+ if isinstance(value, (FrozenDict, FrozenList)):
32
+ return value
33
+ if isinstance(value, dict):
34
+ return FrozenDict({k: freeze(v) for k, v in value.items()})
35
+ if isinstance(value, list):
36
+ return FrozenList(freeze(v) for v in value)
37
+ names = None
38
+ if hasattr(type(value), "model_fields"):
39
+ names = list(type(value).model_fields)
40
+ elif is_dataclass(value) and not isinstance(value, type):
41
+ names = [f.name for f in fields(value)]
42
+ if names is not None:
43
+ with _lock:
44
+ base = type(value)
45
+ if base not in _classes.values():
46
+ frozen = _classes.get(base)
47
+ if frozen is None:
48
+ frozen = type("WardenFrozen" + base.__name__, (base,), {"__slots__": (), "__setattr__": _deny, "__delattr__": _deny})
49
+ _classes[base] = frozen
50
+ for name in names:
51
+ object.__setattr__(value, name, freeze(getattr(value, name)))
52
+ object.__setattr__(value, "__class__", frozen)
53
+ return value