Open YannisDC opened 7 years ago
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))
@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
@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...
@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.
Any workarounds found for this? Currently seeing the same issue as original post
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.
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?