This is a simple React Native app showcasing how to use Noir in a mobile app (both for iOS and Android) to generate and verify proofs directly on mobile phones.
The app integrates with the Swoir library to generate proofs with Noir on iOS. The library is written in Swift and is available as a Swift Package.
The app integrates some Kotlin code following a similar logic to Swoir, by taking the same type of inputs and the circuit manifest to generate proofs with Noir on Android. This part of the code will be exported soon in a separate library to simplify reusability.
If you are unfamiliar with React Native, you can follow the official guide to set up your environment.
For the rest follow the steps below:
- Clone the repository
- Run
npm install
to install the dependencies
- Run
npx pod-install
to install the pods for the iOS project - Open the project in Xcode
- Make sure you see the
Swoir
,SwoirCore
andSwoirenberg
libraries in thePackage Dependencies
(if not please open an issue) - Make sure you have a valid provisioning profile set up for the app in
Signing & Capabilities
- Build & Run the app on your device
- Make sure to define the environment varialbes
ANDROID_HOME
,NDK_VERSION
andHOST_TAG
, they will help the build process to find Android NDK necessary to compile the native code. Example on MacOS:
export ANDROID_HOME=$HOME/Library/Android/sdk
export NDK_VERSION=26.3.11579264
export HOST_TAG=darwin-x86_64
- Connect your Android device and check it is connected by running
npm run android-devices
. It should displayed the connected device asdevice
in the list of devices attached. - Run
npm run android
to build and run the app on your device
Note: If you want to do a clean build, you can run ./scripts/clean-android.sh
before running npm run android
This app comes with a basic Noir circuit checking that the prover knows two private inputs a
and b
such that the public input result
is equal to their product a * b
, a circuit verifying a secp256r1 signature and one doing multiple rounds of pedersen hashing. You can replace any of these circuits with your own by following these steps:
- Go into the
circuits
folder - Create a new folder for your circuit such as
my_circuit
- Create a
Nargo.toml
file in this folder following the structure of theNargo.toml
file in the other subfolders of thecircuits
folder. Don't forget to change the name of the circuit in thename
field - Create a
src
folder and create amain.nr
file in it - Make sure you have the version 0.30.0 of
nargo
. You can check by runningnargo --version
. If you have a different version, you can usenoirup -v 0.30.0
. And if you don't havenoirup
follow the instructions here. - Write your Noir code in
main.nr
and runnargo check
to generate theProver.toml
andVerifier.toml
files - Run
nargo compile
to compile the circuit - It will generate a new
<your_circuit_name>.json
file in/target
- You can then replace the import in the Javascript code to load this circuit instead
Bear in mind that mobile phones have a limited amount of available RAM. The circuit used in this app is really simple so the memory usage is not a problem. However, if you plan to use more complex circuits, you should be aware that the memory usage will increase and may go above the available memory on the device causing the proof generation to fail.
The current version of Noir supported by the app is 0.30.0