Skip to content

zkmopro/zkemail-kotlin-package

Repository files navigation

zkEmail Kotlin Package via MoproFFI

A Kotlin/Android library for generating and verifying zero-knowledge proofs (ZKPs) for the zkemail project, using native Rust code via UniFFI and JNI. This package provides a simple interface to interact with the zkemail proof system.

Getting zkemail 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:zkemail-kotlin-package:Tag")
  }

Replace Tag with the desired release version, e.g. v0.2.2. 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

import uniffi.mopro.proveZkemail
import uniffi.mopro.verifyZkemail

// Prepare your inputs as a Map<String, List<String>>
// Example structure (replace with your actual data):
val inputs = mapOf(
    "header_storage" to listOf("123", "456" /* ... more items ... */),
    "header_len" to listOf("10"),
    "pubkey_modulus" to listOf("abc", "def" /* ... more items ... */),
    "pubkey_redc" to listOf("ghi", "jkl" /* ... more items ... */),
    "signature" to listOf("mno", "pqr" /* ... more items ... */),
    "date_index" to listOf("1"),
    "subject_index" to listOf("2"),
    "subject_length" to listOf("20"),
    "from_header_index" to listOf("3"),
    "from_header_length" to listOf("30"),
    "from_address_index" to listOf("4"),
    "from_address_length" to listOf("40")
)

// Provide the path to your SRS file
val srsPath = "/path/to/your/srs.local"

try {
    // Generate Proof
    val proof = proveZkemail(srsPath, inputs)
    println("Proof generated successfully.")

    // Verify Proof
    val isValid = verifyZkemail(srsPath, proof)
    println("Proof verification result: $isValid")

} catch (e: Exception) { // Replace with specific MoproException if needed
    println("Error: ${e.message}")
}

Warning

The default bindings are built specifically for the zkemail circuit. If you'd like to update the circuit or switch to a different proving scheme, please refer to the How to Build the Package section.

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.

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

Packages

No packages published

Contributors 2

  •  
  •  

Languages