Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
key: 'fromRand',
// Creates a new random BigNum of the given number of bytes
value: function fromRand(length) {
// TODO: This should use a properly seeded, secure RNG
bytes = [];
for (var i = 0; i < length; ++i) {
bytes.push(Math.floor(Math.random() * 128));
}
return new BigNum(bytes);
}
}, {
key: 'ZERO',
// Convenience BigInteger.ZERO decorator
value: new BigNum(BigInteger.ZERO),
enumerable: true
}]);
return BigNum;
})();
import BigInteger from 'jsbn/lib/big-integer';
// C-like BigNum decorator for JSBN's BigInteger
class BigNum {
// Convenience BigInteger.ZERO decorator
static ZERO = new BigNum(BigInteger.ZERO);
// Creates a new BigNum
constructor(value, radix) {
if (typeof value === 'number') {
this._bi = BigInteger.fromInt(value);
} else if (value.constructor === BigInteger) {
this._bi = value;
} else if (value.constructor === BigNum) {
this._bi = value.bi;
} else {
this._bi = new BigInteger(value, radix);
}
}
// Short string description of this BigNum
toString() {