Open confxsd opened 5 months ago
You should never try to generate a private key on an environment that does not have a secure random source, but the source can be modified:
ethers.randomBytes.register((length) => {
// Return a Uint8Array of length, filled with your random values
});
Alternatively, when building for the browser, make sure your bundler is picking up the browser versions of the files; there is a crypto-browser file pulled in via the package.json when configured in your bundler, which uses the Web crypto API.
Does that make sense?
Ethers Version
6.11.1
Search Terms
crypto, SystemRandomSource, randomBytes
Describe the Problem
Hello ethers team,
I am encountering an issue when using the ethers library in a UMD environment that targets both browser and server. The issue relates to the crypto functionality used by the ethers library.
The problem occurs when I try to use
Wallet.createRandom();
and the ethers library tries to access Node.js's crypto module functionalities.I tried polyfill in webpack but it didn't work out.
fallback: { crypto: require.resolve("crypto-browserify"),
Webpack version: 5.90.3 TypeScript version: 4.7.2 Node.js version: 20.4.0
webpack.config.js:
tsconfig.json:
Code Snippet
Contract ABI
No response
Errors
Environment
node.js (v12 or newer), Browser (Chrome, Safari, etc)
Environment (Other)
No response