@foxy.io/sdk
Version:
Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.
46 lines (45 loc) • 1.99 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyWebhookSignature = void 0;
const crypto = __importStar(require("crypto"));
const v8n_1 = __importDefault(require("v8n"));
const webhookV8N = v8n_1.default().schema({
key: v8n_1.default().string(),
payload: v8n_1.default().string(),
signature: v8n_1.default().string(),
});
/**
* Verifies that the webhook your app has received was indeed sent from our servers.
* See [our wiki](https://wiki.foxycart.com/v/2.0/webhooks#validating_the_payload) for more info.
*
* @param webhook info received with the webhook that needs validation
* @returns True if this webhook has a valid signature.
*/
function verifyWebhookSignature(webhook) {
webhookV8N.check(webhook);
const computedSignature = crypto.createHmac('sha256', webhook.key).update(webhook.payload).digest('hex');
return webhook.signature === computedSignature;
}
exports.verifyWebhookSignature = verifyWebhookSignature;