@umbra-privacy/rn-zk-prover 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/MoproFfi.podspec +76 -0
  2. package/android/CMakeLists.txt +78 -0
  3. package/android/build.gradle +167 -0
  4. package/android/cpp-adapter.cpp +43 -0
  5. package/android/create-android-jnilibs-zip.sh +11 -0
  6. package/android/src/main/AndroidManifest.xml +5 -0
  7. package/android/src/main/java/com/moproffi/MoproFfiModule.kt +43 -0
  8. package/android/src/main/java/com/moproffi/MoproFfiPackage.kt +34 -0
  9. package/cpp/generated/mopro_umbra_2.cpp +2291 -0
  10. package/cpp/generated/mopro_umbra_2.hpp +66 -0
  11. package/cpp/mopro-ffi.cpp +16 -0
  12. package/cpp/mopro-ffi.h +15 -0
  13. package/ios/MoproFfi.h +16 -0
  14. package/ios/MoproFfi.mm +66 -0
  15. package/lib/module/NativeMoproFfi.js +7 -0
  16. package/lib/module/NativeMoproFfi.js.map +1 -0
  17. package/lib/module/generated/mopro_umbra_2-ffi.js +47 -0
  18. package/lib/module/generated/mopro_umbra_2-ffi.js.map +1 -0
  19. package/lib/module/generated/mopro_umbra_2.js +567 -0
  20. package/lib/module/generated/mopro_umbra_2.js.map +1 -0
  21. package/lib/module/index.js +43 -0
  22. package/lib/module/index.js.map +1 -0
  23. package/lib/module/package.json +1 -0
  24. package/lib/typescript/package.json +1 -0
  25. package/lib/typescript/src/NativeMoproFfi.d.ts +8 -0
  26. package/lib/typescript/src/NativeMoproFfi.d.ts.map +1 -0
  27. package/lib/typescript/src/generated/mopro_umbra_2-ffi.d.ts +96 -0
  28. package/lib/typescript/src/generated/mopro_umbra_2-ffi.d.ts.map +1 -0
  29. package/lib/typescript/src/generated/mopro_umbra_2.d.ts +426 -0
  30. package/lib/typescript/src/generated/mopro_umbra_2.d.ts.map +1 -0
  31. package/lib/typescript/src/index.d.ts +8 -0
  32. package/lib/typescript/src/index.d.ts.map +1 -0
  33. package/package.json +166 -0
@@ -0,0 +1,76 @@
1
+ # Generated by uniffi-bindgen-react-native
2
+ require "json"
3
+
4
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
5
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
6
+
7
+ Pod::Spec.new do |s|
8
+ s.name = "MoproFfi"
9
+ s.version = package["version"]
10
+ s.summary = package["description"]
11
+ s.homepage = package["homepage"]
12
+ s.license = package["license"]
13
+ s.authors = package["author"]
14
+
15
+ s.platforms = { :ios => min_ios_version_supported }
16
+ s.source = { :git => "https://github.com/zkmopro/react-native-app.git", :tag => "#{s.version}" }
17
+
18
+ # Download xcframework from CloudFront
19
+ xcframework_url = "https://d1hi11upkav2nq.cloudfront.net/zk/MoproBindings.xcframework.zip"
20
+ s.prepare_command = <<-CMD
21
+ set -e
22
+
23
+ # Ensure Sources/MoproiOSBindings directory exists
24
+ if [ ! -d "Sources/MoproiOSBindings" ]; then
25
+ echo "▶︎ Creating Sources/MoproiOSBindings directory…"
26
+ mkdir -p Sources/MoproiOSBindings
27
+ fi
28
+
29
+ cd Sources/MoproiOSBindings
30
+
31
+ if [ -d "MoproBindings.xcframework" ]; then
32
+ folder_count=$(find MoproBindings.xcframework -mindepth 1 -maxdepth 1 -type d | wc -l)
33
+ if [ "$folder_count" -gt 0 ]; then
34
+ echo "▶︎ MoproBindings.xcframework already exists with $folder_count architecture(s), skipping download"
35
+ exit 0
36
+ fi
37
+ fi
38
+
39
+ echo "▶︎ Downloading MoproBindings.xcframework…"
40
+ curl -L -o MoproBindings.xcframework.zip \
41
+ "https://d1hi11upkav2nq.cloudfront.net/zk/MoproBindings.xcframework.zip"
42
+
43
+ echo "▶︎ Unzipping…"
44
+ unzip -o MoproBindings.xcframework.zip
45
+ rm -f MoproBindings.xcframework.zip
46
+ CMD
47
+
48
+
49
+ s.vendored_frameworks = "Sources/MoproiOSBindings/MoproBindings.xcframework"
50
+ s.source_files = "ios/**/*.{h,m,mm,swift}", "ios/generated/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}", "cpp/generated/**/*.{hpp,cpp,c,h}", "Sources/**/*.swift"
51
+ s.static_framework = true
52
+ s.dependency "uniffi-bindgen-react-native", "0.29.3-1"
53
+
54
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
55
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
56
+ if respond_to?(:install_modules_dependencies, true)
57
+ install_modules_dependencies(s)
58
+ else
59
+ s.dependency "React-Core"
60
+
61
+ # Don't install the dependencies when we run `pod install` in the old architecture.
62
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
63
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
64
+ s.pod_target_xcconfig = {
65
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
66
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
67
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
68
+ }
69
+ s.dependency "React-Codegen"
70
+ s.dependency "RCT-Folly"
71
+ s.dependency "RCTRequired"
72
+ s.dependency "RCTTypeSafety"
73
+ s.dependency "ReactCommon/turbomodule/core"
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,78 @@
1
+ # Generated by uniffi-bindgen-react-native
2
+ cmake_minimum_required(VERSION 3.9.0)
3
+ project(MoproFfi)
4
+
5
+ set (CMAKE_VERBOSE_MAKEFILE ON)
6
+ set (CMAKE_CXX_STANDARD 17)
7
+
8
+ # Resolve the path to the uniffi-bindgen-react-native package
9
+ execute_process(
10
+ COMMAND node -p "require.resolve('uniffi-bindgen-react-native/package.json')"
11
+ OUTPUT_VARIABLE UNIFFI_BINDGEN_PATH
12
+ OUTPUT_STRIP_TRAILING_WHITESPACE
13
+ )
14
+ # Get the directory; get_filename_component and cmake_path will normalize
15
+ # paths with Windows path separators.
16
+ get_filename_component(UNIFFI_BINDGEN_PATH "${UNIFFI_BINDGEN_PATH}" DIRECTORY)
17
+
18
+ # Specifies a path to native header files.
19
+ include_directories(
20
+ ../cpp
21
+ ../cpp/generated
22
+ ${UNIFFI_BINDGEN_PATH}/cpp/includes
23
+ )
24
+
25
+ add_library(mopro-ffi SHARED
26
+ ../cpp/mopro-ffi.cpp
27
+ ../cpp/generated/mopro_umbra_2.cpp
28
+ cpp-adapter.cpp
29
+ )
30
+
31
+ # Set C++ compiler flags
32
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
33
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
34
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
35
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
36
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
37
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
38
+
39
+ # Set linker flags for 16KB page size alignment (required for Android 15+)
40
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
41
+
42
+ cmake_path(
43
+ SET MY_RUST_LIB
44
+ ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libmopro_umbra_2.so
45
+ NORMALIZE
46
+ )
47
+ add_library(my_rust_lib SHARED IMPORTED)
48
+ set_target_properties(my_rust_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_LIB} IMPORTED_NO_SONAME ON)
49
+
50
+ # Add ReactAndroid libraries, being careful to account for different versions.
51
+ find_package(ReactAndroid REQUIRED CONFIG)
52
+ find_library(LOGCAT log)
53
+
54
+ # REACTNATIVE_MERGED_SO seems to be only be set in a build.gradle.kt file,
55
+ # which we don't use. Thus falling back to version number sniffing.
56
+ if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
57
+ set(REACTNATIVE_MERGED_SO true)
58
+ endif()
59
+
60
+ # https://github.com/react-native-community/discussions-and-proposals/discussions/816
61
+ # This if-then-else can be removed once this library does not support version below 0.76
62
+ if (REACTNATIVE_MERGED_SO)
63
+ target_link_libraries(mopro-ffi ReactAndroid::reactnative)
64
+ else()
65
+ target_link_libraries(mopro-ffi
66
+ ReactAndroid::turbomodulejsijni
67
+ ReactAndroid::react_nativemodule_core
68
+ )
69
+ endif()
70
+
71
+ find_package(fbjni REQUIRED CONFIG)
72
+ target_link_libraries(
73
+ mopro-ffi
74
+ fbjni::fbjni
75
+ ReactAndroid::jsi
76
+ ${LOGCAT}
77
+ my_rust_lib
78
+ )
@@ -0,0 +1,167 @@
1
+ // Generated by uniffi-bindgen-react-native
2
+
3
+ // Download prebuilt jniLibs from CloudFront
4
+ def androidJniLibsUrl = "https://d1hi11upkav2nq.cloudfront.net/zk/MoproBindings-android-jniLibs.zip"
5
+ def jniLibsDir = file("${projectDir}/src/main/jniLibs")
6
+
7
+ buildscript {
8
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
9
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["DummyLibForAndroid_kotlinVersion"]
10
+
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+
16
+ dependencies {
17
+ classpath "com.android.tools.build:gradle:7.2.1"
18
+ // noinspection DifferentKotlinGradleVersion
19
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
20
+ }
21
+ }
22
+
23
+ def reactNativeArchitectures() {
24
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
25
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
26
+ }
27
+
28
+ def isNewArchitectureEnabled() {
29
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
30
+ }
31
+
32
+ apply plugin: "com.android.library"
33
+ apply plugin: "kotlin-android"
34
+
35
+ if (isNewArchitectureEnabled()) {
36
+ apply plugin: "com.facebook.react"
37
+ }
38
+
39
+ def getExtOrDefault(name) {
40
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["MoproFfi_" + name]
41
+ }
42
+
43
+ def getExtOrIntegerDefault(name) {
44
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["MoproFfi_" + name]).toInteger()
45
+ }
46
+
47
+ def supportsNamespace() {
48
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
49
+ def major = parsed[0].toInteger()
50
+ def minor = parsed[1].toInteger()
51
+
52
+ // Namespace support was added in 7.3.0
53
+ return (major == 7 && minor >= 3) || major >= 8
54
+ }
55
+
56
+ android {
57
+ if (supportsNamespace()) {
58
+ namespace "com.moproffi"
59
+
60
+ sourceSets {
61
+ main {
62
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
63
+ }
64
+ }
65
+ }
66
+
67
+ ndkVersion getExtOrDefault("ndkVersion")
68
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
69
+
70
+ defaultConfig {
71
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
72
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
73
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
74
+ consumerProguardFiles 'proguard-rules.pro'
75
+
76
+ buildFeatures {
77
+ prefab true
78
+ }
79
+ externalNativeBuild {
80
+ cmake {
81
+ arguments '-DANDROID_STL=c++_shared'
82
+ abiFilters (*reactNativeArchitectures())
83
+ }
84
+ }
85
+ ndk {
86
+ abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
87
+ }
88
+ }
89
+
90
+ externalNativeBuild {
91
+ cmake {
92
+ path "CMakeLists.txt"
93
+ }
94
+ }
95
+
96
+ buildFeatures {
97
+ buildConfig true
98
+ }
99
+
100
+ buildTypes {
101
+ release {
102
+ minifyEnabled false
103
+ }
104
+ }
105
+
106
+ lintOptions {
107
+ disable "GradleCompatible"
108
+ }
109
+
110
+ compileOptions {
111
+ sourceCompatibility JavaVersion.VERSION_1_8
112
+ targetCompatibility JavaVersion.VERSION_1_8
113
+ }
114
+
115
+ sourceSets {
116
+ main {
117
+ if (isNewArchitectureEnabled()) {
118
+ java.srcDirs += [
119
+ "generated/java",
120
+ "generated/jni"
121
+ ]
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ repositories {
128
+ mavenCentral()
129
+ google()
130
+ }
131
+
132
+ // Download prebuilt jniLibs from S3 if not present (so .so files don't need to be in repo)
133
+ task downloadAndroidJniLibs(type: Exec) {
134
+ onlyIf {
135
+ !jniLibsDir.exists() || jniLibsDir.list()?.length == 0
136
+ }
137
+ doFirst {
138
+ jniLibsDir.mkdirs()
139
+ }
140
+ commandLine "sh", "-c", """
141
+ curl -L -o /tmp/MoproBindings-android-jniLibs.zip '${androidJniLibsUrl}' && \
142
+ unzip -o /tmp/MoproBindings-android-jniLibs.zip -d '${jniLibsDir.absolutePath}' && \
143
+ rm -f /tmp/MoproBindings-android-jniLibs.zip
144
+ """
145
+ }
146
+
147
+ afterEvaluate {
148
+ tasks.findByName("preBuild")?.dependsOn(downloadAndroidJniLibs)
149
+ }
150
+
151
+ def kotlin_version = getExtOrDefault("kotlinVersion")
152
+
153
+ dependencies {
154
+ // For < 0.71, this will be from the local maven repo
155
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
156
+ //noinspection GradleDynamicVersion
157
+ implementation "com.facebook.react:react-native:+"
158
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
159
+ }
160
+
161
+ if (isNewArchitectureEnabled()) {
162
+ react {
163
+ jsRootDir = file("../src/")
164
+ libraryName = "MoproFfi"
165
+ codegenJavaPackageName = "com.moproffi"
166
+ }
167
+ }
@@ -0,0 +1,43 @@
1
+ // Generated by uniffi-bindgen-react-native
2
+ #include <jni.h>
3
+ #include <jsi/jsi.h>
4
+ #include <ReactCommon/CallInvokerHolder.h>
5
+ #include "mopro-ffi.h"
6
+
7
+ namespace jsi = facebook::jsi;
8
+ namespace react = facebook::react;
9
+
10
+ // Automated testing checks Java_com_moproffi_MoproFfiModule and moproffi
11
+ // by comparing the whole line here.
12
+ /*
13
+ Java_com_moproffi_MoproFfiModule_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) {
14
+ return moproffi::multiply(a, b);
15
+ }
16
+ */
17
+
18
+ // Installer coming from MoproFfiModule
19
+ extern "C"
20
+ JNIEXPORT jboolean JNICALL
21
+ Java_com_moproffi_MoproFfiModule_nativeInstallRustCrate(
22
+ JNIEnv *env,
23
+ jclass type,
24
+ jlong rtPtr,
25
+ jobject callInvokerHolderJavaObj
26
+ ) {
27
+ using JCallInvokerHolder = facebook::react::CallInvokerHolder;
28
+
29
+ auto holderLocal = facebook::jni::make_local(callInvokerHolderJavaObj);
30
+ auto holderRef = facebook::jni::static_ref_cast<JCallInvokerHolder::javaobject>(holderLocal);
31
+ auto* holderCxx = holderRef->cthis();
32
+ auto jsCallInvoker = holderCxx->getCallInvoker();
33
+ auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
34
+
35
+ return moproffi::installRustCrate(*runtime, jsCallInvoker);
36
+ }
37
+
38
+ extern "C"
39
+ JNIEXPORT jboolean JNICALL
40
+ Java_com_moproffi_MoproFfiModule_nativeCleanupRustCrate(JNIEnv *env, jclass type, jlong rtPtr) {
41
+ auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
42
+ return moproffi::cleanupRustCrate(*runtime);
43
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env sh
2
+ # Create MoproBindings-android-jniLibs.zip for upload to CloudFront.
3
+ # Run from anywhere: MoproReactNativeBindings/android/create-android-jnilibs-zip.sh
4
+ # Output: MoproReactNativeBindings/android/MoproBindings-android-jniLibs.zip
5
+
6
+ set -e
7
+ ANDROID_DIR="$(cd "$(dirname "$0")" && pwd)"
8
+ ZIP_OUT="$ANDROID_DIR/MoproBindings-android-jniLibs.zip"
9
+ cd "$ANDROID_DIR/src/main/jniLibs"
10
+ zip -r "$ZIP_OUT" arm64-v8a x86_64
11
+ echo "Created $ZIP_OUT"
@@ -0,0 +1,5 @@
1
+
2
+ <!-- Generated by uniffi-bindgen-react-native -->
3
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
4
+ package="com.moproffi">
5
+ </manifest>
@@ -0,0 +1,43 @@
1
+ // Generated by uniffi-bindgen-react-native
2
+ package com.moproffi
3
+
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.module.annotations.ReactModule
6
+ import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder
7
+
8
+ @ReactModule(name = MoproFfiModule.NAME)
9
+ class MoproFfiModule(reactContext: ReactApplicationContext) :
10
+ NativeMoproFfiSpec(reactContext) {
11
+
12
+ override fun getName(): String {
13
+ return NAME
14
+ }
15
+
16
+ // Two native methods implemented in cpp-adapter.cpp, and ultimately
17
+ // mopro-ffi.cpp
18
+
19
+ external fun nativeInstallRustCrate(runtimePointer: Long, callInvoker: CallInvokerHolder): Boolean
20
+ external fun nativeCleanupRustCrate(runtimePointer: Long): Boolean
21
+
22
+ override fun installRustCrate(): Boolean {
23
+ val context = this.reactApplicationContext
24
+ return nativeInstallRustCrate(
25
+ context.javaScriptContextHolder!!.get(),
26
+ context.jsCallInvokerHolder!!
27
+ )
28
+ }
29
+
30
+ override fun cleanupRustCrate(): Boolean {
31
+ return nativeCleanupRustCrate(
32
+ this.reactApplicationContext.javaScriptContextHolder!!.get()
33
+ )
34
+ }
35
+
36
+ companion object {
37
+ const val NAME = "MoproFfi"
38
+
39
+ init {
40
+ System.loadLibrary("mopro-ffi")
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,34 @@
1
+ // Generated by uniffi-bindgen-react-native
2
+ package com.moproffi
3
+
4
+ import com.facebook.react.TurboReactPackage
5
+ import com.facebook.react.bridge.NativeModule
6
+ import com.facebook.react.bridge.ReactApplicationContext
7
+ import com.facebook.react.module.model.ReactModuleInfo
8
+ import com.facebook.react.module.model.ReactModuleInfoProvider
9
+ import java.util.HashMap
10
+
11
+ class MoproFfiPackage : TurboReactPackage() {
12
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
13
+ return if (name == MoproFfiModule.NAME) {
14
+ MoproFfiModule(reactContext)
15
+ } else {
16
+ null
17
+ }
18
+ }
19
+
20
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
21
+ return ReactModuleInfoProvider {
22
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
23
+ moduleInfos[MoproFfiModule.NAME] = ReactModuleInfo(
24
+ MoproFfiModule.NAME,
25
+ MoproFfiModule.NAME,
26
+ false, // canOverrideExistingModule
27
+ false, // needsEagerInit
28
+ false, // isCxxModule
29
+ true // isTurboModule
30
+ )
31
+ moduleInfos
32
+ }
33
+ }
34
+ }