This is a React Native package for Semaphore protocol.
Use a Node.js package manager in your React Native app to install dependencies. For example:
# npm
npm install https://github.com/zkmopro/SemaphoreReactNative
# yarn / pnpm
yarn add https://github.com/zkmopro/SemaphoreReactNative
Alternatively, you can manually add it to your package.json:
"dependencies": {
"semaphore-react-native": "github:zkmopro/SemaphoreReactNative",
}
Here is an example of how to integrate and use this package
import { Identity } from "semaphore-react-native";
// Create a new identity with a random secret
const secret = "secret";
const secretBytes = new TextEncoder().encode(secret);
// generate an identity from privateKey
const identity = new Identity(secretBytes);
// get the identity commitment
const commitment = identity.commitment();
// get private key
const privateKey = identity.privateKey();
// get secret scalar
const secretScalar = identity.secretScalar();
// convert the type to Element to be used in Group
const toElement = identity.toElement();
import { Group } from "semaphore-react-native";
const group = new Group([identity.toElement(), identity2.toElement()]);
// get root
group.root();
import {
generateSemaphoreProof,
verifySemaphoreProof,
} from "semaphore-react-native";
const message = "message";
const scope = "scope";
const treeDepth = 16;
const proof = await generateSemaphoreProof(
identity,
group,
message,
scope,
treeDepth
);
const valid = await verifySemaphoreProof(proof);
Since this is a native module, you'll need to use Expo's build commands to run it on a device. Notice that, it is not available for Web yet. We've included an example app in the example folder to help you get started and test:
cd example
To run on a connected iOS simulator:
npm run ios:device
To run on a connected iOS device:
npm run ios
Set the ANDROID_HOME
environment variable.
export ANDROID_HOME=~/Library/Android/sdk/
To run on Android emulator/device (if connected):
npm run android
This package relies on bindings generated by the Mopro CLI. To learn how to build Mopro bindings, refer to the Getting Started section. If you'd like to generate custom bindings for your own circuits or proving schemes, check out the guide on how to use the Mopro CLI: Rust Setup for Android/iOS Bindings.
The bindings' source is from here semaphore-bindings
Then, replace the entire bindings directory with your generated files in the following location: Sources/MoproiOSBindings
Alternatively, you can run the following commands to copy your generated bindings into the correct location:
cp -r ../path/to/your/bindings/MoproiOSBindings ./ios && \
cp -r ../path/to/your/bindings/MoproAndroidBindings/uniffi ./android/src/main/java && \
cp -r ../path/to/your/bindings/MoproAndroidBindings/jniLibs ./android/src/main
android/src/main/java/expo/modules/semaphore/IdentityModule.kt
android/src/main/java/expo/modules/semaphore/GroupModule.kt
android/src/main/java/expo/modules/semaphore/ProofModule.kt
- Define React Native's module APIs to pass messages between React Native and your desired platforms.
This work was initially sponsored by a joint grant from PSE and 0xPARC. It is currently incubated by PSE.
This project is heavily inspired by ezkl-swift-package and follows a similar approach for integrating native cryptographic libraries into Swift via a Swift Package.