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
//! # mid-signin
//!
//! The drop-in Relying-Party (RP) kit for **Sign in with MATA** (mID).
//!
//! [`mid_verify`] does the cryptography — the four-step, zero-MATA-runtime
//! verification of a self-issued mID JWT — and deliberately stops there: it is
//! a pure function with no state. A production RP still owes three duties the
//! verifier cannot perform:
//!
//! 1. **Single-use nonces.** The verifier only checks nonce *equality*; the RP
//! must prove the nonce was one it issued and consume it exactly once, or a
//! captured token replays forever. ([`NonceStore`])
//! 2. **Genesis anchoring + rollback detection.** A DID must present the same
//! genesis-roster hash on every sign-in (anything else is spoofing) and a
//! head-roster version that never decreases (a decrease is a stolen-device
//! rollback). The verifier is stateless, so the RP persists the anchor.
//! ([`AnchorStore`])
//! 3. **Session production.** Turning a verified token into "this request is
//! Alice" — which stays the application's choice; this crate hands back an
//! [`RpSession`] and gets out of the way.
//!
//! [`Authenticator`] composes all of it: verify → consume nonce → check
//! anchor. The `redb-store` feature adds a zero-schema embedded persistent
//! store; the `routes` feature adds ready-made axum routes that pair with the
//! `@matanetwork/sovereign-id` frontend SDK.
//!
//! ## Ten-line integration (axum)
//!
//! ```ignore
//! use std::sync::Arc;
//! use mid_signin::{Authenticator, MidRp, MidRpConfig, RedbStore};
//!
//! let store = Arc::new(RedbStore::open("mata-auth.redb")?);
//! let auth = Authenticator::new(store.clone(), store);
//! let rp = Arc::new(MidRp::new(
//! MidRpConfig::new("https://acme.com"),
//! auth,
//! ));
//! let app = axum::Router::new()
//! .merge(mid_signin::routes::router(rp));
//! // Frontend: signIn({ rpOrigin: "https://acme.com", nonce, claims: … })
//! // with nonce from POST /auth/mid/nonce; POST the JWT to /auth/mid/verify.
//! ```
//!
//! ## Purity contract
//!
//! The core (everything outside the `routes` module) reads no clock and does
//! no I/O of its own: `now_unix_secs` is always a parameter, mirroring
//! `mid_verify::VerifyConfig`. The impure boundary — `SystemTime`, HTTP —
//! lives only in [`routes`].
pub
pub use ;
pub use ;
pub use RpError;
pub use ;
pub use ;
pub use RedbStore;
pub use ;
// The mID vocabulary callers need, re-exported so an RP depends only on
// this crate.
pub use ;