This library is React Native wrapper for the Rapidsnark. It enables the generation of proofs for specified circuits within a React Native environment.
iOS: Compatible with any iOS device with 64 bit architecture.
Version for emulator built without assembly optimizations, resulting in slower performance.
Android: Compatible with arm64-v8a, x86_64 architectures.
npm i @iden3/react-native-rapidsnark
Function takes path to .zkey file and witness file (base64 encoded) and returns proof and public signals.
Reads .zkey file directly from filesystem.
import {groth16Prove} from "react-native-rapidsnark";
// ...
const zkeyPath = "path/to/zkey";
const wtns = await RNFS.readFile("path/to/wtns", "base64");
const {proof, pub_signals} = await groth16Prove(zkeyPath, wtns);
Verifies proof and public signals against zkey.
import {groth16Prove, groth16Verify} from "react-native-rapidsnark";
// ...
const zkey = await RNFS.readFile("path/to/zkey", "base64");
const wtns = await RNFS.readFile("path/to/wtns", "base64");
const verificationKey = await RNFS.readFile("path/to/verification_key", "base64");
const {proof, pub_signals} = await groth16Prove(zkey, wtns);
const proofValid = groth16Verify(proof, pub_signals, verificationKey);
Calculates public buffer size for specified zkey.
import { groth16PublicBufferSize } from "react-native-rapidsnark";
// ...
const public_buffer_size_file = await groth16PublicBufferSize("path/to/zkey");
groth16Prove
has an optional proofBufferSize
, publicBufferSize
and errorBufferSize
parameters. If publicBufferSize is too small it will be recalculated automatically by library.
These parameters are used to set the size of the buffers used to store the proof, public signals and error.
If you have embedded circuit in the app, it is recommended to calculate the size of the public buffer once and reuse it.
To calculate the size of public buffer call groth16PublicBufferSize
.
If you're getting invalid witness length error - check that your witness file is not corrupted and is generated for the same circuit as zkey.
If you get an error like this:
building for 'iOS-simulator', but linking in object file (${SRC_ROOT}/ios/Frameworks/Rapidsnark.xcframework/ios-arm64/librapidsnarkmerged.a[2](fq.o)) built for 'iOS'
- Open XCode
- Select your project in the left sidebar
- Select
Build Phases
tab - Expand
Link Binary With Libraries
- Add
Rapidsnark.xcframework
fromWorkspace/Pods
folder.
Check out the example app and example README for a working example.
Place circuits in example/assets
folder and run example/assets/copy_assets.sh
to copy them to the app directories.
Name them circuit.zkey
, witness.wtns
and verification_key.json
.
The project is licensed under either of
at your option.