Skip to content

Commit

Permalink
Merge pull request #177 from zk-passport/new-ux-refactor-circuits
Browse files Browse the repository at this point in the history
refactor repo · new ux · prove circuits · new sdk
  • Loading branch information
remicolin authored Aug 29, 2024
2 parents 2c441c9 + e019d41 commit 40ed5c9
Show file tree
Hide file tree
Showing 291 changed files with 5,152,211 additions and 7,429 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ on:
branches:
- dev
- main
paths:
- 'circuits/**'
- 'common/**'
pull_request:
branches:
- dev
- main
paths:
- 'circuits/**'
- 'common/**'
jobs:
run_circuit_tests:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
environment: development
steps:
Expand Down
3 changes: 2 additions & 1 deletion app/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSameLine: false,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
bracketSpacing: true,
};
5 changes: 2 additions & 3 deletions app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@ function App(): JSX.Element {
useEffect(() => {
setToast(toast);
}, [toast, setToast]);

useEffect(() => {
setSelectedTab('splash');
}, [setSelectedTab]);

useEffect(() => {
if (AMPLITUDE_KEY) {
amplitude.init(AMPLITUDE_KEY);
}
//initUserStore();
}, []);

// TODO: when passportData already stored, retrieve and jump to main screen

return (
<YStack f={1} bc={bgWhite} h="100%" w="100%">
<YStack h="100%" w="100%">
Expand Down
24 changes: 19 additions & 5 deletions app/android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,29 @@ link_directories(lib)
add_library(rapidsnark SHARED IMPORTED)
set_target_properties(rapidsnark PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/librapidsnark.so)

# add_library(register_sha256WithRSAEncryption_65537 SHARED IMPORTED)
# set_target_properties(register_sha256WithRSAEncryption_65537 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_register_sha256WithRSAEncryption_65537.so)

add_library(register_sha256WithRSAEncryption_65537 SHARED IMPORTED)
set_target_properties(register_sha256WithRSAEncryption_65537 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_register_sha256WithRSAEncryption_65537.so)
# add_library(disclose SHARED IMPORTED)
# set_target_properties(disclose PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_disclose.so)

add_library(disclose SHARED IMPORTED)
set_target_properties(disclose PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_disclose.so)
add_library(prove_rsa_65537_sha256 SHARED IMPORTED)
set_target_properties(prove_rsa_65537_sha256 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_rsa_65537_sha256.so)

add_library(prove_rsa_65537_sha1 SHARED IMPORTED)
set_target_properties(prove_rsa_65537_sha1 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_rsa_65537_sha1.so)

add_library(prove_rsapss_65537_sha256 SHARED IMPORTED)
set_target_properties(prove_rsapss_65537_sha256 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libwitnesscalc_prove_rsapss_65537_sha256.so)

add_library(${CMAKE_PROJECT_NAME} SHARED
proofofpassportapp.cpp)

target_link_libraries(${CMAKE_PROJECT_NAME}
rapidsnark register_sha256WithRSAEncryption_65537 disclose)
rapidsnark
# register_sha256WithRSAEncryption_65537
# disclose
prove_rsa_65537_sha256
prove_rsa_65537_sha1
prove_rsapss_65537_sha256
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_prove_rsa_65537_sha1_H
#define WITNESSCALC_prove_rsa_65537_sha1_H


#ifdef __cplusplus
extern "C" {
#endif

#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2

/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/

int
witnesscalc_prove_rsa_65537_sha1(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // WITNESSCALC_prove_rsa_65537_sha1_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_prove_rsa_65537_sha256_H
#define WITNESSCALC_prove_rsa_65537_sha256_H


#ifdef __cplusplus
extern "C" {
#endif

#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2

/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/

int
witnesscalc_prove_rsa_65537_sha256(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // WITNESSCALC_prove_rsa_65537_sha256_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef WITNESSCALC_prove_rsapss_65537_sha256_H
#define WITNESSCALC_prove_rsapss_65537_sha256_H


#ifdef __cplusplus
extern "C" {
#endif

#define WITNESSCALC_OK 0x0
#define WITNESSCALC_ERROR 0x1
#define WITNESSCALC_ERROR_SHORT_BUFFER 0x2

/**
*
* @return error code:
* WITNESSCALC_OK - in case of success.
* WITNESSCALC_ERROR - in case of an error.
*
* On success wtns_buffer is filled with witness data and
* wtns_size contains the number bytes copied to wtns_buffer.
*
* If wtns_buffer is too small then the function returns WITNESSCALC_ERROR_SHORT_BUFFER
* and the minimum size for wtns_buffer in wtns_size.
*
*/

int
witnesscalc_prove_rsapss_65537_sha256(
const char *circuit_buffer, unsigned long circuit_size,
const char *json_buffer, unsigned long json_size,
char *wtns_buffer, unsigned long *wtns_size,
char *error_msg, unsigned long error_msg_maxsize);

#ifdef __cplusplus
}
#endif


#endif // WITNESSCALC_prove_rsapss_65537_sha256_H
Binary file not shown.
Binary file not shown.
Binary file not shown.
126 changes: 120 additions & 6 deletions app/android/app/src/main/cpp/proofofpassportapp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "include/prover.h"
#include "include/witnesscalc_register_sha256WithRSAEncryption_65537.h"
#include "include/witnesscalc_disclose.h"
// #include "include/witnesscalc_register_sha256WithRSAEncryption_65537.h"
// #include "include/witnesscalc_disclose.h"
#include "include/witnesscalc_prove_rsa_65537_sha256.h"
#include "include/witnesscalc_prove_rsa_65537_sha1.h"
#include "include/witnesscalc_prove_rsapss_65537_sha256.h"

#include <jni.h>
#include <iostream>
Expand Down Expand Up @@ -47,9 +50,120 @@ Java_com_proofofpassportapp_prover_ZKPTools_groth16_1prover(JNIEnv *env, jobject
return result;
}

// extern "C"
// JNIEXPORT jint JNICALL
// Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1register_1sha256WithRSAEncryption_165537(JNIEnv *env, jobject thiz,
// jbyteArray circuit_buffer,
// jlong circuit_size, jbyteArray json_buffer,
// jlong json_size, jbyteArray wtns_buffer,
// jlongArray wtns_size, jbyteArray error_msg,
// jlong error_msg_max_size) {
// const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
// circuit_buffer, nullptr));
// const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
// nullptr));
// char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
// char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));

// unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


// int result = witnesscalc_register_sha256WithRSAEncryption_65537(
// circuitBuffer, static_cast<unsigned long>(circuit_size),
// jsonBuffer, static_cast<unsigned long>(json_size),
// wtnsBuffer, &wtnsSize,
// errorMsg, static_cast<unsigned long>(error_msg_max_size));

// // Set the result and release the resources
// env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));

// env->ReleaseByteArrayElements(circuit_buffer,
// reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
// env->ReleaseByteArrayElements(json_buffer,
// reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
// env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
// env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);

// return result;
// }

// extern "C"
// JNIEXPORT jint JNICALL
// Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1disclose(JNIEnv *env, jobject thiz,
// jbyteArray circuit_buffer,
// jlong circuit_size, jbyteArray json_buffer,
// jlong json_size, jbyteArray wtns_buffer,
// jlongArray wtns_size, jbyteArray error_msg,
// jlong error_msg_max_size) {
// const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
// circuit_buffer, nullptr));
// const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
// nullptr));
// char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
// char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));

// unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


// int result = witnesscalc_disclose(
// circuitBuffer, static_cast<unsigned long>(circuit_size),
// jsonBuffer, static_cast<unsigned long>(json_size),
// wtnsBuffer, &wtnsSize,
// errorMsg, static_cast<unsigned long>(error_msg_max_size));

// // Set the result and release the resources
// env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));

// env->ReleaseByteArrayElements(circuit_buffer,
// reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
// env->ReleaseByteArrayElements(json_buffer,
// reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
// env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
// env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);

// return result;
// }

extern "C"
JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsa_165537_1sha256(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
jlongArray wtns_size, jbyteArray error_msg,
jlong error_msg_max_size) {
const char *circuitBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(
circuit_buffer, nullptr));
const char *jsonBuffer = reinterpret_cast<const char *>(env->GetByteArrayElements(json_buffer,
nullptr));
char *wtnsBuffer = reinterpret_cast<char *>(env->GetByteArrayElements(wtns_buffer, nullptr));
char *errorMsg = reinterpret_cast<char *>(env->GetByteArrayElements(error_msg, nullptr));

unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


int result = witnesscalc_prove_rsa_65537_sha256(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
errorMsg, static_cast<unsigned long>(error_msg_max_size));

// Set the result and release the resources
env->SetLongArrayRegion(wtns_size, 0, 1, reinterpret_cast<jlong *>(&wtnsSize));

env->ReleaseByteArrayElements(circuit_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(circuitBuffer)), 0);
env->ReleaseByteArrayElements(json_buffer,
reinterpret_cast<jbyte *>(const_cast<char *>(jsonBuffer)), 0);
env->ReleaseByteArrayElements(wtns_buffer, reinterpret_cast<jbyte *>(wtnsBuffer), 0);
env->ReleaseByteArrayElements(error_msg, reinterpret_cast<jbyte *>(errorMsg), 0);

return result;
}

extern "C"
JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1register_1sha256WithRSAEncryption_165537(JNIEnv *env, jobject thiz,
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsa_165537_1sha1(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
Expand All @@ -65,7 +179,7 @@ Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1register_1sha256WithRSA
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


int result = witnesscalc_register_sha256WithRSAEncryption_65537(
int result = witnesscalc_prove_rsa_65537_sha1(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
Expand All @@ -86,7 +200,7 @@ Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1register_1sha256WithRSA

extern "C"
JNIEXPORT jint JNICALL
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1disclose(JNIEnv *env, jobject thiz,
Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1prove_1rsapss_165537_1sha256(JNIEnv *env, jobject thiz,
jbyteArray circuit_buffer,
jlong circuit_size, jbyteArray json_buffer,
jlong json_size, jbyteArray wtns_buffer,
Expand All @@ -102,7 +216,7 @@ Java_com_proofofpassportapp_prover_ZKPTools_witnesscalc_1disclose(JNIEnv *env, j
unsigned long wtnsSize = env->GetLongArrayElements(wtns_size, nullptr)[0];


int result = witnesscalc_disclose(
int result = witnesscalc_prove_rsapss_65537_sha256(
circuitBuffer, static_cast<unsigned long>(circuit_size),
jsonBuffer, static_cast<unsigned long>(json_size),
wtnsBuffer, &wtnsSize,
Expand Down
Loading

0 comments on commit 40ed5c9

Please sign in to comment.