bunch of cleaning 🧹

This commit is contained in:
0xturboblitz
2024-05-11 22:35:01 +09:00
parent 2b31b8cb49
commit b87707b05a
6 changed files with 27 additions and 1292 deletions

1
app/.gitignore vendored
View File

@@ -68,5 +68,4 @@ yarn-error.log
.expo/
libuniffi_mopro.so
ios/ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset/proof_of_passport.zkey

View File

@@ -1,3 +1 @@
build
app/src/main/res/raw/proof_of_passport_dat.dat
app/src/main/res/raw/proof_of_passport_zkey.zkey
build

View File

@@ -9,7 +9,6 @@ import android.util.Log
import android.content.Context
import java.io.ByteArrayOutputStream
import com.facebook.react.bridge.ReadableMap
import uniffi.mopro.GenerateProofResult
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -53,7 +52,7 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
val gson = GsonBuilder().setPrettyPrinting().create()
Log.e(TAG, gson.toJson(formattedInputs))
// working example
// (used to be) working example
// val inputs = mutableMapOf<String, List<String>>(
// "mrz" to listOf("97","91","95","31","88","80","60","70","82","65","84","65","86","69","82","78","73","69","82","60","60","70","76","79","82","69","78","84","60","72","85","71","85","69","83","60","74","69","65","78","60","60","60","60","60","60","60","60","60","49","57","72","65","51","52","56","50","56","52","70","82","65","48","48","48","55","49","57","49","77","50","57","49","50","48","57","53","60","60","60","60","60","60","60","60","60","60","60","60","60","60","48","50"),
// "reveal_bitmap" to listOf("0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"),
@@ -69,32 +68,10 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
// "address" to listOf("642829559307850963015472508762062935916233390536")
// )
// data class InputsPassport(
// val `in`: List<Int>,
// val currDateYear: Int,
// val currDateMonth: Int,
// val currDateDay: Int,
// val credValidYear: Int,
// val credValidMonth: Int,
// val credValidDay: Int,
// val ageLowerbound: Int
// )
// val formattedInputs = InputsPassport(
// `in` = (dg1!!).toBitArray().toCharArray().map { it1 -> it1.digitToInt() },
// currDateDay = current.dayOfMonth,
// credValidDay = nextDate.dayOfMonth,
// credValidMonth = nextDate.month.value,
// credValidYear = nextDate.year.toString().takeLast(2).toInt(),
// currDateMonth = current.month.value,
// currDateYear = current.year.toString().takeLast(2).toInt(),
// ageLowerbound = 18
// )
val jsonInputs = gson.toJson(formattedInputs).toByteArray()
val zkpTools = ZKPTools(reactApplicationContext) // <== same thing here
val zkpTools = ZKPTools(reactApplicationContext)
// reactContext or context???
val zkp: ZkProof = ZKPUseCase(reactApplicationContext).generateZKP(
R.raw.proof_of_passport_dat, // datID as Int
jsonInputs,
@@ -104,28 +81,6 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
Log.e("ZKP", gson.toJson(zkp))
promise.resolve(zkp.toString())
// val convertedInputs = mutableMapOf<String, List<String>>()
// for ((key, value) in inputs.toHashMap()) {
// val parsedArray = inputs.getArray(key)?.toArrayList()?.map { item ->
// item.toString()
// } ?: emptyList()
// convertedInputs[key] = parsedArray
// }
// Log.e(TAG, "convertedInputs: $convertedInputs")
// val startTime = System.currentTimeMillis()
// res = uniffi.mopro.generateProof2(convertedInputs)
// val endTime = System.currentTimeMillis()
// val provingTime = "proving time: " + (endTime - startTime).toString() + " ms"
// Log.e(TAG, provingTime)
// Log.e(TAG, "res: " + res.toString())
// promise.resolve(res.toString())
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,76 +1,31 @@
#!/bin/bash
# This is adapted from mopro
# Make that not happen if build ios is already done
DEVICE_TYPE="arm64"
BUILD_MODE="release"
# cp ../circuits/build/proof_of_passport_cpp/proof_of_passport.cpp witnesscalc/src
# cp ../circuits/build/proof_of_passport_cpp/proof_of_passport.dat witnesscalc/src
# Determine the architecture and folder based on device type
case $DEVICE_TYPE in
"x86_64")
ARCHITECTURE="x86_64-linux-android"
FOLDER="x86_64"
;;
"x86")
ARCHITECTURE="i686-linux-android"
FOLDER="x86"
;;
"arm")
ARCHITECTURE="armv7-linux-androideabi"
FOLDER="armeabi-v7a"
;;
"arm64")
ARCHITECTURE="aarch64-linux-android"
FOLDER="arm64-v8a"
;;
*)
echo -e "${RED}Error: Invalid device type specified in config: $DEVICE_TYPE${DEFAULT}"
exit 1
;;
esac
# cd witnesscalc/src
# # This adds the namespace to the circuit file as described in the README
# last_include=$(grep -n '#include' proof_of_passport.cpp | tail -1 | cut -d: -f1)
# if [[ "$OSTYPE" == "darwin"* ]]; then
# # macOS requires an empty string with the -i flag and handles backslashes differently
# sed -i "" "${last_include}a\\
# namespace CIRCUIT_NAME {" proof_of_passport.cpp
# else
# # Linux
# sed -i "${last_include}a \\nnamespace CIRCUIT_NAME {" proof_of_passport.cpp
# fi
# echo "}" >> proof_of_passport.cpp
# Determine the library directory and build command based on build mode
case $BUILD_MODE in
"debug")
LIB_DIR="debug"
COMMAND=""
;;
"release")
LIB_DIR="release"
COMMAND="--release"
;;
*)
echo -e "${RED}Error: Invalid build mode specified in config: $BUILD_MODE${DEFAULT}"
exit 1
;;
esac
# cd ../../..
# git submodule init
# git submodule update
PROJECT_DIR=$(pwd)
# cd app/witnesscalc
cd witnesscalc
./build_gmp.sh android
make android
cd ..
cd ${PROJECT_DIR}/mopro-ffi
echo "[android] Install cargo-ndk"
cargo install cargo-ndk
# Print appropriate message based on device type
echo "Using $ARCHITECTURE libmopro_ffi.a ($LIB_DIR) static library..."
echo "This only works on $FOLDER devices!"
echo "[android] Build target in $BUILD_MODE mode"
cargo ndk -t ${ARCHITECTURE} build --lib ${COMMAND}
echo "[android] Copy files in mopro-android/Example/jniLibs/"
for binary in ${PROJECT_DIR}/mopro-ffi/target/*/*/libmopro_ffi.so; do file $binary; done
mkdir -p jniLibs/${FOLDER}/ && \
cp ${PROJECT_DIR}/mopro-ffi/target/${ARCHITECTURE}/${LIB_DIR}/libmopro_ffi.so jniLibs/${FOLDER}/libuniffi_mopro.so
echo "[android] Generating Kotlin bindings in $BUILD_MODE mode..."
cargo run --features=uniffi/cli ${COMMAND} \
--bin uniffi-bindgen \
generate src/mopro.udl \
--language kotlin
echo "[android] Copy Kotlin bindings to android app"
cp -r ${PROJECT_DIR}/mopro-ffi/jniLibs/ ${PROJECT_DIR}/android/app/src/main/jniLibs/
cp -r ${PROJECT_DIR}/mopro-ffi/src/uniffi/ ${PROJECT_DIR}/android/app/src/main/java/uniffi/
cp ../circuits/build/proof_of_passport_cpp/proof_of_passport.dat android/app/src/main/res/raw/proof_of_passport_dat.dat