2018-06-13 15:39:39 -04:00
|
|
|
'use strict';
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
var result = {};
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
result["default"] = mod;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2018-06-19 02:12:57 -04:00
|
|
|
var crypto_1 = require("crypto");
|
2018-06-17 16:47:28 -04:00
|
|
|
var bytes_1 = require("./bytes");
|
2018-09-24 16:07:14 -04:00
|
|
|
var errors = __importStar(require("../errors"));
|
2018-08-01 18:05:19 -04:00
|
|
|
var SupportedAlgorithms;
|
|
|
|
(function (SupportedAlgorithms) {
|
|
|
|
SupportedAlgorithms["sha256"] = "sha256";
|
|
|
|
SupportedAlgorithms["sha512"] = "sha512";
|
|
|
|
})(SupportedAlgorithms = exports.SupportedAlgorithms || (exports.SupportedAlgorithms = {}));
|
|
|
|
;
|
2018-06-19 02:12:57 -04:00
|
|
|
function computeHmac(algorithm, key, data) {
|
2018-08-01 18:05:19 -04:00
|
|
|
if (!SupportedAlgorithms[algorithm]) {
|
2018-06-19 02:12:57 -04:00
|
|
|
errors.throwError('unsupported algorithm ' + algorithm, errors.UNSUPPORTED_OPERATION, { operation: 'hmac', algorithm: algorithm });
|
2018-06-13 15:39:39 -04:00
|
|
|
}
|
2018-09-06 16:41:02 -04:00
|
|
|
return bytes_1.arrayify(crypto_1.createHmac(algorithm, Buffer.from(bytes_1.arrayify(key))).update(Buffer.from(bytes_1.arrayify(data))).digest());
|
2018-06-13 15:39:39 -04:00
|
|
|
}
|
2018-06-19 02:12:57 -04:00
|
|
|
exports.computeHmac = computeHmac;
|