indutny / elliptic

Fast Elliptic Curve Cryptography in plain javascript
1.68k stars 372 forks source link

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

Open ivanpagac opened 6 years ago

ivanpagac commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Same issue here..

maxisacoder commented 5 years ago

same issue

skyflysun commented 5 years ago

same issue here; main problem in dependcy brorand

MichaelQ1an commented 5 years ago

same issue here

karankurbur commented 5 years ago

same issue with react native app

kekby commented 5 years ago

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.