-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-native bitcoinjs install issues #976
Comments
@wmpedersen could you please post your log dump from |
@dcousens it doesn't seem like an issue with my app including bitcoinjs - there's no problem with npm install (other than the dependencies), more of how I include it in a react-native app. I've got the dependencies listed below in my app's node_modules folder, so I don't know why it's not finding them... EDIT: I did seem to figure it out - looks like I had most of the setup correct and followed #559's
And can properly generate a mnemonic with bip39. More testing needs to be done to confirm other crypto libraries, but if my helper library has made it this far, it's looking good. |
weird, now it's giving me secure RNG issues... |
@wmpedersen it may seem like no one is listening, but I guarantee any information you post about the problems you're having will help someone in the future, so please post the details 👍 |
seems like it's doing the same thing but I have react-native-randombytes^3.0.0 I don't know what changed. I might just try from my test repo from the beginning again and add my code. I was messing about with things - I seem to remember |
So no matter what I've done I can't seem to put it back in my working state. My project uses react-native-randombytes properly in terms of importing it into the project again, but it seems bip39 is still complaining about my RNG because it's still trying to use non-react randombytes. |
edit by @dcousens: Warning, this comment contains unsafe code, do not use for generating private keys @wmpedersen If you're still having this issue hopefully the following will help you out. I created a repo here (https://github.com/coreyphillips/react-native-bitcoinjs-lib/blob/master/src/ecpair.js) if you would like to use it as an aid for the ecpair section below:
Resolve Item In Ecpair.js
Resolve Item in Transaction Builder
|
@coreyphillips phillips you understand you could pass in Additionally, your RNG is initializing the edit: That is terrible. @coreyphillips if you have generated private keys with that code, I'd recommend sweeping them as fast as possible. |
Thanks @dcousens. I've updated the makeRandom function to reflect your input. Regarding the myRng function, is there anything that you would suggest implementing there that would be both cryptographically secure and compatible for a React Native implementation? Edit: I haven't generated any private keys using this method. This is just my best effort in getting a working build going for React Native. |
var num = random.int32();
buf.fill(num)
return buf int32 is not 32-bytes, its 32-bits. That is a |
@coreyphillips I'd recommend you open an issue at |
@coreyphillips was the issue #559 (comment) not helpful to you? |
@dcousens I did see that. Unfortunately, react-native-randombytes continues to throw an error. Still more troubleshooting ahead. Almost there though :-) |
Huzzah, looks like it may have been a linking issue with react-native-randombytes. It appears to be working now. I've updated the ecpair.js file here. The only change made to the file is the require for |
Again, you don't need to modify bitcoinjs for this. You can pass react-native-randombytes as an argument to ECPair. |
Thanks @dabura667. Understood. Edit: Just to clarify, while ecpair.js no longer requires any modification when using the library in RN. This appears to be the only remaining issue encountered when using this library in RN. |
@corey-phillips what about the other
|
@dcousens, you are correct. The remaining |
@corey-phillips OK... I'm not against re-introducing |
Facebook. |
@dcousens Basically what dabura667 said. |
@corey-phillips the solution mentioned here works fine on simulator or debugging on device: #976 (comment), however, when I package an release APK file and install it on device, then I get error: ReactNativeJS: TypeError: undefined is not a function (evaluating 'Error.captureStackTrace(this,y)') |
@jackylimel great to know! |
The weird thing is. If I just call Could someone please help? |
I've found the problem is caused by |
The error as follow:
I think it's the
My Env:
This is the issue: mvayngrib/react-native-randombytes#10 |
@zhaozhiming maybe you should bump mvayngrib/react-native-randombytes#10 for answers? As for how we could resolve this... we could optionally remove the default But that seems a bit overkill. |
OK, Thank you. |
Could That library can use different |
That is reeeeally insecure.................. console.log with a warning is not sufficient. The randomness of those values should not be anywhere near an app that generates private keys. |
looping 20 rounds shows that the person who made this has no understanding of how Math.random works. |
Do you have I Followed what coreyphillips wrote above then added a few steps.
Resolve Item In Ecpair.js
Resolve Item in Transaction Builder
Resolve Item In sjcl change in sjcl/sjcl.js where it says:
Then there might be an error for asn1.js will be produced: vm cannot be found
To test if everything is working as expected place the following in render:
|
I solved the missing buffer.reverse() simply by adding the following code to my shim.js.
|
@ShayanJa, to prevent updating or changing the sjcl/sjcl.js file, you can instead:
|
Using the feedback from this thread I've created a gist that documents the setup process for getting version 4.0.1 of bitcoinjs-lib up and running in RN. Hopefully it will help to close this issue. Please let me know if there are any glaring issues or if you have any feedback in general. |
@coreyphillips followed the gist, receiving this error on start:
Followed your suggestion in Update: looks like this happened because I used yarn. I added Update 2: nope. Having issues with Update 3: running |
@cbrwizard Regarding your initial error, you'll want to make sure to apply the following step:
For Regarding update 2 & 3, you should only need to add vm to your postinstall, but, hey, if it works... 😄 |
4.0.2 gets rid of the package.json btw |
Is there a way to automate these changes inside the node_modules btw? Because hard-coding them looks wrong and the changes get reverted back on packages installation. Or do I have to create a fork or something |
@cbrwizard what changes are you referring to specifically? |
Had to switch to bitcoinjs-lib because the react native one is very outdated. Luckily, it worked after I followed https://gist.github.com/coreyphillips/f33d86f3d2307e58f0a5686e6cfc8a7e, so thanks @coreyphillips ! @dcousens I had to manually apply this change in my project's node module: Open package.json in .../bitcoinjs-lib/src/payments/package.json and replace "main": "_testnet.js", with the following: "main": "index.js", |
@cbrwizard package.json does not exist in 4.0.2 |
Check the folder @ 4.0.2 No package.json there at all. The error you experience should not occur. |
@junderw yup 4.0.2 works now without any manual changes in node_modules, so all good! Thank you! @coreyphillips you might want to update the gist to reduce the number of steps with 4.0.2 |
Thanks @cbrwizard. I've updated the 4.0.2 gist: https://gist.github.com/coreyphillips/928ae27ccea69cd0b494d13ad2b3f27d I'm going to do my best to update and maintain a RN compatible repo here (https://github.com/coreyphillips/rn-bitcoinjs-lib) with setup instructions if you ever need it for reference. |
If you are experiencing issues with this library working fine in Simulator/Debug mode, but not working when preparing for release, you need to disable No need to patch anything though, just add the following to your
🎉 |
Can anyone here check if the most recent version still has any of these issues. We have switched to TypeScript, so some issues might just be solvable by messing with tsconfig.json??? |
Versions tested:
@junderw, the more recent versions definitely seem to have smoothed out a few of the previous issues. Using the versions listed above the minimum amount of work required to get it running in RN (as far as I can tell) is as follows: https://gist.github.com/coreyphillips/4d45160fed016417a5f583f179c2cbdb |
@coreyphillips hmmm... I thought I removed all Buffer.prototype.reverse() instances... Is that really needed? |
@junderw Awesome, you're correct, it isn't needed. I just forgot to remove the condition in |
I'm trying to implement bitcoinjs-lib in react-native, but I get errors when it looks for Buffer and other crypto libraries. I have used rn-nodeify as referenced in #582 and #797 and imported the shim but it's still complaining. My install process to include bitcoinjs-lib/bip39 is as follows:
npm install --save bitcoinjs-lib bip39 react-native-crypto
npm install
(at this point the post-install doesrn-nodeify --install fs,dgram,process,path,console --hack
)react-native start
andreact-native run-android
for my emulatorreact-native is still complaining about stream, and once I include stream it complains about buffer/safe-buffer/cipher-base and once I include any of those and rebuild it gives the infamous "Can't find variable Buffer"
I've read around that others have got it to work but have yet to be able to build it myself. Any pointers in the install process?
The text was updated successfully, but these errors were encountered: