orangecheck 3.3.0__tar.gz → 3.4.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 (75) hide show
  1. {orangecheck-3.3.0 → orangecheck-3.4.0}/CHANGELOG.md +22 -0
  2. {orangecheck-3.3.0 → orangecheck-3.4.0}/PKG-INFO +1 -1
  3. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/__init__.py +7 -1
  4. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/integrator.py +66 -7
  5. {orangecheck-3.3.0 → orangecheck-3.4.0}/pyproject.toml +1 -1
  6. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_integrator_vectors.py +30 -2
  7. {orangecheck-3.3.0 → orangecheck-3.4.0}/.gitignore +0 -0
  8. {orangecheck-3.3.0 → orangecheck-3.4.0}/README.md +0 -0
  9. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/__main__.py +0 -0
  10. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/address.py +0 -0
  11. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/bond.py +0 -0
  12. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/canonical.py +0 -0
  13. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/client.py +0 -0
  14. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/connect.py +0 -0
  15. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/errors.py +0 -0
  16. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/__init__.py +0 -0
  17. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/bond.py +0 -0
  18. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/canonical.py +0 -0
  19. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/delegation.py +0 -0
  20. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/envelopes.py +0 -0
  21. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/resolution.py +0 -0
  22. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/pledge/state.py +0 -0
  23. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/py.typed +0 -0
  24. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/tokens.py +0 -0
  25. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/top_level.py +0 -0
  26. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/types.py +0 -0
  27. {orangecheck-3.3.0 → orangecheck-3.4.0}/orangecheck/verify_sig.py +0 -0
  28. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/fixtures/bip137-parity.json +0 -0
  29. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/fixtures/bip322-js-6.1.8.json +0 -0
  30. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/fixtures/bip322-official-basic.json +0 -0
  31. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/fixtures/bip322-official-generated.json +0 -0
  32. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/__init__.py +0 -0
  33. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/test_authority.py +0 -0
  34. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/test_create_signers.py +0 -0
  35. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/test_delegation.py +0 -0
  36. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/test_vectors.py +0 -0
  37. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/pledge/test_wrap.py +0 -0
  38. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_address.py +0 -0
  39. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_bip322_official.py +0 -0
  40. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_client.py +0 -0
  41. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_client_failure_modes.py +0 -0
  42. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_conformance.py +0 -0
  43. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_connect.py +0 -0
  44. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_ripemd160.py +0 -0
  45. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_server_helpers.py +0 -0
  46. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/test_signature_parity.py +0 -0
  47. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/index.json +0 -0
  48. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv01.json +0 -0
  49. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv02.json +0 -0
  50. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv03.json +0 -0
  51. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv04.json +0 -0
  52. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv05.json +0 -0
  53. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv06.json +0 -0
  54. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv07.json +0 -0
  55. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv08.json +0 -0
  56. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv09.json +0 -0
  57. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv10.json +0 -0
  58. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv11.json +0 -0
  59. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv12.json +0 -0
  60. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv13.json +0 -0
  61. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv14.json +0 -0
  62. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv15.json +0 -0
  63. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv16.json +0 -0
  64. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv17.json +0 -0
  65. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv18.json +0 -0
  66. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv19.json +0 -0
  67. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv20.json +0 -0
  68. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv21.json +0 -0
  69. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv22.json +0 -0
  70. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv23.json +0 -0
  71. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv24.json +0 -0
  72. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv25.json +0 -0
  73. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv26.json +0 -0
  74. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv27.json +0 -0
  75. {orangecheck-3.3.0 → orangecheck-3.4.0}/tests/vectors/tv28.json +0 -0
@@ -4,6 +4,28 @@ 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
+ ## [3.4.0] — 2026-10-24
8
+
9
+ ### Added
10
+
11
+ - `Session.merged_rh`, `merged_handles(session)` and
12
+ `match_merged_user(session, lookup)` → `MergedUserMatch`: after an account
13
+ merge, a sign-in token names your site's handle for each account merged in.
14
+ Look them up in the handles you stored: `"none"` (a new user), `"one"`
15
+ (attach this `did_oc` to that user) or `"conflict"` (two of your users: pick
16
+ neither). As `@orangecheck/me-client` 0.45.0's `matchMergedUser`, held to
17
+ the shared vectors (`merged`).
18
+
19
+ ## [3.3.1] — 2026-10-24
20
+
21
+ ### Changed
22
+
23
+ - `RevocationList` reads the `tokens` of its audience's list and answers
24
+ `"revoked"` for a token whose own `jti` is there, as
25
+ `@orangecheck/auth-core`'s `integratorRevocationCheck` does, so a token ended
26
+ with `revoke_token` stops passing once me.ochk.io lists it. `status()` and
27
+ `status_for()` take the jti (shared vectors "a token ended on its own").
28
+
7
29
  ## [3.3.0] — 2026-10-24
8
30
 
9
31
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: orangecheck
3
- Version: 3.3.0
3
+ Version: 3.4.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
@@ -81,6 +81,7 @@ from .integrator import (
81
81
  BondRequired,
82
82
  InvalidSession,
83
83
  InvalidWebhook,
84
+ MergedUserMatch,
84
85
  RevocationList,
85
86
  Session,
86
87
  SessionCheck,
@@ -91,6 +92,8 @@ from .integrator import (
91
92
  bond_meets,
92
93
  check_oc_session,
93
94
  check_sign_in_rule,
95
+ match_merged_user,
96
+ merged_handles,
94
97
  read_bond_claim,
95
98
  revocation_key,
96
99
  sign_event,
@@ -175,6 +178,9 @@ __all__ = [
175
178
  "BondRequired",
176
179
  "bond_meets",
177
180
  "read_bond_claim",
181
+ "MergedUserMatch",
182
+ "match_merged_user",
183
+ "merged_handles",
178
184
  # After a sign-in: one session per token, then end the token at ochk.io
179
185
  "spend_once",
180
186
  "spend_once_async",
@@ -207,7 +213,7 @@ __all__ = [
207
213
  "VerificationError",
208
214
  ]
209
215
 
210
- __version__ = "3.3.0"
216
+ __version__ = "3.4.0"
211
217
 
212
218
  # OC Pledge submodule — sibling primitive for forward-looking commitments
213
219
  # bound to a Bitcoin address. Imported here so consumers can write:
@@ -32,7 +32,7 @@ import re
32
32
  import threading
33
33
  import time
34
34
  import weakref
35
- from collections.abc import Mapping
35
+ from collections.abc import Callable, Mapping
36
36
  from dataclasses import dataclass, field
37
37
  from typing import Any, Optional, Union
38
38
  from urllib.parse import quote, urlsplit
@@ -95,6 +95,8 @@ class Session:
95
95
  claims: dict[str, Any] = field(default_factory=dict)
96
96
  #: The token's revocation handle on its audience's list of ended sessions.
97
97
  rh: Optional[str] = None
98
+ #: This site's handles for accounts merged into this one (see match_merged_user).
99
+ merged_rh: tuple[str, ...] = ()
98
100
 
99
101
 
100
102
  # ─── key sets ────────────────────────────────────────────────────────────
@@ -371,6 +373,7 @@ class _AudienceList:
371
373
  + quote(aud, safe="-_.!~*'()")
372
374
  )
373
375
  self._handles: dict[str, float] = {}
376
+ self._tokens: frozenset[str] = frozenset()
374
377
  self._at: Optional[float] = None
375
378
  # How old the list already was when fetched, by the wall clock.
376
379
  self._age_at_fetch = float("inf")
@@ -408,6 +411,7 @@ class _AudienceList:
408
411
  raw = doc.get("handles")
409
412
  handles: dict[str, Any] = raw if isinstance(raw, dict) else {}
410
413
  self._handles = {k: float(v) for k, v in handles.items() if _finite(v)}
414
+ self._tokens = frozenset(t for t in doc["tokens"] if isinstance(t, str))
411
415
  at: Any = doc.get("at")
412
416
  self._at = float(at) if _finite(at) else None
413
417
  self._age_at_fetch = float("inf") if self._at is None else time.time() - self._at
@@ -449,11 +453,14 @@ class _AudienceList:
449
453
  return WarmPart("failed", problem)
450
454
  return _FETCHED if self._fetched_at != before else _KEPT
451
455
 
452
- def status(self, rh: str, iat: Optional[float]) -> str:
456
+ def status(self, rh: str, iat: Optional[float], jti: Optional[str] = None) -> str:
453
457
  with self._lock:
454
458
  self._refresh()
455
459
  if self._fetched_at is None:
456
460
  return "unverified"
461
+ # A token known to be ended stays ended, however old the copy.
462
+ if isinstance(jti, str) and revocation_key("jti", jti) in self._tokens:
463
+ return "revoked"
457
464
  cutoff = self._handles.get(rh)
458
465
  if cutoff is not None and not (iat is not None and iat >= cutoff):
459
466
  return "revoked"
@@ -507,10 +514,12 @@ class RevocationList:
507
514
  lst = self._lists[aud] = _AudienceList(self, aud)
508
515
  return lst
509
516
 
510
- def status(self, rh: Optional[str], aud: Optional[str], iat: Optional[float]) -> str:
517
+ def status(
518
+ self, rh: Optional[str], aud: Optional[str], iat: Optional[float], jti: Optional[str] = None
519
+ ) -> str:
511
520
  if rh is None:
512
521
  return "live"
513
- return self._status(rh, aud, iat)
522
+ return self._status(rh, aud, iat, jti)
514
523
 
515
524
  def status_for(self, claims: Mapping[str, Any]) -> str:
516
525
  """
@@ -520,12 +529,12 @@ class RevocationList:
520
529
  """
521
530
  if "rh" not in claims:
522
531
  return "live"
523
- return self._status(claims["rh"], claims.get("aud"), claims.get("iat"))
532
+ return self._status(claims["rh"], claims.get("aud"), claims.get("iat"), claims.get("jti"))
524
533
 
525
- def _status(self, rh: Any, aud: Any, iat: Optional[float]) -> str:
534
+ def _status(self, rh: Any, aud: Any, iat: Optional[float], jti: Any = None) -> str:
526
535
  if not isinstance(rh, str) or not rh or not isinstance(aud, str) or not aud:
527
536
  return "revoked"
528
- return self._list(aud).status(rh, iat)
537
+ return self._list(aud).status(rh, iat, jti)
529
538
 
530
539
 
531
540
  # ─── who may sign in (coin backing) ──────────────────────────────────────
@@ -892,11 +901,61 @@ def verify_session(
892
901
  oc_bond=bond if isinstance(bond, dict) else None,
893
902
  claims=payload,
894
903
  rh=rh if isinstance(rh, str) else None,
904
+ merged_rh=merged_handles(payload),
895
905
  )
896
906
  _verified[id(session)] = session
897
907
  return session
898
908
 
899
909
 
910
+ # ─── after an account merge ──────────────────────────────────────────────
911
+
912
+ #: At most this many handles ride one token; a longer claim is not read.
913
+ _MERGED_HANDLES_MAX = 16
914
+
915
+
916
+ def merged_handles(session: Union["Session", Mapping[str, Any]]) -> tuple[str, ...]:
917
+ """
918
+ The merged handles on a verified session (or its claims), as
919
+ ``@orangecheck/me-client``'s ``mergedHandles`` reads them: a claim that is not
920
+ a list of at most 16 non-empty strings reads as none.
921
+ """
922
+ raw = session.get("merged_rh") if isinstance(session, Mapping) else session.claims.get("merged_rh")
923
+ if not isinstance(raw, list) or len(raw) > _MERGED_HANDLES_MAX:
924
+ return ()
925
+ if not all(isinstance(h, str) and h for h in raw):
926
+ return ()
927
+ return tuple(dict.fromkeys(raw))
928
+
929
+
930
+ @dataclass(frozen=True)
931
+ class MergedUserMatch:
932
+ """Which of your users a merged account was: ``kind`` is ``"none"``, ``"one"`` or ``"conflict"``."""
933
+
934
+ kind: str
935
+ user: Optional[str] = None
936
+ users: tuple[str, ...] = ()
937
+
938
+
939
+ def match_merged_user(
940
+ session: Union["Session", Mapping[str, Any]], lookup: Callable[[str], Optional[str]]
941
+ ) -> MergedUserMatch:
942
+ """
943
+ Which of your users this person was before a merge, as me-client's
944
+ ``matchMergedUser``. Call it with a verified session whose ``did_oc`` you have
945
+ no row for; ``lookup`` answers the user that stored a handle, or None.
946
+
947
+ ``"none"``: create a user, as for anyone new. ``"one"``: attach this
948
+ ``did_oc`` and ``rh`` to that user. ``"conflict"``: the handles name two of
949
+ your users; pick neither, and log it.
950
+ """
951
+ users = {u for u in (lookup(h) for h in merged_handles(session)) if isinstance(u, str) and u}
952
+ if not users:
953
+ return MergedUserMatch("none")
954
+ if len(users) == 1:
955
+ return MergedUserMatch("one", user=next(iter(users)))
956
+ return MergedUserMatch("conflict", users=tuple(sorted(users)))
957
+
958
+
900
959
  #: Can't tell right now: the client should try again, never sign the person out.
901
960
  _UNAVAILABLE = frozenset({"revocations_unavailable", "key_set_unavailable", "bond_policy_unavailable"})
902
961
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "orangecheck"
7
- version = "3.3.0"
7
+ version = "3.4.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" }
@@ -31,6 +31,8 @@ from orangecheck import (
31
31
  InvalidSession,
32
32
  SignInPolicy,
33
33
  bond_meets,
34
+ match_merged_user,
35
+ merged_handles,
34
36
  InvalidWebhook,
35
37
  RevocationList,
36
38
  SessionEnded,
@@ -258,15 +260,20 @@ def test_revocation_key_matches_the_node_sdk(v: dict[str, Any]) -> None:
258
260
  assert revocation_key("sub", v["sub"]) == v["key"]
259
261
 
260
262
 
263
+ @pytest.mark.parametrize("v", R["token_keys"], ids=lambda v: v["jti"])
264
+ def test_token_key_matches_the_node_sdk(v: dict[str, Any]) -> None:
265
+ assert revocation_key("jti", v["jti"]) == v["key"]
266
+
267
+
261
268
  @respx.mock
262
269
  @pytest.mark.parametrize("v", R["sessions"], ids=lambda v: v["name"])
263
270
  def test_revocations_decide_as_the_node_sdk_does(v: dict[str, Any]) -> None:
264
271
  _serve_lists()
265
272
  # A key absent from the vector is absent from the claims; null stays null.
266
- claims = {k: v[k] for k in ("rh", "aud", "iat") if k in v}
273
+ claims = {k: v[k] for k in ("rh", "aud", "iat", "jti") if k in v}
267
274
  assert _revocations().status_for(claims) == v["status"]
268
275
  if "rh" not in v or v["rh"] is not None:
269
- assert _revocations().status(v.get("rh"), v["aud"], v["iat"]) == v["status"]
276
+ assert _revocations().status(v.get("rh"), v["aud"], v["iat"], v.get("jti")) == v["status"]
270
277
 
271
278
 
272
279
  @respx.mock
@@ -928,3 +935,24 @@ def test_a_list_dated_ahead_vouches_once_a_lagging_clock_catches_up(monkeypatch:
928
935
  clocks.wall += 31
929
936
  clocks.mono += 1
930
937
  assert rl.status("x", R["request"]["aud"], 0) == "live"
938
+
939
+
940
+ # ─── after an account merge ──────────────────────────────────────────────
941
+
942
+ MV = V["merged"]
943
+
944
+
945
+ def test_a_verified_token_names_the_merged_accounts_handles() -> None:
946
+ v = MV["token"]
947
+ s = verify_session(v["token"], v["audience"], jwks=V["session"]["jwks"])
948
+ assert list(s.merged_rh) == v["merged_rh"]
949
+ assert list(merged_handles(s)) == v["merged_rh"]
950
+
951
+
952
+ @pytest.mark.parametrize("v", MV["cases"], ids=lambda v: v["name"])
953
+ def test_merged_users_match_as_the_node_sdk_does(v: dict[str, Any]) -> None:
954
+ got = match_merged_user(v["session"], lambda rh: v["stored"].get(rh))
955
+ want = v["expect"]
956
+ assert got.kind == want["kind"]
957
+ assert got.user == want.get("user")
958
+ assert list(got.users) == want.get("users", [])
File without changes
File without changes