Skip to content

zkmopro/NoirReactNative

Repository files navigation

Noir React Native

NoirReactNative is a React Native package for generating and verifying Noir zero-knowledge proofs using the Barretenberg backend.

The Swift bindings are generated by the mopro CLI using the Noir adapter, which relies on a prebuilt Barretenberg backend.

To learn more about the original Rust implementation before generating bindings, please refer to noir-rs.

How to Import the Package

Use a Node.js package manager in your React Native app to install dependencies. For example:

# npm
npm install https://github.com/zkmopro/NoirReactNative # Or change to your own URL
# yarn / pnpm
yarn add https://github.com/zkmopro/NoirReactNative # Or change to your own URL

Or add this in package.json

"dependencies": {
    "noir-react-native": "github:zkmopro/NoirReactNative"
}

How to Use the Package

Here is an example of how to integrate and use this package.
For the full test implementation, see example/App.tsx.

Import the package

import {
  getNoirVerificationKey,
  generateNoirProof,
  verifyNoirProof,
} from 'noir-react-native';

Load circuit and srs

Please checkout noir-rs to see how to generate the circuit and the srs.

To load the circuit and srs in a React Native app, please checkout loadAssets to get the path. Then define the file path, e.g.

const circuitPath = await loadAssets(circuitName);
const srsPath = await loadAssets(srsName);

getNoirVerificationKey

const onChain = true; // Use Keccak for Solidity compatibility
const lowMemoryMode = false;
const inputs = ['3', '5'];

const verificationKey = getNoirVerificationKey(
  circuitPath.replace('file://', ''),
  srsPath.replace('file://', ''),
  onChain,
  lowMemoryMode
);

generateNoirProof

const proof: ArrayBuffer = generateNoirProof(
    circuitPath.replace('file://', ''),
    srsPath.replace('file://', ''),
    circuitInputs,
    onChain,
    verificationKey,
    lowMemoryMode
);

verifyNoirProof

const res: boolean = verifyNoirProof(
    circuitPath.replace('file://', ''),
    proof,
    onChain,
    vk,
    lowMemoryMode
);

How to Build the Package

  1. Use mopro-cli and choose noir
mopro init

choose noir

mopro build

choose react-native and all architectures.

  1. Then, replace the entire bindings directory MoproReactNativeBindings with your generated files in the current folder:
├── android
├── babel.config.js
├── cpp
├── example # Optional: keep this folder
├── ios
├── lib
├── MoproFfiFramework.xcframework
├── node_modules
├── package-lock.json
├── package.json
├── README.md
├── src
├── tsconfig.build.json
├── tsconfig.json
├── turbo.json
└── ubrn.config.yaml

or running, e.g.

cp -R \
  MoproReactNativeBindings/android \
  MoproReactNativeBindings/ios \
  MoproReactNativeBindings/src \
  MoproReactNativeBindings/lib \
  MoproReactNativeBindings/MoproFfiFramework.xcframework \
  MoproReactNativeBindings/package.json \
  mopro-react-native-package/
  1. Zip the MoproFfiFramework.xcframework

  2. Upload the MoproFfiFramework.xcframework to some URL

  3. Update the check-mopro-download.sh script

Note

noir-rs v1.0.0-beta.19 build constraints. The ubrn:ios / ubrn:android scripts intentionally omit --and-generate and reuse the committed bindings in src/generated/ and cpp/generated/. Current uniffi-bindgen-react-native (through 0.31.0-3) panics when regenerating bindings for this crate (Module path should map to namespace: unresolved module path mopro_example_app_noir::error) because mopro-ffi's app!() macro exports items from Rust submodules (error, circom_stub, halo2_stub, noir) that ubrn's TypeScript generator can't map. The committed bindings already match beta.19, so regeneration is not needed — only the Rust library is rebuilt. ubrn:ios also pins targets to aarch64-apple-ios,aarch64-apple-ios-sim because barretenberg-rs (beta.19) ships no x86_64-apple-ios prebuilt.

Test the package

Use the example app folder:

  1. Install the dependencies
npm install
  1. Start the server
npm run start
  1. Run the app on iOS
npm run ios
  1. Run the app on Android
export ANDROID_HOME=~/Library/Android/sdk/
npm run android

Warning

If you are using Expo, run the app with:

"ios": "expo run:ios",
"android": "expo run:android"

These commands build and run the native iOS and Android projects.
And make sure the Android minSdkVersion is set to 30 (required by the noir-rs v1.0.0-beta.19 barretenberg prebuilt).

Community

  • X account:
  • Telegram group:

Acknowledgements

This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors