Flutter is a popular cross-platform mobile app development framework. Mopro Flutter shows an example of integrating ZK-proving into a Flutter app, allowing for streamlined creation of ZK-enabled mobile apps.
-
Install Flutter
If Flutter is not already installed, you can follow the official Flutter installation guide for your operating system.
-
Check Flutter Environment
After installing Flutter, verify that your development environment is properly set up by running the following command in your terminal:
flutter doctor
This command will identify any missing dependencies or required configurations.
-
Install Flutter Dependencies
Navigate to the root directory of the project in your terminal and run:
flutter pub get
This will install the necessary dependencies for the project.
- Open the project in VS Code.
- Open the "Run and Debug" panel.
- Start an emulator (iOS/Android) or connect your physical device.
- Select "example" in the run menu and press "Run".
If you prefer using the terminal to run the app, use the following steps:
-
For Android:
Ensure you have an Android emulator running or a device connected. Then run:
flutter run
-
For iOS:
Make sure you have an iOS simulator running or a device connected. Then run:
flutter run
The example app comes with a simple prover generated from a Circom circuit. To integrate your own prover, follow the steps below.
Follow the Rust Setup steps from the MoPro official docs to generate the platform-specific libraries.
- Replace
mopro.swift
atmopro_flutter_plugin/ios/Classes/mopro.swift
with the file generated during the Setup. - Replace the directory
mopro_flutter_plugin/ios/MoproBindings.xcframework
with the one generated during the Setup.
- Replace the directory
mopro_flutter_plugin/android/src/main/jniLibs
with the one generated during the Setup. - Replace
mopro.kt
atmopro_flutter_plugin/android/src/main/kotlin/uniffi/mopro/mopro.kt
with the file generated during the Setup.
-
Place your
.zkey
file in your app's assets folder. For example, to run the included example app, you need to replace the.zkey
atassets/multiplier2_final.zkey
with your file. If you change the.zkey
file name, don't forget to update the asset definition in your app'spubspec.yaml
:assets: - assets/your_new_zkey_file.zkey
-
Load the new
.zkey
file properly in your Dart code. For example, update the file path inlib/main.dart
:var inputs = <String, List<String>>{}; inputs["a"] = ["3"]; inputs["b"] = ["5"]; proofResult = await _moproFlutterPlugin.generateProof("assets/multiplier2_final.zkey", inputs);
Don't forget to modify the input values for your specific case!
Open the ./android
directory in Android Studio. You will be able to browse to the plugin code in Android
and Project
view.