1 | import { Buffer } from "node:buffer";
|
2 | import { createHmac, timingSafeEqual } from "node:crypto";
|
3 | function s2b(str, encoding) {
|
4 | return Buffer.from(str, encoding);
|
5 | }
|
6 | function safeCompare(a, b) {
|
7 | if (a.length !== b.length) {
|
8 | return false;
|
9 | }
|
10 | return timingSafeEqual(a, b);
|
11 | }
|
12 | export default function validateSignature(body, channelSecret, signature) {
|
13 | return safeCompare(createHmac("SHA256", channelSecret).update(body).digest(), s2b(signature, "base64"));
|
14 | }
|
15 |
|
\ | No newline at end of file |