import * as jose from "jose";
const JWKS_URL = "https://sis.sumvin.com/v0/sis/.well-known/jwks.json";
const MY_AUDIENCE = "your-registered-identifier.example.com";
const SIS_API_KEY = process.env.SIS_API_KEY;
const JWKS = jose.createRemoteJWKSet(new URL(JWKS_URL));
async function verifySumvinCredentials(request: Request) {
// 1. Extract the PINT JWT from the x-sumvin-pint-token header
const token = request.headers.get("x-sumvin-pint-token");
if (!token) {
throw new Error("Missing x-sumvin-pint-token header");
}
// 2. Verify JWT signature, issuer, audience, and expiry
const { payload } = await jose.jwtVerify(token, JWKS, {
issuer: "https://sis.sumvin.com",
audience: MY_AUDIENCE,
algorithms: ["ES256"],
});
// 3. Check KYC status
if (payload.kyc_status !== "verified") {
throw new Error(`KYC not verified: ${payload.kyc_status}`);
}
// 4. Check revocation (optional but recommended)
if (SIS_API_KEY) {
const pintId = payload.pint_uri as string;
const statusRes = await fetch(
`https://sis.sumvin.com/v0/sis/pint/${encodeURIComponent(pintId)}/status`,
{ headers: { Authorization: `Bearer ${SIS_API_KEY}` } }
);
const status = await statusRes.json();
if (!status.valid) {
throw new Error(`PINT revoked: ${status.reason}`);
}
}
// 5. Handle enhanced tier if needed
if (payload.verification_tier === "enhanced") {
// See: /merchant/verify-pint-signature
verifyPintSignature(request, payload);
}
return payload;
}