LinusU / react-native-get-random-values

A small implementation of `getRandomValues` for React Native
MIT License
350 stars 48 forks source link

Error: no secure random source avaialble for ethersjs 5.7.0 #43

Closed emclab closed 1 year ago

emclab commented 1 year ago

My React native (0.70) app has been using react-native-get-random-values 1.8.0 with ethersjs 5.7.0 on MacOS to generate private keys for longtime. but I just noticed an error from ethersjs about the secure random source unavailable:

Error: no secure random source avaialble (operation="crypto.getRandomValues", code=UNSUPPORTED_OPERATION, version=random/5.7.0)

Here is the code:

import 'react-native-get-random-values';
import "@ethersproject/shims";  //for ethers.js
// Import the ethers library
import { ContractFactory, ethers } from "ethers";

export default function SplashScreen({navigation, route}) {
   console.log("bytes by crypto.getRandomValues : ", (new ethers.utils.randomBytes(32))); //<<==throw the error above about secure random source
  console.log("bytes by crypto.getRandomValues : ", global.crypto.getRandomValues(arr8));  //<<=global.crypto undefined. access the random value directly on global.crypto.getRandomValues() as specified on the doc
}

What is missing here?

emclab commented 1 year ago

verify that global.crypto.getRandomValues does exist. But somehow ethersjs didn't see it.

LinusU commented 1 year ago

verify that global.crypto.getRandomValues does exist. But somehow ethersjs didn't see it.

This seems like a problem with etherjs then and I'm afraid that I can't help you. Could you open an issue with them?