UNPKG

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

Version:
37 lines 1.13 kB
import CryptoJS from 'crypto-js'; export default class CryptoJSHasher { constructor(algorithm) { let algo; switch (algorithm) { case 'sha1': algo = CryptoJS.algo.SHA1; break; case 'sha256': algo = CryptoJS.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 = CryptoJS.enc.Base64; break; case 'hex': enc = CryptoJS.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; } } //# sourceMappingURL=cryptoJSHasher.js.map