Initial Mebbling hub implementation
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
||||
|
||||
export function createWebhookSecret() { return randomBytes(32).toString("base64url"); }
|
||||
export function webhookSecretHash(secret: string) { return createHash("sha256").update(secret).digest("hex"); }
|
||||
export function webhookSecretMatches(secret: string, expectedHash: string | null) {
|
||||
if (!expectedHash) return false;
|
||||
const actual = Buffer.from(webhookSecretHash(secret), "hex");
|
||||
const expected = Buffer.from(expectedHash, "hex");
|
||||
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
||||
}
|
||||
Reference in New Issue
Block a user