Repository navigation
Expand file tree
/
Copy pathtest-local.sh
More file actions
executable file
·196 lines (152 loc) · 5.71 KB
/
Copy pathtest-local.sh
File metadata and controls
executable file
·196 lines (152 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
echo "�� React Native Kyber & Dilithium - NPM Only Testing Script"
echo "============================================================"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
print_status() { echo -e "${GREEN}✅ $1${NC}"; }
print_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
print_error() { echo -e "${RED}❌ $1${NC}"; }
# Ensure we're using npm
export npm_config_package_manager=npm
unset npm_config_user_config
print_status "Forcing npm usage (no yarn)"
# Step 1: Build package
echo ""
echo "📦 Building package..."
npm run prepack && npm pack
TARBALL=$(ls react-native-kyber-*.tgz 2>/dev/null | head -n 1)
if [ -z "$TARBALL" ]; then
print_error "No tarball found"
exit 1
fi
print_status "Created: $TARBALL"
# Step 2: Create test project
echo ""
echo "🚀 Creating test project..."
cd ..
rm -rf KyberTestApp
# Create with npm, no yarn
npx @react-native-community/cli@latest init KyberTestApp
echo "🚀 done creation moving to install..."
cd KyberTestApp
npm install
print_status "Test project created with npm"
# Step 3: Install our package
echo ""
echo "📥 Installing Kyber package..."
npm install ../react-native-crystals/$TARBALL
print_status "Package installed"
# Step 4: iOS setup
echo ""
echo "🍎 iOS setup..."
if [ -d "ios" ]; then
cd ios && pod install && cd ..
print_status "iOS pods installed"
else
print_warning "No iOS directory found"
fi
# Step 5: Create test file
echo ""
echo "📝 Creating test..."
cat > KyberTest.js << 'EOF'
import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, ScrollView, SafeAreaView } from 'react-native';
import { Kyber, Dilithium } from 'react-native-kyber';
export default function KyberTest() {
const [log, setLog] = useState('Ready to test...\n');
const [testing, setTesting] = useState(false);
const addLog = (msg) => setLog(prev => prev + `${msg}\n`);
const testKyber = async () => {
addLog('🔐 Testing Kyber...');
try {
if (!Kyber) throw new Error('Kyber not imported');
addLog('✅ Kyber module loaded');
const hello = await Kyber.hello();
addLog(`✅ Kyber Hello: ${hello}`);
const keys = await Kyber.generateKeyPair();
addLog(`✅ Kyber Keys: pub=${keys.publicKey.length}, sec=${keys.secretKey.length}`);
const enc = await Kyber.encrypt(keys.publicKey);
addLog(`✅ Kyber Encrypted: ct=${enc.ciphertext.length}, ss=${enc.sharedSecret.length}`);
const dec = await Kyber.decrypt(enc.ciphertext, keys.secretKey);
addLog(`✅ Kyber Decrypted: ss=${dec.sharedSecret.length}`);
const match = enc.sharedSecret === dec.sharedSecret;
addLog(match ? '🎉 Kyber SUCCESS: Secrets match!' : '❌ Kyber FAIL: Secrets differ');
} catch (error) {
addLog(`❌ Kyber Error: ${error.message}`);
}
};
const testDilithium = async () => {
addLog('✍️ Testing Dilithium...');
try {
if (!Dilithium) throw new Error('Dilithium not imported');
addLog('✅ Dilithium module loaded');
const hello = await Dilithium.hello();
addLog(`✅ Dilithium Hello: ${hello}`);
const keys = await Dilithium.generateKeyPair();
addLog(`✅ Dilithium Keys: pub=${keys.publicKey.length}, sec=${keys.secretKey.length}`);
const message = "Hello, post-quantum world!";
const sign = await Dilithium.sign(message, keys.secretKey);
addLog(`✅ Dilithium Signed: sig=${sign.signature.length}`);
const verify = await Dilithium.verify(message, sign.signature, keys.publicKey);
addLog(`✅ Dilithium Verified: ${verify.isValid}`);
addLog(verify.isValid ? '🎉 Dilithium SUCCESS: Signature verified!' : '❌ Dilithium FAIL: Signature invalid');
} catch (error) {
addLog(`❌ Dilithium Error: ${error.message}`);
}
};
const test = async () => {
setTesting(true);
setLog('Testing Kyber & Dilithium...\n');
await testKyber();
addLog('');
await testDilithium();
setTesting(false);
};
return (
<SafeAreaView style={styles.container}>
<Text style={styles.title}>Kyber & Dilithium Test</Text>
<TouchableOpacity
style={[styles.button, testing && styles.disabled]}
onPress={test}
disabled={testing}
>
<Text style={styles.buttonText}>
{testing ? 'Testing...' : 'Test Both'}
</Text>
</TouchableOpacity>
<ScrollView style={styles.log}>
<Text style={styles.logText}>{log}</Text>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: { flex: 1, padding: 20, backgroundColor: '#f0f0f0' },
title: { fontSize: 24, fontWeight: 'bold', textAlign: 'center', marginBottom: 20 },
button: { backgroundColor: '#007AFF', padding: 15, borderRadius: 8, marginBottom: 20 },
disabled: { backgroundColor: '#ccc' },
buttonText: { color: 'white', textAlign: 'center', fontSize: 18, fontWeight: 'bold' },
log: { flex: 1, backgroundColor: '#000', borderRadius: 8, padding: 10 },
logText: { color: '#0f0', fontFamily: 'Courier', fontSize: 14 },
});
EOF
# Update App.js/tsx
if [ -f "App.tsx" ]; then
echo "import KyberTest from './KyberTest'; export default KyberTest;" > App.tsx
else
echo "import KyberTest from './KyberTest'; export default KyberTest;" > App.js
fi
print_status "Test component created"
# Final instructions
echo ""
echo "🎯 Ready to test!"
echo "=================="
print_status "Run: cd KyberTestApp"
print_warning "Android: npx react-native run-android"
print_warning "iOS: npx react-native run-ios"
echo ""
echo "📱 The app will show a 'Test Both' button"
echo "�� Location: $(pwd)"