zkmopro / mopro

Making client-side proving on mobile simple.
https://zkmopro.org
Apache License 2.0
121 stars 34 forks source link

React Native support #43

Closed oskarth closed 2 weeks ago

oskarth commented 10 months ago

Problem

A lot of projects want React Native library. We should support this.

Notes

With native modules we should be able to bind the Swift and Kotlin to a basic React Native library.

See https://reactnative.dev/docs/native-modules-intro

Acceptance criteria

Basic React Native library support.

oskarth commented 8 months ago

Seems like we need an Obj C bridging header. Something like this:

Swift:

// MoproCircom+ReactNative.swift
import Foundation

extension MoproCircom {
    @objc func generateProofWithCallback(circuitInputs: [String: [String]], callback: @escaping RCTResponseSenderBlock) {
        do {
            let result = try generateProof(circuitInputs: circuitInputs)
            // Convert `GenerateProofResult` to a dictionary or array if necessary
            callback([NSNull(), result.toDictionary()])
        } catch let error {
            callback([error.localizedDescription, NSNull()])
        }
    }

    // Add similar methods for `setup` and `verifyProof`
}

Obj C:

// MoproCircomBridge.m
#import "React/RCTBridgeModule.h"

@interface RCT_EXTERN_MODULE(MoproCircom, NSObject)
RCT_EXTERN_METHOD(generateProofWithCallback:(NSDictionary *)circuitInputs callback:(RCTResponseSenderBlock)callback)
// Add similar extern declarations for `setup` and `verifyProof`
@end

JS:

import { NativeModules } from 'react-native';

const { MoproCircom } = NativeModules;

MoproCircom.generateProofWithCallback(circuitInputs, (error, result) => {
  if (error) {
    console.error(error);
  } else {
    console.log(result);
  }
});

// Add similar calls for `setup` and `verifyProof`
Meyanis95 commented 8 months ago

@oskarth I am Assigning this one to me for the moment. I'm working on an RN library setup, that I'll push in our GitHub org once having something working. Once the specs and objc bridge specs are refined, we could add it to Mopro settings if it's wanted/needed by Mopro. WDYT?

oskarth commented 8 months ago

Sounds great!

Meyanis95 commented 8 months ago

Update:

I have a working bridge that you'll be able to find here. It's a bit tricky but possible.

You'll find a working example of the complex-circuit-100k circuit.

image

Next steps:

oskarth commented 8 months ago

Awesome!

oskarth commented 6 months ago

See https://github.com/anon-aadhaar/anon-aadhaar-react-native/commit/d6443316200cd3e1f17ad2679458cc6e6e9fe1f2 for latest React Native WIP integration

oskarth commented 5 months ago

We want to take this RN WIP integration above and:

1) Add to mopro-cli as platform option 2) Integrate into example app template 3) Basic docs about usage

vivianjeng commented 2 months ago

I built this example app https://github.com/zkmopro/react-native-app Next steps: