This is a Flutter package for Semaphore protocol.
Follow these steps to integrate the Semaphore Flutter package into your project.
-
Add Dependency: You can add
semaphore
to your project using the command line or by manually editingpubspec.yaml
.-
Manual Edit (Required for local path or specific Git dependencies): Open your
pubspec.yaml
file and addsemaphore
underdependencies
.dependencies: flutter: sdk: flutter semaphore: git: url: https://github.com/zkmopro/semaphore_flutter.git
-
-
Install Package: Run the following command in your terminal from the root of your Flutter project:
flutter pub get
import 'package:semaphore/semaphore.dart';
final privateKey = utf8.encode("secret");
final identity = Identity(privateKey);
final commitment = await identity.commitment();
final privateKey = await identity.privateKey();
final secretScalar = await identity.secretScalar();
final toElement = await identity.toElement();
import 'package:semaphore/semaphore.dart';
final member1 = await identity1.toElement();
final member2 = await identity2.toElement();
final group = Group([member1, member2]);
// get root
await group.root();
import 'package:semaphore/semaphore.dart';
final message = "message";
final scope = "scope";
final treeDepth = 16;
final proof = await generateSemaphoreProof(
identity,
group,
message,
scope,
treeDepth,
);
final valid = await verifySemaphoreProof(proof);
- Open the example app that uses the defined flutter package in the
example/
foldercd example
- Install the dependencies
flutter pub get
- Open an iOS simulator/device or an Android emulator/device and run the example app
flutter run
- Clean the cache if you update the bindings and it throws errors
flutter clean
-
Follow the instructions in the
mopro-swift-package
README to build the package. -
Copy the bindings to the path
ios/MoproiOSBindings
. -
Then define the native module API in
ios/Classes/SemaphorePlugin.swift
to match the Flutter type. Please refer to Flutter - Data types support
-
Follow the instructions in the
mopro-kotlin-package
README to build the package. -
Copy the
jniLibs
folder toandroid/src/main/jniLibs
and copy theuniffi
folder toandroid/src/main/kotlin/uniffi
-
Then define the native module API in
android/src/main/kotlin/com/example/semaphore/SemaphorePlugin.kt
to match the Flutter type. Please refer to Flutter - Data types support
- Define Flutter's platform channel APIs to pass messages between Flutter and your desired platforms.
This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.