( secret: string, rawBody: string, signatureHeader: string | null )
| 1 | import { computeHmacHex, timingSafeEqual } from "@open-inspect/shared/auth"; |
| 2 | |
| 3 | export async function verifyWebhookSignature( |
| 4 | secret: string, |
| 5 | rawBody: string, |
| 6 | signatureHeader: string | null |
| 7 | ): Promise<boolean> { |
| 8 | if (!signatureHeader || !signatureHeader.startsWith("sha256=")) { |
| 9 | return false; |
| 10 | } |
| 11 | |
| 12 | const expectedHex = signatureHeader.slice("sha256=".length); |
| 13 | const computedHex = await computeHmacHex(rawBody, secret); |
| 14 | |
| 15 | return timingSafeEqual(expectedHex, computedHex); |
| 16 | } |
no test coverage detected