mirror of
https://github.com/selfxyz/self.git
synced 2026-01-21 12:38:03 -05:00
Merge remote-tracking branch 'origin/dev' into black-ui
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "app/witnesscalc/depends/json"]
|
||||
path = app/witnesscalc/depends/json
|
||||
url = https://github.com/nlohmann/json.git
|
||||
27
README.md
27
README.md
@@ -15,18 +15,18 @@ As a first application, users who can prove they indeed hold a valid passport ca
|
||||
- `circuits`: Circom circuits
|
||||
- `contracts`: Solidity contracts
|
||||
- `common`: Common utils
|
||||
- `registry`: Public key registry
|
||||
|
||||
## Roadmap
|
||||
|
||||
- ✅ Basic passport verifier circuit
|
||||
- ✅ Passport verification circuit
|
||||
- ✅ Selective disclosure
|
||||
- ✅ Basic react native frontend
|
||||
- ✅ Passport verification pipeline, android
|
||||
- ✅ Passport verification pipeline, iOS
|
||||
- ✅ Contracts
|
||||
- ✅ On-chain registry of CSCA pubkeys based on the official ICAO masterlist
|
||||
- 🚧 Optimizations
|
||||
- 🚧 Reimplementation of the passport NFC specs in javascript
|
||||
- ✅ Mobile app
|
||||
- ✅ SBT smart contract
|
||||
- ✅ On-chain public key registry
|
||||
- 🚧 Support additional signature algorithms
|
||||
- 🚧 Support Active Authentication
|
||||
- 🚧 SDK
|
||||
|
||||
## FAQ
|
||||
|
||||
@@ -61,7 +61,7 @@ Most countries use RSA with sha256 but some of them use other signature algorith
|
||||
|
||||
#### I just read my passport but it says my signature algorithm is not implemented. What do I do ?
|
||||
|
||||
Currently we only support the most common one `sha256WithRSAEncryption`. We will support the others shortly. Feel free to try your hand at implementing one!
|
||||
Currently we support the most common one, RSA with sha256. We're planning to add support for others shortly. Feel free to try your hand at implementing one!
|
||||
|
||||
#### What's the ICAO ?
|
||||
|
||||
@@ -93,25 +93,28 @@ The SBT circuit includes a commitment to your address. If someone else tries to
|
||||
|
||||
- Integrate Proof of Passport to Gitcoin passport or a similar system to allow better sybil resistance in quadratic funding
|
||||
- Combine with other sources of identity to provide quantified levels of uniqueness, [totem](https://github.com/0xturboblitz/totem)-style. Examples can be [anon aadhaar](https://github.com/privacy-scaling-explorations/anon-aadhaar), [Japan's my number cards](https://github.com/MynaWallet/monorepo) or [Taiwan DID](https://github.com/tw-did/tw-did/)
|
||||
|
||||
- Add Proof of Passport as a [Zupass](https://github.com/proofcarryingdata/zupass) PCD
|
||||
- Build a social network/anonymous message board for people from one specific country
|
||||
- Create a sybil-resistance tool to protect social networks against spambots
|
||||
- Do an airdrop farming protection tool
|
||||
- Allow DeFi protocols to check if the nationality of a user is included in a set of forbidden states
|
||||
- Gate an adult content website to a specific age
|
||||
- Create a petition system or a survey portal
|
||||
- Use for proof of location using place of birth and/or address
|
||||
- Passport Wallet: use [active authentication](https://en.wikipedia.org/wiki/Biometric_passport#:~:text=Active%20Authentication%20(AA),Using%20AA%20is%20optional.) to build a wallet, a multisig or a recovery module using passport signatures
|
||||
|
||||
We will provide bounties for all those applications. Those are not fixed right now, so please contact us if you're interested.
|
||||
|
||||
## Licensing
|
||||
|
||||
Everything we write is MIT licensed. Circom and circomlib are GPL tho.
|
||||
|
||||
## Contributing
|
||||
|
||||
We are actively looking for contributors. Please check the [open issues](https://github.com/zk-passport/proof-of-passport/issues) if you don't know were to start!
|
||||
We are actively looking for contributors. Please check the [open issues](https://github.com/zk-passport/proof-of-passport/issues) if you don't know were to start! We will offer bounties from $100 to $1000 for any significant progress on these, depending on difficulty. Please contact us for more details.
|
||||
|
||||
## Contact us
|
||||
|
||||
Contact me @FlorentTavernier on telegram for any feedback.
|
||||
|
||||
Thanks to [Youssef](https://github.com/yssf-io), [Aayush](https://twitter.com/yush_g), [Andy](https://twitter.com/AndyGuzmanEth), [Vivek](https://twitter.com/viv_boop), [Marcus](https://github.com/base0010) and [Andrew](https://github.com/AndrewCLu) for contributing ideas and helping build this technology, and to [EF PSE](https://pse.dev/) for supporting this work through grants!
|
||||
Thanks to [Rémi](https://github.com/remicolin), [Youssef](https://github.com/yssf-io), [Aayush](https://twitter.com/yush_g), [Andy](https://twitter.com/AndyGuzmanEth), [Vivek](https://twitter.com/viv_boop), [Marcus](https://github.com/base0010) and [Andrew](https://github.com/AndrewCLu) for contributing ideas and helping build this technology, and to [EF PSE](https://pse.dev/) for supporting this work through grants!
|
||||
|
||||
5
app/.gitignore
vendored
5
app/.gitignore
vendored
@@ -4,7 +4,7 @@
|
||||
|
||||
# Xcode
|
||||
#
|
||||
build/
|
||||
ios/build
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
@@ -24,7 +24,6 @@ ios/.xcode.env.local
|
||||
|
||||
# Android/IntelliJ
|
||||
#
|
||||
build/
|
||||
.idea
|
||||
.gradle
|
||||
local.properties
|
||||
@@ -69,4 +68,4 @@ yarn-error.log
|
||||
|
||||
.expo/
|
||||
|
||||
libuniffi_mopro.so
|
||||
ios/ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset/proof_of_passport.zkey
|
||||
75
app/App.tsx
75
app/App.tsx
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
NativeModules,
|
||||
DeviceEventEmitter,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import {
|
||||
DEFAULT_PNUMBER,
|
||||
@@ -21,10 +22,14 @@ import { Buffer } from 'buffer';
|
||||
import { YStack } from 'tamagui';
|
||||
import { prove } from './src/utils/prover';
|
||||
import { useToastController } from '@tamagui/toast';
|
||||
import RNFS from 'react-native-fs';
|
||||
import { ARKZKEY_URL, ZKEY_URL } from '../common/src/constants/constants';
|
||||
global.Buffer = Buffer;
|
||||
|
||||
console.log('DEFAULT_PNUMBER', DEFAULT_PNUMBER);
|
||||
|
||||
const localZkeyPath = RNFS.DocumentDirectoryPath + '/proof_of_passport.zkey';
|
||||
|
||||
function App(): JSX.Element {
|
||||
const [passportNumber, setPassportNumber] = useState(DEFAULT_PNUMBER ?? "");
|
||||
const [dateOfBirth, setDateOfBirth] = useState(DEFAULT_DOB ?? '');
|
||||
@@ -37,6 +42,7 @@ function App(): JSX.Element {
|
||||
const [proof, setProof] = useState<{ proof: string, inputs: string } | null>(null);
|
||||
const [mintText, setMintText] = useState<string>("");
|
||||
const [majority, setMajority] = useState<number>(18);
|
||||
const [zkeydownloadStatus, setDownloadStatus] = useState<"not_started" | "downloading" | "completed" | "error">("not_started");
|
||||
|
||||
const [disclosure, setDisclosure] = useState({
|
||||
issuing_state: false,
|
||||
@@ -69,18 +75,66 @@ function App(): JSX.Element {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
init()
|
||||
downloadZkey()
|
||||
}, []);
|
||||
|
||||
async function init() {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
console.log('launching init')
|
||||
const res = await NativeModules.Prover.runInitAction()
|
||||
console.log('init done')
|
||||
console.log('init res', res)
|
||||
async function initMopro() {
|
||||
if (Platform.OS === 'android') {
|
||||
const res = await NativeModules.Prover.runInitAction()
|
||||
console.log('Mopro init res:', res)
|
||||
}
|
||||
}
|
||||
|
||||
const handleStartCameraScan = () => {
|
||||
async function downloadZkey() {
|
||||
console.log('localZkeyPath:', localZkeyPath)
|
||||
const fileExists = await RNFS.exists(localZkeyPath);
|
||||
if (!fileExists) {
|
||||
console.log('launching zkey download')
|
||||
setDownloadStatus('downloading');
|
||||
|
||||
let previousPercentComplete = -1;
|
||||
|
||||
const options = {
|
||||
// @ts-ignore
|
||||
fromUrl: Platform.OS === 'android' ? ARKZKEY_URL : ZKEY_URL,
|
||||
toFile: localZkeyPath,
|
||||
background: true,
|
||||
begin: () => {
|
||||
console.log('Download has begun');
|
||||
},
|
||||
progress: (res: any) => {
|
||||
const percentComplete = Math.floor((res.bytesWritten / res.contentLength) * 100);
|
||||
if (percentComplete !== previousPercentComplete) {
|
||||
console.log(`${percentComplete}%`);
|
||||
previousPercentComplete = percentComplete;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
RNFS.downloadFile(options).promise
|
||||
.then(() => {
|
||||
setDownloadStatus('completed')
|
||||
console.log('Download complete');
|
||||
initMopro()
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
setDownloadStatus('error');
|
||||
toast.show('Error', {
|
||||
message: `Error: ${error.message}`,
|
||||
customData: {
|
||||
type: "error",
|
||||
},
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('zkey already downloaded')
|
||||
setDownloadStatus('completed');
|
||||
initMopro()
|
||||
}
|
||||
}
|
||||
|
||||
const handleStartCameraScan = async () => {
|
||||
startCameraScan({
|
||||
setPassportNumber,
|
||||
setDateOfBirth,
|
||||
@@ -102,7 +156,7 @@ function App(): JSX.Element {
|
||||
});
|
||||
};
|
||||
|
||||
const handleProve = (path: string) => {
|
||||
const handleProve = () => {
|
||||
prove({
|
||||
passportData,
|
||||
disclosure,
|
||||
@@ -112,7 +166,7 @@ function App(): JSX.Element {
|
||||
setProofTime,
|
||||
setProof,
|
||||
toast
|
||||
}, path);
|
||||
});
|
||||
};
|
||||
|
||||
const handleMint = () => {
|
||||
@@ -151,6 +205,7 @@ function App(): JSX.Element {
|
||||
setDateOfExpiry={setDateOfExpiry}
|
||||
majority={majority}
|
||||
setMajority={setMajority}
|
||||
zkeydownloadStatus={zkeydownloadStatus}
|
||||
/>
|
||||
</YStack>
|
||||
</YStack>
|
||||
|
||||
107
app/README.md
107
app/README.md
@@ -1,14 +1,14 @@
|
||||
# Proof of Passport App
|
||||
|
||||
### Requirements
|
||||
## Requirements
|
||||
|
||||
Install `nodejs v18`, [circom](https://docs.circom.io/) and [snarkjs](https://github.com/iden3/snarkjs)
|
||||
|
||||
For android, install java, android studio and the android sdk
|
||||
For Android, install Java, Android Studio and the Android SDK
|
||||
|
||||
For ios, install Xcode and [cocoapods](https://cocoapods.org/)
|
||||
For iOS, install Xcode and [cocoapods](https://cocoapods.org/)
|
||||
|
||||
### Installation
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
yarn
|
||||
@@ -19,13 +19,50 @@ In `/common`, also run:
|
||||
yarn
|
||||
```
|
||||
|
||||
### Build the app
|
||||
## Run the app
|
||||
|
||||
Go to the `circuit` folder of the monorepo and build the circuit.
|
||||
Let's run the app with the currently deployed zkey to mint the Proof of Passport SBT.
|
||||
|
||||
#### Build the android native module
|
||||
First, connect your phone to your computer and allow access.
|
||||
|
||||
Run:
|
||||
### Android
|
||||
|
||||
Launch the react-native server:
|
||||
```
|
||||
yarn start
|
||||
```
|
||||
|
||||
Press `a` to open the app on Android.
|
||||
|
||||
To see the Android logs you'll have to use the Android Studio Logcat.
|
||||
|
||||
### iOS
|
||||
|
||||
To run the app on iOS, you will need an Apple Developer account. Free accounts can't run apps that use NFC reading.
|
||||
|
||||
Open the ios project on Xcode and add your provisionning profile in Targets > ProofOfPassport > Signing and Capabilities
|
||||
|
||||
Then, install pods:
|
||||
```
|
||||
cd ios
|
||||
pod install
|
||||
```
|
||||
|
||||
And run the app in Xcode.
|
||||
|
||||
## Modify the circuits
|
||||
|
||||
If you want to modify the circuits, you'll have to adapt a few things.
|
||||
|
||||
First, go to the `circuit` folder of the monorepo, modify the circuits and build them.
|
||||
|
||||
Then, upload the zkey and the arkzkey built at a publicly available url and replace the two urls in `common/src/constants/constants.ts`
|
||||
|
||||
Adapt the inputs you pass in `app/src/utils/prover.ts` and if you want to mint SBTs, adapt and redeploy the contracts.
|
||||
|
||||
### Android
|
||||
|
||||
Build the android native module:
|
||||
```
|
||||
./scripts/build_android_module.sh
|
||||
```
|
||||
@@ -36,57 +73,55 @@ rustup default 1.67.0
|
||||
```
|
||||
|
||||
For macOS users you might also need to set-up the path to sdk:
|
||||
in /app/android create local.properties
|
||||
in `/app/android` create `local.properties`
|
||||
|
||||
Add the following line:
|
||||
sdk.dir=/Users/<user>/Library/Android/sdk or any relevant path to your sdk
|
||||
`sdk.dir=/Users/<user>/Library/Android/sdk` or any relevant path to your sdk
|
||||
|
||||
#### Build the iOS native module
|
||||
### iOS
|
||||
|
||||
Run:
|
||||
Find your [development team id](https://chat.openai.com/share/9d52c37f-d9da-4a62-acb9-9e4ee8179f95) and run:
|
||||
```
|
||||
export DEVELOPMENT_TEAM="<your-development-team-id>"
|
||||
./scripts/build_ios_module.sh
|
||||
```
|
||||
|
||||
#### Run the server
|
||||
## Export a new release
|
||||
|
||||
To run the server, first connect your phone to your computer, allow access, then:
|
||||
```
|
||||
yarn start
|
||||
```
|
||||
Then press `a` for android or `i` for iOS
|
||||
### Android
|
||||
|
||||
If you want to see the logs and have a better ios developer experience, open `/ios` in Xcode and launch the app from there instead.
|
||||
#### Export as apk
|
||||
|
||||
> :warning: Due to the current limitations of mopro, see [#51](https://github.com/zk-passport/proof-of-passport/issues/51), the proving on iOS only works when the app is run on Xcode. It will not work with the react native server or in a .ipa build. We are working on fixing that.
|
||||
|
||||
To see the android logs you'll have to use the Android Studio Logcat.
|
||||
|
||||
To export an apk:
|
||||
```
|
||||
cd android
|
||||
./gradlew assembleRelease
|
||||
```
|
||||
The built apk it located at `android/app/build/outputs/apk/release/app-release.apk`
|
||||
|
||||
#### Download zkey
|
||||
If you want to mint a proof of passport SBT, instead of building the circuit yourself, run:
|
||||
```
|
||||
./scripts/download_current_zkey.sh
|
||||
```
|
||||
|
||||
This will download the zkey currently deployed onchain in the proof of passport contract and place it in `circuits/build``
|
||||
Then, build the android or iOS native module and run the app.
|
||||
|
||||
#### Releases
|
||||
|
||||
##### Play Store
|
||||
#### Publish on the Play Store
|
||||
As explained [here](https://reactnative.dev/docs/signed-apk-android), first setup `android/app/my-upload-key.keystore` and the private vars in `~/.gradle/gradle.properties`, then run:
|
||||
```
|
||||
npx react-native build-android --mode=release
|
||||
```
|
||||
This builds `android/app/build/outputs/bundle/release/app-release.aab`.
|
||||
|
||||
Then to test the release on an android phone, delete the previous version of the app and run:
|
||||
```
|
||||
yarn android --mode release
|
||||
```
|
||||
|
||||
### iOS
|
||||
|
||||
In Xcode, go to `Product>Archive` then follow the flow.
|
||||
|
||||
## FAQ
|
||||
|
||||
If you get something like this:
|
||||
```
|
||||
'std::__1::system_error: open: /proof-of-passport/app: Operation not permitted'
|
||||
```
|
||||
You might want to try [this](https://stackoverflow.com/questions/49443341/watchman-crawl-failed-retrying-once-with-node-crawler):
|
||||
```
|
||||
watchman watch-del-all
|
||||
watchman shutdown-server
|
||||
```
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* @format
|
||||
*/
|
||||
|
||||
import 'react-native';
|
||||
import React from 'react';
|
||||
import App from '../App';
|
||||
|
||||
// Note: import explicitly to use the types shiped with jest.
|
||||
import {it} from '@jest/globals';
|
||||
|
||||
// Note: test renderer must be required after react-native.
|
||||
import renderer from 'react-test-renderer';
|
||||
|
||||
it('renders correctly', () => {
|
||||
renderer.create(<App />);
|
||||
});
|
||||
1
app/android/.gitignore
vendored
Normal file
1
app/android/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build
|
||||
@@ -120,8 +120,8 @@ dependencies {
|
||||
// The version of react-native is set by the React Native Gradle Plugin
|
||||
implementation("com.facebook.react:react-android")
|
||||
implementation(project(":react-native-passport-reader")) {
|
||||
exclude group: 'edu.ucar', module: 'jj2000'
|
||||
}
|
||||
exclude group: 'edu.ucar', module: 'jj2000'
|
||||
}
|
||||
implementation project(':passportreader')
|
||||
implementation 'org.jmrtd:jmrtd:0.7.18'
|
||||
|
||||
@@ -139,7 +139,7 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation("net.java.dev.jna:jna:5.13.0@aar")
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android'
|
||||
|
||||
implementation project(':react-native-fs')
|
||||
}
|
||||
|
||||
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
|
||||
|
||||
@@ -8,11 +8,11 @@ import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||
import com.facebook.react.defaults.DefaultReactNativeHost;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.proofofpassport.CameraActivityPackage; // import new package for mrz reading
|
||||
import com.proofofpassport.CameraActivityPackage;
|
||||
import io.tradle.nfc.RNPassportReaderPackage;
|
||||
import java.util.List;
|
||||
import com.proofofpassport.prover.ProverPackage;
|
||||
|
||||
import com.rnfs.RNFSPackage;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
|
||||
|
||||
@@ -45,36 +45,6 @@ class ProverModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
||||
}
|
||||
}
|
||||
|
||||
// @ReactMethod
|
||||
// fun downloadFile(url: String, fileName: String, promise: Promise) {
|
||||
// val client = OkHttpClient()
|
||||
// val request = Request.Builder().url(url).build()
|
||||
|
||||
// try {
|
||||
// client.newCall(request).execute().use { response ->
|
||||
// if (!response.isSuccessful) throw IOException("Failed to download file: $response")
|
||||
|
||||
// // Use the app's internal files directory
|
||||
// val fileOutputStream = reactContext.openFileOutput(fileName, Context.MODE_PRIVATE)
|
||||
|
||||
// val inputStream = response.body?.byteStream()
|
||||
// inputStream.use { input ->
|
||||
// fileOutputStream.use { output ->
|
||||
// input?.copyTo(output)
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Resolve the promise with the file path
|
||||
// val file = File(reactContext.filesDir, fileName)
|
||||
// promise.resolve(file.absolutePath)
|
||||
// }
|
||||
// } catch (e: Exception) {
|
||||
// // Reject the promise if an exception occurs
|
||||
// promise.reject(e)
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
@ReactMethod
|
||||
// fun runProveAction(inputs: ReadableMap, zkeypath: String, promise: Promise) {
|
||||
fun runProveAction(inputs: ReadableMap, promise: Promise) {
|
||||
|
||||
BIN
app/android/app/src/main/jniLibs/arm64-v8a/libuniffi_mopro.so
Executable file
BIN
app/android/app/src/main/jniLibs/arm64-v8a/libuniffi_mopro.so
Executable file
Binary file not shown.
@@ -6,3 +6,5 @@ include ':react-native-passport-reader'
|
||||
project(':react-native-passport-reader').projectDir = new File(rootProject.projectDir, './react-native-passport-reader/android')
|
||||
include ':passportreader'
|
||||
project(':passportreader').projectDir = new File(rootProject.projectDir, './android-passport-reader/app')
|
||||
include ':react-native-fs'
|
||||
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
{"ProofOfPassport":"0xF3F619aB057E3978204Be68549f9D4a503EAa535","Groth16Verifier":"0x2dbaF682BEdC0159C2E04663dF83C803FEC95D82"}
|
||||
{"ProofOfPassport":"0x4057c43602e8D5162Adc1D81706C01F0b6215777","Groth16Verifier":"0xfd07b8bC044d697393d6FE11a7AD808440cDd4eD"}
|
||||
52
app/ios/MoproKit/.gitignore
vendored
52
app/ios/MoproKit/.gitignore
vendored
@@ -1,52 +0,0 @@
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# Xcode
|
||||
build/
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata/
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
|
||||
# Bundler
|
||||
.bundle
|
||||
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build
|
||||
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
|
||||
#
|
||||
# Note: if you ignore the Pods directory, make sure to uncomment
|
||||
# `pod install` in .travis.yml
|
||||
#
|
||||
# Pods/
|
||||
|
||||
# Xcode
|
||||
#
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
|
||||
# CocoaPods
|
||||
Podfile.lock
|
||||
Pods
|
||||
*.xcworkspace
|
||||
|
||||
# Ignore static libs
|
||||
*.a
|
||||
@@ -1,14 +0,0 @@
|
||||
# references:
|
||||
# * https://www.objc.io/issues/6-build-tools/travis-ci/
|
||||
# * https://github.com/supermarin/xcpretty#usage
|
||||
|
||||
osx_image: xcode7.3
|
||||
language: objective-c
|
||||
# cache: cocoapods
|
||||
# podfile: Example/Podfile
|
||||
# before_install:
|
||||
# - gem install cocoapods # Since Travis is not always on latest version
|
||||
# - pod install --project-directory=Example
|
||||
script:
|
||||
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/MoproKit.xcworkspace -scheme MoproKit-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
|
||||
- pod lib lint
|
||||
@@ -1,805 +0,0 @@
|
||||
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
import Foundation
|
||||
|
||||
// Depending on the consumer's build setup, the low-level FFI code
|
||||
// might be in a separate module, or it might be compiled inline into
|
||||
// this module. This is a bit of light hackery to work with both.
|
||||
#if canImport(moproFFI)
|
||||
import moproFFI
|
||||
#endif
|
||||
|
||||
fileprivate extension RustBuffer {
|
||||
// Allocate a new buffer, copying the contents of a `UInt8` array.
|
||||
init(bytes: [UInt8]) {
|
||||
let rbuf = bytes.withUnsafeBufferPointer { ptr in
|
||||
RustBuffer.from(ptr)
|
||||
}
|
||||
self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
|
||||
}
|
||||
|
||||
static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
|
||||
try! rustCall { ffi_mopro_ffi_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
|
||||
}
|
||||
|
||||
// Frees the buffer in place.
|
||||
// The buffer must not be used after this is called.
|
||||
func deallocate() {
|
||||
try! rustCall { ffi_mopro_ffi_rustbuffer_free(self, $0) }
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension ForeignBytes {
|
||||
init(bufferPointer: UnsafeBufferPointer<UInt8>) {
|
||||
self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
|
||||
}
|
||||
}
|
||||
|
||||
// For every type used in the interface, we provide helper methods for conveniently
|
||||
// lifting and lowering that type from C-compatible data, and for reading and writing
|
||||
// values of that type in a buffer.
|
||||
|
||||
// Helper classes/extensions that don't change.
|
||||
// Someday, this will be in a library of its own.
|
||||
|
||||
fileprivate extension Data {
|
||||
init(rustBuffer: RustBuffer) {
|
||||
// TODO: This copies the buffer. Can we read directly from a
|
||||
// Rust buffer?
|
||||
self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len))
|
||||
}
|
||||
}
|
||||
|
||||
// Define reader functionality. Normally this would be defined in a class or
|
||||
// struct, but we use standalone functions instead in order to make external
|
||||
// types work.
|
||||
//
|
||||
// With external types, one swift source file needs to be able to call the read
|
||||
// method on another source file's FfiConverter, but then what visibility
|
||||
// should Reader have?
|
||||
// - If Reader is fileprivate, then this means the read() must also
|
||||
// be fileprivate, which doesn't work with external types.
|
||||
// - If Reader is internal/public, we'll get compile errors since both source
|
||||
// files will try define the same type.
|
||||
//
|
||||
// Instead, the read() method and these helper functions input a tuple of data
|
||||
|
||||
fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
|
||||
(data: data, offset: 0)
|
||||
}
|
||||
|
||||
// Reads an integer at the current offset, in big-endian order, and advances
|
||||
// the offset on success. Throws if reading the integer would move the
|
||||
// offset past the end of the buffer.
|
||||
fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
|
||||
let range = reader.offset..<reader.offset + MemoryLayout<T>.size
|
||||
guard reader.data.count >= range.upperBound else {
|
||||
throw UniffiInternalError.bufferOverflow
|
||||
}
|
||||
if T.self == UInt8.self {
|
||||
let value = reader.data[reader.offset]
|
||||
reader.offset += 1
|
||||
return value as! T
|
||||
}
|
||||
var value: T = 0
|
||||
let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
|
||||
reader.offset = range.upperBound
|
||||
return value.bigEndian
|
||||
}
|
||||
|
||||
// Reads an arbitrary number of bytes, to be used to read
|
||||
// raw bytes, this is useful when lifting strings
|
||||
fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
|
||||
let range = reader.offset..<(reader.offset+count)
|
||||
guard reader.data.count >= range.upperBound else {
|
||||
throw UniffiInternalError.bufferOverflow
|
||||
}
|
||||
var value = [UInt8](repeating: 0, count: count)
|
||||
value.withUnsafeMutableBufferPointer({ buffer in
|
||||
reader.data.copyBytes(to: buffer, from: range)
|
||||
})
|
||||
reader.offset = range.upperBound
|
||||
return value
|
||||
}
|
||||
|
||||
// Reads a float at the current offset.
|
||||
fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
|
||||
return Float(bitPattern: try readInt(&reader))
|
||||
}
|
||||
|
||||
// Reads a float at the current offset.
|
||||
fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
|
||||
return Double(bitPattern: try readInt(&reader))
|
||||
}
|
||||
|
||||
// Indicates if the offset has reached the end of the buffer.
|
||||
fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
|
||||
return reader.offset < reader.data.count
|
||||
}
|
||||
|
||||
// Define writer functionality. Normally this would be defined in a class or
|
||||
// struct, but we use standalone functions instead in order to make external
|
||||
// types work. See the above discussion on Readers for details.
|
||||
|
||||
fileprivate func createWriter() -> [UInt8] {
|
||||
return []
|
||||
}
|
||||
|
||||
fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
|
||||
writer.append(contentsOf: byteArr)
|
||||
}
|
||||
|
||||
// Writes an integer in big-endian order.
|
||||
//
|
||||
// Warning: make sure what you are trying to write
|
||||
// is in the correct type!
|
||||
fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
|
||||
var value = value.bigEndian
|
||||
withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
|
||||
}
|
||||
|
||||
fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
|
||||
writeInt(&writer, value.bitPattern)
|
||||
}
|
||||
|
||||
fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
|
||||
writeInt(&writer, value.bitPattern)
|
||||
}
|
||||
|
||||
// Protocol for types that transfer other types across the FFI. This is
|
||||
// analogous go the Rust trait of the same name.
|
||||
fileprivate protocol FfiConverter {
|
||||
associatedtype FfiType
|
||||
associatedtype SwiftType
|
||||
|
||||
static func lift(_ value: FfiType) throws -> SwiftType
|
||||
static func lower(_ value: SwiftType) -> FfiType
|
||||
static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
|
||||
static func write(_ value: SwiftType, into buf: inout [UInt8])
|
||||
}
|
||||
|
||||
// Types conforming to `Primitive` pass themselves directly over the FFI.
|
||||
fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
|
||||
|
||||
extension FfiConverterPrimitive {
|
||||
public static func lift(_ value: FfiType) throws -> SwiftType {
|
||||
return value
|
||||
}
|
||||
|
||||
public static func lower(_ value: SwiftType) -> FfiType {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
|
||||
// Used for complex types where it's hard to write a custom lift/lower.
|
||||
fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
|
||||
|
||||
extension FfiConverterRustBuffer {
|
||||
public static func lift(_ buf: RustBuffer) throws -> SwiftType {
|
||||
var reader = createReader(data: Data(rustBuffer: buf))
|
||||
let value = try read(from: &reader)
|
||||
if hasRemaining(reader) {
|
||||
throw UniffiInternalError.incompleteData
|
||||
}
|
||||
buf.deallocate()
|
||||
return value
|
||||
}
|
||||
|
||||
public static func lower(_ value: SwiftType) -> RustBuffer {
|
||||
var writer = createWriter()
|
||||
write(value, into: &writer)
|
||||
return RustBuffer(bytes: writer)
|
||||
}
|
||||
}
|
||||
// An error type for FFI errors. These errors occur at the UniFFI level, not
|
||||
// the library level.
|
||||
fileprivate enum UniffiInternalError: LocalizedError {
|
||||
case bufferOverflow
|
||||
case incompleteData
|
||||
case unexpectedOptionalTag
|
||||
case unexpectedEnumCase
|
||||
case unexpectedNullPointer
|
||||
case unexpectedRustCallStatusCode
|
||||
case unexpectedRustCallError
|
||||
case unexpectedStaleHandle
|
||||
case rustPanic(_ message: String)
|
||||
|
||||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
|
||||
case .incompleteData: return "The buffer still has data after lifting its containing value"
|
||||
case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
|
||||
case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
|
||||
case .unexpectedNullPointer: return "Raw pointer value was null"
|
||||
case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
|
||||
case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
|
||||
case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
|
||||
case let .rustPanic(message): return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let CALL_SUCCESS: Int8 = 0
|
||||
fileprivate let CALL_ERROR: Int8 = 1
|
||||
fileprivate let CALL_PANIC: Int8 = 2
|
||||
fileprivate let CALL_CANCELLED: Int8 = 3
|
||||
|
||||
fileprivate extension RustCallStatus {
|
||||
init() {
|
||||
self.init(
|
||||
code: CALL_SUCCESS,
|
||||
errorBuf: RustBuffer.init(
|
||||
capacity: 0,
|
||||
len: 0,
|
||||
data: nil
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
||||
try makeRustCall(callback, errorHandler: nil)
|
||||
}
|
||||
|
||||
private func rustCallWithError<T>(
|
||||
_ errorHandler: @escaping (RustBuffer) throws -> Error,
|
||||
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
|
||||
try makeRustCall(callback, errorHandler: errorHandler)
|
||||
}
|
||||
|
||||
private func makeRustCall<T>(
|
||||
_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
|
||||
errorHandler: ((RustBuffer) throws -> Error)?
|
||||
) throws -> T {
|
||||
uniffiEnsureInitialized()
|
||||
var callStatus = RustCallStatus.init()
|
||||
let returnedVal = callback(&callStatus)
|
||||
try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
|
||||
return returnedVal
|
||||
}
|
||||
|
||||
private func uniffiCheckCallStatus(
|
||||
callStatus: RustCallStatus,
|
||||
errorHandler: ((RustBuffer) throws -> Error)?
|
||||
) throws {
|
||||
switch callStatus.code {
|
||||
case CALL_SUCCESS:
|
||||
return
|
||||
|
||||
case CALL_ERROR:
|
||||
if let errorHandler = errorHandler {
|
||||
throw try errorHandler(callStatus.errorBuf)
|
||||
} else {
|
||||
callStatus.errorBuf.deallocate()
|
||||
throw UniffiInternalError.unexpectedRustCallError
|
||||
}
|
||||
|
||||
case CALL_PANIC:
|
||||
// When the rust code sees a panic, it tries to construct a RustBuffer
|
||||
// with the message. But if that code panics, then it just sends back
|
||||
// an empty buffer.
|
||||
if callStatus.errorBuf.len > 0 {
|
||||
throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
|
||||
} else {
|
||||
callStatus.errorBuf.deallocate()
|
||||
throw UniffiInternalError.rustPanic("Rust panic")
|
||||
}
|
||||
|
||||
case CALL_CANCELLED:
|
||||
throw CancellationError()
|
||||
|
||||
default:
|
||||
throw UniffiInternalError.unexpectedRustCallStatusCode
|
||||
}
|
||||
}
|
||||
|
||||
// Public interface members begin here.
|
||||
|
||||
|
||||
fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
|
||||
typealias FfiType = UInt32
|
||||
typealias SwiftType = UInt32
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
|
||||
return try lift(readInt(&buf))
|
||||
}
|
||||
|
||||
public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
|
||||
writeInt(&buf, lower(value))
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct FfiConverterBool : FfiConverter {
|
||||
typealias FfiType = Int8
|
||||
typealias SwiftType = Bool
|
||||
|
||||
public static func lift(_ value: Int8) throws -> Bool {
|
||||
return value != 0
|
||||
}
|
||||
|
||||
public static func lower(_ value: Bool) -> Int8 {
|
||||
return value ? 1 : 0
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
|
||||
return try lift(readInt(&buf))
|
||||
}
|
||||
|
||||
public static func write(_ value: Bool, into buf: inout [UInt8]) {
|
||||
writeInt(&buf, lower(value))
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct FfiConverterString: FfiConverter {
|
||||
typealias SwiftType = String
|
||||
typealias FfiType = RustBuffer
|
||||
|
||||
public static func lift(_ value: RustBuffer) throws -> String {
|
||||
defer {
|
||||
value.deallocate()
|
||||
}
|
||||
if value.data == nil {
|
||||
return String()
|
||||
}
|
||||
let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
|
||||
return String(bytes: bytes, encoding: String.Encoding.utf8)!
|
||||
}
|
||||
|
||||
public static func lower(_ value: String) -> RustBuffer {
|
||||
return value.utf8CString.withUnsafeBufferPointer { ptr in
|
||||
// The swift string gives us int8_t, we want uint8_t.
|
||||
ptr.withMemoryRebound(to: UInt8.self) { ptr in
|
||||
// The swift string gives us a trailing null byte, we don't want it.
|
||||
let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
|
||||
return RustBuffer.from(buf)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
|
||||
let len: Int32 = try readInt(&buf)
|
||||
return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
|
||||
}
|
||||
|
||||
public static func write(_ value: String, into buf: inout [UInt8]) {
|
||||
let len = Int32(value.utf8.count)
|
||||
writeInt(&buf, len)
|
||||
writeBytes(&buf, value.utf8)
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct FfiConverterData: FfiConverterRustBuffer {
|
||||
typealias SwiftType = Data
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data {
|
||||
let len: Int32 = try readInt(&buf)
|
||||
return Data(try readBytes(&buf, count: Int(len)))
|
||||
}
|
||||
|
||||
public static func write(_ value: Data, into buf: inout [UInt8]) {
|
||||
let len = Int32(value.count)
|
||||
writeInt(&buf, len)
|
||||
writeBytes(&buf, value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public protocol MoproCircomProtocol {
|
||||
func generateProof(circuitInputs: [String: [String]]) throws -> GenerateProofResult
|
||||
func setup(wasmPath: String, r1csPath: String) throws -> SetupResult
|
||||
func verifyProof(proof: Data, publicInput: Data) throws -> Bool
|
||||
|
||||
}
|
||||
|
||||
public class MoproCircom: MoproCircomProtocol {
|
||||
fileprivate let pointer: UnsafeMutableRawPointer
|
||||
|
||||
// TODO: We'd like this to be `private` but for Swifty reasons,
|
||||
// we can't implement `FfiConverter` without making this `required` and we can't
|
||||
// make it `required` without making it `public`.
|
||||
required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
|
||||
self.pointer = pointer
|
||||
}
|
||||
public convenience init() {
|
||||
self.init(unsafeFromRawPointer: try! rustCall() {
|
||||
uniffi_mopro_ffi_fn_constructor_moprocircom_new($0)
|
||||
})
|
||||
}
|
||||
|
||||
deinit {
|
||||
try! rustCall { uniffi_mopro_ffi_fn_free_moprocircom(pointer, $0) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public func generateProof(circuitInputs: [String: [String]]) throws -> GenerateProofResult {
|
||||
return try FfiConverterTypeGenerateProofResult.lift(
|
||||
try
|
||||
rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_method_moprocircom_generate_proof(self.pointer,
|
||||
FfiConverterDictionaryStringSequenceString.lower(circuitInputs),$0
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func setup(wasmPath: String, r1csPath: String) throws -> SetupResult {
|
||||
return try FfiConverterTypeSetupResult.lift(
|
||||
try
|
||||
rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_method_moprocircom_setup(self.pointer,
|
||||
FfiConverterString.lower(wasmPath),
|
||||
FfiConverterString.lower(r1csPath),$0
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func verifyProof(proof: Data, publicInput: Data) throws -> Bool {
|
||||
return try FfiConverterBool.lift(
|
||||
try
|
||||
rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_method_moprocircom_verify_proof(self.pointer,
|
||||
FfiConverterData.lower(proof),
|
||||
FfiConverterData.lower(publicInput),$0
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public struct FfiConverterTypeMoproCircom: FfiConverter {
|
||||
typealias FfiType = UnsafeMutableRawPointer
|
||||
typealias SwiftType = MoproCircom
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MoproCircom {
|
||||
let v: UInt64 = try readInt(&buf)
|
||||
// The Rust code won't compile if a pointer won't fit in a UInt64.
|
||||
// We have to go via `UInt` because that's the thing that's the size of a pointer.
|
||||
let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
|
||||
if (ptr == nil) {
|
||||
throw UniffiInternalError.unexpectedNullPointer
|
||||
}
|
||||
return try lift(ptr!)
|
||||
}
|
||||
|
||||
public static func write(_ value: MoproCircom, into buf: inout [UInt8]) {
|
||||
// This fiddling is because `Int` is the thing that's the same size as a pointer.
|
||||
// The Rust code won't compile if a pointer won't fit in a `UInt64`.
|
||||
writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
|
||||
}
|
||||
|
||||
public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> MoproCircom {
|
||||
return MoproCircom(unsafeFromRawPointer: pointer)
|
||||
}
|
||||
|
||||
public static func lower(_ value: MoproCircom) -> UnsafeMutableRawPointer {
|
||||
return value.pointer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func FfiConverterTypeMoproCircom_lift(_ pointer: UnsafeMutableRawPointer) throws -> MoproCircom {
|
||||
return try FfiConverterTypeMoproCircom.lift(pointer)
|
||||
}
|
||||
|
||||
public func FfiConverterTypeMoproCircom_lower(_ value: MoproCircom) -> UnsafeMutableRawPointer {
|
||||
return FfiConverterTypeMoproCircom.lower(value)
|
||||
}
|
||||
|
||||
|
||||
public struct GenerateProofResult {
|
||||
public var proof: Data
|
||||
public var inputs: Data
|
||||
|
||||
// Default memberwise initializers are never public by default, so we
|
||||
// declare one manually.
|
||||
public init(proof: Data, inputs: Data) {
|
||||
self.proof = proof
|
||||
self.inputs = inputs
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension GenerateProofResult: Equatable, Hashable {
|
||||
public static func ==(lhs: GenerateProofResult, rhs: GenerateProofResult) -> Bool {
|
||||
if lhs.proof != rhs.proof {
|
||||
return false
|
||||
}
|
||||
if lhs.inputs != rhs.inputs {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(proof)
|
||||
hasher.combine(inputs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct FfiConverterTypeGenerateProofResult: FfiConverterRustBuffer {
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> GenerateProofResult {
|
||||
return try GenerateProofResult(
|
||||
proof: FfiConverterData.read(from: &buf),
|
||||
inputs: FfiConverterData.read(from: &buf)
|
||||
)
|
||||
}
|
||||
|
||||
public static func write(_ value: GenerateProofResult, into buf: inout [UInt8]) {
|
||||
FfiConverterData.write(value.proof, into: &buf)
|
||||
FfiConverterData.write(value.inputs, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func FfiConverterTypeGenerateProofResult_lift(_ buf: RustBuffer) throws -> GenerateProofResult {
|
||||
return try FfiConverterTypeGenerateProofResult.lift(buf)
|
||||
}
|
||||
|
||||
public func FfiConverterTypeGenerateProofResult_lower(_ value: GenerateProofResult) -> RustBuffer {
|
||||
return FfiConverterTypeGenerateProofResult.lower(value)
|
||||
}
|
||||
|
||||
|
||||
public struct SetupResult {
|
||||
public var provingKey: Data
|
||||
|
||||
// Default memberwise initializers are never public by default, so we
|
||||
// declare one manually.
|
||||
public init(provingKey: Data) {
|
||||
self.provingKey = provingKey
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension SetupResult: Equatable, Hashable {
|
||||
public static func ==(lhs: SetupResult, rhs: SetupResult) -> Bool {
|
||||
if lhs.provingKey != rhs.provingKey {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(provingKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct FfiConverterTypeSetupResult: FfiConverterRustBuffer {
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SetupResult {
|
||||
return try SetupResult(
|
||||
provingKey: FfiConverterData.read(from: &buf)
|
||||
)
|
||||
}
|
||||
|
||||
public static func write(_ value: SetupResult, into buf: inout [UInt8]) {
|
||||
FfiConverterData.write(value.provingKey, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func FfiConverterTypeSetupResult_lift(_ buf: RustBuffer) throws -> SetupResult {
|
||||
return try FfiConverterTypeSetupResult.lift(buf)
|
||||
}
|
||||
|
||||
public func FfiConverterTypeSetupResult_lower(_ value: SetupResult) -> RustBuffer {
|
||||
return FfiConverterTypeSetupResult.lower(value)
|
||||
}
|
||||
|
||||
public enum MoproError {
|
||||
|
||||
|
||||
|
||||
// Simple error enums only carry a message
|
||||
case CircomError(message: String)
|
||||
|
||||
|
||||
fileprivate static func uniffiErrorHandler(_ error: RustBuffer) throws -> Error {
|
||||
return try FfiConverterTypeMoproError.lift(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public struct FfiConverterTypeMoproError: FfiConverterRustBuffer {
|
||||
typealias SwiftType = MoproError
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MoproError {
|
||||
let variant: Int32 = try readInt(&buf)
|
||||
switch variant {
|
||||
|
||||
|
||||
|
||||
|
||||
case 1: return .CircomError(
|
||||
message: try FfiConverterString.read(from: &buf)
|
||||
)
|
||||
|
||||
|
||||
default: throw UniffiInternalError.unexpectedEnumCase
|
||||
}
|
||||
}
|
||||
|
||||
public static func write(_ value: MoproError, into buf: inout [UInt8]) {
|
||||
switch value {
|
||||
|
||||
|
||||
|
||||
|
||||
case .CircomError(_ /* message is ignored*/):
|
||||
writeInt(&buf, Int32(1))
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension MoproError: Equatable, Hashable {}
|
||||
|
||||
extension MoproError: Error { }
|
||||
|
||||
fileprivate struct FfiConverterSequenceString: FfiConverterRustBuffer {
|
||||
typealias SwiftType = [String]
|
||||
|
||||
public static func write(_ value: [String], into buf: inout [UInt8]) {
|
||||
let len = Int32(value.count)
|
||||
writeInt(&buf, len)
|
||||
for item in value {
|
||||
FfiConverterString.write(item, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String] {
|
||||
let len: Int32 = try readInt(&buf)
|
||||
var seq = [String]()
|
||||
seq.reserveCapacity(Int(len))
|
||||
for _ in 0 ..< len {
|
||||
seq.append(try FfiConverterString.read(from: &buf))
|
||||
}
|
||||
return seq
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate struct FfiConverterDictionaryStringSequenceString: FfiConverterRustBuffer {
|
||||
public static func write(_ value: [String: [String]], into buf: inout [UInt8]) {
|
||||
let len = Int32(value.count)
|
||||
writeInt(&buf, len)
|
||||
for (key, value) in value {
|
||||
FfiConverterString.write(key, into: &buf)
|
||||
FfiConverterSequenceString.write(value, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: [String]] {
|
||||
let len: Int32 = try readInt(&buf)
|
||||
var dict = [String: [String]]()
|
||||
dict.reserveCapacity(Int(len))
|
||||
for _ in 0..<len {
|
||||
let key = try FfiConverterString.read(from: &buf)
|
||||
let value = try FfiConverterSequenceString.read(from: &buf)
|
||||
dict[key] = value
|
||||
}
|
||||
return dict
|
||||
}
|
||||
}
|
||||
|
||||
public func add(a: UInt32, b: UInt32) -> UInt32 {
|
||||
return try! FfiConverterUInt32.lift(
|
||||
try! rustCall() {
|
||||
uniffi_mopro_ffi_fn_func_add(
|
||||
FfiConverterUInt32.lower(a),
|
||||
FfiConverterUInt32.lower(b),$0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func generateProof2(circuitInputs: [String: [String]]) throws -> GenerateProofResult {
|
||||
return try FfiConverterTypeGenerateProofResult.lift(
|
||||
try rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_func_generate_proof2(
|
||||
FfiConverterDictionaryStringSequenceString.lower(circuitInputs),$0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func hello() -> String {
|
||||
return try! FfiConverterString.lift(
|
||||
try! rustCall() {
|
||||
uniffi_mopro_ffi_fn_func_hello($0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func initializeMopro() throws {
|
||||
try rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_func_initialize_mopro($0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public func initializeMoproDylib(dylibPath: String) throws {
|
||||
try rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_func_initialize_mopro_dylib(
|
||||
FfiConverterString.lower(dylibPath),$0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public func verifyProof2(proof: Data, publicInput: Data) throws -> Bool {
|
||||
return try FfiConverterBool.lift(
|
||||
try rustCallWithError(FfiConverterTypeMoproError.lift) {
|
||||
uniffi_mopro_ffi_fn_func_verify_proof2(
|
||||
FfiConverterData.lower(proof),
|
||||
FfiConverterData.lower(publicInput),$0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private enum InitializationResult {
|
||||
case ok
|
||||
case contractVersionMismatch
|
||||
case apiChecksumMismatch
|
||||
}
|
||||
// Use a global variables to perform the versioning checks. Swift ensures that
|
||||
// the code inside is only computed once.
|
||||
private var initializationResult: InitializationResult {
|
||||
// Get the bindings contract version from our ComponentInterface
|
||||
let bindings_contract_version = 24
|
||||
// Get the scaffolding contract version by calling the into the dylib
|
||||
let scaffolding_contract_version = ffi_mopro_ffi_uniffi_contract_version()
|
||||
if bindings_contract_version != scaffolding_contract_version {
|
||||
return InitializationResult.contractVersionMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_add() != 8411) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_generate_proof2() != 40187) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_hello() != 46136) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_initialize_mopro() != 17540) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_initialize_mopro_dylib() != 64476) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_func_verify_proof2() != 37192) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_method_moprocircom_generate_proof() != 64602) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_method_moprocircom_setup() != 57700) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_method_moprocircom_verify_proof() != 61522) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_mopro_ffi_checksum_constructor_moprocircom_new() != 42205) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
|
||||
return InitializationResult.ok
|
||||
}
|
||||
|
||||
private func uniffiEnsureInitialized() {
|
||||
switch initializationResult {
|
||||
case .ok:
|
||||
break
|
||||
case .contractVersionMismatch:
|
||||
fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
|
||||
case .apiChecksumMismatch:
|
||||
fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||
}
|
||||
}
|
||||
@@ -1,670 +0,0 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
2A418AB02AF4B1200004B747 /* CircomUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A418AAF2AF4B1200004B747 /* CircomUITests.swift */; };
|
||||
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6E5BAE2AF499460052A601 /* CircomTests.swift */; };
|
||||
4384FD09A96F702A375841EE /* Pods_MoproKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */; };
|
||||
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
|
||||
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
|
||||
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
|
||||
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
|
||||
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
|
||||
7A38AEC233A3880A843B0133 /* Pods_MoproKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8BE5A40EAC7D019B9C7566CA /* Pods_MoproKit_Example.framework */; };
|
||||
CE2C1B8C2AFFCC5E002AF8BC /* main.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */; };
|
||||
CE2C1B8D2AFFCC5E002AF8BC /* main.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */; };
|
||||
CE5A5C062AD43A790074539D /* keccak256_256_test.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */; };
|
||||
CE5A5C072AD43A790074539D /* keccak256_256_test.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */; };
|
||||
CE5A5C092AD43A860074539D /* keccak256_256_test.r1cs in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */; };
|
||||
CE5A5C0A2AD43A860074539D /* keccak256_256_test.r1cs in Resources */ = {isa = PBXBuildFile; fileRef = CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */; };
|
||||
CEA2D12F2AB96A7A00F292D2 /* multiplier2.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */; };
|
||||
CEA2D1302AB96A7A00F292D2 /* multiplier2.wasm in Resources */ = {isa = PBXBuildFile; fileRef = CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */; };
|
||||
CEA2D1322AB96AB500F292D2 /* multiplier2.r1cs in Resources */ = {isa = PBXBuildFile; fileRef = CEA2D1312AB96AB500F292D2 /* multiplier2.r1cs */; };
|
||||
CEA2D1332AB96AB500F292D2 /* multiplier2.r1cs in Resources */ = {isa = PBXBuildFile; fileRef = CEA2D1312AB96AB500F292D2 /* multiplier2.r1cs */; };
|
||||
CEB804502AFF81960063F091 /* KeccakSetupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB8044F2AFF81960063F091 /* KeccakSetupViewController.swift */; };
|
||||
CEB804562AFF81AF0063F091 /* KeccakZkeyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB804552AFF81AF0063F091 /* KeccakZkeyViewController.swift */; };
|
||||
CEB804582AFF81BF0063F091 /* RSAViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEB804572AFF81BF0063F091 /* RSAViewController.swift */; };
|
||||
E69338642AFFDB1A00B80312 /* AnonAadhaarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E69338632AFFDB1A00B80312 /* AnonAadhaarViewController.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 607FACC81AFB9204008FA782 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 607FACCF1AFB9204008FA782;
|
||||
remoteInfo = MoproKit;
|
||||
};
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
1E5E014D70B48C9A59F14658 /* Pods-MoproKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Example.release.xcconfig"; path = "Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example.release.xcconfig"; sourceTree = "<group>"; };
|
||||
2A418AAF2AF4B1200004B747 /* CircomUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomUITests.swift; sourceTree = "<group>"; };
|
||||
2A6E5BAE2AF499460052A601 /* CircomTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomTests.swift; sourceTree = "<group>"; };
|
||||
47F8ADB0AC4168C6E874818D /* MoproKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MoproKit.podspec; path = ../MoproKit.podspec; sourceTree = "<group>"; };
|
||||
5DAF212A114DFA0C9F4282B2 /* Pods-MoproKit_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Tests.debug.xcconfig"; path = "Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
607FACD01AFB9204008FA782 /* MoproKit_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MoproKit_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
|
||||
607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
|
||||
607FACE51AFB9204008FA782 /* MoproKit_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MoproKit_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MoproKit_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
8BE5A40EAC7D019B9C7566CA /* Pods_MoproKit_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MoproKit_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
90EAF1BEF8AD3C193665DBED /* Pods-MoproKit_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Tests.release.xcconfig"; path = "Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
92580ABC3B6DBAD1A9544456 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
|
||||
B4016A34BBB20BC381CCFC2D /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
|
||||
C61628A63419B5C140B24AF7 /* Pods-MoproKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Example.debug.xcconfig"; path = "Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = main.wasm; path = "../../../../../mopro-core/examples/circom/rsa/target/main_js/main.wasm"; sourceTree = "<group>"; };
|
||||
CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test.wasm; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm"; sourceTree = "<group>"; };
|
||||
CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */ = {isa = PBXFileReference; lastKnownFileType = file; name = keccak256_256_test.r1cs; path = "../../../../../mopro-core/examples/circom/keccak256/target/keccak256_256_test.r1cs"; sourceTree = "<group>"; };
|
||||
CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */ = {isa = PBXFileReference; lastKnownFileType = file; name = multiplier2.wasm; path = "../../../../../mopro-core/examples/circom/multiplier2/target/multiplier2_js/multiplier2.wasm"; sourceTree = "<group>"; };
|
||||
CEA2D1312AB96AB500F292D2 /* multiplier2.r1cs */ = {isa = PBXFileReference; lastKnownFileType = file; name = multiplier2.r1cs; path = "../../../../../mopro-core/examples/circom/multiplier2/target/multiplier2.r1cs"; sourceTree = "<group>"; };
|
||||
CEB8044F2AFF81960063F091 /* KeccakSetupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeccakSetupViewController.swift; sourceTree = "<group>"; };
|
||||
CEB804552AFF81AF0063F091 /* KeccakZkeyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeccakZkeyViewController.swift; sourceTree = "<group>"; };
|
||||
CEB804572AFF81BF0063F091 /* RSAViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RSAViewController.swift; sourceTree = "<group>"; };
|
||||
E69338632AFFDB1A00B80312 /* AnonAadhaarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnonAadhaarViewController.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
607FACCD1AFB9204008FA782 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7A38AEC233A3880A843B0133 /* Pods_MoproKit_Example.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
607FACE21AFB9204008FA782 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4384FD09A96F702A375841EE /* Pods_MoproKit_Tests.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
164B820D208F5EFE221D6A86 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8BE5A40EAC7D019B9C7566CA /* Pods_MoproKit_Example.framework */,
|
||||
78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACC71AFB9204008FA782 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
607FACF51AFB993E008FA782 /* Podspec Metadata */,
|
||||
607FACD21AFB9204008FA782 /* Example for MoproKit */,
|
||||
607FACE81AFB9204008FA782 /* Tests */,
|
||||
607FACD11AFB9204008FA782 /* Products */,
|
||||
EEB809FA0FFBEC7559BC7169 /* Pods */,
|
||||
164B820D208F5EFE221D6A86 /* Frameworks */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACD11AFB9204008FA782 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
607FACD01AFB9204008FA782 /* MoproKit_Example.app */,
|
||||
607FACE51AFB9204008FA782 /* MoproKit_Tests.xctest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACD21AFB9204008FA782 /* Example for MoproKit */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CEB804572AFF81BF0063F091 /* RSAViewController.swift */,
|
||||
E69338632AFFDB1A00B80312 /* AnonAadhaarViewController.swift */,
|
||||
CEB804552AFF81AF0063F091 /* KeccakZkeyViewController.swift */,
|
||||
CEB8044F2AFF81960063F091 /* KeccakSetupViewController.swift */,
|
||||
CEA2D1282AB9681E00F292D2 /* Resources */,
|
||||
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
|
||||
607FACD71AFB9204008FA782 /* ViewController.swift */,
|
||||
607FACD91AFB9204008FA782 /* Main.storyboard */,
|
||||
607FACDC1AFB9204008FA782 /* Images.xcassets */,
|
||||
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
|
||||
607FACD31AFB9204008FA782 /* Supporting Files */,
|
||||
);
|
||||
name = "Example for MoproKit";
|
||||
path = MoproKit;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACD31AFB9204008FA782 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
607FACD41AFB9204008FA782 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACE81AFB9204008FA782 /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2A418AAF2AF4B1200004B747 /* CircomUITests.swift */,
|
||||
607FACE91AFB9204008FA782 /* Supporting Files */,
|
||||
2A6E5BAE2AF499460052A601 /* CircomTests.swift */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACE91AFB9204008FA782 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
607FACEA1AFB9204008FA782 /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACF51AFB993E008FA782 /* Podspec Metadata */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
47F8ADB0AC4168C6E874818D /* MoproKit.podspec */,
|
||||
B4016A34BBB20BC381CCFC2D /* README.md */,
|
||||
92580ABC3B6DBAD1A9544456 /* LICENSE */,
|
||||
);
|
||||
name = "Podspec Metadata";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
CEA2D1282AB9681E00F292D2 /* Resources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CE2C1B8B2AFFCC5E002AF8BC /* main.wasm */,
|
||||
CE5A5C082AD43A860074539D /* keccak256_256_test.r1cs */,
|
||||
CE5A5C052AD43A790074539D /* keccak256_256_test.wasm */,
|
||||
CEA2D12E2AB96A7A00F292D2 /* multiplier2.wasm */,
|
||||
CEA2D1312AB96AB500F292D2 /* multiplier2.r1cs */,
|
||||
);
|
||||
path = Resources;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
EEB809FA0FFBEC7559BC7169 /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C61628A63419B5C140B24AF7 /* Pods-MoproKit_Example.debug.xcconfig */,
|
||||
1E5E014D70B48C9A59F14658 /* Pods-MoproKit_Example.release.xcconfig */,
|
||||
5DAF212A114DFA0C9F4282B2 /* Pods-MoproKit_Tests.debug.xcconfig */,
|
||||
90EAF1BEF8AD3C193665DBED /* Pods-MoproKit_Tests.release.xcconfig */,
|
||||
);
|
||||
path = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
607FACCF1AFB9204008FA782 /* MoproKit_Example */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "MoproKit_Example" */;
|
||||
buildPhases = (
|
||||
C880BC635097821F74482E9F /* [CP] Check Pods Manifest.lock */,
|
||||
607FACCC1AFB9204008FA782 /* Sources */,
|
||||
607FACCD1AFB9204008FA782 /* Frameworks */,
|
||||
607FACCE1AFB9204008FA782 /* Resources */,
|
||||
AE90EE4FFCA95237FBC047A3 /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = MoproKit_Example;
|
||||
productName = MoproKit;
|
||||
productReference = 607FACD01AFB9204008FA782 /* MoproKit_Example.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
607FACE41AFB9204008FA782 /* MoproKit_Tests */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "MoproKit_Tests" */;
|
||||
buildPhases = (
|
||||
2A673A4155C4EBC1B609897B /* [CP] Check Pods Manifest.lock */,
|
||||
607FACE11AFB9204008FA782 /* Sources */,
|
||||
607FACE21AFB9204008FA782 /* Frameworks */,
|
||||
607FACE31AFB9204008FA782 /* Resources */,
|
||||
2B1BB55A83D0E5B7D03D5DA0 /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
607FACE71AFB9204008FA782 /* PBXTargetDependency */,
|
||||
);
|
||||
name = MoproKit_Tests;
|
||||
productName = Tests;
|
||||
productReference = 607FACE51AFB9204008FA782 /* MoproKit_Tests.xctest */;
|
||||
productType = "com.apple.product-type.bundle.unit-test";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
607FACC81AFB9204008FA782 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 0830;
|
||||
LastUpgradeCheck = 0830;
|
||||
ORGANIZATIONNAME = CocoaPods;
|
||||
TargetAttributes = {
|
||||
607FACCF1AFB9204008FA782 = {
|
||||
CreatedOnToolsVersion = 6.3.1;
|
||||
DevelopmentTeam = 5B29R5LYHQ;
|
||||
LastSwiftMigration = 0900;
|
||||
};
|
||||
607FACE41AFB9204008FA782 = {
|
||||
CreatedOnToolsVersion = 6.3.1;
|
||||
DevelopmentTeam = 5B29R5LYHQ;
|
||||
LastSwiftMigration = 0900;
|
||||
TestTargetID = 607FACCF1AFB9204008FA782;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "MoproKit" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
English,
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 607FACC71AFB9204008FA782;
|
||||
productRefGroup = 607FACD11AFB9204008FA782 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
607FACCF1AFB9204008FA782 /* MoproKit_Example */,
|
||||
607FACE41AFB9204008FA782 /* MoproKit_Tests */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
607FACCE1AFB9204008FA782 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
CEA2D1322AB96AB500F292D2 /* multiplier2.r1cs in Resources */,
|
||||
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
|
||||
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
|
||||
CE5A5C062AD43A790074539D /* keccak256_256_test.wasm in Resources */,
|
||||
CE2C1B8C2AFFCC5E002AF8BC /* main.wasm in Resources */,
|
||||
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
|
||||
CEA2D12F2AB96A7A00F292D2 /* multiplier2.wasm in Resources */,
|
||||
CE5A5C092AD43A860074539D /* keccak256_256_test.r1cs in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
607FACE31AFB9204008FA782 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
CE5A5C0A2AD43A860074539D /* keccak256_256_test.r1cs in Resources */,
|
||||
CE5A5C072AD43A790074539D /* keccak256_256_test.wasm in Resources */,
|
||||
CE2C1B8D2AFFCC5E002AF8BC /* main.wasm in Resources */,
|
||||
CEA2D1332AB96AB500F292D2 /* multiplier2.r1cs in Resources */,
|
||||
CEA2D1302AB96A7A00F292D2 /* multiplier2.wasm in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXShellScriptBuildPhase section */
|
||||
2A673A4155C4EBC1B609897B /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-MoproKit_Tests-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
2B1BB55A83D0E5B7D03D5DA0 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests-frameworks.sh",
|
||||
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MoproKit_Tests/Pods-MoproKit_Tests-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
AE90EE4FFCA95237FBC047A3 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example-frameworks.sh",
|
||||
"${BUILT_PRODUCTS_DIR}/MoproKit/MoproKit.framework",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputPaths = (
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MoproKit.framework",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
C880BC635097821F74482E9F /* [CP] Check Pods Manifest.lock */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
);
|
||||
inputPaths = (
|
||||
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
|
||||
"${PODS_ROOT}/Manifest.lock",
|
||||
);
|
||||
name = "[CP] Check Pods Manifest.lock";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
"$(DERIVED_FILE_DIR)/Pods-MoproKit_Example-checkManifestLockResult.txt",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
607FACCC1AFB9204008FA782 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
CEB804582AFF81BF0063F091 /* RSAViewController.swift in Sources */,
|
||||
CEB804562AFF81AF0063F091 /* KeccakZkeyViewController.swift in Sources */,
|
||||
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
|
||||
CEB804502AFF81960063F091 /* KeccakSetupViewController.swift in Sources */,
|
||||
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
|
||||
E69338642AFFDB1A00B80312 /* AnonAadhaarViewController.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
607FACE11AFB9204008FA782 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */,
|
||||
2A418AB02AF4B1200004B747 /* CircomUITests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
607FACE71AFB9204008FA782 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 607FACCF1AFB9204008FA782 /* MoproKit_Example */;
|
||||
targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */;
|
||||
};
|
||||
/* End PBXTargetDependency section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
607FACD91AFB9204008FA782 /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
607FACDA1AFB9204008FA782 /* Base */,
|
||||
);
|
||||
name = Main.storyboard;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
607FACDF1AFB9204008FA782 /* Base */,
|
||||
);
|
||||
name = LaunchScreen.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
607FACED1AFB9204008FA782 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
607FACEE1AFB9204008FA782 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
607FACF01AFB9204008FA782 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = C61628A63419B5C140B24AF7 /* Pods-MoproKit_Example.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
INFOPLIST_FILE = MoproKit/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
MODULE_NAME = ExampleApp;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mopro.examples;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
607FACF11AFB9204008FA782 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 1E5E014D70B48C9A59F14658 /* Pods-MoproKit_Example.release.xcconfig */;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
INFOPLIST_FILE = MoproKit/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
MODULE_NAME = ExampleApp;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mopro.examples;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
607FACF31AFB9204008FA782 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 5DAF212A114DFA0C9F4282B2 /* Pods-MoproKit_Tests.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MoproKit_Example.app/MoproKit_Example";
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mopro.examples.test;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MoproKit_Example.app/MoproKit_Example";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
607FACF41AFB9204008FA782 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = 90EAF1BEF8AD3C193665DBED /* Pods-MoproKit_Tests.release.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/MoproKit_Example.app/MoproKit_Example";
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
|
||||
"$(inherited)",
|
||||
);
|
||||
INFOPLIST_FILE = Tests/Info.plist;
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.mopro.examples.test;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
SWIFT_VERSION = 4.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MoproKit_Example.app/MoproKit_Example";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "MoproKit" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
607FACED1AFB9204008FA782 /* Debug */,
|
||||
607FACEE1AFB9204008FA782 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "MoproKit_Example" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
607FACF01AFB9204008FA782 /* Debug */,
|
||||
607FACF11AFB9204008FA782 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "MoproKit_Tests" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
607FACF31AFB9204008FA782 /* Debug */,
|
||||
607FACF41AFB9204008FA782 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 607FACC81AFB9204008FA782 /* Project object */;
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0900"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Example.app"
|
||||
BlueprintName = "MoproKit_Example"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACE41AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Tests.xctest"
|
||||
BlueprintName = "MoproKit_Tests"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
codeCoverageEnabled = "YES"
|
||||
onlyGenerateCoverageForSpecifiedTargets = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Example.app"
|
||||
BlueprintName = "MoproKit_Example"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
<CodeCoverageTargets>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Example.app"
|
||||
BlueprintName = "MoproKit_Example"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "37729DE650F35D13EA7BF03F8E697892"
|
||||
BuildableName = "MoproKit.framework"
|
||||
BlueprintName = "MoproKit"
|
||||
ReferencedContainer = "container:Pods/Pods.xcodeproj">
|
||||
</BuildableReference>
|
||||
</CodeCoverageTargets>
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACE41AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Tests.xctest"
|
||||
BlueprintName = "MoproKit_Tests"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Example.app"
|
||||
BlueprintName = "MoproKit_Example"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
|
||||
BuildableName = "MoproKit_Example.app"
|
||||
BlueprintName = "MoproKit_Example"
|
||||
ReferencedContainer = "container:MoproKit.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -1,192 +0,0 @@
|
||||
//
|
||||
// AnonAadhaarViewController.swift
|
||||
// MoproKit_Example
|
||||
//
|
||||
// Created by Yanis Meziane on 11/11/2023.
|
||||
// Copyright © 2023 CocoaPods. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import WebKit
|
||||
import MoproKit
|
||||
|
||||
class AnonAadhaarViewController: UIViewController, WKScriptMessageHandler, WKNavigationDelegate {
|
||||
let webView = WKWebView()
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
//var setupResult: SetupResult?
|
||||
var generatedProof: Data?
|
||||
var publicInputs: Data?
|
||||
let containerView = UIView()
|
||||
var textView = UITextView()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
runInitAction()
|
||||
setupUI()
|
||||
|
||||
let contentController = WKUserContentController()
|
||||
contentController.add(self, name: "startProvingHandler")
|
||||
contentController.add(self, name: "messageHandler")
|
||||
|
||||
let configuration = WKWebViewConfiguration()
|
||||
configuration.userContentController = contentController
|
||||
configuration.preferences.javaScriptEnabled = true
|
||||
|
||||
// Assign the configuration to the WKWebView
|
||||
let webView = WKWebView(frame: view.bounds, configuration: configuration)
|
||||
webView.navigationDelegate = self
|
||||
|
||||
view.addSubview(webView)
|
||||
view.addSubview(textView)
|
||||
|
||||
guard let url = URL(string: "https://webview-anon-adhaar.vercel.app/") else { return }
|
||||
webView.load(URLRequest(url: url))
|
||||
}
|
||||
|
||||
func setupUI() {
|
||||
textView.isEditable = false
|
||||
|
||||
textView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(textView)
|
||||
|
||||
// Make text view visible
|
||||
textView.heightAnchor.constraint(equalToConstant: 200).isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
|
||||
textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
|
||||
textView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20)
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
|
||||
@objc func runInitAction() {
|
||||
// Update the textView on the main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "Initializing library\n"
|
||||
}
|
||||
|
||||
// Execute long-running tasks in the background
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
do {
|
||||
try initializeMopro()
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Again, update the UI on the main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n"
|
||||
}
|
||||
} catch {
|
||||
// Handle errors - update UI on main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "An error occurred during initialization: \(error)\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runProveAction(inputs: [String: [String]]) {
|
||||
// Logic for prove (generate_proof2)
|
||||
do {
|
||||
textView.text += "Starts proving...\n"
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try generateProof2(circuitInputs: inputs)
|
||||
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
//assert(Data(expectedOutput) == generateProofResult.inputs, "Circuit outputs mismatch the expected outputs")
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Store the generated proof and public inputs for later verification
|
||||
generatedProof = generateProofResult.proof
|
||||
publicInputs = generateProofResult.inputs
|
||||
|
||||
print("Proof generation took \(timeTaken) seconds.\n")
|
||||
|
||||
textView.text += "Proof generated!!! \n"
|
||||
textView.text += "Proof generation took \(timeTaken) seconds.\n"
|
||||
textView.text += "---\n"
|
||||
runVerifyAction()
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
override func viewDidLayoutSubviews() {
|
||||
super.viewDidLayoutSubviews()
|
||||
webView.frame = view.bounds
|
||||
}
|
||||
|
||||
struct Witness {
|
||||
let signature: [String]
|
||||
let modulus: [String]
|
||||
let base_message: [String]
|
||||
}
|
||||
|
||||
// Implement WKScriptMessageHandler method
|
||||
func provingContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == "messageHandler" {
|
||||
// Handle messages for "messageHandler"
|
||||
print("Received message from JavaScript:", message.body)
|
||||
}
|
||||
}
|
||||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == "startProvingHandler", let data = message.body as? [String: Any] {
|
||||
// Check for the "witness" key in the received data
|
||||
if let witnessData = data["witness"] as? [String: [String]] {
|
||||
if let signature = witnessData["signature"],
|
||||
let modulus = witnessData["modulus"],
|
||||
let baseMessage = witnessData["base_message"] {
|
||||
|
||||
let inputs: [String: [String]] = [
|
||||
"signature": signature,
|
||||
"modulus": modulus,
|
||||
"base_message": baseMessage
|
||||
]
|
||||
|
||||
// Call your Swift function with the received witness data
|
||||
runProveAction(inputs: inputs)
|
||||
}
|
||||
} else if let error = data["error"] as? String {
|
||||
// Handle error data
|
||||
print("Received error value from JavaScript:", error)
|
||||
} else {
|
||||
print("No valid data keys found in the message data.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runVerifyAction() {
|
||||
// Logic for verify
|
||||
guard let proof = generatedProof,
|
||||
let publicInputs = publicInputs else {
|
||||
print("Proof has not been generated yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Verify Proof
|
||||
let isValid = try verifyProof2(proof: proof, publicInput: publicInputs)
|
||||
assert(isValid, "Proof verification should succeed")
|
||||
|
||||
textView.text += "Proof verification succeeded.\n"
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// MoproKit
|
||||
//
|
||||
// Created by 1552237 on 09/16/2023.
|
||||
// Copyright (c) 2023 1552237. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@UIApplicationMain
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
|
||||
window = UIWindow(frame: UIScreen.main.bounds)
|
||||
let viewController = ViewController()
|
||||
let navigationController = UINavigationController(rootViewController: viewController)
|
||||
window?.rootViewController = navigationController
|
||||
window?.makeKeyAndVisible()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="iN0-l3-epB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 CocoaPods. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
|
||||
<rect key="frame" x="20" y="439" width="441" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="MoproKit" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
|
||||
<rect key="frame" x="20" y="140" width="441" height="43"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
|
||||
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
|
||||
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
|
||||
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
|
||||
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
|
||||
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="548" y="455"/>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="ufC-wZ-h7g">
|
||||
<objects>
|
||||
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="MoproKit_Example" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
|
||||
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
||||
@@ -1,53 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "20x20",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "29x29",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "40x40",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "iphone",
|
||||
"size" : "60x60",
|
||||
"scale" : "3x"
|
||||
},
|
||||
{
|
||||
"idiom" : "ios-marketing",
|
||||
"size" : "1024x1024",
|
||||
"scale" : "1x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,186 +0,0 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// MoproKit
|
||||
//
|
||||
// Created by 1552237 on 09/16/2023.
|
||||
// Copyright (c) 2023 1552237. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MoproKit
|
||||
|
||||
class KeccakSetupViewController: UIViewController {
|
||||
|
||||
var setupButton = UIButton(type: .system)
|
||||
var proveButton = UIButton(type: .system)
|
||||
var verifyButton = UIButton(type: .system)
|
||||
var textView = UITextView()
|
||||
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
var setupResult: SetupResult?
|
||||
var generatedProof: Data?
|
||||
var publicInputs: Data?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Set title
|
||||
let title = UILabel()
|
||||
title.text = "Keccak256 (setup)"
|
||||
title.textColor = .white
|
||||
title.textAlignment = .center
|
||||
navigationItem.titleView = title
|
||||
navigationController?.navigationBar.isHidden = false
|
||||
navigationController?.navigationBar.prefersLargeTitles = true
|
||||
|
||||
// view.backgroundColor = .white
|
||||
// navigationController?.navigationBar.prefersLargeTitles = true
|
||||
// navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
|
||||
// navigationController?.navigationBar.barTintColor = UIColor.white // or any other contrasting color
|
||||
// self.title = "Keccak256 (setup)"
|
||||
|
||||
setupUI()
|
||||
}
|
||||
|
||||
func setupUI() {
|
||||
setupButton.setTitle("Setup", for: .normal)
|
||||
proveButton.setTitle("Prove", for: .normal)
|
||||
verifyButton.setTitle("Verify", for: .normal)
|
||||
|
||||
textView.isEditable = false
|
||||
|
||||
//self.title = "Keccak256 (setup)"
|
||||
//view.backgroundColor = .black
|
||||
|
||||
// Setup actions for buttons
|
||||
setupButton.addTarget(self, action: #selector(runSetupAction), for: .touchUpInside)
|
||||
proveButton.addTarget(self, action: #selector(runProveAction), for: .touchUpInside)
|
||||
verifyButton.addTarget(self, action: #selector(runVerifyAction), for: .touchUpInside)
|
||||
|
||||
setupButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [setupButton, proveButton, verifyButton, textView])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 10
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stackView)
|
||||
|
||||
// Make text view visible
|
||||
textView.heightAnchor.constraint(equalToConstant: 200).isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
|
||||
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
|
||||
])
|
||||
}
|
||||
|
||||
@objc func runSetupAction() {
|
||||
// Logic for setup
|
||||
if let wasmPath = Bundle.main.path(forResource: "keccak256_256_test", ofType: "wasm"),
|
||||
let r1csPath = Bundle.main.path(forResource: "keccak256_256_test", ofType: "r1cs") {
|
||||
|
||||
// Multiplier example
|
||||
// if let wasmPath = Bundle.main.path(forResource: "multiplier2", ofType: "wasm"),
|
||||
// let r1csPath = Bundle.main.path(forResource: "multiplier2", ofType: "r1cs") {
|
||||
|
||||
do {
|
||||
setupResult = try moproCircom.setup(wasmPath: wasmPath, r1csPath: r1csPath)
|
||||
proveButton.isEnabled = true // Enable the Prove button upon successful setup
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
} else {
|
||||
print("Error getting paths for resources")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runProveAction() {
|
||||
// Logic for prove
|
||||
guard let setupResult = setupResult else {
|
||||
print("Setup is not completed yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Prepare inputs
|
||||
let inputVec: [UInt8] = [
|
||||
116, 101, 115, 116, 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,
|
||||
]
|
||||
let bits = bytesToBits(bytes: inputVec)
|
||||
var inputs = [String: [String]]()
|
||||
inputs["in"] = bits
|
||||
|
||||
// Multiplier example
|
||||
// var inputs = [String: [String]]()
|
||||
// let a = 3
|
||||
// let b = 5
|
||||
// inputs["a"] = [String(a)]
|
||||
// inputs["b"] = [String(b)]
|
||||
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs)
|
||||
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Store the generated proof and public inputs for later verification
|
||||
generatedProof = generateProofResult.proof
|
||||
publicInputs = generateProofResult.inputs
|
||||
|
||||
textView.text += "Proof generation took \(timeTaken) seconds.\n"
|
||||
verifyButton.isEnabled = true // Enable the Verify button once proof has been generated
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runVerifyAction() {
|
||||
// Logic for verify
|
||||
guard let setupResult = setupResult,
|
||||
let proof = generatedProof,
|
||||
let publicInputs = publicInputs else {
|
||||
print("Setup is not completed or proof has not been generated yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Verify Proof
|
||||
let isValid = try moproCircom.verifyProof(proof: proof, publicInput: publicInputs)
|
||||
assert(isValid, "Proof verification should succeed")
|
||||
|
||||
textView.text += "Proof verification succeeded.\n"
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
}
|
||||
|
||||
func bytesToBits(bytes: [UInt8]) -> [String] {
|
||||
var bits = [String]()
|
||||
for byte in bytes {
|
||||
for j in 0..<8 {
|
||||
let bit = (byte >> j) & 1
|
||||
bits.append(String(bit))
|
||||
}
|
||||
}
|
||||
return bits
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// MoproKit
|
||||
//
|
||||
// Created by 1552237 on 09/16/2023.
|
||||
// Copyright (c) 2023 1552237. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MoproKit
|
||||
|
||||
class KeccakZkeyViewController: UIViewController {
|
||||
|
||||
var initButton = UIButton(type: .system)
|
||||
var proveButton = UIButton(type: .system)
|
||||
var verifyButton = UIButton(type: .system)
|
||||
var textView = UITextView()
|
||||
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
//var setupResult: SetupResult?
|
||||
var generatedProof: Data?
|
||||
var publicInputs: Data?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Set title
|
||||
let title = UILabel()
|
||||
title.text = "Keccak256 (Zkey)"
|
||||
title.textColor = .white
|
||||
title.textAlignment = .center
|
||||
navigationItem.titleView = title
|
||||
navigationController?.navigationBar.isHidden = false
|
||||
navigationController?.navigationBar.prefersLargeTitles = true
|
||||
|
||||
setupUI()
|
||||
}
|
||||
|
||||
func setupUI() {
|
||||
initButton.setTitle("Init", for: .normal)
|
||||
proveButton.setTitle("Prove", for: .normal)
|
||||
verifyButton.setTitle("Verify", for: .normal)
|
||||
|
||||
// Uncomment once init separate
|
||||
//proveButton.isEnabled = false
|
||||
proveButton.isEnabled = true
|
||||
verifyButton.isEnabled = false
|
||||
textView.isEditable = false
|
||||
|
||||
// Setup actions for buttons
|
||||
initButton.addTarget(self, action: #selector(runInitAction), for: .touchUpInside)
|
||||
proveButton.addTarget(self, action: #selector(runProveAction), for: .touchUpInside)
|
||||
verifyButton.addTarget(self, action: #selector(runVerifyAction), for: .touchUpInside)
|
||||
|
||||
initButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [initButton, proveButton, verifyButton, textView])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 10
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stackView)
|
||||
|
||||
// Make text view visible
|
||||
textView.heightAnchor.constraint(equalToConstant: 200).isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
|
||||
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
|
||||
])
|
||||
}
|
||||
|
||||
@objc func runInitAction() {
|
||||
// Logic for init
|
||||
do {
|
||||
textView.text += "Initializing library\n"
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
try initializeMopro()
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n"
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runProveAction() {
|
||||
// Logic for prove (generate_proof2)
|
||||
do {
|
||||
// Prepare inputs
|
||||
let inputVec: [UInt8] = [
|
||||
116, 101, 115, 116, 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,
|
||||
]
|
||||
let bits = bytesToBits(bytes: inputVec)
|
||||
var inputs = [String: [String]]()
|
||||
inputs["in"] = bits
|
||||
|
||||
// Expected outputs
|
||||
let outputVec: [UInt8] = [
|
||||
37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88,
|
||||
212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21,
|
||||
]
|
||||
let outputBits: [String] = bytesToBits(bytes: outputVec)
|
||||
// let expectedOutput: [UInt8] = serializeOutputs(outputBits)
|
||||
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try generateProof2(circuitInputs: inputs)
|
||||
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
//assert(Data(expectedOutput) == generateProofResult.inputs, "Circuit outputs mismatch the expected outputs")
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Store the generated proof and public inputs for later verification
|
||||
generatedProof = generateProofResult.proof
|
||||
publicInputs = generateProofResult.inputs
|
||||
|
||||
textView.text += "Proof generation took \(timeTaken) seconds.\n"
|
||||
// TODO: Enable verify
|
||||
verifyButton.isEnabled = false
|
||||
//verifyButton.isEnabled = true // Enable the Verify button once proof has been generated
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runVerifyAction() {
|
||||
// Logic for verify
|
||||
}
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// MoproKit
|
||||
//
|
||||
// Created by 1552237 on 09/16/2023.
|
||||
// Copyright (c) 2023 1552237. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MoproKit
|
||||
|
||||
class RSAViewController: UIViewController {
|
||||
|
||||
var initButton = UIButton(type: .system)
|
||||
var proveButton = UIButton(type: .system)
|
||||
var verifyButton = UIButton(type: .system)
|
||||
var textView = UITextView()
|
||||
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
//var setupResult: SetupResult?
|
||||
var generatedProof: Data?
|
||||
var publicInputs: Data?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
// Set title
|
||||
let title = UILabel()
|
||||
title.text = "RSA (Zkey)"
|
||||
title.textColor = .white
|
||||
title.textAlignment = .center
|
||||
navigationItem.titleView = title
|
||||
navigationController?.navigationBar.isHidden = false
|
||||
navigationController?.navigationBar.prefersLargeTitles = true
|
||||
|
||||
setupUI()
|
||||
}
|
||||
|
||||
func setupUI() {
|
||||
initButton.setTitle("Init", for: .normal)
|
||||
proveButton.setTitle("Prove", for: .normal)
|
||||
verifyButton.setTitle("Verify", for: .normal)
|
||||
|
||||
// Uncomment once init separate
|
||||
//proveButton.isEnabled = false
|
||||
proveButton.isEnabled = true
|
||||
verifyButton.isEnabled = false
|
||||
textView.isEditable = false
|
||||
|
||||
// Setup actions for buttons
|
||||
initButton.addTarget(self, action: #selector(runInitAction), for: .touchUpInside)
|
||||
proveButton.addTarget(self, action: #selector(runProveAction), for: .touchUpInside)
|
||||
verifyButton.addTarget(self, action: #selector(runVerifyAction), for: .touchUpInside)
|
||||
|
||||
initButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [initButton, proveButton, verifyButton, textView])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 10
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stackView)
|
||||
|
||||
// Make text view visible
|
||||
textView.heightAnchor.constraint(equalToConstant: 200).isActive = true
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
|
||||
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
|
||||
])
|
||||
}
|
||||
|
||||
@objc func runInitAction() {
|
||||
// Update the textView on the main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "Initializing library\n"
|
||||
}
|
||||
|
||||
// Execute long-running tasks in the background
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
do {
|
||||
try initializeMopro()
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Again, update the UI on the main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "Initializing arkzkey took \(timeTaken) seconds.\n"
|
||||
}
|
||||
} catch {
|
||||
// Handle errors - update UI on main thread
|
||||
DispatchQueue.main.async {
|
||||
self.textView.text += "An error occurred during initialization: \(error)\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runProveAction() {
|
||||
// Logic for prove (generate_proof2)
|
||||
do {
|
||||
// Prepare inputs
|
||||
let signature: [String] = [
|
||||
"3582320600048169363",
|
||||
"7163546589759624213",
|
||||
"18262551396327275695",
|
||||
"4479772254206047016",
|
||||
"1970274621151677644",
|
||||
"6547632513799968987",
|
||||
"921117808165172908",
|
||||
"7155116889028933260",
|
||||
"16769940396381196125",
|
||||
"17141182191056257954",
|
||||
"4376997046052607007",
|
||||
"17471823348423771450",
|
||||
"16282311012391954891",
|
||||
"70286524413490741",
|
||||
"1588836847166444745",
|
||||
"15693430141227594668",
|
||||
"13832254169115286697",
|
||||
"15936550641925323613",
|
||||
"323842208142565220",
|
||||
"6558662646882345749",
|
||||
"15268061661646212265",
|
||||
"14962976685717212593",
|
||||
"15773505053543368901",
|
||||
"9586594741348111792",
|
||||
"1455720481014374292",
|
||||
"13945813312010515080",
|
||||
"6352059456732816887",
|
||||
"17556873002865047035",
|
||||
"2412591065060484384",
|
||||
"11512123092407778330",
|
||||
"8499281165724578877",
|
||||
"12768005853882726493",
|
||||
]
|
||||
|
||||
let modulus: [String] = [
|
||||
"13792647154200341559",
|
||||
"12773492180790982043",
|
||||
"13046321649363433702",
|
||||
"10174370803876824128",
|
||||
"7282572246071034406",
|
||||
"1524365412687682781",
|
||||
"4900829043004737418",
|
||||
"6195884386932410966",
|
||||
"13554217876979843574",
|
||||
"17902692039595931737",
|
||||
"12433028734895890975",
|
||||
"15971442058448435996",
|
||||
"4591894758077129763",
|
||||
"11258250015882429548",
|
||||
"16399550288873254981",
|
||||
"8246389845141771315",
|
||||
"14040203746442788850",
|
||||
"7283856864330834987",
|
||||
"12297563098718697441",
|
||||
"13560928146585163504",
|
||||
"7380926829734048483",
|
||||
"14591299561622291080",
|
||||
"8439722381984777599",
|
||||
"17375431987296514829",
|
||||
"16727607878674407272",
|
||||
"3233954801381564296",
|
||||
"17255435698225160983",
|
||||
"15093748890170255670",
|
||||
"15810389980847260072",
|
||||
"11120056430439037392",
|
||||
"5866130971823719482",
|
||||
"13327552690270163501",
|
||||
]
|
||||
|
||||
let base_message: [String] = ["18114495772705111902", "2254271930739856077",
|
||||
"2068851770", "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",
|
||||
]
|
||||
|
||||
var inputs = [String: [String]]()
|
||||
inputs["signature"] = signature;
|
||||
inputs["modulus"] = modulus;
|
||||
inputs["base_message"] = base_message;
|
||||
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try generateProof2(circuitInputs: inputs)
|
||||
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Store the generated proof and public inputs for later verification
|
||||
generatedProof = generateProofResult.proof
|
||||
publicInputs = generateProofResult.inputs
|
||||
|
||||
textView.text += "Proof generation took \(timeTaken) seconds.\n"
|
||||
verifyButton.isEnabled = true
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
textView.text += "MoproError: \(error)\n"
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
textView.text += "Unexpected error: \(error)\n"
|
||||
}
|
||||
}
|
||||
|
||||
@objc func runVerifyAction() {
|
||||
// Logic for verify
|
||||
guard let proof = generatedProof,
|
||||
let publicInputs = publicInputs else {
|
||||
print("Proof has not been generated yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Verify Proof
|
||||
let isValid = try verifyProof2(proof: proof, publicInput: publicInputs)
|
||||
assert(isValid, "Proof verification should succeed")
|
||||
|
||||
textView.text += "Proof verification succeeded.\n"
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// MoproKit
|
||||
//
|
||||
// Created by 1552237 on 09/16/2023.
|
||||
// Copyright (c) 2023 1552237. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import MoproKit
|
||||
|
||||
|
||||
// Main ViewController
|
||||
class ViewController: UIViewController {
|
||||
|
||||
let keccakSetupButton = UIButton(type: .system)
|
||||
let keccakZkeyButton = UIButton(type: .system)
|
||||
let rsaButton = UIButton(type: .system)
|
||||
let aadhaarButton = UIButton(type: .system)
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// TODO: Improve style
|
||||
|
||||
// Set title
|
||||
let title = UILabel()
|
||||
title.text = "Mopro Examples"
|
||||
title.textColor = .white
|
||||
title.textAlignment = .center
|
||||
navigationItem.titleView = title
|
||||
navigationController?.navigationBar.isHidden = false
|
||||
navigationController?.navigationBar.prefersLargeTitles = true
|
||||
|
||||
setupMainUI()
|
||||
}
|
||||
|
||||
func setupMainUI() {
|
||||
keccakSetupButton.setTitle("Keccak (Setup)", for: .normal)
|
||||
keccakSetupButton.addTarget(self, action: #selector(openKeccakSetup), for: .touchUpInside)
|
||||
|
||||
keccakZkeyButton.setTitle("Keccak (Zkey)", for: .normal)
|
||||
keccakZkeyButton.addTarget(self, action: #selector(openKeccakZkey), for: .touchUpInside)
|
||||
|
||||
rsaButton.setTitle("RSA", for: .normal)
|
||||
rsaButton.addTarget(self, action: #selector(openRSA), for: .touchUpInside)
|
||||
|
||||
aadhaarButton.setTitle("Anon Aadhaar", for: .normal)
|
||||
aadhaarButton.addTarget(self, action: #selector(openAnonAadhaar), for: .touchUpInside)
|
||||
|
||||
|
||||
keccakSetupButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
keccakZkeyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
rsaButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
|
||||
// self.title = "Mopro Examples"
|
||||
// navigationController?.navigationBar.prefersLargeTitles = true
|
||||
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [keccakSetupButton, keccakZkeyButton, rsaButton, aadhaarButton])
|
||||
stackView.axis = .vertical
|
||||
stackView.spacing = 20
|
||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(stackView)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
|
||||
])
|
||||
}
|
||||
|
||||
@objc func openKeccakSetup() {
|
||||
let keccakSetupVC = KeccakSetupViewController()
|
||||
navigationController?.pushViewController(keccakSetupVC, animated: true)
|
||||
}
|
||||
|
||||
@objc func openKeccakZkey() {
|
||||
let keccakZkeyVC = KeccakZkeyViewController()
|
||||
navigationController?.pushViewController(keccakZkeyVC, animated: true)
|
||||
}
|
||||
|
||||
@objc func openRSA() {
|
||||
let rsaVC = RSAViewController()
|
||||
navigationController?.pushViewController(rsaVC, animated: true)
|
||||
}
|
||||
|
||||
@objc func openAnonAadhaar() {
|
||||
let anonAadhaarVC = AnonAadhaarViewController()
|
||||
navigationController?.pushViewController(anonAadhaarVC, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
// // Make buttons bigger
|
||||
// proveButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
// verifyButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 16, bottom: 12, right: 16)
|
||||
|
||||
// NSLayoutConstraint.activate([
|
||||
// stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
|
||||
// stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
|
||||
// stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20)
|
||||
// ])
|
||||
@@ -1,24 +0,0 @@
|
||||
use_frameworks!
|
||||
|
||||
platform :ios, '13.0'
|
||||
|
||||
target 'MoproKit_Example' do
|
||||
pod 'MoproKit', :path => '../'
|
||||
|
||||
target 'MoproKit_Tests' do
|
||||
inherit! :search_paths
|
||||
|
||||
pod 'Quick', '~> 2.2.0'
|
||||
pod 'Nimble', '~> 10.0.0'
|
||||
end
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.generated_projects.each do |project|
|
||||
project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,109 +0,0 @@
|
||||
@testable import MoproKit
|
||||
import XCTest
|
||||
|
||||
final class CircomTests: XCTestCase {
|
||||
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
|
||||
func testMultiplier() {
|
||||
let wasmPath = Bundle.main.path(forResource: "multiplier2", ofType: "wasm")!
|
||||
let r1csPath = Bundle.main.path(forResource: "multiplier2", ofType: "r1cs")!
|
||||
XCTAssertNoThrow(try moproCircom.setup(wasmPath: wasmPath, r1csPath: r1csPath), "Mopro circom setup failed")
|
||||
|
||||
do {
|
||||
var inputs = [String: [String]]()
|
||||
let a = 3
|
||||
let b = 5
|
||||
let c = a*b
|
||||
inputs["a"] = [String(a)]
|
||||
inputs["b"] = [String(b)]
|
||||
let outputs: [String] = [String(c), String(a)]
|
||||
let expectedOutput: [UInt8] = serializeOutputs(outputs)
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs)
|
||||
XCTAssertFalse(generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
XCTAssertEqual(Data(expectedOutput), generateProofResult.inputs, "Circuit outputs mismatch the expected outputs")
|
||||
|
||||
let isValid = try moproCircom.verifyProof(proof: generateProofResult.proof, publicInput: generateProofResult.inputs)
|
||||
XCTAssertTrue(isValid, "Proof verification should succeed")
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func testKeccak256() {
|
||||
let wasmPath = Bundle.main.path(forResource: "keccak256_256_test", ofType: "wasm")!
|
||||
let r1csPath = Bundle.main.path(forResource: "keccak256_256_test", ofType: "r1cs")!
|
||||
XCTAssertNoThrow(try moproCircom.setup(wasmPath: wasmPath, r1csPath: r1csPath), "Mopro circom setup failed")
|
||||
|
||||
do {
|
||||
// Prepare inputs
|
||||
let inputVec: [UInt8] = [
|
||||
116, 101, 115, 116, 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,
|
||||
]
|
||||
let bits = bytesToBits(bytes: inputVec)
|
||||
var inputs = [String: [String]]()
|
||||
inputs["in"] = bits
|
||||
|
||||
// Expected outputs
|
||||
let outputVec: [UInt8] = [
|
||||
37, 17, 98, 135, 161, 178, 88, 97, 125, 150, 143, 65, 228, 211, 170, 133, 153, 9, 88,
|
||||
212, 4, 212, 175, 238, 249, 210, 214, 116, 170, 85, 45, 21,
|
||||
]
|
||||
let outputBits: [String] = bytesToBits(bytes: outputVec)
|
||||
let expectedOutput: [UInt8] = serializeOutputs(outputBits)
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try moproCircom.generateProof(circuitInputs: inputs)
|
||||
XCTAssertFalse(generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
XCTAssertEqual(Data(expectedOutput), generateProofResult.inputs, "Circuit outputs mismatch the expected outputs")
|
||||
|
||||
let isValid = try moproCircom.verifyProof(proof: generateProofResult.proof, publicInput: generateProofResult.inputs)
|
||||
XCTAssertTrue(isValid, "Proof verification should succeed")
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func bytesToBits(bytes: [UInt8]) -> [String] {
|
||||
var bits = [String]()
|
||||
for byte in bytes {
|
||||
for j in 0..<8 {
|
||||
let bit = (byte >> j) & 1
|
||||
bits.append(String(bit))
|
||||
}
|
||||
}
|
||||
return bits
|
||||
}
|
||||
|
||||
func serializeOutputs(_ stringArray: [String]) -> [UInt8] {
|
||||
var bytesArray: [UInt8] = []
|
||||
let length = stringArray.count
|
||||
var littleEndianLength = length.littleEndian
|
||||
let targetLength = 32
|
||||
withUnsafeBytes(of: &littleEndianLength) {
|
||||
bytesArray.append(contentsOf: $0)
|
||||
}
|
||||
for value in stringArray {
|
||||
// TODO: should handle 254-bit input
|
||||
var littleEndian = Int32(value)!.littleEndian
|
||||
var byteLength = 0
|
||||
withUnsafeBytes(of: &littleEndian) {
|
||||
bytesArray.append(contentsOf: $0)
|
||||
byteLength = byteLength + $0.count
|
||||
}
|
||||
if byteLength < targetLength {
|
||||
let paddingCount = targetLength - byteLength
|
||||
let paddingArray = [UInt8](repeating: 0, count: paddingCount)
|
||||
bytesArray.append(contentsOf: paddingArray)
|
||||
}
|
||||
}
|
||||
return bytesArray
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import XCTest
|
||||
@testable import MoproKit_Example
|
||||
|
||||
final class CircomUITests: XCTestCase {
|
||||
|
||||
let ui = KeccakSetupViewController()
|
||||
|
||||
func testSuccessUI() {
|
||||
XCTAssertNoThrow(ui.setupUI(), "Setup UI failed")
|
||||
XCTAssertNoThrow(ui.runProveAction(), "Prove action failed")
|
||||
XCTAssertNoThrow(ui.runVerifyAction(), "Verify action failed")
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,238 +0,0 @@
|
||||
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// The following structs are used to implement the lowest level
|
||||
// of the FFI, and thus useful to multiple uniffied crates.
|
||||
// We ensure they are declared exactly once, with a header guard, UNIFFI_SHARED_H.
|
||||
#ifdef UNIFFI_SHARED_H
|
||||
// We also try to prevent mixing versions of shared uniffi header structs.
|
||||
// If you add anything to the #else block, you must increment the version suffix in UNIFFI_SHARED_HEADER_V4
|
||||
#ifndef UNIFFI_SHARED_HEADER_V4
|
||||
#error Combining helper code from multiple versions of uniffi is not supported
|
||||
#endif // ndef UNIFFI_SHARED_HEADER_V4
|
||||
#else
|
||||
#define UNIFFI_SHARED_H
|
||||
#define UNIFFI_SHARED_HEADER_V4
|
||||
// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️
|
||||
// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️
|
||||
|
||||
typedef struct RustBuffer
|
||||
{
|
||||
int32_t capacity;
|
||||
int32_t len;
|
||||
uint8_t *_Nullable data;
|
||||
} RustBuffer;
|
||||
|
||||
typedef int32_t (*ForeignCallback)(uint64_t, int32_t, const uint8_t *_Nonnull, int32_t, RustBuffer *_Nonnull);
|
||||
|
||||
// Task defined in Rust that Swift executes
|
||||
typedef void (*UniFfiRustTaskCallback)(const void * _Nullable, int8_t);
|
||||
|
||||
// Callback to execute Rust tasks using a Swift Task
|
||||
//
|
||||
// Args:
|
||||
// executor: ForeignExecutor lowered into a size_t value
|
||||
// delay: Delay in MS
|
||||
// task: UniFfiRustTaskCallback to call
|
||||
// task_data: data to pass the task callback
|
||||
typedef int8_t (*UniFfiForeignExecutorCallback)(size_t, uint32_t, UniFfiRustTaskCallback _Nullable, const void * _Nullable);
|
||||
|
||||
typedef struct ForeignBytes
|
||||
{
|
||||
int32_t len;
|
||||
const uint8_t *_Nullable data;
|
||||
} ForeignBytes;
|
||||
|
||||
// Error definitions
|
||||
typedef struct RustCallStatus {
|
||||
int8_t code;
|
||||
RustBuffer errorBuf;
|
||||
} RustCallStatus;
|
||||
|
||||
// ⚠️ Attention: If you change this #else block (ending in `#endif // def UNIFFI_SHARED_H`) you *must* ⚠️
|
||||
// ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V4 in this file. ⚠️
|
||||
#endif // def UNIFFI_SHARED_H
|
||||
|
||||
// Continuation callback for UniFFI Futures
|
||||
typedef void (*UniFfiRustFutureContinuation)(void * _Nonnull, int8_t);
|
||||
|
||||
// Scaffolding functions
|
||||
void uniffi_mopro_ffi_fn_free_moprocircom(void*_Nonnull ptr, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void*_Nonnull uniffi_mopro_ffi_fn_constructor_moprocircom_new(RustCallStatus *_Nonnull out_status
|
||||
|
||||
);
|
||||
RustBuffer uniffi_mopro_ffi_fn_method_moprocircom_generate_proof(void*_Nonnull ptr, RustBuffer circuit_inputs, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_mopro_ffi_fn_method_moprocircom_setup(void*_Nonnull ptr, RustBuffer wasm_path, RustBuffer r1cs_path, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
int8_t uniffi_mopro_ffi_fn_method_moprocircom_verify_proof(void*_Nonnull ptr, RustBuffer proof, RustBuffer public_input, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
uint32_t uniffi_mopro_ffi_fn_func_add(uint32_t a, uint32_t b, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_mopro_ffi_fn_func_generate_proof2(RustBuffer circuit_inputs, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_mopro_ffi_fn_func_hello(RustCallStatus *_Nonnull out_status
|
||||
|
||||
);
|
||||
void uniffi_mopro_ffi_fn_func_initialize_mopro(RustCallStatus *_Nonnull out_status
|
||||
|
||||
);
|
||||
void uniffi_mopro_ffi_fn_func_initialize_mopro_dylib(RustBuffer dylib_path, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
int8_t uniffi_mopro_ffi_fn_func_verify_proof2(RustBuffer proof, RustBuffer public_input, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer ffi_mopro_ffi_rustbuffer_alloc(int32_t size, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer ffi_mopro_ffi_rustbuffer_from_bytes(ForeignBytes bytes, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rustbuffer_free(RustBuffer buf, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer ffi_mopro_ffi_rustbuffer_reserve(RustBuffer buf, int32_t additional, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_continuation_callback_set(UniFfiRustFutureContinuation _Nonnull callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_u8(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_u8(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_u8(void* _Nonnull handle
|
||||
);
|
||||
uint8_t ffi_mopro_ffi_rust_future_complete_u8(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_i8(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_i8(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_i8(void* _Nonnull handle
|
||||
);
|
||||
int8_t ffi_mopro_ffi_rust_future_complete_i8(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_u16(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_u16(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_u16(void* _Nonnull handle
|
||||
);
|
||||
uint16_t ffi_mopro_ffi_rust_future_complete_u16(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_i16(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_i16(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_i16(void* _Nonnull handle
|
||||
);
|
||||
int16_t ffi_mopro_ffi_rust_future_complete_i16(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_u32(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_u32(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_u32(void* _Nonnull handle
|
||||
);
|
||||
uint32_t ffi_mopro_ffi_rust_future_complete_u32(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_i32(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_i32(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_i32(void* _Nonnull handle
|
||||
);
|
||||
int32_t ffi_mopro_ffi_rust_future_complete_i32(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_u64(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_u64(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_u64(void* _Nonnull handle
|
||||
);
|
||||
uint64_t ffi_mopro_ffi_rust_future_complete_u64(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_i64(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_i64(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_i64(void* _Nonnull handle
|
||||
);
|
||||
int64_t ffi_mopro_ffi_rust_future_complete_i64(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_f32(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_f32(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_f32(void* _Nonnull handle
|
||||
);
|
||||
float ffi_mopro_ffi_rust_future_complete_f32(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_f64(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_f64(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_f64(void* _Nonnull handle
|
||||
);
|
||||
double ffi_mopro_ffi_rust_future_complete_f64(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_pointer(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_pointer(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_pointer(void* _Nonnull handle
|
||||
);
|
||||
void*_Nonnull ffi_mopro_ffi_rust_future_complete_pointer(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_rust_buffer(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_rust_buffer(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_rust_buffer(void* _Nonnull handle
|
||||
);
|
||||
RustBuffer ffi_mopro_ffi_rust_future_complete_rust_buffer(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_poll_void(void* _Nonnull handle, void* _Nonnull uniffi_callback
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_cancel_void(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_free_void(void* _Nonnull handle
|
||||
);
|
||||
void ffi_mopro_ffi_rust_future_complete_void(void* _Nonnull handle, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_add(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_generate_proof2(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_hello(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_initialize_mopro(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_initialize_mopro_dylib(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_func_verify_proof2(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_method_moprocircom_generate_proof(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_method_moprocircom_setup(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_method_moprocircom_verify_proof(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_mopro_ffi_checksum_constructor_moprocircom_new(void
|
||||
|
||||
);
|
||||
uint32_t ffi_mopro_ffi_uniffi_contract_version(void
|
||||
|
||||
);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
Copyright (c) 2023 1552237 <oskarth@titanproxy.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
@@ -1,50 +0,0 @@
|
||||
#
|
||||
# Be sure to run `pod lib lint MoproKit.podspec' to ensure this is a
|
||||
# valid spec before submitting.
|
||||
#
|
||||
# Any lines starting with a # are optional, but their use is encouraged
|
||||
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
|
||||
#
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'MoproKit'
|
||||
s.version = '0.1.0'
|
||||
s.summary = 'A short description of MoproKit.'
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
# * Think: What does it do? Why did you write it? What is the focus?
|
||||
# * Try to keep it short, snappy and to the point.
|
||||
# * Write the description between the DESC delimiters below.
|
||||
# * Finally, don't worry about the indent, CocoaPods strips it!
|
||||
|
||||
s.description = <<-DESC
|
||||
TODO: Add long description of the pod here.
|
||||
DESC
|
||||
|
||||
s.homepage = 'https://github.com/1552237/MoproKit'
|
||||
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.author = { '1552237' => 'oskarth@titanproxy.com' }
|
||||
s.source = { :git => 'https://github.com/1552237/MoproKit.git', :tag => s.version.to_s }
|
||||
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
|
||||
|
||||
s.ios.deployment_target = '13.0'
|
||||
|
||||
s.source_files = 'MoproKit/Classes/**/*'
|
||||
|
||||
# libmopro library, headers and modulemap
|
||||
# XXX: static library is not in source control, and needs to be inlcuded manually
|
||||
# Have to be mindful of architecture and simulator or not here, should be improved
|
||||
s.preserve_paths = 'Libs/libmopro_uniffi.a'
|
||||
s.vendored_libraries = 'Libs/libmopro_uniffi.a'
|
||||
s.source_files = 'Include/*.h', 'Bindings/*.swift'
|
||||
s.resource = 'Resources/moproFFI.modulemap'
|
||||
|
||||
# s.resource_bundles = {
|
||||
# 'MoproKit' => ['MoproKit/Assets/*.png']
|
||||
# }
|
||||
|
||||
# s.public_header_files = 'Pod/Classes/**/*.h'
|
||||
# s.frameworks = 'UIKit', 'MapKit'
|
||||
# s.dependency 'AFNetworking', '~> 2.3'
|
||||
end
|
||||
@@ -1,29 +0,0 @@
|
||||
# MoproKit
|
||||
|
||||
[](https://travis-ci.org/1552237/MoproKit)
|
||||
[](https://cocoapods.org/pods/MoproKit)
|
||||
[](https://cocoapods.org/pods/MoproKit)
|
||||
[](https://cocoapods.org/pods/MoproKit)
|
||||
|
||||
## Example
|
||||
|
||||
To run the example project, clone the repo, and run `pod install` from the Example directory first.
|
||||
|
||||
## Requirements
|
||||
|
||||
## Installation
|
||||
|
||||
MoproKit is available through [CocoaPods](https://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod 'MoproKit'
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
1552237, oskarth@titanproxy.com
|
||||
|
||||
## License
|
||||
|
||||
MoproKit is available under the MIT license. See the LICENSE file for more info.
|
||||
@@ -1,6 +0,0 @@
|
||||
// This file was autogenerated by some hot garbage in the `uniffi` crate.
|
||||
// Trust me, you don't want to mess with it!
|
||||
module moproFFI {
|
||||
header "moproFFI.h"
|
||||
export *
|
||||
}
|
||||
@@ -39,8 +39,8 @@ target 'ProofOfPassport' do
|
||||
|
||||
use_frameworks!
|
||||
pod 'NFCPassportReader', git: 'https://github.com/0xturboblitz/NFCPassportReader.git', commit: '310ecb519655d9ed8b1afc5eb490b2f51a4d3595'
|
||||
pod 'MoproKit', :path => './MoproKit'
|
||||
pod 'QKMRZScanner'
|
||||
pod 'RNFS', :path => '../node_modules/react-native-fs'
|
||||
|
||||
use_react_native!(
|
||||
:path => config[:reactNativePath],
|
||||
@@ -66,6 +66,7 @@ target 'ProofOfPassport' do
|
||||
project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
|
||||
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ PODS:
|
||||
- ReactCommon/turbomodule/core (= 0.72.3)
|
||||
- fmt (6.2.1)
|
||||
- glog (0.3.5)
|
||||
- MoproKit (0.1.0)
|
||||
- NFCPassportReader (2.0.3):
|
||||
- OpenSSL-Universal (= 1.1.1100)
|
||||
- OpenSSL-Universal (1.1.1100)
|
||||
@@ -397,6 +396,8 @@ PODS:
|
||||
- React-perflogger (= 0.72.3)
|
||||
- RNCClipboard (1.5.1):
|
||||
- React-Core
|
||||
- RNFS (2.20.0):
|
||||
- React-Core
|
||||
- RNSVG (13.4.0):
|
||||
- React-Core
|
||||
- SocketRocket (0.6.1)
|
||||
@@ -409,7 +410,6 @@ DEPENDENCIES:
|
||||
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
|
||||
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
|
||||
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
|
||||
- MoproKit (from `./MoproKit`)
|
||||
- NFCPassportReader (from `https://github.com/0xturboblitz/NFCPassportReader.git`, commit `310ecb519655d9ed8b1afc5eb490b2f51a4d3595`)
|
||||
- QKMRZScanner
|
||||
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
|
||||
@@ -446,6 +446,7 @@ DEPENDENCIES:
|
||||
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
|
||||
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
|
||||
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
|
||||
- RNFS (from `../node_modules/react-native-fs`)
|
||||
- RNSVG (from `../node_modules/react-native-svg`)
|
||||
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
|
||||
|
||||
@@ -469,8 +470,6 @@ EXTERNAL SOURCES:
|
||||
:path: "../node_modules/react-native/React/FBReactNativeSpec"
|
||||
glog:
|
||||
:podspec: "../node_modules/react-native/third-party-podspecs/glog.podspec"
|
||||
MoproKit:
|
||||
:path: "./MoproKit"
|
||||
NFCPassportReader:
|
||||
:commit: 310ecb519655d9ed8b1afc5eb490b2f51a4d3595
|
||||
:git: https://github.com/0xturboblitz/NFCPassportReader.git
|
||||
@@ -540,6 +539,8 @@ EXTERNAL SOURCES:
|
||||
:path: "../node_modules/react-native/ReactCommon"
|
||||
RNCClipboard:
|
||||
:path: "../node_modules/@react-native-community/clipboard"
|
||||
RNFS:
|
||||
:path: "../node_modules/react-native-fs"
|
||||
RNSVG:
|
||||
:path: "../node_modules/react-native-svg"
|
||||
Yoga:
|
||||
@@ -557,7 +558,6 @@ SPEC CHECKSUMS:
|
||||
FBReactNativeSpec: c6bd9e179757b3c0ecf815864fae8032377903ef
|
||||
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
|
||||
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
|
||||
MoproKit: d1faf8f9495e8e84d085f6c4e57e36f951e6f07e
|
||||
NFCPassportReader: a160b80e3df3b5325c13902f90405f5eef7520b3
|
||||
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
|
||||
QKMRZParser: 6b419b6f07d6bff6b50429b97de10846dc902c29
|
||||
@@ -571,13 +571,13 @@ SPEC CHECKSUMS:
|
||||
React-Core: 8293312ad137ea82fd2c29deb163dbc24aa4e00e
|
||||
React-CoreModules: 32fab1d62416849a3b6dac6feff9d54e5ddc2d1e
|
||||
React-cxxreact: 55d0f7cb6b4cc09ba9190797f1da87182d1a2fb6
|
||||
React-debug: 7e61555c8158126c6cd98c3154381ad3821aaaca
|
||||
React-debug: 533bc7812bc4731d1c73b70001c9fe7f037c122e
|
||||
React-jsc: 0db8e8cc2074d979c37ffa7b8d7c914833960497
|
||||
React-jsi: 58677ff4848ceb6aeb9118fe03448a843ea5e16a
|
||||
React-jsiexecutor: 2c15ba1bace70177492368d5180b564f165870fd
|
||||
React-jsinspector: b511447170f561157547bc0bef3f169663860be7
|
||||
React-logger: c5b527272d5f22eaa09bb3c3a690fee8f237ae95
|
||||
React-NativeModulesApple: 0438665fc7473be6edc496e823e6ea0b0537b46c
|
||||
React-NativeModulesApple: 4d9624c9e6c8f034f2b174509ab8671c2ba51a8e
|
||||
React-perflogger: 6bd153e776e6beed54c56b0847e1220a3ff92ba5
|
||||
React-RCTActionSheet: c0b62af44e610e69d9a2049a682f5dba4e9dff17
|
||||
React-RCTAnimation: fe7005136b58f58871cab2f70732343b6e330d30
|
||||
@@ -591,15 +591,16 @@ SPEC CHECKSUMS:
|
||||
React-RCTVibration: ea3a68a49873a54ced927c90923fc6932baf344a
|
||||
React-rncore: 9672a017af4a7da7495d911f0b690cbcae9dd18d
|
||||
React-runtimeexecutor: 369ae9bb3f83b65201c0c8f7d50b72280b5a1dbc
|
||||
React-runtimescheduler: ec1066a4f2d1152eb1bc3fb61d69376b3bc0dde0
|
||||
React-utils: d55ba834beb39f01b0b470ae43478c0a3a024abe
|
||||
ReactCommon: 68e3a815fbb69af3bb4196e04c6ae7abb306e7a8
|
||||
React-runtimescheduler: 810e1eb2778ad5ff7d36e531dffb2cf6e06a373f
|
||||
React-utils: 9290f42c6de69e770dd9db84b0ab673d5098a4ab
|
||||
ReactCommon: 792bc220c086422d4bea3449f74b1c44360f56a7
|
||||
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
|
||||
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
|
||||
RNSVG: 07dbd870b0dcdecc99b3a202fa37c8ca163caec2
|
||||
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
|
||||
SwiftyTesseract: 1f3d96668ae92dc2208d9842c8a59bea9fad2cbb
|
||||
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce
|
||||
|
||||
PODFILE CHECKSUM: bfa6f6f947d05938da674ddbd61afd65fc7ece34
|
||||
PODFILE CHECKSUM: 3ec33f7f648c4a3966f1b01bfcf100100bbbebdc
|
||||
|
||||
COCOAPODS: 1.14.3
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
#import "React/RCTBridgeModule.h"
|
||||
#include "witnesscalc_proof_of_passport.h"
|
||||
#include "groth16_prover.h"
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
00E356F31AD99517003FC87E /* ProofOfPassportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* ProofOfPassportTests.m */; };
|
||||
057DFC5F2B56DC0D003D24A3 /* libmopro_ffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 057DFC5E2B56DC0D003D24A3 /* libmopro_ffi.a */; };
|
||||
05BD9DCC2B548AA900823023 /* MoproKit in Resources */ = {isa = PBXBuildFile; fileRef = 05BD9DCB2B548AA900823023 /* MoproKit */; };
|
||||
05BD9DCE2B554FA300823023 /* libmopro_ffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05BD9DCD2B554FA300823023 /* libmopro_ffi.a */; };
|
||||
0569F35B2BBC9015006670BD /* librapidsnark.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F35A2BBC900D006670BD /* librapidsnark.a */; };
|
||||
0569F35F2BBC98D5006670BD /* libfq.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F35E2BBC98C9006670BD /* libfq.a */; };
|
||||
0569F3612BBCE4EF006670BD /* libwitnesscalc_proof_of_passport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */; };
|
||||
05D985F52BB331AB00F58EEA /* libgmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D985F22BB331AB00F58EEA /* libgmp.a */; };
|
||||
05D985F62BB331AB00F58EEA /* libfr.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D985F32BB331AB00F58EEA /* libfr.a */; };
|
||||
05D985FB2BB3344600F58EEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 05D985FA2BB3344600F58EEA /* Assets.xcassets */; };
|
||||
05E2174E2E7E48EB80B9C8D8 /* Luciole-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ABB740B68A8141229E6118AC /* Luciole-Bold.ttf */; };
|
||||
05EDEDC62B52D25D00AA51AD /* Prover.m in Sources */ = {isa = PBXBuildFile; fileRef = 05EDEDC42B52D25D00AA51AD /* Prover.m */; };
|
||||
05EDEDC72B52D25D00AA51AD /* Prover.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05EDEDC52B52D25D00AA51AD /* Prover.swift */; };
|
||||
@@ -65,12 +67,14 @@
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
00E356EE1AD99517003FC87E /* ProofOfPassportTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ProofOfPassportTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
00E356F21AD99517003FC87E /* ProofOfPassportTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ProofOfPassportTests.m; sourceTree = "<group>"; };
|
||||
057DFC5E2B56DC0D003D24A3 /* libmopro_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmopro_ffi.a; path = MoproKit/Libs/libmopro_ffi.a; sourceTree = "<group>"; };
|
||||
05A0773D2B5333CE0037E489 /* MoproKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MoproKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
05BD9DCB2B548AA900823023 /* MoproKit */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MoproKit; sourceTree = "<group>"; };
|
||||
05BD9DCD2B554FA300823023 /* libmopro_ffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmopro_ffi.a; path = MoproKit/Libs/libmopro_ffi.a; sourceTree = "<group>"; };
|
||||
0569F35A2BBC900D006670BD /* librapidsnark.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = librapidsnark.a; sourceTree = "<group>"; };
|
||||
0569F35E2BBC98C9006670BD /* libfq.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfq.a; sourceTree = "<group>"; };
|
||||
0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libwitnesscalc_proof_of_passport.a; sourceTree = "<group>"; };
|
||||
0569F3622BBCE52D006670BD /* proof_of_passport.zkey */ = {isa = PBXFileReference; lastKnownFileType = file; name = proof_of_passport.zkey; path = ProofOfPassport/Assets.xcassets/proof_of_passport.zkey.dataset/proof_of_passport.zkey; sourceTree = "<group>"; };
|
||||
0569F3642BBCE53D006670BD /* proof_of_passport.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = proof_of_passport.dat; path = ProofOfPassport/Assets.xcassets/proof_of_passport.dat.dataset/proof_of_passport.dat; sourceTree = "<group>"; };
|
||||
05D985F22BB331AB00F58EEA /* libgmp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgmp.a; sourceTree = "<group>"; };
|
||||
05D985F32BB331AB00F58EEA /* libfr.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libfr.a; sourceTree = "<group>"; };
|
||||
05D985FA2BB3344600F58EEA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = ProofOfPassport/Assets.xcassets; sourceTree = "<group>"; };
|
||||
05EDEDC42B52D25D00AA51AD /* Prover.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Prover.m; sourceTree = "<group>"; };
|
||||
05EDEDC52B52D25D00AA51AD /* Prover.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Prover.swift; sourceTree = "<group>"; };
|
||||
066DD67BD55B4E90941F2B97 /* Inter-Black.otf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = "Inter-Black.otf"; path = "../node_modules/@tamagui/font-inter/otf/Inter-Black.otf"; sourceTree = "<group>"; };
|
||||
@@ -137,31 +141,17 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
0651723A94C70A2B31E3E4F8 /* Pods_ProofOfPassport.framework in Frameworks */,
|
||||
05BD9DCE2B554FA300823023 /* libmopro_ffi.a in Frameworks */,
|
||||
057DFC5F2B56DC0D003D24A3 /* libmopro_ffi.a in Frameworks */,
|
||||
0569F3612BBCE4EF006670BD /* libwitnesscalc_proof_of_passport.a in Frameworks */,
|
||||
05D985F52BB331AB00F58EEA /* libgmp.a in Frameworks */,
|
||||
0569F35F2BBC98D5006670BD /* libfq.a in Frameworks */,
|
||||
0569F35B2BBC9015006670BD /* librapidsnark.a in Frameworks */,
|
||||
05D985F62BB331AB00F58EEA /* libfr.a in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
00E356EF1AD99517003FC87E /* ProofOfPassportTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
00E356F21AD99517003FC87E /* ProofOfPassportTests.m */,
|
||||
00E356F01AD99517003FC87E /* Supporting Files */,
|
||||
);
|
||||
path = ProofOfPassportTests;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
00E356F01AD99517003FC87E /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
00E356F11AD99517003FC87E /* Info.plist */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
13B07FAE1A68108700A75B9A /* ProofOfPassport */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -169,13 +159,13 @@
|
||||
05EDEDC52B52D25D00AA51AD /* Prover.swift */,
|
||||
905B700A2A72A5E900AFA232 /* masterList.pem */,
|
||||
905B70082A729CD400AFA232 /* ProofOfPassport.entitlements */,
|
||||
057DFC5E2B56DC0D003D24A3 /* libmopro_ffi.a */,
|
||||
05D985F32BB331AB00F58EEA /* libfr.a */,
|
||||
05D985FA2BB3344600F58EEA /* Assets.xcassets */,
|
||||
05D985F22BB331AB00F58EEA /* libgmp.a */,
|
||||
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
|
||||
05BD9DCB2B548AA900823023 /* MoproKit */,
|
||||
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
|
||||
13B07FB51A68108700A75B9A /* Images.xcassets */,
|
||||
13B07FB61A68108700A75B9A /* Info.plist */,
|
||||
05BD9DCD2B554FA300823023 /* libmopro_ffi.a */,
|
||||
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
|
||||
13B07FB71A68108700A75B9A /* main.m */,
|
||||
905B70042A72767900AFA232 /* PassportReader.swift */,
|
||||
@@ -192,7 +182,9 @@
|
||||
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
05A0773D2B5333CE0037E489 /* MoproKit.framework */,
|
||||
0569F3602BBCE4EB006670BD /* libwitnesscalc_proof_of_passport.a */,
|
||||
0569F35E2BBC98C9006670BD /* libfq.a */,
|
||||
0569F35A2BBC900D006670BD /* librapidsnark.a */,
|
||||
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
|
||||
3DAAF621B99F62C9ED35AA07 /* Pods_ProofOfPassport.framework */,
|
||||
CFAE0EE7E1942128592D0CC4 /* Pods_ProofOfPassport_ProofOfPassportTests.framework */,
|
||||
@@ -242,9 +234,10 @@
|
||||
83CBB9F61A601CBA00E9B192 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
0569F3642BBCE53D006670BD /* proof_of_passport.dat */,
|
||||
0569F3622BBCE52D006670BD /* proof_of_passport.zkey */,
|
||||
13B07FAE1A68108700A75B9A /* ProofOfPassport */,
|
||||
832341AE1AAA6A7D00B99B32 /* Libraries */,
|
||||
00E356EF1AD99517003FC87E /* ProofOfPassportTests */,
|
||||
83CBBA001A601CBA00E9B192 /* Products */,
|
||||
2D16E6871FA4F8E400B85C8A /* Frameworks */,
|
||||
BBD78D7AC51CEA395F1C20DB /* Pods */,
|
||||
@@ -325,7 +318,7 @@
|
||||
83CBB9F71A601CBA00E9B192 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 1210;
|
||||
LastUpgradeCheck = 1520;
|
||||
TargetAttributes = {
|
||||
00E356ED1AD99517003FC87E = {
|
||||
CreatedOnToolsVersion = 6.2;
|
||||
@@ -368,7 +361,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
905B700B2A72A5E900AFA232 /* masterList.pem in Resources */,
|
||||
05BD9DCC2B548AA900823023 /* MoproKit in Resources */,
|
||||
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
|
||||
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
|
||||
2FA7C90AFAF5417DAA7BCB1E /* Inter-Black.otf in Resources */,
|
||||
@@ -377,6 +369,7 @@
|
||||
1D2A11340C7041909B820A90 /* Inter-ExtraBold.otf in Resources */,
|
||||
E4BC7CC193684992A11E3135 /* Inter-ExtraBoldItalic.otf in Resources */,
|
||||
1BA25F26C91C45F697D55099 /* Inter-ExtraLight.otf in Resources */,
|
||||
05D985FB2BB3344600F58EEA /* Assets.xcassets in Resources */,
|
||||
625D35EA2F1643E89F9887CE /* Inter-ExtraLightItalic.otf in Resources */,
|
||||
EEC491DF41A44001A577E8C5 /* Inter-Italic.otf in Resources */,
|
||||
0A6918EB0654476189741475 /* Inter-Light.otf in Resources */,
|
||||
@@ -522,7 +515,6 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
00E356F31AD99517003FC87E /* ProofOfPassportTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -616,9 +608,105 @@
|
||||
CODE_SIGN_ENTITLEMENTS = ProofOfPassport/ProofOfPassport.entitlements;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 42;
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/DoubleConversion\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/MoproKit\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/NFCPassportReader\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZParser\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZScanner\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCTTypeSafety\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNCClipboard\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNSVG\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Codegen\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Core\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-CoreModules\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAnimation\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAppDelegate\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTBlob\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTImage\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTLinking\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTNetwork\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTSettings\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTText\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTVibration\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-cxxreact\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-debug\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsc\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsi\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsiexecutor\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsinspector\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-logger\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-perflogger\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimescheduler\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-utils\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyTesseract\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/Yoga\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/fmt\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/glog\"",
|
||||
"\"${PODS_ROOT}/OpenSSL-Universal/Frameworks\"",
|
||||
"\"${PODS_ROOT}/SwiftyTesseract/SwiftyTesseract\"",
|
||||
"\"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal\"",
|
||||
"\"${PODS_XCFRAMEWORKS_BUILD_DIR}/SwiftyTesseract\"",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/DoubleConversion/DoubleConversion.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/MoproKit/MoproKit.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/NFCPassportReader/NFCPassportReader.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZParser/QKMRZParser.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZScanner/QKMRZScanner.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly/folly.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCTTypeSafety/RCTTypeSafety.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNCClipboard/RNCClipboard.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNSVG/RNSVG.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Codegen/React_Codegen.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/React.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-CoreModules/CoreModules.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAnimation/RCTAnimation.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAppDelegate/React_RCTAppDelegate.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTBlob/RCTBlob.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTImage/RCTImage.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTLinking/RCTLinking.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTNetwork/RCTNetwork.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTSettings/RCTSettings.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTText/RCTText.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTVibration/RCTVibration.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-cxxreact/cxxreact.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-debug/React_debug.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsc/React_jsc.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsi/jsi.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsiexecutor/jsireact.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsinspector/jsinspector.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-logger/logger.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-perflogger/reactperflogger.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimescheduler/React_runtimescheduler.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-utils/React_utils.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket/SocketRocket.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyTesseract/SwiftyTesseract.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/Yoga/yoga.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/fmt/fmt.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/glog/glog.framework/Headers\"",
|
||||
"\"${PODS_ROOT}/Headers/Public\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/FBLazyVector\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/RCTRequired\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/React-callinvoker\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/React-runtimeexecutor\"",
|
||||
"\"$(PODS_ROOT)/DoubleConversion\"",
|
||||
"\"$(PODS_ROOT)/boost\"",
|
||||
"\"$(PODS_ROOT)/Headers/Private/React-Core\"",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
INFOPLIST_FILE = ProofOfPassport/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@@ -641,6 +729,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.warroom.proofofpassport;
|
||||
PRODUCT_NAME = ProofOfPassport;
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/ProofOfPassport-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
@@ -654,8 +743,104 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = ProofOfPassport/ProofOfPassport.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 42;
|
||||
DEVELOPMENT_TEAM = 5B29R5LYHQ;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/DoubleConversion\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/MoproKit\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/NFCPassportReader\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZParser\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZScanner\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCTTypeSafety\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNCClipboard\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNSVG\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Codegen\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Core\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-CoreModules\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAnimation\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAppDelegate\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTBlob\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTImage\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTLinking\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTNetwork\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTSettings\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTText\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTVibration\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-cxxreact\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-debug\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsc\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsi\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsiexecutor\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsinspector\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-logger\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-perflogger\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimescheduler\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-utils\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyTesseract\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/Yoga\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/fmt\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/glog\"",
|
||||
"\"${PODS_ROOT}/OpenSSL-Universal/Frameworks\"",
|
||||
"\"${PODS_ROOT}/SwiftyTesseract/SwiftyTesseract\"",
|
||||
"\"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal\"",
|
||||
"\"${PODS_XCFRAMEWORKS_BUILD_DIR}/SwiftyTesseract\"",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
HEADER_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/DoubleConversion/DoubleConversion.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/MoproKit/MoproKit.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/NFCPassportReader/NFCPassportReader.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZParser/QKMRZParser.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/QKMRZScanner/QKMRZScanner.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly/folly.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RCTTypeSafety/RCTTypeSafety.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNCClipboard/RNCClipboard.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/RNSVG/RNSVG.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Codegen/React_Codegen.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-Core/React.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-CoreModules/CoreModules.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-NativeModulesApple/React_NativeModulesApple.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAnimation/RCTAnimation.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAppDelegate/React_RCTAppDelegate.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTBlob/RCTBlob.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTImage/RCTImage.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTLinking/RCTLinking.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTNetwork/RCTNetwork.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTSettings/RCTSettings.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTText/RCTText.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTVibration/RCTVibration.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-cxxreact/cxxreact.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-debug/React_debug.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsc/React_jsc.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsi/jsi.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsiexecutor/jsireact.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-jsinspector/jsinspector.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-logger/logger.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-perflogger/reactperflogger.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-runtimescheduler/React_runtimescheduler.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/React-utils/React_utils.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SocketRocket/SocketRocket.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/SwiftyTesseract/SwiftyTesseract.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/Yoga/yoga.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/fmt/fmt.framework/Headers\"",
|
||||
"\"${PODS_CONFIGURATION_BUILD_DIR}/glog/glog.framework/Headers\"",
|
||||
"\"${PODS_ROOT}/Headers/Public\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/FBLazyVector\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/RCTRequired\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/React-callinvoker\"",
|
||||
"\"${PODS_ROOT}/Headers/Public/React-runtimeexecutor\"",
|
||||
"\"$(PODS_ROOT)/DoubleConversion\"",
|
||||
"\"$(PODS_ROOT)/boost\"",
|
||||
"\"$(PODS_ROOT)/Headers/Private/React-Core\"",
|
||||
"$(PROJECT_DIR)",
|
||||
);
|
||||
INFOPLIST_FILE = ProofOfPassport/Info.plist;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
@@ -676,6 +861,7 @@
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.warroom.proofofpassport;
|
||||
PRODUCT_NAME = ProofOfPassport;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/ProofOfPassport-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
};
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"filename" : "proof_of_passport.dat",
|
||||
"idiom" : "universal",
|
||||
"universal-type-identifier" : "dyn.ah62d4rv4ge80k2py"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"filename" : "proof_of_passport.zkey",
|
||||
"idiom" : "universal",
|
||||
"universal-type-identifier" : "dyn.ah62d4rv4ge81y45fte"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -10,16 +10,10 @@
|
||||
|
||||
@interface RCT_EXTERN_MODULE(Prover, NSObject)
|
||||
|
||||
RCT_EXTERN_METHOD(runInitAction:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(runProveAction:(NSDictionary *)inputs
|
||||
resolve:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(runVerifyAction:(RCTPromiseResolveBlock)resolve
|
||||
reject:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
+ (BOOL) requiresMainQueueSetup {
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -8,133 +8,152 @@
|
||||
import Foundation
|
||||
import React
|
||||
import Security
|
||||
import MoproKit
|
||||
|
||||
#if canImport(witnesscalc_proof_of_passport)
|
||||
import witnesscalc_proof_of_passport
|
||||
#endif
|
||||
|
||||
#if canImport(groth16_prover)
|
||||
import groth16_prover
|
||||
#endif
|
||||
|
||||
struct Proof: Codable {
|
||||
let piA: [String]
|
||||
let piB: [[String]]
|
||||
let piC: [String]
|
||||
let proofProtocol: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case piA = "pi_a"
|
||||
case piB = "pi_b"
|
||||
case piC = "pi_c"
|
||||
case proofProtocol = "protocol"
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 15, *)
|
||||
@objc(Prover)
|
||||
class Prover: NSObject {
|
||||
@objc(runProveAction:resolve:reject:)
|
||||
func runProveAction(_ inputs: [String: [String]], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
do {
|
||||
let inputsJson = try! JSONEncoder().encode(inputs)
|
||||
print("inputs size: \(inputsJson.count) bytes")
|
||||
print("inputs data: \(String(data: inputsJson, encoding: .utf8) ?? "")")
|
||||
|
||||
let wtns = try! calcWtns(inputsJson: inputsJson)
|
||||
print("wtns size: \(wtns.count) bytes")
|
||||
|
||||
let moproCircom = MoproKit.MoproCircom()
|
||||
var generatedProof: Data?
|
||||
var publicInputs: Data?
|
||||
let (proofRaw, pubSignalsRaw) = try groth16prove(wtns: wtns)
|
||||
let proof = try JSONDecoder().decode(Proof.self, from: proofRaw)
|
||||
let pubSignals = try JSONDecoder().decode([String].self, from: pubSignalsRaw)
|
||||
|
||||
@objc(runInitAction:reject:)
|
||||
func runInitAction(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { // Update the textView on the main thread
|
||||
print("Initializing library")
|
||||
let proofObject: [String: Any] = [
|
||||
"proof": [
|
||||
"a": proof.piA,
|
||||
"b": proof.piB,
|
||||
"c": proof.piC,
|
||||
],
|
||||
"inputs": pubSignals
|
||||
]
|
||||
|
||||
// Execute long-running tasks in the background
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
// Record start time
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
do {
|
||||
try initializeMopro()
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
|
||||
// Log the time taken for initialization
|
||||
print("Initializing arkzkey took \(timeTaken) seconds.")
|
||||
resolve("Done")
|
||||
} catch {
|
||||
// Log any errors that occurred during initialization
|
||||
print("An error occurred during initialization: \(error)")
|
||||
reject("PROVER", "An error occurred during initialization", error)
|
||||
}
|
||||
let proofData = try JSONSerialization.data(withJSONObject: proofObject, options: [])
|
||||
let proofObjectString = String(data: proofData, encoding: .utf8) ?? ""
|
||||
print("Whole proof: \(proofObjectString)")
|
||||
resolve(proofObjectString)
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
reject("PROVER", "An error occurred during proof generation", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc(runProveAction:resolve:reject:)
|
||||
func runProveAction(_ inputs: [String: [String]], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
// Logic for prove (generate_proof2)
|
||||
do {
|
||||
// format of inputs, if you want to manage it manually:
|
||||
|
||||
// WORKING, SAMPLE DATA:
|
||||
// let mrz: [String] = ["97","91","95","31","88","80","60","70","82","65","68","85","80","79","78","84","60","60","65","76","80","72","79","78","83","69","60","72","85","71","85","69","83","60","65","76","66","69","82","84","60","60","60","60","60","60","60","60","60","50","52","72","66","56","49","56","51","50","52","70","82","65","48","52","48","50","49","49","49","77","51","49","49","49","49","49","53","60","60","60","60","60","60","60","60","60","60","60","60","60","60","48","50"]
|
||||
// let reveal_bitmap: [String] = ["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"]
|
||||
// let dataHashes: [String] = ["48","130","1","37","2","1","0","48","11","6","9","96","134","72","1","101","3","4","2","1","48","130","1","17","48","37","2","1","1","4","32","176","223","31","133","108","84","158","102","70","11","165","175","196","12","201","130","25","131","46","125","156","194","28","23","55","133","157","164","135","136","220","78","48","37","2","1","2","4","32","190","82","180","235","222","33","79","50","152","136","142","35","116","224","6","242","156","141","128","248","10","61","98","86","248","45","207","210","90","232","175","38","48","37","2","1","3","4","32","0","194","104","108","237","246","97","230","116","198","69","110","26","87","17","89","110","199","108","250","36","21","39","87","110","102","250","213","174","131","171","174","48","37","2","1","11","4","32","136","155","87","144","111","15","152","127","85","25","154","81","20","58","51","75","193","116","234","0","60","30","29","30","183","141","72","247","255","203","100","124","48","37","2","1","12","4","32","41","234","106","78","31","11","114","137","237","17","92","71","134","47","62","78","189","233","201","214","53","4","47","189","201","133","6","121","34","131","64","142","48","37","2","1","13","4","32","91","222","210","193","62","222","104","82","36","41","138","253","70","15","148","208","156","45","105","171","241","195","185","43","217","162","146","201","222","89","238","38","48","37","2","1","14","4","32","76","123","216","13","51","227","72","245","59","193","238","166","103","49","23","164","171","188","194","197","156","187","249","28","198","95","69","15","182","56","54","38"]
|
||||
// let eContentBytes: [String] = ["49","102","48","21","6","9","42","134","72","134","247","13","1","9","3","49","8","6","6","103","129","8","1","1","1","48","28","6","9","42","134","72","134","247","13","1","9","5","49","15","23","13","49","57","49","50","49","54","49","55","50","50","51","56","90","48","47","6","9","42","134","72","134","247","13","1","9","4","49","34","4","32","32","85","108","174","127","112","178","182","8","43","134","123","192","211","131","66","184","240","212","181","240","180","106","195","24","117","54","129","19","10","250","53"]
|
||||
// let signature: [String] = ["7924608050410952186","18020331358710788578","8570093713362871693","158124167841380627","11368970785933558334","13741644704804016484","3255497432248429697","18325134696633464276","11159517223698754974","14221210644107127310","18395843719389189885","14516795783073238806","2008163829408627473","10489977208787195755","11349558951945231290","10261182129521943851","898517390497363184","7991226362010359134","16695870541274258886","3471091665352332245","9966265751297511656","15030994431171601215","10723494832064770597","14939163534927288303","13596611050508022203","12058746125656824488","7806259275107295093","9171418878976478189","16438005721800053020","315207309308375554","3950355816720285857","5415176625244763446"]
|
||||
// let pubkey: [String] = ["10501872816920780427","9734403015003984321","14411195268255541454","5140370262757446136","442944543003039303","2084906169692591819","13619051978156646232","11308439966240653768","11784026229075891869","3619707049269329199","14678094225574041482","13372281921787791985","5760458619375959191","1351001273751492154","9127780359628047919","5377643070972775368","14145972494784958946","295160036043261024","12244573192558293296","13273111070076476096","15787778596745267629","12026125372525341435","17186889501189543072","1678833675164196298","11525741336698300342","9004411014119053043","3653149686233893817","3525782291631180893","13397424121878903415","12208454420188007950","5024240771370648155","15842149209258762075"]
|
||||
// let address: [String] = ["897585614395172552642670145532424661022951192962"] // decimal of 0x9D392187c08fc28A86e1354aD63C70897165b982
|
||||
|
||||
// var inputs = [String: [String]]()
|
||||
// inputs["mrz"] = mrz;
|
||||
// inputs["reveal_bitmap"] = reveal_bitmap;
|
||||
// inputs["dataHashes"] = dataHashes;
|
||||
// inputs["eContentBytes"] = eContentBytes;
|
||||
// inputs["signature"] = signature;
|
||||
// inputs["pubkey"] = pubkey;
|
||||
// inputs["address"] = address;
|
||||
|
||||
print(inputs)
|
||||
|
||||
let start = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
// Generate Proof
|
||||
let generateProofResult = try generateProof2(circuitInputs: inputs)
|
||||
assert(!generateProofResult.proof.isEmpty, "Proof should not be empty")
|
||||
|
||||
// Record end time and compute duration
|
||||
let end = CFAbsoluteTimeGetCurrent()
|
||||
let timeTaken = end - start
|
||||
print("Proof generation took \(timeTaken) seconds.")
|
||||
|
||||
// Store the generated proof and public inputs for later verification
|
||||
print("generateProofResult", generateProofResult)
|
||||
generatedProof = generateProofResult.proof
|
||||
publicInputs = generateProofResult.inputs
|
||||
|
||||
// Convert Data to array of bytes
|
||||
let proofBytes = [UInt8](generateProofResult.proof)
|
||||
let inputsBytes = [UInt8](generateProofResult.inputs)
|
||||
|
||||
print("proofBytes", proofBytes)
|
||||
print("inputsBytes", inputsBytes)
|
||||
|
||||
// Create a dictionary with byte arrays
|
||||
let resultDict: [String: [UInt8]] = [
|
||||
"proof": proofBytes,
|
||||
"inputs": inputsBytes
|
||||
]
|
||||
|
||||
// Serialize dictionary to JSON
|
||||
let jsonData = try JSONSerialization.data(withJSONObject: resultDict, options: [])
|
||||
let jsonString = String(data: jsonData, encoding: .utf8)!
|
||||
|
||||
resolve(jsonString)
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
reject("PROVER", "An error occurred during proof generation", error)
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
reject("PROVER", "An error occurred during proof generation", error)
|
||||
}
|
||||
}
|
||||
|
||||
@objc(runVerifyAction:reject:)
|
||||
func runVerifyAction(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
// Logic for verify
|
||||
guard let proof = generatedProof,
|
||||
let publicInputs = publicInputs else {
|
||||
print("Proof has not been generated yet.")
|
||||
return
|
||||
}
|
||||
do {
|
||||
// Verify Proof
|
||||
let isValid = try verifyProof2(proof: proof, publicInput: publicInputs)
|
||||
assert(isValid, "Proof verification should succeed")
|
||||
|
||||
print("Proof verification succeeded.")
|
||||
resolve(isValid)
|
||||
} catch let error as MoproError {
|
||||
print("MoproError: \(error)")
|
||||
reject("PROVER", "An error occurred during proof verification", error)
|
||||
} catch {
|
||||
print("Unexpected error: \(error)")
|
||||
reject("PROVER", "An error occurred during proof verification", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func calcWtns(inputsJson: Data) throws -> Data {
|
||||
let dat = NSDataAsset(name: "proof_of_passport.dat")!.data
|
||||
return try _calcWtns(dat: dat, jsonData: inputsJson)
|
||||
}
|
||||
|
||||
private func _calcWtns(dat: Data, jsonData: Data) throws -> Data {
|
||||
let datSize = UInt(dat.count)
|
||||
let jsonDataSize = UInt(jsonData.count)
|
||||
|
||||
let errorSize = UInt(256);
|
||||
|
||||
let wtnsSize = UnsafeMutablePointer<UInt>.allocate(capacity: Int(1));
|
||||
wtnsSize.initialize(to: UInt(100 * 1024 * 1024 ))
|
||||
|
||||
let wtnsBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: (100 * 1024 * 1024))
|
||||
let errorBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(errorSize))
|
||||
|
||||
let result = witnesscalc_proof_of_passport(
|
||||
(dat as NSData).bytes, datSize,
|
||||
(jsonData as NSData).bytes, jsonDataSize,
|
||||
wtnsBuffer, wtnsSize,
|
||||
errorBuffer, errorSize
|
||||
)
|
||||
|
||||
if result == WITNESSCALC_ERROR {
|
||||
let errorMessage = String(bytes: Data(bytes: errorBuffer, count: Int(errorSize)), encoding: .utf8)!
|
||||
.replacingOccurrences(of: "\0", with: "")
|
||||
throw NSError(domain: "WitnessCalculationError", code: Int(WITNESSCALC_ERROR), userInfo: [NSLocalizedDescriptionKey: errorMessage])
|
||||
}
|
||||
|
||||
if result == WITNESSCALC_ERROR_SHORT_BUFFER {
|
||||
let shortBufferMessage = "Short buffer, required size: \(wtnsSize.pointee)"
|
||||
throw NSError(domain: "WitnessCalculationError", code: Int(WITNESSCALC_ERROR_SHORT_BUFFER), userInfo: [NSLocalizedDescriptionKey: shortBufferMessage])
|
||||
}
|
||||
return Data(bytes: wtnsBuffer, count: Int(wtnsSize.pointee))
|
||||
}
|
||||
|
||||
public func groth16prove(wtns: Data) throws -> (proof: Data, publicInputs: Data) {
|
||||
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let zkeyURL = documentsPath.appendingPathComponent("proof_of_passport.zkey")
|
||||
|
||||
guard let zkeyData = try? Data(contentsOf: zkeyURL) else {
|
||||
throw NSError(domain: "YourErrorDomain", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to load zkey file."])
|
||||
}
|
||||
|
||||
return try _groth16Prover(zkey: zkeyData, wtns: wtns)
|
||||
}
|
||||
|
||||
public func _groth16Prover(zkey: Data, wtns: Data) throws -> (proof: Data, publicInputs: Data) {
|
||||
let zkeySize = zkey.count
|
||||
let wtnsSize = wtns.count
|
||||
|
||||
var proofSize: UInt = 4 * 1024 * 1024
|
||||
var publicSize: UInt = 4 * 1024 * 1024
|
||||
|
||||
let proofBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(proofSize))
|
||||
let publicBuffer = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(publicSize))
|
||||
|
||||
let errorBuffer = UnsafeMutablePointer<Int8>.allocate(capacity: 256)
|
||||
let errorMaxSize: UInt = 256
|
||||
|
||||
let result = groth16_prover(
|
||||
(zkey as NSData).bytes, UInt(zkeySize),
|
||||
(wtns as NSData).bytes, UInt(wtnsSize),
|
||||
proofBuffer, &proofSize,
|
||||
publicBuffer, &publicSize,
|
||||
errorBuffer, errorMaxSize
|
||||
)
|
||||
if result == PROVER_ERROR {
|
||||
let errorMessage = String(bytes: Data(bytes: errorBuffer, count: Int(errorMaxSize)), encoding: .utf8)!
|
||||
.replacingOccurrences(of: "\0", with: "")
|
||||
throw NSError(domain: "", code: Int(result), userInfo: [NSLocalizedDescriptionKey: errorMessage])
|
||||
}
|
||||
|
||||
if result == PROVER_ERROR_SHORT_BUFFER {
|
||||
let shortBufferMessage = "Proof or public inputs buffer is too short"
|
||||
throw NSError(domain: "", code: Int(result), userInfo: [NSLocalizedDescriptionKey: shortBufferMessage])
|
||||
}
|
||||
var proof = Data(bytes: proofBuffer, count: Int(proofSize))
|
||||
var publicInputs = Data(bytes: publicBuffer, count: Int(publicSize))
|
||||
|
||||
let proofNullIndex = proof.firstIndex(of: 0x00)!
|
||||
let publicInputsNullIndex = publicInputs.firstIndex(of: 0x00)!
|
||||
|
||||
proof = proof[0..<proofNullIndex]
|
||||
publicInputs = publicInputs[0..<publicInputsNullIndex]
|
||||
|
||||
return (proof: proof, publicInputs: publicInputs)
|
||||
}
|
||||
32
app/ios/groth16_prover.h
Normal file
32
app/ios/groth16_prover.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef PROVER_HPP
|
||||
#define PROVER_HPP
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//Error codes returned by the functions.
|
||||
#define PROVER_OK 0x0
|
||||
#define PROVER_ERROR 0x1
|
||||
#define PROVER_ERROR_SHORT_BUFFER 0x2
|
||||
|
||||
|
||||
/**
|
||||
* @return error code:
|
||||
* PRPOVER_OK - in case of success.
|
||||
* PPROVER_ERROR - in case of an error.
|
||||
*/
|
||||
|
||||
int
|
||||
groth16_prover(const void *zkey_buffer, unsigned long zkey_size,
|
||||
const void *wtns_buffer, unsigned long wtns_size,
|
||||
char *proof_buffer, unsigned long *proof_size,
|
||||
char *public_buffer, unsigned long *public_size,
|
||||
char *error_msg, unsigned long error_msg_maxsize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // PROVER_HPP
|
||||
BIN
app/ios/libfq.a
Normal file
BIN
app/ios/libfq.a
Normal file
Binary file not shown.
BIN
app/ios/libfr.a
Normal file
BIN
app/ios/libfr.a
Normal file
Binary file not shown.
BIN
app/ios/libgmp.a
Normal file
BIN
app/ios/libgmp.a
Normal file
Binary file not shown.
BIN
app/ios/librapidsnark.a
Normal file
BIN
app/ios/librapidsnark.a
Normal file
Binary file not shown.
BIN
app/ios/libwitnesscalc_proof_of_passport.a
Normal file
BIN
app/ios/libwitnesscalc_proof_of_passport.a
Normal file
Binary file not shown.
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# update xcconfig
|
||||
MODES="debug release"
|
||||
XCCONFIG_PATH=Pods/Target\ Support\ Files/MoproKit
|
||||
CONFIGS="
|
||||
LIBRARY_SEARCH_PATHS=\${SRCROOT}/../MoproKit/Libs
|
||||
OTHER_LDFLAGS=-lmopro_ffi
|
||||
USER_HEADER_SEARCH_PATHS=\${SRCROOT}/../MoproKit/include
|
||||
"
|
||||
for mode in ${MODES}
|
||||
do
|
||||
FILE_NAME=${XCCONFIG_PATH}/MoproKit.${mode}.xcconfig
|
||||
for config in ${CONFIGS}; do
|
||||
EXIST=$(grep -c "${config}" "${FILE_NAME}")
|
||||
if [[ $EXIST -eq 0 ]]; then
|
||||
echo "${config}" >> "${FILE_NAME}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo "Finished updating xcconfig"
|
||||
41
app/ios/witnesscalc_proof_of_passport.h
Normal file
41
app/ios/witnesscalc_proof_of_passport.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef WITNESSCALC_PROOFOFPASSPORT_H
|
||||
#define WITNESSCALC_PROOFOFPASSPORT_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_proof_of_passport(
|
||||
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 // WITNESSCALC_PROOFOFPASSPORT_H
|
||||
|
||||
|
||||
#endif // WITNESSCALC_PROOFOFPASSPORT_H
|
||||
@@ -5,9 +5,9 @@ use self::{
|
||||
use crate::MoproError;
|
||||
|
||||
use std::collections::HashMap;
|
||||
//use std::io::Cursor;
|
||||
use std::sync::Mutex;
|
||||
use std::time::Instant;
|
||||
use std::fs;
|
||||
|
||||
use ark_bn254::{Bn254, Fr};
|
||||
use ark_circom::{
|
||||
@@ -15,7 +15,7 @@ use ark_circom::{
|
||||
CircomCircuit,
|
||||
CircomConfig,
|
||||
CircomReduction,
|
||||
WitnessCalculator, //read_zkey,
|
||||
WitnessCalculator,
|
||||
};
|
||||
use ark_crypto_primitives::snark::SNARK;
|
||||
use ark_groth16::{prepare_verifying_key, Groth16, ProvingKey};
|
||||
@@ -30,13 +30,7 @@ use once_cell::sync::{Lazy, OnceCell};
|
||||
|
||||
use wasmer::{Module, Store};
|
||||
|
||||
use ark_zkey::read_arkzkey_from_bytes; //SerializableConstraintMatrices
|
||||
|
||||
#[cfg(feature = "dylib")]
|
||||
use {
|
||||
std::{env, path::Path},
|
||||
wasmer::Dylib,
|
||||
};
|
||||
use ark_zkey::{read_arkzkey_from_bytes};
|
||||
|
||||
pub mod serialization;
|
||||
pub mod utils;
|
||||
@@ -61,22 +55,11 @@ impl Default for CircomState {
|
||||
|
||||
// NOTE: A lot of the contents of this file is inspired by github.com/worldcoin/semaphore-rs
|
||||
|
||||
// TODO: Replace printlns with logging
|
||||
|
||||
//const ZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ZKEY_FILE"));
|
||||
|
||||
const ARKZKEY_BYTES: &[u8] = include_bytes!(env!("BUILD_RS_ARKZKEY_FILE"));
|
||||
|
||||
// static ZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
|
||||
// let mut reader = Cursor::new(ZKEY_BYTES);
|
||||
// read_zkey(&mut reader).expect("Failed to read zkey")
|
||||
// });
|
||||
|
||||
static ARKZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
|
||||
//let mut reader = Cursor::new(ARKZKEY_BYTES);
|
||||
// TODO: Use reader? More flexible; unclear if perf diff
|
||||
read_arkzkey_from_bytes(ARKZKEY_BYTES).expect("Failed to read arkzkey")
|
||||
});
|
||||
// const fileName = "passport.arkzkey"
|
||||
// const path = "/data/user/0/com.proofofpassport/files/" + fileName
|
||||
// const ZKEY_PATH_STR: &str = "proof_of_passport.arkzkey";
|
||||
const ZKEY_PATH_STR: &str = "/data/user/0/com.proofofpassport/files/proof_of_passport.zkey";
|
||||
|
||||
const WASM: &[u8] = include_bytes!(env!("BUILD_RS_WASM_FILE"));
|
||||
|
||||
@@ -85,79 +68,31 @@ const WASM: &[u8] = include_bytes!(env!("BUILD_RS_WASM_FILE"));
|
||||
/// access from multiple threads.
|
||||
static WITNESS_CALCULATOR: OnceCell<Mutex<WitnessCalculator>> = OnceCell::new();
|
||||
|
||||
/// Initializes the `WITNESS_CALCULATOR` singleton with a `WitnessCalculator` instance created from
|
||||
/// a specified dylib file (WASM circuit). Also initialize `ZKEY`.
|
||||
#[cfg(feature = "dylib")]
|
||||
pub fn initialize(dylib_path: &Path) {
|
||||
println!("Initializing dylib: {:?}", dylib_path);
|
||||
static ARKZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
|
||||
let bytes = fs::read(ZKEY_PATH_STR).map_err(|e| MoproError::CircomError(e.to_string())).unwrap();
|
||||
read_arkzkey_from_bytes(&bytes).map_err(|e| MoproError::CircomError(e.to_string())).unwrap()
|
||||
});
|
||||
|
||||
WITNESS_CALCULATOR
|
||||
.set(from_dylib(dylib_path))
|
||||
.expect("Failed to set WITNESS_CALCULATOR");
|
||||
|
||||
// Initialize ARKZKEY
|
||||
// TODO: Speed this up even more
|
||||
let now = std::time::Instant::now();
|
||||
Lazy::force(&ARKZKEY);
|
||||
println!("Initializing arkzkey took: {:.2?}", now.elapsed());
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "dylib"))]
|
||||
pub fn initialize() {
|
||||
println!("Initializing library with arkzkey");
|
||||
|
||||
// Initialize ARKZKEY
|
||||
// TODO: Speed this up even more!
|
||||
let now = std::time::Instant::now();
|
||||
Lazy::force(&ARKZKEY);
|
||||
println!("Initializing arkzkey took: {:.2?}", now.elapsed());
|
||||
}
|
||||
|
||||
/// Creates a `WitnessCalculator` instance from a dylib file.
|
||||
#[cfg(feature = "dylib")]
|
||||
fn from_dylib(path: &Path) -> Mutex<WitnessCalculator> {
|
||||
let store = Store::new(&Dylib::headless().engine());
|
||||
let module = unsafe {
|
||||
Module::deserialize_from_file(&store, path).expect("Failed to load dylib module")
|
||||
};
|
||||
let result =
|
||||
WitnessCalculator::from_module(module).expect("Failed to create WitnessCalculator");
|
||||
|
||||
Mutex::new(result)
|
||||
}
|
||||
|
||||
// #[must_use]
|
||||
// pub fn zkey() -> &'static (ProvingKey<Bn254>, ConstraintMatrices<Fr>) {
|
||||
// &ZKEY
|
||||
// fn load_arkzkey_from_file(
|
||||
// zkey_path: &str,
|
||||
// ) -> Result<(ProvingKey<Bn254>, ConstraintMatrices<Fr>), MoproError> {
|
||||
// let bytes = fs::read(zkey_path).map_err(|e| MoproError::CircomError(e.to_string()))?;
|
||||
// read_arkzkey_from_bytes(&bytes).map_err(|e| MoproError::CircomError(e.to_string()))
|
||||
// }
|
||||
|
||||
// Experimental
|
||||
#[must_use]
|
||||
pub fn arkzkey() -> &'static (ProvingKey<Bn254>, ConstraintMatrices<Fr>) {
|
||||
&ARKZKEY
|
||||
pub fn arkzkey() -> (ProvingKey<Bn254>, ConstraintMatrices<Fr>) {
|
||||
// load_arkzkey_from_file(zkey_path).unwrap()
|
||||
ARKZKEY.clone()
|
||||
}
|
||||
|
||||
/// Provides access to the `WITNESS_CALCULATOR` singleton, initializing it if necessary.
|
||||
/// It expects the path to the dylib file to be set in the `CIRCUIT_WASM_DYLIB` environment variable.
|
||||
#[cfg(feature = "dylib")]
|
||||
#[must_use]
|
||||
pub fn witness_calculator() -> &'static Mutex<WitnessCalculator> {
|
||||
let var_name = "CIRCUIT_WASM_DYLIB";
|
||||
|
||||
WITNESS_CALCULATOR.get_or_init(|| {
|
||||
let path = env::var(var_name).unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Mopro circuit WASM Dylib not initialized. \
|
||||
Please set {} environment variable to the path of the dylib file",
|
||||
var_name
|
||||
)
|
||||
});
|
||||
from_dylib(Path::new(&path))
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "dylib"))]
|
||||
#[must_use]
|
||||
pub fn witness_calculator() -> &'static Mutex<WitnessCalculator> {
|
||||
WITNESS_CALCULATOR.get_or_init(|| {
|
||||
let store = Store::default();
|
||||
@@ -189,7 +124,7 @@ pub fn generate_proof2(
|
||||
println!("Witness generation took: {:.2?}", now.elapsed());
|
||||
|
||||
let now = std::time::Instant::now();
|
||||
//let zkey = zkey();
|
||||
|
||||
let zkey = arkzkey();
|
||||
println!("Loading arkzkey took: {:.2?}", now.elapsed());
|
||||
|
||||
@@ -210,7 +145,6 @@ pub fn generate_proof2(
|
||||
|
||||
println!("proof generation took: {:.2?}", now.elapsed());
|
||||
|
||||
// TODO: Add SerializableInputs(inputs)))
|
||||
Ok((SerializableProof(proof), SerializableInputs(public_inputs)))
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.3",
|
||||
"react-native-canvas": "^0.1.39",
|
||||
"react-native-fs": "^2.20.0",
|
||||
"react-native-passport-reader": "^1.0.3",
|
||||
"react-native-svg": "13.4.0",
|
||||
"tamagui": "^1.94.3"
|
||||
|
||||
@@ -1,55 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This is adapted from mopro
|
||||
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
|
||||
|
||||
ARCHITECTURE="aarch64-apple-ios" # or "x86_64-apple-ios" for "x86_64", "aarch64-apple-ios-sim" for simulator
|
||||
LIB_DIR="release" # or "debug"
|
||||
PROJECT_DIR=$(pwd)
|
||||
|
||||
# Assert we're in the /app dir
|
||||
if [[ ! -d "mopro-ffi" || ! -d "mopro-core" || ! -d "ark-zkey" ]]; then
|
||||
echo -e "${RED}Error: This script must be run from the /app dir that contains mopro-ffi, mopro-core and ark-zkey folders.${DEFAULT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for target support
|
||||
check_target_support() {
|
||||
rustup target list | grep installed | grep -q "$1"
|
||||
}
|
||||
|
||||
# check target is installed
|
||||
if ! check_target_support $ARCHITECTURE; then
|
||||
rustup target add $ARCHITECTURE
|
||||
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
|
||||
echo "Target $ARCHITECTURE already installed, skipping."
|
||||
# Linux
|
||||
sed -i "${last_include}a \\nnamespace CIRCUIT_NAME {" proof_of_passport.cpp
|
||||
fi
|
||||
echo "}" >> proof_of_passport.cpp
|
||||
|
||||
cd ../../..
|
||||
git submodule init
|
||||
git submodule update
|
||||
|
||||
cd mopro-core
|
||||
cargo build --release
|
||||
cd app/witnesscalc
|
||||
./build_gmp.sh ios
|
||||
make ios
|
||||
|
||||
cd ../mopro-ffi
|
||||
echo "Building mopro-ffi static library..."
|
||||
cargo build --release --target ${ARCHITECTURE}
|
||||
cp target/${ARCHITECTURE}/${LIB_DIR}/libmopro_ffi.a ../ios/MoproKit/Libs/
|
||||
echo "copied libmopro_ffi.a to ios/Moprokit/Libs/"
|
||||
|
||||
cd ../ios
|
||||
pod install
|
||||
./post_install.sh
|
||||
|
||||
# TODO: if functions signatures change, we have to rebuild the bindings by adapting theses lines:
|
||||
# cd ..
|
||||
# Install uniffi-bindgen binary in mopro-ffi
|
||||
# echo "[ffi] Installing uniffi-bindgen..."
|
||||
# if ! command -v uniffi-bindgen &> /dev/null
|
||||
# then
|
||||
# cargo install --bin uniffi-bindgen --path .
|
||||
# else
|
||||
# echo "uniffi-bindgen already installed, skipping."
|
||||
# fi
|
||||
# echo "Updating mopro-ffi bindings and library..."
|
||||
# uniffi-bindgen generate mopro-ffi/src/mopro.udl --language swift --out-dir ${TARGET_DIR}/SwiftBindings
|
||||
# cp ${TARGET_DIR}/SwiftBindings/moproFFI.h ${MOPROKIT_DIR}/Include/
|
||||
# cp ${TARGET_DIR}/SwiftBindings/mopro.swift ${MOPROKIT_DIR}/Bindings/
|
||||
# cp ${TARGET_DIR}/SwiftBindings/moproFFI.modulemap ${MOPROKIT_DIR}/Resources/
|
||||
cd build_witnesscalc_ios
|
||||
xcodebuild -project witnesscalc.xcodeproj \
|
||||
-scheme proof_of_passport \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
DEVELOPMENT_TEAM="$DEVELOPMENT_TEAM" \
|
||||
ARCHS="arm64" \
|
||||
-destination 'generic/platform=iOS' \
|
||||
PRODUCT_BUNDLE_IDENTIFIER=com.warrom.witnesscalc \
|
||||
build
|
||||
cd ../..
|
||||
cp witnesscalc/build_witnesscalc_ios/src/Release-iphoneos/libwitnesscalc_proof_of_passport.a ios
|
||||
cp witnesscalc/src/proof_of_passport.dat ios/ProofOfPassport/Assets.xcassets/proof_of_passport.dat.dataset/proof_of_passport.dat
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p ../circuits/build
|
||||
cd ../circuits/build
|
||||
if [ -f "proof_of_passport_final.zkey" ]; then
|
||||
echo "found old proof_of_passport_final.zkey, deleting it"
|
||||
rm "proof_of_passport_final.zkey"
|
||||
fi
|
||||
echo "downloading proof_of_passport_final.zkey to /circuits/build/"
|
||||
wget https://current-pop-zkey.s3.eu-north-1.amazonaws.com/proof_of_passport_final_merkle_and_age.arkzkey
|
||||
mv proof_of_passport_final_merkle_and_age.arkzkey proof_of_passport_final.arkzkey
|
||||
@@ -27,7 +27,7 @@ interface MainScreenProps {
|
||||
address: string;
|
||||
setAddress: (address: string) => void;
|
||||
generatingProof: boolean;
|
||||
handleProve: (path: string) => void;
|
||||
handleProve: () => void;
|
||||
step: number;
|
||||
mintText: string;
|
||||
proof: any;
|
||||
@@ -42,6 +42,7 @@ interface MainScreenProps {
|
||||
setDateOfExpiry: (date: string) => void;
|
||||
majority: number;
|
||||
setMajority: (age: number) => void;
|
||||
zkeydownloadStatus: string;
|
||||
}
|
||||
|
||||
const MainScreen: React.FC<MainScreenProps> = ({
|
||||
@@ -67,7 +68,8 @@ const MainScreen: React.FC<MainScreenProps> = ({
|
||||
dateOfExpiry,
|
||||
setDateOfExpiry,
|
||||
majority,
|
||||
setMajority
|
||||
setMajority,
|
||||
zkeydownloadStatus
|
||||
}) => {
|
||||
const [NFCScanIsOpen, setNFCScanIsOpen] = useState(false);
|
||||
const [SettingsIsOpen, setSettingsIsOpen] = useState(false);
|
||||
@@ -431,7 +433,9 @@ const MainScreen: React.FC<MainScreenProps> = ({
|
||||
ens={ens}
|
||||
setEns={setEns}
|
||||
majority={majority}
|
||||
setMajority={setMajority} />
|
||||
setMajority={setMajority}
|
||||
zkeydownloadStatus={zkeydownloadStatus}
|
||||
/>
|
||||
</Tabs.Content>
|
||||
<Tabs.Content value="mint" f={1}>
|
||||
<MintScreen
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { NativeModules } from 'react-native';
|
||||
import { YStack, XStack, Text, Checkbox, Input, Button, Spinner, Image, useWindowDimensions, ScrollView, SizableStack, SizableText } from 'tamagui';
|
||||
import { Check, Plus, Minus, ExternalLink, Cpu, PenTool, Info } from '@tamagui/lucide-icons';
|
||||
import { getFirstName } from '../../utils/utils';
|
||||
import { YStack, XStack, Text, Checkbox, Input, Button, Spinner, Image, useWindowDimensions, ScrollView } from 'tamagui';
|
||||
import { Check, LayoutGrid, Scan, Copy, Plus, Minus, PenTool } from '@tamagui/lucide-icons';
|
||||
import { getFirstName, formatDuration, maskString, shortenInput, getTx } from '../../utils/utils';
|
||||
import { attributeToPosition } from '../../../common/src/constants/constants';
|
||||
import USER from '../images/user.png'
|
||||
import { App } from '../utils/AppClass';
|
||||
import { Keyboard, Platform } from 'react-native';
|
||||
import { DEFAULT_ADDRESS } from '@env';
|
||||
import { blueColor, borderColor, componentBgColor, componentBgColor2, textColor1, textColor2 } from '../utils/colors';
|
||||
import ENS from "../images/ens_mark_dao.png"
|
||||
import { useToastController } from '@tamagui/toast'
|
||||
|
||||
const { ethers } = require('ethers');
|
||||
const fileName = "passport.arkzkey"
|
||||
const path = "/data/user/0/com.proofofpassport/files/" + fileName
|
||||
import Clipboard from '@react-native-community/clipboard';
|
||||
import { ethers } from 'ethers';
|
||||
import { Platform } from 'react-native';
|
||||
|
||||
interface ProveScreenProps {
|
||||
selectedApp: App | null;
|
||||
@@ -24,12 +21,18 @@ interface ProveScreenProps {
|
||||
address: string;
|
||||
setAddress: (address: string) => void;
|
||||
generatingProof: boolean;
|
||||
handleProve: (path: string) => void;
|
||||
handleProve: () => void;
|
||||
handleMint: () => void;
|
||||
step: number;
|
||||
mintText: string;
|
||||
proof: { proof: string, inputs: string } | null;
|
||||
proofTime: number;
|
||||
hideData: boolean;
|
||||
ens: string;
|
||||
setEns: (ens: string) => void;
|
||||
majority: number;
|
||||
setMajority: (age: number) => void;
|
||||
zkeydownloadStatus: string;
|
||||
}
|
||||
|
||||
const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
@@ -45,52 +48,23 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
ens,
|
||||
setEns,
|
||||
majority,
|
||||
setMajority
|
||||
setMajority,
|
||||
zkeydownloadStatus
|
||||
}) => {
|
||||
const [zkeyLoading, setZkeyLoading] = useState(false);
|
||||
const [zkeyLoaded, setZkeyLoaded] = useState(true);
|
||||
const toast = useToastController()
|
||||
|
||||
|
||||
const downloadZkey = async () => {
|
||||
// TODO: don't redownload if already in the file system at path, if downloaded from previous session
|
||||
setZkeyLoading(true);
|
||||
// Allow the spinner to show up before app freeze on android
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
try {
|
||||
console.log('Downloading file...')
|
||||
const result = await NativeModules.RNPassportReader.downloadFile(
|
||||
'https://current-pop-zkey.s3.eu-north-1.amazonaws.com/proof_of_passport_final_merkle_and_age.arkzkey',
|
||||
fileName
|
||||
);
|
||||
console.log("Download successful");
|
||||
console.log(result);
|
||||
setZkeyLoaded(true);
|
||||
setZkeyLoading(false);
|
||||
} catch (e: any) {
|
||||
console.log("Download not successful");
|
||||
toast.show('Error', {
|
||||
message: `${e.message}`,
|
||||
customData: {
|
||||
type: "error",
|
||||
},
|
||||
})
|
||||
setZkeyLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const maskString = (input: string): string => {
|
||||
if (input.length <= 5) {
|
||||
return input.charAt(0) + '*'.repeat(input.length - 1);
|
||||
} else {
|
||||
return input.charAt(0) + input.charAt(1) + '*'.repeat(input.length - 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const { height } = useWindowDimensions();
|
||||
const [inputValue, setInputValue] = useState(DEFAULT_ADDRESS ?? '');
|
||||
const provider = new ethers.JsonRpcProvider(`https://eth-mainnet.g.alchemy.com/v2/lpOn3k6Fezetn1e5QF-iEsn-J0C6oGE0`);
|
||||
const toast = useToastController()
|
||||
|
||||
const copyToClipboard = (input: string) => {
|
||||
Clipboard.setString(input);
|
||||
toast.show('Info', {
|
||||
message: `🖨️ Tx copied to clipboard`,
|
||||
customData: {
|
||||
type: "info",
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (ens != '' && inputValue == '') {
|
||||
@@ -100,7 +74,6 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
else if (address != ethers.ZeroAddress && inputValue == '') {
|
||||
setInputValue(address);
|
||||
}
|
||||
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -128,10 +101,6 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
})
|
||||
if (hideData) {
|
||||
console.log(maskString(address));
|
||||
// setInputValue(maskString(address));
|
||||
}
|
||||
else {
|
||||
// setInputValue(address);
|
||||
}
|
||||
} else {
|
||||
toast.show('Error', {
|
||||
@@ -159,26 +128,6 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
resolveENS();
|
||||
}, [inputValue]);
|
||||
|
||||
|
||||
|
||||
|
||||
// Keyboard management
|
||||
const [keyboardVisible, setKeyboardVisible] = useState(false);
|
||||
const { height, width } = useWindowDimensions();
|
||||
useEffect(() => {
|
||||
const showSubscription = Keyboard.addListener('keyboardDidShow', () => {
|
||||
setKeyboardVisible(true);
|
||||
});
|
||||
const hideSubscription = Keyboard.addListener('keyboardDidHide', () => {
|
||||
setKeyboardVisible(false);
|
||||
});
|
||||
|
||||
return () => {
|
||||
showSubscription.remove();
|
||||
hideSubscription.remove();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<YStack px="$4" f={1} mb={Platform.OS === 'ios' ? "$5" : "$0"}>
|
||||
<YStack flex={1} mx="$2" gap="$2">
|
||||
@@ -248,7 +197,7 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
<Text fontSize={16} fow="bold" color="#ededed">Disclose</Text>
|
||||
{/* <Info size="$1" color={textColor2} /> */}
|
||||
</XStack>
|
||||
<SizableText color="#a0a0a0">Select optionnal data </SizableText>
|
||||
<Text color="#a0a0a0">Select optionnal data </Text>
|
||||
</YStack>
|
||||
</XStack>
|
||||
</YStack>
|
||||
@@ -295,23 +244,36 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
);
|
||||
})}
|
||||
|
||||
</ScrollView>
|
||||
</YStack>
|
||||
</ScrollView >
|
||||
</YStack >
|
||||
</YStack >
|
||||
</YStack>
|
||||
<Button disabled={zkeyLoading || (address == ethers.ZeroAddress)} borderWidth={1.3} borderColor={borderColor} borderRadius={100} onPress={() => { (!zkeyLoaded && Platform.OS != "ios") ? downloadZkey() : handleProve(path) }} mt="$8" backgroundColor={(zkeyLoading || (address == ethers.ZeroAddress)) ? "#1c1c1c" : "#3185FC"} alignSelf='center' >
|
||||
{!zkeyLoaded && Platform.OS != "ios" ? (
|
||||
<XStack ai="center" gap="$2">
|
||||
{zkeyLoading && <Spinner />}
|
||||
<Text color={textColor1} fow="bold">{zkeyLoading ? "Downloading ZK circuit" : "Download ZK circuit"}</Text>
|
||||
</YStack >
|
||||
<Button disabled={zkeydownloadStatus != "completed" || (address == ethers.ZeroAddress)} borderWidth={1.3} borderColor={borderColor} borderRadius={100} onPress={handleProve} mt="$8" backgroundColor={address == ethers.ZeroAddress ? "#cecece" : "#3185FC"} alignSelf='center' >
|
||||
{zkeydownloadStatus === "downloading" ? (
|
||||
<XStack ai="center" gap="$1">
|
||||
<Spinner />
|
||||
<Text color={textColor1} fow="bold">
|
||||
Downloading ZK proving key
|
||||
</Text>
|
||||
</XStack>
|
||||
) : zkeydownloadStatus === "error" ? (
|
||||
<XStack ai="center" gap="$1">
|
||||
<Spinner />
|
||||
<Text color={textColor1} fow="bold">
|
||||
Error downloading ZK proving key
|
||||
</Text>
|
||||
</XStack>
|
||||
) : generatingProof ? (
|
||||
<XStack ai="center" gap="$1">
|
||||
<Spinner />
|
||||
<Text color={textColor1} marginLeft="$2" fow="bold" >Generating ZK proof</Text>
|
||||
<Text color={textColor1} marginLeft="$2" fow="bold">
|
||||
Generating ZK proof
|
||||
</Text>
|
||||
</XStack>
|
||||
) : (
|
||||
<Text color={(zkeyLoading || (address == ethers.ZeroAddress)) ? "#343434" : "#ededed"} fow="bold">Generate ZK proof</Text>
|
||||
<Text color={textColor1} fow="bold">
|
||||
Generate ZK proof
|
||||
</Text>
|
||||
)}
|
||||
</Button>
|
||||
{(height > 750) && <Text fontSize={10} color={generatingProof ? "#a0a0a0" : "#161616"} py="$2" alignSelf='center'>This operation can take up to 2 mn, phone may freeze during this time</Text>}
|
||||
@@ -320,4 +282,5 @@ const ProveScreen: React.FC<ProveScreenProps> = ({
|
||||
</YStack >
|
||||
);
|
||||
};
|
||||
export default ProveScreen;
|
||||
|
||||
export default ProveScreen;
|
||||
@@ -76,6 +76,8 @@ export const mint = async ({ proof, setStep, setMintText, toast }: MinterProps)
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.log('err', err);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
setMintText(`Error minting SBT. Network: Sepolia.`);
|
||||
if (err.isAxiosError && err.response) {
|
||||
const errorMessage = err.response.data.error;
|
||||
console.log('Server error message:', errorMessage);
|
||||
@@ -100,6 +102,5 @@ export const mint = async ({ proof, setStep, setMintText, toast }: MinterProps)
|
||||
console.log('Failed to parse blockchain error');
|
||||
}
|
||||
}
|
||||
setMintText(`Error minting SBT. Network: Sepolia.`);
|
||||
}
|
||||
};
|
||||
@@ -25,7 +25,7 @@ export const prove = async ({
|
||||
setProofTime,
|
||||
setProof,
|
||||
toast
|
||||
}: ProverProps, path?: string) => {
|
||||
}: ProverProps) => {
|
||||
if (passportData === null) {
|
||||
console.log('passport data is null');
|
||||
return;
|
||||
@@ -58,7 +58,7 @@ export const prove = async ({
|
||||
});
|
||||
|
||||
const start = Date.now();
|
||||
await generateProof(inputs, setProofTime, setProof, setGeneratingProof, setStep, path);
|
||||
await generateProof(inputs, setProofTime, setProof, setGeneratingProof, setStep);
|
||||
const end = Date.now();
|
||||
console.log('Total proof time from frontend:', end - start);
|
||||
} catch (error: any) {
|
||||
@@ -80,40 +80,52 @@ const generateProof = async (
|
||||
setProof: (value: { proof: string; inputs: string } | null) => void,
|
||||
setGeneratingProof: (value: boolean) => void,
|
||||
setStep: (value: number) => void,
|
||||
path?: string,
|
||||
) => {
|
||||
try {
|
||||
console.log('launching generateProof function');
|
||||
console.log('inputs in App.tsx', inputs);
|
||||
|
||||
await NativeModules.Prover.runInitAction();
|
||||
if (Platform.OS == "android") {
|
||||
await NativeModules.Prover.runInitAction();
|
||||
}
|
||||
|
||||
console.log('running prove action');
|
||||
const startTime = Date.now();
|
||||
console.log('running mopro prove action');
|
||||
const response = await NativeModules.Prover.runProveAction(inputs);
|
||||
console.log('proof response:', response);
|
||||
|
||||
const parsedResponse = Platform.OS === 'android'
|
||||
? parseProofAndroid(response)
|
||||
: JSON.parse(response);
|
||||
console.log('parsedResponse', parsedResponse);
|
||||
|
||||
const endTime = Date.now();
|
||||
console.log('time spent:', endTime - startTime);
|
||||
console.log('proof response:', response);
|
||||
console.log('typeof proof response:', typeof response);
|
||||
setProofTime(endTime - startTime);
|
||||
|
||||
console.log('running mopro verify action');
|
||||
const res = await NativeModules.Prover.runVerifyAction();
|
||||
console.log('verify response:', res);
|
||||
if (Platform.OS === 'android') {
|
||||
const parsedResponse = parseProofAndroid(response);
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(formatProof(parsedResponse.proof)),
|
||||
inputs: JSON.stringify(formatInputs(parsedResponse.inputs)),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(formatProof(parsedResponse.proof)),
|
||||
inputs: JSON.stringify(formatInputs(parsedResponse.inputs)),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
} else {
|
||||
const parsedResponse = JSON.parse(response);
|
||||
console.log('parsedResponse', parsedResponse);
|
||||
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
console.log('parsedResponse.proof:', parsedResponse.proof);
|
||||
console.log('parsedResponse.inputs:', parsedResponse.inputs);
|
||||
|
||||
const finalProof = {
|
||||
proof: JSON.stringify(parsedResponse.proof),
|
||||
inputs: JSON.stringify(parsedResponse.inputs),
|
||||
};
|
||||
console.log('finalProof:', finalProof);
|
||||
|
||||
setProof(finalProof);
|
||||
setGeneratingProof(false);
|
||||
setStep(Steps.PROOF_GENERATED);
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.log('err', err);
|
||||
}
|
||||
|
||||
@@ -38,3 +38,26 @@ export function checkInputs(
|
||||
message: ''
|
||||
};
|
||||
}
|
||||
|
||||
export const maskString = (input: string): string => {
|
||||
if (input.length <= 5) {
|
||||
return input.charAt(0) + '*'.repeat(input.length - 1);
|
||||
} else {
|
||||
return input.charAt(0) + input.charAt(1) + '*'.repeat(input.length - 2);
|
||||
}
|
||||
}
|
||||
|
||||
export const getTx = (input: string | null): string => {
|
||||
if (!input) return '';
|
||||
const transaction = input.split(' ').filter(word => word.startsWith('0x')).join(' ');
|
||||
return transaction;
|
||||
}
|
||||
|
||||
export const shortenInput = (input: string | null): string => {
|
||||
if (!input) return '';
|
||||
if (input.length > 9) {
|
||||
return input.substring(0, 25) + '\u2026';
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
78
app/witnesscalc/.gitignore
vendored
Normal file
78
app/witnesscalc/.gitignore
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
# build/
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Typescript v1 declaration files
|
||||
typings/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
tmp
|
||||
temp
|
||||
|
||||
.DS_Store
|
||||
|
||||
# Workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
CMakeLists.txt.user
|
||||
|
||||
depends/gmp*
|
||||
|
||||
build/*.o
|
||||
build_witnesscalc_ios
|
||||
package*
|
||||
|
||||
.idea/
|
||||
60
app/witnesscalc/CMakeLists.txt
Normal file
60
app/witnesscalc/CMakeLists.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
include(cmake/platform.cmake)
|
||||
|
||||
set(USE_ASM ON CACHE BOOL "Use asm implementation for Fr and Fq")
|
||||
|
||||
project(witnesscalc LANGUAGES CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
message("USE_ASM=" ${USE_ASM})
|
||||
message("CMAKE_CROSSCOMPILING=" ${CMAKE_CROSSCOMPILING})
|
||||
|
||||
message("GMP_PREFIX=" ${GMP_PREFIX})
|
||||
message("GMP_INCLUDE_DIR=" ${GMP_INCLUDE_DIR})
|
||||
message("GMP_LIB_DIR=" ${GMP_LIB_DIR})
|
||||
|
||||
if (NOT EXISTS ${GMP_INCLUDE_FILE_FULLPATH})
|
||||
message("WARNING: ${GMP_INCLUDE_FILE_FULLPATH} is not found and so system ${GMP_INCLUDE_FILE} is used.")
|
||||
endif()
|
||||
|
||||
if (NOT EXISTS ${GMP_LIB_FILE_FULLPATH})
|
||||
message("WARNING: ${GMP_LIB_FILE_FULLPATH} is not found and so system ${GMP_LIB_FILE} is used.")
|
||||
set(GMP_LIB gmp)
|
||||
endif()
|
||||
|
||||
|
||||
include_directories(BEFORE ${GMP_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
|
||||
install(TARGETS
|
||||
tests
|
||||
test_platform
|
||||
authV2
|
||||
proof_of_passport
|
||||
witnesscalc_proof_of_passport
|
||||
witnesscalc_proof_of_passportStatic
|
||||
witnesscalc_authV2
|
||||
witnesscalc_authV2Static
|
||||
fr
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
BUNDLE DESTINATION ${CMAKE_INSTALL_PREFIX}/app
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
||||
install(FILES "${GMP_LIB_DIR}/${GMP_LIB_FILE}"
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
||||
|
||||
install(FILES
|
||||
src/proof_of_passport.dat
|
||||
src/authV2.dat
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
||||
install(FILES
|
||||
src/witnesscalc.h
|
||||
src/witnesscalc_proof_of_passport.h
|
||||
src/witnesscalc_authV2.h
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
|
||||
675
app/witnesscalc/COPYING
Normal file
675
app/witnesscalc/COPYING
Normal file
@@ -0,0 +1,675 @@
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2021 0Kims Association <https://0kims.org>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
33
app/witnesscalc/Makefile
Normal file
33
app/witnesscalc/Makefile
Normal file
@@ -0,0 +1,33 @@
|
||||
###
|
||||
|
||||
#Build targets
|
||||
host:
|
||||
rm -rf build_witnesscalc && mkdir build_witnesscalc && cd build_witnesscalc && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
arm64_host:
|
||||
rm -rf build_witnesscalc && mkdir build_witnesscalc && cd build_witnesscalc && \
|
||||
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
android:
|
||||
rm -rf build_witnesscalc_android && mkdir build_witnesscalc_android && cd build_witnesscalc_android && \
|
||||
cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
android_x86_64:
|
||||
rm -rf build_witnesscalc_android_x86_64 && mkdir build_witnesscalc_android_x86_64 && cd build_witnesscalc_android_x86_64 && \
|
||||
cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_x86_64 && \
|
||||
make -j4 -vvv && make install
|
||||
|
||||
ios:
|
||||
rm -rf build_witnesscalc_ios && mkdir build_witnesscalc_ios && cd build_witnesscalc_ios && \
|
||||
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_ios && \
|
||||
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
|
||||
|
||||
ios_x86_64:
|
||||
rm -rf build_witnesscalc_ios_x86_64 && mkdir build_witnesscalc_ios_x86_64 && cd build_witnesscalc_ios_x86_64 && \
|
||||
cmake .. -GXcode -DTARGET_PLATFORM=IOS_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_ios_x86_64 && \
|
||||
echo "" && echo "Now open Xcode and compile the generated project" && echo ""
|
||||
|
||||
92
app/witnesscalc/README.md
Normal file
92
app/witnesscalc/README.md
Normal file
@@ -0,0 +1,92 @@
|
||||
## Dependencies
|
||||
|
||||
You should have installed gcc and cmake
|
||||
|
||||
In ubuntu:
|
||||
|
||||
```sh
|
||||
sudo apt install build-essential cmake m4
|
||||
```
|
||||
|
||||
## Compilation
|
||||
|
||||
### Preparation
|
||||
```sh
|
||||
git submodule init
|
||||
git submodule update
|
||||
```
|
||||
|
||||
### Compile witnesscalc for x86_64 host machine
|
||||
|
||||
```sh
|
||||
./build_gmp.sh host
|
||||
make host
|
||||
```
|
||||
|
||||
### Compile witnesscalc for arm64 host machine
|
||||
|
||||
```sh
|
||||
./build_gmp.sh host
|
||||
make arm64_host
|
||||
```
|
||||
|
||||
### Compile witnesscalc for Android
|
||||
|
||||
Install Android NDK from https://developer.android.com/ndk or with help of "SDK Manager" in Android Studio.
|
||||
|
||||
Set the value of ANDROID_NDK environment variable to the absolute path of Android NDK root directory.
|
||||
|
||||
Examples:
|
||||
|
||||
```sh
|
||||
export ANDROID_NDK=/home/test/Android/Sdk/ndk/23.1.7779620 # NDK is installed by "SDK Manager" in Android Studio.
|
||||
export ANDROID_NDK=/home/test/android-ndk-r23b # NDK is installed as a stand-alone package.
|
||||
```
|
||||
|
||||
Compilation for arm64:
|
||||
|
||||
```sh
|
||||
./build_gmp.sh android
|
||||
make android
|
||||
```
|
||||
|
||||
Compilation for x86_64:
|
||||
|
||||
```sh
|
||||
./build_gmp.sh android_x86_64
|
||||
make android_x86_64
|
||||
```
|
||||
|
||||
### Compile witnesscalc for iOS
|
||||
|
||||
Requirements: Xcode.
|
||||
|
||||
1. Run:
|
||||
````sh
|
||||
./build_gmp.sh ios
|
||||
make ios
|
||||
````
|
||||
2. Open generated Xcode project.
|
||||
3. Add compilation flag `-D_LONG_LONG_LIMB` to all build targets.
|
||||
4. Add compilation flag `-DCIRCUIT_NAME=auth`, `-DCIRCUIT_NAME=sig` and `-DCIRCUIT_NAME=mtp` to the respective targets.
|
||||
5. Compile witnesscalc.
|
||||
|
||||
## Updating circuits
|
||||
1. Compile a circuit with compile-circuit.sh script in circuits repo as usual.
|
||||
2. Replace existing <circuitname>.cpp and <circuitname>.dat files with generated ones (e.g. auth.cpp & auth.dat).
|
||||
3. Enclose all the code inside <circuitname>.cpp file with `namespace CIRCUIT_NAME` (do not replace `CIRCUIT_NAME` with the real name, it will be replaced at compilation), like this:
|
||||
```c++
|
||||
#include ...
|
||||
#include ...
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
// millions of code lines here
|
||||
|
||||
} // namespace
|
||||
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
witnesscalc is part of the iden3 project copyright 2022 0KIMS association and published with GPL-3 license. Please check the COPYING file for more details.
|
||||
8803
app/witnesscalc/build/fr.asm
Normal file
8803
app/witnesscalc/build/fr.asm
Normal file
File diff suppressed because it is too large
Load Diff
324
app/witnesscalc/build/fr.cpp
Normal file
324
app/witnesscalc/build/fr.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
#include "fr.hpp"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmp.h>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
static mpz_t q;
|
||||
static mpz_t zero;
|
||||
static mpz_t one;
|
||||
static mpz_t mask;
|
||||
static size_t nBits;
|
||||
static bool initialized = false;
|
||||
|
||||
void Fr_toMpz(mpz_t r, PFrElement pE) {
|
||||
FrElement tmp;
|
||||
Fr_toNormal(&tmp, pE);
|
||||
if (!(tmp.type & Fr_LONG)) {
|
||||
mpz_set_si(r, tmp.shortVal);
|
||||
if (tmp.shortVal<0) {
|
||||
mpz_add(r, r, q);
|
||||
}
|
||||
} else {
|
||||
mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)tmp.longVal);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_fromMpz(PFrElement pE, mpz_t v) {
|
||||
if (mpz_fits_sint_p(v)) {
|
||||
pE->type = Fr_SHORT;
|
||||
pE->shortVal = mpz_get_si(v);
|
||||
} else {
|
||||
pE->type = Fr_LONG;
|
||||
for (int i=0; i<Fr_N64; i++) pE->longVal[i] = 0;
|
||||
mpz_export((void *)(pE->longVal), NULL, -1, 8, -1, 0, v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Fr_init() {
|
||||
if (initialized) return false;
|
||||
initialized = true;
|
||||
mpz_init(q);
|
||||
mpz_import(q, Fr_N64, -1, 8, -1, 0, (const void *)Fr_q.longVal);
|
||||
mpz_init_set_ui(zero, 0);
|
||||
mpz_init_set_ui(one, 1);
|
||||
nBits = mpz_sizeinbase (q, 2);
|
||||
mpz_init(mask);
|
||||
mpz_mul_2exp(mask, one, nBits);
|
||||
mpz_sub(mask, mask, one);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Fr_str2element(PFrElement pE, char const *s, uint base) {
|
||||
mpz_t mr;
|
||||
mpz_init_set_str(mr, s, base);
|
||||
mpz_fdiv_r(mr, mr, q);
|
||||
Fr_fromMpz(pE, mr);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
char *Fr_element2str(PFrElement pE) {
|
||||
FrElement tmp;
|
||||
mpz_t r;
|
||||
if (!(pE->type & Fr_LONG)) {
|
||||
if (pE->shortVal>=0) {
|
||||
const size_t rLn = 32;
|
||||
char *r = new char[rLn];
|
||||
snprintf(r, rLn, "%d", pE->shortVal);
|
||||
return r;
|
||||
} else {
|
||||
mpz_init_set_si(r, pE->shortVal);
|
||||
mpz_add(r, r, q);
|
||||
}
|
||||
} else {
|
||||
Fr_toNormal(&tmp, pE);
|
||||
mpz_init(r);
|
||||
mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)tmp.longVal);
|
||||
}
|
||||
char *res = mpz_get_str (0, 10, r);
|
||||
mpz_clear(r);
|
||||
return res;
|
||||
}
|
||||
|
||||
void Fr_idiv(PFrElement r, PFrElement a, PFrElement b) {
|
||||
mpz_t ma;
|
||||
mpz_t mb;
|
||||
mpz_t mr;
|
||||
mpz_init(ma);
|
||||
mpz_init(mb);
|
||||
mpz_init(mr);
|
||||
|
||||
Fr_toMpz(ma, a);
|
||||
// char *s1 = mpz_get_str (0, 10, ma);
|
||||
// printf("s1 %s\n", s1);
|
||||
Fr_toMpz(mb, b);
|
||||
// char *s2 = mpz_get_str (0, 10, mb);
|
||||
// printf("s2 %s\n", s2);
|
||||
mpz_fdiv_q(mr, ma, mb);
|
||||
// char *sr = mpz_get_str (0, 10, mr);
|
||||
// printf("r %s\n", sr);
|
||||
Fr_fromMpz(r, mr);
|
||||
|
||||
mpz_clear(ma);
|
||||
mpz_clear(mb);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void Fr_mod(PFrElement r, PFrElement a, PFrElement b) {
|
||||
mpz_t ma;
|
||||
mpz_t mb;
|
||||
mpz_t mr;
|
||||
mpz_init(ma);
|
||||
mpz_init(mb);
|
||||
mpz_init(mr);
|
||||
|
||||
Fr_toMpz(ma, a);
|
||||
Fr_toMpz(mb, b);
|
||||
mpz_fdiv_r(mr, ma, mb);
|
||||
Fr_fromMpz(r, mr);
|
||||
|
||||
mpz_clear(ma);
|
||||
mpz_clear(mb);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void Fr_pow(PFrElement r, PFrElement a, PFrElement b) {
|
||||
mpz_t ma;
|
||||
mpz_t mb;
|
||||
mpz_t mr;
|
||||
mpz_init(ma);
|
||||
mpz_init(mb);
|
||||
mpz_init(mr);
|
||||
|
||||
Fr_toMpz(ma, a);
|
||||
Fr_toMpz(mb, b);
|
||||
mpz_powm(mr, ma, mb, q);
|
||||
Fr_fromMpz(r, mr);
|
||||
|
||||
mpz_clear(ma);
|
||||
mpz_clear(mb);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void Fr_inv(PFrElement r, PFrElement a) {
|
||||
mpz_t ma;
|
||||
mpz_t mr;
|
||||
mpz_init(ma);
|
||||
mpz_init(mr);
|
||||
|
||||
Fr_toMpz(ma, a);
|
||||
mpz_invert(mr, ma, q);
|
||||
Fr_fromMpz(r, mr);
|
||||
mpz_clear(ma);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void Fr_div(PFrElement r, PFrElement a, PFrElement b) {
|
||||
FrElement tmp;
|
||||
Fr_inv(&tmp, b);
|
||||
Fr_mul(r, a, &tmp);
|
||||
}
|
||||
|
||||
void Fr_fail() {
|
||||
throw std::runtime_error("Fr error");
|
||||
}
|
||||
|
||||
void Fr_longErr()
|
||||
{
|
||||
Fr_fail();
|
||||
}
|
||||
|
||||
RawFr::RawFr() {
|
||||
Fr_init();
|
||||
set(fZero, 0);
|
||||
set(fOne, 1);
|
||||
neg(fNegOne, fOne);
|
||||
}
|
||||
|
||||
RawFr::~RawFr() {
|
||||
}
|
||||
|
||||
void RawFr::fromString(Element &r, const std::string &s, uint32_t radix) {
|
||||
mpz_t mr;
|
||||
mpz_init_set_str(mr, s.c_str(), radix);
|
||||
mpz_fdiv_r(mr, mr, q);
|
||||
for (int i=0; i<Fr_N64; i++) r.v[i] = 0;
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, mr);
|
||||
Fr_rawToMontgomery(r.v,r.v);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void RawFr::fromUI(Element &r, unsigned long int v) {
|
||||
mpz_t mr;
|
||||
mpz_init(mr);
|
||||
mpz_set_ui(mr, v);
|
||||
for (int i=0; i<Fr_N64; i++) r.v[i] = 0;
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, mr);
|
||||
Fr_rawToMontgomery(r.v,r.v);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
RawFr::Element RawFr::set(int value) {
|
||||
Element r;
|
||||
set(r, value);
|
||||
return r;
|
||||
}
|
||||
|
||||
void RawFr::set(Element &r, int value) {
|
||||
mpz_t mr;
|
||||
mpz_init(mr);
|
||||
mpz_set_si(mr, value);
|
||||
if (value < 0) {
|
||||
mpz_add(mr, mr, q);
|
||||
}
|
||||
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, mr);
|
||||
|
||||
for (int i=0; i<Fr_N64; i++) r.v[i] = 0;
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, mr);
|
||||
Fr_rawToMontgomery(r.v,r.v);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
std::string RawFr::toString(const Element &a, uint32_t radix) {
|
||||
Element tmp;
|
||||
mpz_t r;
|
||||
Fr_rawFromMontgomery(tmp.v, a.v);
|
||||
mpz_init(r);
|
||||
mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)(tmp.v));
|
||||
char *res = mpz_get_str (0, radix, r);
|
||||
mpz_clear(r);
|
||||
std::string resS(res);
|
||||
free(res);
|
||||
return resS;
|
||||
}
|
||||
|
||||
void RawFr::inv(Element &r, const Element &a) {
|
||||
mpz_t mr;
|
||||
mpz_init(mr);
|
||||
mpz_import(mr, Fr_N64, -1, 8, -1, 0, (const void *)(a.v));
|
||||
mpz_invert(mr, mr, q);
|
||||
|
||||
|
||||
for (int i=0; i<Fr_N64; i++) r.v[i] = 0;
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, mr);
|
||||
|
||||
Fr_rawMMul(r.v, r.v,Fr_R3.longVal);
|
||||
mpz_clear(mr);
|
||||
}
|
||||
|
||||
void RawFr::div(Element &r, const Element &a, const Element &b) {
|
||||
Element tmp;
|
||||
inv(tmp, b);
|
||||
mul(r, a, tmp);
|
||||
}
|
||||
|
||||
#define BIT_IS_SET(s, p) (s[p>>3] & (1 << (p & 0x7)))
|
||||
void RawFr::exp(Element &r, const Element &base, uint8_t* scalar, unsigned int scalarSize) {
|
||||
bool oneFound = false;
|
||||
Element copyBase;
|
||||
copy(copyBase, base);
|
||||
for (int i=scalarSize*8-1; i>=0; i--) {
|
||||
if (!oneFound) {
|
||||
if ( !BIT_IS_SET(scalar, i) ) continue;
|
||||
copy(r, copyBase);
|
||||
oneFound = true;
|
||||
continue;
|
||||
}
|
||||
square(r, r);
|
||||
if ( BIT_IS_SET(scalar, i) ) {
|
||||
mul(r, r, copyBase);
|
||||
}
|
||||
}
|
||||
if (!oneFound) {
|
||||
copy(r, fOne);
|
||||
}
|
||||
}
|
||||
|
||||
void RawFr::toMpz(mpz_t r, const Element &a) {
|
||||
Element tmp;
|
||||
Fr_rawFromMontgomery(tmp.v, a.v);
|
||||
mpz_import(r, Fr_N64, -1, 8, -1, 0, (const void *)tmp.v);
|
||||
}
|
||||
|
||||
void RawFr::fromMpz(Element &r, const mpz_t a) {
|
||||
for (int i=0; i<Fr_N64; i++) r.v[i] = 0;
|
||||
mpz_export((void *)(r.v), NULL, -1, 8, -1, 0, a);
|
||||
Fr_rawToMontgomery(r.v, r.v);
|
||||
}
|
||||
|
||||
int RawFr::toRprBE(const Element &element, uint8_t *data, int bytes)
|
||||
{
|
||||
if (bytes < Fr_N64 * 8) {
|
||||
return -(Fr_N64 * 8);
|
||||
}
|
||||
|
||||
mpz_t r;
|
||||
mpz_init(r);
|
||||
|
||||
toMpz(r, element);
|
||||
|
||||
mpz_export(data, NULL, 1, 8, 1, 0, r);
|
||||
|
||||
return Fr_N64 * 8;
|
||||
}
|
||||
|
||||
int RawFr::fromRprBE(Element &element, const uint8_t *data, int bytes)
|
||||
{
|
||||
if (bytes < Fr_N64 * 8) {
|
||||
return -(Fr_N64* 8);
|
||||
}
|
||||
mpz_t r;
|
||||
mpz_init(r);
|
||||
|
||||
mpz_import(r, Fr_N64 * 8, 0, 1, 0, 0, data);
|
||||
fromMpz(element, r);
|
||||
return Fr_N64 * 8;
|
||||
}
|
||||
|
||||
static bool init = Fr_init();
|
||||
|
||||
RawFr RawFr::field;
|
||||
287
app/witnesscalc/build/fr.hpp
Normal file
287
app/witnesscalc/build/fr.hpp
Normal file
@@ -0,0 +1,287 @@
|
||||
#ifndef __FR_H
|
||||
#define __FR_H
|
||||
|
||||
#include "fr_element.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <gmp.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/types.h> // typedef unsigned int uint;
|
||||
#endif // __APPLE__
|
||||
|
||||
extern FrElement Fr_q;
|
||||
extern FrElement Fr_R2;
|
||||
extern FrElement Fr_R3;
|
||||
extern FrRawElement Fr_rawq;
|
||||
extern FrRawElement Fr_rawR3;
|
||||
|
||||
#ifdef USE_ASM
|
||||
|
||||
#if defined(ARCH_X86_64)
|
||||
|
||||
extern "C" void Fr_copy(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_copyn(PFrElement r, PFrElement a, int n);
|
||||
extern "C" void Fr_add(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_sub(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_neg(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_mul(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_square(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_band(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_bor(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_bxor(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_bnot(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_shl(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_shr(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_eq(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_neq(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_lt(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_gt(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_leq(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_geq(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_land(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_lor(PFrElement r, PFrElement a, PFrElement b);
|
||||
extern "C" void Fr_lnot(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_toNormal(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_toLongNormal(PFrElement r, PFrElement a);
|
||||
extern "C" void Fr_toMontgomery(PFrElement r, PFrElement a);
|
||||
|
||||
extern "C" int Fr_isTrue(PFrElement pE);
|
||||
extern "C" int Fr_toInt(PFrElement pE);
|
||||
|
||||
extern "C" void Fr_rawCopy(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawSwap(FrRawElement pRawResult, FrRawElement pRawA);
|
||||
extern "C" void Fr_rawAdd(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawSub(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawNeg(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawMMul(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawMSquare(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawMMul1(FrRawElement pRawResult, const FrRawElement pRawA, uint64_t pRawB);
|
||||
extern "C" void Fr_rawToMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
extern "C" void Fr_rawFromMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
extern "C" int Fr_rawIsEq(const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" int Fr_rawIsZero(const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawShl(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
extern "C" void Fr_rawShr(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
|
||||
extern "C" void Fr_fail();
|
||||
|
||||
#elif defined(ARCH_ARM64)
|
||||
|
||||
void Fr_copy(PFrElement r, PFrElement a);
|
||||
void Fr_mul(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_toNormal(PFrElement r, PFrElement a);
|
||||
|
||||
void Fr_toLongNormal(PFrElement r, PFrElement a);
|
||||
int Fr_isTrue(PFrElement pE);
|
||||
void Fr_copyn(PFrElement r, PFrElement a, int n);
|
||||
void Fr_lt(PFrElement r, PFrElement a, PFrElement b);
|
||||
int Fr_toInt(PFrElement pE);
|
||||
void Fr_shr(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_shl(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_band(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bxor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bnot(PFrElement r, PFrElement a);
|
||||
void Fr_sub(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_eq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_neq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_add(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_gt(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_leq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_geq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_lor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_lnot(PFrElement r, PFrElement a);
|
||||
void Fr_land(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_neg(PFrElement r, PFrElement a);
|
||||
void Fr_toMontgomery(PFrElement r, PFrElement a);
|
||||
void Fr_square(PFrElement r, PFrElement a);
|
||||
|
||||
extern "C" void Fr_rawCopy(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawSwap(FrRawElement pRawResult, FrRawElement pRawA);
|
||||
extern "C" void Fr_rawAdd(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawSub(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" void Fr_rawNeg(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawMMul(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
void Fr_rawMSquare(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
extern "C" void Fr_rawMMul1(FrRawElement pRawResult, const FrRawElement pRawA, uint64_t pRawB);
|
||||
void Fr_rawToMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
extern "C" void Fr_rawFromMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
extern "C" int Fr_rawIsEq(const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
extern "C" int Fr_rawIsZero(const FrRawElement pRawB);
|
||||
void Fr_rawZero(FrRawElement pRawResult);
|
||||
extern "C" void Fr_rawCopyS2L(FrRawElement pRawResult, int64_t val);
|
||||
extern "C" void Fr_rawAddLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
extern "C" void Fr_rawSubSL(FrRawElement pRawResult, uint64_t rawA, FrRawElement pRawB);
|
||||
extern "C" void Fr_rawSubLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
extern "C" void Fr_rawNegLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
extern "C" int Fr_rawCmp(FrRawElement pRawA, FrRawElement pRawB);
|
||||
extern "C" void Fr_rawAnd(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
extern "C" void Fr_rawOr(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
extern "C" void Fr_rawXor(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
extern "C" void Fr_rawShl(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
extern "C" void Fr_rawShr(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
extern "C" void Fr_rawNot(FrRawElement pRawResult, FrRawElement pRawA);
|
||||
extern "C" void Fr_rawSubRegular(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
|
||||
void Fr_fail();
|
||||
void Fr_longErr();
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
|
||||
void Fr_copy(PFrElement r, PFrElement a);
|
||||
void Fr_mul(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_toNormal(PFrElement r, PFrElement a);
|
||||
|
||||
void Fr_toLongNormal(PFrElement r, PFrElement a);
|
||||
int Fr_isTrue(PFrElement pE);
|
||||
void Fr_copyn(PFrElement r, PFrElement a, int n);
|
||||
void Fr_lt(PFrElement r, PFrElement a, PFrElement b);
|
||||
int Fr_toInt(PFrElement pE);
|
||||
void Fr_shl(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_shr(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_band(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bxor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_bnot(PFrElement r, PFrElement a);
|
||||
void Fr_sub(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_eq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_neq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_add(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_gt(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_leq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_geq(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_lor(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_lnot(PFrElement r, PFrElement a);
|
||||
void Fr_land(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_neg(PFrElement r, PFrElement a);
|
||||
void Fr_toMontgomery(PFrElement r, PFrElement a);
|
||||
void Fr_square(PFrElement r, PFrElement a);
|
||||
|
||||
void Fr_rawCopy(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
void Fr_rawSwap(FrRawElement pRawResult, FrRawElement pRawA);
|
||||
void Fr_rawAdd(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
void Fr_rawSub(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
void Fr_rawNeg(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
void Fr_rawMMul(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
void Fr_rawMSquare(FrRawElement pRawResult, const FrRawElement pRawA);
|
||||
void Fr_rawMMul1(FrRawElement pRawResult, const FrRawElement pRawA, uint64_t pRawB);
|
||||
void Fr_rawToMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
void Fr_rawFromMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA);
|
||||
int Fr_rawIsEq(const FrRawElement pRawA, const FrRawElement pRawB);
|
||||
int Fr_rawIsZero(const FrRawElement pRawB);
|
||||
void Fr_rawZero(FrRawElement pRawResult);
|
||||
void Fr_rawCopyS2L(FrRawElement pRawResult, int64_t val);
|
||||
void Fr_rawAddLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
void Fr_rawSubSL(FrRawElement pRawResult, uint64_t rawA, FrRawElement pRawB);
|
||||
void Fr_rawSubLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
void Fr_rawNegLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB);
|
||||
int Fr_rawCmp(FrRawElement pRawA, FrRawElement pRawB);
|
||||
void Fr_rawAnd(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
void Fr_rawOr(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
void Fr_rawXor(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
void Fr_rawShl(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
void Fr_rawShr(FrRawElement r, FrRawElement a, uint64_t b);
|
||||
void Fr_rawNot(FrRawElement pRawResult, FrRawElement pRawA);
|
||||
void Fr_rawSubRegular(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB);
|
||||
|
||||
void Fr_fail();
|
||||
void Fr_longErr();
|
||||
|
||||
#endif
|
||||
|
||||
// Pending functions to convert
|
||||
|
||||
void Fr_str2element(PFrElement pE, char const*s, uint base);
|
||||
char *Fr_element2str(PFrElement pE);
|
||||
void Fr_idiv(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_mod(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_inv(PFrElement r, PFrElement a);
|
||||
void Fr_div(PFrElement r, PFrElement a, PFrElement b);
|
||||
void Fr_pow(PFrElement r, PFrElement a, PFrElement b);
|
||||
|
||||
class RawFr {
|
||||
|
||||
public:
|
||||
const static int N64 = Fr_N64;
|
||||
const static int MaxBits = 254;
|
||||
|
||||
|
||||
struct Element {
|
||||
FrRawElement v;
|
||||
};
|
||||
|
||||
private:
|
||||
Element fZero;
|
||||
Element fOne;
|
||||
Element fNegOne;
|
||||
|
||||
public:
|
||||
|
||||
RawFr();
|
||||
~RawFr();
|
||||
|
||||
const Element &zero() { return fZero; };
|
||||
const Element &one() { return fOne; };
|
||||
const Element &negOne() { return fNegOne; };
|
||||
Element set(int value);
|
||||
void set(Element &r, int value);
|
||||
|
||||
void fromString(Element &r, const std::string &n, uint32_t radix = 10);
|
||||
std::string toString(const Element &a, uint32_t radix = 10);
|
||||
|
||||
void inline copy(Element &r, const Element &a) { Fr_rawCopy(r.v, a.v); };
|
||||
void inline swap(Element &a, Element &b) { Fr_rawSwap(a.v, b.v); };
|
||||
void inline add(Element &r, const Element &a, const Element &b) { Fr_rawAdd(r.v, a.v, b.v); };
|
||||
void inline sub(Element &r, const Element &a, const Element &b) { Fr_rawSub(r.v, a.v, b.v); };
|
||||
void inline mul(Element &r, const Element &a, const Element &b) { Fr_rawMMul(r.v, a.v, b.v); };
|
||||
|
||||
Element inline add(const Element &a, const Element &b) { Element r; Fr_rawAdd(r.v, a.v, b.v); return r;};
|
||||
Element inline sub(const Element &a, const Element &b) { Element r; Fr_rawSub(r.v, a.v, b.v); return r;};
|
||||
Element inline mul(const Element &a, const Element &b) { Element r; Fr_rawMMul(r.v, a.v, b.v); return r;};
|
||||
|
||||
Element inline neg(const Element &a) { Element r; Fr_rawNeg(r.v, a.v); return r; };
|
||||
Element inline square(const Element &a) { Element r; Fr_rawMSquare(r.v, a.v); return r; };
|
||||
|
||||
Element inline add(int a, const Element &b) { return add(set(a), b);};
|
||||
Element inline sub(int a, const Element &b) { return sub(set(a), b);};
|
||||
Element inline mul(int a, const Element &b) { return mul(set(a), b);};
|
||||
|
||||
Element inline add(const Element &a, int b) { return add(a, set(b));};
|
||||
Element inline sub(const Element &a, int b) { return sub(a, set(b));};
|
||||
Element inline mul(const Element &a, int b) { return mul(a, set(b));};
|
||||
|
||||
void inline mul1(Element &r, const Element &a, uint64_t b) { Fr_rawMMul1(r.v, a.v, b); };
|
||||
void inline neg(Element &r, const Element &a) { Fr_rawNeg(r.v, a.v); };
|
||||
void inline square(Element &r, const Element &a) { Fr_rawMSquare(r.v, a.v); };
|
||||
void inv(Element &r, const Element &a);
|
||||
void div(Element &r, const Element &a, const Element &b);
|
||||
void exp(Element &r, const Element &base, uint8_t* scalar, unsigned int scalarSize);
|
||||
|
||||
void inline toMontgomery(Element &r, const Element &a) { Fr_rawToMontgomery(r.v, a.v); };
|
||||
void inline fromMontgomery(Element &r, const Element &a) { Fr_rawFromMontgomery(r.v, a.v); };
|
||||
int inline eq(const Element &a, const Element &b) { return Fr_rawIsEq(a.v, b.v); };
|
||||
int inline isZero(const Element &a) { return Fr_rawIsZero(a.v); };
|
||||
|
||||
void toMpz(mpz_t r, const Element &a);
|
||||
void fromMpz(Element &a, const mpz_t r);
|
||||
|
||||
int toRprBE(const Element &element, uint8_t *data, int bytes);
|
||||
int fromRprBE(Element &element, const uint8_t *data, int bytes);
|
||||
|
||||
int bytes ( void ) { return Fr_N64 * 8; };
|
||||
|
||||
void fromUI(Element &r, unsigned long int v);
|
||||
|
||||
static RawFr field;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __FR_H
|
||||
|
||||
|
||||
|
||||
23
app/witnesscalc/build/fr_element.hpp
Normal file
23
app/witnesscalc/build/fr_element.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef FR_ELEMENT_HPP
|
||||
#define FR_ELEMENT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#define Fr_N64 4
|
||||
#define Fr_SHORT 0x00000000
|
||||
#define Fr_MONTGOMERY 0x40000000
|
||||
#define Fr_SHORTMONTGOMERY 0x40000000
|
||||
#define Fr_LONG 0x80000000
|
||||
#define Fr_LONGMONTGOMERY 0xC0000000
|
||||
|
||||
typedef uint64_t FrRawElement[Fr_N64];
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
int32_t shortVal;
|
||||
uint32_t type;
|
||||
FrRawElement longVal;
|
||||
} FrElement;
|
||||
|
||||
typedef FrElement *PFrElement;
|
||||
|
||||
#endif // FR_ELEMENT_HPP
|
||||
2388
app/witnesscalc/build/fr_generic.cpp
Executable file
2388
app/witnesscalc/build/fr_generic.cpp
Executable file
File diff suppressed because it is too large
Load Diff
1199
app/witnesscalc/build/fr_raw_arm64.s
Executable file
1199
app/witnesscalc/build/fr_raw_arm64.s
Executable file
File diff suppressed because it is too large
Load Diff
364
app/witnesscalc/build/fr_raw_generic.cpp
Normal file
364
app/witnesscalc/build/fr_raw_generic.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
#include "fr_element.hpp"
|
||||
#include <gmp.h>
|
||||
#include <cstring>
|
||||
|
||||
static uint64_t Fr_rawq[] = {0x43e1f593f0000001,0x2833e84879b97091,0xb85045b68181585d,0x30644e72e131a029, 0};
|
||||
static FrRawElement Fr_rawR2 = {0x1bb8e645ae216da7,0x53fe3ab1e35c59e3,0x8c49833d53bb8085,0x0216d0b17f4e44a5};
|
||||
static uint64_t Fr_np = {0xc2e1f593efffffff};
|
||||
static uint64_t lboMask = 0x3fffffffffffffff;
|
||||
|
||||
|
||||
void Fr_rawAdd(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB)
|
||||
{
|
||||
uint64_t carry = mpn_add_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
if(carry || mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawAddLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB)
|
||||
{
|
||||
uint64_t carry = mpn_add_1(pRawResult, pRawA, Fr_N64, rawB);
|
||||
|
||||
if(carry || mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawSub(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB)
|
||||
{
|
||||
uint64_t carry = mpn_sub_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
if(carry)
|
||||
{
|
||||
mpn_add_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawSubRegular(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
}
|
||||
|
||||
void Fr_rawSubSL(FrRawElement pRawResult, uint64_t rawA, FrRawElement pRawB)
|
||||
{
|
||||
FrRawElement pRawA = {rawA, 0, 0, 0};
|
||||
|
||||
uint64_t carry = mpn_sub_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
if(carry)
|
||||
{
|
||||
mpn_add_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawSubLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB)
|
||||
{
|
||||
uint64_t carry = mpn_sub_1(pRawResult, pRawA, Fr_N64, rawB);
|
||||
|
||||
if(carry)
|
||||
{
|
||||
mpn_add_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawNeg(FrRawElement pRawResult, const FrRawElement pRawA)
|
||||
{
|
||||
const uint64_t zero[Fr_N64] = {0, 0, 0, 0};
|
||||
|
||||
if (mpn_cmp(pRawA, zero, Fr_N64) != 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, Fr_rawq, pRawA, Fr_N64);
|
||||
}
|
||||
else
|
||||
{
|
||||
mpn_copyi(pRawResult, zero, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
// Substracts a long element and a short element form 0
|
||||
void Fr_rawNegLS(FrRawElement pRawResult, FrRawElement pRawA, uint64_t rawB)
|
||||
{
|
||||
uint64_t carry1 = mpn_sub_1(pRawResult, Fr_rawq, Fr_N64, rawB);
|
||||
uint64_t carry2 = mpn_sub_n(pRawResult, pRawResult, pRawA, Fr_N64);
|
||||
|
||||
if (carry1 || carry2)
|
||||
{
|
||||
mpn_add_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawCopy(FrRawElement pRawResult, const FrRawElement pRawA)
|
||||
{
|
||||
pRawResult[0] = pRawA[0];
|
||||
pRawResult[1] = pRawA[1];
|
||||
pRawResult[2] = pRawA[2];
|
||||
pRawResult[3] = pRawA[3];
|
||||
}
|
||||
|
||||
int Fr_rawIsEq(const FrRawElement pRawA, const FrRawElement pRawB)
|
||||
{
|
||||
return mpn_cmp(pRawA, pRawB, Fr_N64) == 0;
|
||||
}
|
||||
|
||||
void Fr_rawMMul(FrRawElement pRawResult, const FrRawElement pRawA, const FrRawElement pRawB)
|
||||
{
|
||||
const mp_size_t N = Fr_N64+1;
|
||||
const uint64_t *mq = Fr_rawq;
|
||||
|
||||
uint64_t np0;
|
||||
|
||||
uint64_t product0[N] = {0};
|
||||
uint64_t product1[N] = {0};
|
||||
uint64_t product2[N] = {0};
|
||||
uint64_t product3[N] = {0};
|
||||
|
||||
product0[4] = mpn_mul_1(product0, pRawB, Fr_N64, pRawA[0]);
|
||||
|
||||
np0 = Fr_np * product0[0];
|
||||
product1[1] = mpn_addmul_1(product0, mq, N, np0);
|
||||
|
||||
product1[4] = mpn_addmul_1(product1, pRawB, Fr_N64, pRawA[1]);
|
||||
mpn_add(product1, product1, N, product0+1, N-1);
|
||||
|
||||
np0 = Fr_np * product1[0];
|
||||
product2[1] = mpn_addmul_1(product1, mq, N, np0);
|
||||
|
||||
product2[4] = mpn_addmul_1(product2, pRawB, Fr_N64, pRawA[2]);
|
||||
mpn_add(product2, product2, N, product1+1, N-1);
|
||||
|
||||
np0 = Fr_np * product2[0];
|
||||
product3[1] = mpn_addmul_1(product2, mq, N, np0);
|
||||
|
||||
product3[4] = mpn_addmul_1(product3, pRawB, Fr_N64, pRawA[3]);
|
||||
mpn_add(product3, product3, N, product2+1, N-1);
|
||||
|
||||
np0 = Fr_np * product3[0];
|
||||
mpn_addmul_1(product3, mq, N, np0);
|
||||
|
||||
mpn_copyi(pRawResult, product3+1, Fr_N64);
|
||||
|
||||
if (mpn_cmp(pRawResult, mq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, mq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawMSquare(FrRawElement pRawResult, const FrRawElement pRawA)
|
||||
{
|
||||
Fr_rawMMul(pRawResult, pRawA, pRawA);
|
||||
}
|
||||
|
||||
void Fr_rawMMul1(FrRawElement pRawResult, const FrRawElement pRawA, uint64_t pRawB)
|
||||
{
|
||||
const mp_size_t N = Fr_N64+1;
|
||||
const uint64_t *mq = Fr_rawq;
|
||||
|
||||
uint64_t np0;
|
||||
|
||||
uint64_t product0[N] = {0};
|
||||
uint64_t product1[N] = {0};
|
||||
uint64_t product2[N] = {0};
|
||||
uint64_t product3[N] = {0};
|
||||
|
||||
product0[4] = mpn_mul_1(product0, pRawA, Fr_N64, pRawB);
|
||||
|
||||
np0 = Fr_np * product0[0];
|
||||
product1[1] = mpn_addmul_1(product0, mq, N, np0);
|
||||
mpn_add(product1, product1, N, product0+1, N-1);
|
||||
|
||||
np0 = Fr_np * product1[0];
|
||||
product2[1] = mpn_addmul_1(product1, mq, N, np0);
|
||||
mpn_add(product2, product2, N, product1+1, N-1);
|
||||
|
||||
np0 = Fr_np * product2[0];
|
||||
product3[1] = mpn_addmul_1(product2, mq, N, np0);
|
||||
mpn_add(product3, product3, N, product2+1, N-1);
|
||||
|
||||
np0 = Fr_np * product3[0];
|
||||
mpn_addmul_1(product3, mq, N, np0);
|
||||
|
||||
mpn_copyi(pRawResult, product3+1, Fr_N64);
|
||||
|
||||
if (mpn_cmp(pRawResult, mq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, mq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawToMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA)
|
||||
{
|
||||
Fr_rawMMul(pRawResult, pRawA, Fr_rawR2);
|
||||
}
|
||||
|
||||
void Fr_rawFromMontgomery(FrRawElement pRawResult, const FrRawElement &pRawA)
|
||||
{
|
||||
const mp_size_t N = Fr_N64+1;
|
||||
const uint64_t *mq = Fr_rawq;
|
||||
|
||||
uint64_t np0;
|
||||
|
||||
uint64_t product0[N];
|
||||
uint64_t product1[N] = {0};
|
||||
uint64_t product2[N] = {0};
|
||||
uint64_t product3[N] = {0};
|
||||
|
||||
mpn_copyi(product0, pRawA, Fr_N64); product0[4] = 0;
|
||||
|
||||
np0 = Fr_np * product0[0];
|
||||
product1[1] = mpn_addmul_1(product0, mq, N, np0);
|
||||
mpn_add(product1, product1, N, product0+1, N-1);
|
||||
|
||||
np0 = Fr_np * product1[0];
|
||||
product2[1] = mpn_addmul_1(product1, mq, N, np0);
|
||||
mpn_add(product2, product2, N, product1+1, N-1);
|
||||
|
||||
np0 = Fr_np * product2[0];
|
||||
product3[1] = mpn_addmul_1(product2, mq, N, np0);
|
||||
mpn_add(product3, product3, N, product2+1, N-1);
|
||||
|
||||
np0 = Fr_np * product3[0];
|
||||
mpn_addmul_1(product3, mq, N, np0);
|
||||
|
||||
mpn_copyi(pRawResult, product3+1, Fr_N64);
|
||||
|
||||
if (mpn_cmp(pRawResult, mq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, mq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
int Fr_rawIsZero(const FrRawElement rawA)
|
||||
{
|
||||
return mpn_zero_p(rawA, Fr_N64) ? 1 : 0;
|
||||
}
|
||||
|
||||
int Fr_rawCmp(FrRawElement pRawA, FrRawElement pRawB)
|
||||
{
|
||||
return mpn_cmp(pRawA, pRawB, Fr_N64);
|
||||
}
|
||||
|
||||
void Fr_rawSwap(FrRawElement pRawResult, FrRawElement pRawA)
|
||||
{
|
||||
FrRawElement temp;
|
||||
|
||||
temp[0] = pRawResult[0];
|
||||
temp[1] = pRawResult[1];
|
||||
temp[2] = pRawResult[2];
|
||||
temp[3] = pRawResult[3];
|
||||
|
||||
pRawResult[0] = pRawA[0];
|
||||
pRawResult[1] = pRawA[1];
|
||||
pRawResult[2] = pRawA[2];
|
||||
pRawResult[3] = pRawA[3];
|
||||
|
||||
pRawA[0] = temp[0];
|
||||
pRawA[1] = temp[1];
|
||||
pRawA[2] = temp[2];
|
||||
pRawA[3] = temp[3];
|
||||
}
|
||||
|
||||
void Fr_rawCopyS2L(FrRawElement pRawResult, int64_t val)
|
||||
{
|
||||
pRawResult[0] = val;
|
||||
pRawResult[1] = 0;
|
||||
pRawResult[2] = 0;
|
||||
pRawResult[3] = 0;
|
||||
|
||||
if (val < 0)
|
||||
{
|
||||
pRawResult[1] = -1;
|
||||
pRawResult[2] = -1;
|
||||
pRawResult[3] = -1;
|
||||
|
||||
mpn_add_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawAnd(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB)
|
||||
{
|
||||
mpn_and_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
pRawResult[3] &= lboMask;
|
||||
|
||||
if (mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawOr(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB)
|
||||
{
|
||||
mpn_ior_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
pRawResult[3] &= lboMask;
|
||||
|
||||
if (mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawXor(FrRawElement pRawResult, FrRawElement pRawA, FrRawElement pRawB)
|
||||
{
|
||||
mpn_xor_n(pRawResult, pRawA, pRawB, Fr_N64);
|
||||
|
||||
pRawResult[3] &= lboMask;
|
||||
|
||||
if (mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawShl(FrRawElement r, FrRawElement a, uint64_t b)
|
||||
{
|
||||
uint64_t bit_shift = b % 64;
|
||||
uint64_t word_shift = b / 64;
|
||||
uint64_t word_count = Fr_N64 - word_shift;
|
||||
|
||||
mpn_copyi(r + word_shift, a, word_count);
|
||||
std::memset(r, 0, word_shift * sizeof(uint64_t));
|
||||
|
||||
if (bit_shift)
|
||||
{
|
||||
mpn_lshift(r, r, Fr_N64, bit_shift);
|
||||
}
|
||||
|
||||
r[3] &= lboMask;
|
||||
|
||||
if (mpn_cmp(r, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(r, r, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawShr(FrRawElement r, FrRawElement a, uint64_t b)
|
||||
{
|
||||
const uint64_t bit_shift = b % 64;
|
||||
const uint64_t word_shift = b / 64;
|
||||
const uint64_t word_count = Fr_N64 - word_shift;
|
||||
|
||||
mpn_copyi(r, a + word_shift, word_count);
|
||||
std::memset(r + word_count, 0, word_shift * sizeof(uint64_t));
|
||||
|
||||
if (bit_shift)
|
||||
{
|
||||
mpn_rshift(r, r, Fr_N64, bit_shift);
|
||||
}
|
||||
}
|
||||
|
||||
void Fr_rawNot(FrRawElement pRawResult, FrRawElement pRawA)
|
||||
{
|
||||
mpn_com(pRawResult, pRawA, Fr_N64);
|
||||
|
||||
pRawResult[3] &= lboMask;
|
||||
|
||||
if (mpn_cmp(pRawResult, Fr_rawq, Fr_N64) >= 0)
|
||||
{
|
||||
mpn_sub_n(pRawResult, pRawResult, Fr_rawq, Fr_N64);
|
||||
}
|
||||
}
|
||||
412
app/witnesscalc/build_gmp.sh
Executable file
412
app/witnesscalc/build_gmp.sh
Executable file
@@ -0,0 +1,412 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
NPROC=8
|
||||
fetch_cmd=$( (type wget > /dev/null 2>&1 && echo "wget") || echo "curl -O" )
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "USAGE: $0 <target>"
|
||||
echo "where target is one of:"
|
||||
echo " ios: build for iOS arm64"
|
||||
echo " ios_simulator: build for iPhone Simulator for arm64/x86_64 (fat binary)"
|
||||
echo " macos: build for macOS for arm64/x86_64 (fat binary)"
|
||||
echo " macos_arm64: build for macOS arm64"
|
||||
echo " macos_x86_64: build for macOS x86_64"
|
||||
echo " android: build for Android arm64"
|
||||
echo " android_x86_64: build for Android x86_64"
|
||||
echo " host: build for this host"
|
||||
echo " host_noasm: build for this host without asm optimizations (e.g. needed for macOS)"
|
||||
echo " aarch64: build for Linux aarch64"
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
get_gmp()
|
||||
{
|
||||
GMP_NAME=gmp-6.2.1
|
||||
GMP_ARCHIVE=${GMP_NAME}.tar.xz
|
||||
GMP_URL=https://ftp.gnu.org/gnu/gmp/${GMP_ARCHIVE}
|
||||
|
||||
if [ ! -f ${GMP_ARCHIVE} ]; then
|
||||
|
||||
$fetch_cmd ${GMP_URL}
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -d gmp ]; then
|
||||
|
||||
tar -xvf ${GMP_ARCHIVE}
|
||||
mv ${GMP_NAME} gmp
|
||||
fi
|
||||
}
|
||||
|
||||
build_aarch64()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package_aarch64"
|
||||
BUILD_DIR=build_aarch64
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "aarch64 package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
export TARGET=aarch64-linux-gnu
|
||||
|
||||
echo $TARGET
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_host()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package"
|
||||
BUILD_DIR=build
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "Host package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --prefix="$PACKAGE_DIR" --with-pic --disable-fft &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_host_noasm()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package"
|
||||
BUILD_DIR=build
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "Host package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --prefix="$PACKAGE_DIR" --with-pic --disable-fft --disable-assembly &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_android()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package_android_arm64"
|
||||
BUILD_DIR=build_android_arm64
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "Android package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$ANDROID_NDK" ]; then
|
||||
|
||||
echo "ERROR: ANDROID_NDK environment variable is not set."
|
||||
echo " It must be an absolute path to the root directory of Android NDK."
|
||||
echo " For instance /home/test/Android/Sdk/ndk/23.1.7779620"
|
||||
return 1
|
||||
fi
|
||||
|
||||
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
|
||||
|
||||
export TARGET=aarch64-linux-android
|
||||
export API=21
|
||||
|
||||
export AR=$TOOLCHAIN/bin/llvm-ar
|
||||
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
|
||||
export AS=$CC
|
||||
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
|
||||
export LD=$TOOLCHAIN/bin/ld
|
||||
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
|
||||
export STRIP=$TOOLCHAIN/bin/llvm-strip
|
||||
|
||||
echo "$TOOLCHAIN"
|
||||
echo "$TARGET"
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_android_x86_64()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package_android_x86_64"
|
||||
BUILD_DIR=build_android_x86_64
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "Android package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$ANDROID_NDK" ]; then
|
||||
|
||||
echo "ERROR: ANDROID_NDK environment variable is not set."
|
||||
echo " It must be an absolute path to the root directory of Android NDK."
|
||||
echo " For instance /home/test/Android/Sdk/ndk/23.1.7779620"
|
||||
return 1
|
||||
fi
|
||||
|
||||
export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64
|
||||
|
||||
export TARGET=x86_64-linux-android
|
||||
export API=21
|
||||
|
||||
export AR=$TOOLCHAIN/bin/llvm-ar
|
||||
export CC=$TOOLCHAIN/bin/$TARGET$API-clang
|
||||
export AS=$CC
|
||||
export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
|
||||
export LD=$TOOLCHAIN/bin/ld
|
||||
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
|
||||
export STRIP=$TOOLCHAIN/bin/llvm-strip
|
||||
|
||||
echo "$TOOLCHAIN"
|
||||
echo $TARGET
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_ios()
|
||||
{
|
||||
PACKAGE_DIR="$GMP_DIR/package_ios_arm64"
|
||||
BUILD_DIR=build_ios_arm64
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "iOS package is built already. See $PACKAGE_DIR"
|
||||
return 1
|
||||
fi
|
||||
|
||||
export SDK="iphoneos"
|
||||
export TARGET=arm64-apple-darwin
|
||||
export MIN_IOS_VERSION=8.0
|
||||
|
||||
export ARCH_FLAGS="-arch arm64 -arch arm64e"
|
||||
export OPT_FLAGS="-O3 -g3 -fembed-bitcode"
|
||||
HOST_FLAGS="${ARCH_FLAGS} -miphoneos-version-min=${MIN_IOS_VERSION} -isysroot $(xcrun --sdk ${SDK} --show-sdk-path)"
|
||||
|
||||
CC=$(xcrun --find --sdk "${SDK}" clang)
|
||||
export CC
|
||||
CXX=$(xcrun --find --sdk "${SDK}" clang++)
|
||||
export CXX
|
||||
CPP=$(xcrun --find --sdk "${SDK}" cpp)
|
||||
export CPP
|
||||
export CFLAGS="${HOST_FLAGS} ${OPT_FLAGS}"
|
||||
export CXXFLAGS="${HOST_FLAGS} ${OPT_FLAGS}"
|
||||
export LDFLAGS="${HOST_FLAGS}"
|
||||
|
||||
echo $TARGET
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --host $TARGET --prefix="$PACKAGE_DIR" --with-pic --disable-fft --disable-assembly &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_ios_simulator()
|
||||
{
|
||||
libs=()
|
||||
for ARCH in "arm64" "x86_64"; do
|
||||
case "$ARCH" in
|
||||
"arm64" )
|
||||
echo "Building for iPhone Simulator arm64"
|
||||
ARCH_FLAGS="-arch arm64 -arch arm64e"
|
||||
;;
|
||||
"x86_64" )
|
||||
echo "Building for iPhone Simulator x86_64"
|
||||
ARCH_FLAGS="-arch x86_64"
|
||||
;;
|
||||
* )
|
||||
echo "Incorrect iPhone Simulator arch"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
BUILD_DIR="build_iphone_simulator_${ARCH}"
|
||||
PACKAGE_DIR="$GMP_DIR/package_iphone_simulator_${ARCH}"
|
||||
libs+=("${PACKAGE_DIR}/lib/libgmp.a")
|
||||
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "iPhone Simulator ${ARCH} package is built already. See $PACKAGE_DIR. Skip building this ARCH."
|
||||
continue
|
||||
fi
|
||||
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
../configure --prefix="${PACKAGE_DIR}" \
|
||||
CC="$(xcrun --sdk iphonesimulator --find clang)" \
|
||||
CFLAGS="-O3 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path) ${ARCH_FLAGS} -fvisibility=hidden -mios-simulator-version-min=8.0" \
|
||||
LDFLAGS="" \
|
||||
--host ${ARCH}-apple-darwin --disable-assembly --enable-static --disable-shared --with-pic &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
|
||||
cd ..
|
||||
done
|
||||
|
||||
mkdir -p "${GMP_DIR}/package_iphone_simulator/lib"
|
||||
lipo "${libs[@]}" -create -output "${GMP_DIR}/package_iphone_simulator/lib/libgmp.a"
|
||||
echo "Wrote universal fat library for iPhone Simulator arm64/x86_64 to ${GMP_DIR}/package_iphone_simulator/lib/libgmp.a"
|
||||
}
|
||||
|
||||
build_macos_arch()
|
||||
{
|
||||
ARCH="$1"
|
||||
case "$ARCH" in
|
||||
"arm64" )
|
||||
ARCH_FLAGS="-arch arm64 -arch arm64e"
|
||||
;;
|
||||
"x86_64" )
|
||||
ARCH_FLAGS="-arch x86_64"
|
||||
;;
|
||||
* )
|
||||
echo "Incorrect arch"
|
||||
exit 1
|
||||
esac
|
||||
|
||||
BUILD_DIR="build_macos_${ARCH}"
|
||||
PACKAGE_DIR="$GMP_DIR/package_macos_${ARCH}"
|
||||
if [ -d "$PACKAGE_DIR" ]; then
|
||||
echo "macOS ${ARCH} package is built already. See $PACKAGE_DIR. Skip building this ARCH."
|
||||
return
|
||||
fi
|
||||
rm -rf "$BUILD_DIR"
|
||||
mkdir "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
../configure --prefix="${PACKAGE_DIR}" \
|
||||
CC="$(xcrun --sdk macosx --find clang)" \
|
||||
CFLAGS="-O3 -isysroot $(xcrun --sdk macosx --show-sdk-path) ${ARCH_FLAGS} -fvisibility=hidden -mmacos-version-min=14.0" \
|
||||
LDFLAGS="" \
|
||||
--host "${ARCH}-apple-darwin" --disable-assembly --enable-static --disable-shared --with-pic &&
|
||||
make -j${NPROC} &&
|
||||
make install
|
||||
cd ..
|
||||
}
|
||||
|
||||
build_macos_fat()
|
||||
{
|
||||
echo "Building for macOS arm64"
|
||||
build_macos_arch "arm64"
|
||||
echo "Building for macOS x86_64"
|
||||
build_macos_arch "x86_64"
|
||||
|
||||
gmp_lib_arm64="$GMP_DIR/package_macos_arm64/lib/libgmp.a"
|
||||
gmp_lib_x86_64="$GMP_DIR/package_macos_x86_64/lib/libgmp.a"
|
||||
gmp_lib_fat="$GMP_DIR/package_macos/lib/libgmp.a"
|
||||
|
||||
mkdir -p "${GMP_DIR}/package_macos/lib"
|
||||
lipo "${gmp_lib_arm64}" "${gmp_lib_x86_64}" -create -output "${gmp_lib_fat}"
|
||||
mkdir -p "${GMP_DIR}/package_macos/include"
|
||||
cp "${GMP_DIR}/package_macos_arm64/include/gmp.h" "${GMP_DIR}/package_macos/include/"
|
||||
echo "Wrote universal fat library for macOS arm64/x86_64 to ${GMP_DIR}/package_macos/lib/libgmp.a"
|
||||
}
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
TARGET_PLATFORM=$(echo "$1" | tr "[:upper:]" "[:lower:]")
|
||||
|
||||
cd depends
|
||||
|
||||
get_gmp
|
||||
|
||||
cd gmp
|
||||
|
||||
GMP_DIR=$PWD
|
||||
|
||||
case "$TARGET_PLATFORM" in
|
||||
|
||||
"ios" )
|
||||
echo "Building for ios"
|
||||
build_ios
|
||||
;;
|
||||
|
||||
"ios_simulator" )
|
||||
echo "Building for iPhone Simulator"
|
||||
build_ios_simulator
|
||||
;;
|
||||
|
||||
"macos" )
|
||||
echo "Building fat library for macOS"
|
||||
build_macos_fat
|
||||
;;
|
||||
|
||||
"macos_arm64" )
|
||||
echo "Building library for macOS arm64"
|
||||
build_macos_arch "arm64"
|
||||
;;
|
||||
|
||||
"macos_x86_64" )
|
||||
echo "Building library for macOS x86_64"
|
||||
build_macos_arch "x86_64"
|
||||
;;
|
||||
|
||||
"android" )
|
||||
echo "Building for android"
|
||||
build_android
|
||||
;;
|
||||
|
||||
"android_x86_64" )
|
||||
echo "Building for android x86_64"
|
||||
build_android_x86_64
|
||||
;;
|
||||
|
||||
"host" )
|
||||
echo "Building for this host"
|
||||
build_host
|
||||
;;
|
||||
|
||||
"host_noasm" )
|
||||
echo "Building for this host without asm optimizations (e.g. needed for macOS)"
|
||||
build_host_noasm
|
||||
;;
|
||||
|
||||
"aarch64" )
|
||||
echo "Building for linux aarch64"
|
||||
build_aarch64
|
||||
;;
|
||||
|
||||
* )
|
||||
usage
|
||||
|
||||
esac
|
||||
82
app/witnesscalc/cmake/platform.cmake
Normal file
82
app/witnesscalc/cmake/platform.cmake
Normal file
@@ -0,0 +1,82 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
string(TOLOWER "${TARGET_PLATFORM}" TARGET_PLATFORM)
|
||||
|
||||
message("Building for " ${TARGET_PLATFORM})
|
||||
|
||||
set(GMP_ROOT depends/gmp)
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "android")
|
||||
|
||||
if(NOT DEFINED ENV{ANDROID_NDK})
|
||||
message("ANDROID_NDK environment variable is not set.")
|
||||
message("It must be an absolute path to the root directory of Android NDK.")
|
||||
message(" For instance /home/test/Android/Sdk/ndk/23.1.7779620")
|
||||
message(FATAL_ERROR "Build failed.")
|
||||
else()
|
||||
message("Android NDK path is " $ENV{ANDROID_NDK})
|
||||
endif()
|
||||
|
||||
set(CMAKE_SYSTEM_NAME Android)
|
||||
set(CMAKE_SYSTEM_VERSION 23) # API level
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "android_x86_64")
|
||||
set(CMAKE_ANDROID_ARCH_ABI x86_64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_android_x86_64)
|
||||
set(ARCH x86_64)
|
||||
else()
|
||||
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_android_arm64)
|
||||
set(ARCH arm64)
|
||||
endif()
|
||||
|
||||
message("CMAKE_ANDROID_ARCH_ABI=" ${CMAKE_ANDROID_ARCH_ABI})
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "ios")
|
||||
|
||||
set(CMAKE_SYSTEM_NAME iOS)
|
||||
|
||||
if(TARGET_PLATFORM MATCHES "ios_x86_64")
|
||||
set(CMAKE_OSX_ARCHITECTURES x86_64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_ios_x86_64)
|
||||
set(ARCH x86_64)
|
||||
else()
|
||||
set(CMAKE_OSX_ARCHITECTURES arm64)
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_ios_arm64)
|
||||
set(ARCH arm64)
|
||||
endif()
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "aarch64")
|
||||
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package_aarch64)
|
||||
set(ARCH arm64)
|
||||
|
||||
elseif(TARGET_PLATFORM MATCHES "arm64_host")
|
||||
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package)
|
||||
set(ARCH arm64)
|
||||
|
||||
else()
|
||||
set(GMP_PREFIX ${GMP_ROOT}/package)
|
||||
set(ARCH x86_64)
|
||||
|
||||
endif()
|
||||
|
||||
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(GMP_DEFINIONS -D_LONG_LONG_LIMB)
|
||||
endif()
|
||||
|
||||
|
||||
set(GMP_INCLUDE_DIR ${GMP_PREFIX}/include)
|
||||
set(GMP_INCLUDE_FILE gmp.h)
|
||||
set(GMP_LIB_DIR ${GMP_PREFIX}/lib)
|
||||
set(GMP_LIB_FILE libgmp.a)
|
||||
|
||||
set(GMP_LIB_FILE_FULLPATH ${CMAKE_SOURCE_DIR}/${GMP_LIB_DIR}/${GMP_LIB_FILE})
|
||||
set(GMP_INCLUDE_FILE_FULLPATH ${CMAKE_SOURCE_DIR}/${GMP_INCLUDE_DIR}/${GMP_INCLUDE_FILE})
|
||||
|
||||
set(GMP_LIB ${GMP_LIB_FILE_FULLPATH})
|
||||
|
||||
message("CMAKE_HOST_SYSTEM_NAME=" ${CMAKE_HOST_SYSTEM_NAME})
|
||||
message("CMAKE_SYSTEM_NAME=" ${CMAKE_SYSTEM_NAME})
|
||||
message("ARCH=" ${ARCH})
|
||||
1
app/witnesscalc/depends/json
Submodule
1
app/witnesscalc/depends/json
Submodule
Submodule app/witnesscalc/depends/json added at 199dea11b1
102
app/witnesscalc/src/CMakeLists.txt
Normal file
102
app/witnesscalc/src/CMakeLists.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
include_directories(
|
||||
../src
|
||||
../build
|
||||
../depends/json/single_include)
|
||||
|
||||
link_libraries(${GMP_LIB})
|
||||
|
||||
add_definitions(${GMP_DEFINIONS})
|
||||
|
||||
if(USE_ASM)
|
||||
if(ARCH MATCHES "arm64")
|
||||
add_definitions(-DUSE_ASM -DARCH_ARM64)
|
||||
elseif(ARCH MATCHES "x86_64")
|
||||
add_definitions(-DUSE_ASM -DARCH_X86_64)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_ASM AND ARCH MATCHES "x86_64")
|
||||
|
||||
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(NASM_FLAGS -fmacho64 --prefix _)
|
||||
else()
|
||||
set(NASM_FLAGS -felf64 -DPIC)
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fq_asm.o
|
||||
COMMAND nasm ${NASM_FLAGS} fq.asm -o fq_asm.o
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/build/fq.asm
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/build/fr_asm.o
|
||||
COMMAND nasm ${NASM_FLAGS} fr.asm -o fr_asm.o
|
||||
DEPENDS ${CMAKE_SOURCE_DIR}/build/fr.asm
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build)
|
||||
endif()
|
||||
|
||||
set(FR_SOURCES
|
||||
../build/fr.hpp
|
||||
../build/fr.cpp
|
||||
)
|
||||
|
||||
if(USE_ASM)
|
||||
if(ARCH MATCHES "arm64")
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_raw_arm64.s ../build/fr_raw_generic.cpp ../build/fr_generic.cpp)
|
||||
elseif(ARCH MATCHES "x86_64")
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_asm.o)
|
||||
endif()
|
||||
else()
|
||||
set(FR_SOURCES ${FR_SOURCES} ../build/fr_generic.cpp ../build/fr_raw_generic.cpp)
|
||||
endif()
|
||||
|
||||
add_library(fr STATIC ${FR_SOURCES})
|
||||
set_target_properties(fr PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
link_libraries(fr)
|
||||
|
||||
|
||||
add_executable(tests tests.cpp)
|
||||
add_executable(test_platform test_platform.cpp)
|
||||
|
||||
|
||||
set(LIB_SOURCES
|
||||
calcwit.cpp
|
||||
witnesscalc.h
|
||||
witnesscalc.cpp
|
||||
)
|
||||
|
||||
# authV2
|
||||
set(AUTHV2_SOURCES ${LIB_SOURCES}
|
||||
authV2.cpp
|
||||
witnesscalc_authV2.h
|
||||
witnesscalc_authV2.cpp
|
||||
)
|
||||
|
||||
add_library(witnesscalc_authV2 SHARED ${AUTHV2_SOURCES})
|
||||
add_library(witnesscalc_authV2Static STATIC ${AUTHV2_SOURCES})
|
||||
set_target_properties(witnesscalc_authV2Static PROPERTIES OUTPUT_NAME witnesscalc_authV2)
|
||||
|
||||
add_executable(authV2 main.cpp)
|
||||
target_link_libraries(authV2 witnesscalc_authV2Static)
|
||||
|
||||
target_compile_definitions(witnesscalc_authV2 PUBLIC CIRCUIT_NAME=authV2)
|
||||
target_compile_definitions(witnesscalc_authV2Static PUBLIC CIRCUIT_NAME=authV2)
|
||||
target_compile_definitions(authV2 PUBLIC CIRCUIT_NAME=authV2)
|
||||
|
||||
# proof_of_passport
|
||||
set(PROOFOFPASSPORT_SOURCES ${LIB_SOURCES}
|
||||
proof_of_passport.cpp
|
||||
witnesscalc_proof_of_passport.h
|
||||
witnesscalc_proof_of_passport.cpp
|
||||
)
|
||||
|
||||
add_library(witnesscalc_proof_of_passport SHARED ${PROOFOFPASSPORT_SOURCES})
|
||||
add_library(witnesscalc_proof_of_passportStatic STATIC ${PROOFOFPASSPORT_SOURCES})
|
||||
set_target_properties(witnesscalc_proof_of_passportStatic PROPERTIES OUTPUT_NAME witnesscalc_proof_of_passport)
|
||||
|
||||
add_executable(proof_of_passport main.cpp)
|
||||
target_link_libraries(proof_of_passport witnesscalc_proof_of_passportStatic)
|
||||
|
||||
target_compile_definitions(witnesscalc_proof_of_passport PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
target_compile_definitions(witnesscalc_proof_of_passportStatic PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
target_compile_definitions(proof_of_passport PUBLIC CIRCUIT_NAME=proof_of_passport)
|
||||
947587
app/witnesscalc/src/authV2.cpp
Normal file
947587
app/witnesscalc/src/authV2.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
app/witnesscalc/src/authV2.dat
Normal file
BIN
app/witnesscalc/src/authV2.dat
Normal file
Binary file not shown.
148
app/witnesscalc/src/calcwit.cpp
Normal file
148
app/witnesscalc/src/calcwit.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "calcwit.hpp"
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
extern void run(Circom_CalcWit* ctx);
|
||||
|
||||
|
||||
void check(bool condition) {
|
||||
if (!condition) {
|
||||
std::cerr << "assert failed" << std::endl;
|
||||
throw std::runtime_error("assert failed");
|
||||
}
|
||||
}
|
||||
|
||||
void checkWithMsg(bool condition, const char* failMsg) {
|
||||
if (!condition) {
|
||||
std::stringstream stream;
|
||||
stream << "assert failed: "
|
||||
<< failMsg;
|
||||
std::cerr << stream.str() << std::endl;
|
||||
throw std::runtime_error(stream.str());
|
||||
}
|
||||
}
|
||||
|
||||
std::string int_to_hex( u64 i )
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "0x"
|
||||
<< std::setfill ('0') << std::setw(16)
|
||||
<< std::hex << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
u64 fnv1a(std::string s) {
|
||||
u64 hash = 0xCBF29CE484222325LL;
|
||||
for(char& c : s) {
|
||||
hash ^= u64(c);
|
||||
hash *= 0x100000001B3LL;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
Circom_CalcWit::Circom_CalcWit (Circom_Circuit *aCircuit, uint maxTh) {
|
||||
circuit = aCircuit;
|
||||
inputSignalAssignedCounter = get_main_input_signal_no();
|
||||
inputSignalAssigned = new bool[inputSignalAssignedCounter];
|
||||
for (int i = 0; i< inputSignalAssignedCounter; i++) {
|
||||
inputSignalAssigned[i] = false;
|
||||
}
|
||||
signalValues = new FrElement[get_total_signal_no()];
|
||||
Fr_str2element(&signalValues[0], "1", 10);
|
||||
componentMemory = new Circom_Component[get_number_of_components()];
|
||||
circuitConstants = circuit ->circuitConstants;
|
||||
templateInsId2IOSignalInfo = circuit -> templateInsId2IOSignalInfo;
|
||||
|
||||
maxThread = maxTh;
|
||||
|
||||
// parallelism
|
||||
numThread = 0;
|
||||
|
||||
}
|
||||
|
||||
Circom_CalcWit::~Circom_CalcWit() {
|
||||
// ...
|
||||
}
|
||||
|
||||
uint Circom_CalcWit::getInputSignalHashPosition(u64 h) {
|
||||
uint n = get_size_of_input_hashmap();
|
||||
uint pos = (uint)(h % (u64)n);
|
||||
if (circuit->InputHashMap[pos].hash!=h){
|
||||
uint inipos = pos;
|
||||
pos++;
|
||||
while (pos != inipos) {
|
||||
if (circuit->InputHashMap[pos].hash==h) return pos;
|
||||
if (circuit->InputHashMap[pos].hash==0) {
|
||||
fprintf(stderr, "Signal not found\n");
|
||||
throw std::runtime_error("Signal not found");
|
||||
}
|
||||
pos = (pos+1)%n;
|
||||
}
|
||||
fprintf(stderr, "Signals not found\n");
|
||||
throw std::runtime_error("Signals not found");
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
void Circom_CalcWit::tryRunCircuit(){
|
||||
if (inputSignalAssignedCounter == 0) {
|
||||
run(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Circom_CalcWit::setInputSignal(u64 h, uint i, FrElement & val){
|
||||
if (inputSignalAssignedCounter == 0) {
|
||||
fprintf(stderr, "No more signals to be assigned\n");
|
||||
throw std::runtime_error("No more signals to be assigned");
|
||||
}
|
||||
uint pos = getInputSignalHashPosition(h);
|
||||
if (i >= circuit->InputHashMap[pos].signalsize) {
|
||||
fprintf(stderr, "Input signal array access exceeds the size\n");
|
||||
throw std::runtime_error("Input signal array access exceeds the size");
|
||||
}
|
||||
|
||||
uint si = circuit->InputHashMap[pos].signalid+i;
|
||||
if (inputSignalAssigned[si-get_main_input_signal_start()]) {
|
||||
fprintf(stderr, "Signal assigned twice: %d\n", si);
|
||||
const size_t errLn = 256;
|
||||
char err[errLn];
|
||||
snprintf(err, errLn, "Signal assigned twice: %d", si);
|
||||
throw std::runtime_error(err);
|
||||
}
|
||||
signalValues[si] = val;
|
||||
inputSignalAssigned[si-get_main_input_signal_start()] = true;
|
||||
inputSignalAssignedCounter--;
|
||||
tryRunCircuit();
|
||||
}
|
||||
|
||||
u64 Circom_CalcWit::getInputSignalSize(u64 h) {
|
||||
uint pos = getInputSignalHashPosition(h);
|
||||
return circuit->InputHashMap[pos].signalsize;
|
||||
}
|
||||
|
||||
std::string Circom_CalcWit::getTrace(u64 id_cmp){
|
||||
if (id_cmp == 0) return componentMemory[id_cmp].componentName;
|
||||
else{
|
||||
u64 id_father = componentMemory[id_cmp].idFather;
|
||||
std::string my_name = componentMemory[id_cmp].componentName;
|
||||
|
||||
return Circom_CalcWit::getTrace(id_father) + "." + my_name;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Circom_CalcWit::generate_position_array(uint* dimensions, uint size_dimensions, uint index){
|
||||
std::string positions = "";
|
||||
|
||||
for (uint i = 0 ; i < size_dimensions; i++){
|
||||
uint last_pos = index % dimensions[size_dimensions -1 - i];
|
||||
index = index / dimensions[size_dimensions -1 - i];
|
||||
std::string new_pos = "[" + std::to_string(last_pos) + "]";
|
||||
positions = new_pos + positions;
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
} //namespace
|
||||
76
app/witnesscalc/src/calcwit.hpp
Normal file
76
app/witnesscalc/src/calcwit.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#ifndef CIRCOM_CALCWIT_H
|
||||
#define CIRCOM_CALCWIT_H
|
||||
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "circom.hpp"
|
||||
#include "fr.hpp"
|
||||
|
||||
#define NMUTEXES 12 //512
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
u64 fnv1a(std::string s);
|
||||
|
||||
void check(bool condition);
|
||||
void checkWithMsg(bool condition, const char* failMsg);
|
||||
|
||||
class Circom_CalcWit {
|
||||
|
||||
bool *inputSignalAssigned;
|
||||
uint inputSignalAssignedCounter;
|
||||
|
||||
Circom_Circuit *circuit;
|
||||
|
||||
public:
|
||||
|
||||
FrElement *signalValues;
|
||||
Circom_Component* componentMemory;
|
||||
FrElement* circuitConstants;
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo;
|
||||
std::string* listOfTemplateMessages;
|
||||
|
||||
// parallelism
|
||||
std::mutex numThreadMutex;
|
||||
std::condition_variable ntcvs;
|
||||
uint numThread;
|
||||
|
||||
uint maxThread;
|
||||
|
||||
// Functions called by the circuit
|
||||
Circom_CalcWit(Circom_Circuit *aCircuit, uint numTh = NMUTEXES);
|
||||
~Circom_CalcWit();
|
||||
|
||||
// Public functions
|
||||
void setInputSignal(u64 h, uint i, FrElement &val);
|
||||
void tryRunCircuit();
|
||||
|
||||
u64 getInputSignalSize(u64 h);
|
||||
|
||||
inline uint getRemaingInputsToBeSet() {
|
||||
return inputSignalAssignedCounter;
|
||||
}
|
||||
|
||||
inline void getWitness(uint idx, PFrElement val) {
|
||||
Fr_copy(val, &signalValues[circuit->witness2SignalList[idx]]);
|
||||
}
|
||||
|
||||
std::string getTrace(u64 id_cmp);
|
||||
|
||||
std::string generate_position_array(uint* dimensions, uint size_dimensions, uint index);
|
||||
|
||||
private:
|
||||
|
||||
uint getInputSignalHashPosition(u64 h);
|
||||
|
||||
};
|
||||
|
||||
typedef void (*Circom_TemplateFunction)(uint __cIdx, Circom_CalcWit* __ctx);
|
||||
|
||||
} //namespace
|
||||
|
||||
#endif // CIRCOM_CALCWIT_H
|
||||
93
app/witnesscalc/src/circom.hpp
Normal file
93
app/witnesscalc/src/circom.hpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#ifndef __CIRCOM_H
|
||||
#define __CIRCOM_H
|
||||
|
||||
#include <map>
|
||||
#include <gmp.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "fr.hpp"
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
typedef unsigned long long u64;
|
||||
typedef uint32_t u32;
|
||||
typedef uint8_t u8;
|
||||
|
||||
//only for the main inputs
|
||||
struct __attribute__((__packed__)) HashSignalInfo {
|
||||
u64 hash;
|
||||
u64 signalid;
|
||||
u64 signalsize;
|
||||
};
|
||||
|
||||
struct IODef {
|
||||
u32 offset;
|
||||
u32 len;
|
||||
u32 *lengths;
|
||||
};
|
||||
|
||||
struct IODefPair {
|
||||
u32 len;
|
||||
IODef* defs;
|
||||
};
|
||||
|
||||
struct Circom_Circuit {
|
||||
// const char *P;
|
||||
HashSignalInfo* InputHashMap;
|
||||
u64* witness2SignalList;
|
||||
FrElement* circuitConstants;
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo;
|
||||
};
|
||||
|
||||
|
||||
struct Circom_Component {
|
||||
u32 templateId;
|
||||
u64 signalStart;
|
||||
u32 inputCounter;
|
||||
std::string templateName;
|
||||
std::string componentName;
|
||||
u64 idFather;
|
||||
u32* subcomponents;
|
||||
bool* subcomponentsParallel;
|
||||
bool *outputIsSet; //one for each output
|
||||
std::mutex *mutexes; //one for each output
|
||||
std::condition_variable *cvs;
|
||||
std::thread *sbct; //subcomponent threads
|
||||
|
||||
Circom_Component()
|
||||
: subcomponents(0), subcomponentsParallel(0), outputIsSet(0), mutexes(0), cvs(0), sbct(0)
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
For every template instantiation create two functions:
|
||||
- name_create
|
||||
- name_run
|
||||
|
||||
//PFrElement: pointer to FrElement
|
||||
|
||||
Every name_run or circom_function has:
|
||||
=====================================
|
||||
|
||||
//array of PFrElements for auxiliars in expression computation (known size);
|
||||
PFrElements expaux[];
|
||||
|
||||
//array of PFrElements for local vars (known size)
|
||||
PFrElements lvar[];
|
||||
|
||||
*/
|
||||
|
||||
uint get_main_input_signal_start();
|
||||
uint get_main_input_signal_no();
|
||||
uint get_total_signal_no();
|
||||
uint get_number_of_components();
|
||||
uint get_size_of_input_hashmap();
|
||||
uint get_size_of_witness();
|
||||
uint get_size_of_constants();
|
||||
uint get_size_of_io_map();
|
||||
|
||||
} //namespace
|
||||
#endif // __CIRCOM_H
|
||||
47
app/witnesscalc/src/filemaploader.hpp
Normal file
47
app/witnesscalc/src/filemaploader.hpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#ifndef WITNESSCALC_INTERNAL_H
|
||||
#define WITNESSCALC_INTERNAL_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class FileMapLoader
|
||||
{
|
||||
public:
|
||||
explicit FileMapLoader(const std::string &datFileName)
|
||||
{
|
||||
int fd;
|
||||
struct stat sb;
|
||||
|
||||
fd = open(datFileName.c_str(), O_RDONLY);
|
||||
if (fd == -1) {
|
||||
std::cout << ".dat file not found: " << datFileName << "\n";
|
||||
throw std::system_error(errno, std::generic_category(), "open");
|
||||
}
|
||||
|
||||
if (fstat(fd, &sb) == -1) { /* To obtain file size */
|
||||
close(fd);
|
||||
throw std::system_error(errno, std::generic_category(), "fstat");
|
||||
}
|
||||
|
||||
size = sb.st_size;
|
||||
buffer = (char*)mmap(NULL, size, PROT_READ , MAP_PRIVATE, fd, 0);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
~FileMapLoader()
|
||||
{
|
||||
munmap(buffer, size);
|
||||
}
|
||||
|
||||
FileMapLoader(const FileMapLoader&) = delete; // Delete the copy constructor
|
||||
FileMapLoader& operator=(const FileMapLoader&) = delete; // Delete the copy assignment operator
|
||||
|
||||
char *buffer;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#endif //WITNESSCALC_INTERNAL_H
|
||||
76
app/witnesscalc/src/main.cpp
Normal file
76
app/witnesscalc/src/main.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "witnesscalc.h"
|
||||
#include "filemaploader.hpp"
|
||||
|
||||
#define handle_error(msg) \
|
||||
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
||||
|
||||
void writeBinWitness(char *witnessBuffer, unsigned long witnessSize, std::string wtnsFileName)
|
||||
{
|
||||
FILE *write_ptr;
|
||||
write_ptr = fopen(wtnsFileName.c_str(),"wb");
|
||||
|
||||
if (write_ptr == NULL) {
|
||||
std::string msg("Could not open ");
|
||||
msg += wtnsFileName + " for write";
|
||||
throw std::system_error(errno, std::generic_category(), msg);
|
||||
}
|
||||
|
||||
fwrite(witnessBuffer, witnessSize, 1, write_ptr);
|
||||
fclose(write_ptr);
|
||||
}
|
||||
|
||||
static const size_t WitnessBufferSize = 4*1024*1024;
|
||||
static char WitnessBuffer[WitnessBufferSize];
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
|
||||
std::string cl(argv[0]);
|
||||
|
||||
if (argc!=3) {
|
||||
std::cout << "Usage: " << cl << " <input.json> <output.wtns>\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
std::string datfile = cl + ".dat";
|
||||
std::string jsonfile(argv[1]);
|
||||
std::string wtnsFileName(argv[2]);
|
||||
|
||||
size_t witnessSize = sizeof(WitnessBuffer);
|
||||
char errorMessage[256];
|
||||
|
||||
FileMapLoader jsonLoader(jsonfile);
|
||||
|
||||
int error = CIRCUIT_NAME::witnesscalc_from_dat_file(datfile.c_str(),
|
||||
jsonLoader.buffer, jsonLoader.size,
|
||||
WitnessBuffer, &witnessSize,
|
||||
errorMessage, sizeof(errorMessage));
|
||||
|
||||
if (error == WITNESSCALC_ERROR_SHORT_BUFFER) {
|
||||
|
||||
std::cerr << "Error: Short buffer for witness."
|
||||
<< " It should " << witnessSize << " bytes at least." << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if (error) {
|
||||
|
||||
std::cerr << errorMessage << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
writeBinWitness(WitnessBuffer, witnessSize, wtnsFileName);
|
||||
|
||||
} catch (std::exception* e) {
|
||||
std::cerr << e->what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
972300
app/witnesscalc/src/proof_of_passport.cpp
Normal file
972300
app/witnesscalc/src/proof_of_passport.cpp
Normal file
File diff suppressed because it is too large
Load Diff
BIN
app/witnesscalc/src/proof_of_passport.dat
Normal file
BIN
app/witnesscalc/src/proof_of_passport.dat
Normal file
Binary file not shown.
21
app/witnesscalc/src/stub.cpp
Normal file
21
app/witnesscalc/src/stub.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "circom.hpp"
|
||||
#include "calcwit.hpp"
|
||||
|
||||
uint get_main_input_signal_start() {return 0;}
|
||||
|
||||
uint get_main_input_signal_no() {return 0;}
|
||||
|
||||
uint get_total_signal_no() {return 0;}
|
||||
|
||||
uint get_number_of_components() {return 0;}
|
||||
|
||||
uint get_size_of_input_hashmap() {return 0;}
|
||||
|
||||
uint get_size_of_witness() {return 0;}
|
||||
|
||||
uint get_size_of_constants() {return 0;}
|
||||
|
||||
uint get_size_of_io_map() {return 0;}
|
||||
|
||||
void run(Circom_CalcWit* ctx){
|
||||
}
|
||||
28
app/witnesscalc/src/test_platform.cpp
Normal file
28
app/witnesscalc/src/test_platform.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <gmp.h>
|
||||
#include "fr.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "sizeof int32_t : " << sizeof(int32_t) << std::endl;
|
||||
std::cout << "sizeof int64_t : " << sizeof(int64_t) << std::endl;
|
||||
|
||||
std::cout << "sizeof int : " << sizeof(int) << std::endl;
|
||||
std::cout << "sizeof unsigned int : " << sizeof(unsigned int) << std::endl;
|
||||
std::cout << "sizeof long : " << sizeof(long) << std::endl;
|
||||
std::cout << "sizeof unsigned long : " << sizeof(unsigned long) << std::endl;
|
||||
std::cout << "sizeof long long : " << sizeof(long long) << std::endl;
|
||||
std::cout << "sizeof unsigned long long : " << sizeof(unsigned long long) << std::endl;
|
||||
std::cout << "sizeof mp_limb_t : " << sizeof(mp_limb_t) << std::endl;
|
||||
std::cout << "sizeof mp_limb_signed_t : " << sizeof(mp_limb_signed_t) << std::endl;
|
||||
std::cout << "sizeof FrRawElement : " << sizeof(FrRawElement) << std::endl;
|
||||
std::cout << "sizeof FrElement : " << sizeof(FrElement) << std::endl;
|
||||
|
||||
int32_t x = -5;
|
||||
uint32_t y = 5;
|
||||
|
||||
std::cout << "-5 >> 1 : " << (x >> 1) << std::endl;
|
||||
std::cout << "5 >> 1 : " << (y >> 1) << std::endl;
|
||||
}
|
||||
5611
app/witnesscalc/src/tests.cpp
Normal file
5611
app/witnesscalc/src/tests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
339
app/witnesscalc/src/witnesscalc.cpp
Normal file
339
app/witnesscalc/src/witnesscalc.cpp
Normal file
@@ -0,0 +1,339 @@
|
||||
#include "witnesscalc.h"
|
||||
#include "filemaploader.hpp"
|
||||
#include "calcwit.hpp"
|
||||
#include "circom.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
Circom_Circuit* loadCircuit(const void *buffer, unsigned long buffer_size) {
|
||||
if (buffer_size % sizeof(u32) != 0) {
|
||||
throw std::runtime_error("Invalid circuit file: wrong buffer_size");
|
||||
}
|
||||
|
||||
Circom_Circuit *circuit = new Circom_Circuit;
|
||||
|
||||
u8* bdata = (u8*)buffer;
|
||||
|
||||
circuit->InputHashMap = new HashSignalInfo[get_size_of_input_hashmap()];
|
||||
uint dsize = get_size_of_input_hashmap()*sizeof(HashSignalInfo);
|
||||
if (buffer_size < dsize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize");
|
||||
}
|
||||
memcpy((void *)(circuit->InputHashMap), (void *)bdata, dsize);
|
||||
|
||||
circuit->witness2SignalList = new u64[get_size_of_witness()];
|
||||
uint inisize = dsize;
|
||||
dsize = get_size_of_witness()*sizeof(u64);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)(circuit->witness2SignalList), (void *)(bdata+inisize), dsize);
|
||||
|
||||
circuit->circuitConstants = new FrElement[get_size_of_constants()];
|
||||
if (get_size_of_constants()>0) {
|
||||
inisize += dsize;
|
||||
dsize = get_size_of_constants()*sizeof(FrElement);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)(circuit->circuitConstants), (void *)(bdata+inisize), dsize);
|
||||
}
|
||||
|
||||
std::map<u32,IODefPair> templateInsId2IOSignalInfo1;
|
||||
if (get_size_of_io_map()>0) {
|
||||
u32 index[get_size_of_io_map()];
|
||||
inisize += dsize;
|
||||
dsize = get_size_of_io_map()*sizeof(u32);
|
||||
if (buffer_size < dsize + inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= dsize + inisize");
|
||||
}
|
||||
memcpy((void *)index, (void *)(bdata+inisize), dsize);
|
||||
inisize += dsize;
|
||||
if (inisize % sizeof(u32) != 0) {
|
||||
throw std::runtime_error("Invalid circuit file: wrong inisize");
|
||||
}
|
||||
if (buffer_size <= inisize) {
|
||||
throw std::runtime_error("Invalid circuit file: buffer_size <= inisize");
|
||||
}
|
||||
u32 dataiomap[(buffer_size-inisize)/sizeof(u32)];
|
||||
memcpy((void *)dataiomap, (void *)(bdata+inisize), buffer_size-inisize);
|
||||
u32* pu32 = dataiomap;
|
||||
|
||||
for (int i = 0; i < get_size_of_io_map(); i++) {
|
||||
u32 n = *pu32;
|
||||
IODefPair p;
|
||||
p.len = n;
|
||||
IODef defs[n];
|
||||
pu32 += 1;
|
||||
for (u32 j = 0; j <n; j++){
|
||||
defs[j].offset=*pu32;
|
||||
u32 len = *(pu32+1);
|
||||
defs[j].len = len;
|
||||
defs[j].lengths = new u32[len];
|
||||
memcpy((void *)defs[j].lengths,(void *)(pu32+2),len*sizeof(u32));
|
||||
pu32 += len + 2;
|
||||
}
|
||||
p.defs = (IODef*)calloc(10, sizeof(IODef));
|
||||
for (u32 j = 0; j < p.len; j++){
|
||||
p.defs[j] = defs[j];
|
||||
}
|
||||
templateInsId2IOSignalInfo1[index[i]] = p;
|
||||
}
|
||||
}
|
||||
circuit->templateInsId2IOSignalInfo = std::move(templateInsId2IOSignalInfo1);
|
||||
|
||||
return circuit;
|
||||
}
|
||||
|
||||
bool check_valid_number(std::string & s, uint base){
|
||||
bool is_valid = true;
|
||||
if (base == 16){
|
||||
for (uint i = 0; i < s.size(); i++){
|
||||
is_valid &= (
|
||||
('0' <= s[i] && s[i] <= '9') ||
|
||||
('a' <= s[i] && s[i] <= 'f') ||
|
||||
('A' <= s[i] && s[i] <= 'F')
|
||||
);
|
||||
}
|
||||
} else{
|
||||
for (uint i = 0; i < s.size(); i++){
|
||||
is_valid &= ('0' <= s[i] && s[i] < char(int('0') + base));
|
||||
}
|
||||
}
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
void json2FrElements (json val, std::vector<FrElement> & vval){
|
||||
if (!val.is_array()) {
|
||||
FrElement v;
|
||||
std::string s_aux, s;
|
||||
uint base;
|
||||
if (val.is_string()) {
|
||||
s_aux = val.get<std::string>();
|
||||
std::string possible_prefix = s_aux.substr(0, 2);
|
||||
if (possible_prefix == "0b" || possible_prefix == "0B"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 2;
|
||||
} else if (possible_prefix == "0o" || possible_prefix == "0O"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 8;
|
||||
} else if (possible_prefix == "0x" || possible_prefix == "0X"){
|
||||
s = s_aux.substr(2, s_aux.size() - 2);
|
||||
base = 16;
|
||||
} else{
|
||||
s = s_aux;
|
||||
base = 10;
|
||||
}
|
||||
if (!check_valid_number(s, base)){
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Invalid number in JSON input: " << s_aux << "\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
} else if (val.is_number()) {
|
||||
double vd = val.get<double>();
|
||||
std::stringstream stream;
|
||||
stream << std::fixed << std::setprecision(0) << vd;
|
||||
s = stream.str();
|
||||
base = 10;
|
||||
} else {
|
||||
throw std::runtime_error("Invalid JSON type");
|
||||
}
|
||||
Fr_str2element (&v, s.c_str(), base);
|
||||
vval.push_back(v);
|
||||
} else {
|
||||
for (uint i = 0; i < val.size(); i++) {
|
||||
json2FrElements (val[i], vval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadJson(Circom_CalcWit *ctx, const char *json_buffer, unsigned long buffer_size) {
|
||||
|
||||
json j = json::parse(json_buffer, json_buffer + buffer_size);
|
||||
|
||||
u64 nItems = j.size();
|
||||
// printf("Items : %llu\n",nItems);
|
||||
if (nItems == 0){
|
||||
ctx->tryRunCircuit();
|
||||
}
|
||||
for (json::iterator it = j.begin(); it != j.end(); ++it) {
|
||||
// std::cout << it.key() << " => " << it.value() << '\n';
|
||||
u64 h = fnv1a(it.key());
|
||||
std::vector<FrElement> v;
|
||||
json2FrElements(it.value(),v);
|
||||
uint signalSize = ctx->getInputSignalSize(h);
|
||||
if (v.size() < signalSize) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error loading signal " << it.key() << ": Not enough values\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
if (v.size() > signalSize) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error loading signal " << it.key() << ": Too many values\n";
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
for (uint i = 0; i<v.size(); i++){
|
||||
try {
|
||||
// std::cout << it.key() << "," << i << " => " << Fr_element2str(&(v[i])) << '\n';
|
||||
ctx->setInputSignal(h,i,v[i]);
|
||||
} catch (std::runtime_error e) {
|
||||
std::ostringstream errStrStream;
|
||||
errStrStream << "Error setting signal: " << it.key() << "\n" << e.what();
|
||||
throw std::runtime_error(errStrStream.str() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long getBinWitnessSize() {
|
||||
|
||||
uint Nwtns = get_size_of_witness();
|
||||
|
||||
return 44 + Fr_N64*8 * (Nwtns + 1);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const void *src, unsigned long src_size) {
|
||||
|
||||
memcpy(buffer, src, src_size);
|
||||
return buffer + src_size;
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const u32 src) {
|
||||
|
||||
return appendBuffer(buffer, &src, 4);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const u64 src) {
|
||||
|
||||
return appendBuffer(buffer, &src, 8);
|
||||
}
|
||||
|
||||
char *appendBuffer(char *buffer, const FrRawElement src) {
|
||||
|
||||
return appendBuffer(buffer, src, Fr_N64*8);
|
||||
}
|
||||
|
||||
void storeBinWitness(Circom_CalcWit *ctx, char *buffer) {
|
||||
|
||||
buffer = appendBuffer(buffer, "wtns", 4);
|
||||
|
||||
u32 version = 2;
|
||||
buffer = appendBuffer(buffer, version);
|
||||
|
||||
u32 nSections = 2;
|
||||
buffer = appendBuffer(buffer, nSections);
|
||||
|
||||
// Header
|
||||
u32 idSection1 = 1;
|
||||
buffer = appendBuffer(buffer, idSection1);
|
||||
|
||||
u32 n8 = Fr_N64*8;
|
||||
|
||||
u64 idSection1length = 8 + n8;
|
||||
buffer = appendBuffer(buffer, idSection1length);
|
||||
|
||||
buffer = appendBuffer(buffer, n8);
|
||||
|
||||
buffer = appendBuffer(buffer, Fr_q.longVal);
|
||||
|
||||
uint Nwtns = get_size_of_witness();
|
||||
|
||||
u32 nVars = (u32)Nwtns;
|
||||
buffer = appendBuffer(buffer, nVars);
|
||||
|
||||
// Data
|
||||
u32 idSection2 = 2;
|
||||
buffer = appendBuffer(buffer, idSection2);
|
||||
|
||||
u64 idSection2length = (u64)n8*(u64)Nwtns;
|
||||
buffer = appendBuffer(buffer, idSection2length);
|
||||
|
||||
FrElement v;
|
||||
|
||||
for (int i=0;i<Nwtns;i++) {
|
||||
ctx->getWitness(i, &v);
|
||||
Fr_toLongNormal(&v, &v);
|
||||
buffer = appendBuffer(buffer, v.longVal);
|
||||
}
|
||||
}
|
||||
|
||||
int witnesscalc(
|
||||
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)
|
||||
{
|
||||
unsigned long witnessSize = getBinWitnessSize();
|
||||
|
||||
if (*wtns_size < witnessSize) {
|
||||
*wtns_size = witnessSize;
|
||||
return WITNESSCALC_ERROR_SHORT_BUFFER;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
std::unique_ptr<Circom_Circuit> circuit(loadCircuit(circuit_buffer, circuit_size));
|
||||
|
||||
std::unique_ptr<Circom_CalcWit> ctx(new Circom_CalcWit(circuit.get()));
|
||||
|
||||
loadJson(ctx.get(), json_buffer, json_size);
|
||||
|
||||
if (ctx->getRemaingInputsToBeSet() != 0) {
|
||||
std::stringstream stream;
|
||||
stream << "Not all inputs have been set. Only "
|
||||
<< get_main_input_signal_no()-ctx->getRemaingInputsToBeSet()
|
||||
<< " out of " << get_main_input_signal_no();
|
||||
|
||||
strncpy(error_msg, stream.str().c_str(), error_msg_maxsize);
|
||||
return WITNESSCALC_ERROR;
|
||||
}
|
||||
|
||||
storeBinWitness(ctx.get(), wtns_buffer);
|
||||
*wtns_size = witnessSize;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, e.what(), error_msg_maxsize);
|
||||
}
|
||||
return WITNESSCALC_ERROR;
|
||||
|
||||
} catch (std::exception *e) {
|
||||
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, e->what(), error_msg_maxsize);
|
||||
}
|
||||
delete e;
|
||||
return WITNESSCALC_ERROR;
|
||||
|
||||
} catch (...) {
|
||||
if (error_msg) {
|
||||
strncpy(error_msg, "unknown error", error_msg_maxsize);
|
||||
}
|
||||
return WITNESSCALC_ERROR;
|
||||
}
|
||||
|
||||
return WITNESSCALC_OK;
|
||||
}
|
||||
|
||||
int witnesscalc_from_dat_file(
|
||||
const char *dat_fname,
|
||||
const char *json_buffer, unsigned long json_size,
|
||||
char *wtns_buffer, unsigned long *wtns_size,
|
||||
char *error_msg, unsigned long error_msg_maxsize)
|
||||
{
|
||||
|
||||
std::string s(dat_fname);
|
||||
FileMapLoader dat(dat_fname);
|
||||
return witnesscalc(dat.buffer, dat.size, json_buffer,
|
||||
json_size, wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
44
app/witnesscalc/src/witnesscalc.h
Normal file
44
app/witnesscalc/src/witnesscalc.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef WITNESSCALC_H
|
||||
#define WITNESSCALC_H
|
||||
|
||||
namespace CIRCUIT_NAME {
|
||||
|
||||
#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(
|
||||
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);
|
||||
|
||||
/**
|
||||
* A wrapper function for `witnesscalc` that takes the circuit as a .dat file
|
||||
* name instead of a buffer.
|
||||
*/
|
||||
int
|
||||
witnesscalc_from_dat_file(
|
||||
const char *dat_fname,
|
||||
const char *json_buffer, unsigned long json_size,
|
||||
char *wtns_buffer, unsigned long *wtns_size,
|
||||
char *error_msg, unsigned long error_msg_maxsize);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // WITNESSCALC_H
|
||||
15
app/witnesscalc/src/witnesscalc_authV2.cpp
Normal file
15
app/witnesscalc/src/witnesscalc_authV2.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "witnesscalc_authV2.h"
|
||||
#include "witnesscalc.h"
|
||||
|
||||
int
|
||||
witnesscalc_authV2(
|
||||
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)
|
||||
{
|
||||
return CIRCUIT_NAME::witnesscalc(circuit_buffer, circuit_size,
|
||||
json_buffer, json_size,
|
||||
wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
39
app/witnesscalc/src/witnesscalc_authV2.h
Normal file
39
app/witnesscalc/src/witnesscalc_authV2.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef WITNESSCALC_AUTHV2_H
|
||||
#define WITNESSCALC_AUTHV2_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_authV2(
|
||||
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_AUTHV2_H
|
||||
15
app/witnesscalc/src/witnesscalc_proof_of_passport.cpp
Normal file
15
app/witnesscalc/src/witnesscalc_proof_of_passport.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "witnesscalc_proof_of_passport.h"
|
||||
#include "witnesscalc.h"
|
||||
|
||||
int
|
||||
witnesscalc_proof_of_passport(
|
||||
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)
|
||||
{
|
||||
return CIRCUIT_NAME::witnesscalc(circuit_buffer, circuit_size,
|
||||
json_buffer, json_size,
|
||||
wtns_buffer, wtns_size,
|
||||
error_msg, error_msg_maxsize);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user