UNPKG

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

Version:
40 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_js_1 = require("crypto-js"); class CryptoJSHasher { constructor(algorithm) { 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._cryptoJSHasher = algo.create(); } digest(encoding) { const result = this._cryptoJSHasher.finalize(); let enc; switch (encoding) { case 'base64': enc = crypto_js_1.default.enc.Base64; break; case 'hex': enc = crypto_js_1.default.enc.Hex; break; default: throw new Error('unsupported output encoding. Only base64 and hex are supported.'); } return result.toString(enc); } update(data) { this._cryptoJSHasher.update(data); return this; } } exports.default = CryptoJSHasher; //# sourceMappingURL=cryptoJSHasher.js.map