UNPKG

@launchdarkly/js-server-sdk-common-edge

Version:
35 lines 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_js_1 = require("crypto-js"); class CryptoJSHmac { constructor(algorithm, key) { let algo; switch (algorithm) { case 'sha1': algo = crypto_js_1.default.algo.SHA1; break; case 'sha256': algo = crypto_js_1.default.algo.SHA256; break; default: throw new Error('unsupported hash algorithm. Only sha1 and sha256 are supported.'); } this._cryptoJSHmac = crypto_js_1.default.algo.HMAC.create(algo, key); } digest(encoding) { const result = this._cryptoJSHmac.finalize(); if (encoding === 'base64') { return result.toString(crypto_js_1.default.enc.Base64); } if (encoding === 'hex') { return result.toString(crypto_js_1.default.enc.Hex); } throw new Error('unsupported output encoding. Only base64 and hex are supported.'); } update(data) { this._cryptoJSHmac.update(data); return this; } } exports.default = CryptoJSHmac; //# sourceMappingURL=cryptoJSHmac.js.map