16 lines
525 B
TypeScript
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);
|
|
}
|