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,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACnC,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC/C,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { CodedError } from '@unimodules/core';\nimport { CryptoDigestAlgorithm, CryptoEncoding, CryptoDigestOptions } from './Crypto.types';\n\nexport default {\n get name(): string {\n return 'ExpoCrypto';\n },\n async digestStringAsync(\n algorithm: CryptoDigestAlgorithm,\n data: string,\n options: CryptoDigestOptions\n ): Promise<string> {\n if (!crypto.subtle) {\n throw new CodedError(\n 'ERR_CRYPTO_UNAVAILABLE',\n 'Access to the WebCrypto API is restricted to secure origins (https).'\n );\n }\n const encoder = new TextEncoder();\n const buffer = encoder.encode(data);\n const hashedData = await crypto.subtle.digest(algorithm, buffer);\n if (options.encoding === CryptoEncoding.HEX) {\n return hexString(hashedData);\n } else if (options.encoding === CryptoEncoding.BASE64) {\n return btoa(String.fromCharCode(...new Uint8Array(hashedData)));\n }\n throw new CodedError('ERR_CRYPTO_DIGEST', 'Invalid encoding type provided.');\n },\n};\n\nfunction hexString(buffer: ArrayBuffer): string {\n const byteArray = new Uint8Array(buffer);\n\n const hexCodes = [...byteArray].map(value => {\n const hexCode = value.toString(16);\n const paddedHexCode = hexCode.padStart(2, '0');\n return paddedHexCode;\n });\n\n return hexCodes.join('');\n}\n"]}
\No newline at end of file