ethers.js/shims/hmac.js

27 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-23 09:59:01 +03: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 });
var hash = __importStar(require("hash.js"));
var bytes_1 = require("../utils/bytes");
2018-09-24 23:07:14 +03:00
var errors = __importStar(require("../errors"));
2018-08-02 01:05:19 +03:00
///////////////////////////////
var SupportedAlgorithms;
(function (SupportedAlgorithms) {
SupportedAlgorithms["sha256"] = "sha256";
SupportedAlgorithms["sha512"] = "sha512";
})(SupportedAlgorithms = exports.SupportedAlgorithms || (exports.SupportedAlgorithms = {}));
;
2018-07-23 09:59:01 +03:00
function computeHmac(algorithm, key, data) {
2018-08-02 01:05:19 +03:00
if (!SupportedAlgorithms[algorithm]) {
2018-07-23 09:59:01 +03:00
errors.throwError('unsupported algorithm ' + algorithm, errors.UNSUPPORTED_OPERATION, { operation: 'hmac', algorithm: algorithm });
}
return bytes_1.arrayify(hash.hmac(hash[algorithm], bytes_1.arrayify(key)).update(bytes_1.arrayify(data)).digest());
}
exports.computeHmac = computeHmac;