3. Load a Groth16 prover for each platform

Once the RAILGUN Engine is initialized, you will set a Groth16 Prover.
NOTE: A Prover is only necessary for applications that intend to generate proofs and send private transactions. Shield-only applications can safely skip this step.
There is a distinct Groth16 prover for mobile (native prover) and for node/browser (snarkjs). Both provers generate Groth16 snarks using different assembly processes that are compatible with different platforms.
  1. 1.
    Mobile apps use a C++ implementation: @railgun-community/native-prover
  2. 2.
    Node.js and browser uses a web assembly implementation: snarkjs

Example: Native Prover (mobile)

Install with yarn add @railgun-community/native-prover
import { getProver } from '@railgun-community/wallet';
import { nativeProve, CIRCUITS } from '@railgun-community/native-prover';
...
// After starting RAILGUN Engine
getProver().setNativeProverGroth16(nativeProve, CIRCUITS);

Example: Minified SnarkJS (browser)

  1. 1.
    Get snarkjs.min.js file from Wallet SDK repo
  2. 2.
    Load script in your app's index.html: <script src="./snarkjs.min.js"></script>
import { getProver, Groth16 } from '@railgun-community/wallet';
...
// After starting RAILGUN Engine
// Note: SnarkJS library does not have proper typings.
const groth16 = (global as unknown as { snarkjs: { groth16: Groth16 } })
.snarkjs.groth16;
getProver().setSnarkJSGroth16(groth16);

Example: SnarkJS NPM (node.js)

Install with yarn add snarkjs
import { getProver, Groth16 } from '@railgun-community/wallet';
import { groth16 } from 'snarkjs';
...
// After starting RAILGUN Engine
// Note: SnarkJS library does not have proper typings.
getProver().setSnarkJSGroth16(groth16 as Groth16);