UNPKG

magicbell

Version:
25 lines 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createHmac = createHmac; const tslib_1 = require("tslib"); const crypto_1 = tslib_1.__importDefault(require("crypto")); const dataKeys = ['userExternalId', 'userEmail', 'id', '_id', 'email']; function getData(data) { if (typeof data === 'string') return data; if (typeof data === 'object' && !data) return ''; const key = dataKeys.find((key) => key in data && data[key]); return key ? data[key] : ''; } function createHmac(secret, data) { if (!crypto_1.default?.createHmac) throw new Error('Your environment does not support crypto.createHmac'); if (!secret) throw new Error(`You'll need to provide a secret to create an HMAC.`); const msg = getData(data); if (!msg || typeof msg !== 'string') throw new Error(`You'll need to provide data to create an HMAC.`); return crypto_1.default.createHmac('sha256', secret).update(msg).digest('base64'); } //# sourceMappingURL=crypto.js.map