iden3 / snarkjs

zkSNARK implementation in JavaScript & WASM
GNU General Public License v3.0
1.77k stars 421 forks source link

crypto.randomBytes is not a function #272

Closed signorecello closed 1 year ago

signorecello commented 1 year ago

Running the example on the README with something like snarkjs.zkey.contribute fails on the browser with Uncaught (in promise) TypeError: crypto.randomBytes is not a function.

I think randomBytes is not available anymore on browsers. An alternative could be found perhaps using cypto.getRandomValues

phated commented 1 year ago

crypto.randomBytes is a nodejs function. If you are trying to use snrakjs in the browser, you need to use the IIFE browser build at https://github.com/iden3/snarkjs/blob/master/build/snarkjs.js (or set up your bundler correctly)