Skip to content
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

Usage in React Native #139

Open
YannisDC opened this issue Mar 23, 2017 · 6 comments
Open

Usage in React Native #139

YannisDC opened this issue Mar 23, 2017 · 6 comments

Comments

@YannisDC
Copy link

Since crypto doesn't work in react native apparently I tried using react-native-crypto and installed it as suggested.

However I get the same error saying: Unable to resolve module crypto from <PROJECTROOT>/node_modules/bitcore-lib/lib/crypto/hash.js

Is there any way to circumvent this?

@Loyz07
Copy link

Loyz07 commented Apr 3, 2017

Same issue. We manage to install react-native-crypto but we've got a new error :
undefined is not a function (evaluating BufferUtil.isBuffer(argument))

@seanavery
Copy link

seanavery commented Apr 4, 2017

@YannisDC @Loyz07 I am also working around this.

I have used this hack: https://github.com/mvayngrib/rn-nodeify and it seems to work with "browserifying" node's crypto library, also web3 and its dependencies.

However, I am still having issues with eth-lightwallet. I have to import from the ./index instead of the minified js dist.

Also exploring this alternative: https://github.com/philikon/ReactNativify

@seanavery
Copy link

@Loyz07 Were you able to sort out the undefined BufferUtil, I am having the same issue.

Seems to be a problem with the bitcore/lib/util/preconditions.js

Some people have had success by hacking the file as such:

var buffer = require('buffer');
        if (!(buffer.Buffer.isBuffer(argument) || argument instanceof Uint8Array)){
          throw new errors.InvalidArgumentType(argument, type, argumentName);
        }
        // var BufferUtil = require('./buffer');
        // if (!BufferUtil.isBuffer(argument)) {
        //   throw new errors.InvalidArgumentType(argument, type, argumentName);
        // }

However, this is not working for me...

@Loyz07
Copy link

Loyz07 commented Apr 5, 2017

@seanavery No sorry. It seems to be a problem with rn-nodeify that doesn't polyfill correctly Buffer module.

We are working on an other solution with Web3J and a native module since no solution is found for this issue.

@pablohern427
Copy link

Any workarounds found for this? Currently seeing the same issue as original post

@alex-miller-0
Copy link

I'm new to react-native so can't provide a ton of deep insight, but I run into similar issues just trying to get crypto functions working.

Since crypto is a node package and not supported by react-native, you will need to use rn-noedify and run the following postinstall script:

node_modules/.bin/rn-nodeify --install assert,buffer,crypto,events,process,stream,vm --hack

Or whatever combination of packages you want. If you want to install all node packages, you can run:

node_modules/.bin/rn-nodeify --install --hack

As @Loyz07 noted, this will not resolve the Buffer module properly. rn-nodeify will populate your root project directory with a file called shim.js. You may need to import this when using crypto.

let crypto = require('crypto');
import '../shim.js'

I believe the above is actual an aliased version of react-native-crypto, which you will also need to have installed and linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants