dop-wallet-v6 1.3.32 → 1.3.34
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.
- package/.eslintrc.js +11 -1
- package/README.md +367 -9
- package/dist/services/dop/core/index.d.ts +4 -0
- package/dist/services/dop/core/index.js +5 -0
- package/dist/services/dop/core/index.js.map +1 -1
- package/dist/services/dop/core/react-native-init.js +28 -1
- package/dist/services/dop/core/react-native-init.js.map +1 -1
- package/dist/services/dop/core/react-native-prover-setup.d.ts +51 -0
- package/dist/services/dop/core/react-native-prover-setup.js +227 -0
- package/dist/services/dop/core/react-native-prover-setup.js.map +1 -0
- package/dist/services/dop/crypto/mopro-circuit-loader.d.ts +103 -0
- package/dist/services/dop/crypto/mopro-circuit-loader.js +308 -0
- package/dist/services/dop/crypto/mopro-circuit-loader.js.map +1 -0
- package/dist/services/dop/crypto/mopro-prover-adapter.d.ts +117 -0
- package/dist/services/dop/crypto/mopro-prover-adapter.js +243 -0
- package/dist/services/dop/crypto/mopro-prover-adapter.js.map +1 -0
- package/dist/services/dop/crypto/user-rapidsnark-adapter.d.ts +98 -0
- package/dist/services/dop/crypto/user-rapidsnark-adapter.js +226 -0
- package/dist/services/dop/crypto/user-rapidsnark-adapter.js.map +1 -0
- package/package.json +1 -1
- package/react-native.js +13 -1
|
@@ -0,0 +1,308 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mopro-circuit-loader.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/mopro-circuit-loader.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAgD;AA0BhD,IAAI,UAAU,GAAyB,IAAI,CAAC;AAE5C;;GAEG;AACI,MAAM,cAAc,GAAG,KAAK,IAAsB,EAAE;;IACzD,IAAI,CAAC,uBAAa,EAAE;QAClB,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,MAAM,UAAU,GAAG,iBAAiB,CAA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AAI,CAAC,IAAA,uBAAe,GAAE,EAAE;QACtB,MAAM,WAAW,GAAG,MAAM,IAAA,sBAAc,GAAE,CAAC;QAC3C,IAAI,CAAC,WAAW,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,sFAAsF,CACvF,CAAC;SACH;KACF;IAED,MAAM,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACxC,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;IAC1B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAbW,QAAA,mBAAmB,uBAa9B","sourcesContent":["/**\n * Mopro Circuit Loader for React Native\n * \n * This module handles loading and caching DOP circuit files (zkey) on\n * the React Native device filesystem. Circuit files are downloaded from\n * IPFS by the artifact downloader and then saved to the app's document\n * directory for use by Mopro's native proof generation.\n * \n * Features:\n * - Caches circuit file paths to avoid repeated file operations\n * - Handles circuit file compression (brotli)\n * - Preloads circuits at app startup for faster proof generation\n * - Manages cleanup of old circuit files\n */\n\nimport { isReactNative } from '../util/runtime';\n\n/**\n * Circuit file information\n */\ninterface CircuitInfo {\n circuitId: string;\n zkeyPath: string;\n fileSize: number;\n loadedAt: number;\n}\n\n/**\n * React Native filesystem interface (react-native-fs)\n * Declared as interface to avoid compilation errors when not installed\n */\ninterface ReactNativeFS {\n DocumentDirectoryPath: string;\n mkdir: (path: string, options?: { NSURLIsExcludedFromBackupKey?: boolean }) => Promise<void>;\n writeFile: (path: string, contents: string, encoding?: string) => Promise<void>;\n readFile: (path: string, encoding?: string) => Promise<string>;\n exists: (path: string) => Promise<boolean>;\n unlink: (path: string) => Promise<void>;\n stat: (path: string) => Promise<{ size: number }>;\n}\n\nlet rnfsModule: ReactNativeFS | null = null;\n\n/**\n * Initialize React Native filesystem module\n */\nexport const initializeRNFS = async (): Promise<boolean> => {\n if (!isReactNative) {\n return false;\n }\n\n try {\n const moduleName = 'react-native-fs';\n const rnfsImport = await import(moduleName);\n rnfsModule = (rnfsImport.default ?? rnfsImport) as ReactNativeFS;\n \n console.log('📁 React Native FS initialized');\n return true;\n } catch (error) {\n console.warn('⚠️ react-native-fs not available:', error);\n console.log('💡 Install react-native-fs: npm install react-native-fs');\n return false;\n }\n};\n\n/**\n * Check if RNFS is available\n */\nexport const isRNFSAvailable = (): boolean => {\n return isReactNative && rnfsModule !== null;\n};\n\n/**\n * Mopro Circuit Loader Class\n * \n * Manages circuit files on the React Native filesystem\n */\nexport class MoproCircuitLoader {\n private circuitCache: Map<string, CircuitInfo> = new Map();\n private circuitsDir: string;\n private initialized = false;\n\n constructor() {\n if (!isRNFSAvailable() || !rnfsModule) {\n throw new Error(\n 'react-native-fs not available. Install it with: npm install react-native-fs'\n );\n }\n \n this.circuitsDir = `${rnfsModule.DocumentDirectoryPath}/dop-circuits`;\n }\n\n /**\n * Initialize the circuit loader\n * Creates the circuits directory if it doesn't exist\n */\n async initialize(): Promise<void> {\n if (this.initialized || !rnfsModule) {\n return;\n }\n\n try {\n console.log('📂 Initializing Mopro circuit loader...');\n console.log(` Circuits directory: ${this.circuitsDir}`);\n\n // Create circuits directory\n await rnfsModule.mkdir(this.circuitsDir, {\n NSURLIsExcludedFromBackupKey: true // Don't backup to iCloud\n });\n\n this.initialized = true;\n console.log('✅ Circuit loader initialized');\n } catch (error) {\n // Directory might already exist, that's okay\n if (error instanceof Error && error.message.includes('already exists')) {\n this.initialized = true;\n console.log('✅ Circuit loader initialized (directory exists)');\n } else {\n console.error('❌ Failed to initialize circuit loader:', error);\n throw error;\n }\n }\n }\n\n /**\n * Load a circuit file from buffer and save to filesystem\n * \n * @param circuitId - Circuit identifier (e.g., '1x2', '2x2')\n * @param zkeyBuffer - The zkey file buffer\n * @returns Path to the saved zkey file\n */\n async loadCircuit(\n circuitId: string,\n zkeyBuffer: Uint8Array\n ): Promise<string> {\n if (!rnfsModule) {\n throw new Error('react-native-fs not initialized');\n }\n\n await this.initialize();\n\n // Check if circuit is already cached\n const cached = this.circuitCache.get(circuitId);\n if (cached) {\n // Verify file still exists\n const exists = await rnfsModule.exists(cached.zkeyPath);\n if (exists) {\n console.log(`📦 Using cached circuit: ${circuitId}`);\n return cached.zkeyPath;\n }\n // File was deleted, remove from cache\n this.circuitCache.delete(circuitId);\n }\n\n try {\n console.log(`💾 Loading circuit to filesystem: ${circuitId}`);\n const startTime = Date.now();\n\n // Generate file path\n const zkeyPath = `${this.circuitsDir}/${circuitId}.zkey`;\n\n // Convert buffer to base64 for react-native-fs\n const base64Data = MoproCircuitLoader.bufferToBase64(zkeyBuffer);\n\n // Write to file\n await rnfsModule.writeFile(zkeyPath, base64Data, 'base64');\n\n // Verify file was written\n const stat = await rnfsModule.stat(zkeyPath);\n const fileSize = stat.size;\n\n // Cache the circuit info\n const circuitInfo: CircuitInfo = {\n circuitId,\n zkeyPath,\n fileSize,\n loadedAt: Date.now()\n };\n this.circuitCache.set(circuitId, circuitInfo);\n\n const elapsedTime = Date.now() - startTime;\n console.log(`✅ Circuit loaded successfully in ${elapsedTime}ms`);\n // eslint-disable-next-line no-console\n console.log(` File size: ${MoproCircuitLoader.formatFileSize(fileSize)}`);\n // eslint-disable-next-line no-console\n console.log(` Path: ${zkeyPath}`);\n\n return zkeyPath;\n\n } catch (error) {\n console.error(`❌ Failed to load circuit ${circuitId}:`, error);\n throw new Error(\n `Circuit loading failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n\n /**\n * Preload multiple circuits at app startup\n * This prevents delays during first proof generation\n * \n * @param circuits - Map of circuitId to zkeyBuffer\n */\n async preloadCircuits(\n circuits: Map<string, Uint8Array>\n ): Promise<void> {\n console.log(`🚀 Preloading ${circuits.size} circuits...`);\n const startTime = Date.now();\n\n const loadPromises = Array.from(circuits.entries()).map(\n ([circuitId, zkeyBuffer]) => this.loadCircuit(circuitId, zkeyBuffer)\n );\n\n try {\n await Promise.all(loadPromises);\n const elapsedTime = Date.now() - startTime;\n console.log(`✅ Preloaded ${circuits.size} circuits in ${elapsedTime}ms`);\n } catch (error) {\n console.error('❌ Failed to preload circuits:', error);\n throw error;\n }\n }\n\n /**\n * Get cached circuit info\n */\n getCircuitInfo(circuitId: string): CircuitInfo | undefined {\n return this.circuitCache.get(circuitId);\n }\n\n /**\n * Clear all cached circuits from memory\n * (Files remain on disk)\n */\n clearCache(): void {\n console.log(`🗑️ Clearing circuit cache (${this.circuitCache.size} entries)`);\n this.circuitCache.clear();\n }\n\n /**\n * Delete circuit files from filesystem\n * \n * @param circuitIds - Array of circuit IDs to delete, or empty to delete all\n */\n async deleteCircuits(circuitIds?: string[]): Promise<void> {\n if (!rnfsModule) {\n throw new Error('react-native-fs not initialized');\n }\n\n const toDelete = circuitIds || Array.from(this.circuitCache.keys());\n // eslint-disable-next-line no-console\n console.log(`🗑️ Deleting ${toDelete.length} circuit files...`);\n\n const rnfs = rnfsModule; // Capture for use in async callbacks\n const deletePromises = toDelete.map(async (circuitId) => {\n try {\n const cached = this.circuitCache.get(circuitId);\n if (cached) {\n const exists = await rnfs.exists(cached.zkeyPath);\n if (exists) {\n await rnfs.unlink(cached.zkeyPath);\n // eslint-disable-next-line no-console\n console.log(` Deleted: ${circuitId}`);\n }\n this.circuitCache.delete(circuitId);\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.warn(` Failed to delete ${circuitId}:`, error);\n }\n });\n \n await Promise.all(deletePromises);\n\n // eslint-disable-next-line no-console\n console.log('✅ Circuit deletion complete');\n }\n\n /**\n * Get total size of cached circuits\n */\n getTotalCacheSize(): number {\n let totalSize = 0;\n for (const info of this.circuitCache.values()) {\n totalSize += info.fileSize;\n }\n return totalSize;\n }\n\n /**\n * Get cache statistics\n */\n getCacheStats(): {\n circuitCount: number;\n totalSize: string;\n circuits: CircuitInfo[];\n } {\n const circuits = Array.from(this.circuitCache.values());\n return {\n circuitCount: circuits.length,\n totalSize: MoproCircuitLoader.formatFileSize(this.getTotalCacheSize()),\n circuits\n };\n }\n\n /**\n * Convert Uint8Array to base64 string\n */\n private static bufferToBase64(buffer: Uint8Array): string {\n if (typeof Buffer !== 'undefined') {\n return Buffer.from(buffer).toString('base64');\n }\n\n // Fallback for environments without Buffer\n let binary = '';\n for (let i = 0; i < buffer.length; i += 1) {\n binary += String.fromCharCode(buffer[i]);\n }\n return btoa(binary);\n }\n\n /**\n * Format file size for human readability\n */\n private static formatFileSize(bytes: number): string {\n if (bytes < 1024) {\n return `${bytes} B`;\n }\n if (bytes < 1024 * 1024) {\n return `${(bytes / 1024).toFixed(2)} KB`;\n }\n return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;\n }\n}\n\n/**\n * Create a circuit loader instance\n * Automatically initializes RNFS if not already done\n */\nexport const createCircuitLoader = async (): Promise<MoproCircuitLoader> => {\n if (!isRNFSAvailable()) {\n const initialized = await initializeRNFS();\n if (!initialized) {\n throw new Error(\n 'Failed to initialize react-native-fs. Make sure it is installed and linked properly.'\n );\n }\n }\n\n const loader = new MoproCircuitLoader();\n await loader.initialize();\n return loader;\n};\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mopro Prover Adapter for React Native
|
|
3
|
+
*
|
|
4
|
+
* This adapter enables fully on-device zero-knowledge proof generation
|
|
5
|
+
* using the Mopro (Mobile Prover) toolkit, eliminating the need for
|
|
6
|
+
* backend witness generation services.
|
|
7
|
+
*
|
|
8
|
+
* Mopro provides native witness calculation and proof generation through
|
|
9
|
+
* Rust FFI bindings, bypassing React Native's WebAssembly limitations.
|
|
10
|
+
*
|
|
11
|
+
* Performance Benefits:
|
|
12
|
+
* - Witness generation: 2-29x faster than browser SnarkJS
|
|
13
|
+
* - Proof generation: 8-15x faster than browser SnarkJS
|
|
14
|
+
* - Native iOS/Android performance
|
|
15
|
+
* - No network calls required
|
|
16
|
+
*
|
|
17
|
+
* @see https://zkmopro.org/docs/intro
|
|
18
|
+
*/
|
|
19
|
+
import type { FormattedCircuitInputsDop, Proof } from 'dop-engine-v3';
|
|
20
|
+
/**
|
|
21
|
+
* Mopro CircomProofResult structure
|
|
22
|
+
* This is the proof format returned by mopro's generateCircomProof
|
|
23
|
+
*/
|
|
24
|
+
interface MoproCircomProofResult {
|
|
25
|
+
proof: {
|
|
26
|
+
a: string[];
|
|
27
|
+
b: string[][];
|
|
28
|
+
c: string[];
|
|
29
|
+
};
|
|
30
|
+
pub_signals: string[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Mopro ProofLib enum for selecting proof backend
|
|
34
|
+
*/
|
|
35
|
+
declare enum ProofLib {
|
|
36
|
+
Arkworks = "Arkworks",
|
|
37
|
+
Rapidsnark = "Rapidsnark"
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Initialize Mopro module
|
|
41
|
+
* Dynamically imports mopro-ffi to avoid compilation errors when not installed
|
|
42
|
+
*/
|
|
43
|
+
export declare const initializeMopro: () => Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if Mopro is available and initialized
|
|
46
|
+
*/
|
|
47
|
+
export declare const isMoproAvailable: () => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Mopro Prover Adapter Class
|
|
50
|
+
*
|
|
51
|
+
* Provides a unified interface for generating proofs with Mopro
|
|
52
|
+
* that is compatible with DOP Engine's proof format.
|
|
53
|
+
*/
|
|
54
|
+
export declare class MoproProverAdapter {
|
|
55
|
+
private proofLib;
|
|
56
|
+
constructor(proofLib?: ProofLib);
|
|
57
|
+
/**
|
|
58
|
+
* Generate a zero-knowledge proof using Mopro
|
|
59
|
+
*
|
|
60
|
+
* @param circuitId - Circuit identifier for logging/debugging
|
|
61
|
+
* @param zkeyPath - Path to the zkey file on device filesystem
|
|
62
|
+
* @param jsonInputs - Circuit inputs in JSON format
|
|
63
|
+
* @param progressCallback - Optional progress callback (0-100)
|
|
64
|
+
* @returns DOP Engine compatible proof object
|
|
65
|
+
*/
|
|
66
|
+
generateProof(circuitId: string, zkeyPath: string, jsonInputs: FormattedCircuitInputsDop, progressCallback?: (progress: number) => void): Promise<Proof>;
|
|
67
|
+
/**
|
|
68
|
+
* Verify a proof using Mopro (optional, for debugging)
|
|
69
|
+
*
|
|
70
|
+
* @param zkeyPath - Path to the zkey file
|
|
71
|
+
* @param proof - The proof to verify
|
|
72
|
+
* @returns true if proof is valid
|
|
73
|
+
*/
|
|
74
|
+
verifyProof(zkeyPath: string, proof: MoproCircomProofResult): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Convert Mopro proof format to DOP Engine format
|
|
77
|
+
*
|
|
78
|
+
* Mopro format:
|
|
79
|
+
* {
|
|
80
|
+
* proof: { a: [string, string], b: [[string, string], [string, string]], c: [string, string] },
|
|
81
|
+
* pub_signals: string[]
|
|
82
|
+
* }
|
|
83
|
+
*
|
|
84
|
+
* DOP Engine format:
|
|
85
|
+
* {
|
|
86
|
+
* pi_a: [string, string],
|
|
87
|
+
* pi_b: [[string, string], [string, string]],
|
|
88
|
+
* pi_c: [string, string]
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* Note: Public signals are handled separately by DOP Engine
|
|
92
|
+
*/
|
|
93
|
+
private static convertMoproProofToDopFormat;
|
|
94
|
+
/**
|
|
95
|
+
* Get public signals from Mopro proof result
|
|
96
|
+
* DOP Engine may need these separately
|
|
97
|
+
*/
|
|
98
|
+
static getPublicSignals(moproResult: MoproCircomProofResult): string[];
|
|
99
|
+
/**
|
|
100
|
+
* Set the proof backend (Arkworks or Rapidsnark)
|
|
101
|
+
*
|
|
102
|
+
* Arkworks: Pure Rust implementation, consistent performance
|
|
103
|
+
* Rapidsnark: C++ optimized, potentially faster on some devices
|
|
104
|
+
*/
|
|
105
|
+
setProofLib(proofLib: ProofLib): void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Export ProofLib enum for external use
|
|
109
|
+
*/
|
|
110
|
+
export { ProofLib };
|
|
111
|
+
/**
|
|
112
|
+
* Create a configured Mopro prover adapter
|
|
113
|
+
*
|
|
114
|
+
* @param useRapidsnark - Use Rapidsnark backend instead of Arkworks
|
|
115
|
+
* @returns Configured MoproProverAdapter instance
|
|
116
|
+
*/
|
|
117
|
+
export declare const createMoproProver: (useRapidsnark?: boolean) => MoproProverAdapter;
|