react-native-quick-crypto
react-native-quick-crypto copied to clipboard
Getting Error while creating wallet from ethers
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

INFO: React Native: 0.69.5 (also tested on 0.68.4) ios Simulator: ios 15 Machine: Mac M1
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.
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 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
This is a duplicate of https://github.com/margelo/react-native-quick-crypto/issues/85 Solution is linked in issue
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