All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.dist.src.webhookutils.index.js Maven / Gradle / Ivy

There is a newer version: 1.105.0
Show newest version
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateWebhookRequest = exports.RequestValidation = void 0;
const crypto = require("crypto");
var RequestValidation;
(function (RequestValidation) {
    RequestValidation["VALID"] = "valid";
    RequestValidation["INVALID"] = "invalid";
})(RequestValidation = exports.RequestValidation || (exports.RequestValidation = {}));
/**
 * This function is a helper function that can be used to validate that webhook
 * requests are coming from Momento. It is best practice to validate incoming
 * request to a public webhook endpoint
 * @param props {Props}
 */
const validateWebhookRequest = (props) => {
    const hash = crypto.createHmac('SHA3-256', props.signingSecret);
    const hashed = hash.update(props.body).digest('hex');
    console.log('expected', props.signature);
    console.log('actual', hashed);
    if (hashed === props.signature) {
        return RequestValidation.VALID;
    }
    return RequestValidation.INVALID;
};
exports.validateWebhookRequest = validateWebhookRequest;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvd2ViaG9va3V0aWxzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLGlDQUFpQztBQWlCakMsSUFBWSxpQkFHWDtBQUhELFdBQVksaUJBQWlCO0lBQzNCLG9DQUFlLENBQUE7SUFDZix3Q0FBbUIsQ0FBQTtBQUNyQixDQUFDLEVBSFcsaUJBQWlCLEdBQWpCLHlCQUFpQixLQUFqQix5QkFBaUIsUUFHNUI7QUFFRDs7Ozs7R0FLRztBQUNJLE1BQU0sc0JBQXNCLEdBQUcsQ0FBQyxLQUFZLEVBQXFCLEVBQUU7SUFDeEUsTUFBTSxJQUFJLEdBQUcsTUFBTSxDQUFDLFVBQVUsQ0FBQyxVQUFVLEVBQUUsS0FBSyxDQUFDLGFBQWEsQ0FBQyxDQUFDO0lBQ2hFLE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