bitcoinjs / tiny-secp256k1

A tiny secp256k1 native/JS wrapper
MIT License
90 stars 55 forks source link

I want to use this in react-native app but it failed with this error #84

Closed Ella-noncelab closed 2 years ago

Ella-noncelab commented 2 years ago

This is the code snippet I used tiny-secp256k1

스크린샷 2022-04-25 오후 7 22 26


When I run this app, below error occurred.

error: Error: While trying to resolve module tiny-secp256k1 from file /Users/eunjilim/AssetController.ts, the package /Users/app/node_modules/tiny-secp256k1/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/Users/app/node_modules/tiny-secp256k1/lib/cjs/index.cjs. Indeed, none of these files exist:


and when try to run application this warning show up

스크린샷 2022-04-25 오후 7 00 38

junderw commented 2 years ago

Probably better to ask this on the metro repo.

niteshbalusu11 commented 2 years ago

@Ella-noncelab did you have any luck with this one? I have the same issue.

junderw commented 2 years ago

It's probably an issue with hybrid packages.

  1. Node uses a new exports key in package.json to denote the ESM vs. the CJS modules.
  2. Some legacy tools require a main key in package.json to point to CJS.
  3. Your tool probably bundles the ESM but then looks for the main key (CJS) and is probably getting confused.

But I don't know, since I am not the developer of metro

Please ask them.

junderw commented 2 years ago

I've gone ahead and reported the issue on your behalf, hopefully a solution will be found.

robhogan commented 2 years ago

Metro maintainer here - thanks @junderw for calling attention to this, it's a known issue on the Metro side. See https://github.com/facebook/metro/issues/815#issuecomment-1117607661 for a workaround.

junderw commented 2 years ago

Thanks for the temporary solution and confirmation that the fix is on your radar.

niteshbalusu11 commented 2 years ago

Thanks guys! Appreciate the help.

Ella-noncelab commented 2 years ago

@Ella-noncelab did you have any luck with this one? I have the same issue.

Sorry.. I just gave up to use this. Because I only have to get addresses and keys so I use 'hdkey' package instead. https://www.npmjs.com/package/hdkey

landabaso commented 2 years ago

Anyway guys, be aware that tiny-secp256k1 uses WASM which is not supported by react-native Javascript Core engine (iOS / Android). It does work on react-native-web though. Note that Android emulator may run WASM but it will not run on the actual device.

You can use the older version tiny-secp256k1@1 (which is quite slow on devices but does the job) or @noble/secp256k1 which is super fast (order-of-magnitude comparable to WASM) and works together just fine with bitcoinjs-lib.

One last thing. One problem with @noble/secp256k1 is that it is based on BigInt, which is only supported in React-Native by iOS right now, but will also join Android in the upcoming RN-0.70 release (using the new Hermes Js engine).

wookaas commented 2 years ago

Anyway guys, be aware that tiny-secp256k1 uses WASM which is not supported by react-native Javascript Core engine (iOS / Android). It does work on react-native-web though. Note that Android emulator may run WASM but it will not run on the actual device.

You can use the older version tiny-secp256k1@1 (which is quite slow on devices but does the job) or @noble/secp256k1 which is super fast (order-of-magnitude comparable to WASM) and works together just fine with bitcoinjs-lib.

One last thing. One problem with @noble/secp256k1 is that it is based on BigInt, which is only supported in React-Native by iOS right now, but will also join Android in the upcoming RN-0.70 release (using the new Hermes Js engine).

How to replace tiny-secp256k1 with @noble/secp256k1? They have different methods. I want to use it with bitcoinjs-lib

landabaso commented 1 year ago

How to replace tiny-secp256k1 with @noble/secp256k1? They have different methods. I want to use it with bitcoinjs-lib

Take a look to this npm package: https://github.com/bitcoinerlab/secp256k1.

crukundo commented 1 year ago

How to replace tiny-secp256k1 with @noble/secp256k1? They have different methods. I want to use it with bitcoinjs-lib

Take a look to this npm package: https://github.com/bitcoinerlab/secp256k1.

This helped. If you are running RN >0.70 with Hermes, this might unblock you.