mid-verify
RP-side mID verifier. Start here if you are adding "Sign in with MATA" to your backend.
Takes a JWS compact-form mID token plus your local policy (VerifyConfig) and
runs the four-step verification entirely locally — pure Rust, no I/O, no
clock reads, and zero runtime calls to MATA infrastructure under any code
path. The token carries everything needed to verify it: the DID is the
genesis public key.
Implements ADR 0005 Decision 1. Licensed MIT OR Apache-2.0.
Building a website sign-in? You probably want
mid-signin— the drop-in kit that wraps this verifier with the stateful RP duties (single-use nonces, genesis anchoring, rollback detection) plus ready-made axum routes. This crate is the cryptographic core it composes.
[]
= "0.1"
Verifying a sign-in
use ;
let config = VerifyConfig ;
let verified = verify_mid_response?;
// verified.did — the user's stable identifier
// verified.claims — disclosed claims (all self-attested in v1)
// verified.current_version — head roster version (persist for rollback checks)
// verified.genesis_roster_hash — persist on first sight; must never change
The four checks
- Genesis self-signature — decode the genesis public key from the DID string itself and verify the embedded genesis roster's self-signature against it. No registry, no resolver.
- Roster chain — every roster mutation is signed by a key present in the prior roster; versions strictly increase. Proves the current roster legitimately descends from genesis.
- Head-roster membership — the device key that signed this token is in the current roster (revoked devices fail here).
- JWS signature — standard ES256 verification of the token against that
device key, plus audience, nonce,
iatskew, and expiry checks.
What stays your job (or mid-signin's)
This function is stateless on purpose. Cross-sign-in defenses need your storage:
- Single-use nonces — equality is checked here; issuance + one-time consumption is yours.
- Anchor on first sight — record
(did, genesis_roster_hash); reject any future sign-in whose genesis differs. - Rollback detection — record the highest
current_versionseen per DID and callVerifiedMid::check_rollback(last_seen)(or compare yourself); a lower version is a stolen device presenting a pre-revocation roster.
Errors
VerifyError is a 16-variant enum with structured fields
(AudienceMismatch, NonceMismatch, Expired, ChainVersionNotMonotonic,
RollbackDetected { current, last_seen }, …) — match on it; don't parse
messages.
Who calls it
- Any relying party backend, directly or through
mid-signin. mata-sign— reuses the same four checks for document/post signatures.- The
@matanetwork/sovereign-id-verifynpm package wraps this crate for Node/Deno/Bun backends.