orangecheck 2.5.2__tar.gz → 2.6.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.
- {orangecheck-2.5.2 → orangecheck-2.6.0}/CHANGELOG.md +13 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/PKG-INFO +1 -1
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/__init__.py +1 -1
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/integrator.py +27 -4
- {orangecheck-2.5.2 → orangecheck-2.6.0}/pyproject.toml +1 -1
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_integrator_vectors.py +29 -1
- {orangecheck-2.5.2 → orangecheck-2.6.0}/.gitignore +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/README.md +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/__main__.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/address.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/bond.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/canonical.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/client.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/errors.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/__init__.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/bond.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/canonical.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/delegation.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/envelopes.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/resolution.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/pledge/state.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/py.typed +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/top_level.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/types.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/orangecheck/verify_sig.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/fixtures/bip137-parity.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/fixtures/bip322-js-6.1.8.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/fixtures/bip322-official-basic.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/fixtures/bip322-official-generated.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/pledge/__init__.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/pledge/test_authority.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/pledge/test_delegation.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/pledge/test_vectors.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/pledge/test_wrap.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_address.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_bip322_official.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_client.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_client_failure_modes.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_conformance.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_ripemd160.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/test_signature_parity.py +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/index.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv01.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv02.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv03.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv04.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv05.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv06.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv07.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv08.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv09.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv10.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv11.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv12.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv13.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv14.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv15.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv16.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv17.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv18.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv19.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv20.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv21.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv22.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv23.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv24.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv25.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv26.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv27.json +0 -0
- {orangecheck-2.5.2 → orangecheck-2.6.0}/tests/vectors/tv28.json +0 -0
|
@@ -4,6 +4,19 @@ All notable changes to the **`orangecheck`** Python package. Follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
[Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [2.6.0] — 2026-10-22
|
|
8
|
+
|
|
9
|
+
### Changed — key rotation and outages, as `@orangecheck/auth-core` 2.10.0
|
|
10
|
+
|
|
11
|
+
- `verify_session` reads `status: "retired"` and `retired_at` on a key in the
|
|
12
|
+
set. A retired key verifies only tokens whose `iat` is before its
|
|
13
|
+
`retired_at`; anything else is refused with reason `retired_key`. The
|
|
14
|
+
shared integrator vectors carry both cases, so the Node and Python SDKs
|
|
15
|
+
agree.
|
|
16
|
+
- A fetched key set stands in through a failed refresh for at most six hours.
|
|
17
|
+
Past that, `verify_session` and `verify_webhook` refuse with
|
|
18
|
+
`key_set_unavailable` until a fetch succeeds.
|
|
19
|
+
|
|
7
20
|
## [2.5.2] — 2026-10-22
|
|
8
21
|
|
|
9
22
|
### Fixed — an agent pledge's agent is never its swearer
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: orangecheck
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.0
|
|
4
4
|
Summary: Python SDK for OrangeCheck — proof of Bitcoin stake, the OC Pledge primitive, and ochk.app sign-in for your backend.
|
|
5
5
|
Project-URL: Homepage, https://ochk.io
|
|
6
6
|
Project-URL: Documentation, https://ochk.io/docs
|
|
@@ -139,7 +139,7 @@ __all__ = [
|
|
|
139
139
|
"VerificationError",
|
|
140
140
|
]
|
|
141
141
|
|
|
142
|
-
__version__ = "2.
|
|
142
|
+
__version__ = "2.6.0"
|
|
143
143
|
|
|
144
144
|
# OC Pledge submodule — sibling primitive for forward-looking commitments
|
|
145
145
|
# bound to a Bitcoin address. Imported here so consumers can write:
|
|
@@ -40,6 +40,8 @@ SESSION_JWKS_URL = "https://ochk.io/.well-known/jwks.json"
|
|
|
40
40
|
WEBHOOK_JWKS_URL = "https://me.ochk.io/api/dev-jwks"
|
|
41
41
|
|
|
42
42
|
_JWKS_TTL_SECONDS = 3600
|
|
43
|
+
#: How old a key set may be and still stand in for one that can't be fetched.
|
|
44
|
+
_JWKS_MAX_STALE_SECONDS = 6 * 3600
|
|
43
45
|
_FORCED_REFRESH_MIN_SECONDS = 60
|
|
44
46
|
|
|
45
47
|
|
|
@@ -78,11 +80,12 @@ class Session:
|
|
|
78
80
|
|
|
79
81
|
|
|
80
82
|
class _KeySet:
|
|
81
|
-
"""A fetched JWKS, cached for an hour and kept through a failed refresh."""
|
|
83
|
+
"""A fetched JWKS, cached for an hour and kept through a failed refresh for six."""
|
|
82
84
|
|
|
83
85
|
def __init__(self, url: str):
|
|
84
86
|
self.url = url
|
|
85
87
|
self._keys: dict[str, Ed25519PublicKey] = {}
|
|
88
|
+
self._retired: dict[str, float] = {}
|
|
86
89
|
self._fetched_at = 0.0
|
|
87
90
|
self._forced_at = 0.0
|
|
88
91
|
self._lock = threading.Lock()
|
|
@@ -91,13 +94,18 @@ class _KeySet:
|
|
|
91
94
|
try:
|
|
92
95
|
r = httpx.get(self.url, headers={"Accept": "application/json"}, timeout=10.0)
|
|
93
96
|
r.raise_for_status()
|
|
94
|
-
|
|
97
|
+
doc = r.json()
|
|
98
|
+
self._keys = _import_jwks(doc)
|
|
99
|
+
self._retired = _retired_at(doc)
|
|
95
100
|
self._fetched_at = time.time()
|
|
96
101
|
except (httpx.HTTPError, ValueError):
|
|
97
|
-
# Stale on error: a key set seen before keeps working through an outage.
|
|
98
|
-
if not self._keys:
|
|
102
|
+
# Stale on error: a key set seen before keeps working through an outage, for a while.
|
|
103
|
+
if not self._keys or time.time() - self._fetched_at >= _JWKS_MAX_STALE_SECONDS:
|
|
99
104
|
raise
|
|
100
105
|
|
|
106
|
+
def retired_at(self, kid: str) -> Optional[float]:
|
|
107
|
+
return self._retired.get(kid)
|
|
108
|
+
|
|
101
109
|
def get(self, kid: str) -> Optional[Ed25519PublicKey]:
|
|
102
110
|
with self._lock:
|
|
103
111
|
if not self._keys or time.time() - self._fetched_at >= _JWKS_TTL_SECONDS:
|
|
@@ -119,6 +127,16 @@ def _b64url(s: str) -> bytes:
|
|
|
119
127
|
return base64.urlsafe_b64decode(s + "=" * (-len(s) % 4))
|
|
120
128
|
|
|
121
129
|
|
|
130
|
+
def _retired_at(doc: Any) -> dict[str, float]:
|
|
131
|
+
"""kid → ``retired_at`` for keys published as retired; 0 when it can't be read."""
|
|
132
|
+
out: dict[str, float] = {}
|
|
133
|
+
for k in doc.get("keys", []) if isinstance(doc, dict) else []:
|
|
134
|
+
if isinstance(k, dict) and isinstance(k.get("kid"), str) and k.get("status") == "retired":
|
|
135
|
+
at = k.get("retired_at")
|
|
136
|
+
out[k["kid"]] = at if isinstance(at, (int, float)) and not isinstance(at, bool) else 0
|
|
137
|
+
return out
|
|
138
|
+
|
|
139
|
+
|
|
122
140
|
def _import_jwks(doc: Any) -> dict[str, Ed25519PublicKey]:
|
|
123
141
|
if not isinstance(doc, dict) or not isinstance(doc.get("keys"), list):
|
|
124
142
|
raise ValueError("JWKS did not return {keys: [...]}")
|
|
@@ -184,11 +202,13 @@ def verify_session(
|
|
|
184
202
|
key = _import_jwks(dict(jwks)).get(kid)
|
|
185
203
|
except ValueError as err:
|
|
186
204
|
raise InvalidSession("unknown_key") from err
|
|
205
|
+
retired_at = _retired_at(dict(jwks)).get(kid)
|
|
187
206
|
else:
|
|
188
207
|
try:
|
|
189
208
|
key = _session_keys.get(kid)
|
|
190
209
|
except (httpx.HTTPError, ValueError) as err:
|
|
191
210
|
raise InvalidSession("key_set_unavailable") from err
|
|
211
|
+
retired_at = _session_keys.retired_at(kid)
|
|
192
212
|
if key is None:
|
|
193
213
|
raise InvalidSession("unknown_key")
|
|
194
214
|
try:
|
|
@@ -210,6 +230,9 @@ def verify_session(
|
|
|
210
230
|
iat = payload.get("iat")
|
|
211
231
|
if iat is not None and not isinstance(iat, (int, float)):
|
|
212
232
|
raise InvalidSession("claims")
|
|
233
|
+
# A retired key vouches only for what it signed before it retired.
|
|
234
|
+
if retired_at is not None and not (iat is not None and iat < retired_at):
|
|
235
|
+
raise InvalidSession("retired_key")
|
|
213
236
|
for claim in ("sub", "did_oc", "jti"):
|
|
214
237
|
if not isinstance(payload.get(claim), str) or not payload[claim]:
|
|
215
238
|
raise InvalidSession("claims")
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "orangecheck"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.6.0"
|
|
8
8
|
description = "Python SDK for OrangeCheck — proof of Bitcoin stake, the OC Pledge primitive, and ochk.app sign-in for your backend."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -80,11 +80,39 @@ def test_session_keeps_a_key_set_through_an_outage(fresh_key_sets: None) -> None
|
|
|
80
80
|
v = V["session"]["valid"][0]
|
|
81
81
|
verify_session(v["token"], v["audience"])
|
|
82
82
|
# The hour is up, the refetch fails, and the keys already held still verify.
|
|
83
|
-
integrator._session_keys._fetched_at =
|
|
83
|
+
integrator._session_keys._fetched_at = V["now"] - 3600
|
|
84
84
|
assert verify_session(v["token"], v["audience"]).did_oc == v["claims"]["did_oc"]
|
|
85
85
|
assert route.call_count == 2
|
|
86
86
|
|
|
87
87
|
|
|
88
|
+
@respx.mock
|
|
89
|
+
def test_session_stops_leaning_on_a_key_set_six_hours_old(fresh_key_sets: None) -> None:
|
|
90
|
+
respx.get("https://ochk.io/.well-known/jwks.json").mock(
|
|
91
|
+
side_effect=[httpx.Response(200, json=V["session"]["jwks"])] + [httpx.Response(503)] * 3
|
|
92
|
+
)
|
|
93
|
+
v = V["session"]["valid"][0]
|
|
94
|
+
verify_session(v["token"], v["audience"])
|
|
95
|
+
integrator._session_keys._fetched_at = V["now"] - 5 * 3600
|
|
96
|
+
assert verify_session(v["token"], v["audience"]).did_oc == v["claims"]["did_oc"]
|
|
97
|
+
integrator._session_keys._fetched_at = V["now"] - 6 * 3600 - 1
|
|
98
|
+
with pytest.raises(InvalidSession) as err:
|
|
99
|
+
verify_session(v["token"], v["audience"])
|
|
100
|
+
assert err.value.reason == "key_set_unavailable"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@respx.mock
|
|
104
|
+
def test_webhook_stops_leaning_on_a_key_set_six_hours_old(fresh_key_sets: None) -> None:
|
|
105
|
+
respx.get("https://me.ochk.io/api/dev-jwks").mock(
|
|
106
|
+
side_effect=[httpx.Response(200, json=V["webhook"]["jwks"])] + [httpx.Response(503)] * 3
|
|
107
|
+
)
|
|
108
|
+
v = V["webhook"]["valid"][0]
|
|
109
|
+
verify_webhook(v["headers"], v["body"])
|
|
110
|
+
integrator._webhook_keys._fetched_at = V["now"] - 6 * 3600 - 1
|
|
111
|
+
with pytest.raises(InvalidWebhook) as err:
|
|
112
|
+
verify_webhook(v["headers"], v["body"])
|
|
113
|
+
assert err.value.reason == "key_set_unavailable"
|
|
114
|
+
|
|
115
|
+
|
|
88
116
|
@respx.mock
|
|
89
117
|
def test_session_without_any_key_set_is_refused(fresh_key_sets: None) -> None:
|
|
90
118
|
respx.get("https://ochk.io/.well-known/jwks.json").mock(return_value=httpx.Response(503))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|