react-native-quick-crypto icon indicating copy to clipboard operation
react-native-quick-crypto copied to clipboard

Getting Error while creating wallet from ethers

Open informsharique opened this issue 3 years ago • 3 comments

I'm getting the following error while creating a wallet using ethers. const wallet = ether.Wallet.createRandom()

WARNING: Missing strong random number source ERROR Error: no secure random source avaialble (operation="crypto.getRandomValues", code=UNSUPPORTED_OPERATION, version=random/5.7.0), js engine: hermes

image

INFO: React Native: 0.69.5 (also tested on 0.68.4) ios Simulator: ios 15 Machine: Mac M1

informsharique avatar Sep 06 '22 23:09 informsharique

I checked the issue and found out that it is because of getRandomValues() used by ethers.js So I found a package called react-native-get-random-values, installed it and now wallet is being created but its taking 15475 ms to create a wallet which is not what I expected. Seems the package is not coming into actions. Any idea??

Here's my bable.config.js

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    [
      'module-resolver',
      {
        alias: {
          crypto: 'react-native-quick-crypto',
          stream: 'stream-browserify',
          buffer: '@craftzdog/react-native-buffer',
          'bn.js': 'react-native-bignumber',
        },
      },
    ],
  ],
};

And here what I'm doing in the app

import 'react-native-get-random-values';
import {ethers} from 'ethers';
import {Text, TouchableHighlight, View} from 'react-native';

const App: React.FC<
  PropsWithChildren<{
    title: string;
  }>
> = ({title}) => {
  const createCryptoWallet = () => {
    const start = Date.now();
    const wallet = ethers.Wallet.createRandom();
    const end = Date.now();
    console.log(`Creating a Wallet took ${end - start} ms.`);
  };

  return (
    <View style={styles.sectionContainer}>
      <Text style={styles.header}>{title}</Text>
      <TouchableHighlight style={styles.button} onPress={createCryptoWallet}>
        <Text>Create Wallet</Text>
      </TouchableHighlight>
    </View>
  );
};

And this is the log LOG Creating a Wallet took 15475 ms.

informsharique avatar Sep 07 '22 00:09 informsharique

I'm having the same problem. react-native-quick-crypto is supposed to be replacing the default one. I was able to work around this by importing crypto from react-native-quick-crypto in my index.js file so the global was overridden...

import crypto from 'react-native-quick-crypto';

paulingalls avatar Sep 10 '22 18:09 paulingalls

@paulingalls This is not working for me. Taking the same about 15s to create a random wallet. I tried few other options as well including importing buffer and react-native-bignumber. Nothing seems to work

informsharique avatar Sep 15 '22 18:09 informsharique

This is a duplicate of https://github.com/margelo/react-native-quick-crypto/issues/85 Solution is linked in issue

hbriese avatar Apr 20 '23 04:04 hbriese

thank you for reporting this issue, but it is (like already mentioned) a duplicate of:

-https://github.com/margelo/react-native-quick-crypto/issues/85

Montchy avatar Aug 14 '23 09:08 Montchy