( secret: string, identity: AdminMfaIdentity, purpose: Purpose, proof: typeof Proof.Type, now: number, )
| 33 | |
| 34 | /** Sign a purpose-specific, session-bound proof with an explicit expiration. */ |
| 35 | export const signAdminMfaProof = ( |
| 36 | secret: string, |
| 37 | identity: AdminMfaIdentity, |
| 38 | purpose: Purpose, |
| 39 | proof: typeof Proof.Type, |
| 40 | now: number, |
| 41 | ) => |
| 42 | Effect.tryPromise({ |
| 43 | try: () => |
| 44 | new SignJWT({ factorId: proof.factorId, challengeId: proof.challengeId, mode: proof.mode }) |
| 45 | .setProtectedHeader({ alg: "HS256" }) |
| 46 | .setIssuer(issuer(purpose)) |
| 47 | .setSubject(identity.userId) |
| 48 | .setAudience(identity.sessionId) |
| 49 | .setIssuedAt(Math.floor(now / 1000)) |
| 50 | .setExpirationTime(proof.exp) |
| 51 | .sign(key(secret)), |
| 52 | catch: (cause) => new AdminMfaProofError({ cause }), |
| 53 | }); |
| 54 | |
| 55 | /** Reject expired, tampered, cross-user, cross-session, and wrong-purpose proofs. */ |
| 56 | export const readAdminMfaProof = ( |
no test coverage detected