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, which are necessary to send private transactions (private transfers, private cross-contract calls, and unshielding). Shield-only applications can safely skip this step.

There is a distinct Groth16 prover for node/browser (snarkjs) and a different prover for mobile (native prover). Both provers generate Groth16 snarks using different assembly processes that are compatible with different platforms.

  1. Node.js and browser uses a web assembly implementation: snarkjs.

  2. Mobile apps use a C++ implementation: @railgun-community/native-prover.

Example: Minified SnarkJS (browser)

  1. Get snarkjs.min.js file from the Wallet SDK repo.

  2. Load script in your app's index.html: <script src="./snarkjs.min.js"></script>

// main.ts
...
import {
  ...
  getProver,
  Groth16
} from '@railgun-community/wallet';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  // Note: SnarkJS library does not have proper typings.
  const groth16 = (global as unknown as { snarkjs: { groth16: SnarkJSGroth16 } })
        .snarkjs.groth16;
        
  getProver().setSnarkJSGroth16(groth16);
} catch (err) {
  // Handle err
}

Example: SnarkJS NPM (node.js)

Install with yarn add snarkjs

// main.js
...
import {
  ...
  getProver,
  Groth16
} from '@railgun-community/wallet';
import { groth16 } from 'snarkjs';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  // Note: SnarkJS library does not have proper typings.
  getProver().setSnarkJSGroth16(groth16 as SnarkJSGroth16);
} catch (err) {
  // Handle err
}

Example: Native Prover (mobile)

Install with yarn add @railgun-community/native-prover

// main.js
...
import {
  ...
  getProver
} from '@railgun-community/wallet';
import { nativeProve, CIRCUITS } from '@railgun-community/native-prover';

// App launch
try {
  initializeEngine(); // Defined in Step 1
  ...
  getProver().setNativeProverGroth16(nativeProve, CIRCUITS);
} catch (err) {
  // Handle err
}

Last updated