Files
suaveplan/packages/security-stack/security/otp/src/ocra/verify-ocra.ts
2026-05-27 23:47:53 +01:00

16 lines
525 B
TypeScript

import { constantTimeStringEqual } from "../totp/verify.js";
import { ocra } from "./ocra.js";
import type { OcraParams } from "./ocra.types.js";
/** Constant-time verify: recomputes the OCRA response under the given suite
* and key and compares it to `response` without short-circuiting. */
export function verifyOcra(
response: string,
suite: string,
key: Uint8Array,
params: OcraParams
): boolean {
const expected = ocra(suite, key, params);
return constantTimeStringEqual(response, expected);
}