Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const genPrivKey: PrivKey = () => {
// Check whether we are using the correct value for SNARK_FIELD_SIZE
assert(SNARK_FIELD_SIZE.eq(snarkjs.bn128.r))
// Prevent modulo bias
const min = (
(snarkjs.bigInt(2).pow(snarkjs.bigInt(256))) - SNARK_FIELD_SIZE
) % SNARK_FIELD_SIZE
let rand: SnarkBigInt
while (true) {
rand = snarkjs.bigInt('0x' + crypto.randomBytes(32).toString('hex'))
if (rand >= min) {
break
}
}