dop-wallet-v6 1.3.34 → 1.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.eslintrc.js +1 -11
  2. package/README.md +9 -367
  3. package/dist/services/dop/core/index.d.ts +0 -4
  4. package/dist/services/dop/core/index.js +0 -5
  5. package/dist/services/dop/core/index.js.map +1 -1
  6. package/dist/services/dop/core/prover.js +50 -1
  7. package/dist/services/dop/core/prover.js.map +1 -1
  8. package/dist/services/dop/core/react-native-init.js +1 -28
  9. package/dist/services/dop/core/react-native-init.js.map +1 -1
  10. package/dist/services/dop/crypto/custom-prover.d.ts +78 -0
  11. package/dist/services/dop/crypto/custom-prover.js +78 -0
  12. package/dist/services/dop/crypto/custom-prover.js.map +1 -0
  13. package/dist/services/dop/crypto/index.d.ts +1 -0
  14. package/dist/services/dop/crypto/index.js +18 -0
  15. package/dist/services/dop/crypto/index.js.map +1 -0
  16. package/dist/services/dop/index.d.ts +1 -0
  17. package/dist/services/dop/index.js +1 -0
  18. package/dist/services/dop/index.js.map +1 -1
  19. package/package.json +1 -1
  20. package/react-native.js +1 -13
  21. package/dist/services/dop/core/react-native-prover-setup.d.ts +0 -51
  22. package/dist/services/dop/core/react-native-prover-setup.js +0 -227
  23. package/dist/services/dop/core/react-native-prover-setup.js.map +0 -1
  24. package/dist/services/dop/crypto/mopro-circuit-loader.d.ts +0 -103
  25. package/dist/services/dop/crypto/mopro-circuit-loader.js +0 -308
  26. package/dist/services/dop/crypto/mopro-circuit-loader.js.map +0 -1
  27. package/dist/services/dop/crypto/mopro-prover-adapter.d.ts +0 -117
  28. package/dist/services/dop/crypto/mopro-prover-adapter.js +0 -243
  29. package/dist/services/dop/crypto/mopro-prover-adapter.js.map +0 -1
  30. package/dist/services/dop/crypto/user-rapidsnark-adapter.d.ts +0 -98
  31. package/dist/services/dop/crypto/user-rapidsnark-adapter.js +0 -226
  32. package/dist/services/dop/crypto/user-rapidsnark-adapter.js.map +0 -1
  33. package/dist/services/transactions/tx-encrypt-relayer.d.ts +0 -6
  34. package/dist/services/transactions/tx-encrypt-relayer.js +0 -80
  35. package/dist/services/transactions/tx-encrypt-relayer.js.map +0 -1
@@ -1,227 +0,0 @@
1
- "use strict";
2
- /**
3
- * React Native Prover Setup
4
- *
5
- * This module enables fully on-device zero-knowledge proof generation in React Native
6
- * using Mopro (Mobile Prover) toolkit.
7
- *
8
- * SUPPORTED APPROACHES:
9
- * 1. Mopro (Recommended) - Full on-device proof generation with native performance
10
- * 2. Backend Witness Service - Generate witness on backend, proof on device with Rapidsnark
11
- * 3. Encrypted Transfers Only - Shield operations without proof generation
12
- *
13
- * MOPRO INTEGRATION:
14
- * - Witness generation: Native C++/Rust (2-29x faster than browser)
15
- * - Proof generation: Native Arkworks or Rapidsnark (8-15x faster than browser)
16
- * - No WebAssembly required (bypasses React Native limitations)
17
- * - No backend service needed
18
- *
19
- * @see https://zkmopro.org/docs/intro
20
- * @see MOPRO_INTEGRATION_PLAN.md
21
- */
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.getCircuitLoader = exports.autoSetupProverForReactNative = exports.setupReactNativeProver = exports.setupMoproProver = exports.checkReactNativeProverSupport = void 0;
24
- const prover_1 = require("./prover");
25
- const runtime_1 = require("../util/runtime");
26
- const react_native_rapidsnark_prover_1 = require("../crypto/react-native-rapidsnark-prover");
27
- const mopro_prover_adapter_1 = require("../crypto/mopro-prover-adapter");
28
- const mopro_circuit_loader_1 = require("../crypto/mopro-circuit-loader");
29
- /**
30
- * Check if proof generation is available in React Native
31
- * Tries Mopro first (recommended), then falls back to Rapidsnark backend approach
32
- */
33
- const checkReactNativeProverSupport = async () => {
34
- if (!runtime_1.isReactNative) {
35
- return {
36
- available: true,
37
- method: 'none',
38
- message: 'Not in React Native environment'
39
- };
40
- }
41
- try {
42
- // Try to initialize Mopro (fully on-device)
43
- const moproInit = await (0, mopro_prover_adapter_1.initializeMopro)();
44
- const rnfsInit = await (0, mopro_circuit_loader_1.initializeRNFS)();
45
- if (moproInit && rnfsInit && (0, mopro_prover_adapter_1.isMoproAvailable)() && (0, mopro_circuit_loader_1.isRNFSAvailable)()) {
46
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
47
- console.log('✅ MOPRO PROOF GENERATION AVAILABLE');
48
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
49
- console.log('');
50
- console.log('🚀 Fully on-device proof generation enabled via Mopro');
51
- console.log(' - No backend witness service needed');
52
- console.log(' - Native performance (8-25x faster than browser)');
53
- console.log(' - All DOP operations work fully on-device');
54
- console.log('');
55
- console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
56
- return {
57
- available: true,
58
- method: 'mopro',
59
- message: 'Mopro initialized successfully'
60
- };
61
- }
62
- // Mopro not available, try Rapidsnark backend approach
63
- const rapidsnarkInit = await (0, react_native_rapidsnark_prover_1.initializeRapidsnark)();
64
- if (rapidsnarkInit && (0, react_native_rapidsnark_prover_1.isRapidsnarkAvailable)()) {
65
- console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
66
- console.warn('⚠️ RAPIDSNARK AVAILABLE (BACKEND WITNESS REQUIRED)');
67
- console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
68
- console.warn('');
69
- console.warn('Rapidsnark is available for proof generation, but witness');
70
- console.warn('calculation must be done on a backend service.');
71
- console.warn('');
72
- console.warn('For fully on-device proof generation, install Mopro:');
73
- console.warn(' npm install mopro-ffi react-native-fs');
74
- console.warn(' See: https://zkmopro.org/docs/setup/react-native-setup');
75
- console.warn('');
76
- console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
77
- return {
78
- available: true,
79
- method: 'rapidsnark-backend',
80
- message: 'Rapidsnark available, backend witness required'
81
- };
82
- }
83
- // Neither Mopro nor Rapidsnark available
84
- console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
85
- console.error('⚠️ REACT NATIVE PROOF GENERATION NOT AVAILABLE');
86
- console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
87
- console.error('');
88
- console.error('The DOP SDK cannot generate zero-knowledge proofs in');
89
- console.error('React Native because SnarkJS requires WebAssembly.');
90
- console.error('');
91
- console.error('RECOMMENDED SOLUTION:');
92
- console.error('');
93
- console.error('Install Mopro for fully on-device proof generation:');
94
- console.error(' npm install mopro-ffi react-native-fs');
95
- console.error(' Setup guide: https://zkmopro.org/docs/setup/react-native-setup');
96
- console.error('');
97
- console.error('Benefits:');
98
- console.error(' ✅ No backend service needed');
99
- console.error(' ✅ 8-25x faster than browser');
100
- console.error(' ✅ Native iOS/Android performance');
101
- console.error(' ✅ Privacy-preserving (no data leaves device)');
102
- console.error('');
103
- console.error('ALTERNATIVE SOLUTIONS:');
104
- console.error('');
105
- console.error('1. Backend Witness Service:');
106
- console.error(' Install @iden3/react-native-rapidsnark for proof generation');
107
- console.error(' Set up backend service for witness calculation');
108
- console.error('');
109
- console.error('2. Encrypted Transfers Only:');
110
- console.error(' Shield operations work without proof generation');
111
- console.error('');
112
- console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
113
- return {
114
- available: false,
115
- method: 'none',
116
- message: 'No proof generation method available'
117
- };
118
- }
119
- catch (error) {
120
- console.error('Error checking React Native prover support:', error);
121
- return {
122
- available: false,
123
- method: 'none',
124
- message: `Error: ${error instanceof Error ? error.message : String(error)}`
125
- };
126
- }
127
- };
128
- exports.checkReactNativeProverSupport = checkReactNativeProverSupport;
129
- /**
130
- * Setup Mopro prover for React Native
131
- * Configures DOP Engine to use Mopro for fully on-device proof generation
132
- *
133
- * @param useRapidsnark - Use Rapidsnark backend instead of Arkworks (default: false)
134
- * @returns true if setup successful
135
- */
136
- const setupMoproProver = async (useRapidsnark = false) => {
137
- if (!runtime_1.isReactNative) {
138
- return true;
139
- }
140
- try {
141
- // Initialize Mopro and RNFS
142
- const moproInit = await (0, mopro_prover_adapter_1.initializeMopro)();
143
- const rnfsInit = await (0, mopro_circuit_loader_1.initializeRNFS)();
144
- if (!moproInit || !rnfsInit) {
145
- console.error('❌ Failed to initialize Mopro or RNFS');
146
- return false;
147
- }
148
- console.log('🔧 Setting up Mopro prover for DOP Engine...');
149
- // Create Mopro adapter
150
- const proofLib = useRapidsnark ? mopro_prover_adapter_1.ProofLib.Rapidsnark : mopro_prover_adapter_1.ProofLib.Arkworks;
151
- const moproAdapter = new mopro_prover_adapter_1.MoproProverAdapter(proofLib);
152
- // Create circuit loader
153
- const circuitLoader = await (0, mopro_circuit_loader_1.createCircuitLoader)();
154
- // Get DOP Engine prover instance
155
- const prover = (0, prover_1.getProver)();
156
- // Circuit ID mapping for DOP Engine
157
- const CIRCUIT_IDS = {
158
- dop: 0,
159
- decrypt: 1,
160
- nullify: 2
161
- };
162
- // Configure DOP Engine to use Mopro as native prover
163
- const moproNativeProver = async (circuitId, _datBuffer, zkeyBuffer, jsonInputs, progressCallback) => {
164
- // Convert circuit ID to name
165
- const circuitName = Object.keys(CIRCUIT_IDS).find(key => CIRCUIT_IDS[key] === circuitId) ?? `circuit-${circuitId}`;
166
- // Load circuit file to device filesystem
167
- const zkeyPath = await circuitLoader.loadCircuit(circuitName, new Uint8Array(zkeyBuffer));
168
- // Generate proof with Mopro
169
- return moproAdapter.generateProof(circuitName, zkeyPath, jsonInputs, progressCallback);
170
- };
171
- // Set the native prover in DOP Engine
172
- prover.setNativeProverGroth16(moproNativeProver, CIRCUIT_IDS);
173
- console.log('✅ Mopro prover setup complete');
174
- console.log(` Using proof backend: ${proofLib}`);
175
- return true;
176
- }
177
- catch (error) {
178
- console.error('❌ Mopro prover setup failed:', error);
179
- return false;
180
- }
181
- };
182
- exports.setupMoproProver = setupMoproProver;
183
- /**
184
- * Setup Groth16 prover for React Native
185
- * Tries Mopro first, falls back to checking Rapidsnark backend availability
186
- */
187
- const setupReactNativeProver = async () => {
188
- if (!runtime_1.isReactNative) {
189
- return true; // Not in React Native, nothing to do
190
- }
191
- const support = await (0, exports.checkReactNativeProverSupport)();
192
- if (support.method === 'mopro') {
193
- // Try to setup Mopro
194
- const moproSetup = await (0, exports.setupMoproProver)();
195
- if (moproSetup) {
196
- return true;
197
- }
198
- }
199
- return support.available;
200
- };
201
- exports.setupReactNativeProver = setupReactNativeProver;
202
- /**
203
- * Auto-setup prover if in React Native environment
204
- */
205
- const autoSetupProverForReactNative = async () => {
206
- if (runtime_1.isReactNative) {
207
- await (0, exports.setupReactNativeProver)();
208
- }
209
- };
210
- exports.autoSetupProverForReactNative = autoSetupProverForReactNative;
211
- /**
212
- * Get circuit loader instance (for manual circuit preloading)
213
- */
214
- const getCircuitLoader = async () => {
215
- if (!runtime_1.isReactNative || !(0, mopro_circuit_loader_1.isRNFSAvailable)()) {
216
- return null;
217
- }
218
- try {
219
- return await (0, mopro_circuit_loader_1.createCircuitLoader)();
220
- }
221
- catch (error) {
222
- console.error('Failed to create circuit loader:', error);
223
- return null;
224
- }
225
- };
226
- exports.getCircuitLoader = getCircuitLoader;
227
- //# sourceMappingURL=react-native-prover-setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-native-prover-setup.js","sourceRoot":"","sources":["../../../../src/services/dop/core/react-native-prover-setup.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAEH,qCAAiF;AACjF,6CAAgD;AAChD,6FAAuG;AACvG,yEAKwC;AACxC,yEAKwC;AAExC;;;GAGG;AACI,MAAM,6BAA6B,GAAG,KAAK,IAI/C,EAAE;IACH,IAAI,CAAC,uBAAa,EAAE;QAClB,OAAO;YACL,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,M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,KAAK,IAAwC,EAAE;IAC7E,IAAI,CAAC,uBAAa,IAAI,CAAC,IAAA,sCAAe,GAAE,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IAAI;QACF,OAAO,MAAM,IAAA,0CAAmB,GAAE,CAAC;KACpC;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC;KACb;AACH,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B","sourcesContent":["/**\n * React Native Prover Setup\n * \n * This module enables fully on-device zero-knowledge proof generation in React Native\n * using Mopro (Mobile Prover) toolkit.\n * \n * SUPPORTED APPROACHES:\n * 1. Mopro (Recommended) - Full on-device proof generation with native performance\n * 2. Backend Witness Service - Generate witness on backend, proof on device with Rapidsnark\n * 3. Encrypted Transfers Only - Shield operations without proof generation\n * \n * MOPRO INTEGRATION:\n * - Witness generation: Native C++/Rust (2-29x faster than browser)\n * - Proof generation: Native Arkworks or Rapidsnark (8-15x faster than browser)\n * - No WebAssembly required (bypasses React Native limitations)\n * - No backend service needed\n * \n * @see https://zkmopro.org/docs/intro\n * @see MOPRO_INTEGRATION_PLAN.md\n */\n\nimport { getProver, type FormattedCircuitInputsDop, type Proof } from './prover';\nimport { isReactNative } from '../util/runtime';\nimport { initializeRapidsnark, isRapidsnarkAvailable } from '../crypto/react-native-rapidsnark-prover';\nimport { \n initializeMopro, \n isMoproAvailable, \n MoproProverAdapter,\n ProofLib\n} from '../crypto/mopro-prover-adapter';\nimport { \n initializeRNFS,\n isRNFSAvailable,\n createCircuitLoader,\n type MoproCircuitLoader\n} from '../crypto/mopro-circuit-loader';\n\n/**\n * Check if proof generation is available in React Native\n * Tries Mopro first (recommended), then falls back to Rapidsnark backend approach\n */\nexport const checkReactNativeProverSupport = async (): Promise<{\n available: boolean;\n method: 'mopro' | 'rapidsnark-backend' | 'none';\n message: string;\n}> => {\n if (!isReactNative) {\n return {\n available: true,\n method: 'none',\n message: 'Not in React Native environment'\n };\n }\n\n try {\n // Try to initialize Mopro (fully on-device)\n const moproInit = await initializeMopro();\n const rnfsInit = await initializeRNFS();\n \n if (moproInit && rnfsInit && isMoproAvailable() && isRNFSAvailable()) {\n console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.log('✅ MOPRO PROOF GENERATION AVAILABLE');\n console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.log('');\n console.log('🚀 Fully on-device proof generation enabled via Mopro');\n console.log(' - No backend witness service needed');\n console.log(' - Native performance (8-25x faster than browser)');\n console.log(' - All DOP operations work fully on-device');\n console.log('');\n console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n \n return {\n available: true,\n method: 'mopro',\n message: 'Mopro initialized successfully'\n };\n }\n\n // Mopro not available, try Rapidsnark backend approach\n const rapidsnarkInit = await initializeRapidsnark();\n \n if (rapidsnarkInit && isRapidsnarkAvailable()) {\n console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.warn('⚠️ RAPIDSNARK AVAILABLE (BACKEND WITNESS REQUIRED)');\n console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.warn('');\n console.warn('Rapidsnark is available for proof generation, but witness');\n console.warn('calculation must be done on a backend service.');\n console.warn('');\n console.warn('For fully on-device proof generation, install Mopro:');\n console.warn(' npm install mopro-ffi react-native-fs');\n console.warn(' See: https://zkmopro.org/docs/setup/react-native-setup');\n console.warn('');\n console.warn('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n \n return {\n available: true,\n method: 'rapidsnark-backend',\n message: 'Rapidsnark available, backend witness required'\n };\n }\n\n // Neither Mopro nor Rapidsnark available\n console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.error('⚠️ REACT NATIVE PROOF GENERATION NOT AVAILABLE');\n console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n console.error('');\n console.error('The DOP SDK cannot generate zero-knowledge proofs in');\n console.error('React Native because SnarkJS requires WebAssembly.');\n console.error('');\n console.error('RECOMMENDED SOLUTION:');\n console.error('');\n console.error('Install Mopro for fully on-device proof generation:');\n console.error(' npm install mopro-ffi react-native-fs');\n console.error(' Setup guide: https://zkmopro.org/docs/setup/react-native-setup');\n console.error('');\n console.error('Benefits:');\n console.error(' ✅ No backend service needed');\n console.error(' ✅ 8-25x faster than browser');\n console.error(' ✅ Native iOS/Android performance');\n console.error(' ✅ Privacy-preserving (no data leaves device)');\n console.error('');\n console.error('ALTERNATIVE SOLUTIONS:');\n console.error('');\n console.error('1. Backend Witness Service:');\n console.error(' Install @iden3/react-native-rapidsnark for proof generation');\n console.error(' Set up backend service for witness calculation');\n console.error('');\n console.error('2. Encrypted Transfers Only:');\n console.error(' Shield operations work without proof generation');\n console.error('');\n console.error('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');\n \n return {\n available: false,\n method: 'none',\n message: 'No proof generation method available'\n };\n \n } catch (error) {\n console.error('Error checking React Native prover support:', error);\n return {\n available: false,\n method: 'none',\n message: `Error: ${error instanceof Error ? error.message : String(error)}`\n };\n }\n};\n\n/**\n * Setup Mopro prover for React Native\n * Configures DOP Engine to use Mopro for fully on-device proof generation\n * \n * @param useRapidsnark - Use Rapidsnark backend instead of Arkworks (default: false)\n * @returns true if setup successful\n */\nexport const setupMoproProver = async (useRapidsnark = false): Promise<boolean> => {\n if (!isReactNative) {\n return true;\n }\n\n try {\n // Initialize Mopro and RNFS\n const moproInit = await initializeMopro();\n const rnfsInit = await initializeRNFS();\n\n if (!moproInit || !rnfsInit) {\n console.error('❌ Failed to initialize Mopro or RNFS');\n return false;\n }\n\n console.log('🔧 Setting up Mopro prover for DOP Engine...');\n\n // Create Mopro adapter\n const proofLib = useRapidsnark ? ProofLib.Rapidsnark : ProofLib.Arkworks;\n const moproAdapter = new MoproProverAdapter(proofLib);\n\n // Create circuit loader\n const circuitLoader = await createCircuitLoader();\n\n // Get DOP Engine prover instance\n const prover = getProver();\n\n // Circuit ID mapping for DOP Engine\n const CIRCUIT_IDS = {\n dop: 0,\n decrypt: 1,\n nullify: 2\n };\n\n // Configure DOP Engine to use Mopro as native prover\n const moproNativeProver = async (\n circuitId: number,\n _datBuffer: Buffer,\n zkeyBuffer: Buffer,\n jsonInputs: FormattedCircuitInputsDop,\n progressCallback?: (progress: number) => void\n ): Promise<Proof> => {\n // Convert circuit ID to name\n const circuitName: string = Object.keys(CIRCUIT_IDS).find(\n key => CIRCUIT_IDS[key as keyof typeof CIRCUIT_IDS] === circuitId\n ) ?? `circuit-${circuitId}`;\n\n // Load circuit file to device filesystem\n const zkeyPath = await circuitLoader.loadCircuit(\n circuitName,\n new Uint8Array(zkeyBuffer)\n );\n\n // Generate proof with Mopro\n return moproAdapter.generateProof(\n circuitName,\n zkeyPath,\n jsonInputs,\n progressCallback\n );\n };\n\n // Set the native prover in DOP Engine\n prover.setNativeProverGroth16(moproNativeProver as any, CIRCUIT_IDS);\n \n console.log('✅ Mopro prover setup complete');\n console.log(` Using proof backend: ${proofLib}`);\n \n return true;\n\n } catch (error) {\n console.error('❌ Mopro prover setup failed:', error);\n return false;\n }\n};\n\n/**\n * Setup Groth16 prover for React Native\n * Tries Mopro first, falls back to checking Rapidsnark backend availability\n */\nexport const setupReactNativeProver = async (): Promise<boolean> => {\n if (!isReactNative) {\n return true; // Not in React Native, nothing to do\n }\n\n const support = await checkReactNativeProverSupport();\n \n if (support.method === 'mopro') {\n // Try to setup Mopro\n const moproSetup = await setupMoproProver();\n if (moproSetup) {\n return true;\n }\n }\n\n return support.available;\n};\n\n/**\n * Auto-setup prover if in React Native environment\n */\nexport const autoSetupProverForReactNative = async (): Promise<void> => {\n if (isReactNative) {\n await setupReactNativeProver();\n }\n};\n\n/**\n * Get circuit loader instance (for manual circuit preloading)\n */\nexport const getCircuitLoader = async (): Promise<MoproCircuitLoader | null> => {\n if (!isReactNative || !isRNFSAvailable()) {\n return null;\n }\n\n try {\n return await createCircuitLoader();\n } catch (error) {\n console.error('Failed to create circuit loader:', error);\n return null;\n }\n};\n"]}
@@ -1,103 +0,0 @@
1
- /**
2
- * Mopro Circuit Loader for React Native
3
- *
4
- * This module handles loading and caching DOP circuit files (zkey) on
5
- * the React Native device filesystem. Circuit files are downloaded from
6
- * IPFS by the artifact downloader and then saved to the app's document
7
- * directory for use by Mopro's native proof generation.
8
- *
9
- * Features:
10
- * - Caches circuit file paths to avoid repeated file operations
11
- * - Handles circuit file compression (brotli)
12
- * - Preloads circuits at app startup for faster proof generation
13
- * - Manages cleanup of old circuit files
14
- */
15
- /**
16
- * Circuit file information
17
- */
18
- interface CircuitInfo {
19
- circuitId: string;
20
- zkeyPath: string;
21
- fileSize: number;
22
- loadedAt: number;
23
- }
24
- /**
25
- * Initialize React Native filesystem module
26
- */
27
- export declare const initializeRNFS: () => Promise<boolean>;
28
- /**
29
- * Check if RNFS is available
30
- */
31
- export declare const isRNFSAvailable: () => boolean;
32
- /**
33
- * Mopro Circuit Loader Class
34
- *
35
- * Manages circuit files on the React Native filesystem
36
- */
37
- export declare class MoproCircuitLoader {
38
- private circuitCache;
39
- private circuitsDir;
40
- private initialized;
41
- constructor();
42
- /**
43
- * Initialize the circuit loader
44
- * Creates the circuits directory if it doesn't exist
45
- */
46
- initialize(): Promise<void>;
47
- /**
48
- * Load a circuit file from buffer and save to filesystem
49
- *
50
- * @param circuitId - Circuit identifier (e.g., '1x2', '2x2')
51
- * @param zkeyBuffer - The zkey file buffer
52
- * @returns Path to the saved zkey file
53
- */
54
- loadCircuit(circuitId: string, zkeyBuffer: Uint8Array): Promise<string>;
55
- /**
56
- * Preload multiple circuits at app startup
57
- * This prevents delays during first proof generation
58
- *
59
- * @param circuits - Map of circuitId to zkeyBuffer
60
- */
61
- preloadCircuits(circuits: Map<string, Uint8Array>): Promise<void>;
62
- /**
63
- * Get cached circuit info
64
- */
65
- getCircuitInfo(circuitId: string): CircuitInfo | undefined;
66
- /**
67
- * Clear all cached circuits from memory
68
- * (Files remain on disk)
69
- */
70
- clearCache(): void;
71
- /**
72
- * Delete circuit files from filesystem
73
- *
74
- * @param circuitIds - Array of circuit IDs to delete, or empty to delete all
75
- */
76
- deleteCircuits(circuitIds?: string[]): Promise<void>;
77
- /**
78
- * Get total size of cached circuits
79
- */
80
- getTotalCacheSize(): number;
81
- /**
82
- * Get cache statistics
83
- */
84
- getCacheStats(): {
85
- circuitCount: number;
86
- totalSize: string;
87
- circuits: CircuitInfo[];
88
- };
89
- /**
90
- * Convert Uint8Array to base64 string
91
- */
92
- private static bufferToBase64;
93
- /**
94
- * Format file size for human readability
95
- */
96
- private static formatFileSize;
97
- }
98
- /**
99
- * Create a circuit loader instance
100
- * Automatically initializes RNFS if not already done
101
- */
102
- export declare const createCircuitLoader: () => Promise<MoproCircuitLoader>;
103
- export {};
@@ -1,308 +0,0 @@
1
- "use strict";
2
- /**
3
- * Mopro Circuit Loader for React Native
4
- *
5
- * This module handles loading and caching DOP circuit files (zkey) on
6
- * the React Native device filesystem. Circuit files are downloaded from
7
- * IPFS by the artifact downloader and then saved to the app's document
8
- * directory for use by Mopro's native proof generation.
9
- *
10
- * Features:
11
- * - Caches circuit file paths to avoid repeated file operations
12
- * - Handles circuit file compression (brotli)
13
- * - Preloads circuits at app startup for faster proof generation
14
- * - Manages cleanup of old circuit files
15
- */
16
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
- if (k2 === undefined) k2 = k;
18
- var desc = Object.getOwnPropertyDescriptor(m, k);
19
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
- desc = { enumerable: true, get: function() { return m[k]; } };
21
- }
22
- Object.defineProperty(o, k2, desc);
23
- }) : (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- o[k2] = m[k];
26
- }));
27
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
- Object.defineProperty(o, "default", { enumerable: true, value: v });
29
- }) : function(o, v) {
30
- o["default"] = v;
31
- });
32
- var __importStar = (this && this.__importStar) || function (mod) {
33
- if (mod && mod.__esModule) return mod;
34
- var result = {};
35
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
36
- __setModuleDefault(result, mod);
37
- return result;
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.createCircuitLoader = exports.MoproCircuitLoader = exports.isRNFSAvailable = exports.initializeRNFS = void 0;
41
- const runtime_1 = require("../util/runtime");
42
- let rnfsModule = null;
43
- /**
44
- * Initialize React Native filesystem module
45
- */
46
- const initializeRNFS = async () => {
47
- var _a;
48
- if (!runtime_1.isReactNative) {
49
- return false;
50
- }
51
- try {
52
- const moduleName = 'react-native-fs';
53
- const rnfsImport = await (_a = moduleName, Promise.resolve().then(() => __importStar(require(_a))));
54
- rnfsModule = (rnfsImport.default ?? rnfsImport);
55
- console.log('📁 React Native FS initialized');
56
- return true;
57
- }
58
- catch (error) {
59
- console.warn('⚠️ react-native-fs not available:', error);
60
- console.log('💡 Install react-native-fs: npm install react-native-fs');
61
- return false;
62
- }
63
- };
64
- exports.initializeRNFS = initializeRNFS;
65
- /**
66
- * Check if RNFS is available
67
- */
68
- const isRNFSAvailable = () => {
69
- return runtime_1.isReactNative && rnfsModule !== null;
70
- };
71
- exports.isRNFSAvailable = isRNFSAvailable;
72
- /**
73
- * Mopro Circuit Loader Class
74
- *
75
- * Manages circuit files on the React Native filesystem
76
- */
77
- class MoproCircuitLoader {
78
- circuitCache = new Map();
79
- circuitsDir;
80
- initialized = false;
81
- constructor() {
82
- if (!(0, exports.isRNFSAvailable)() || !rnfsModule) {
83
- throw new Error('react-native-fs not available. Install it with: npm install react-native-fs');
84
- }
85
- this.circuitsDir = `${rnfsModule.DocumentDirectoryPath}/dop-circuits`;
86
- }
87
- /**
88
- * Initialize the circuit loader
89
- * Creates the circuits directory if it doesn't exist
90
- */
91
- async initialize() {
92
- if (this.initialized || !rnfsModule) {
93
- return;
94
- }
95
- try {
96
- console.log('📂 Initializing Mopro circuit loader...');
97
- console.log(` Circuits directory: ${this.circuitsDir}`);
98
- // Create circuits directory
99
- await rnfsModule.mkdir(this.circuitsDir, {
100
- NSURLIsExcludedFromBackupKey: true // Don't backup to iCloud
101
- });
102
- this.initialized = true;
103
- console.log('✅ Circuit loader initialized');
104
- }
105
- catch (error) {
106
- // Directory might already exist, that's okay
107
- if (error instanceof Error && error.message.includes('already exists')) {
108
- this.initialized = true;
109
- console.log('✅ Circuit loader initialized (directory exists)');
110
- }
111
- else {
112
- console.error('❌ Failed to initialize circuit loader:', error);
113
- throw error;
114
- }
115
- }
116
- }
117
- /**
118
- * Load a circuit file from buffer and save to filesystem
119
- *
120
- * @param circuitId - Circuit identifier (e.g., '1x2', '2x2')
121
- * @param zkeyBuffer - The zkey file buffer
122
- * @returns Path to the saved zkey file
123
- */
124
- async loadCircuit(circuitId, zkeyBuffer) {
125
- if (!rnfsModule) {
126
- throw new Error('react-native-fs not initialized');
127
- }
128
- await this.initialize();
129
- // Check if circuit is already cached
130
- const cached = this.circuitCache.get(circuitId);
131
- if (cached) {
132
- // Verify file still exists
133
- const exists = await rnfsModule.exists(cached.zkeyPath);
134
- if (exists) {
135
- console.log(`📦 Using cached circuit: ${circuitId}`);
136
- return cached.zkeyPath;
137
- }
138
- // File was deleted, remove from cache
139
- this.circuitCache.delete(circuitId);
140
- }
141
- try {
142
- console.log(`💾 Loading circuit to filesystem: ${circuitId}`);
143
- const startTime = Date.now();
144
- // Generate file path
145
- const zkeyPath = `${this.circuitsDir}/${circuitId}.zkey`;
146
- // Convert buffer to base64 for react-native-fs
147
- const base64Data = MoproCircuitLoader.bufferToBase64(zkeyBuffer);
148
- // Write to file
149
- await rnfsModule.writeFile(zkeyPath, base64Data, 'base64');
150
- // Verify file was written
151
- const stat = await rnfsModule.stat(zkeyPath);
152
- const fileSize = stat.size;
153
- // Cache the circuit info
154
- const circuitInfo = {
155
- circuitId,
156
- zkeyPath,
157
- fileSize,
158
- loadedAt: Date.now()
159
- };
160
- this.circuitCache.set(circuitId, circuitInfo);
161
- const elapsedTime = Date.now() - startTime;
162
- console.log(`✅ Circuit loaded successfully in ${elapsedTime}ms`);
163
- // eslint-disable-next-line no-console
164
- console.log(` File size: ${MoproCircuitLoader.formatFileSize(fileSize)}`);
165
- // eslint-disable-next-line no-console
166
- console.log(` Path: ${zkeyPath}`);
167
- return zkeyPath;
168
- }
169
- catch (error) {
170
- console.error(`❌ Failed to load circuit ${circuitId}:`, error);
171
- throw new Error(`Circuit loading failed: ${error instanceof Error ? error.message : String(error)}`);
172
- }
173
- }
174
- /**
175
- * Preload multiple circuits at app startup
176
- * This prevents delays during first proof generation
177
- *
178
- * @param circuits - Map of circuitId to zkeyBuffer
179
- */
180
- async preloadCircuits(circuits) {
181
- console.log(`🚀 Preloading ${circuits.size} circuits...`);
182
- const startTime = Date.now();
183
- const loadPromises = Array.from(circuits.entries()).map(([circuitId, zkeyBuffer]) => this.loadCircuit(circuitId, zkeyBuffer));
184
- try {
185
- await Promise.all(loadPromises);
186
- const elapsedTime = Date.now() - startTime;
187
- console.log(`✅ Preloaded ${circuits.size} circuits in ${elapsedTime}ms`);
188
- }
189
- catch (error) {
190
- console.error('❌ Failed to preload circuits:', error);
191
- throw error;
192
- }
193
- }
194
- /**
195
- * Get cached circuit info
196
- */
197
- getCircuitInfo(circuitId) {
198
- return this.circuitCache.get(circuitId);
199
- }
200
- /**
201
- * Clear all cached circuits from memory
202
- * (Files remain on disk)
203
- */
204
- clearCache() {
205
- console.log(`🗑️ Clearing circuit cache (${this.circuitCache.size} entries)`);
206
- this.circuitCache.clear();
207
- }
208
- /**
209
- * Delete circuit files from filesystem
210
- *
211
- * @param circuitIds - Array of circuit IDs to delete, or empty to delete all
212
- */
213
- async deleteCircuits(circuitIds) {
214
- if (!rnfsModule) {
215
- throw new Error('react-native-fs not initialized');
216
- }
217
- const toDelete = circuitIds || Array.from(this.circuitCache.keys());
218
- // eslint-disable-next-line no-console
219
- console.log(`🗑️ Deleting ${toDelete.length} circuit files...`);
220
- const rnfs = rnfsModule; // Capture for use in async callbacks
221
- const deletePromises = toDelete.map(async (circuitId) => {
222
- try {
223
- const cached = this.circuitCache.get(circuitId);
224
- if (cached) {
225
- const exists = await rnfs.exists(cached.zkeyPath);
226
- if (exists) {
227
- await rnfs.unlink(cached.zkeyPath);
228
- // eslint-disable-next-line no-console
229
- console.log(` Deleted: ${circuitId}`);
230
- }
231
- this.circuitCache.delete(circuitId);
232
- }
233
- }
234
- catch (error) {
235
- // eslint-disable-next-line no-console
236
- console.warn(` Failed to delete ${circuitId}:`, error);
237
- }
238
- });
239
- await Promise.all(deletePromises);
240
- // eslint-disable-next-line no-console
241
- console.log('✅ Circuit deletion complete');
242
- }
243
- /**
244
- * Get total size of cached circuits
245
- */
246
- getTotalCacheSize() {
247
- let totalSize = 0;
248
- for (const info of this.circuitCache.values()) {
249
- totalSize += info.fileSize;
250
- }
251
- return totalSize;
252
- }
253
- /**
254
- * Get cache statistics
255
- */
256
- getCacheStats() {
257
- const circuits = Array.from(this.circuitCache.values());
258
- return {
259
- circuitCount: circuits.length,
260
- totalSize: MoproCircuitLoader.formatFileSize(this.getTotalCacheSize()),
261
- circuits
262
- };
263
- }
264
- /**
265
- * Convert Uint8Array to base64 string
266
- */
267
- static bufferToBase64(buffer) {
268
- if (typeof Buffer !== 'undefined') {
269
- return Buffer.from(buffer).toString('base64');
270
- }
271
- // Fallback for environments without Buffer
272
- let binary = '';
273
- for (let i = 0; i < buffer.length; i += 1) {
274
- binary += String.fromCharCode(buffer[i]);
275
- }
276
- return btoa(binary);
277
- }
278
- /**
279
- * Format file size for human readability
280
- */
281
- static formatFileSize(bytes) {
282
- if (bytes < 1024) {
283
- return `${bytes} B`;
284
- }
285
- if (bytes < 1024 * 1024) {
286
- return `${(bytes / 1024).toFixed(2)} KB`;
287
- }
288
- return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
289
- }
290
- }
291
- exports.MoproCircuitLoader = MoproCircuitLoader;
292
- /**
293
- * Create a circuit loader instance
294
- * Automatically initializes RNFS if not already done
295
- */
296
- const createCircuitLoader = async () => {
297
- if (!(0, exports.isRNFSAvailable)()) {
298
- const initialized = await (0, exports.initializeRNFS)();
299
- if (!initialized) {
300
- throw new Error('Failed to initialize react-native-fs. Make sure it is installed and linked properly.');
301
- }
302
- }
303
- const loader = new MoproCircuitLoader();
304
- await loader.initialize();
305
- return loader;
306
- };
307
- exports.createCircuitLoader = createCircuitLoader;
308
- //# sourceMappingURL=mopro-circuit-loader.js.map