MetaMask / eth-sig-util

A collection of functions for signing and verifying data with Ethereum keys.
ISC License
577 stars 226 forks source link

Cannot convert a BigInt value to a number #298

Open irzhywau opened 1 year ago

irzhywau commented 1 year ago

When I loaded the library I just got this error in a react app

import { recoverTypedSignature } from '@metamask/eth-sig-util';

I got this error when loading the page, the method is not even executed yet. any idea?

React version 18.2.0

coderguy1998 commented 1 year ago

I have got the same error and I guess this is being produced by the @noble package being used internally, I'm using it in an Angular project and the by keeping the buildOptimiser as true it breaks (basically the prod server) but locally everything works fine.

mcmire commented 1 year ago

Hi @irzhywau, when you say you received this error in a React app, did you use create-react-app to create your app? Just so we can reliably reproduce this error.

malaDev commented 1 year ago

yes indeed I used create-react-app

mcmire commented 1 year ago

@malaDev Hmm, I'm not able to reproduce this in a fresh React app (create-react-app 5.0.1, React 18.2.0). I did get an error about Buffer not being available, but that's expected — you'll need the buffer package to get around this. But I didn't get the error you mentioned. Any chance you can push up a repo that reproduces this error?

malaDev commented 1 year ago

oh really

unfortunately it's a private repo. that's weird. do you have any idea which part can cause such an exception? any other lib?

mcmire commented 1 year ago

@malaDev It's possible that it's some other library. Do you have any other dependencies that you're using in your repo besides this library?

malaDev commented 1 year ago

I actually only get this error when I add the library, without it everything work smoothly

mcmire commented 1 year ago

@malaDev Right, but there may be an interaction between this library and another library you're using. If I know all of the libraries you're using then I am better able to reproduce this issue. Or, if there's a stack trace you can post, that may give me more information.

keithchew commented 1 year ago

Hi

I was also having this issue, and I tracked it down to v5.0.0 moving to @noble package (which uses BigInt).

https://github.com/MetaMask/eth-sig-util/releases

Changed
BREAKING: Removed support for Node v12 in favor of v14 (https://github.com/MetaMask/eth-json-rpc-middleware/pull/137)
Replace heavy crypto packages for lighter noble implementations via upgrading ethereumjs-util to latest (now called @ethereumjs/util) (https://github.com/MetaMask/eth-sig-util/pull/260)
Migrate to Yarn 3 (https://github.com/MetaMask/eth-sig-util/pull/264)

I pinned my version to the last version before this change:

"@metamask/eth-sig-util": "^4.0.1",

and all is good, my dapp supports safari < 14 again.

Hope this helps.