UNPKG

547 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const crypto_1 = require("crypto");
4function s2b(str, encoding) {
5 return Buffer.from(str, encoding);
6}
7function safeCompare(a, b) {
8 if (a.length !== b.length) {
9 return false;
10 }
11 return (0, crypto_1.timingSafeEqual)(a, b);
12}
13function validateSignature(body, channelSecret, signature) {
14 return safeCompare((0, crypto_1.createHmac)("SHA256", channelSecret).update(body).digest(), s2b(signature, "base64"));
15}
16exports.default = validateSignature;