Skip to content

Commit d07d43c

Browse files
authored
Merge pull request #7 from anon-aadhaar/feat/frameworks
Feat/frameworks
2 parents 7d0c774 + a5a002a commit d07d43c

24 files changed

+657
-195
lines changed

anon-aadhaar-react-native.podspec

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ Pod::Spec.new do |s|
1414
s.platforms = { :ios => min_ios_version_supported }
1515
s.source = { :git => "https://github.com/Meyanis95/anon-aadhaar-react-native.git", :tag => "#{s.version}" }
1616

17-
s.source_files = 'ios/**/*.{h,m,mm,swift}'
18-
s.public_header_files = 'ios/*.h'
19-
s.vendored_libraries = "ios/libmopro_ffi.a"
20-
s.preserve_paths = 'ios/moproFFI.modulemap'
21-
s.resource = 'ios/anonAadhaar.dylib'
17+
s.vendored_frameworks = 'ios/Frameworks/MoproBindings.xcframework'
18+
s.source_files = "ios/Frameworks/MoproBindings.xcframework/ios-arm64/Headers/*.{h,m,swift}"
2219

2320
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2421
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
@@ -42,5 +39,5 @@ Pod::Spec.new do |s|
4239
s.dependency "RCTTypeSafety"
4340
s.dependency "ReactCommon/turbomodule/core"
4441
end
45-
end
42+
end
4643
end

example/ios/AnonAadhaarApp.xcodeproj/project.pbxproj

+79-69
Large diffs are not rendered by default.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "App Icon 1024.png",
5+
"idiom" : "universal",
6+
"platform" : "ios",
7+
"size" : "1024x1024"
8+
}
9+
],
10+
"info" : {
11+
"author" : "xcode",
12+
"version" : 1
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}

example/ios/Podfile

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ target 'AnonAadhaarApp' do
3939
:app_path => "#{Pod::Config.instance.installation_root}/.."
4040
)
4141

42+
pod 'CircuitBindings', :path => '../../ios/Frameworks/CircuitBindings.podspec'
43+
4244
target 'AnonAadhaarAppTests' do
4345
inherit! :complete
4446
# Pods for testing

example/src/App.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import React, { useEffect, useState } from 'react';
22
import { setupMopro } from '@anon-aadhaar/react-native';
33
import { OnboardingScreen } from './OnboardingScreen';
44
import { MainScreen } from './MainScreen';
5+
import BenchmarkView from './BenchmarkView';
6+
7+
export type Views = 'Onboarding' | 'Main' | 'Benchmark';
58

69
export default function App() {
710
const [setupReady, setSetupReady] = useState<boolean>(false);
8-
const [currentScreen, setCurrentScreen] = useState<string>('Onboarding');
11+
const [currentScreen, setCurrentScreen] = useState<Views>('Onboarding');
912

1013
useEffect(() => {
1114
try {
@@ -28,6 +31,9 @@ export default function App() {
2831
/>
2932
)}
3033
{currentScreen === 'Main' && <MainScreen />}
34+
{currentScreen === 'Benchmark' && (
35+
<BenchmarkView setupReady={setupReady} />
36+
)}
3137
</>
3238
);
3339
}

example/src/BenchmarkView.tsx

+70-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import {
1616
import { useEffect, useState } from 'react';
1717
import { circuitInputsFromQR } from '../../src/generateInputs';
1818

19+
const Toast = ({ message }: { message: string }) => (
20+
<View style={styles.toastContainer}>
21+
<Text style={styles.toastText}>{message}</Text>
22+
</View>
23+
);
24+
1925
export default function BenchmarkView({ setupReady }: { setupReady: boolean }) {
2026
const [complexProof, setComplexProof] = useState<string | null>(null);
2127
const [publicInputs, setPublicInputs] = useState<string | null>(null);
@@ -25,12 +31,21 @@ export default function BenchmarkView({ setupReady }: { setupReady: boolean }) {
2531
const [isVerifyingSig, setIsVerifyingSig] = useState<boolean>(false);
2632
const [isQrScanned, setIsQrScanned] = useState<boolean>(false);
2733
const [sigVerified, setSigVerified] = useState<boolean>(false);
34+
const [errorToastMessage, setErrorToastMessage] = useState<string | null>(
35+
null
36+
);
2837
const [anonAadhaarArgs, setAnonAadhaarArgs] = useState<{
29-
aadhaarData: string[];
30-
aadhaarDataLength: string[];
38+
qrDataPadded: string[];
39+
qrDataPaddedLength: string[];
40+
nonPaddedDataLength: string[];
41+
delimiterIndices: string[];
3142
signature: string[];
3243
pubKey: string[];
3344
signalHash: string[];
45+
revealGender: string[];
46+
revealAgeAbove18: string[];
47+
revealState: string[];
48+
revealPinCode: string[];
3449
} | null>(null);
3550
const [qrCodeValue, setQrCodeValue] = useState<string>('');
3651
const [executionTime, setExecutionTime] = useState<{
@@ -59,25 +74,52 @@ export default function BenchmarkView({ setupReady }: { setupReady: boolean }) {
5974
}
6075
}, [qrCodeValue]);
6176

77+
const showToast = (message: string) => {
78+
setErrorToastMessage(message);
79+
setTimeout(() => setErrorToastMessage(null), 3000); // hide after 3 seconds
80+
};
81+
6282
const genProof = async () => {
63-
setIsProving(true);
64-
const startProof = Date.now();
65-
const { proof, inputs } = await generateProof(anonAadhaarArgs);
66-
setComplexProof(proof);
67-
setPublicInputs(inputs);
68-
setExecutionTime((prev) => ({ ...prev, proof: Date.now() - startProof }));
69-
setIsProving(false);
83+
try {
84+
setIsProving(true);
85+
const startProof = Date.now();
86+
const { proof, inputs } = await generateProof(anonAadhaarArgs);
87+
setComplexProof(proof);
88+
setPublicInputs(inputs);
89+
setExecutionTime((prev) => ({ ...prev, proof: Date.now() - startProof }));
90+
setIsProving(false);
91+
} catch (e) {
92+
if (e instanceof Error) {
93+
showToast(e.message);
94+
} else {
95+
throw new Error('generateProof: something went wrong!');
96+
}
97+
}
7098
};
7199

72100
const verifProof = async (_proof: any, _publicInputs: any) => {
73-
const startVerif = Date.now();
74-
const res = await verifyProof(_proof, _publicInputs);
75-
setProofVerified(res);
76-
setExecutionTime((prev) => ({ ...prev, verify: Date.now() - startVerif }));
101+
try {
102+
const startVerif = Date.now();
103+
const res = await verifyProof(_proof, _publicInputs);
104+
console.log('Verification result: ', res);
105+
setProofVerified(res);
106+
setExecutionTime((prev) => ({
107+
...prev,
108+
verify: Date.now() - startVerif,
109+
}));
110+
} catch (e) {
111+
if (e instanceof Error) {
112+
showToast(e.message);
113+
} else {
114+
throw new Error('verifProof: something went wrong!');
115+
}
116+
}
77117
};
78118

79119
return (
80120
<View style={styles.container}>
121+
{errorToastMessage && <Toast message={errorToastMessage} />}
122+
81123
<Text style={styles.title}>Anon Aadhaar Mobile</Text>
82124
<View style={styles.statusRow}>
83125
<View
@@ -209,4 +251,19 @@ const styles = StyleSheet.create({
209251
justifyContent: 'center',
210252
alignItems: 'center',
211253
},
254+
toastContainer: {
255+
position: 'absolute',
256+
bottom: 50,
257+
left: 20,
258+
right: 20,
259+
backgroundColor: 'red',
260+
padding: 15,
261+
borderRadius: 5,
262+
alignItems: 'center',
263+
justifyContent: 'center',
264+
zIndex: 1000, // Make sure it's above other elements
265+
},
266+
toastText: {
267+
color: 'white',
268+
},
212269
});

example/src/OnboardingScreen.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import {
1717
import messages from '../assets/messages.json';
1818
import { CircularProgress } from './CircleProgress';
1919
import { ProgressBar } from './ProgressBar';
20+
import type { Views } from './App';
2021

2122
export type OnboardingScreenProps = {
2223
setupReady?: boolean;
23-
setCurrentScreen: Dispatch<SetStateAction<string>>;
24+
setCurrentScreen: Dispatch<SetStateAction<Views>>;
2425
};
2526

2627
const images = [
@@ -75,6 +76,12 @@ export const OnboardingScreen: FunctionComponent<OnboardingScreenProps> = ({
7576

7677
return (
7778
<SafeAreaView style={styles.safeArea}>
79+
<TouchableOpacity
80+
style={styles.shortcut}
81+
onPress={() => setCurrentScreen('Benchmark')}
82+
>
83+
<Text style={styles.buttonText}>Go to benchmark</Text>
84+
</TouchableOpacity>
7885
<View style={styles.content}>
7986
<View style={styles.scrollView}>
8087
{isLoading && null}
@@ -176,6 +183,10 @@ const styles = StyleSheet.create({
176183
backgroundColor: '#06753b',
177184
borderRadius: 50,
178185
},
186+
shortcut: {
187+
paddingHorizontal: 70,
188+
paddingVertical: 15,
189+
},
179190
buttonDisabled: {
180191
paddingHorizontal: 70,
181192
paddingVertical: 15,

example/src/ProgressBar.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import React from 'react';
22
import { StyleSheet, View } from 'react-native';
33

4-
export const ProgressBar = ({ currentIndex, itemCount }) => {
4+
export const ProgressBar = ({
5+
currentIndex,
6+
itemCount,
7+
}: {
8+
currentIndex: number;
9+
itemCount: number;
10+
}) => {
511
return (
612
<View style={styles.progressBarContainer}>
713
{Array.from({ length: itemCount }, (_, index) => (
@@ -28,7 +34,7 @@ const styles = StyleSheet.create({
2834
height: 8, // Small height for dots
2935
borderRadius: 4, // Half of width/height to make it circular
3036
marginHorizontal: 4, // Spacing between dots
31-
transition: 'all 0.2s ease-in-out', // Smooth transition for web, ignored in native
37+
// transition: 'all 0.2s ease-in-out', // Smooth transition for web, ignored in native
3238
},
3339
activeDot: {
3440
backgroundColor: '#06753b', // Active dot color

example/src/ProofModal.tsx

+17-7
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ const ProveScreen = ({
9999

100100
const genProof = async () => {
101101
setIsProving(true);
102-
const { proof, inputs } = await generateProof(anonAadhaarArgs);
103-
const res = await verifyProof(proof, inputs);
104-
setProofs({ proof, inputs });
105-
setProofVerified(res);
106-
setIsProving(false);
102+
try {
103+
const { proof, inputs } = await generateProof(anonAadhaarArgs);
104+
const res = await verifyProof(proof, inputs);
105+
setProofs({ proof, inputs });
106+
setProofVerified(res);
107+
setIsProving(false);
108+
} catch (e) {
109+
console.error(e);
110+
}
107111
};
108112

109113
return (
@@ -141,11 +145,17 @@ export const ProofModal = ({
141145
const [qrCodeValue, setQrCodeValue] = useState<string>('');
142146
const [proofVerified, setProofVerified] = useState<boolean>(false);
143147
const [anonAadhaarArgs, setAnonAadhaarArgs] = useState<{
144-
aadhaarData: string[];
145-
aadhaarDataLength: string[];
148+
qrDataPadded: string[];
149+
qrDataPaddedLength: string[];
150+
nonPaddedDataLength: string[];
151+
delimiterIndices: string[];
146152
signature: string[];
147153
pubKey: string[];
148154
signalHash: string[];
155+
revealGender: string[];
156+
revealAgeAbove18: string[];
157+
revealState: string[];
158+
revealPinCode: string[];
149159
} | null>(null);
150160

151161
useEffect(() => {
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Pod::Spec.new do |spec|
2+
spec.name = 'CircuitBindings'
3+
spec.version = '0.1.0'
4+
spec.summary = 'CircuitBindings XCFramework'
5+
spec.homepage = 'https://github.com/oskarth/mopro'
6+
spec.license = { :type => 'MIT/Apache-2.0', :file => 'LICENSE' }
7+
spec.author = { 'Mopro' => '[email protected]' }
8+
spec.platform = :ios, '13.0'
9+
spec.source = { :path => 'CircuitBindings.xcframework' }
10+
spec.vendored_frameworks = 'CircuitBindings.xcframework'
11+
end
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>BinaryPath</key>
9+
<string>anonAadhaar.dylib</string>
10+
<key>LibraryIdentifier</key>
11+
<string>ios-arm64</string>
12+
<key>LibraryPath</key>
13+
<string>anonAadhaar.dylib</string>
14+
<key>SupportedArchitectures</key>
15+
<array>
16+
<string>arm64</string>
17+
</array>
18+
<key>SupportedPlatform</key>
19+
<string>ios</string>
20+
</dict>
21+
</array>
22+
<key>CFBundlePackageType</key>
23+
<string>XFWK</string>
24+
<key>XCFrameworkFormatVersion</key>
25+
<string>1.0</string>
26+
<key>CFBundleIdentifier</key>
27+
<string>com.example.CircuitBindings</string>
28+
</dict>
29+
</plist>

0 commit comments

Comments
 (0)