ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.91k stars 1.84k forks source link

ethers.Wallet.createRandom() is taking long time on android ethers@5.7.2 #3930

Open salahbm opened 1 year ago

salahbm commented 1 year ago

Ethers Version

5.7.2

Search Terms

No response

Describe the Problem

I have been using using ethers 5.7.2, because v6 didnt match with my environment. So the Problem is when I create the wallet on iOS device it works fast however not on the android; on the android device it takes around 1 min and around 30 secs on the android emulator.

Code Snippet

import {ethers} from 'ethers';

export default function newWallet() {
  const start = performance.now();

  const wallet = ethers.Wallet.createRandom();
  const walletInfo = {
    mnemonic: wallet._mnemonic().phrase,
    address: wallet.address,
    privateKey: wallet.privateKey,
  };
  const end = performance.now();
  console.log(`Creating a Wallet took ${end - start} ms.`);
  return walletInfo;
}

Contract ABI

No response

Errors

LOG  Creating a Wallet took 161352.9246249795 ms.

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli), React Native/Expo/JavaScriptCore

Environment (Other)

No response

zemse commented 1 year ago

Related https://github.com/ethers-io/ethers.js/issues/1503. From the discussion, it seems that pbkdf2's JS implementation is used which is very slow on Andriod, so somehow you can try using a native implementation.

Also can you try on v6?

salahbm commented 1 year ago

Yeah I have tried native implamentation shown there previously, however, facing an error still. Thanks

ricmoo commented 1 year ago

For an immediate fix (as long as you don’t need a mnemonic) you can use new Wallet(hexlify(randomBytes(32))).

I’m working on a RN package that will install and configure everything for you too.

salahbm commented 1 year ago

n immediate fix (as l

Thanks, appreciate it. But I need mnemoic. so looking forward to RN package be fixed...

dtourassis commented 1 year ago

@ricmoo Glad to hear that a RN package is on the way, really looking forward to it!