1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! sv-port — per-account `session_version` epoch revocation check
//! (RFC_2026-05-04_jwt-full-adoption Phase 5 commit 5.5).
//!
//! Account-wide axis distinct from `check_session` (per-row liveness):
//! a `LogoutAll` / break-glass increments the substrate's per-account
//! counter, invalidating every prior token within the cache TTL window.
//! STANDARDS_AUTH_PPOPPO §17.7 + STANDARDS_AUTH_INVALIDATION §2.3.
//!
//! ── sv lives on the wire, hidden from `Claims` ──────────────────────────
//!
//! Phase 4 Decision 1 keeps `sv` HIDDEN (`engine/check_domain.rs` ALLOWED
//! list contains `"sv"` so M45 admits it, but the value is not surfaced).
//! Surfacing would push enforcement responsibility onto every caller —
//! against the deep-module rule. Engine reads sv from the raw payload at
//! the one site that needs it (here) and hands the comparison off to the
//! port.
//!
//! ── Short-circuit conditions ────────────────────────────────────────────
//!
//! 1. `cfg.epoch` is a named non-`Enforced` stance (`EnforcedElsewhere` /
//! `Unenforced` — RFC_202607150428 Q3 typed stance; the silent
//! `Option::None` slot is retired). This is the ONLY short-circuit: a
//! non-`Enforced` validator never reaches the payload read. Unlike the
//! old `None`, the stance is declared, greppable, and boot-logged.
//!
//! There is no longer a "missing `sv` ⇒ admit" short-circuit. Post-S4 every
//! PAS mint stamps `sv`, so a *wired* validator that receives a token without
//! one refuses it (**R6 legacy-admit retired**, RFC_202607150428 S6) — see the
//! failure-mode contract below. STANDARDS_AUTH_PPOPPO §4.2.1 R6.
//!
//! ── Why `sv` not `Claims.sv` ────────────────────────────────────────────
//!
//! `Claims.sv` does not exist (Phase 4 design: HIDDEN). Engine reads the
//! raw payload via `parse_payload_json` exactly as `check_domain` does
//! for other hidden claims. The single re-parse here is symmetric with
//! the existing pattern (`check_domain` already re-parses for M40/M41/...).
//!
//! ── Failure-mode contract (fail-closed) ────────────────────────────────
//!
//! - `payload.sv` absent (wired validator) → `AuthError::SessionVersionStale`
//! (`reason = "unstamped"` in the trace — a mint forgot to stamp, or a
//! pre-cutover legacy token; refuse it, S6).
//! - `current(sub) = Ok(c)` and `token.sv >= c` → admit.
//! - `current(sub) = Ok(c)` and `token.sv < c` → `AuthError::SessionVersionStale`
//! (`reason = "stale"` — break-glass / LogoutAll just kicked this token).
//! - `current(sub) = Err(_)` → `AuthError::SessionVersionLookupUnavailable`
//! (infrastructure signal — substrate down; admit-on-failure would let
//! stale tokens slip through during the outage window).
//!
//! ── M37 observability ──────────────────────────────────────────────────
//!
//! Same `revocation.checked` event shape as the replay/session ports so
//! ops dashboards aggregate by `port = "epoch"`.
use crateEpochRevocationError;
use crate;
use crateparse_payload_json;
pub async