dop-wallet-v6 1.3.34 → 1.3.35
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 +1 -11
- package/README.md +9 -367
- package/dist/services/dop/core/index.d.ts +0 -4
- package/dist/services/dop/core/index.js +0 -5
- package/dist/services/dop/core/index.js.map +1 -1
- package/dist/services/dop/core/react-native-init.js +1 -28
- package/dist/services/dop/core/react-native-init.js.map +1 -1
- package/package.json +1 -1
- package/react-native.js +1 -13
- package/dist/services/dop/core/react-native-prover-setup.d.ts +0 -51
- package/dist/services/dop/core/react-native-prover-setup.js +0 -227
- package/dist/services/dop/core/react-native-prover-setup.js.map +0 -1
- package/dist/services/dop/crypto/mopro-circuit-loader.d.ts +0 -103
- package/dist/services/dop/crypto/mopro-circuit-loader.js +0 -308
- package/dist/services/dop/crypto/mopro-circuit-loader.js.map +0 -1
- package/dist/services/dop/crypto/mopro-prover-adapter.d.ts +0 -117
- package/dist/services/dop/crypto/mopro-prover-adapter.js +0 -243
- package/dist/services/dop/crypto/mopro-prover-adapter.js.map +0 -1
- package/dist/services/dop/crypto/user-rapidsnark-adapter.d.ts +0 -98
- package/dist/services/dop/crypto/user-rapidsnark-adapter.js +0 -226
- package/dist/services/dop/crypto/user-rapidsnark-adapter.js.map +0 -1
- package/dist/services/transactions/tx-encrypt-relayer.d.ts +0 -6
- package/dist/services/transactions/tx-encrypt-relayer.js +0 -80
- package/dist/services/transactions/tx-encrypt-relayer.js.map +0 -1
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Mopro Prover Adapter for React Native
|
|
4
|
-
*
|
|
5
|
-
* This adapter enables fully on-device zero-knowledge proof generation
|
|
6
|
-
* using the Mopro (Mobile Prover) toolkit, eliminating the need for
|
|
7
|
-
* backend witness generation services.
|
|
8
|
-
*
|
|
9
|
-
* Mopro provides native witness calculation and proof generation through
|
|
10
|
-
* Rust FFI bindings, bypassing React Native's WebAssembly limitations.
|
|
11
|
-
*
|
|
12
|
-
* Performance Benefits:
|
|
13
|
-
* - Witness generation: 2-29x faster than browser SnarkJS
|
|
14
|
-
* - Proof generation: 8-15x faster than browser SnarkJS
|
|
15
|
-
* - Native iOS/Android performance
|
|
16
|
-
* - No network calls required
|
|
17
|
-
*
|
|
18
|
-
* @see https://zkmopro.org/docs/intro
|
|
19
|
-
*/
|
|
20
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
-
}
|
|
26
|
-
Object.defineProperty(o, k2, desc);
|
|
27
|
-
}) : (function(o, m, k, k2) {
|
|
28
|
-
if (k2 === undefined) k2 = k;
|
|
29
|
-
o[k2] = m[k];
|
|
30
|
-
}));
|
|
31
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
-
}) : function(o, v) {
|
|
34
|
-
o["default"] = v;
|
|
35
|
-
});
|
|
36
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.createMoproProver = exports.ProofLib = exports.MoproProverAdapter = exports.isMoproAvailable = exports.initializeMopro = void 0;
|
|
45
|
-
const runtime_1 = require("../util/runtime");
|
|
46
|
-
/**
|
|
47
|
-
* Mopro ProofLib enum for selecting proof backend
|
|
48
|
-
*/
|
|
49
|
-
var ProofLib;
|
|
50
|
-
(function (ProofLib) {
|
|
51
|
-
ProofLib["Arkworks"] = "Arkworks";
|
|
52
|
-
ProofLib["Rapidsnark"] = "Rapidsnark";
|
|
53
|
-
})(ProofLib || (ProofLib = {}));
|
|
54
|
-
exports.ProofLib = ProofLib;
|
|
55
|
-
let moproModule = null;
|
|
56
|
-
/**
|
|
57
|
-
* Initialize Mopro module
|
|
58
|
-
* Dynamically imports mopro-ffi to avoid compilation errors when not installed
|
|
59
|
-
*/
|
|
60
|
-
const initializeMopro = async () => {
|
|
61
|
-
var _a;
|
|
62
|
-
if (!runtime_1.isReactNative) {
|
|
63
|
-
console.log('🖥️ Not in React Native environment, skipping mopro initialization');
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
console.log('📱 Initializing Mopro for React Native...');
|
|
68
|
-
// Dynamic import to avoid errors when mopro-ffi is not installed
|
|
69
|
-
let moproImport;
|
|
70
|
-
try {
|
|
71
|
-
const moduleName = 'mopro-ffi';
|
|
72
|
-
moproImport = await (_a = moduleName, Promise.resolve().then(() => __importStar(require(_a))));
|
|
73
|
-
}
|
|
74
|
-
catch (importError) {
|
|
75
|
-
console.log('📝 mopro-ffi not available:', String(importError));
|
|
76
|
-
console.log('💡 Install mopro-ffi for on-device proof generation:');
|
|
77
|
-
console.log(' npm install mopro-ffi');
|
|
78
|
-
console.log(' Follow setup guide: https://zkmopro.org/docs/setup/react-native-setup');
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const { generateCircomProof, verifyCircomProof } = moproImport;
|
|
82
|
-
moproModule = {
|
|
83
|
-
generateCircomProof,
|
|
84
|
-
verifyCircomProof
|
|
85
|
-
};
|
|
86
|
-
console.log('✅ Mopro initialized successfully');
|
|
87
|
-
console.log('🚀 Fully on-device proof generation enabled');
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.warn('⚠️ Mopro initialization failed:', error);
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
exports.initializeMopro = initializeMopro;
|
|
96
|
-
/**
|
|
97
|
-
* Check if Mopro is available and initialized
|
|
98
|
-
*/
|
|
99
|
-
const isMoproAvailable = () => {
|
|
100
|
-
return runtime_1.isReactNative && moproModule !== null;
|
|
101
|
-
};
|
|
102
|
-
exports.isMoproAvailable = isMoproAvailable;
|
|
103
|
-
/**
|
|
104
|
-
* Mopro Prover Adapter Class
|
|
105
|
-
*
|
|
106
|
-
* Provides a unified interface for generating proofs with Mopro
|
|
107
|
-
* that is compatible with DOP Engine's proof format.
|
|
108
|
-
*/
|
|
109
|
-
class MoproProverAdapter {
|
|
110
|
-
proofLib;
|
|
111
|
-
constructor(proofLib = ProofLib.Arkworks) {
|
|
112
|
-
this.proofLib = proofLib;
|
|
113
|
-
if (!(0, exports.isMoproAvailable)()) {
|
|
114
|
-
throw new Error('Mopro is not initialized. Call initializeMopro() first.');
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Generate a zero-knowledge proof using Mopro
|
|
119
|
-
*
|
|
120
|
-
* @param circuitId - Circuit identifier for logging/debugging
|
|
121
|
-
* @param zkeyPath - Path to the zkey file on device filesystem
|
|
122
|
-
* @param jsonInputs - Circuit inputs in JSON format
|
|
123
|
-
* @param progressCallback - Optional progress callback (0-100)
|
|
124
|
-
* @returns DOP Engine compatible proof object
|
|
125
|
-
*/
|
|
126
|
-
async generateProof(circuitId, zkeyPath, jsonInputs, progressCallback) {
|
|
127
|
-
if (!moproModule) {
|
|
128
|
-
throw new Error('Mopro module not initialized');
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
console.log(`🔐 Generating proof with Mopro for circuit: ${circuitId}`);
|
|
132
|
-
const startTime = Date.now();
|
|
133
|
-
if (progressCallback) {
|
|
134
|
-
progressCallback(10);
|
|
135
|
-
}
|
|
136
|
-
// Convert circuit inputs to JSON string
|
|
137
|
-
const circuitInputsJson = JSON.stringify(jsonInputs);
|
|
138
|
-
// Remove 'file://' prefix if present
|
|
139
|
-
const cleanZkeyPath = zkeyPath.replace('file://', '');
|
|
140
|
-
if (progressCallback) {
|
|
141
|
-
progressCallback(20);
|
|
142
|
-
}
|
|
143
|
-
// Generate proof using Mopro
|
|
144
|
-
console.log(` Using proof backend: ${this.proofLib}`);
|
|
145
|
-
const moproResult = moproModule.generateCircomProof(cleanZkeyPath, circuitInputsJson, this.proofLib);
|
|
146
|
-
if (progressCallback) {
|
|
147
|
-
progressCallback(90);
|
|
148
|
-
}
|
|
149
|
-
// Convert Mopro proof format to DOP Engine format
|
|
150
|
-
const dopProof = MoproProverAdapter.convertMoproProofToDopFormat(moproResult);
|
|
151
|
-
const elapsedTime = Date.now() - startTime;
|
|
152
|
-
console.log(`✅ Proof generated successfully in ${elapsedTime}ms`);
|
|
153
|
-
if (progressCallback) {
|
|
154
|
-
progressCallback(100);
|
|
155
|
-
}
|
|
156
|
-
return dopProof;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
console.error(`❌ Mopro proof generation failed for ${circuitId}:`, error);
|
|
160
|
-
throw new Error(`Mopro proof generation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Verify a proof using Mopro (optional, for debugging)
|
|
165
|
-
*
|
|
166
|
-
* @param zkeyPath - Path to the zkey file
|
|
167
|
-
* @param proof - The proof to verify
|
|
168
|
-
* @returns true if proof is valid
|
|
169
|
-
*/
|
|
170
|
-
async verifyProof(zkeyPath, proof) {
|
|
171
|
-
if (!moproModule) {
|
|
172
|
-
throw new Error('Mopro module not initialized');
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
const cleanZkeyPath = zkeyPath.replace('file://', '');
|
|
176
|
-
const isValid = moproModule.verifyCircomProof(cleanZkeyPath, proof, this.proofLib);
|
|
177
|
-
console.log(`🔍 Proof verification result: ${isValid ? '✅ Valid' : '❌ Invalid'}`);
|
|
178
|
-
return isValid;
|
|
179
|
-
}
|
|
180
|
-
catch (error) {
|
|
181
|
-
console.error('❌ Proof verification failed:', error);
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Convert Mopro proof format to DOP Engine format
|
|
187
|
-
*
|
|
188
|
-
* Mopro format:
|
|
189
|
-
* {
|
|
190
|
-
* proof: { a: [string, string], b: [[string, string], [string, string]], c: [string, string] },
|
|
191
|
-
* pub_signals: string[]
|
|
192
|
-
* }
|
|
193
|
-
*
|
|
194
|
-
* DOP Engine format:
|
|
195
|
-
* {
|
|
196
|
-
* pi_a: [string, string],
|
|
197
|
-
* pi_b: [[string, string], [string, string]],
|
|
198
|
-
* pi_c: [string, string]
|
|
199
|
-
* }
|
|
200
|
-
*
|
|
201
|
-
* Note: Public signals are handled separately by DOP Engine
|
|
202
|
-
*/
|
|
203
|
-
static convertMoproProofToDopFormat(moproResult) {
|
|
204
|
-
return {
|
|
205
|
-
pi_a: [moproResult.proof.a[0], moproResult.proof.a[1]],
|
|
206
|
-
pi_b: [
|
|
207
|
-
[moproResult.proof.b[0][0], moproResult.proof.b[0][1]],
|
|
208
|
-
[moproResult.proof.b[1][0], moproResult.proof.b[1][1]]
|
|
209
|
-
],
|
|
210
|
-
pi_c: [moproResult.proof.c[0], moproResult.proof.c[1]]
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Get public signals from Mopro proof result
|
|
215
|
-
* DOP Engine may need these separately
|
|
216
|
-
*/
|
|
217
|
-
static getPublicSignals(moproResult) {
|
|
218
|
-
return moproResult.pub_signals;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Set the proof backend (Arkworks or Rapidsnark)
|
|
222
|
-
*
|
|
223
|
-
* Arkworks: Pure Rust implementation, consistent performance
|
|
224
|
-
* Rapidsnark: C++ optimized, potentially faster on some devices
|
|
225
|
-
*/
|
|
226
|
-
setProofLib(proofLib) {
|
|
227
|
-
this.proofLib = proofLib;
|
|
228
|
-
console.log(`📝 Mopro proof backend set to: ${proofLib}`);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
exports.MoproProverAdapter = MoproProverAdapter;
|
|
232
|
-
/**
|
|
233
|
-
* Create a configured Mopro prover adapter
|
|
234
|
-
*
|
|
235
|
-
* @param useRapidsnark - Use Rapidsnark backend instead of Arkworks
|
|
236
|
-
* @returns Configured MoproProverAdapter instance
|
|
237
|
-
*/
|
|
238
|
-
const createMoproProver = (useRapidsnark = false) => {
|
|
239
|
-
const proofLib = useRapidsnark ? ProofLib.Rapidsnark : ProofLib.Arkworks;
|
|
240
|
-
return new MoproProverAdapter(proofLib);
|
|
241
|
-
};
|
|
242
|
-
exports.createMoproProver = createMoproProver;
|
|
243
|
-
//# sourceMappingURL=mopro-prover-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mopro-prover-adapter.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/mopro-prover-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAgD;AAgBhD;;GAEG;AACH,IAAK,QAGJ;AAHD,WAAK,QAAQ;IACX,iCAAqB,CAAA;IACrB,qCAAyB,CAAA;AAC3B,CAAC,EAHI,QAAQ,KAAR,QAAQ,QAGZ;AAsPQ,4BAAQ;AAnOjB,IAAI,WAAW,GAAoB,IAAI,CAAC;AAExC;;;GAGG;AACI,MAAM,eAAe,GAAG,KAAK,IAAsB,EAAE;;IAC1D,IAAI,CAAC,uBAAa,EAAE;QAClB,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;QAClF,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,OAAO,CAAC,GAA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AAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtD,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACvD;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACvD,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAmC;QACzD,OAAO,WAAW,CAAC,WAAW,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACH,WAAW,CAAC,QAAkB;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF;AAjKD,gDAiKC;AAOD;;;;;GAKG;AACI,MAAM,iBAAiB,GAAG,CAAC,aAAa,GAAG,KAAK,EAAsB,EAAE;IAC7E,MAAM,QAAQ,GAAG,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;IACzE,OAAO,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC,CAAC;AAHW,QAAA,iBAAiB,qBAG5B","sourcesContent":["/**\n * Mopro Prover Adapter for React Native\n * \n * This adapter enables fully on-device zero-knowledge proof generation\n * using the Mopro (Mobile Prover) toolkit, eliminating the need for\n * backend witness generation services.\n * \n * Mopro provides native witness calculation and proof generation through\n * Rust FFI bindings, bypassing React Native's WebAssembly limitations.\n * \n * Performance Benefits:\n * - Witness generation: 2-29x faster than browser SnarkJS\n * - Proof generation: 8-15x faster than browser SnarkJS\n * - Native iOS/Android performance\n * - No network calls required\n * \n * @see https://zkmopro.org/docs/intro\n */\n\nimport { isReactNative } from '../util/runtime';\nimport type { FormattedCircuitInputsDop, Proof } from 'dop-engine-v3';\n\n/**\n * Mopro CircomProofResult structure\n * This is the proof format returned by mopro's generateCircomProof\n */\ninterface MoproCircomProofResult {\n proof: {\n a: string[];\n b: string[][];\n c: string[];\n };\n pub_signals: string[];\n}\n\n/**\n * Mopro ProofLib enum for selecting proof backend\n */\nenum ProofLib {\n Arkworks = 'Arkworks',\n Rapidsnark = 'Rapidsnark'\n}\n\n/**\n * Mopro FFI interface (dynamically imported)\n */\ninterface MoproFFI {\n generateCircomProof: (\n zkeyPath: string,\n circuitInputsJson: string,\n proofLib: ProofLib\n ) => MoproCircomProofResult;\n \n verifyCircomProof: (\n zkeyPath: string,\n proof: MoproCircomProofResult,\n proofLib: ProofLib\n ) => boolean;\n}\n\nlet moproModule: MoproFFI | null = null;\n\n/**\n * Initialize Mopro module\n * Dynamically imports mopro-ffi to avoid compilation errors when not installed\n */\nexport const initializeMopro = async (): Promise<boolean> => {\n if (!isReactNative) {\n console.log('🖥️ Not in React Native environment, skipping mopro initialization');\n return false;\n }\n\n try {\n console.log('📱 Initializing Mopro for React Native...');\n \n // Dynamic import to avoid errors when mopro-ffi is not installed\n let moproImport: unknown;\n try {\n const moduleName = 'mopro-ffi';\n moproImport = await import(moduleName);\n } catch (importError) {\n console.log('📝 mopro-ffi not available:', String(importError));\n console.log('💡 Install mopro-ffi for on-device proof generation:');\n console.log(' npm install mopro-ffi');\n console.log(' Follow setup guide: https://zkmopro.org/docs/setup/react-native-setup');\n return false;\n }\n \n const { generateCircomProof, verifyCircomProof } = moproImport as {\n generateCircomProof: MoproFFI['generateCircomProof'];\n verifyCircomProof: MoproFFI['verifyCircomProof'];\n };\n \n moproModule = {\n generateCircomProof,\n verifyCircomProof\n };\n \n console.log('✅ Mopro initialized successfully');\n console.log('🚀 Fully on-device proof generation enabled');\n return true;\n \n } catch (error) {\n console.warn('⚠️ Mopro initialization failed:', error);\n return false;\n }\n};\n\n/**\n * Check if Mopro is available and initialized\n */\nexport const isMoproAvailable = (): boolean => {\n return isReactNative && moproModule !== null;\n};\n\n/**\n * Mopro Prover Adapter Class\n * \n * Provides a unified interface for generating proofs with Mopro\n * that is compatible with DOP Engine's proof format.\n */\nexport class MoproProverAdapter {\n private proofLib: ProofLib;\n\n constructor(proofLib: ProofLib = ProofLib.Arkworks) {\n this.proofLib = proofLib;\n \n if (!isMoproAvailable()) {\n throw new Error(\n 'Mopro is not initialized. Call initializeMopro() first.'\n );\n }\n }\n\n /**\n * Generate a zero-knowledge proof using Mopro\n * \n * @param circuitId - Circuit identifier for logging/debugging\n * @param zkeyPath - Path to the zkey file on device filesystem\n * @param jsonInputs - Circuit inputs in JSON format\n * @param progressCallback - Optional progress callback (0-100)\n * @returns DOP Engine compatible proof object\n */\n async generateProof(\n circuitId: string,\n zkeyPath: string,\n jsonInputs: FormattedCircuitInputsDop,\n progressCallback?: (progress: number) => void\n ): Promise<Proof> {\n if (!moproModule) {\n throw new Error('Mopro module not initialized');\n }\n\n try {\n console.log(`🔐 Generating proof with Mopro for circuit: ${circuitId}`);\n const startTime = Date.now();\n\n if (progressCallback) {\n progressCallback(10);\n }\n\n // Convert circuit inputs to JSON string\n const circuitInputsJson = JSON.stringify(jsonInputs);\n \n // Remove 'file://' prefix if present\n const cleanZkeyPath = zkeyPath.replace('file://', '');\n\n if (progressCallback) {\n progressCallback(20);\n }\n\n // Generate proof using Mopro\n console.log(` Using proof backend: ${this.proofLib}`);\n const moproResult: MoproCircomProofResult = moproModule.generateCircomProof(\n cleanZkeyPath,\n circuitInputsJson,\n this.proofLib\n );\n\n if (progressCallback) {\n progressCallback(90);\n }\n\n // Convert Mopro proof format to DOP Engine format\n const dopProof: Proof = MoproProverAdapter.convertMoproProofToDopFormat(moproResult);\n\n const elapsedTime = Date.now() - startTime;\n console.log(`✅ Proof generated successfully in ${elapsedTime}ms`);\n\n if (progressCallback) {\n progressCallback(100);\n }\n\n return dopProof;\n\n } catch (error) {\n console.error(`❌ Mopro proof generation failed for ${circuitId}:`, error);\n throw new Error(\n `Mopro proof generation failed: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n }\n\n /**\n * Verify a proof using Mopro (optional, for debugging)\n * \n * @param zkeyPath - Path to the zkey file\n * @param proof - The proof to verify\n * @returns true if proof is valid\n */\n async verifyProof(\n zkeyPath: string,\n proof: MoproCircomProofResult\n ): Promise<boolean> {\n if (!moproModule) {\n throw new Error('Mopro module not initialized');\n }\n\n try {\n const cleanZkeyPath = zkeyPath.replace('file://', '');\n const isValid = moproModule.verifyCircomProof(\n cleanZkeyPath,\n proof,\n this.proofLib\n );\n \n console.log(`🔍 Proof verification result: ${isValid ? '✅ Valid' : '❌ Invalid'}`);\n return isValid;\n\n } catch (error) {\n console.error('❌ Proof verification failed:', error);\n return false;\n }\n }\n\n /**\n * Convert Mopro proof format to DOP Engine format\n * \n * Mopro format:\n * {\n * proof: { a: [string, string], b: [[string, string], [string, string]], c: [string, string] },\n * pub_signals: string[]\n * }\n * \n * DOP Engine format:\n * {\n * pi_a: [string, string],\n * pi_b: [[string, string], [string, string]],\n * pi_c: [string, string]\n * }\n * \n * Note: Public signals are handled separately by DOP Engine\n */\n private static convertMoproProofToDopFormat(moproResult: MoproCircomProofResult): Proof {\n return {\n pi_a: [moproResult.proof.a[0], moproResult.proof.a[1]],\n pi_b: [\n [moproResult.proof.b[0][0], moproResult.proof.b[0][1]],\n [moproResult.proof.b[1][0], moproResult.proof.b[1][1]]\n ],\n pi_c: [moproResult.proof.c[0], moproResult.proof.c[1]]\n };\n }\n\n /**\n * Get public signals from Mopro proof result\n * DOP Engine may need these separately\n */\n static getPublicSignals(moproResult: MoproCircomProofResult): string[] {\n return moproResult.pub_signals;\n }\n\n /**\n * Set the proof backend (Arkworks or Rapidsnark)\n * \n * Arkworks: Pure Rust implementation, consistent performance\n * Rapidsnark: C++ optimized, potentially faster on some devices\n */\n setProofLib(proofLib: ProofLib): void {\n this.proofLib = proofLib;\n console.log(`📝 Mopro proof backend set to: ${proofLib}`);\n }\n}\n\n/**\n * Export ProofLib enum for external use\n */\nexport { ProofLib };\n\n/**\n * Create a configured Mopro prover adapter\n * \n * @param useRapidsnark - Use Rapidsnark backend instead of Arkworks\n * @returns Configured MoproProverAdapter instance\n */\nexport const createMoproProver = (useRapidsnark = false): MoproProverAdapter => {\n const proofLib = useRapidsnark ? ProofLib.Rapidsnark : ProofLib.Arkworks;\n return new MoproProverAdapter(proofLib);\n};\n"]}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* User-Configurable Rapidsnark Adapter for React Native
|
|
3
|
-
*
|
|
4
|
-
* This module provides a way for React Native developers to configure
|
|
5
|
-
* their own Rapidsnark prover implementation, bypassing SDK limitations.
|
|
6
|
-
*
|
|
7
|
-
* The user is responsible for:
|
|
8
|
-
* 1. Installing @iden3/react-native-rapidsnark
|
|
9
|
-
* 2. Managing circuit files (.zkey files)
|
|
10
|
-
* 3. Implementing witness generation
|
|
11
|
-
* 4. Calling setCustomRapidsnarkProver() after engine initialization
|
|
12
|
-
*/
|
|
13
|
-
import type { FormattedCircuitInputsDop, Proof } from 'dop-engine-v3';
|
|
14
|
-
/**
|
|
15
|
-
* Interface that users must implement for their Rapidsnark prover
|
|
16
|
-
*/
|
|
17
|
-
export interface UserRapidsnarkProver {
|
|
18
|
-
/**
|
|
19
|
-
* Generate a zero-knowledge proof using Rapidsnark
|
|
20
|
-
*
|
|
21
|
-
* @param circuitId - The circuit identifier (e.g., 'dop', 'decrypt', 'nullify')
|
|
22
|
-
* @param zkeyBuffer - The zkey file buffer (or path to zkey file in user's implementation)
|
|
23
|
-
* @param jsonInputs - The circuit inputs as JSON object
|
|
24
|
-
* @param progressCallback - Optional callback for progress updates
|
|
25
|
-
* @returns Promise containing the generated proof
|
|
26
|
-
*/
|
|
27
|
-
generateProof(circuitId: string, zkeyBuffer: Uint8Array, jsonInputs: FormattedCircuitInputsDop, progressCallback?: (progress: number) => void): Promise<Proof>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Helper function to convert Uint8Array to base64 string
|
|
31
|
-
*/
|
|
32
|
-
export declare const uint8ArrayToBase64: (buffer: Uint8Array) => string;
|
|
33
|
-
/**
|
|
34
|
-
* Helper function to save buffer to file system (React Native)
|
|
35
|
-
* Users should implement their own version using react-native-fs or similar
|
|
36
|
-
*/
|
|
37
|
-
export declare const saveBufferToFile: (_buffer: Uint8Array, _filename: string) => Promise<string>;
|
|
38
|
-
/**
|
|
39
|
-
* Set a custom Rapidsnark prover implementation
|
|
40
|
-
*
|
|
41
|
-
* This function allows React Native developers to provide their own
|
|
42
|
-
* Rapidsnark implementation, giving them full control over proof generation.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* import { setCustomRapidsnarkProver } from 'dop-wallet-v6';
|
|
47
|
-
* import { groth16Prove } from '@iden3/react-native-rapidsnark';
|
|
48
|
-
* import RNFS from 'react-native-fs';
|
|
49
|
-
*
|
|
50
|
-
* // Implement your own prover adapter
|
|
51
|
-
* const myRapidsnarkAdapter = {
|
|
52
|
-
* async generateProof(circuitId, zkeyBuffer, jsonInputs, progressCallback) {
|
|
53
|
-
* // 1. Save zkey to file
|
|
54
|
-
* const zkeyPath = `${RNFS.DocumentDirectoryPath}/${circuitId}.zkey`;
|
|
55
|
-
* await RNFS.writeFile(zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');
|
|
56
|
-
*
|
|
57
|
-
* // 2. Generate witness (implement your own witness generation)
|
|
58
|
-
* const witnessBase64 = await generateWitness(circuitId, jsonInputs);
|
|
59
|
-
*
|
|
60
|
-
* // 3. Generate proof with Rapidsnark
|
|
61
|
-
* const rapidsnarkProof = await groth16Prove(zkeyPath, witnessBase64);
|
|
62
|
-
*
|
|
63
|
-
* // 4. Convert to DOP Engine proof format
|
|
64
|
-
* return {
|
|
65
|
-
* pi_a: rapidsnarkProof.proof.a,
|
|
66
|
-
* pi_b: rapidsnarkProof.proof.b,
|
|
67
|
-
* pi_c: rapidsnarkProof.proof.c,
|
|
68
|
-
* publicSignals: rapidsnarkProof.pub_signals
|
|
69
|
-
* };
|
|
70
|
-
* }
|
|
71
|
-
* };
|
|
72
|
-
*
|
|
73
|
-
* // Set it after engine initialization
|
|
74
|
-
* await startDopEngineReactNative(...);
|
|
75
|
-
* setCustomRapidsnarkProver(myRapidsnarkAdapter);
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
/**
|
|
79
|
-
* Circuit ID mapping for DOP Engine
|
|
80
|
-
* These IDs are used internally by DOP Engine's native prover interface
|
|
81
|
-
*/
|
|
82
|
-
export declare const CIRCUIT_IDS: {
|
|
83
|
-
readonly dop: 0;
|
|
84
|
-
readonly decrypt: 1;
|
|
85
|
-
readonly nullify: 2;
|
|
86
|
-
};
|
|
87
|
-
export declare const setCustomRapidsnarkProver: (userProver: UserRapidsnarkProver) => void;
|
|
88
|
-
/**
|
|
89
|
-
* Remove custom prover and revert to default behavior
|
|
90
|
-
*/
|
|
91
|
-
export declare const clearCustomRapidsnarkProver: () => void;
|
|
92
|
-
/**
|
|
93
|
-
* Example implementation template for users to customize
|
|
94
|
-
*
|
|
95
|
-
* This is a reference implementation that users should copy and modify
|
|
96
|
-
* according to their specific needs and file system setup.
|
|
97
|
-
*/
|
|
98
|
-
export declare const createRapidsnarkProverTemplate: () => string;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* User-Configurable Rapidsnark Adapter for React Native
|
|
4
|
-
*
|
|
5
|
-
* This module provides a way for React Native developers to configure
|
|
6
|
-
* their own Rapidsnark prover implementation, bypassing SDK limitations.
|
|
7
|
-
*
|
|
8
|
-
* The user is responsible for:
|
|
9
|
-
* 1. Installing @iden3/react-native-rapidsnark
|
|
10
|
-
* 2. Managing circuit files (.zkey files)
|
|
11
|
-
* 3. Implementing witness generation
|
|
12
|
-
* 4. Calling setCustomRapidsnarkProver() after engine initialization
|
|
13
|
-
*/
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.createRapidsnarkProverTemplate = exports.clearCustomRapidsnarkProver = exports.setCustomRapidsnarkProver = exports.CIRCUIT_IDS = exports.saveBufferToFile = exports.uint8ArrayToBase64 = void 0;
|
|
16
|
-
const prover_1 = require("../core/prover");
|
|
17
|
-
const runtime_1 = require("../util/runtime");
|
|
18
|
-
/**
|
|
19
|
-
* Helper function to convert Uint8Array to base64 string
|
|
20
|
-
*/
|
|
21
|
-
const uint8ArrayToBase64 = (buffer) => {
|
|
22
|
-
if (typeof Buffer !== 'undefined') {
|
|
23
|
-
return Buffer.from(buffer).toString('base64');
|
|
24
|
-
}
|
|
25
|
-
// Fallback for environments without Buffer
|
|
26
|
-
let binary = '';
|
|
27
|
-
for (let i = 0; i < buffer.length; i += 1) {
|
|
28
|
-
binary += String.fromCharCode(buffer[i]);
|
|
29
|
-
}
|
|
30
|
-
return btoa(binary);
|
|
31
|
-
};
|
|
32
|
-
exports.uint8ArrayToBase64 = uint8ArrayToBase64;
|
|
33
|
-
/**
|
|
34
|
-
* Helper function to save buffer to file system (React Native)
|
|
35
|
-
* Users should implement their own version using react-native-fs or similar
|
|
36
|
-
*/
|
|
37
|
-
const saveBufferToFile = async (_buffer, _filename) => {
|
|
38
|
-
throw new Error('saveBufferToFile must be implemented by the user. ' +
|
|
39
|
-
'Use react-native-fs or similar library to save buffer to file system.');
|
|
40
|
-
};
|
|
41
|
-
exports.saveBufferToFile = saveBufferToFile;
|
|
42
|
-
/**
|
|
43
|
-
* Set a custom Rapidsnark prover implementation
|
|
44
|
-
*
|
|
45
|
-
* This function allows React Native developers to provide their own
|
|
46
|
-
* Rapidsnark implementation, giving them full control over proof generation.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* import { setCustomRapidsnarkProver } from 'dop-wallet-v6';
|
|
51
|
-
* import { groth16Prove } from '@iden3/react-native-rapidsnark';
|
|
52
|
-
* import RNFS from 'react-native-fs';
|
|
53
|
-
*
|
|
54
|
-
* // Implement your own prover adapter
|
|
55
|
-
* const myRapidsnarkAdapter = {
|
|
56
|
-
* async generateProof(circuitId, zkeyBuffer, jsonInputs, progressCallback) {
|
|
57
|
-
* // 1. Save zkey to file
|
|
58
|
-
* const zkeyPath = `${RNFS.DocumentDirectoryPath}/${circuitId}.zkey`;
|
|
59
|
-
* await RNFS.writeFile(zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');
|
|
60
|
-
*
|
|
61
|
-
* // 2. Generate witness (implement your own witness generation)
|
|
62
|
-
* const witnessBase64 = await generateWitness(circuitId, jsonInputs);
|
|
63
|
-
*
|
|
64
|
-
* // 3. Generate proof with Rapidsnark
|
|
65
|
-
* const rapidsnarkProof = await groth16Prove(zkeyPath, witnessBase64);
|
|
66
|
-
*
|
|
67
|
-
* // 4. Convert to DOP Engine proof format
|
|
68
|
-
* return {
|
|
69
|
-
* pi_a: rapidsnarkProof.proof.a,
|
|
70
|
-
* pi_b: rapidsnarkProof.proof.b,
|
|
71
|
-
* pi_c: rapidsnarkProof.proof.c,
|
|
72
|
-
* publicSignals: rapidsnarkProof.pub_signals
|
|
73
|
-
* };
|
|
74
|
-
* }
|
|
75
|
-
* };
|
|
76
|
-
*
|
|
77
|
-
* // Set it after engine initialization
|
|
78
|
-
* await startDopEngineReactNative(...);
|
|
79
|
-
* setCustomRapidsnarkProver(myRapidsnarkAdapter);
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
/**
|
|
83
|
-
* Circuit ID mapping for DOP Engine
|
|
84
|
-
* These IDs are used internally by DOP Engine's native prover interface
|
|
85
|
-
*/
|
|
86
|
-
exports.CIRCUIT_IDS = {
|
|
87
|
-
dop: 0,
|
|
88
|
-
decrypt: 1,
|
|
89
|
-
nullify: 2 // Nullifier circuit
|
|
90
|
-
};
|
|
91
|
-
const setCustomRapidsnarkProver = (userProver) => {
|
|
92
|
-
if (!runtime_1.isReactNative) {
|
|
93
|
-
// eslint-disable-next-line no-console
|
|
94
|
-
console.warn('⚠️ Custom Rapidsnark prover is only needed in React Native environment');
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
const prover = (0, prover_1.getProver)();
|
|
99
|
-
// Wrap user's prover to match DOP Engine's expected interface
|
|
100
|
-
// DOP Engine expects: (circuitId: number, datBuffer, zkeyBuffer, inputJson, progressCallback)
|
|
101
|
-
const wrappedProver = (circuitId, datBuffer, zkeyBuffer, jsonInputs, progressCallback) => {
|
|
102
|
-
// Convert numeric circuit ID to string name for user's convenience
|
|
103
|
-
const circuitName = Object.keys(exports.CIRCUIT_IDS).find(key => exports.CIRCUIT_IDS[key] === circuitId);
|
|
104
|
-
const circuitDisplayName = circuitName ?? `circuit_${circuitId}`;
|
|
105
|
-
// eslint-disable-next-line no-console
|
|
106
|
-
console.log(`🔄 Generating proof for circuit: ${circuitDisplayName} (ID: ${circuitId})`);
|
|
107
|
-
try {
|
|
108
|
-
const proof = userProver.generateProof(circuitDisplayName, zkeyBuffer, jsonInputs, progressCallback);
|
|
109
|
-
// eslint-disable-next-line no-console
|
|
110
|
-
console.log(`✅ Proof generated successfully for circuit: ${circuitDisplayName}`);
|
|
111
|
-
return proof;
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
// eslint-disable-next-line no-console
|
|
115
|
-
console.error(`❌ Proof generation failed for circuit ${circuitDisplayName}:`, error);
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
// Set the native prover in DOP Engine with circuit ID mapping
|
|
120
|
-
prover.setNativeProverGroth16(wrappedProver, exports.CIRCUIT_IDS);
|
|
121
|
-
// eslint-disable-next-line no-console
|
|
122
|
-
console.log('✅ Custom Rapidsnark prover configured successfully');
|
|
123
|
-
// eslint-disable-next-line no-console
|
|
124
|
-
console.log('🚀 React Native proof generation is now enabled');
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
// eslint-disable-next-line no-console
|
|
128
|
-
console.error('❌ Failed to set custom Rapidsnark prover:', error);
|
|
129
|
-
throw new Error(`Failed to set custom Rapidsnark prover: ${String(error)}`);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
exports.setCustomRapidsnarkProver = setCustomRapidsnarkProver;
|
|
133
|
-
/**
|
|
134
|
-
* Remove custom prover and revert to default behavior
|
|
135
|
-
*/
|
|
136
|
-
const clearCustomRapidsnarkProver = () => {
|
|
137
|
-
try {
|
|
138
|
-
const prover = (0, prover_1.getProver)();
|
|
139
|
-
prover.setNativeProverGroth16(undefined, {});
|
|
140
|
-
// eslint-disable-next-line no-console
|
|
141
|
-
console.log('✅ Custom Rapidsnark prover cleared');
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
// eslint-disable-next-line no-console
|
|
145
|
-
console.error('❌ Failed to clear custom prover:', error);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
exports.clearCustomRapidsnarkProver = clearCustomRapidsnarkProver;
|
|
149
|
-
/**
|
|
150
|
-
* Example implementation template for users to customize
|
|
151
|
-
*
|
|
152
|
-
* This is a reference implementation that users should copy and modify
|
|
153
|
-
* according to their specific needs and file system setup.
|
|
154
|
-
*/
|
|
155
|
-
const createRapidsnarkProverTemplate = () => {
|
|
156
|
-
return `
|
|
157
|
-
// Example Rapidsnark Prover Implementation Template
|
|
158
|
-
// Copy this and customize for your app's needs
|
|
159
|
-
|
|
160
|
-
import { setCustomRapidsnarkProver, uint8ArrayToBase64 } from 'dop-wallet-v6';
|
|
161
|
-
import { groth16Prove } from '@iden3/react-native-rapidsnark';
|
|
162
|
-
import RNFS from 'react-native-fs';
|
|
163
|
-
|
|
164
|
-
// 1. Implement witness generation (specific to your circuit setup)
|
|
165
|
-
const generateWitness = async (circuitId: string, inputs: any): Promise<string> => {
|
|
166
|
-
// TODO: Implement witness generation
|
|
167
|
-
// This depends on your circuit setup and how you handle .wasm files
|
|
168
|
-
|
|
169
|
-
// Option A: Use a witness generator service
|
|
170
|
-
const response = await fetch('https://your-backend.com/generate-witness', {
|
|
171
|
-
method: 'POST',
|
|
172
|
-
body: JSON.stringify({ circuitId, inputs })
|
|
173
|
-
});
|
|
174
|
-
const { witnessBase64 } = await response.json();
|
|
175
|
-
return witnessBase64;
|
|
176
|
-
|
|
177
|
-
// Option B: Generate locally if you have witness generator
|
|
178
|
-
// const witnessBuffer = await yourWitnessGenerator(circuitId, inputs);
|
|
179
|
-
// return uint8ArrayToBase64(witnessBuffer);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
// 2. Create your prover adapter
|
|
183
|
-
const myRapidsnarkProver = {
|
|
184
|
-
async generateProof(circuitId, zkeyBuffer, jsonInputs, progressCallback) {
|
|
185
|
-
try {
|
|
186
|
-
// Save zkey to file system
|
|
187
|
-
const zkeyPath = \`\${RNFS.DocumentDirectoryPath}/circuits/\${circuitId}.zkey\`;
|
|
188
|
-
await RNFS.mkdir(\`\${RNFS.DocumentDirectoryPath}/circuits\`);
|
|
189
|
-
await RNFS.writeFile(zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');
|
|
190
|
-
|
|
191
|
-
if (progressCallback) progressCallback(0.3);
|
|
192
|
-
|
|
193
|
-
// Generate witness
|
|
194
|
-
const witnessBase64 = await generateWitness(circuitId, jsonInputs);
|
|
195
|
-
|
|
196
|
-
if (progressCallback) progressCallback(0.6);
|
|
197
|
-
|
|
198
|
-
// Generate proof with Rapidsnark
|
|
199
|
-
const rapidsnarkProof = await groth16Prove(zkeyPath, witnessBase64);
|
|
200
|
-
|
|
201
|
-
if (progressCallback) progressCallback(0.9);
|
|
202
|
-
|
|
203
|
-
// Convert to DOP Engine proof format
|
|
204
|
-
return {
|
|
205
|
-
pi_a: rapidsnarkProof.proof.a,
|
|
206
|
-
pi_b: rapidsnarkProof.proof.b,
|
|
207
|
-
pi_c: rapidsnarkProof.proof.c,
|
|
208
|
-
publicSignals: rapidsnarkProof.pub_signals
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
} catch (error) {
|
|
212
|
-
console.error('Proof generation failed:', error);
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// 3. Set it up after DOP Engine initialization
|
|
219
|
-
export const setupMyRapidsnarkProver = () => {
|
|
220
|
-
setCustomRapidsnarkProver(myRapidsnarkProver);
|
|
221
|
-
console.log('✅ My custom Rapidsnark prover is ready!');
|
|
222
|
-
};
|
|
223
|
-
`;
|
|
224
|
-
};
|
|
225
|
-
exports.createRapidsnarkProverTemplate = createRapidsnarkProverTemplate;
|
|
226
|
-
//# sourceMappingURL=user-rapidsnark-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-rapidsnark-adapter.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/user-rapidsnark-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,2CAA2C;AAE3C,6CAAgD;AAuBhD;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAAC,MAAkB,EAAU,EAAE;IAC/D,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAC/C;IAED,2CAA2C;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACzC,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1C;IACD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC,CAAC;AAXW,QAAA,kBAA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;;;;;;;;;;;;CAmER,CAAC;AACF,CAAC,CAAC;AArEW,QAAA,8BAA8B,kCAqEzC","sourcesContent":["/**\n * User-Configurable Rapidsnark Adapter for React Native\n * \n * This module provides a way for React Native developers to configure\n * their own Rapidsnark prover implementation, bypassing SDK limitations.\n * \n * The user is responsible for:\n * 1. Installing @iden3/react-native-rapidsnark\n * 2. Managing circuit files (.zkey files)\n * 3. Implementing witness generation\n * 4. Calling setCustomRapidsnarkProver() after engine initialization\n */\n\nimport { getProver } from '../core/prover';\nimport type { FormattedCircuitInputsDop, Proof } from 'dop-engine-v3';\nimport { isReactNative } from '../util/runtime';\n\n/**\n * Interface that users must implement for their Rapidsnark prover\n */\nexport interface UserRapidsnarkProver {\n /**\n * Generate a zero-knowledge proof using Rapidsnark\n * \n * @param circuitId - The circuit identifier (e.g., 'dop', 'decrypt', 'nullify')\n * @param zkeyBuffer - The zkey file buffer (or path to zkey file in user's implementation)\n * @param jsonInputs - The circuit inputs as JSON object\n * @param progressCallback - Optional callback for progress updates\n * @returns Promise containing the generated proof\n */\n generateProof(\n circuitId: string,\n zkeyBuffer: Uint8Array,\n jsonInputs: FormattedCircuitInputsDop,\n progressCallback?: (progress: number) => void\n ): Promise<Proof>;\n}\n\n/**\n * Helper function to convert Uint8Array to base64 string\n */\nexport const uint8ArrayToBase64 = (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 * Helper function to save buffer to file system (React Native)\n * Users should implement their own version using react-native-fs or similar\n */\nexport const saveBufferToFile = async (\n _buffer: Uint8Array,\n _filename: string\n): Promise<string> => {\n throw new Error(\n 'saveBufferToFile must be implemented by the user. ' +\n 'Use react-native-fs or similar library to save buffer to file system.'\n );\n};\n\n/**\n * Set a custom Rapidsnark prover implementation\n * \n * This function allows React Native developers to provide their own\n * Rapidsnark implementation, giving them full control over proof generation.\n * \n * @example\n * ```typescript\n * import { setCustomRapidsnarkProver } from 'dop-wallet-v6';\n * import { groth16Prove } from '@iden3/react-native-rapidsnark';\n * import RNFS from 'react-native-fs';\n * \n * // Implement your own prover adapter\n * const myRapidsnarkAdapter = {\n * async generateProof(circuitId, zkeyBuffer, jsonInputs, progressCallback) {\n * // 1. Save zkey to file\n * const zkeyPath = `${RNFS.DocumentDirectoryPath}/${circuitId}.zkey`;\n * await RNFS.writeFile(zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');\n * \n * // 2. Generate witness (implement your own witness generation)\n * const witnessBase64 = await generateWitness(circuitId, jsonInputs);\n * \n * // 3. Generate proof with Rapidsnark\n * const rapidsnarkProof = await groth16Prove(zkeyPath, witnessBase64);\n * \n * // 4. Convert to DOP Engine proof format\n * return {\n * pi_a: rapidsnarkProof.proof.a,\n * pi_b: rapidsnarkProof.proof.b,\n * pi_c: rapidsnarkProof.proof.c,\n * publicSignals: rapidsnarkProof.pub_signals\n * };\n * }\n * };\n * \n * // Set it after engine initialization\n * await startDopEngineReactNative(...);\n * setCustomRapidsnarkProver(myRapidsnarkAdapter);\n * ```\n */\n/**\n * Circuit ID mapping for DOP Engine\n * These IDs are used internally by DOP Engine's native prover interface\n */\nexport const CIRCUIT_IDS = {\n dop: 0, // Main DOP transfer circuit\n decrypt: 1, // Decrypt circuit\n nullify: 2 // Nullifier circuit\n} as const;\n\nexport const setCustomRapidsnarkProver = (userProver: UserRapidsnarkProver): void => {\n if (!isReactNative) {\n // eslint-disable-next-line no-console\n console.warn('⚠️ Custom Rapidsnark prover is only needed in React Native environment');\n return;\n }\n\n try {\n const prover = getProver();\n \n // Wrap user's prover to match DOP Engine's expected interface\n // DOP Engine expects: (circuitId: number, datBuffer, zkeyBuffer, inputJson, progressCallback)\n const wrappedProver = (\n circuitId: number,\n datBuffer: Uint8Array,\n zkeyBuffer: Uint8Array,\n jsonInputs: FormattedCircuitInputsDop,\n progressCallback?: (progress: number) => void\n ): Promise<Proof> => {\n // Convert numeric circuit ID to string name for user's convenience\n const circuitName = Object.keys(CIRCUIT_IDS).find(\n key => CIRCUIT_IDS[key as keyof typeof CIRCUIT_IDS] === circuitId\n );\n const circuitDisplayName = circuitName ?? `circuit_${circuitId}`;\n \n // eslint-disable-next-line no-console\n console.log(`🔄 Generating proof for circuit: ${circuitDisplayName} (ID: ${circuitId})`);\n \n try {\n const proof = userProver.generateProof(\n circuitDisplayName,\n zkeyBuffer,\n jsonInputs,\n progressCallback\n );\n \n // eslint-disable-next-line no-console\n console.log(`✅ Proof generated successfully for circuit: ${circuitDisplayName}`);\n return proof;\n \n } catch (error) {\n // eslint-disable-next-line no-console\n console.error(`❌ Proof generation failed for circuit ${circuitDisplayName}:`, error);\n throw error;\n }\n };\n \n // Set the native prover in DOP Engine with circuit ID mapping\n prover.setNativeProverGroth16(wrappedProver as any, CIRCUIT_IDS);\n \n // eslint-disable-next-line no-console\n console.log('✅ Custom Rapidsnark prover configured successfully');\n // eslint-disable-next-line no-console\n console.log('🚀 React Native proof generation is now enabled');\n \n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('❌ Failed to set custom Rapidsnark prover:', error);\n throw new Error(`Failed to set custom Rapidsnark prover: ${String(error)}`);\n }\n};\n\n/**\n * Remove custom prover and revert to default behavior\n */\nexport const clearCustomRapidsnarkProver = (): void => {\n try {\n const prover = getProver();\n prover.setNativeProverGroth16(undefined as any, {});\n // eslint-disable-next-line no-console\n console.log('✅ Custom Rapidsnark prover cleared');\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('❌ Failed to clear custom prover:', error);\n }\n};\n\n/**\n * Example implementation template for users to customize\n * \n * This is a reference implementation that users should copy and modify\n * according to their specific needs and file system setup.\n */\nexport const createRapidsnarkProverTemplate = (): string => {\n return `\n// Example Rapidsnark Prover Implementation Template\n// Copy this and customize for your app's needs\n\nimport { setCustomRapidsnarkProver, uint8ArrayToBase64 } from 'dop-wallet-v6';\nimport { groth16Prove } from '@iden3/react-native-rapidsnark';\nimport RNFS from 'react-native-fs';\n\n// 1. Implement witness generation (specific to your circuit setup)\nconst generateWitness = async (circuitId: string, inputs: any): Promise<string> => {\n // TODO: Implement witness generation\n // This depends on your circuit setup and how you handle .wasm files\n \n // Option A: Use a witness generator service\n const response = await fetch('https://your-backend.com/generate-witness', {\n method: 'POST',\n body: JSON.stringify({ circuitId, inputs })\n });\n const { witnessBase64 } = await response.json();\n return witnessBase64;\n \n // Option B: Generate locally if you have witness generator\n // const witnessBuffer = await yourWitnessGenerator(circuitId, inputs);\n // return uint8ArrayToBase64(witnessBuffer);\n};\n\n// 2. Create your prover adapter\nconst myRapidsnarkProver = {\n async generateProof(circuitId, zkeyBuffer, jsonInputs, progressCallback) {\n try {\n // Save zkey to file system\n const zkeyPath = \\`\\${RNFS.DocumentDirectoryPath}/circuits/\\${circuitId}.zkey\\`;\n await RNFS.mkdir(\\`\\${RNFS.DocumentDirectoryPath}/circuits\\`);\n await RNFS.writeFile(zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');\n \n if (progressCallback) progressCallback(0.3);\n \n // Generate witness\n const witnessBase64 = await generateWitness(circuitId, jsonInputs);\n \n if (progressCallback) progressCallback(0.6);\n \n // Generate proof with Rapidsnark\n const rapidsnarkProof = await groth16Prove(zkeyPath, witnessBase64);\n \n if (progressCallback) progressCallback(0.9);\n \n // Convert to DOP Engine proof format\n return {\n pi_a: rapidsnarkProof.proof.a,\n pi_b: rapidsnarkProof.proof.b,\n pi_c: rapidsnarkProof.proof.c,\n publicSignals: rapidsnarkProof.pub_signals\n };\n \n } catch (error) {\n console.error('Proof generation failed:', error);\n throw error;\n }\n }\n};\n\n// 3. Set it up after DOP Engine initialization\nexport const setupMyRapidsnarkProver = () => {\n setCustomRapidsnarkProver(myRapidsnarkProver);\n console.log('✅ My custom Rapidsnark prover is ready!');\n};\n`;\n};\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { DopPopulateTransactionResponse, DopTransactionGasEstimateResponse, NetworkName, DopERC20AmountRecipient, DopNFTAmountRecipient, TransactionGasDetails, TXIDVersion } from 'dop-sharedmodels-v3';
|
|
2
|
-
import { ContractTransaction } from 'ethers';
|
|
3
|
-
export declare const getEncryptPrivateKeySignatureMessage: () => string;
|
|
4
|
-
export declare const generateEncryptTransactionWithRelayer: (txidVersion: TXIDVersion, networkName: NetworkName, encryptPrivateKey: string, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], fromWalletAddress: string) => Promise<ContractTransaction>;
|
|
5
|
-
export declare const populateEncryptWithRelayer: (txidVersion: TXIDVersion, networkName: NetworkName, encryptPrivateKey: string, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], fromWalletAddress: string, gasDetails?: TransactionGasDetails) => Promise<DopPopulateTransactionResponse>;
|
|
6
|
-
export declare const gasEstimateForEncryptWithRelayer: (txidVersion: TXIDVersion, networkName: NetworkName, encryptPrivateKey: string, erc20AmountRecipients: DopERC20AmountRecipient[], nftAmountRecipients: DopNFTAmountRecipient[], fromWalletAddress: string) => Promise<DopTransactionGasEstimateResponse>;
|