mvayngrib / react-native-randombytes

randomBytes for react-native
MIT License
83 stars 95 forks source link

Build fails because sjcl depends on node.js #20

Closed ianmcgregor closed 6 years ago

ianmcgregor commented 6 years ago

I was able to get this working by bypassing require('react-native-randombytes'):

const RNRandomBytes = require('react-native').NativeModules.RNRandomBytes;

RNRandomBytes.randomBytes(4, (err, base64String) => {
  if (err) {
    this.setState({err: err})
  } else {
    this.setState({rnd: base64String})
  }
});

Should the synchronous sjcl based method be removed entirely so that this module works out of the box?

mvayngrib commented 6 years ago

@ianmcgregor this module works out of the box if you have things set up with rn-nodeify. That said, rn-nodeify is missing from this README! I guess I assumed people would be installing this module as part of https://github.com/tradle/react-native-crypto , which explains what to do

ianmcgregor commented 6 years ago

Thanks @mvayngrib -- I only need the RNG so this is great now I've got it working. Could also add this example for usage outside of rn-nodify? I can submit a PR if that helps?

mvayngrib commented 6 years ago

@ianmcgregor i like your first suggestion, of having it work out of the box async. Maybe the code should allow require('sjcl') to fail. On failure, console.warn and on sync invocation throw an Error, but keep async working. Either way an explanation in the readme would be good to have. Happy to accept a PR for either the refactor, the readme or both :)

ianmcgregor commented 6 years ago

@mvayngrib Allowing the require('sjcl') to fail is looking difficult without adding undesirable complexity to your code due to the way React Native's 'Haste' module system works.

I think your recent update to the README makes it clear how to use for standalone random. Thanks for sharing this code.