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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react-native-prover.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/react-native-prover.ts"],"names":[],"mappings":";AAAA,+BAA+B;AAC/B,gCAAgC;AAChC,yCAAyC;AACzC,8BAA8B;AAC9B,sDAAsD;AACtD,kEAAkE;AAClE;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,2CAA2C;AAyH3C,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,kBAAkB,CAAC,IAAgB;I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,YAAY,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAChD,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC;QACnB,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC;KACzB,CAAC,CAAC;IAEH,OAAO,OAAO,IAAI,YAAY,CAAC;AACjC,CAAC;AAfD,wCAeC;AAED,wDAAwD","sourcesContent":["/* eslint-disable no-bitwise */\n/* eslint-disable no-plusplus */\n/* eslint-disable max-classes-per-file */\n/* eslint-disable camelcase */\n/* eslint-disable import/no-extraneous-dependencies */\n/* eslint-disable @typescript-eslint/strict-boolean-expressions */\n/**\n * React Native Prover - Complete ZK Proof Solution\n * \n * This module provides a complete proof generation solution for React Native\n * that works exactly like snarkjs in Node.js:\n * \n * Node.js snarkjs flow:\n * 1. groth16.fullProve(inputs, wasmPath, zkeyPath)\n * 2. Internally: Load WASM -> Create WitnessCalculator -> Calculate witness -> Generate proof\n * \n * React Native rapidsnark flow (this module):\n * 1. setReactNativeProver(config) - Initialize with rapidsnark + file system\n * 2. DOP Engine calls groth16.fullProveDop(inputs, wasm, zkey)\n * 3. Internally: Calculate witness using WASM -> Save files -> Call rapidsnark -> Return proof\n * \n * Key components:\n * - CircuitArtifactManager: Downloads and stores circuit files (WASM, zkey) locally\n * - WitnessGenerator: Calculates witness from inputs using WASM (like circom_runtime)\n * - RapidsnarkProver: Generates proof using witness and zkey\n */\n\nimport { FormattedCircuitInputsDop, Proof, SnarkJSGroth16 } from 'dop-engine-v3';\nimport { getEngine } from '../core/engine';\n\n// ============================================================================\n// Types and Interfaces\n// ============================================================================\n\n/**\n * Result from rapidsnark groth16Prove\n */\nexport interface RNRapidsnarkProofResult {\n proof: {\n a: string[];\n b: string[][];\n c: string[];\n };\n pub_signals: string[];\n}\n\n/**\n * Rapidsnark's groth16Prove function signature\n * From: import { groth16Prove } from 'react-native-rapidsnark'\n */\nexport type RNGroth16ProveFunction = (\n zkeyPath: string,\n witnessBase64: string\n) => Promise<RNRapidsnarkProofResult>;\n\n/**\n * Rapidsnark's groth16ProveWithZKeyFilePath for file-based proving\n * Some versions of rapidsnark support this\n */\nexport type RNGroth16ProveWithFilesFunction = (\n zkeyPath: string,\n witnessPath: string\n) => Promise<RNRapidsnarkProofResult>;\n\n/**\n * File system interface for React Native\n * Implement using react-native-fs or expo-file-system\n */\nexport interface RNFileSystem {\n // File operations\n writeFile(path: string, data: string, encoding: 'base64' | 'utf8'): Promise<void>;\n readFile(path: string, encoding: 'base64' | 'utf8'): Promise<string>;\n exists(path: string): Promise<boolean>;\n unlink(path: string): Promise<void>;\n mkdir(path: string): Promise<void>;\n \n // Directory paths\n documentDirectory: string;\n cacheDirectory: string;\n}\n\n/**\n * Witness calculation result\n */\nexport interface WitnessResult {\n witnessBin: Uint8Array;\n witnessBase64: string;\n}\n\n/**\n * Rapidsnark's groth16Verify function signature\n * From: import { groth16Verify } from 'react-native-rapidsnark'\n */\nexport type RNGroth16VerifyFunction = (\n proof: string,\n inputs: string,\n verificationKey: string\n) => Promise<boolean>;\n\n/**\n * Circuit artifacts stored on device\n */\nexport interface StoredCircuitArtifacts {\n wasmPath: string;\n zkeyPath: string;\n vkeyPath: string;\n circuitId: string;\n}\n\n/**\n * Configuration for React Native Prover\n */\nexport interface ReactNativeProverConfig {\n /**\n * Rapidsnark's groth16Prove function\n * Import: import { groth16Prove } from 'react-native-rapidsnark'\n */\n groth16Prove: RNGroth16ProveFunction;\n \n /**\n * Optional: Rapidsnark's groth16Verify function for local proof verification\n * Import: import { groth16Verify } from 'react-native-rapidsnark'\n * If not provided, verification will throw an error\n */\n groth16Verify?: RNGroth16VerifyFunction;\n \n /**\n * File system interface (react-native-fs or expo-file-system)\n */\n fs: RNFileSystem;\n \n /**\n * Optional: Custom artifact storage directory\n * Default: fs.documentDirectory + '/dop-circuits'\n */\n artifactDir?: string;\n \n /**\n * Optional: Enable debug logging\n */\n debug?: boolean;\n \n /**\n * Optional: Custom witness calculator\n * If not provided, will use the built-in WASM-based calculator\n */\n witnessCalculator?: (wasmBuffer: Uint8Array, inputs: FormattedCircuitInputsDop) => Promise<Uint8Array>;\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Convert Uint8Array to base64 string (React Native compatible)\n */\nexport function uint8ArrayToBase64(data: Uint8Array): string {\n // Use Buffer if available (Node.js/React Native with buffer polyfill)\n if (typeof Buffer !== 'undefined') {\n return Buffer.from(data).toString('base64');\n }\n \n // Fallback for pure JS environments\n let binary = '';\n const len = data.byteLength;\n for (let i = 0; i < len; i++) {\n binary += String.fromCharCode(data[i]);\n }\n return btoa(binary);\n}\n\n/**\n * Convert base64 string to Uint8Array (React Native compatible)\n */\nexport function base64ToUint8Array(base64: string): Uint8Array {\n // Use Buffer if available\n if (typeof Buffer !== 'undefined') {\n return new Uint8Array(Buffer.from(base64, 'base64'));\n }\n \n // Fallback for pure JS environments\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i);\n }\n return bytes;\n}\n\n/**\n * Get circuit ID from formatted inputs\n * DOP circuits are named like \"3x2\" (3 nullifiers, 2 commitments)\n */\nfunction getCircuitIdFromInputs(inputs: FormattedCircuitInputsDop): string {\n const nullifierCount = inputs.nullifiers?.filter(\n (n: bigint | string) => n !== undefined && n !== null && BigInt(n) !== BigInt(0)\n ).length || 0;\n \n const commitmentCount = inputs.commitmentsOut?.filter(\n (c: bigint | string) => c !== undefined && c !== null && BigInt(c) !== BigInt(0)\n ).length || 0;\n \n return `${nullifierCount}x${commitmentCount}`;\n}\n\n// ============================================================================\n// Witness Calculator (WASM-based, like circom_runtime)\n// ============================================================================\n\n/**\n * The BN128 prime field used in Groth16\n */\nconst BN128_PRIME = BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617');\n\n/**\n * FNV-1a hash function for signal names (same as circom_runtime)\n */\nfunction fnvHash(str: string): bigint {\n const FNV_OFFSET = BigInt('0xCBF29CE484222325');\n const FNV_PRIME = BigInt('0x100000001B3');\n \n let hash = FNV_OFFSET;\n for (let i = 0; i < str.length; i++) {\n hash ^= BigInt(str.charCodeAt(i));\n hash = (hash * FNV_PRIME) % (BigInt(1) << BigInt(64));\n }\n return hash;\n}\n\n/**\n * Convert bigint to 32-bit array (little-endian, like circom_runtime)\n */\nfunction toArray32(num: bigint, size: number): Uint32Array {\n const result = new Uint32Array(size);\n let temp = num;\n for (let i = 0; i < size; i++) {\n result[i] = Number(temp & BigInt(0xFFFFFFFF));\n temp >>= BigInt(32);\n }\n return result;\n}\n\n/**\n * Normalize value to prime field (like circom_runtime)\n */\nfunction normalizeToField(value: bigint | string | number): bigint {\n let num: bigint;\n \n if (typeof value === 'bigint') {\n num = value;\n } else if (typeof value === 'string') {\n // Handle hex strings\n if (value.startsWith('0x')) {\n num = BigInt(value);\n } else {\n num = BigInt(value);\n }\n } else {\n num = BigInt(value);\n }\n \n // Normalize to prime field\n num %= BN128_PRIME;\n if (num < BigInt(0)) {\n num += BN128_PRIME;\n }\n \n return num;\n}\n\n/**\n * Flatten nested arrays (like circom_runtime)\n */\nfunction flatArray(arr: unknown): bigint[] {\n const result: bigint[] = [];\n \n function flatten(item: unknown): void {\n if (Array.isArray(item)) {\n for (const subItem of item) {\n flatten(subItem);\n }\n } else if (typeof item === 'bigint' || typeof item === 'string' || typeof item === 'number') {\n result.push(normalizeToField(item));\n }\n }\n \n flatten(arr);\n return result;\n}\n\n/**\n * Create WTNS (witness) binary format\n * This matches the format expected by rapidsnark\n * \n * WTNS format:\n * - 4 bytes: \"wtns\" magic\n * - 4 bytes: version (2)\n * - 4 bytes: number of sections\n * - Section 1 (header): field info\n * - Section 2 (data): witness values\n */\nfunction createWTNSBin(witness: bigint[]): Uint8Array {\n const n8 = 32; // 32 bytes per field element (256 bits)\n const witnessSize = witness.length;\n \n // Calculate total size\n // Header: magic(4) + version(4) + numSections(4) = 12\n // Section 1 header: sectionType(4) + sectionSize(8) = 12\n // Section 1 data: n8(4) + prime(n8) + witnessSize(4) = 4 + 32 + 4 = 40\n // Section 2 header: sectionType(4) + sectionSize(8) = 12\n // Section 2 data: witness values = witnessSize * n8\n const section1Size = 4 + n8 + 4; // n8 size + prime + witness count\n const section2Size = witnessSize * n8;\n const totalSize = 12 + 12 + section1Size + 12 + section2Size;\n \n const buffer = new ArrayBuffer(totalSize);\n const view = new DataView(buffer);\n const uint8 = new Uint8Array(buffer);\n \n let offset = 0;\n \n // Magic \"wtns\"\n uint8[offset++] = 0x77; // 'w'\n uint8[offset++] = 0x74; // 't'\n uint8[offset++] = 0x6e; // 'n'\n uint8[offset++] = 0x73; // 's'\n \n // Version (2)\n view.setUint32(offset, 2, true);\n offset += 4;\n \n // Number of sections (2)\n view.setUint32(offset, 2, true);\n offset += 4;\n \n // Section 1: Header\n view.setUint32(offset, 1, true); // section type\n offset += 4;\n // Section size as 64-bit\n view.setUint32(offset, section1Size, true);\n offset += 4;\n view.setUint32(offset, 0, true);\n offset += 4;\n \n // n8 (field element size in bytes)\n view.setUint32(offset, n8, true);\n offset += 4;\n \n // Prime (BN128 prime, little-endian)\n const primeArray = toArray32(BN128_PRIME, 8);\n for (let i = 0; i < 8; i++) {\n view.setUint32(offset, primeArray[i], true);\n offset += 4;\n }\n \n // Witness size\n view.setUint32(offset, witnessSize, true);\n offset += 4;\n \n // Section 2: Data (witness values)\n view.setUint32(offset, 2, true); // section type\n offset += 4;\n // Section size as 64-bit\n view.setUint32(offset, section2Size, true);\n offset += 4;\n view.setUint32(offset, 0, true);\n offset += 4;\n \n // Write witness values (each as 32-byte little-endian)\n for (const w of witness) {\n const wArray = toArray32(w, 8);\n for (let i = 0; i < 8; i++) {\n view.setUint32(offset, wArray[i], true);\n offset += 4;\n }\n }\n \n return uint8;\n}\n\n/**\n * Calculate witness using WASM\n * This is the core function that mimics circom_runtime's WitnessCalculator\n * \n * For React Native, the WASM execution needs special handling.\n * This function provides the interface - the actual WASM execution\n * should be done by a native module or WebAssembly polyfill.\n */\nexport async function calculateWitnessFromWASM(\n wasmBuffer: Uint8Array,\n inputs: FormattedCircuitInputsDop,\n wasmExecutor?: (wasm: Uint8Array, inputs: Record<string, unknown>) => Promise<bigint[]>\n): Promise<WitnessResult> {\n let witness: bigint[];\n \n if (wasmExecutor) {\n // Use provided WASM executor\n witness = await wasmExecutor(wasmBuffer, inputs as unknown as Record<string, unknown>);\n } else {\n // Try to use circom_runtime if available\n try {\n const circomRuntime = await import('circom_runtime');\n const witnessCalculator = await circomRuntime.WitnessCalculatorBuilder(wasmBuffer);\n const witnessBin = await witnessCalculator.calculateWTNSBin(inputs);\n \n // Return directly as it's already in WTNS format\n return {\n witnessBin: new Uint8Array(witnessBin),\n witnessBase64: uint8ArrayToBase64(new Uint8Array(witnessBin)),\n };\n } catch {\n throw new Error(\n 'WASM execution not available. Please provide a wasmExecutor or ensure circom_runtime is available.'\n );\n }\n }\n \n // Create WTNS binary from witness array\n const witnessBin = createWTNSBin(witness);\n \n return {\n witnessBin,\n witnessBase64: uint8ArrayToBase64(witnessBin),\n };\n}\n\n// ============================================================================\n// Circuit Artifact Manager\n// ============================================================================\n\n/**\n * Manages circuit artifacts (WASM, zkey, vkey) on the device\n */\nexport class CircuitArtifactManager {\n private fs: RNFileSystem;\n private artifactDir: string;\n private debug: boolean;\n \n constructor(fs: RNFileSystem, artifactDir?: string, debug = false) {\n this.fs = fs;\n this.artifactDir = artifactDir || `${fs.documentDirectory}/dop-circuits`;\n this.debug = debug;\n }\n \n private log(message: string): void {\n if (this.debug) {\n console.log(`[CircuitArtifactManager] ${message}`);\n }\n }\n \n /**\n * Ensure artifact directory exists\n */\n async ensureDir(dir: string): Promise<void> {\n try {\n if (!(await this.fs.exists(dir))) {\n await this.fs.mkdir(dir);\n this.log(`Created directory: ${dir}`);\n }\n } catch {\n // Directory might already exist\n }\n }\n \n /**\n * Get paths for circuit artifacts\n */\n getArtifactPaths(circuitId: string): StoredCircuitArtifacts {\n const circuitDir = `${this.artifactDir}/${circuitId}`;\n return {\n wasmPath: `${circuitDir}/circuit.wasm`,\n zkeyPath: `${circuitDir}/circuit.zkey`,\n vkeyPath: `${circuitDir}/vkey.json`,\n circuitId,\n };\n }\n \n /**\n * Check if circuit artifacts are already stored\n */\n async hasArtifacts(circuitId: string): Promise<boolean> {\n const paths = this.getArtifactPaths(circuitId);\n const [hasWasm, hasZkey] = await Promise.all([\n this.fs.exists(paths.wasmPath),\n this.fs.exists(paths.zkeyPath),\n ]);\n return hasWasm && hasZkey;\n }\n \n /**\n * Store circuit artifacts from buffers\n * Call this after downloading artifacts\n */\n async storeArtifacts(\n circuitId: string,\n wasmBuffer: Uint8Array,\n zkeyBuffer: Uint8Array,\n vkeyJson?: object\n ): Promise<StoredCircuitArtifacts> {\n const paths = this.getArtifactPaths(circuitId);\n const circuitDir = `${this.artifactDir}/${circuitId}`;\n \n await this.ensureDir(this.artifactDir);\n await this.ensureDir(circuitDir);\n \n this.log(`Storing artifacts for circuit ${circuitId}`);\n \n // Store WASM\n await this.fs.writeFile(paths.wasmPath, uint8ArrayToBase64(wasmBuffer), 'base64');\n this.log(`Stored WASM: ${paths.wasmPath} (${wasmBuffer.byteLength} bytes)`);\n \n // Store zkey\n await this.fs.writeFile(paths.zkeyPath, uint8ArrayToBase64(zkeyBuffer), 'base64');\n this.log(`Stored zkey: ${paths.zkeyPath} (${zkeyBuffer.byteLength} bytes)`);\n \n // Store vkey if provided\n if (vkeyJson) {\n await this.fs.writeFile(paths.vkeyPath, JSON.stringify(vkeyJson), 'utf8');\n this.log(`Stored vkey: ${paths.vkeyPath}`);\n }\n \n return paths;\n }\n \n /**\n * Store artifacts from the DOP Engine's artifact getter\n * This is called during proof generation when we receive buffers from the engine\n */\n async storeArtifactsFromBuffers(\n circuitId: string,\n wasmOrDat: Uint8Array | ArrayLike<number>,\n zkey: ArrayLike<number>\n ): Promise<StoredCircuitArtifacts> {\n const wasmBuffer = wasmOrDat instanceof Uint8Array \n ? wasmOrDat \n : new Uint8Array(wasmOrDat);\n const zkeyBuffer = new Uint8Array(zkey);\n \n return this.storeArtifacts(circuitId, wasmBuffer, zkeyBuffer);\n }\n \n /**\n * Load WASM buffer from stored file\n */\n async loadWASM(circuitId: string): Promise<Uint8Array> {\n const paths = this.getArtifactPaths(circuitId);\n const base64 = await this.fs.readFile(paths.wasmPath, 'base64');\n return base64ToUint8Array(base64);\n }\n \n /**\n * Get zkey path for rapidsnark\n */\n getZkeyPath(circuitId: string): string {\n return this.getArtifactPaths(circuitId).zkeyPath;\n }\n \n /**\n * Clean up artifacts for a circuit\n */\n async removeArtifacts(circuitId: string): Promise<void> {\n const paths = this.getArtifactPaths(circuitId);\n \n try {\n await this.fs.unlink(paths.wasmPath);\n } catch { /* ignore */ }\n \n try {\n await this.fs.unlink(paths.zkeyPath);\n } catch { /* ignore */ }\n \n try {\n await this.fs.unlink(paths.vkeyPath);\n } catch { /* ignore */ }\n \n this.log(`Removed artifacts for circuit ${circuitId}`);\n }\n \n /**\n * Get all stored circuit IDs\n */\n getArtifactDirectory(): string {\n return this.artifactDir;\n }\n}\n\n// ============================================================================\n// React Native Prover\n// ============================================================================\n\n/**\n * React Native Prover Instance\n * Manages the complete proof generation flow\n */\nclass ReactNativeProverInstance {\n private config: ReactNativeProverConfig;\n private artifactManager: CircuitArtifactManager;\n private initialized = false;\n \n constructor(config: ReactNativeProverConfig) {\n this.config = config;\n this.artifactManager = new CircuitArtifactManager(\n config.fs,\n config.artifactDir,\n config.debug\n );\n }\n \n private log(message: string): void {\n if (this.config.debug) {\n console.log(`[ReactNativeProver] ${message}`);\n }\n }\n \n /**\n * Initialize the prover (ensure directories exist)\n */\n async initialize(): Promise<void> {\n if (this.initialized) return;\n \n await this.artifactManager.ensureDir(\n this.config.artifactDir || `${this.config.fs.documentDirectory}/dop-circuits`\n );\n \n this.initialized = true;\n this.log('Initialized');\n }\n \n /**\n * Generate proof using rapidsnark\n * This is the main function that mimics snarkjs.groth16.fullProve\n */\n async generateProof(\n inputs: FormattedCircuitInputsDop,\n wasmBuffer: Uint8Array | ArrayLike<number>,\n zkeyBuffer: ArrayLike<number>,\n logger: { debug: (log: string) => void },\n progressCallback?: (progress: number) => void\n ): Promise<{ proof: Proof; publicSignals: string[] }> {\n await this.initialize();\n \n const circuitId = getCircuitIdFromInputs(inputs);\n this.log(`Generating proof for circuit ${circuitId}`);\n \n progressCallback?.(5);\n \n // Step 1: Store artifacts on device (if not already stored)\n logger.debug(`[RN Prover] Step 1: Preparing artifacts for circuit ${circuitId}...`);\n \n const wasm = wasmBuffer instanceof Uint8Array \n ? wasmBuffer \n : new Uint8Array(wasmBuffer);\n \n const artifacts = await this.artifactManager.storeArtifactsFromBuffers(\n circuitId,\n wasm,\n zkeyBuffer\n );\n \n this.log(`Artifacts stored at: ${artifacts.zkeyPath}`);\n progressCallback?.(20);\n \n // Step 2: Calculate witness from inputs\n logger.debug('[RN Prover] Step 2: Calculating witness...');\n \n let witnessResult: WitnessResult;\n \n if (this.config.witnessCalculator) {\n // Use custom witness calculator\n const witnessBin = await this.config.witnessCalculator(wasm, inputs);\n witnessResult = {\n witnessBin,\n witnessBase64: uint8ArrayToBase64(witnessBin),\n };\n } else {\n // Use built-in WASM-based calculator\n witnessResult = await calculateWitnessFromWASM(wasm, inputs);\n }\n \n this.log(`Witness calculated: ${witnessResult.witnessBin.byteLength} bytes`);\n progressCallback?.(50);\n \n // Step 3: Generate proof with rapidsnark\n logger.debug('[RN Prover] Step 3: Generating proof with rapidsnark...');\n \n const rapidsnarkResult = await this.config.groth16Prove(\n artifacts.zkeyPath,\n witnessResult.witnessBase64\n );\n \n this.log('Proof generated successfully');\n progressCallback?.(90);\n \n // Step 4: Convert to DOP Engine format\n const proof: Proof = {\n pi_a: [rapidsnarkResult.proof.a[0], rapidsnarkResult.proof.a[1]],\n pi_b: [\n [rapidsnarkResult.proof.b[0][0], rapidsnarkResult.proof.b[0][1]],\n [rapidsnarkResult.proof.b[1][0], rapidsnarkResult.proof.b[1][1]],\n ],\n pi_c: [rapidsnarkResult.proof.c[0], rapidsnarkResult.proof.c[1]],\n };\n \n progressCallback?.(100);\n \n return {\n proof,\n publicSignals: rapidsnarkResult.pub_signals,\n };\n }\n \n /**\n * Get the artifact manager for manual artifact management\n */\n getArtifactManager(): CircuitArtifactManager {\n return this.artifactManager;\n }\n}\n\n// ============================================================================\n// Main Export: setReactNativeProver\n// ============================================================================\n\nlet globalReactNativeProver: ReactNativeProverInstance | null = null;\n\n/**\n * Set up React Native prover for DOP Engine\n * \n * This function configures the DOP Engine to use rapidsnark for proof generation\n * on React Native. It works exactly like setSnarkJSGroth16 but uses rapidsnark\n * under the hood.\n * \n * @example\n * ```typescript\n * import { groth16Prove } from 'react-native-rapidsnark';\n * import RNFS from 'react-native-fs';\n * import { setReactNativeProver } from 'new-dop-wallet-v3';\n * \n * // Create file system interface for react-native-fs\n * const fs: RNFileSystem = {\n * writeFile: (path, data, encoding) => RNFS.writeFile(path, data, encoding),\n * readFile: (path, encoding) => RNFS.readFile(path, encoding),\n * exists: RNFS.exists,\n * unlink: RNFS.unlink,\n * mkdir: RNFS.mkdir,\n * documentDirectory: RNFS.DocumentDirectoryPath,\n * cacheDirectory: RNFS.CachesDirectoryPath,\n * };\n * \n * // Initialize React Native prover (call after initDOP)\n * await setReactNativeProver({\n * groth16Prove,\n * fs,\n * debug: true,\n * });\n * \n * // Now all DOP SDK transactions will use rapidsnark automatically!\n * ```\n */\nexport async function setReactNativeProver(config: ReactNativeProverConfig): Promise<void> {\n const engine = getEngine();\n \n if (!engine) {\n throw new Error('DOP Engine not initialized. Call initDOP() first.');\n }\n \n // Create prover instance\n globalReactNativeProver = new ReactNativeProverInstance(config);\n await globalReactNativeProver.initialize();\n \n console.log('[RN Prover] Setting up React Native prover with rapidsnark');\n \n // Create groth16 implementation\n const reactNativeGroth16 = {\n fullProve: async (\n inputs: FormattedCircuitInputsDop,\n wasm: ArrayLike<number> | undefined,\n zkey: ArrayLike<number>,\n logger: { debug: (log: string) => void }\n ): Promise<{ proof: Proof; publicSignals: string[] }> => {\n if (!globalReactNativeProver) {\n throw new Error('React Native prover not initialized');\n }\n \n if (!wasm) {\n throw new Error('WASM buffer is required for proof generation');\n }\n \n return globalReactNativeProver.generateProof(\n inputs,\n wasm,\n zkey,\n logger,\n undefined\n );\n },\n \n /**\n * Verify a proof using rapidsnark's groth16Verify\n * This works like snarkjs.groth16.verify in Node.js\n */\n verify: async (\n vkey: object,\n publicSignals: string[],\n proof: Proof\n ): Promise<boolean> => {\n // Check if groth16Verify was provided in config\n if (!config.groth16Verify) {\n console.warn('[RN Prover] groth16Verify not provided in config. Cannot verify proof locally.');\n throw new Error(\n 'Proof verification requires groth16Verify function. ' +\n 'Pass groth16Verify from react-native-rapidsnark in setReactNativeProver config.'\n );\n }\n \n try {\n // Convert proof to rapidsnark format\n // rapidsnark expects: proof as JSON string, inputs as JSON string, vkey as JSON string\n const rapidsnarkProof = {\n pi_a: proof.pi_a,\n pi_b: proof.pi_b,\n pi_c: proof.pi_c,\n protocol: 'groth16',\n curve: 'bn128',\n };\n \n const proofJson = JSON.stringify(rapidsnarkProof);\n const inputsJson = JSON.stringify(publicSignals);\n const vkeyJson = JSON.stringify(vkey);\n \n const isValid = await config.groth16Verify(proofJson, inputsJson, vkeyJson);\n \n console.log('[RN Prover] Proof verification result:', isValid);\n return isValid;\n \n } catch (error) {\n console.error('[RN Prover] Proof verification failed:', error);\n throw error;\n }\n },\n };\n \n // Set on engine\n engine.prover.setSnarkJSGroth16(reactNativeGroth16 as unknown as SnarkJSGroth16);\n \n console.log('[RN Prover] React Native prover configured successfully');\n}\n\n/**\n * Get the global React Native prover instance\n * Useful for accessing the artifact manager directly\n */\nexport function getReactNativeProver(): ReactNativeProverInstance | null {\n return globalReactNativeProver;\n}\n\n// ============================================================================\n// Helper: Create file system interfaces\n// ============================================================================\n\n/**\n * Create RNFileSystem from react-native-fs (RNFS)\n * \n * @example\n * ```typescript\n * import RNFS from 'react-native-fs';\n * const fs = createRNFSInterface(RNFS);\n * ```\n */\nexport function createRNFSInterface(RNFS: {\n writeFile: (path: string, content: 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 mkdir: (path: string, options?: object) => Promise<void>;\n DocumentDirectoryPath: string;\n CachesDirectoryPath: string;\n}): RNFileSystem {\n return {\n writeFile: (path, data, encoding) => RNFS.writeFile(path, data, encoding),\n readFile: (path, encoding) => RNFS.readFile(path, encoding),\n exists: RNFS.exists,\n unlink: RNFS.unlink,\n mkdir: (path) => RNFS.mkdir(path, { NSURLIsExcludedFromBackupKey: true }),\n documentDirectory: RNFS.DocumentDirectoryPath,\n cacheDirectory: RNFS.CachesDirectoryPath,\n };\n}\n\n/**\n * Create RNFileSystem from expo-file-system\n * \n * @example\n * ```typescript\n * import * as FileSystem from 'expo-file-system';\n * const fs = createExpoFSInterface(FileSystem);\n * ```\n */\nexport function createExpoFSInterface(ExpoFS: {\n writeAsStringAsync: (path: string, content: string, options?: { encoding: string }) => Promise<void>;\n readAsStringAsync: (path: string, options?: { encoding: string }) => Promise<string>;\n getInfoAsync: (path: string) => Promise<{ exists: boolean }>;\n deleteAsync: (path: string, options?: { idempotent: boolean }) => Promise<void>;\n makeDirectoryAsync: (path: string, options?: { intermediates: boolean }) => Promise<void>;\n documentDirectory: string | null;\n cacheDirectory: string | null;\n}): RNFileSystem {\n const docDir = ExpoFS.documentDirectory || '';\n const cacheDir = ExpoFS.cacheDirectory || '';\n \n return {\n writeFile: async (path, data, encoding) => {\n const options = encoding === 'base64' \n ? { encoding: 'base64' as const }\n : { encoding: 'utf8' as const };\n await ExpoFS.writeAsStringAsync(path, data, options);\n },\n \n readFile: async (path, encoding) => {\n const options = encoding === 'base64'\n ? { encoding: 'base64' as const }\n : { encoding: 'utf8' as const };\n return ExpoFS.readAsStringAsync(path, options);\n },\n \n exists: async (path) => {\n const info = await ExpoFS.getInfoAsync(path);\n return info.exists;\n },\n \n unlink: (path) => ExpoFS.deleteAsync(path, { idempotent: true }),\n \n mkdir: (path) => ExpoFS.makeDirectoryAsync(path, { intermediates: true }),\n \n documentDirectory: docDir,\n cacheDirectory: cacheDir,\n };\n}\n\n// ============================================================================\n// React Native Artifact Store - For SDK Integration\n// ============================================================================\n\n/**\n * ArtifactStore type matching the SDK's artifact-store.ts\n */\nexport interface RNArtifactStore {\n get: (path: string) => Promise<string | Buffer | null>;\n store: (dir: string, path: string, item: string | Uint8Array) => Promise<void>;\n exists: (path: string) => Promise<boolean>;\n}\n\n/**\n * Create an ArtifactStore for React Native that stores files to device storage\n * \n * This allows the SDK's ArtifactDownloader to automatically save artifacts\n * to a location that rapidsnark can access by file path.\n * \n * Use this when initializing the DOP Engine to make artifacts available for rapidsnark.\n * \n * @example\n * ```typescript\n * import RNFS from 'react-native-fs';\n * import { createRNArtifactStore, createRNFSInterface } from 'new-dop-wallet-v3';\n * \n * const fs = createRNFSInterface(RNFS);\n * const artifactStore = createRNArtifactStore(fs);\n * \n * // Pass to ArtifactDownloader when initializing DOP Engine\n * const artifactDownloader = new ArtifactDownloader(artifactStore, false);\n * ```\n */\nexport function createRNArtifactStore(\n fs: RNFileSystem,\n baseDir?: string\n): RNArtifactStore {\n const artifactBaseDir = baseDir || `${fs.documentDirectory}/dop-artifacts`;\n \n // Ensure base directory exists\n const ensureBaseDir = async (): Promise<void> => {\n try {\n if (!(await fs.exists(artifactBaseDir))) {\n await fs.mkdir(artifactBaseDir);\n }\n } catch {\n // Directory might already exist\n }\n };\n \n return {\n /**\n * Get artifact content from device storage\n */\n get: async (path: string): Promise<string | Buffer | null> => {\n const fullPath = `${artifactBaseDir}/${path}`;\n \n try {\n if (!(await fs.exists(fullPath))) {\n return null;\n }\n \n // Check if it's a JSON file (vkey)\n if (path.endsWith('.json')) {\n const content = await fs.readFile(fullPath, 'utf8');\n return content;\n }\n \n // Binary file (zkey, wasm, dat)\n const base64 = await fs.readFile(fullPath, 'base64');\n return Buffer.from(base64, 'base64');\n \n } catch {\n return null;\n }\n },\n \n /**\n * Store artifact to device storage\n * This is called by SDK's ArtifactDownloader after downloading\n */\n store: async (dir: string, path: string, item: string | Uint8Array): Promise<void> => {\n await ensureBaseDir();\n \n const fullDir = `${artifactBaseDir}/${dir}`;\n const fullPath = `${artifactBaseDir}/${path}`;\n \n // Ensure directory exists\n try {\n if (!(await fs.exists(fullDir))) {\n await fs.mkdir(fullDir);\n }\n } catch {\n // Directory might already exist\n }\n \n // Store the artifact\n if (typeof item === 'string') {\n // JSON string (vkey)\n await fs.writeFile(fullPath, item, 'utf8');\n } else {\n // Binary data (zkey, wasm, dat)\n const base64 = uint8ArrayToBase64(item);\n await fs.writeFile(fullPath, base64, 'base64');\n }\n \n console.log(`[RN ArtifactStore] Stored artifact: ${path}`);\n },\n \n /**\n * Check if artifact exists on device\n */\n exists: async (path: string): Promise<boolean> => {\n const fullPath = `${artifactBaseDir}/${path}`;\n return fs.exists(fullPath);\n },\n };\n}\n\n/**\n * Get the full file path for an artifact stored via RNArtifactStore\n * \n * Use this to get the path for rapidsnark's groth16Prove function\n * \n * @example\n * ```typescript\n * const zkeyPath = getRNArtifactPath(fs, '3x2', 'zkey');\n * const proofResult = await groth16Prove(zkeyPath, witnessBase64);\n * ```\n */\nexport function getRNArtifactPath(\n fs: RNFileSystem,\n circuitId: string,\n artifactType: 'zkey' | 'wasm' | 'vkey' | 'dat',\n baseDir?: string\n): string {\n const artifactBaseDir = baseDir || `${fs.documentDirectory}/dop-artifacts`;\n const artifactDir = `artifacts-v2.1/${circuitId}`;\n \n switch (artifactType) {\n case 'zkey':\n return `${artifactBaseDir}/${artifactDir}/zkey`;\n case 'wasm':\n return `${artifactBaseDir}/${artifactDir}/wasm`;\n case 'vkey':\n return `${artifactBaseDir}/${artifactDir}/vkey.json`;\n case 'dat':\n return `${artifactBaseDir}/${artifactDir}/dat`;\n }\n}\n\n/**\n * Check if all artifacts for a circuit are downloaded\n */\nexport async function hasRNArtifacts(\n fs: RNFileSystem,\n circuitId: string,\n baseDir?: string,\n useNativeArtifacts = false\n): Promise<boolean> {\n const zkeyPath = getRNArtifactPath(fs, circuitId, 'zkey', baseDir);\n const wasmOrDatPath = getRNArtifactPath(fs, circuitId, useNativeArtifacts ? 'dat' : 'wasm', baseDir);\n \n const [hasZkey, hasWasmOrDat] = await Promise.all([\n fs.exists(zkeyPath),\n fs.exists(wasmOrDatPath),\n ]);\n \n return hasZkey && hasWasmOrDat;\n}\n\n// Types and classes are exported where they are defined\n\n"]}
|
|
@@ -38,20 +38,21 @@ let rapidsnarkModule = null;
|
|
|
38
38
|
const initializeRapidsnark = async () => {
|
|
39
39
|
var _a;
|
|
40
40
|
if (!runtime_1.isReactNative) {
|
|
41
|
-
console.log('
|
|
41
|
+
console.log('[Rapidsnark] Not in React Native environment, skipping rapidsnark initialization');
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
44
|
try {
|
|
45
|
-
console.log('
|
|
45
|
+
console.log('[Rapidsnark] Initializing rapidsnark for React Native...');
|
|
46
46
|
// Dynamic import with try-catch for optional dependency
|
|
47
47
|
let rapidsnarkImport;
|
|
48
48
|
try {
|
|
49
49
|
// Use string literal to avoid TypeScript compilation errors when module is not installed
|
|
50
|
-
|
|
50
|
+
// The actual package name is 'react-native-rapidsnark' (not @iden3/react-native-rapidsnark)
|
|
51
|
+
const moduleName = 'react-native-rapidsnark';
|
|
51
52
|
rapidsnarkImport = await (_a = moduleName, Promise.resolve().then(() => __importStar(require(_a))));
|
|
52
53
|
}
|
|
53
54
|
catch (importError) {
|
|
54
|
-
console.log('
|
|
55
|
+
console.log('[Rapidsnark] react-native-rapidsnark not available:', String(importError));
|
|
55
56
|
return false;
|
|
56
57
|
}
|
|
57
58
|
const { groth16Prove, groth16Verify, groth16PublicBufferSize } = rapidsnarkImport;
|
|
@@ -60,12 +61,12 @@ const initializeRapidsnark = async () => {
|
|
|
60
61
|
groth16Verify,
|
|
61
62
|
groth16PublicBufferSize
|
|
62
63
|
};
|
|
63
|
-
console.log('
|
|
64
|
+
console.log('[Rapidsnark] Rapidsnark initialized successfully');
|
|
64
65
|
return true;
|
|
65
66
|
}
|
|
66
67
|
catch (error) {
|
|
67
|
-
console.warn('
|
|
68
|
-
console.log('
|
|
68
|
+
console.warn('[Rapidsnark] Rapidsnark not available:', error);
|
|
69
|
+
console.log('[Rapidsnark] Install react-native-rapidsnark for React Native proof generation');
|
|
69
70
|
return false;
|
|
70
71
|
}
|
|
71
72
|
};
|
|
@@ -82,19 +83,19 @@ exports.isRapidsnarkAvailable = isRapidsnarkAvailable;
|
|
|
82
83
|
*/
|
|
83
84
|
const generateProofWithRapidsnark = async (zkeyPath, witnessBase64) => {
|
|
84
85
|
if (!(0, exports.isRapidsnarkAvailable)()) {
|
|
85
|
-
throw new Error('Rapidsnark is not available. Please ensure
|
|
86
|
+
throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');
|
|
86
87
|
}
|
|
87
88
|
try {
|
|
88
|
-
console.log('
|
|
89
|
+
console.log('[Rapidsnark] Generating proof with rapidsnark...');
|
|
89
90
|
if (!rapidsnarkModule) {
|
|
90
91
|
throw new Error('Rapidsnark module not initialized');
|
|
91
92
|
}
|
|
92
93
|
const proof = await rapidsnarkModule.groth16Prove(zkeyPath, witnessBase64);
|
|
93
|
-
console.log('
|
|
94
|
+
console.log('[Rapidsnark] Proof generated successfully with rapidsnark');
|
|
94
95
|
return proof;
|
|
95
96
|
}
|
|
96
97
|
catch (error) {
|
|
97
|
-
console.error('
|
|
98
|
+
console.error('[Rapidsnark] Rapidsnark proof generation failed:', String(error));
|
|
98
99
|
throw new Error(`Rapidsnark proof generation failed: ${String(error)}`);
|
|
99
100
|
}
|
|
100
101
|
};
|
|
@@ -104,19 +105,19 @@ exports.generateProofWithRapidsnark = generateProofWithRapidsnark;
|
|
|
104
105
|
*/
|
|
105
106
|
const verifyProofWithRapidsnark = async (proof, publicSignals, verificationKeyBase64) => {
|
|
106
107
|
if (!(0, exports.isRapidsnarkAvailable)()) {
|
|
107
|
-
throw new Error('Rapidsnark is not available. Please ensure
|
|
108
|
+
throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');
|
|
108
109
|
}
|
|
109
110
|
try {
|
|
110
|
-
console.log('
|
|
111
|
+
console.log('[Rapidsnark] Verifying proof with rapidsnark...');
|
|
111
112
|
if (!rapidsnarkModule) {
|
|
112
113
|
throw new Error('Rapidsnark module not initialized');
|
|
113
114
|
}
|
|
114
115
|
const isValid = rapidsnarkModule.groth16Verify(proof, publicSignals, verificationKeyBase64);
|
|
115
|
-
console.log('
|
|
116
|
+
console.log('[Rapidsnark] Proof verification completed:', isValid);
|
|
116
117
|
return isValid;
|
|
117
118
|
}
|
|
118
119
|
catch (error) {
|
|
119
|
-
console.error('
|
|
120
|
+
console.error('[Rapidsnark] Rapidsnark proof verification failed:', String(error));
|
|
120
121
|
throw new Error(`Rapidsnark proof verification failed: ${String(error)}`);
|
|
121
122
|
}
|
|
122
123
|
};
|
|
@@ -126,18 +127,18 @@ exports.verifyProofWithRapidsnark = verifyProofWithRapidsnark;
|
|
|
126
127
|
*/
|
|
127
128
|
const getPublicBufferSize = async (zkeyPath) => {
|
|
128
129
|
if (!(0, exports.isRapidsnarkAvailable)()) {
|
|
129
|
-
throw new Error('Rapidsnark is not available. Please ensure
|
|
130
|
+
throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');
|
|
130
131
|
}
|
|
131
132
|
try {
|
|
132
133
|
if (!rapidsnarkModule) {
|
|
133
134
|
throw new Error('Rapidsnark module not initialized');
|
|
134
135
|
}
|
|
135
136
|
const bufferSize = await rapidsnarkModule.groth16PublicBufferSize(zkeyPath);
|
|
136
|
-
console.log('
|
|
137
|
+
console.log('[Rapidsnark] Public buffer size calculated:', bufferSize);
|
|
137
138
|
return bufferSize;
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
|
-
console.error('
|
|
141
|
+
console.error('[Rapidsnark] Failed to calculate public buffer size:', String(error));
|
|
141
142
|
throw new Error(`Failed to calculate public buffer size: ${String(error)}`);
|
|
142
143
|
}
|
|
143
144
|
};
|
|
@@ -149,17 +150,17 @@ const testRapidsnark = async () => {
|
|
|
149
150
|
try {
|
|
150
151
|
const initialized = await (0, exports.initializeRapidsnark)();
|
|
151
152
|
if (!initialized) {
|
|
152
|
-
console.log('
|
|
153
|
+
console.log('[Rapidsnark] Rapidsnark not available in this environment');
|
|
153
154
|
return false;
|
|
154
155
|
}
|
|
155
|
-
console.log('
|
|
156
|
+
console.log('[Rapidsnark] Testing rapidsnark functionality...');
|
|
156
157
|
// Note: This is just initialization testing
|
|
157
158
|
// Actual proof generation requires circuit files (.zkey, .wtns)
|
|
158
|
-
console.log('
|
|
159
|
+
console.log('[Rapidsnark] Rapidsnark is ready for proof generation');
|
|
159
160
|
return true;
|
|
160
161
|
}
|
|
161
162
|
catch (error) {
|
|
162
|
-
console.error('
|
|
163
|
+
console.error('[Rapidsnark] Rapidsnark test failed:', error);
|
|
163
164
|
return false;
|
|
164
165
|
}
|
|
165
166
|
};
|
|
@@ -183,8 +184,8 @@ class ReactNativeProver {
|
|
|
183
184
|
return (0, exports.generateProofWithRapidsnark)(zkeyPath, witnessBase64);
|
|
184
185
|
}
|
|
185
186
|
// Fallback to DOP Engine's prover
|
|
186
|
-
console.log('
|
|
187
|
-
throw new Error('Rapidsnark not available. Please ensure
|
|
187
|
+
console.log('[Rapidsnark] Using DOP Engine prover as fallback');
|
|
188
|
+
throw new Error('Rapidsnark not available. Please ensure react-native-rapidsnark is installed for React Native proof generation.');
|
|
188
189
|
}
|
|
189
190
|
async verifyProof(proof, publicSignals, verificationKey) {
|
|
190
191
|
await this.initialize();
|
|
@@ -192,8 +193,8 @@ class ReactNativeProver {
|
|
|
192
193
|
return (0, exports.verifyProofWithRapidsnark)(proof, publicSignals, verificationKey);
|
|
193
194
|
}
|
|
194
195
|
// Fallback to DOP Engine's verifier
|
|
195
|
-
console.log('
|
|
196
|
-
throw new Error('Rapidsnark not available. Please ensure
|
|
196
|
+
console.log('[Rapidsnark] Using DOP Engine verifier as fallback');
|
|
197
|
+
throw new Error('Rapidsnark not available. Please ensure react-native-rapidsnark is installed for React Native proof verification.');
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
exports.ReactNativeProver = ReactNativeProver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-rapidsnark-prover.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/react-native-rapidsnark-prover.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAgD;AAkBhD,IAAI,gBAAgB,GAA+B,IAAI,CAAC;AAExD;;GAEG;AACI,MAAM,oBAAoB,GAAG,KAAK,IAAsB,EAAE;;IAC/D,IAAI,CAAC,uBAAa,EAAE;QAClB,OAAO,CAAC,GAAG,CAAC,yEAAyE,CAAC,CAAC;QACvF,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;QAE9D,wDAAwD;QACxD,IAAI,gBAAyB,CAAC;QAC9B,IAAI;YACF,yFAAyF;YACzF,MAAM,UAAU,GAAG,gCAAgC,CAAC;YACpD,gBAAgB,GAAG,YAAa,UAAU,0DAAC,CAAC;SAC7C;QAAC,OAAO,WAAW,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,kDAAkD,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;YACrF,OAAO,KAAK,CAAC;SACd;QAED,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,uBAAuB,EAAE,GAAG,gBAIhE,CAAC;QAEF,gBAAgB,GAAG;YACjB,YAAY;YACZ,aAAa;YACb,uBAAuB;SACxB,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;KAEb;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,CAAC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,EAAE,aAAsB,EAAE,eAAuB;QAC/E,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAExB,IAAI,IAAA,6BAAqB,GAAE,EAAE;YAC3B,OAAO,IAAA,iCAAyB,EAAC,KAAK,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;SACzE;QACC,oCAAoC;QACpC,OAAO,CAAC,GAAG,CAAC,0CAA0C,CAAC,CAAC;QACxD,MAAM,IAAI,KAAK,CAAC,0HAA0H,CAAC,CAAC;IAEhJ,CAAC;CACF;AApCD,8CAoCC;AAED,4BAA4B;AACf,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["/**\n * React Native Rapidsnark Prover Integration\n * \n * This module provides an alternative proof generation system using rapidsnark\n * for React Native environments where circomlibjs/snarkjs may not work optimally.\n */\n\nimport { isReactNative } from '../util/runtime';\n\n// Type definitions for rapidsnark\ninterface RapidsnarkProof {\n proof: {\n a: string[];\n b: string[][];\n c: string[];\n };\n pub_signals: string[];\n}\n\ninterface RapidsnarkInterface {\n groth16Prove: (zkeyPath: string, wtns: string) => Promise<RapidsnarkProof>;\n groth16Verify: (proof: unknown, pubSignals: unknown, verificationKey: string) => boolean;\n groth16PublicBufferSize: (zkeyPath: string) => Promise<number>;\n}\n\nlet rapidsnarkModule: RapidsnarkInterface | null = null;\n\n/**\n * Initialize rapidsnark module for React Native\n */\nexport const initializeRapidsnark = async (): Promise<boolean> => {\n if (!isReactNative) {\n console.log('🖥️ Not in React Native environment, skipping rapidsnark initialization');\n return false;\n }\n\n try {\n console.log('📱 Initializing rapidsnark for React Native...');\n \n // Dynamic import with try-catch for optional dependency\n let rapidsnarkImport: unknown;\n try {\n // Use string literal to avoid TypeScript compilation errors when module is not installed\n const moduleName = '@iden3/react-native-rapidsnark';\n rapidsnarkImport = await import(moduleName);\n } catch (importError) {\n console.log('📝 @iden3/react-native-rapidsnark not available:', String(importError));\n return false;\n }\n \n const { groth16Prove, groth16Verify, groth16PublicBufferSize } = rapidsnarkImport as {\n groth16Prove: RapidsnarkInterface['groth16Prove'];\n groth16Verify: RapidsnarkInterface['groth16Verify'];\n groth16PublicBufferSize: RapidsnarkInterface['groth16PublicBufferSize'];\n };\n \n rapidsnarkModule = {\n groth16Prove,\n groth16Verify,\n groth16PublicBufferSize\n };\n \n console.log('✅ Rapidsnark initialized successfully');\n return true;\n \n } catch (error) {\n console.warn('⚠️ Rapidsnark not available:', error);\n console.log('💡 Install @iden3/react-native-rapidsnark for React Native proof generation');\n return false;\n }\n};\n\n/**\n * Check if rapidsnark is available and initialized\n */\nexport const isRapidsnarkAvailable = (): boolean => {\n return isReactNative && rapidsnarkModule !== null;\n};\n\n/**\n * Generate proof using rapidsnark (React Native only)\n */\nexport const generateProofWithRapidsnark = async (\n zkeyPath: string,\n witnessBase64: string\n): Promise<RapidsnarkProof> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n console.log('🔄 Generating proof with rapidsnark...');\n \n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const proof = await rapidsnarkModule.groth16Prove(zkeyPath, witnessBase64);\n \n console.log('✅ Proof generated successfully with rapidsnark');\n return proof;\n \n } catch (error) {\n console.error('❌ Rapidsnark proof generation failed:', String(error));\n throw new Error(`Rapidsnark proof generation failed: ${String(error)}`);\n }\n};\n\n/**\n * Verify proof using rapidsnark (React Native only)\n */\nexport const verifyProofWithRapidsnark = async (\n proof: unknown,\n publicSignals: unknown,\n verificationKeyBase64: string\n): Promise<boolean> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n console.log('🔍 Verifying proof with rapidsnark...');\n \n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const isValid = rapidsnarkModule.groth16Verify(proof, publicSignals, verificationKeyBase64);\n \n console.log('✅ Proof verification completed:', isValid);\n return isValid;\n \n } catch (error) {\n console.error('❌ Rapidsnark proof verification failed:', String(error));\n throw new Error(`Rapidsnark proof verification failed: ${String(error)}`);\n }\n};\n\n/**\n * Get public buffer size for zkey (React Native only)\n */\nexport const getPublicBufferSize = async (zkeyPath: string): Promise<number> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const bufferSize = await rapidsnarkModule.groth16PublicBufferSize(zkeyPath);\n console.log('📏 Public buffer size calculated:', bufferSize);\n return bufferSize;\n \n } catch (error) {\n console.error('❌ Failed to calculate public buffer size:', String(error));\n throw new Error(`Failed to calculate public buffer size: ${String(error)}`);\n }\n};\n\n/**\n * Test rapidsnark functionality\n */\nexport const testRapidsnark = async (): Promise<boolean> => {\n try {\n const initialized = await initializeRapidsnark();\n \n if (!initialized) {\n console.log('ℹ️ Rapidsnark not available in this environment');\n return false;\n }\n\n console.log('🧪 Testing rapidsnark functionality...');\n \n // Note: This is just initialization testing\n // Actual proof generation requires circuit files (.zkey, .wtns)\n console.log('✅ Rapidsnark is ready for proof generation');\n \n return true;\n \n } catch (error) {\n console.error('❌ Rapidsnark test failed:', error);\n return false;\n }\n};\n\n/**\n * React Native-specific prover that uses rapidsnark when available\n */\nexport class ReactNativeProver {\n private initialized = false;\n \n async initialize(): Promise<void> {\n if (this.initialized) return;\n \n if (isReactNative) {\n await initializeRapidsnark();\n }\n \n this.initialized = true;\n }\n \n async generateProof(zkeyPath: string, witnessBase64: string): Promise<unknown> {\n await this.initialize();\n \n if (isRapidsnarkAvailable()) {\n return generateProofWithRapidsnark(zkeyPath, witnessBase64);\n } \n // Fallback to DOP Engine's prover\n console.log('📝 Using DOP Engine prover as fallback');\n throw new Error('Rapidsnark not available. Please ensure @iden3/react-native-rapidsnark is installed for React Native proof generation.');\n \n }\n \n async verifyProof(proof: unknown, publicSignals: unknown, verificationKey: string): Promise<boolean> {\n await this.initialize();\n \n if (isRapidsnarkAvailable()) {\n return verifyProofWithRapidsnark(proof, publicSignals, verificationKey);\n } \n // Fallback to DOP Engine's verifier\n console.log('📝 Using DOP Engine verifier as fallback');\n throw new Error('Rapidsnark not available. Please ensure @iden3/react-native-rapidsnark is installed for React Native proof verification.');\n \n }\n}\n\n// Export singleton instance\nexport const reactNativeProver = new ReactNativeProver();"]}
|
|
1
|
+
{"version":3,"file":"react-native-rapidsnark-prover.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/react-native-rapidsnark-prover.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAAgD;AAkBhD,IAAI,gBAAgB,GAA+B,IAAI,CAAC;AAExD;;GAEG;AACI,MAAM,oBAAoB,GAAG,KAAK,IAAsB,EAAE;;IAC/D,IAAI,CAAC,uBAAa,EAAE;QAClB,OAAO,CAAC,GAAG,CAAC,kFAAkF,CAAC,CAAC;QAChG,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,OAAO,CAAC,GAAG,CAAC,0DAA0D,CAAC,CAAC;QAExE,wDAAwD;QACxD,IAAI,gBAAyB,CAAC;QAC9B,IAAI;YACF,yFAAyF;YACzF,4FAA4F;YAC5F,MAAM,UAAU,GAAG,yBAAyB,CAAC;YAC7C,gBAAgB,GAAG,YAAa,UAAU,0DAAC,CAAC;SAC7C;QAAC,OAAO,WAAW,EAAE;YACpB,OAAO,CAAC,GAAG,CAAC,qDAAqD,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;YACxF,OAAO,KAAK,CAAC;SACd;QAED,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,uBAAuB,EAAE,GAAG,gBAIhE,CAAC;QAEF,gBAAgB,GAAG;YACjB,YAAY;YACZ,aAAa;YACb,uBAAuB;SACxB,CAAC;QAEF,OAAO,CAAC,G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AC,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,iHAAiH,CAAC,CAAC;IAEvI,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAc,EAAE,aAAsB,EAAE,eAAuB;QAC/E,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QAExB,IAAI,IAAA,6BAAqB,GAAE,EAAE;YAC3B,OAAO,IAAA,iCAAyB,EAAC,KAAK,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;SACzE;QACC,oCAAoC;QACpC,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,mHAAmH,CAAC,CAAC;IAEzI,CAAC;CACF;AApCD,8CAoCC;AAED,4BAA4B;AACf,QAAA,iBAAiB,GAAG,IAAI,iBAAiB,EAAE,CAAC","sourcesContent":["/**\n * React Native Rapidsnark Prover Integration\n * \n * This module provides an alternative proof generation system using rapidsnark\n * for React Native environments where circomlibjs/snarkjs may not work optimally.\n */\n\nimport { isReactNative } from '../util/runtime';\n\n// Type definitions for rapidsnark\ninterface RapidsnarkProof {\n proof: {\n a: string[];\n b: string[][];\n c: string[];\n };\n pub_signals: string[];\n}\n\ninterface RapidsnarkInterface {\n groth16Prove: (zkeyPath: string, wtns: string) => Promise<RapidsnarkProof>;\n groth16Verify: (proof: unknown, pubSignals: unknown, verificationKey: string) => boolean;\n groth16PublicBufferSize: (zkeyPath: string) => Promise<number>;\n}\n\nlet rapidsnarkModule: RapidsnarkInterface | null = null;\n\n/**\n * Initialize rapidsnark module for React Native\n */\nexport const initializeRapidsnark = async (): Promise<boolean> => {\n if (!isReactNative) {\n console.log('[Rapidsnark] Not in React Native environment, skipping rapidsnark initialization');\n return false;\n }\n\n try {\n console.log('[Rapidsnark] Initializing rapidsnark for React Native...');\n \n // Dynamic import with try-catch for optional dependency\n let rapidsnarkImport: unknown;\n try {\n // Use string literal to avoid TypeScript compilation errors when module is not installed\n // The actual package name is 'react-native-rapidsnark' (not @iden3/react-native-rapidsnark)\n const moduleName = 'react-native-rapidsnark';\n rapidsnarkImport = await import(moduleName);\n } catch (importError) {\n console.log('[Rapidsnark] react-native-rapidsnark not available:', String(importError));\n return false;\n }\n \n const { groth16Prove, groth16Verify, groth16PublicBufferSize } = rapidsnarkImport as {\n groth16Prove: RapidsnarkInterface['groth16Prove'];\n groth16Verify: RapidsnarkInterface['groth16Verify'];\n groth16PublicBufferSize: RapidsnarkInterface['groth16PublicBufferSize'];\n };\n \n rapidsnarkModule = {\n groth16Prove,\n groth16Verify,\n groth16PublicBufferSize\n };\n \n console.log('[Rapidsnark] Rapidsnark initialized successfully');\n return true;\n \n } catch (error) {\n console.warn('[Rapidsnark] Rapidsnark not available:', error);\n console.log('[Rapidsnark] Install react-native-rapidsnark for React Native proof generation');\n return false;\n }\n};\n\n/**\n * Check if rapidsnark is available and initialized\n */\nexport const isRapidsnarkAvailable = (): boolean => {\n return isReactNative && rapidsnarkModule !== null;\n};\n\n/**\n * Generate proof using rapidsnark (React Native only)\n */\nexport const generateProofWithRapidsnark = async (\n zkeyPath: string,\n witnessBase64: string\n): Promise<RapidsnarkProof> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n console.log('[Rapidsnark] Generating proof with rapidsnark...');\n \n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const proof = await rapidsnarkModule.groth16Prove(zkeyPath, witnessBase64);\n \n console.log('[Rapidsnark] Proof generated successfully with rapidsnark');\n return proof;\n \n } catch (error) {\n console.error('[Rapidsnark] Rapidsnark proof generation failed:', String(error));\n throw new Error(`Rapidsnark proof generation failed: ${String(error)}`);\n }\n};\n\n/**\n * Verify proof using rapidsnark (React Native only)\n */\nexport const verifyProofWithRapidsnark = async (\n proof: unknown,\n publicSignals: unknown,\n verificationKeyBase64: string\n): Promise<boolean> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n console.log('[Rapidsnark] Verifying proof with rapidsnark...');\n \n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const isValid = rapidsnarkModule.groth16Verify(proof, publicSignals, verificationKeyBase64);\n \n console.log('[Rapidsnark] Proof verification completed:', isValid);\n return isValid;\n \n } catch (error) {\n console.error('[Rapidsnark] Rapidsnark proof verification failed:', String(error));\n throw new Error(`Rapidsnark proof verification failed: ${String(error)}`);\n }\n};\n\n/**\n * Get public buffer size for zkey (React Native only)\n */\nexport const getPublicBufferSize = async (zkeyPath: string): Promise<number> => {\n if (!isRapidsnarkAvailable()) {\n throw new Error('Rapidsnark is not available. Please ensure react-native-rapidsnark is installed and this is running in React Native.');\n }\n\n try {\n if (!rapidsnarkModule) {\n throw new Error('Rapidsnark module not initialized');\n }\n \n const bufferSize = await rapidsnarkModule.groth16PublicBufferSize(zkeyPath);\n console.log('[Rapidsnark] Public buffer size calculated:', bufferSize);\n return bufferSize;\n \n } catch (error) {\n console.error('[Rapidsnark] Failed to calculate public buffer size:', String(error));\n throw new Error(`Failed to calculate public buffer size: ${String(error)}`);\n }\n};\n\n/**\n * Test rapidsnark functionality\n */\nexport const testRapidsnark = async (): Promise<boolean> => {\n try {\n const initialized = await initializeRapidsnark();\n \n if (!initialized) {\n console.log('[Rapidsnark] Rapidsnark not available in this environment');\n return false;\n }\n\n console.log('[Rapidsnark] Testing rapidsnark functionality...');\n \n // Note: This is just initialization testing\n // Actual proof generation requires circuit files (.zkey, .wtns)\n console.log('[Rapidsnark] Rapidsnark is ready for proof generation');\n \n return true;\n \n } catch (error) {\n console.error('[Rapidsnark] Rapidsnark test failed:', error);\n return false;\n }\n};\n\n/**\n * React Native-specific prover that uses rapidsnark when available\n */\nexport class ReactNativeProver {\n private initialized = false;\n \n async initialize(): Promise<void> {\n if (this.initialized) return;\n \n if (isReactNative) {\n await initializeRapidsnark();\n }\n \n this.initialized = true;\n }\n \n async generateProof(zkeyPath: string, witnessBase64: string): Promise<unknown> {\n await this.initialize();\n \n if (isRapidsnarkAvailable()) {\n return generateProofWithRapidsnark(zkeyPath, witnessBase64);\n } \n // Fallback to DOP Engine's prover\n console.log('[Rapidsnark] Using DOP Engine prover as fallback');\n throw new Error('Rapidsnark not available. Please ensure react-native-rapidsnark is installed for React Native proof generation.');\n \n }\n \n async verifyProof(proof: unknown, publicSignals: unknown, verificationKey: string): Promise<boolean> {\n await this.initialize();\n \n if (isRapidsnarkAvailable()) {\n return verifyProofWithRapidsnark(proof, publicSignals, verificationKey);\n } \n // Fallback to DOP Engine's verifier\n console.log('[Rapidsnark] Using DOP Engine verifier as fallback');\n throw new Error('Rapidsnark not available. Please ensure react-native-rapidsnark is installed for React Native proof verification.');\n \n }\n}\n\n// Export singleton instance\nexport const reactNativeProver = new ReactNativeProver();"]}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native WCD Prover - Using circom-witnesscalc .wcd files
|
|
3
|
+
*
|
|
4
|
+
* This module provides witness calculation using pre-compiled .wcd graph files
|
|
5
|
+
* from iden3/circom-witnesscalc. This is the recommended approach for React Native
|
|
6
|
+
* as it provides fast, native witness calculation without WASM overhead.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. Load .wcd graph file for the circuit
|
|
10
|
+
* 2. Use @iden3/react-native-circom-witnesscalc to calculate witness
|
|
11
|
+
* 3. Use react-native-rapidsnark to generate proof
|
|
12
|
+
*
|
|
13
|
+
* Benefits over WASM approach:
|
|
14
|
+
* - Faster witness calculation (native code)
|
|
15
|
+
* - No WASM runtime needed
|
|
16
|
+
* - Smaller memory footprint
|
|
17
|
+
* - Better mobile performance
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Result from rapidsnark groth16Prove
|
|
21
|
+
*/
|
|
22
|
+
export interface WCDRapidsnarkProofResult {
|
|
23
|
+
proof: {
|
|
24
|
+
a: string[];
|
|
25
|
+
b: string[][];
|
|
26
|
+
c: string[];
|
|
27
|
+
};
|
|
28
|
+
pub_signals: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Rapidsnark's groth16Prove function signature
|
|
32
|
+
*/
|
|
33
|
+
export type WCDGroth16ProveFunction = (zkeyPath: string, witnessBase64: string) => Promise<WCDRapidsnarkProofResult>;
|
|
34
|
+
/**
|
|
35
|
+
* circom-witnesscalc's calculateWitness function signature
|
|
36
|
+
* From: import { calculateWitness } from '@iden3/react-native-circom-witnesscalc'
|
|
37
|
+
*/
|
|
38
|
+
export type WCDCalculateWitnessFunction = (inputsJson: string, graphBase64: string) => Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* File system interface for React Native
|
|
41
|
+
*/
|
|
42
|
+
export interface WCDFileSystem {
|
|
43
|
+
writeFile(path: string, data: string, encoding: 'base64' | 'utf8'): Promise<void>;
|
|
44
|
+
readFile(path: string, encoding: 'base64' | 'utf8'): Promise<string>;
|
|
45
|
+
exists(path: string): Promise<boolean>;
|
|
46
|
+
unlink(path: string): Promise<void>;
|
|
47
|
+
mkdir(path: string): Promise<void>;
|
|
48
|
+
documentDirectory: string;
|
|
49
|
+
cacheDirectory: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for WCD-based React Native Prover
|
|
53
|
+
*/
|
|
54
|
+
export interface WCDProverConfig {
|
|
55
|
+
/**
|
|
56
|
+
* circom-witnesscalc's calculateWitness function
|
|
57
|
+
* Import: import { calculateWitness } from '@iden3/react-native-circom-witnesscalc'
|
|
58
|
+
*/
|
|
59
|
+
calculateWitness: WCDCalculateWitnessFunction;
|
|
60
|
+
/**
|
|
61
|
+
* Rapidsnark's groth16Prove function
|
|
62
|
+
* Import: import { groth16Prove } from 'react-native-rapidsnark'
|
|
63
|
+
*/
|
|
64
|
+
groth16Prove: WCDGroth16ProveFunction;
|
|
65
|
+
/**
|
|
66
|
+
* File system interface (react-native-fs or expo-file-system)
|
|
67
|
+
*/
|
|
68
|
+
fs: WCDFileSystem;
|
|
69
|
+
/**
|
|
70
|
+
* Base directory where .wcd files are stored
|
|
71
|
+
* Default: fs.documentDirectory + '/dop-wcd'
|
|
72
|
+
*/
|
|
73
|
+
wcdDirectory?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Base directory where .zkey files are stored
|
|
76
|
+
* Default: fs.documentDirectory + '/dop-zkeys'
|
|
77
|
+
*/
|
|
78
|
+
zkeyDirectory?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Enable debug logging
|
|
81
|
+
*/
|
|
82
|
+
debug?: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Stored WCD artifacts info
|
|
86
|
+
*/
|
|
87
|
+
export interface WCDArtifacts {
|
|
88
|
+
wcdPath: string;
|
|
89
|
+
zkeyPath: string;
|
|
90
|
+
vkeyPath?: string;
|
|
91
|
+
circuitId: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Convert Uint8Array to base64 string
|
|
95
|
+
*/
|
|
96
|
+
export declare function wcdUint8ArrayToBase64(data: Uint8Array): string;
|
|
97
|
+
/**
|
|
98
|
+
* Convert base64 string to Uint8Array
|
|
99
|
+
*/
|
|
100
|
+
export declare function wcdBase64ToUint8Array(base64: string): Uint8Array;
|
|
101
|
+
/**
|
|
102
|
+
* Manages WCD artifacts on the device
|
|
103
|
+
*/
|
|
104
|
+
export declare class WCDArtifactManager {
|
|
105
|
+
private fs;
|
|
106
|
+
private wcdDir;
|
|
107
|
+
private zkeyDir;
|
|
108
|
+
private debug;
|
|
109
|
+
constructor(config: WCDProverConfig);
|
|
110
|
+
private log;
|
|
111
|
+
/**
|
|
112
|
+
* Get WCD directory path
|
|
113
|
+
*/
|
|
114
|
+
getWCDDirectory(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Get zkey directory path
|
|
117
|
+
*/
|
|
118
|
+
getZkeyDirectory(): string;
|
|
119
|
+
/**
|
|
120
|
+
* Ensure directory exists
|
|
121
|
+
*/
|
|
122
|
+
ensureDir(dir: string): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Get artifact paths for a circuit
|
|
125
|
+
*/
|
|
126
|
+
getArtifactPaths(circuitId: string): WCDArtifacts;
|
|
127
|
+
/**
|
|
128
|
+
* Check if artifacts exist for a circuit
|
|
129
|
+
*/
|
|
130
|
+
hasArtifacts(circuitId: string): Promise<boolean>;
|
|
131
|
+
/**
|
|
132
|
+
* Store WCD artifact from buffer
|
|
133
|
+
*/
|
|
134
|
+
storeWCD(circuitId: string, wcdBuffer: Uint8Array): Promise<string>;
|
|
135
|
+
/**
|
|
136
|
+
* Store zkey artifact from buffer
|
|
137
|
+
*/
|
|
138
|
+
storeZkey(circuitId: string, zkeyBuffer: Uint8Array): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Get WCD file as base64
|
|
141
|
+
*/
|
|
142
|
+
getWCDBase64(circuitId: string): Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Get zkey file path
|
|
145
|
+
*/
|
|
146
|
+
getZkeyPath(circuitId: string): string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if WCD prover is configured
|
|
150
|
+
*/
|
|
151
|
+
export declare function hasWCDProver(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Get WCD prover configuration
|
|
154
|
+
*/
|
|
155
|
+
export declare function getWCDProverConfig(): WCDProverConfig | null;
|
|
156
|
+
/**
|
|
157
|
+
* Set up WCD-based prover for React Native
|
|
158
|
+
*
|
|
159
|
+
* This configures the SDK to use .wcd graph files with circom-witnesscalc
|
|
160
|
+
* for witness calculation, and rapidsnark for proof generation.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* import { calculateWitness } from '@iden3/react-native-circom-witnesscalc';
|
|
165
|
+
* import { groth16Prove } from 'react-native-rapidsnark';
|
|
166
|
+
* import RNFS from 'react-native-fs';
|
|
167
|
+
*
|
|
168
|
+
* setWCDProver({
|
|
169
|
+
* calculateWitness,
|
|
170
|
+
* groth16Prove,
|
|
171
|
+
* fs: {
|
|
172
|
+
* writeFile: (path, data, encoding) => RNFS.writeFile(path, data, encoding),
|
|
173
|
+
* readFile: (path, encoding) => RNFS.readFile(path, encoding),
|
|
174
|
+
* exists: (path) => RNFS.exists(path),
|
|
175
|
+
* unlink: (path) => RNFS.unlink(path),
|
|
176
|
+
* mkdir: (path) => RNFS.mkdir(path),
|
|
177
|
+
* documentDirectory: RNFS.DocumentDirectoryPath,
|
|
178
|
+
* cacheDirectory: RNFS.CachesDirectoryPath,
|
|
179
|
+
* },
|
|
180
|
+
* debug: true,
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export declare function setWCDProver(config: WCDProverConfig): void;
|
|
185
|
+
/**
|
|
186
|
+
* Clear WCD prover configuration
|
|
187
|
+
*/
|
|
188
|
+
export declare function clearWCDProver(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Create a WCD artifact store for storing/loading .wcd files
|
|
191
|
+
*/
|
|
192
|
+
export declare function createWCDArtifactManager(config: WCDProverConfig): WCDArtifactManager;
|
|
193
|
+
/**
|
|
194
|
+
* Store WCD artifacts from local buffers (for testing/development)
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* // Load WCD file from assets
|
|
199
|
+
* const wcdBuffer = await loadWCDFromAssets('3x2.wcd');
|
|
200
|
+
* const zkeyBuffer = await loadZkeyFromAssets('3x2.zkey');
|
|
201
|
+
*
|
|
202
|
+
* await storeWCDArtifacts('3x2', wcdBuffer, zkeyBuffer);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export declare function storeWCDArtifacts(circuitId: string, wcdBuffer: Uint8Array, zkeyBuffer: Uint8Array): Promise<WCDArtifacts>;
|
|
206
|
+
/**
|
|
207
|
+
* Check if WCD artifacts are available for a circuit
|
|
208
|
+
*/
|
|
209
|
+
export declare function hasWCDArtifacts(circuitId: string): Promise<boolean>;
|
|
210
|
+
/**
|
|
211
|
+
* Get the path where WCD file should be stored
|
|
212
|
+
*/
|
|
213
|
+
export declare function getWCDPath(circuitId: string): string;
|
|
214
|
+
/**
|
|
215
|
+
* Get the path where zkey file should be stored
|
|
216
|
+
*/
|
|
217
|
+
export declare function getZkeyPathForWCD(circuitId: string): string;
|
|
218
|
+
/**
|
|
219
|
+
* Store only WCD file (SDK handles zkey download automatically)
|
|
220
|
+
*
|
|
221
|
+
* Use this when bundling WCD files with your mobile app.
|
|
222
|
+
* The SDK will download zkey files on-demand via ArtifactDownloader.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Load WCD from bundled assets
|
|
227
|
+
* const wcdBuffer = await loadWCDFromAssets('3x2.wcd');
|
|
228
|
+
* await storeWCDOnly('3x2', wcdBuffer);
|
|
229
|
+
*
|
|
230
|
+
* // Now SDK can generate proofs for 3x2 circuit
|
|
231
|
+
* // zkey will be downloaded automatically when needed
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function storeWCDOnly(circuitId: string, wcdBuffer: Uint8Array): Promise<string>;
|
|
235
|
+
/**
|
|
236
|
+
* Check if WCD file exists for a circuit (zkey is handled by SDK)
|
|
237
|
+
*/
|
|
238
|
+
export declare function hasWCDFile(circuitId: string): Promise<boolean>;
|
|
239
|
+
/**
|
|
240
|
+
* Get list of all stored WCD circuit IDs
|
|
241
|
+
*/
|
|
242
|
+
export declare function getStoredWCDCircuits(): Promise<string[]>;
|