UNPKG

@launchdarkly/react-native-client-sdk

Version:
28 lines 1 kB
import { sha256 } from '../../fromExternal/js-sha256'; import { base64FromByteArray } from '../../polyfills'; export default class PlatformHasher { constructor(algorithm, hmacKey) { switch (algorithm) { case 'sha256': this._hasher = hmacKey ? sha256.hmac.create(hmacKey) : sha256.create(); break; default: throw new Error(`Unsupported hash algorithm: ${algorithm}. Only sha256 is supported.`); } } digest(encoding) { switch (encoding) { case 'base64': return base64FromByteArray(new Uint8Array(this._hasher.arrayBuffer())); case 'hex': return this._hasher.hex(); default: throw new Error(`unsupported output encoding: ${encoding}. Only base64 and hex are supported.`); } } update(data) { this._hasher.update(data); return this; } } //# sourceMappingURL=PlatformHasher.js.map