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

null is not an object (evaluating 'this.rand.getBytes') #159

Open
ivanpagac opened this issue Jun 4, 2018 · 7 comments
Open

null is not an object (evaluating 'this.rand.getBytes') #159

ivanpagac opened this issue Jun 4, 2018 · 7 comments

Comments

@ivanpagac
Copy link

Hi Guys, trying to create keyPair with

import { ec as EC } from "elliptic";

const ECContext = new EC("p256");

export function generateKeyPair() {
  let pair = ECContext.genKeyPair();
....
}

but failing on getKeyPair, probably brorand library failing ? Anyone with this issue? Tried multiple node_modules removal, npm installs. To give you context I am creating react-native app.

@nshCore
Copy link

nshCore commented Jun 11, 2018

Im getting same issue looks like its not finding the brorand library correctly, but you can just pass your own entropy in as an option.

EC.genKeyPair({ entropy: 'some 256 bit string that is random here})

@ansonyao
Copy link

Same issue here..

@maxisacoder
Copy link

same issue

@skyflysun
Copy link

same issue here;
main problem in dependcy brorand

@MichaelQ1an
Copy link

same issue here

@karankurbur
Copy link

same issue with react native app

@kekby
Copy link

kekby commented Apr 11, 2019

yeas, problem is in brorand package.
brorand needs crypto package, but it doesnt exist in JSCore, so we need to tell brorand to use react-native-randombytes instead of crypto.randomBytes.
this can be fixed via patch-package and manually editing brorand package, by example:

 try {
    var randBytes = require('react-native-randombytes').randomBytes;
    if (typeof randBytes !== 'function')
      throw new Error('Not supported');
    Rand.prototype._rand = function _rand(n) {
      return randBytes(n);
    };
  } catch (e) {
  }

and then patch-package brorand, so it will create .patch file for brorand.

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

8 participants