diff --git a/android/build.gradle b/android/build.gradle index d46a04828..a3ffb52b0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -47,11 +47,6 @@ android { main.java.srcDirs += 'src/main/kotlin' main.jniLibs.srcDirs += 'src/main/jniLibs' } - externalNativeBuild { - cmake { - path "src/main/cpp/CMakeLists.txt" - } - } defaultConfig { minSdkVersion 21 diff --git a/android/src/main/cpp/CMakeLists.txt b/android/src/main/cpp/CMakeLists.txt deleted file mode 100644 index 2080bf769..000000000 --- a/android/src/main/cpp/CMakeLists.txt +++ /dev/null @@ -1,67 +0,0 @@ -cmake_minimum_required(VERSION 3.4.1) - -set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_CXX_STANDARD 11) - -# Define a name for this project. It will be accessible with ${PROJECT_NAME}. -project(rapidsnark_module) - -# Create a library with the name defined for the project. -# Set it as SHARED library (will generate a .so file) -# Set the source file -add_library( - ${PROJECT_NAME} - SHARED - rapidsnark_module.cpp -) -target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-value) - -# Import an already existing .so file -# Here, we add a dependency to the shared_library prebuilt -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs) - -set( - SHARED_PROVER_LIBRARY_SO - ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/librapidsnark.so -) -# IMPORTED allows to depends on a library file outside the project. -add_library( - rapidsnark_prover_lib - SHARED - IMPORTED -) -# IMPORTED_LOCATION specifies the location of the library file on disk -set_target_properties( - rapidsnark_prover_lib - PROPERTIES - IMPORTED_LOCATION ${SHARED_PROVER_LIBRARY_SO} -) - -#set( -# SHARED_SDK_LIBRARY_SO -# ${CMAKE_CURRENT_SOURCE_DIR}/../jniLibs/${CMAKE_ANDROID_ARCH_ABI}/libpolygonid.so -#) -## IMPORTED allows to depends on a library file outside the project. -#add_library( -# rapidsnark_sdk_lib -# SHARED -# IMPORTED -#) -## IMPORTED_LOCATION specifies the location of the library file on disk -#set_target_properties( -# rapidsnark_sdk_lib -# PROPERTIES -# IMPORTED_LOCATION ${SHARED_SDK_LIBRARY_SO} -# NO_SONAME 1 -#) - -# Add libraries to this project -target_link_libraries( - ${PROJECT_NAME} - rapidsnark_prover_lib -# rapidsnark_sdk_lib -) - -# Add the log library -find_library(log-lib log) -target_link_libraries(${PROJECT_NAME} ${log-lib}) diff --git a/android/src/main/cpp/rapidsnark_module.cpp b/android/src/main/cpp/rapidsnark_module.cpp deleted file mode 100644 index f1cc8b402..000000000 --- a/android/src/main/cpp/rapidsnark_module.cpp +++ /dev/null @@ -1,226 +0,0 @@ -#include "rapidsnark_module.h" - -#define TAG "RapidsnarkExampleNative" -#define LOGI(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16Prove( - JNIEnv *env, jobject obj, - jbyteArray zkeyBuffer, jlong zkeySize, - jbyteArray wtnsBuffer, jlong wtnsSize, - jbyteArray proofBuffer, jlongArray proofSize, - jbyteArray publicBuffer, jlongArray publicSize, - jbyteArray errorMsg, jlong errorMsgMaxSize -) { - LOGI("groth16Prover native called"); - - // Convert jbyteArray to native types - void *nativeZkeyBuffer = env->GetByteArrayElements(zkeyBuffer, nullptr); - void *nativeWtnsBuffer = env->GetByteArrayElements(wtnsBuffer, nullptr); - - char *nativeProofBuffer = (char *) env->GetByteArrayElements(proofBuffer, nullptr); - char *nativePublicBuffer = (char *) env->GetByteArrayElements(publicBuffer, nullptr); - char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr); - - jlong * nativeProofSizeArr = env->GetLongArrayElements(proofSize, 0); - jlong * nativePublicSizeArr = env->GetLongArrayElements(publicSize, 0); - - unsigned long nativeProofSize = nativeProofSizeArr[0]; - unsigned long nativePublicSize = nativePublicSizeArr[0]; - - // Call the groth16_prover function - int result = groth16_prover( - nativeZkeyBuffer, zkeySize, - nativeWtnsBuffer, wtnsSize, - nativeProofBuffer, &nativeProofSize, - nativePublicBuffer, &nativePublicSize, - nativeErrorMsg, errorMsgMaxSize - ); - - // Convert the results back to JNI types - nativeProofSizeArr[0] = nativeProofSize; - nativePublicSizeArr[0] = nativePublicSize; - - env->SetLongArrayRegion(proofSize, 0, 1, (jlong * ) - nativeProofSizeArr); - env->SetLongArrayRegion(publicSize, 0, 1, (jlong * ) - nativePublicSizeArr); - - // Release the native buffers - env->ReleaseByteArrayElements(zkeyBuffer, (jbyte *) nativeZkeyBuffer, 0); - env->ReleaseByteArrayElements(wtnsBuffer, (jbyte *) nativeWtnsBuffer, 0); - env->ReleaseByteArrayElements(proofBuffer, (jbyte *) nativeProofBuffer, 0); - env->ReleaseByteArrayElements(publicBuffer, (jbyte *) nativePublicBuffer, 0); - env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0); - - env->ReleaseLongArrayElements(proofSize, (jlong * ) - nativeProofSizeArr, 0); - env->ReleaseLongArrayElements(publicSize, (jlong * ) - nativePublicSizeArr, 0); - - return result; -} - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16ProveWithZKeyFilePath( - JNIEnv *env, jobject obj, - jstring zkeyPath, - jbyteArray wtnsBuffer, jlong wtnsSize, - jbyteArray proofBuffer, jlongArray proofSize, - jbyteArray publicBuffer, jlongArray publicSize, - jbyteArray errorMsg, jlong errorMsgMaxSize -) { - LOGI("groth16ProverZkeyFile native called"); - - // Convert jbyteArray to native types - const char *nativeZkeyPath = env->GetStringUTFChars(zkeyPath, nullptr); - - void *nativeWtnsBuffer = env->GetByteArrayElements(wtnsBuffer, nullptr); - - char *nativeProofBuffer = (char *) env->GetByteArrayElements(proofBuffer, nullptr); - char *nativePublicBuffer = (char *) env->GetByteArrayElements(publicBuffer, nullptr); - char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr); - - jlong * nativeProofSizeArr = env->GetLongArrayElements(proofSize, 0); - jlong * nativePublicSizeArr = env->GetLongArrayElements(publicSize, 0); - - unsigned long nativeProofSize = nativeProofSizeArr[0]; - unsigned long nativePublicSize = nativePublicSizeArr[0]; - - // Call the groth16_prover function` - int status_code = groth16_prover_zkey_file( - nativeZkeyPath, - nativeWtnsBuffer, wtnsSize, - nativeProofBuffer, &nativeProofSize, - nativePublicBuffer, &nativePublicSize, - nativeErrorMsg, errorMsgMaxSize - ); - - // Convert the results back to JNI types - nativeProofSizeArr[0] = nativeProofSize; - nativePublicSizeArr[0] = nativePublicSize; - - env->SetLongArrayRegion(proofSize, 0, 1, (jlong * ) - nativeProofSizeArr); - env->SetLongArrayRegion(publicSize, 0, 1, (jlong * ) - nativePublicSizeArr); - - // Release the native buffers - env->ReleaseByteArrayElements(wtnsBuffer, (jbyte *) nativeWtnsBuffer, 0); - env->ReleaseByteArrayElements(proofBuffer, (jbyte *) nativeProofBuffer, 0); - env->ReleaseByteArrayElements(publicBuffer, (jbyte *) nativePublicBuffer, 0); - env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0); - - env->ReleaseLongArrayElements(proofSize, (jlong * ) - nativeProofSizeArr, 0); - env->ReleaseLongArrayElements(publicSize, (jlong * ) - nativePublicSizeArr, 0); - - return status_code; -} - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16Verify( - JNIEnv *env, jobject obj, - jstring proof, jstring inputs, jstring verificationKey, - jbyteArray errorMsg, jlong errorMsgMaxSize -) { - LOGI("groth16Verifier native called"); - - // Convert jstring to native types - const char *nativeInputs = env->GetStringUTFChars(inputs, nullptr); - const char *nativeProof = env->GetStringUTFChars(proof, nullptr); - const char *nativeVerificationKey = env->GetStringUTFChars(verificationKey, nullptr); - - char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr); - - // Call the groth16_verify function - int status_code = groth16_verify( - nativeProof, - nativeInputs, - nativeVerificationKey, - nativeErrorMsg, errorMsgMaxSize - ); - - // Release the native buffers - env->ReleaseStringUTFChars(inputs, nativeInputs); - env->ReleaseStringUTFChars(proof, nativeProof); - env->ReleaseStringUTFChars(verificationKey, nativeVerificationKey); - - env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0); - - return status_code; -} - -JNIEXPORT jlong JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16PublicSizeForZkeyBuf( - JNIEnv *env, jobject obj, - jbyteArray zkeyBuffer, jlong zkeySize, - jbyteArray errorMsg, jlong errorMsgMaxSize -) { - LOGI("groth16_public_size_for_zkey_buf native called"); - - void *nativeZkeyBuffer = env->GetByteArrayElements(zkeyBuffer, nullptr); - char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr); - - jlong nativePublicSize = 0; - - // Call the groth16_public_size_for_zkey_buf function - int status_code = groth16_public_size_for_zkey_buf( - nativeZkeyBuffer, zkeySize, - (size_t * ) & nativePublicSize, - nativeErrorMsg, errorMsgMaxSize - ); - - LOGI("groth16_public_size_for_zkey_buf:%lu", nativePublicSize); - - // Release the native buffers - env->ReleaseByteArrayElements(zkeyBuffer, (jbyte *) nativeZkeyBuffer, 0); - env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0); - - return nativePublicSize; -} - -JNIEXPORT jlong JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16PublicSizeForZkeyFile( - JNIEnv *env, jobject obj, - jstring zkeyPath, - jbyteArray errorMsg, jlong errorMsgMaxSize -) { - LOGI("groth16_public_size_for_zkey_file native called"); - - const char *nativeZkeyPath = env->GetStringUTFChars(zkeyPath, nullptr); - - char *nativeErrorMsg = (char *) env->GetByteArrayElements(errorMsg, nullptr); - - jlong nativePublicSize = 0; - - // Call the groth16_public_size_for_zkey_file function - int status_code = groth16_public_size_for_zkey_file( - nativeZkeyPath, - (unsigned long *) &nativePublicSize, - nativeErrorMsg, errorMsgMaxSize - ); - - LOGI("groth16_public_size_for_zkey_file:%lu", nativePublicSize); - - // Release the native buffers - env->ReleaseStringUTFChars(zkeyPath, nativeZkeyPath); - env->ReleaseByteArrayElements(errorMsg, (jbyte *) nativeErrorMsg, 0); - - return nativePublicSize; -} - -inline const char *ToString(PLGNStatusCode v) { - switch (v) { - case PLGNSTATUSCODE_ERROR: - return "PLGNSTATUSCODE_ERROR"; - case PLGNSTATUSCODE_NIL_POINTER: - return "PLGNSTATUSCODE_NIL_POINTER"; - default: - return "[Unknown PLGNStatusCode]"; - } -} - -#ifdef __cplusplus -} -#endif diff --git a/android/src/main/cpp/rapidsnark_module.h b/android/src/main/cpp/rapidsnark_module.h deleted file mode 100644 index 1bee8c5cb..000000000 --- a/android/src/main/cpp/rapidsnark_module.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef ANDROID_CMAKE_RAPIDSNARK_MODULE_H -#define ANDROID_CMAKE_RAPIDSNARK_MODULE_H - -#include -#include -#include -#include "libpolygonid.h" -#include "prover.h" -#include "verifier.h" - -extern "C" { - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16Prove( - JNIEnv *env, jobject obj, - jbyteArray zkeyBuffer, jlong zkeySize, - jbyteArray wtnsBuffer, jlong wtnsSize, - jbyteArray proofBuffer, jlongArray proofSize, - jbyteArray publicBuffer, jlongArray publicSize, - jbyteArray errorMsg, jlong errorMsgMaxSize -); - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16ProveWithZKeyFilePath( - JNIEnv *env, jobject obj, - jstring zkeyPath, - jbyteArray wtnsBuffer, jlong wtnsSize, - jbyteArray proofBuffer, jlongArray proofSize, - jbyteArray publicBuffer, jlongArray publicSize, - jbyteArray errorMsg, jlong errorMsgMaxSize -); - -JNIEXPORT jint JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16Verify( - JNIEnv *env, jobject obj, - jstring proof, jstring inputs, jstring verificationKey, - jbyteArray errorMsg, jlong errorMsgMaxSize -); - -JNIEXPORT jlong JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16PublicSizeForZkeyBuf( - JNIEnv *env, jobject obj, - jbyteArray zkeyBuffer, jlong zkeySize, - jbyteArray errorMsg, jlong errorMsgMaxSize -); - -JNIEXPORT jlong JNICALL Java_io_iden3_polygonid_1flutter_1sdk_RapidsnarkJniBridge_groth16PublicSizeForZkeyFile( - JNIEnv *env, jobject obj, - jstring zkeyPath, - jbyteArray errorMsg, jlong errorMsgMaxSize -); - -} - -#endif //ANDROID_CMAKE_RAPIDSNARK_MODULE_H - - - - diff --git a/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/PolygonIdSdkPlugin.kt b/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/PolygonIdSdkPlugin.kt index 29dfb8d37..61918e734 100644 --- a/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/PolygonIdSdkPlugin.kt +++ b/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/PolygonIdSdkPlugin.kt @@ -8,7 +8,6 @@ import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import io.iden3.polygonid_flutter_sdk.* /** PolygonIdSdkPlugin */ class PolygonIdSdkPlugin : FlutterPlugin, MethodCallHandler { @@ -36,21 +35,7 @@ class PolygonIdSdkPlugin : FlutterPlugin, MethodCallHandler { } override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { - if (call.method == "prove") { - val zKeyPath = call.argument("zKeyPath") - val wtnsBytes = call.argument("wtnsBytes") - - val proof = groth16ProveWithZKeyFilePath(zKeyPath!!, wtnsBytes!!) - - result.success( - mapOf( - "proof" to proof.proof, - "pub_signals" to proof.publicSignals - ) - ) - } else { - result.notImplemented() - } + result.notImplemented() } override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { diff --git a/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/Rapidsnark.kt b/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/Rapidsnark.kt deleted file mode 100644 index 92fb1aaff..000000000 Binary files a/android/src/main/kotlin/io/iden3/polygonid_flutter_sdk/Rapidsnark.kt and /dev/null differ diff --git a/lib/proof/data/data_sources/prover_lib_data_source.dart b/lib/proof/data/data_sources/prover_lib_data_source.dart index f39fec7d7..62e2627eb 100644 --- a/lib/proof/data/data_sources/prover_lib_data_source.dart +++ b/lib/proof/data/data_sources/prover_lib_data_source.dart @@ -38,23 +38,8 @@ class ProverLibDataSource { String zKeyPath, Uint8List wtnsBytes, ) async { - if (Platform.isAndroid) { - final result = await _methodChannel.invokeMapMethod( - 'prove', - { - 'zKeyPath': zKeyPath, - 'wtnsBytes': wtnsBytes, - }, - ); - result?['proof'] = jsonDecode(result['proof'] as String); - result?['pub_signals'] = jsonDecode(result['pub_signals'] as String); - - return result?.cast(); - } else { - final result = - await _proverLibWrapper.prover(circuitId, zKeyPath, wtnsBytes); - - return result; - } + final result = + await _proverLibWrapper.prover(circuitId, zKeyPath, wtnsBytes); + return result; } }