diff --git a/index.js b/index.js index ea95358..8a6bf62 100644 --- a/index.js +++ b/index.js @@ -4,21 +4,6 @@ const { TurboModuleRegistry } = require('react-native') class TypeMismatchError extends Error {} class QuotaExceededError extends Error {} -let warned = false -function insecureRandomValues (array) { - if (!warned) { - console.warn('Using an insecure random number generator, this should only happen when running in a debugger without support for crypto.getRandomValues') - warned = true - } - - for (let i = 0, r; i < array.length; i++) { - if ((i & 0x03) === 0) r = Math.random() * 0x100000000 - array[i] = (r >>> ((i & 0x03) << 3)) & 0xff - } - - return array -} - let module = null /** * @param {number} byteLength @@ -51,27 +36,11 @@ function getRandomValues (array) { return array } - // Calling getRandomBase64 in remote debugging mode leads to the error - // "Calling synchronous methods on native modules is not supported in Chrome". - // So in that specific case we fall back to just using Math.random(). - if (isRemoteDebuggingInChrome()) { - return insecureRandomValues(array) - } - base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength)) return array } -function isRemoteDebuggingInChrome () { - // Remote debugging in Chrome is not supported in bridgeless - if ('RN$Bridgeless' in global && RN$Bridgeless === true) { - return false - } - - return __DEV__ && typeof global.nativeCallSyncHook === 'undefined' -} - if (typeof global.crypto !== 'object') { global.crypto = {} }