dop-wallet-v6 1.3.39 → 1.3.41
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/dist/services/dop/core/prover.d.ts +7 -0
- package/dist/services/dop/core/prover.js +6 -48
- package/dist/services/dop/core/prover.js.map +1 -1
- package/dist/services/dop/crypto/index.d.ts +3 -1
- package/dist/services/dop/crypto/index.js +43 -15
- package/dist/services/dop/crypto/index.js.map +1 -1
- package/dist/services/dop/crypto/rapidsnark-groth16.d.ts +211 -0
- package/dist/services/dop/crypto/rapidsnark-groth16.js +418 -0
- package/dist/services/dop/crypto/rapidsnark-groth16.js.map +1 -0
- package/dist/services/dop/crypto/react-native-prover.d.ts +338 -0
- package/dist/services/dop/crypto/react-native-prover.js +814 -0
- package/dist/services/dop/crypto/react-native-prover.js.map +1 -0
- package/dist/services/dop/crypto/react-native-rapidsnark-prover.js +27 -26
- package/dist/services/dop/crypto/react-native-rapidsnark-prover.js.map +1 -1
- package/dist/services/dop/crypto/wcd-prover.d.ts +242 -0
- package/dist/services/dop/crypto/wcd-prover.js +499 -0
- package/dist/services/dop/crypto/wcd-prover.js.map +1 -0
- package/package.json +1 -1
- package/dist/services/dop/crypto/custom-prover.d.ts +0 -78
- package/dist/services/dop/crypto/custom-prover.js +0 -78
- package/dist/services/dop/crypto/custom-prover.js.map +0 -1
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { FormattedCircuitInputsDop, SnarkJSGroth16, Proof, Prover } from 'dop-engine-v3';
|
|
2
|
+
/**
|
|
3
|
+
* Get the prover instance from DOP Engine
|
|
4
|
+
*
|
|
5
|
+
* Note: For React Native, use setWCDProver() from crypto/wcd-prover.ts
|
|
6
|
+
* which automatically intercepts the prover to use WCD-based proof generation.
|
|
7
|
+
* This is the recommended approach for mobile.
|
|
8
|
+
*/
|
|
2
9
|
export declare const getProver: () => Prover;
|
|
3
10
|
export { FormattedCircuitInputsDop, Proof, SnarkJSGroth16 };
|
|
@@ -3,61 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getProver = void 0;
|
|
4
4
|
const engine_1 = require("./engine");
|
|
5
5
|
const dop_sharedmodels_v3_1 = require("dop-sharedmodels-v3");
|
|
6
|
-
const custom_prover_1 = require("../crypto/custom-prover");
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Get the prover instance from DOP Engine
|
|
8
|
+
*
|
|
9
|
+
* Note: For React Native, use setWCDProver() from crypto/wcd-prover.ts
|
|
10
|
+
* which automatically intercepts the prover to use WCD-based proof generation.
|
|
11
|
+
* This is the recommended approach for mobile.
|
|
10
12
|
*/
|
|
11
|
-
function getCircuitIdFromInputs(formattedInputs) {
|
|
12
|
-
// Count nullifiers (non-zero entries)
|
|
13
|
-
const nullifierCount = formattedInputs.nullifiers?.filter((n) => n !== undefined && n !== null && BigInt(n) !== BigInt(0)).length || 0;
|
|
14
|
-
// Count commitments (non-zero entries)
|
|
15
|
-
const commitmentCount = formattedInputs.commitmentsOut?.filter((c) => c !== undefined && c !== null && BigInt(c) !== BigInt(0)).length || 0;
|
|
16
|
-
return `${nullifierCount}x${commitmentCount}`;
|
|
17
|
-
}
|
|
18
|
-
let proverIntercepted = false;
|
|
19
13
|
const getProver = () => {
|
|
20
14
|
const engine = (0, engine_1.getEngine)();
|
|
21
15
|
if (!(0, dop_sharedmodels_v3_1.isDefined)(engine)) {
|
|
22
16
|
throw new Error('DOP Engine not yet init. Please reload your app or try again.');
|
|
23
17
|
}
|
|
24
|
-
|
|
25
|
-
// Intercept groth16.fullProveDop only once
|
|
26
|
-
if (!proverIntercepted && prover.groth16) {
|
|
27
|
-
proverIntercepted = true;
|
|
28
|
-
const originalFullProveDop = prover.groth16.fullProveDop;
|
|
29
|
-
// Wrap fullProveDop to check for custom prover
|
|
30
|
-
prover.groth16.fullProveDop = async (formattedInputs, wasm, zkey, logger, dat, progressCallback) => {
|
|
31
|
-
// Check if custom prover is available
|
|
32
|
-
if ((0, custom_prover_1.hasCustomRapidsnarkProver)()) {
|
|
33
|
-
const customProver = (0, custom_prover_1.getCustomRapidsnarkProver)();
|
|
34
|
-
if (!customProver) {
|
|
35
|
-
throw new Error('Custom prover is null');
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
// Determine circuit ID from inputs
|
|
39
|
-
const circuitId = getCircuitIdFromInputs(formattedInputs);
|
|
40
|
-
logger.debug(`[Custom Prover] Using custom prover for circuit ${circuitId}`);
|
|
41
|
-
// Call custom prover (e.g., backend server)
|
|
42
|
-
const proof = await customProver.generateProof(circuitId, new Uint8Array(zkey), formattedInputs, progressCallback);
|
|
43
|
-
logger.debug(`[Custom Prover] Proof generated successfully via custom prover`);
|
|
44
|
-
// Return in expected format
|
|
45
|
-
return {
|
|
46
|
-
proof,
|
|
47
|
-
publicSignals: proof.publicSignals ?? []
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
52
|
-
logger.debug(`[Custom Prover] Error: ${errorMessage}`);
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// No custom prover - use original implementation
|
|
57
|
-
return originalFullProveDop(formattedInputs, wasm, zkey, logger, dat, progressCallback);
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return prover;
|
|
18
|
+
return engine.prover;
|
|
61
19
|
};
|
|
62
20
|
exports.getProver = getProver;
|
|
63
21
|
//# sourceMappingURL=prover.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prover.js","sourceRoot":"","sources":["../../../../src/services/dop/core/prover.ts"],"names":[],"mappings":";;;AAMA,qCAAqC;AACrC,6DAAgD;
|
|
1
|
+
{"version":3,"file":"prover.js","sourceRoot":"","sources":["../../../../src/services/dop/core/prover.ts"],"names":[],"mappings":";;;AAMA,qCAAqC;AACrC,6DAAgD;AAEhD;;;;;;GAMG;AACI,MAAM,SAAS,GAAG,GAAW,EAAE;IACpC,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;IAC3B,IAAI,CAAC,IAAA,+BAAS,EAAC,MAAM,CAAC,EAAE;QACtB,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;KACH;IAED,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC,CAAC;AATW,QAAA,SAAS,aASpB","sourcesContent":["import {\n FormattedCircuitInputsDop,\n SnarkJSGroth16,\n Proof,\n Prover,\n} from 'dop-engine-v3';\nimport { getEngine } from './engine';\nimport { isDefined } from 'dop-sharedmodels-v3';\n\n/**\n * Get the prover instance from DOP Engine\n * \n * Note: For React Native, use setWCDProver() from crypto/wcd-prover.ts\n * which automatically intercepts the prover to use WCD-based proof generation.\n * This is the recommended approach for mobile.\n */\nexport const getProver = (): Prover => {\n const engine = getEngine();\n if (!isDefined(engine)) {\n throw new Error(\n 'DOP Engine not yet init. Please reload your app or try again.',\n );\n }\n \n return engine.prover;\n};\n\nexport { FormattedCircuitInputsDop, Proof, SnarkJSGroth16 };\n"]}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { setRapidSnarkGroth16, type RapidSnarkGroth16Config, type RapidsnarkProofResult, type WitnessCalculator, type FileSystemInterface, type Groth16ProveFunction, createCircomWitnessCalculator, createReactNativeFSInterface, } from './rapidsnark-groth16';
|
|
2
|
+
export { setReactNativeProver, getReactNativeProver, type ReactNativeProverConfig, type RNFileSystem, type RNGroth16ProveFunction, type RNGroth16VerifyFunction, type RNRapidsnarkProofResult, type WitnessResult, type StoredCircuitArtifacts, CircuitArtifactManager, uint8ArrayToBase64, base64ToUint8Array, calculateWitnessFromWASM, createRNFSInterface, createExpoFSInterface, type RNArtifactStore, createRNArtifactStore, getRNArtifactPath, hasRNArtifacts, } from './react-native-prover';
|
|
3
|
+
export { setWCDProver, clearWCDProver, hasWCDProver, getWCDProverConfig, type WCDProverConfig, type WCDFileSystem, type WCDCalculateWitnessFunction, type WCDGroth16ProveFunction, type WCDRapidsnarkProofResult, type WCDArtifacts, WCDArtifactManager, createWCDArtifactManager, storeWCDArtifacts, hasWCDArtifacts, getWCDPath, getZkeyPathForWCD, storeWCDOnly, hasWCDFile, wcdUint8ArrayToBase64, wcdBase64ToUint8Array, } from './wcd-prover';
|
|
@@ -1,18 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.wcdBase64ToUint8Array = exports.wcdUint8ArrayToBase64 = exports.hasWCDFile = exports.storeWCDOnly = exports.getZkeyPathForWCD = exports.getWCDPath = exports.hasWCDArtifacts = exports.storeWCDArtifacts = exports.createWCDArtifactManager = exports.WCDArtifactManager = exports.getWCDProverConfig = exports.hasWCDProver = exports.clearWCDProver = exports.setWCDProver = exports.hasRNArtifacts = exports.getRNArtifactPath = exports.createRNArtifactStore = exports.createExpoFSInterface = exports.createRNFSInterface = exports.calculateWitnessFromWASM = exports.base64ToUint8Array = exports.uint8ArrayToBase64 = exports.CircuitArtifactManager = exports.getReactNativeProver = exports.setReactNativeProver = exports.createReactNativeFSInterface = exports.createCircomWitnessCalculator = exports.setRapidSnarkGroth16 = void 0;
|
|
4
|
+
// Export from rapidsnark-groth16 (legacy API, requires WitnessCalculator to be provided)
|
|
5
|
+
var rapidsnark_groth16_1 = require("./rapidsnark-groth16");
|
|
6
|
+
Object.defineProperty(exports, "setRapidSnarkGroth16", { enumerable: true, get: function () { return rapidsnark_groth16_1.setRapidSnarkGroth16; } });
|
|
7
|
+
Object.defineProperty(exports, "createCircomWitnessCalculator", { enumerable: true, get: function () { return rapidsnark_groth16_1.createCircomWitnessCalculator; } });
|
|
8
|
+
Object.defineProperty(exports, "createReactNativeFSInterface", { enumerable: true, get: function () { return rapidsnark_groth16_1.createReactNativeFSInterface; } });
|
|
9
|
+
// Export from react-native-prover (WASM-based API, handles everything internally)
|
|
10
|
+
var react_native_prover_1 = require("./react-native-prover");
|
|
11
|
+
// Main prover setup
|
|
12
|
+
Object.defineProperty(exports, "setReactNativeProver", { enumerable: true, get: function () { return react_native_prover_1.setReactNativeProver; } });
|
|
13
|
+
Object.defineProperty(exports, "getReactNativeProver", { enumerable: true, get: function () { return react_native_prover_1.getReactNativeProver; } });
|
|
14
|
+
Object.defineProperty(exports, "CircuitArtifactManager", { enumerable: true, get: function () { return react_native_prover_1.CircuitArtifactManager; } });
|
|
15
|
+
// Utility functions
|
|
16
|
+
Object.defineProperty(exports, "uint8ArrayToBase64", { enumerable: true, get: function () { return react_native_prover_1.uint8ArrayToBase64; } });
|
|
17
|
+
Object.defineProperty(exports, "base64ToUint8Array", { enumerable: true, get: function () { return react_native_prover_1.base64ToUint8Array; } });
|
|
18
|
+
Object.defineProperty(exports, "calculateWitnessFromWASM", { enumerable: true, get: function () { return react_native_prover_1.calculateWitnessFromWASM; } });
|
|
19
|
+
// File system helpers
|
|
20
|
+
Object.defineProperty(exports, "createRNFSInterface", { enumerable: true, get: function () { return react_native_prover_1.createRNFSInterface; } });
|
|
21
|
+
Object.defineProperty(exports, "createExpoFSInterface", { enumerable: true, get: function () { return react_native_prover_1.createExpoFSInterface; } });
|
|
22
|
+
Object.defineProperty(exports, "createRNArtifactStore", { enumerable: true, get: function () { return react_native_prover_1.createRNArtifactStore; } });
|
|
23
|
+
Object.defineProperty(exports, "getRNArtifactPath", { enumerable: true, get: function () { return react_native_prover_1.getRNArtifactPath; } });
|
|
24
|
+
Object.defineProperty(exports, "hasRNArtifacts", { enumerable: true, get: function () { return react_native_prover_1.hasRNArtifacts; } });
|
|
25
|
+
// Export from wcd-prover (RECOMMENDED for React Native - uses .wcd graph files)
|
|
26
|
+
// This is the fastest approach for mobile witness calculation
|
|
27
|
+
var wcd_prover_1 = require("./wcd-prover");
|
|
28
|
+
// Main prover setup
|
|
29
|
+
Object.defineProperty(exports, "setWCDProver", { enumerable: true, get: function () { return wcd_prover_1.setWCDProver; } });
|
|
30
|
+
Object.defineProperty(exports, "clearWCDProver", { enumerable: true, get: function () { return wcd_prover_1.clearWCDProver; } });
|
|
31
|
+
Object.defineProperty(exports, "hasWCDProver", { enumerable: true, get: function () { return wcd_prover_1.hasWCDProver; } });
|
|
32
|
+
Object.defineProperty(exports, "getWCDProverConfig", { enumerable: true, get: function () { return wcd_prover_1.getWCDProverConfig; } });
|
|
33
|
+
// Artifact management
|
|
34
|
+
Object.defineProperty(exports, "WCDArtifactManager", { enumerable: true, get: function () { return wcd_prover_1.WCDArtifactManager; } });
|
|
35
|
+
Object.defineProperty(exports, "createWCDArtifactManager", { enumerable: true, get: function () { return wcd_prover_1.createWCDArtifactManager; } });
|
|
36
|
+
Object.defineProperty(exports, "storeWCDArtifacts", { enumerable: true, get: function () { return wcd_prover_1.storeWCDArtifacts; } });
|
|
37
|
+
Object.defineProperty(exports, "hasWCDArtifacts", { enumerable: true, get: function () { return wcd_prover_1.hasWCDArtifacts; } });
|
|
38
|
+
Object.defineProperty(exports, "getWCDPath", { enumerable: true, get: function () { return wcd_prover_1.getWCDPath; } });
|
|
39
|
+
Object.defineProperty(exports, "getZkeyPathForWCD", { enumerable: true, get: function () { return wcd_prover_1.getZkeyPathForWCD; } });
|
|
40
|
+
// WCD-only management (SDK handles zkey automatically)
|
|
41
|
+
Object.defineProperty(exports, "storeWCDOnly", { enumerable: true, get: function () { return wcd_prover_1.storeWCDOnly; } });
|
|
42
|
+
Object.defineProperty(exports, "hasWCDFile", { enumerable: true, get: function () { return wcd_prover_1.hasWCDFile; } });
|
|
43
|
+
// Utility functions
|
|
44
|
+
Object.defineProperty(exports, "wcdUint8ArrayToBase64", { enumerable: true, get: function () { return wcd_prover_1.wcdUint8ArrayToBase64; } });
|
|
45
|
+
Object.defineProperty(exports, "wcdBase64ToUint8Array", { enumerable: true, get: function () { return wcd_prover_1.wcdBase64ToUint8Array; } });
|
|
18
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/index.ts"],"names":[],"mappings":";;;AAAA,yFAAyF;AACzF,2DAS8B;AAR5B,0HAAA,oBAAoB,OAAA;AAMpB,mIAAA,6BAA6B,OAAA;AAC7B,kIAAA,4BAA4B,OAAA;AAG9B,kFAAkF;AAClF,6DAwB+B;AAvB7B,oBAAoB;AACpB,2HAAA,oBAAoB,OAAA;AACpB,2HAAA,oBAAoB,OAAA;AAQpB,6HAAA,sBAAsB,OAAA;AACtB,oBAAoB;AACpB,yHAAA,kBAAkB,OAAA;AAClB,yHAAA,kBAAkB,OAAA;AAClB,+HAAA,wBAAwB,OAAA;AACxB,sBAAsB;AACtB,0HAAA,mBAAmB,OAAA;AACnB,4HAAA,qBAAqB,OAAA;AAGrB,4HAAA,qBAAqB,OAAA;AACrB,wHAAA,iBAAiB,OAAA;AACjB,qHAAA,cAAc,OAAA;AAGhB,gFAAgF;AAChF,8DAA8D;AAC9D,2CAyBsB;AAxBpB,oBAAoB;AACpB,0GAAA,YAAY,OAAA;AACZ,4GAAA,cAAc,OAAA;AACd,0GAAA,YAAY,OAAA;AACZ,gHAAA,kBAAkB,OAAA;AAOlB,sBAAsB;AACtB,gHAAA,kBAAkB,OAAA;AAClB,sHAAA,wBAAwB,OAAA;AACxB,+GAAA,iBAAiB,OAAA;AACjB,6GAAA,eAAe,OAAA;AACf,wGAAA,UAAU,OAAA;AACV,+GAAA,iBAAiB,OAAA;AACjB,uDAAuD;AACvD,0GAAA,YAAY,OAAA;AACZ,wGAAA,UAAU,OAAA;AACV,oBAAoB;AACpB,mHAAA,qBAAqB,OAAA;AACrB,mHAAA,qBAAqB,OAAA","sourcesContent":["// Export from rapidsnark-groth16 (legacy API, requires WitnessCalculator to be provided)\nexport {\n setRapidSnarkGroth16,\n type RapidSnarkGroth16Config,\n type RapidsnarkProofResult,\n type WitnessCalculator,\n type FileSystemInterface,\n type Groth16ProveFunction,\n createCircomWitnessCalculator,\n createReactNativeFSInterface,\n} from './rapidsnark-groth16';\n\n// Export from react-native-prover (WASM-based API, handles everything internally)\nexport {\n // Main prover setup\n setReactNativeProver,\n getReactNativeProver,\n type ReactNativeProverConfig,\n type RNFileSystem,\n type RNGroth16ProveFunction,\n type RNGroth16VerifyFunction,\n type RNRapidsnarkProofResult,\n type WitnessResult,\n type StoredCircuitArtifacts,\n CircuitArtifactManager,\n // Utility functions\n uint8ArrayToBase64,\n base64ToUint8Array,\n calculateWitnessFromWASM,\n // File system helpers\n createRNFSInterface,\n createExpoFSInterface,\n // Artifact store for SDK integration\n type RNArtifactStore,\n createRNArtifactStore,\n getRNArtifactPath,\n hasRNArtifacts,\n} from './react-native-prover';\n\n// Export from wcd-prover (RECOMMENDED for React Native - uses .wcd graph files)\n// This is the fastest approach for mobile witness calculation\nexport {\n // Main prover setup\n setWCDProver,\n clearWCDProver,\n hasWCDProver,\n getWCDProverConfig,\n type WCDProverConfig,\n type WCDFileSystem,\n type WCDCalculateWitnessFunction,\n type WCDGroth16ProveFunction,\n type WCDRapidsnarkProofResult,\n type WCDArtifacts,\n // Artifact management\n WCDArtifactManager,\n createWCDArtifactManager,\n storeWCDArtifacts,\n hasWCDArtifacts,\n getWCDPath,\n getZkeyPathForWCD,\n // WCD-only management (SDK handles zkey automatically)\n storeWCDOnly,\n hasWCDFile,\n // Utility functions\n wcdUint8ArrayToBase64,\n wcdBase64ToUint8Array,\n} from './wcd-prover';\n"]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RapidSnark Groth16 Integration for React Native
|
|
3
|
+
*
|
|
4
|
+
* This module provides a setRapidSnarkGroth16 function that mirrors the behavior
|
|
5
|
+
* of setSnarkJSGroth16 from dop-engine-v3, but uses rapidsnark for proof generation.
|
|
6
|
+
*
|
|
7
|
+
* Key differences from Node.js snarkjs:
|
|
8
|
+
* - Node.js: groth16.fullProve(inputs, wasmPath, zkeyPath) -> handles everything internally
|
|
9
|
+
* - Rapidsnark: groth16Prove(zkeyPath, witnessBase64) -> needs witness pre-calculated
|
|
10
|
+
*
|
|
11
|
+
* This module bridges the gap by:
|
|
12
|
+
* 1. Calculating witness from inputs using WASM
|
|
13
|
+
* 2. Saving zkey to device storage
|
|
14
|
+
* 3. Calling rapidsnark with zkeyPath and witnessBase64
|
|
15
|
+
*/
|
|
16
|
+
import { FormattedCircuitInputsDop } from 'dop-engine-v3';
|
|
17
|
+
export interface RapidsnarkProofResult {
|
|
18
|
+
proof: {
|
|
19
|
+
a: string[];
|
|
20
|
+
b: string[][];
|
|
21
|
+
c: string[];
|
|
22
|
+
};
|
|
23
|
+
pub_signals: string[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Witness calculator interface
|
|
27
|
+
* This should be provided by the mobile app using circom WASM
|
|
28
|
+
*/
|
|
29
|
+
export interface WitnessCalculator {
|
|
30
|
+
/**
|
|
31
|
+
* Calculate witness binary from circuit inputs
|
|
32
|
+
* @param wasmBuffer - Circuit WASM file content (Uint8Array or base64 string)
|
|
33
|
+
* @param inputs - Formatted circuit inputs
|
|
34
|
+
* @returns Witness binary as Uint8Array
|
|
35
|
+
*/
|
|
36
|
+
calculateWTNSBin(wasmBuffer: Uint8Array | string, inputs: FormattedCircuitInputsDop): Promise<Uint8Array>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* File system interface for React Native
|
|
40
|
+
* Should be implemented using react-native-fs or expo-file-system
|
|
41
|
+
*/
|
|
42
|
+
export interface FileSystemInterface {
|
|
43
|
+
/**
|
|
44
|
+
* Write binary data to a file
|
|
45
|
+
* @param path - Absolute file path
|
|
46
|
+
* @param data - Binary data to write (Uint8Array or base64 string)
|
|
47
|
+
*/
|
|
48
|
+
writeFile(path: string, data: Uint8Array | string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Read binary data from a file
|
|
51
|
+
* @param path - Absolute file path
|
|
52
|
+
* @returns Binary data as Uint8Array
|
|
53
|
+
*/
|
|
54
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a file exists
|
|
57
|
+
* @param path - Absolute file path
|
|
58
|
+
*/
|
|
59
|
+
exists(path: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Delete a file
|
|
62
|
+
* @param path - Absolute file path
|
|
63
|
+
*/
|
|
64
|
+
unlink(path: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the cache/temp directory path
|
|
67
|
+
*/
|
|
68
|
+
getCacheDirectory(): string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Rapidsnark groth16 prove function type
|
|
72
|
+
* Matches react-native-rapidsnark's groth16Prove signature
|
|
73
|
+
*/
|
|
74
|
+
export type Groth16ProveFunction = (zkeyPath: string, witnessBase64: string) => Promise<RapidsnarkProofResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Configuration for setRapidSnarkGroth16
|
|
77
|
+
*/
|
|
78
|
+
export interface RapidSnarkGroth16Config {
|
|
79
|
+
/**
|
|
80
|
+
* Rapidsnark's groth16Prove function
|
|
81
|
+
* Import from react-native-rapidsnark: import { groth16Prove } from 'react-native-rapidsnark'
|
|
82
|
+
*/
|
|
83
|
+
groth16Prove: Groth16ProveFunction;
|
|
84
|
+
/**
|
|
85
|
+
* Witness calculator implementation
|
|
86
|
+
* You can use circom_runtime or a custom implementation
|
|
87
|
+
*/
|
|
88
|
+
witnessCalculator: WitnessCalculator;
|
|
89
|
+
/**
|
|
90
|
+
* File system interface for React Native
|
|
91
|
+
* Use react-native-fs or expo-file-system
|
|
92
|
+
*/
|
|
93
|
+
fs: FileSystemInterface;
|
|
94
|
+
/**
|
|
95
|
+
* Optional: Custom directory for storing zkey files
|
|
96
|
+
* Defaults to fs.getCacheDirectory() + '/zkeys'
|
|
97
|
+
*/
|
|
98
|
+
zkeyStorageDir?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Optional: Whether to cache zkey files on device
|
|
101
|
+
* Defaults to true for better performance
|
|
102
|
+
*/
|
|
103
|
+
cacheZkeys?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Set up RapidSnark as the groth16 implementation for DOP Engine
|
|
107
|
+
*
|
|
108
|
+
* This function should be called after initDOP() and before any proof generation.
|
|
109
|
+
* It configures the DOP Engine to use rapidsnark for ZK proof generation on React Native.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { groth16Prove } from 'react-native-rapidsnark';
|
|
114
|
+
* import RNFS from 'react-native-fs';
|
|
115
|
+
* import { setRapidSnarkGroth16 } from 'new-dop-wallet-v3';
|
|
116
|
+
*
|
|
117
|
+
* // Create file system interface
|
|
118
|
+
* const fs: FileSystemInterface = {
|
|
119
|
+
* writeFile: async (path, data) => {
|
|
120
|
+
* if (data instanceof Uint8Array) {
|
|
121
|
+
* await RNFS.writeFile(path, uint8ArrayToBase64(data), 'base64');
|
|
122
|
+
* } else {
|
|
123
|
+
* await RNFS.writeFile(path, data, 'base64');
|
|
124
|
+
* }
|
|
125
|
+
* },
|
|
126
|
+
* readFile: async (path) => {
|
|
127
|
+
* const base64 = await RNFS.readFile(path, 'base64');
|
|
128
|
+
* return base64ToUint8Array(base64);
|
|
129
|
+
* },
|
|
130
|
+
* exists: RNFS.exists,
|
|
131
|
+
* unlink: RNFS.unlink,
|
|
132
|
+
* getCacheDirectory: () => RNFS.CachesDirectoryPath,
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* // Create witness calculator (using circom WASM)
|
|
136
|
+
* const witnessCalculator: WitnessCalculator = {
|
|
137
|
+
* calculateWTNSBin: async (wasmBuffer, inputs) => {
|
|
138
|
+
* // Use circom_runtime or similar
|
|
139
|
+
* const { WitnessCalculatorBuilder } = await import('circom_runtime');
|
|
140
|
+
* const wasmData = typeof wasmBuffer === 'string'
|
|
141
|
+
* ? base64ToUint8Array(wasmBuffer)
|
|
142
|
+
* : wasmBuffer;
|
|
143
|
+
* const wc = await WitnessCalculatorBuilder(wasmData);
|
|
144
|
+
* return await wc.calculateWTNSBin(inputs);
|
|
145
|
+
* },
|
|
146
|
+
* };
|
|
147
|
+
*
|
|
148
|
+
* // Initialize RapidSnark for DOP Engine
|
|
149
|
+
* await setRapidSnarkGroth16({
|
|
150
|
+
* groth16Prove,
|
|
151
|
+
* witnessCalculator,
|
|
152
|
+
* fs,
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare function setRapidSnarkGroth16(config: RapidSnarkGroth16Config): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Helper: Create a WitnessCalculator using circom_runtime
|
|
159
|
+
*
|
|
160
|
+
* This is a factory function that creates a WitnessCalculator
|
|
161
|
+
* using the WitnessCalculatorBuilder from circom_runtime.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // In React Native, you'll need to handle WASM loading differently
|
|
166
|
+
* const witnessCalculator = await createCircomWitnessCalculator();
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function createCircomWitnessCalculator(): WitnessCalculator;
|
|
170
|
+
/**
|
|
171
|
+
* Helper: Create a FileSystemInterface using react-native-fs
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* import RNFS from 'react-native-fs';
|
|
176
|
+
* const fs = createReactNativeFSInterface(RNFS);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function createReactNativeFSInterface(RNFS: {
|
|
180
|
+
writeFile: (path: string, content: string, encoding: string) => Promise<void>;
|
|
181
|
+
readFile: (path: string, encoding: string) => Promise<string>;
|
|
182
|
+
exists: (path: string) => Promise<boolean>;
|
|
183
|
+
unlink: (path: string) => Promise<void>;
|
|
184
|
+
CachesDirectoryPath: string;
|
|
185
|
+
mkdir: (path: string) => Promise<void>;
|
|
186
|
+
}): FileSystemInterface;
|
|
187
|
+
/**
|
|
188
|
+
* Helper: Create a FileSystemInterface using expo-file-system
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* import * as FileSystem from 'expo-file-system';
|
|
193
|
+
* const fs = createExpoFSInterface(FileSystem);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export declare function createExpoFSInterface(ExpoFS: {
|
|
197
|
+
writeAsStringAsync: (path: string, content: string, options?: {
|
|
198
|
+
encoding: string;
|
|
199
|
+
}) => Promise<void>;
|
|
200
|
+
readAsStringAsync: (path: string, options?: {
|
|
201
|
+
encoding: string;
|
|
202
|
+
}) => Promise<string>;
|
|
203
|
+
getInfoAsync: (path: string) => Promise<{
|
|
204
|
+
exists: boolean;
|
|
205
|
+
}>;
|
|
206
|
+
deleteAsync: (path: string) => Promise<void>;
|
|
207
|
+
cacheDirectory: string | null;
|
|
208
|
+
makeDirectoryAsync: (path: string, options?: {
|
|
209
|
+
intermediates: boolean;
|
|
210
|
+
}) => Promise<void>;
|
|
211
|
+
}): FileSystemInterface;
|