"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.crypto = exports.getRandomValues = exports.packageInfo = void 0; const react_native_1 = require("react-native"); const base64_1 = require("@pezkuwi/wasm-util/base64"); const x_global_1 = require("@pezkuwi/x-global"); const browser_js_1 = require("./browser.js"); var packageInfo_js_1 = require("./packageInfo.js"); Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } }); /** * @internal * * A getRandomValues util that detects and uses the available RN * random utiliy generation functions. **/ function getRandomValuesRn(output) { if (!react_native_1.NativeModules['ExpoRandom'] && !react_native_1.NativeModules.RNGetRandomValues) { throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues and no React Native secure RNG module is available.'); } return (0, base64_1.base64Decode)(react_native_1.NativeModules.RNGetRandomValues ? react_native_1.NativeModules.RNGetRandomValues.getRandomBase64(output.length) : react_native_1.NativeModules.ExpoRandom.getRandomBase64String(output.length), output); } const hasNativeRNModules = !!react_native_1.NativeModules['ExpoRandom'] || !!react_native_1.NativeModules.RNGetRandomValues; const hasNativeCrypto = typeof x_global_1.xglobal.crypto === 'object' && typeof x_global_1.xglobal.crypto.getRandomValues === 'function'; exports.getRandomValues = (hasNativeRNModules ? getRandomValuesRn : hasNativeCrypto ? browser_js_1.getRandomValues : () => { throw new Error('No secure random number generator available. This environment does not support crypto.getRandomValues.'); }); exports.crypto = (exports.getRandomValues === browser_js_1.getRandomValues ? browser_js_1.crypto : { getRandomValues: exports.getRandomValues });