mirror of https://github.com/openclaw/openclaw.git
13 lines
407 B
TypeScript
13 lines
407 B
TypeScript
import { createHash, timingSafeEqual } from "node:crypto";
|
|
|
|
export function safeEqualSecret(
|
|
provided: string | undefined | null,
|
|
expected: string | undefined | null,
|
|
): boolean {
|
|
if (typeof provided !== "string" || typeof expected !== "string") {
|
|
return false;
|
|
}
|
|
const hash = (s: string) => createHash("sha256").update(s).digest();
|
|
return timingSafeEqual(hash(provided), hash(expected));
|
|
}
|