UNPKG

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