Coder Social home page Coder Social logo

Comments (22)

lf94 avatar lf94 commented on May 21, 2024 6

I'm encountering the same problem. Unfortunately expo / metro can't be stopped easily in this regard.

This is literally the only package in our deps causing this issue. The exact issue is this:

** is being transpiled to Math.pow, which is incorrect, because Math.pow only takes regular number and not BigInt. So even if there is a BigInt polyfill, this does not fix the issue because now the code does Math.pow(BigInt(a), BigInt(b)). You can try this for yourself in nodejs or the browser console: 1n ** 1n is valid, Math.pow(1n, 1n) causes the error.

As a consequence we're going to have to fork the code and make adjustments... Which is not a big deal for us, but it will fragment the usage of this package.

Edit: I would like to point out that you have already done some work for supporting certain execution environments, i.e.

// Be friendly to bad ECMAScript parsers by not using bigint literals like 123n

This change would be along the same lines!

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024 3

Report this to FB. They need to move -- not us.

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024 2

So, what do you want? Change constants to some shitty computed value? How would you audit them after that? One of the primary reasons for creating the lib was auditability.

This is a bug of bad parsers. Report it to appropriate repos. I've did everything I could to ease the burden. Don't want to do what's unnecessary.

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024 2

Thanks for the pull request @lf94. Folks who run into the same problem could totally fork secp and use the solution. As i've mentioned, it uses eval, so be careful with CSP (secure contexts).

Those who want to use this with React Native should report the issue to facebook/metro#359. As soon as they'll get enough exposure, they should do something. Maybe submit pull requests to Metro, and call FB developers via Twitter etc.

I'm just a one guy trying to maintain this library. FB has more than enough resources to adjust their stuff to modern syntax.

from noble-secp256k1.

landabaso avatar landabaso commented on May 21, 2024 2

I believe it is not a good idea to fork this library.

It's better to fix the source of the problem (not this lib).

Open this file:

node_modules/metro-react-native-babel-preset/src/configs/main.js

And comment these lines so that the buggy transformer is not used:

+  //if (!isHermes && (isNull || src.indexOf("**") !== -1)) {
+  //  extraPlugins.push([
+  //    require("@babel/plugin-transform-exponentiation-operator"),
+  //  ]);
+  //}

And then run this command to make the patch permanent. npx patch-package metro-react-native-babel-preset

Anyway @lf94 , this will not work on Android anyway, right? react-native on Android does not support BigInt (so far).
Any shim will not work because they won't do operator overloading unless I'm missing something.
From what I read, next react-native 0.7 version will support BigInt.

from noble-secp256k1.

landabaso avatar landabaso commented on May 21, 2024 2

It will work on Android through various means but in the end it all really sucks.

@LeeAlephium I'd be very wary about using noble-secp256k1 with a BigInt polyfill for react-native & Android.

Note that polyfills will give wrong results for this kind of thing: BigInt("big number") + BigInt("another big number").
polyfills do not implement operator overloading. Worse than that, they will fail silently if I'm not mistaken.

Maybe you were thinking in another way to go around BigInt not being available in Android/RN that that I'm not aware?
Anyway I leave this note here in case someone else is tempted to use a polyfill with this library.

from noble-secp256k1.

lf94 avatar lf94 commented on May 21, 2024 1

For those who will inevitably find themselves here: https://github.com/paulmillr/noble-secp256k1/pull/60/files

from noble-secp256k1.

lf94 avatar lf94 commented on May 21, 2024 1

Yeah I totally understand. Thank you regardless for this excellent work you've done!

Unfortunately that issue is 3 years old (we found that issue early on in our attempts to fix this) and I don't expect anything to happen any time soon... Hence why I've come to you. 🙂 (Edit: I've commented on the issue so at least my vote is cast...)

To anyone else: you can use @alephium/noble-secp256k1 which is explicit about being a fork of this project, and that you should use this project over it if it's possible. It uses the precomputed solution so it's way way faster.

from noble-secp256k1.

steveluscher avatar steveluscher commented on May 21, 2024 1

Yep! I know. I already have a PR going on against facebook/react-native#34589

I also updated the Solana Cookbook to this effect: solana-developers/solana-cookbook#435

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024

There is no "shim" for native bigints. You need to use environments which support bigints natively. We don't provide support for transpiled code

from noble-secp256k1.

lf94 avatar lf94 commented on May 21, 2024

I had to do worse actually: eval of a string of the equivalent to **, but it builds and all tests pass.

What I'm suggesting here is maybe keep this second file on the side and add a react-native property to your package.json. I'll open a PR so you can see what I've done. You'll see it's absolutely disgusting but there's no other option for us... I'm on your side that the parsers / transpilers need to step up but that's just the shitty ecosystem we are in. I'm with you that this change makes it much less auditable, if at all.

I would rather work with you on this than against; if this package can just provide a react-native variant, that's more than enough, even if it's shitty.

from noble-secp256k1.

LeeAlephium avatar LeeAlephium commented on May 21, 2024

It will work on Android through various means but in the end it all really sucks. Unfortunately avoiding BigInt is hard when it comes to cryptography. I believe it isn't a good idea either to fork the library but the choices are few and far between...

from noble-secp256k1.

LeeAlephium avatar LeeAlephium commented on May 21, 2024

I share the sentiment and warning to others. 👍 You must be very careful. I reiterate the whole situation sucks (and not because of noble-secp256k1 but because of FB)...

from noble-secp256k1.

steveluscher avatar steveluscher commented on May 21, 2024

Help is finally on the way. The combination of React Native 0.70 and Hermes will bring support for bigint and the exponentiation operator. https://twitter.com/steveluscher/status/1563940234005745665

from noble-secp256k1.

elliotsayes avatar elliotsayes commented on May 21, 2024

@steveluscher Even with RN 7.0.0 and hermes, this does not yet work by default. See my comment here on how to activate it:
facebook/metro#359 (comment)

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024

75c244b makes sure bigint ** is never used. With this change, and new release, the library now works in React Native 0.70.

from noble-secp256k1.

GabiDev45 avatar GabiDev45 commented on May 21, 2024

Any solution for this issue has been found yet ?

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024

@GabiDev45 upgrade to latest react native

from noble-secp256k1.

VGabriel45 avatar VGabriel45 commented on May 21, 2024

@GabiDev45 upgrade to latest react native

I already have it upgraded, tried everything discussed here, nothing seems to work.

from noble-secp256k1.

horatiubran avatar horatiubran commented on May 21, 2024

ITS 2023... IS IT JUST ME HAVING THIS ISSUE ?

from noble-secp256k1.

paulmillr avatar paulmillr commented on May 21, 2024

@horatiubran yes. 1. update react-native. 2. use noble-curves instead of noble-secp v2

from noble-secp256k1.

KholdStare avatar KholdStare commented on May 21, 2024

May not be related, but some transpilers like babel will convert things like ** to Math.pow which doesn't work with BigInt. See hirosystems/stacks.js#1096 (comment) . Perhaps the problem is in something else in your setup that is transpiling the code wrong.

from noble-secp256k1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.