Closed oskarth closed 2 weeks 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`
@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?
Sounds great!
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.
Next steps:
Awesome!
See https://github.com/anon-aadhaar/anon-aadhaar-react-native/commit/d6443316200cd3e1f17ad2679458cc6e6e9fe1f2 for latest React Native WIP integration
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
I built this example app https://github.com/zkmopro/react-native-app Next steps:
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.