classy-pay-core
Version:
Shared tools used in ClassyPay-related projects
22 lines • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateHMACSigner = void 0;
require('source-map-support').install();
const crypto = require("crypto");
const CreateHMACSigner = (service, token, secret) => {
if (!service)
throw Error('Hmac256AuthSigner config requires a service');
if (!token)
throw Error('Hmac256AuthSigner config requires a token');
if (!secret)
throw Error('Hmac256AuthSigner config requires a secret');
return (method, path, contentType, body) => {
const ts = Math.floor(new Date().getTime() / 1000);
const bodyPart = body ? crypto.createHash('md5').update(body).digest('hex') : '';
const message = `${method}\n${path}\n${(body ? contentType : '')}\n${ts}\n${bodyPart}`;
const signature = crypto.createHmac('sha256', secret).update(message).digest('hex');
return `${service} ts=${ts} token=${token} signature=${signature}`;
};
};
exports.CreateHMACSigner = CreateHMACSigner;
//# sourceMappingURL=hmac256AuthSigner.js.map