Files
automata/apps/api/util/validateJsonWebhook.ts
SrIzan10 40113a840d feat!: monorepo (#12)
* refactor: initial monorepo

* chore: remove accidentally commited repos

* chore: remove accidentally commited repos

* feat: more progress

* feat: finally monorepo done

* feat: move away from pocketbase

* fix: seren's reviews and schema frontend login errors

* fix: for some reason didn't remove await lol
2023-12-27 18:39:26 +01:00

19 lines
568 B
TypeScript

import type { Request } from "express";
import * as crypto from 'crypto';
export function validateJsonWebhook(request: Request) {
// calculate the signature
const expectedSignature = "sha256=" +
crypto.createHmac("sha256", process.env.TOKEN!)
.update(JSON.stringify(request.body))
.digest("hex");
// compare the signature against the one in the request
const signature = request.headers["x-hub-signature-256"];
if (signature !== expectedSignature) {
return false;
} else {
return true;
}
}