question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Secure random number generation is not supported by this browser

See original GitHub issue

I want to generate mnemonic in react-native. I use bip39 with browserify, and getting the error:

Error: Secure random number generation is not supported by this browser.
Use Chrome, Firefox or Internet Explorer 11

OS: MacOS node: v9.10.0 npm: 5.6.0 react-native-cli: 2.0.1 react-native: 0.57.1 “expo”: “^32.0.0” “bip39”: “^3.0.2”

Here is the project

image image image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
junderwcommented, May 8, 2019

Please do your own dev work.

This library is only guaranteed to work in the browser and NodeJS environments.

Anything else will require you to figure out how to make it work, trial and error.

Do what I said and it will work.

Synchronus calls use SJCL which relies on crypto, which react cannot use. Asynchronus calls use the native iOS/Android calls.

1reaction
leoparis89commented, Mar 30, 2022
import { randomBytes } from 'react-native-randombytes';

const getRandom = count => new Promise((resolve, reject) => {
  return randomBytes(count, (err, bytes) => {
    if (err) reject(err)
    else resolve(bytes)
  })
})

then you can use

async function someFunc() {
  const entropy = await getRandom(16)
  console.log(bip39.entropyToMnemonic(entropy))
}

You need to do the following for this to work.

1 - install react-native-random-bytes

yarn add react-native-randombytes
cd ios && pod install 

2 - shim node stream lib like follows (I found the shims here):

// metro.config.js
const path = require('path');
module.exports = {
  resolver: {
    extraNodeModules: {
      stream: path.resolve(__dirname, './node_modules/readable-stream'),
    },
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: true,
      },
    }),
  },
};



3 - And finally do:

yarn add events since readable-stream depends on it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Secure random number generation is not supported by ...
Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11. Works fine for iOS debug.
Read more >
Web3 ReactNative Error Secure random number generation is ...
Error: Secure random number generation is not supported by this browser. Use Chrome, Firefox or Internet Explorer 11.
Read more >
secure random number generation not supported by this ...
Original error: Error: secure random number generation not supported by this browser use chrome, FireFox or Internet Explorer 11.
Read more >
Crypto.randomUUID() - Web APIs - MDN Web Docs
The randomUUID() method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator.
Read more >
SecureRandom - Android Developers
Constructs a secure random number generator (RNG) implementing the default ... the first Provider that supports a SecureRandom (RNG) algorithm is returned.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found