ppoppo_token/lib.rs
1//! **NOT a stable public API.** Engine-tier JWT engine — 3rd parties never
2//! reach it directly: the External-Developer verification surface is
3//! `ppoppo_pas_external`'s verifier facade (the γ-port), which re-exports what
4//! integrations need. Published only because cargo requires every crate in
5//! the SDK family's dependency closure on the registry.
6
7#![deny(rust_2018_idioms)]
8#![warn(missing_debug_implementations)]
9
10// JWT engine (RFC_2026-05-04_jwt-full-adoption Phase 1+).
11//
12// Profile-aware top-level layout (Phase 10.0 — D1):
13//
14// - `access_token::*` — RFC 9068 access-token profile (Phase 1-5 code).
15// Public re-exports: `verify` / `issue` entry points, `Claims`,
16// `VerifyConfig`, `IssueConfig`, `IssueRequest`, `AuthError`,
17// `IssueError`, plus the operational ports `EpochRevocation` /
18// `ReplayDefense` / `SessionRevocation` (RFC 9068 sv-/jti-/sid-coupled).
19//
20// - `id_token::*` — OIDC Core 1.0 id-token profile. Phase 10.1+ scaffold;
21// ships in subsequent commits.
22//
23// - Crate-root pubs (this file): JOSE-shared primitives that neither
24// profile owns — `Algorithm`, `KeySet`, `SigningKey`, `Jwk`, `Jwks`,
25// plus the operational shared-cache contract (`SV_CACHE_TTL`,
26// `sv_cache_key`).
27//
28// - `engine::*` — `pub(crate)` only. JWS check pipeline reachable solely
29// through `access_token::verify` / `access_token::issue` (and Phase
30// 10.1's `id_token::verify` / `id_token::issue`). Direct calls to
31// `jsonwebtoken::*` outside `engine/` are forbidden (M51/M52 lint,
32// landed Phase 7).
33mod algorithm;
34pub(crate) mod engine;
35mod jwks;
36mod key_set;
37mod signing_key;
38
39pub mod access_token;
40pub mod id_token;
41
42pub use crate::algorithm::Algorithm;
43pub use crate::engine::shared_error::SharedAuthError;
44pub use crate::jwks::{Jwk, Jwks, JwksError};
45pub use crate::key_set::KeySet;
46pub use crate::signing_key::{SigningKey, ed25519_public_from_pem};
47
48pub const DEFAULT_ISSUER: &str = "accounts.ppoppo.com";
49
50/// TTL for the `sv:{ppnum_id}` cache entry shared between PAS (writer) and
51/// PCS / external SDK consumers (readers). Bounds the post-break-glass
52/// staleness window when the writer cannot preemptively invalidate.
53///
54/// Value contract: 60 s. See STS_SHARED_CACHE §3.1 (Reader / Writer
55/// table) and STS_AUTH_PPOPPO §17.7 (wiring status).
56pub const SV_CACHE_TTL: std::time::Duration = std::time::Duration::from_secs(60);
57
58/// Build the shared cache key for a given Human ppnum's `session_version`.
59///
60/// Returned shape: `sv:{ppnum_id}`. Encapsulates the prefix so callers
61/// cannot accidentally mis-format the key (forgetting the colon, double
62/// prefixing, etc.). PAS writes this key on break-glass commit; PCS
63/// chat-auth and the ppoppo-pas-external SDK validator read it.
64///
65/// SSOT: STS_SHARED_CACHE §3.1 (`sv:` shared contract).
66#[must_use]
67pub fn sv_cache_key(ppnum_id: &str) -> String {
68 format!("sv:{ppnum_id}")
69}