Library does not work on the FE side
bkosm opened this issue · comments
Bartosz Kosmala commented
Hey, I'm trying to get this lib working on the client side with React, Vite, Javascript & pnpm.
The library was added with pnpm i ethereum-cryptography
.
A utils file looks like this:
import { keccak256 } from "ethereum-cryptography/keccak";
import { utf8ToBytes, toHex } from "ethereum-cryptography/utils";
import secp from "ethereum-cryptography/secp256k1";
//...
/**
* @returns {string} random private key as hex string
*/
function randomPrivateKey() {
return pipe(
secp.utils.randomPrivateKey(),
toHex
)
}
export {
//...
randomPrivateKey,
}
I use the function randomPrivateKey
inside of a react component and it fails with:
Uncaught TypeError: Cannot read properties of undefined (reading 'utils')
at randomPrivateKey (utils.js:68:14)
at onGenerate (KeyGen.jsx:7:24)
A project that demonstrates this issue can be found here.
Sorry to bother you but I can't find solutions online. Am I missing some configuration to get this to work, or is it not possible altogether?
Paul Miller commented
import * as secp