i hyperfocused and here is v1

This commit is contained in:
Rose 2024-04-19 00:15:20 -04:00
parent 8f43e6a6a9
commit 4090fd621e
No known key found for this signature in database
34 changed files with 4135 additions and 22 deletions

View file

@ -0,0 +1,19 @@
import { createHmac, timingSafeEqual } from "node:crypto";
if (!process.env.GITHUB_WEBHOOK_SECRET) {
throw new Error("GITHUB_WEBHOOK_SECRET is not defined");
}
export function verifyGithub(signature: string, body: object): boolean {
const verify = createHmac(
"sha256",
// biome-ignore lint/style/noNonNullAssertion: check is ran before the function
process.env.GITHUB_WEBHOOK_SECRET!,
)
.update(JSON.stringify(body))
.digest("hex");
return timingSafeEqual(
Buffer.from(signature),
Buffer.from(`sha256=${verify}`),
);
}