Skip to content

zkmopro/SemaphoreKotlin

Repository files navigation

Semaphore Kotlin Package

This is a Kotlin package for Semaphore protocol.

Getting mopro via JitPack

To get this library from GitHub using JitPack:

Step 1. Add the JitPack repository to your settings.gradle.kts at the end of repositories:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
    }
}

Step 2. Add the dependency to your build.gradle.kts:

  dependencies {
      implementation("com.github.zkmopro:semaphore:Tag")
  }

Replace Tag with the desired release version, e.g. v0.1.0. See the JitPack page for available versions.

Note: If you're using an Android template from mopro create, comment out these UniFFI dependencies in your build file to prevent duplicate class errors.

  // // Uniffi
  // implementation("net.java.dev.jna:jna:5.13.0@aar")
  // implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")

Usage Example

Identity

val privateKey = "secret".toByteArray()
// generate an identity from privateKey
val identity = Identity(privateKey)
// get the identity commitment
identity.commitment()
// get private key
identity.privateKey()
// get secret scalar
identity.secretScalar()
// convert the type to Element to be used in Group
identity.toElement()

Group

let group = Group(listOf(
    identity.toElement(),
    identity2.toElement()
))
// get root
group.root()
// get depth (TODO: need to be tested)
// get members (TODO: need to be tested)
// index of (TODO: need to be tested)
// add member (TODO: need to be tested)
// add members (TODO: need to be tested)
// update member (TODO: need to be tested)
// remove member (TODO: need to be tested)

Proof

val message = "message"
val scope = "scope"
// generate semaphore proof
// It will output a JSON string
// You can parse it with swift JSON parser
val proof = generateSemaphoreProof(
    identity,
    group,
    message,
    scope,
    16.toUShort()
)
// verify semaphore proof
val valid = verifySemaphoreProof(proof)

How to Build the Package

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:

  • android/app/src/main/java/uniffi
  • android/app/src/main/jniLibs

Alternatively, you can run the following commands to copy your generated bindings into the correct location:

cp -r MoproAndroidBindings/uniffi android/app/src/main/java
cp -r MoproAndroidBindings/jniLibs android/app/src/main

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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages