dop-wallet-v6 1.2.14 โ†’ 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +14 -1
  2. package/dist/services/dop/core/react-native-init.d.ts +18 -0
  3. package/dist/services/dop/core/react-native-init.js +30 -24
  4. package/dist/services/dop/core/react-native-init.js.map +1 -1
  5. package/dist/services/dop/crypto/react-native-crypto-provider.d.ts +41 -0
  6. package/dist/services/dop/crypto/react-native-crypto-provider.js +146 -0
  7. package/dist/services/dop/crypto/react-native-crypto-provider.js.map +1 -0
  8. package/dist/services/dop/crypto/react-native-rapidsnark-prover.d.ts +49 -0
  9. package/dist/services/dop/crypto/react-native-rapidsnark-prover.js +202 -0
  10. package/dist/services/dop/crypto/react-native-rapidsnark-prover.js.map +1 -0
  11. package/dist/services/dop/util/runtime.d.ts +1 -0
  12. package/dist/services/dop/util/runtime.js +34 -2
  13. package/dist/services/dop/util/runtime.js.map +1 -1
  14. package/dist/services/dop/wallets/wallets.js +47 -46
  15. package/dist/services/dop/wallets/wallets.js.map +1 -1
  16. package/metro.config.react-native.example.js +10 -8
  17. package/node-polyfills/fs-polyfill.js +54 -0
  18. package/node-polyfills/path-polyfill.js +36 -0
  19. package/node-polyfills/process-polyfill.js +61 -0
  20. package/node-polyfills/url-polyfill.js +32 -0
  21. package/node-polyfills/util-polyfill.js +76 -0
  22. package/package.json +16 -4
  23. package/react-native-shims.js +27 -10
  24. package/react-native.js +12 -0
  25. package/DOP_WALLET_V6_REACT_NATIVE_INTEGRATION_GUIDE.md +0 -2174
  26. package/SELECTIVE_TRANSPARENCY.md +0 -207
  27. package/WEB_WORKER_TROUBLESHOOTING.md +0 -180
  28. package/issuev3.md +0 -78
package/README.md CHANGED
@@ -6,5 +6,18 @@ The DOP Wallet SDK is an open-source project developed by [DOP](https://www.dop.
6
6
 
7
7
  The Wallet SDK enables dApp and DeFi developers to provide privacy to users safely and conveniently on Ethereum, Polygon and BNB Chain.
8
8
 
9
- The repo is written in TypeScript, and compatible with node.js and modern web browsers.
9
+ The repo is written in TypeScript, and compatible with **Node.js**, **modern web browsers**, and **React Native**.
10
+
11
+ ## ๐Ÿ“ฑ React Native Support
12
+
13
+ This SDK now has comprehensive React Native support with optimized polyfills and easy integration:
14
+
15
+ ```typescript
16
+ import 'react-native-get-random-values';
17
+ import { DopWallet } from 'dop-wallet-v6/react-native';
18
+ ```
19
+
20
+ **๐Ÿ“š Quick Start:** See [REACT_NATIVE_INTEGRATION_GUIDE.md](./REACT_NATIVE_INTEGRATION_GUIDE.md) for complete setup instructions.
21
+
22
+ **๐Ÿ”ง Verify Compatibility:** Run `npm run verify-rn-compatibility` to ensure your setup is correct.
10
23
 
@@ -1,4 +1,22 @@
1
1
  import { ArtifactStore } from '../../artifacts/artifact-store';
2
+ /**
3
+ * React Native compatible LevelDB implementation using memdown with AsyncStorage persistence.
4
+ * This provides a persistent database solution that works reliably in React Native environments.
5
+ */
6
+ export declare class ReactNativeLevelDB {
7
+ private db;
8
+ private storageKey;
9
+ private AsyncStorage;
10
+ constructor(name: string);
11
+ open(callback: (error?: Error) => void): Promise<void>;
12
+ close(callback: (error?: Error) => void): void;
13
+ put(key: any, value: any, callback: (error?: Error) => void): void;
14
+ get(key: any, callback: (error?: Error, value?: any) => void): void;
15
+ del(key: any, callback: (error?: Error) => void): void;
16
+ batch(operations: any[], callback: (error?: Error) => void): void;
17
+ iterator(options?: any): any;
18
+ private _persistData;
19
+ }
2
20
  /**
3
21
  * Initialize DOP Engine specifically for React Native environments.
4
22
  * Uses a custom LevelDB implementation that persists data to AsyncStorage.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startDopEngineReactNative = void 0;
3
+ exports.startDopEngineReactNative = exports.ReactNativeLevelDB = void 0;
4
4
  const init_1 = require("./init");
5
5
  // Use memdown for React Native database - with error handling
6
6
  let memdown;
@@ -24,33 +24,39 @@ class ReactNativeLevelDB {
24
24
  this.db = memdown();
25
25
  // Dynamically import AsyncStorage to avoid bundling issues
26
26
  try {
27
+ // Try to require AsyncStorage - this will work in React Native
27
28
  this.AsyncStorage = require('@react-native-async-storage/async-storage').default;
28
29
  }
29
30
  catch (error) {
30
- console.warn('AsyncStorage not available, data will not persist between app restarts');
31
+ // AsyncStorage not available - this is expected in Node.js test environment
31
32
  this.AsyncStorage = null;
32
33
  }
33
34
  }
34
35
  // Implement AbstractLevelDOWN interface
35
36
  async open(callback) {
36
37
  try {
37
- // Load persisted data from AsyncStorage
38
+ // Load persisted data from AsyncStorage (only if available)
38
39
  if (this.AsyncStorage) {
39
- const persistedData = await this.AsyncStorage.getItem(this.storageKey);
40
- if (persistedData) {
41
- const data = JSON.parse(persistedData);
42
- // Restore data to memdown instance
43
- for (const [key, value] of Object.entries(data)) {
44
- await new Promise((resolve, reject) => {
45
- this.db.put(key, value, (err) => {
46
- if (err)
47
- reject(err);
48
- else
49
- resolve();
40
+ try {
41
+ const persistedData = await this.AsyncStorage.getItem(this.storageKey);
42
+ if (persistedData) {
43
+ const data = JSON.parse(persistedData);
44
+ // Restore data to memdown instance
45
+ for (const [key, value] of Object.entries(data)) {
46
+ await new Promise((resolve, reject) => {
47
+ this.db.put(key, value, (err) => {
48
+ if (err)
49
+ reject(err);
50
+ else
51
+ resolve();
52
+ });
50
53
  });
51
- });
54
+ }
52
55
  }
53
56
  }
57
+ catch (asyncStorageError) {
58
+ // AsyncStorage not available or failed - continue without persistence
59
+ }
54
60
  }
55
61
  // Open the memdown database
56
62
  this.db.open(callback);
@@ -125,6 +131,7 @@ class ReactNativeLevelDB {
125
131
  }
126
132
  }
127
133
  }
134
+ exports.ReactNativeLevelDB = ReactNativeLevelDB;
128
135
  /**
129
136
  * Initialize DOP Engine specifically for React Native environments.
130
137
  * Uses a custom LevelDB implementation that persists data to AsyncStorage.
@@ -140,16 +147,15 @@ class ReactNativeLevelDB {
140
147
  */
141
148
  const startDopEngineReactNative = async (walletSource, shouldDebug, artifactStore, useNativeArtifacts = true, skipMerkletreeScans = false, verboseScanLogging = false, databaseName = 'dop-wallet-db') => {
142
149
  // Create React Native compatible database instance
143
- const db = new ReactNativeLevelDB(databaseName);
150
+ // const db = new ReactNativeLevelDB(databaseName);
144
151
  // Ensure database is opened before proceeding
145
- await new Promise((resolve, reject) => {
146
- db.open((error) => {
147
- if (error)
148
- reject(error);
149
- else
150
- resolve();
151
- });
152
- });
152
+ // await new Promise<void>((resolve, reject) => {
153
+ // db.open((error) => {
154
+ // if (error) reject(error);
155
+ // else resolve();
156
+ // });
157
+ // });
158
+ const db = memdown(); // Use in-memory DB if AsyncStorage is not available
153
159
  // Initialize the DOP Engine with the React Native database
154
160
  return (0, init_1.startDopEngine)(walletSource, db, // Cast to any since TypeScript doesn't know about our custom implementation
155
161
  shouldDebug, artifactStore, useNativeArtifacts, skipMerkletreeScans, verboseScanLogging);
@@ -1 +1 @@
1
- {"version":3,"file":"react-native-init.js","sourceRoot":"","sources":["../../../../src/services/dop/core/react-native-init.ts"],"names":[],"mappings":";;;AAcA,iCAAwC;AAExC,8DAA8D;AAC9D,IAAI,OAAY,CAAC;AACjB,IAAI;IACF,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CAC9B;AAAC,OAAO,KAAK,EAAE;IACd,MAAM,IAAI,KAAK,CACb,2DAA2D;QAC3D,oDAAoD,CACrD,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,kBAAkB;IACd,EAAE,CAAM;IACR,UAAU,CAAS;IACnB,YAAY,CAAM;IAE1B,YAAY,IAAY;QACtB,IAAI,CAAC,UAAU,GAAG,WAAW,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;QAEpB,2DAA2D;QAC3D,IAAI;YACF,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC,OAAO,CAAC;SAClF;QAAC,OAAO,KAAK,EAAE;YACd,OA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AM,EAAE,GAAG,IAAI,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAEhD,8CAA8C;IAC9C,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,KAAK;gBAAE,MAAM,CAAC,KAAK,CAAC,CAAC;;gBACpB,OAAO,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,2DAA2D;IAC3D,OAAO,IAAA,qBAAc,EACnB,YAAY,EACZ,EAAS,EAAE,4EAA4E;IACvF,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC;AA9BW,QAAA,yBAAyB,6BA8BpC","sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/strict-boolean-expressions */\n/* eslint-disable no-underscore-dangle */\n/* eslint-disable no-console */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable @typescript-eslint/no-floating-promises */\n/* eslint-disable global-require */\n/* eslint-disable no-void */\nimport { ArtifactStore } from '../../artifacts/artifact-store';\nimport { startDopEngine } from './init';\n\n// Use memdown for React Native database - with error handling\nlet memdown: any;\ntry {\n memdown = require('memdown');\n} catch (error) {\n throw new Error(\n 'memdown dependency is required for React Native support. ' +\n 'Please install it with: npm install memdown@^6.1.1'\n );\n}\n\n/**\n * React Native compatible LevelDB implementation using memdown with AsyncStorage persistence.\n * This provides a persistent database solution that works reliably in React Native environments.\n */\nclass ReactNativeLevelDB {\n private db: any;\n private storageKey: string;\n private AsyncStorage: any;\n\n constructor(name: string) {\n this.storageKey = `leveldb_${name}`;\n this.db = memdown();\n \n // Dynamically import AsyncStorage to avoid bundling issues\n try {\n this.AsyncStorage = require('@react-native-async-storage/async-storage').default;\n } catch (error) {\n console.warn('AsyncStorage not available, data will not persist between app restarts');\n this.AsyncStorage = null;\n }\n }\n\n // Implement AbstractLevelDOWN interface\n async open(callback: (error?: Error) => void): Promise<void> {\n try {\n // Load persisted data from AsyncStorage\n if (this.AsyncStorage) {\n const persistedData = await this.AsyncStorage.getItem(this.storageKey);\n if (persistedData) {\n const data = JSON.parse(persistedData);\n // Restore data to memdown instance\n for (const [key, value] of Object.entries(data)) {\n await new Promise<void>((resolve, reject) => {\n this.db.put(key, value, (err: any) => {\n if (err) reject(err);\n else resolve();\n });\n });\n }\n }\n }\n \n // Open the memdown database\n this.db.open(callback);\n } catch (error) {\n callback(error as Error);\n }\n }\n\n close(callback: (error?: Error) => void): void {\n this.db.close(callback);\n }\n\n put(key: any, value: any, callback: (error?: Error) => void): void {\n this.db.put(key, value, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n get(key: any, callback: (error?: Error, value?: any) => void): void {\n this.db.get(key, callback);\n }\n\n del(key: any, callback: (error?: Error) => void): void {\n this.db.del(key, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n batch(operations: any[], callback: (error?: Error) => void): void {\n this.db.batch(operations, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n iterator(options?: any): any {\n return this.db.iterator(options);\n }\n\n private async _persistData(): Promise<void> {\n if (!this.AsyncStorage) return;\n\n try {\n const data: Record<string, any> = {};\n const iterator = this.db.iterator();\n \n await new Promise<void>((resolve, reject) => {\n const processNext = () => {\n iterator.next((err: any, key: any, value: any) => {\n if (err) {\n iterator.end(() => reject(err));\n return;\n }\n \n if (key === undefined) {\n iterator.end(() => resolve());\n return;\n }\n \n data[key.toString()] = value;\n processNext();\n });\n };\n processNext();\n });\n\n await this.AsyncStorage.setItem(this.storageKey, JSON.stringify(data));\n } catch (error) {\n console.warn('Failed to persist data to AsyncStorage:', error);\n }\n }\n}\n\n/**\n * Initialize DOP Engine specifically for React Native environments.\n * Uses a custom LevelDB implementation that persists data to AsyncStorage.\n * This provides full database persistence while being compatible with React Native.\n * \n * @param walletSource - Name for your wallet implementation (max 16 chars, lowercase)\n * @param shouldDebug - Whether to forward Engine debug logs to Logger\n * @param artifactStore - Persistent store for downloading large artifact files\n * @param useNativeArtifacts - Whether to download native C++ artifacts (should be TRUE for mobile)\n * @param skipMerkletreeScans - Whether to skip merkletree syncs and private balance scans\n * @param verboseScanLogging - Enable verbose logging for scanning operations\n * @param databaseName - Name for the database (used as prefix in AsyncStorage)\n */\nexport const startDopEngineReactNative = async (\n walletSource: string,\n shouldDebug: boolean,\n artifactStore: ArtifactStore,\n useNativeArtifacts = true,\n skipMerkletreeScans = false,\n verboseScanLogging = false,\n databaseName = 'dop-wallet-db'\n): Promise<void> => {\n // Create React Native compatible database instance\n const db = new ReactNativeLevelDB(databaseName);\n \n // Ensure database is opened before proceeding\n await new Promise<void>((resolve, reject) => {\n db.open((error) => {\n if (error) reject(error);\n else resolve();\n });\n });\n \n // Initialize the DOP Engine with the React Native database\n return startDopEngine(\n walletSource,\n db as any, // Cast to any since TypeScript doesn't know about our custom implementation\n shouldDebug,\n artifactStore,\n useNativeArtifacts,\n skipMerkletreeScans,\n verboseScanLogging\n );\n};\n"]}
1
+ {"version":3,"file":"react-native-init.js","sourceRoot":"","sources":["../../../../src/services/dop/core/react-native-init.ts"],"names":[],"mappings":";;;AAcA,iCAAwC;AAExC,8DAA8D;AAC9D,IAAI,OAAY,CAAC;AACjB,IAAI;IACF,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAA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CAAC;YAChB,CAAC,CAAC,CAAC;YAEH,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;SACxE;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;SAChE;IACH,CAAC;CACF;AA5HD,gDA4HC;AAED;;;;;;;;;;;;GAYG;AACI,MAAM,yBAAyB,GAAG,KAAK,EAC5C,YAAoB,EACpB,WAAoB,EACpB,aAA4B,EAC5B,kBAAkB,GAAG,IAAI,EACzB,mBAAmB,GAAG,KAAK,EAC3B,kBAAkB,GAAG,KAAK,EAC1B,YAAY,GAAG,eAAe,EACf,EAAE;IACjB,mDAAmD;IACnD,mDAAmD;IAEnD,8CAA8C;IAC9C,iDAAiD;IACjD,yBAAyB;IACzB,gCAAgC;IAChC,sBAAsB;IACtB,QAAQ;IACR,MAAM;IAEN,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,oDAAoD;IAE1E,2DAA2D;IAC3D,OAAO,IAAA,qBAAc,EACnB,YAAY,EACZ,EAAE,EAAG,4EAA4E;IACjF,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC;AAhCW,QAAA,yBAAyB,6BAgCpC","sourcesContent":["/* eslint-disable @typescript-eslint/no-var-requires */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable @typescript-eslint/strict-boolean-expressions */\n/* eslint-disable no-underscore-dangle */\n/* eslint-disable no-console */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable @typescript-eslint/no-floating-promises */\n/* eslint-disable global-require */\n/* eslint-disable no-void */\nimport { ArtifactStore } from '../../artifacts/artifact-store';\nimport { startDopEngine } from './init';\n\n// Use memdown for React Native database - with error handling\nlet memdown: any;\ntry {\n memdown = require('memdown');\n} catch (error) {\n throw new Error(\n 'memdown dependency is required for React Native support. ' +\n 'Please install it with: npm install memdown@^6.1.1'\n );\n}\n\n/**\n * React Native compatible LevelDB implementation using memdown with AsyncStorage persistence.\n * This provides a persistent database solution that works reliably in React Native environments.\n */\nexport class ReactNativeLevelDB {\n private db: any;\n private storageKey: string;\n private AsyncStorage: any;\n\n constructor(name: string) {\n this.storageKey = `leveldb_${name}`;\n this.db = memdown();\n \n // Dynamically import AsyncStorage to avoid bundling issues\n try {\n // Try to require AsyncStorage - this will work in React Native\n this.AsyncStorage = require('@react-native-async-storage/async-storage').default;\n } catch (error) {\n // AsyncStorage not available - this is expected in Node.js test environment\n this.AsyncStorage = null;\n }\n }\n\n // Implement AbstractLevelDOWN interface\n async open(callback: (error?: Error) => void): Promise<void> {\n try {\n // Load persisted data from AsyncStorage (only if available)\n if (this.AsyncStorage) {\n try {\n const persistedData = await this.AsyncStorage.getItem(this.storageKey);\n if (persistedData) {\n const data = JSON.parse(persistedData);\n // Restore data to memdown instance\n for (const [key, value] of Object.entries(data)) {\n await new Promise<void>((resolve, reject) => {\n this.db.put(key, value, (err: any) => {\n if (err) reject(err);\n else resolve();\n });\n });\n }\n }\n } catch (asyncStorageError) {\n // AsyncStorage not available or failed - continue without persistence\n }\n }\n \n // Open the memdown database\n this.db.open(callback);\n } catch (error) {\n callback(error as Error);\n }\n }\n\n close(callback: (error?: Error) => void): void {\n this.db.close(callback);\n }\n\n put(key: any, value: any, callback: (error?: Error) => void): void {\n this.db.put(key, value, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n get(key: any, callback: (error?: Error, value?: any) => void): void {\n this.db.get(key, callback);\n }\n\n del(key: any, callback: (error?: Error) => void): void {\n this.db.del(key, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n batch(operations: any[], callback: (error?: Error) => void): void {\n this.db.batch(operations, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Persist to AsyncStorage in background\n void this._persistData().catch(console.warn);\n }\n callback(err);\n });\n }\n\n iterator(options?: any): any {\n return this.db.iterator(options);\n }\n\n private async _persistData(): Promise<void> {\n if (!this.AsyncStorage) return;\n\n try {\n const data: Record<string, any> = {};\n const iterator = this.db.iterator();\n \n await new Promise<void>((resolve, reject) => {\n const processNext = () => {\n iterator.next((err: any, key: any, value: any) => {\n if (err) {\n iterator.end(() => reject(err));\n return;\n }\n \n if (key === undefined) {\n iterator.end(() => resolve());\n return;\n }\n \n data[key.toString()] = value;\n processNext();\n });\n };\n processNext();\n });\n\n await this.AsyncStorage.setItem(this.storageKey, JSON.stringify(data));\n } catch (error) {\n console.warn('Failed to persist data to AsyncStorage:', error);\n }\n }\n}\n\n/**\n * Initialize DOP Engine specifically for React Native environments.\n * Uses a custom LevelDB implementation that persists data to AsyncStorage.\n * This provides full database persistence while being compatible with React Native.\n * \n * @param walletSource - Name for your wallet implementation (max 16 chars, lowercase)\n * @param shouldDebug - Whether to forward Engine debug logs to Logger\n * @param artifactStore - Persistent store for downloading large artifact files\n * @param useNativeArtifacts - Whether to download native C++ artifacts (should be TRUE for mobile)\n * @param skipMerkletreeScans - Whether to skip merkletree syncs and private balance scans\n * @param verboseScanLogging - Enable verbose logging for scanning operations\n * @param databaseName - Name for the database (used as prefix in AsyncStorage)\n */\nexport const startDopEngineReactNative = async (\n walletSource: string,\n shouldDebug: boolean,\n artifactStore: ArtifactStore,\n useNativeArtifacts = true,\n skipMerkletreeScans = false,\n verboseScanLogging = false,\n databaseName = 'dop-wallet-db'\n): Promise<void> => {\n // Create React Native compatible database instance\n // const db = new ReactNativeLevelDB(databaseName);\n \n // Ensure database is opened before proceeding\n // await new Promise<void>((resolve, reject) => {\n // db.open((error) => {\n // if (error) reject(error);\n // else resolve();\n // });\n // });\n\n const db = memdown(); // Use in-memory DB if AsyncStorage is not available\n \n // Initialize the DOP Engine with the React Native database\n return startDopEngine(\n walletSource,\n db , // Cast to any since TypeScript doesn't know about our custom implementation\n shouldDebug,\n artifactStore,\n useNativeArtifacts,\n skipMerkletreeScans,\n verboseScanLogging\n );\n};\n"]}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * React Native Crypto Provider
3
+ *
4
+ * Provides lightweight alternatives to circomlibjs for React Native environments.
5
+ * Uses poseidon-lite and @zk-kit/eddsa-poseidon for better mobile compatibility.
6
+ */
7
+ /// <reference types="node" />
8
+ /// <reference types="node" />
9
+ import { poseidon2, poseidon3, poseidon4, poseidon5, poseidon6 } from 'poseidon-lite';
10
+ export interface ReactNativeCryptoProvider {
11
+ poseidon: (inputs: bigint[]) => bigint;
12
+ eddsa: {
13
+ signPoseidon: (privateKey: Uint8Array, message: bigint) => unknown;
14
+ prv2pub: (privateKey: Buffer) => unknown;
15
+ verifyPoseidon: (message: bigint, signature: unknown, publicKey: unknown) => boolean;
16
+ };
17
+ }
18
+ /**
19
+ * React Native crypto provider that replaces circomlibjs
20
+ */
21
+ export declare const reactNativeCryptoProvider: ReactNativeCryptoProvider;
22
+ /**
23
+ * Utility functions for React Native crypto operations
24
+ */
25
+ export declare const reactNativeCryptoUtils: {
26
+ derivePublicKey: (privateKey: string | Uint8Array | Buffer) => import("@zk-kit/baby-jubjub").Point<bigint>;
27
+ signMessage: (privateKey: string | Uint8Array | Buffer, message: import("@zk-kit/utils").BigNumberish) => import("@zk-kit/eddsa-poseidon").Signature<bigint>;
28
+ verifySignature: (message: import("@zk-kit/utils").BigNumberish, signature: import("@zk-kit/eddsa-poseidon").Signature<import("@zk-kit/utils").BigNumber>, publicKey: import("@zk-kit/baby-jubjub").Point<import("@zk-kit/utils").BigNumber>) => boolean;
29
+ deriveSecretScalar: (privateKey: string | Uint8Array | Buffer) => bigint;
30
+ packPublicKey: (publicKey: import("@zk-kit/baby-jubjub").Point<import("@zk-kit/utils").BigNumber>) => bigint;
31
+ unpackPublicKey: (publicKey: import("@zk-kit/utils").BigNumberish) => import("@zk-kit/baby-jubjub").Point<bigint>;
32
+ poseidon2: typeof poseidon2;
33
+ poseidon3: typeof poseidon3;
34
+ poseidon4: typeof poseidon4;
35
+ poseidon5: typeof poseidon5;
36
+ poseidon6: typeof poseidon6;
37
+ };
38
+ /**
39
+ * Get the appropriate crypto provider based on environment
40
+ */
41
+ export declare const getCryptoProvider: () => Promise<ReactNativeCryptoProvider | any>;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * React Native Crypto Provider
4
+ *
5
+ * Provides lightweight alternatives to circomlibjs for React Native environments.
6
+ * Uses poseidon-lite and @zk-kit/eddsa-poseidon for better mobile compatibility.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.getCryptoProvider = exports.reactNativeCryptoUtils = exports.reactNativeCryptoProvider = void 0;
33
+ const poseidon_lite_1 = require("poseidon-lite");
34
+ const eddsa_poseidon_1 = require("@zk-kit/eddsa-poseidon");
35
+ const runtime_1 = require("../util/runtime");
36
+ // Allow manual override for testing (handle cases where process might not be available)
37
+ const FORCE_REACT_NATIVE = (() => {
38
+ try {
39
+ return typeof process !== 'undefined' && process.env?.FORCE_REACT_NATIVE_CRYPTO === 'true';
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ })();
45
+ /**
46
+ * Poseidon hash function that automatically selects the right variant based on input length
47
+ */
48
+ const poseidonHash = (inputs) => {
49
+ const length = inputs.length;
50
+ // Convert inputs to string format that poseidon-lite expects
51
+ const stringInputs = inputs.map(input => `0x${input.toString(16)}`);
52
+ let result;
53
+ switch (length) {
54
+ case 2:
55
+ result = (0, poseidon_lite_1.poseidon2)(stringInputs);
56
+ break;
57
+ case 3:
58
+ result = (0, poseidon_lite_1.poseidon3)(stringInputs);
59
+ break;
60
+ case 4:
61
+ result = (0, poseidon_lite_1.poseidon4)(stringInputs);
62
+ break;
63
+ case 5:
64
+ result = (0, poseidon_lite_1.poseidon5)(stringInputs);
65
+ break;
66
+ case 6:
67
+ result = (0, poseidon_lite_1.poseidon6)(stringInputs);
68
+ break;
69
+ default: {
70
+ // For other lengths, use poseidon2 in a recursive manner
71
+ if (length === 1) {
72
+ result = (0, poseidon_lite_1.poseidon2)([stringInputs[0], '0x0']);
73
+ }
74
+ else {
75
+ // For lengths > 6, hash in chunks of 2
76
+ let tempResult = inputs[0];
77
+ for (let i = 1; i < length; i += 1) {
78
+ tempResult = (0, poseidon_lite_1.poseidon2)([`0x${tempResult.toString(16)}`, `0x${inputs[i].toString(16)}`]);
79
+ }
80
+ result = tempResult;
81
+ }
82
+ break;
83
+ }
84
+ }
85
+ return result;
86
+ };
87
+ /**
88
+ * EdDSA operations compatible with circomlibjs interface
89
+ */
90
+ const eddsaOperations = {
91
+ signPoseidon: (privateKey, message) => {
92
+ // Convert Uint8Array to string for @zk-kit/eddsa-poseidon
93
+ const privateKeyHex = Buffer.from(privateKey).toString('hex');
94
+ const messageStr = message.toString();
95
+ const signature = (0, eddsa_poseidon_1.signMessage)(privateKeyHex, messageStr);
96
+ return signature;
97
+ },
98
+ prv2pub: (privateKey) => {
99
+ const privateKeyHex = privateKey.toString('hex');
100
+ const publicKey = (0, eddsa_poseidon_1.derivePublicKey)(privateKeyHex);
101
+ return publicKey;
102
+ },
103
+ verifyPoseidon: (message, signature, publicKey) => {
104
+ const messageStr = message.toString();
105
+ const result = (0, eddsa_poseidon_1.verifySignature)(messageStr, signature, publicKey);
106
+ return result;
107
+ }
108
+ };
109
+ /**
110
+ * React Native crypto provider that replaces circomlibjs
111
+ */
112
+ exports.reactNativeCryptoProvider = {
113
+ poseidon: poseidonHash,
114
+ eddsa: eddsaOperations
115
+ };
116
+ /**
117
+ * Utility functions for React Native crypto operations
118
+ */
119
+ exports.reactNativeCryptoUtils = {
120
+ derivePublicKey: eddsa_poseidon_1.derivePublicKey,
121
+ signMessage: eddsa_poseidon_1.signMessage,
122
+ verifySignature: eddsa_poseidon_1.verifySignature,
123
+ deriveSecretScalar: eddsa_poseidon_1.deriveSecretScalar,
124
+ packPublicKey: eddsa_poseidon_1.packPublicKey,
125
+ unpackPublicKey: eddsa_poseidon_1.unpackPublicKey,
126
+ poseidon2: poseidon_lite_1.poseidon2,
127
+ poseidon3: poseidon_lite_1.poseidon3,
128
+ poseidon4: poseidon_lite_1.poseidon4,
129
+ poseidon5: poseidon_lite_1.poseidon5,
130
+ poseidon6: poseidon_lite_1.poseidon6
131
+ };
132
+ /**
133
+ * Get the appropriate crypto provider based on environment
134
+ */
135
+ const getCryptoProvider = async () => {
136
+ const useReactNative = runtime_1.isReactNative || FORCE_REACT_NATIVE;
137
+ if (useReactNative) {
138
+ // Use React Native crypto provider in React Native environment
139
+ return exports.reactNativeCryptoProvider;
140
+ }
141
+ // Import circomlibjs for non-React Native environments
142
+ const { poseidon, eddsa } = await Promise.resolve().then(() => __importStar(require('circomlibjs')));
143
+ return { poseidon, eddsa };
144
+ };
145
+ exports.getCryptoProvider = getCryptoProvider;
146
+ //# sourceMappingURL=react-native-crypto-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-crypto-provider.js","sourceRoot":"","sources":["../../../../src/services/dop/crypto/react-native-crypto-provider.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iDAAsF;AACtF,2DAOgC;AAChC,6CAAgD;AAEhD,wFAAwF;AACxF,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE;IAC/B,IAAI;QACF,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,yBAAyB,KAAK,MAAM,CAAC;KAC5F;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC,EAAE,CAAC;AAWL;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,MAAgB,EAAU,EAAE;IAChD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE7B,6DAA6D;IAC7D,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAEpE,IAAI,MAAc,CAAC;IAEnB,QAAQ,MAAM,EAAE;QACd,KAAK,CAAC;YACJ,MAAM,GAAG,IAAA,yBAAS,EAAC,YAAY,CAAC,CAAC;YACjC,MAAM;QACR,KAAK,CAAC;YACF,MAAM,GAAG,IAAA,yBAAS,EAAC,YAAY,CAAC,CAAC;YACjC,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,GAAG,IAAA,yBAAS,EAAC,YAAY,CAAC,CAAC;YACjC,MAAM;QACR,KAAK,CAAC;YACJ,MAAM,GAAG,IAAA,yBAAS,EAA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AC;QACjD,MAAM,SAAS,GAAG,IAAA,gCAAe,EAAC,aAAa,CAAC,CAAC;QACjD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,cAAc,EAAE,CAAC,OAAe,EAAE,SAAkB,EAAE,SAAkB,EAAW,EAAE;QACnF,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,IAAA,gCAAe,EAAC,UAAU,EAAE,SAAkD,EAAE,SAAkD,CAAC,CAAC;QACnJ,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC;AAEF;;GAEG;AACU,QAAA,yBAAyB,GAA8B;IAClE,QAAQ,EAAE,YAAY;IACtB,KAAK,EAAE,eAAe;CACvB,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG;IACpC,eAAe,EAAf,gCAAe;IACf,WAAW,EAAX,4BAAW;IACX,eAAe,EAAf,gCAAe;IACf,kBAAkB,EAAlB,mCAAkB;IAClB,aAAa,EAAb,8BAAa;IACb,eAAe,EAAf,gCAAe;IACf,SAAS,EAAT,yBAAS;IACT,SAAS,EAAT,yBAAS;IACT,SAAS,EAAT,yBAAS;IACT,SAAS,EAAT,yBAAS;IACT,SAAS,EAAT,yBAAS;CACV,CAAC;AAEF;;GAEG;AACI,MAAM,iBAAiB,GAAG,KAAK,IAA8C,EAAE;IACpF,MAAM,cAAc,GAAG,uBAAa,IAAI,kBAAkB,CAAC;IAE3D,IAAI,cAAc,EAAE;QAClB,+DAA+D;QAC/D,OAAO,iCAAyB,CAAC;KAClC;IAED,uDAAuD;IACvD,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,wDAAa,aAAa,GAAC,CAAC;IACxD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC,CAAC;AAXW,QAAA,iBAAiB,qBAW5B","sourcesContent":["/**\n * React Native Crypto Provider\n * \n * Provides lightweight alternatives to circomlibjs for React Native environments.\n * Uses poseidon-lite and @zk-kit/eddsa-poseidon for better mobile compatibility.\n */\n\nimport { poseidon2, poseidon3, poseidon4, poseidon5, poseidon6 } from 'poseidon-lite';\nimport {\n derivePublicKey,\n signMessage,\n verifySignature,\n deriveSecretScalar,\n packPublicKey,\n unpackPublicKey\n} from '@zk-kit/eddsa-poseidon';\nimport { isReactNative } from '../util/runtime';\n\n// Allow manual override for testing (handle cases where process might not be available)\nconst FORCE_REACT_NATIVE = (() => {\n try {\n return typeof process !== 'undefined' && process.env?.FORCE_REACT_NATIVE_CRYPTO === 'true';\n } catch {\n return false;\n }\n})();\n\nexport interface ReactNativeCryptoProvider {\n poseidon: (inputs: bigint[]) => bigint;\n eddsa: {\n signPoseidon: (privateKey: Uint8Array, message: bigint) => unknown;\n prv2pub: (privateKey: Buffer) => unknown;\n verifyPoseidon: (message: bigint, signature: unknown, publicKey: unknown) => boolean;\n };\n}\n\n/**\n * Poseidon hash function that automatically selects the right variant based on input length\n */\nconst poseidonHash = (inputs: bigint[]): bigint => {\n const length = inputs.length;\n \n // Convert inputs to string format that poseidon-lite expects\n const stringInputs = inputs.map(input => `0x${input.toString(16)}`);\n \n let result: bigint;\n \n switch (length) {\n case 2:\n result = poseidon2(stringInputs);\n break;\n case 3:\n result = poseidon3(stringInputs);\n break;\n case 4:\n result = poseidon4(stringInputs);\n break;\n case 5:\n result = poseidon5(stringInputs);\n break;\n case 6:\n result = poseidon6(stringInputs);\n break;\n default: {\n // For other lengths, use poseidon2 in a recursive manner\n if (length === 1) {\n result = poseidon2([stringInputs[0], '0x0']);\n } else {\n // For lengths > 6, hash in chunks of 2\n let tempResult = inputs[0];\n for (let i = 1; i < length; i += 1) {\n tempResult = poseidon2([`0x${tempResult.toString(16)}`, `0x${inputs[i].toString(16)}`]);\n }\n result = tempResult;\n }\n break;\n }\n }\n \n return result;\n};\n\n/**\n * EdDSA operations compatible with circomlibjs interface\n */\nconst eddsaOperations = {\n signPoseidon: (privateKey: Uint8Array, message: bigint): unknown => {\n // Convert Uint8Array to string for @zk-kit/eddsa-poseidon\n const privateKeyHex = Buffer.from(privateKey).toString('hex');\n const messageStr = message.toString();\n \n const signature = signMessage(privateKeyHex, messageStr);\n return signature;\n },\n \n prv2pub: (privateKey: Buffer): unknown => {\n const privateKeyHex = privateKey.toString('hex');\n const publicKey = derivePublicKey(privateKeyHex);\n return publicKey;\n },\n \n verifyPoseidon: (message: bigint, signature: unknown, publicKey: unknown): boolean => {\n const messageStr = message.toString();\n const result = verifySignature(messageStr, signature as Parameters<typeof verifySignature>[1], publicKey as Parameters<typeof verifySignature>[2]);\n return result;\n }\n};\n\n/**\n * React Native crypto provider that replaces circomlibjs\n */\nexport const reactNativeCryptoProvider: ReactNativeCryptoProvider = {\n poseidon: poseidonHash,\n eddsa: eddsaOperations\n};\n\n/**\n * Utility functions for React Native crypto operations\n */\nexport const reactNativeCryptoUtils = {\n derivePublicKey,\n signMessage,\n verifySignature,\n deriveSecretScalar,\n packPublicKey,\n unpackPublicKey,\n poseidon2,\n poseidon3,\n poseidon4,\n poseidon5,\n poseidon6\n};\n\n/**\n * Get the appropriate crypto provider based on environment\n */\nexport const getCryptoProvider = async (): Promise<ReactNativeCryptoProvider | any> => {\n const useReactNative = isReactNative || FORCE_REACT_NATIVE;\n \n if (useReactNative) {\n // Use React Native crypto provider in React Native environment\n return reactNativeCryptoProvider;\n } \n \n // Import circomlibjs for non-React Native environments\n const { poseidon, eddsa } = await import('circomlibjs');\n return { poseidon, eddsa };\n};"]}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * React Native Rapidsnark Prover Integration
3
+ *
4
+ * This module provides an alternative proof generation system using rapidsnark
5
+ * for React Native environments where circomlibjs/snarkjs may not work optimally.
6
+ */
7
+ interface RapidsnarkProof {
8
+ proof: {
9
+ a: string[];
10
+ b: string[][];
11
+ c: string[];
12
+ };
13
+ pub_signals: string[];
14
+ }
15
+ /**
16
+ * Initialize rapidsnark module for React Native
17
+ */
18
+ export declare const initializeRapidsnark: () => Promise<boolean>;
19
+ /**
20
+ * Check if rapidsnark is available and initialized
21
+ */
22
+ export declare const isRapidsnarkAvailable: () => boolean;
23
+ /**
24
+ * Generate proof using rapidsnark (React Native only)
25
+ */
26
+ export declare const generateProofWithRapidsnark: (zkeyPath: string, witnessBase64: string) => Promise<RapidsnarkProof>;
27
+ /**
28
+ * Verify proof using rapidsnark (React Native only)
29
+ */
30
+ export declare const verifyProofWithRapidsnark: (proof: unknown, publicSignals: unknown, verificationKeyBase64: string) => Promise<boolean>;
31
+ /**
32
+ * Get public buffer size for zkey (React Native only)
33
+ */
34
+ export declare const getPublicBufferSize: (zkeyPath: string) => Promise<number>;
35
+ /**
36
+ * Test rapidsnark functionality
37
+ */
38
+ export declare const testRapidsnark: () => Promise<boolean>;
39
+ /**
40
+ * React Native-specific prover that uses rapidsnark when available
41
+ */
42
+ export declare class ReactNativeProver {
43
+ private initialized;
44
+ initialize(): Promise<void>;
45
+ generateProof(zkeyPath: string, witnessBase64: string): Promise<unknown>;
46
+ verifyProof(proof: unknown, publicSignals: unknown, verificationKey: string): Promise<boolean>;
47
+ }
48
+ export declare const reactNativeProver: ReactNativeProver;
49
+ export {};
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * React Native Rapidsnark Prover Integration
4
+ *
5
+ * This module provides an alternative proof generation system using rapidsnark
6
+ * for React Native environments where circomlibjs/snarkjs may not work optimally.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || function (mod) {
25
+ if (mod && mod.__esModule) return mod;
26
+ var result = {};
27
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
+ __setModuleDefault(result, mod);
29
+ return result;
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ exports.reactNativeProver = exports.ReactNativeProver = exports.testRapidsnark = exports.getPublicBufferSize = exports.verifyProofWithRapidsnark = exports.generateProofWithRapidsnark = exports.isRapidsnarkAvailable = exports.initializeRapidsnark = void 0;
33
+ const runtime_1 = require("../util/runtime");
34
+ let rapidsnarkModule = null;
35
+ /**
36
+ * Initialize rapidsnark module for React Native
37
+ */
38
+ const initializeRapidsnark = async () => {
39
+ var _a;
40
+ if (!runtime_1.isReactNative) {
41
+ console.log('๐Ÿ–ฅ๏ธ Not in React Native environment, skipping rapidsnark initialization');
42
+ return false;
43
+ }
44
+ try {
45
+ console.log('๐Ÿ“ฑ Initializing rapidsnark for React Native...');
46
+ // Dynamic import with try-catch for optional dependency
47
+ let rapidsnarkImport;
48
+ try {
49
+ // Use string literal to avoid TypeScript compilation errors when module is not installed
50
+ const moduleName = '@iden3/react-native-rapidsnark';
51
+ rapidsnarkImport = await (_a = moduleName, Promise.resolve().then(() => __importStar(require(_a))));
52
+ }
53
+ catch (importError) {
54
+ console.log('๐Ÿ“ @iden3/react-native-rapidsnark not available:', String(importError));
55
+ return false;
56
+ }
57
+ const { groth16Prove, groth16Verify, groth16PublicBufferSize } = rapidsnarkImport;
58
+ rapidsnarkModule = {
59
+ groth16Prove,
60
+ groth16Verify,
61
+ groth16PublicBufferSize
62
+ };
63
+ console.log('โœ… Rapidsnark initialized successfully');
64
+ return true;
65
+ }
66
+ catch (error) {
67
+ console.warn('โš ๏ธ Rapidsnark not available:', error);
68
+ console.log('๐Ÿ’ก Install @iden3/react-native-rapidsnark for React Native proof generation');
69
+ return false;
70
+ }
71
+ };
72
+ exports.initializeRapidsnark = initializeRapidsnark;
73
+ /**
74
+ * Check if rapidsnark is available and initialized
75
+ */
76
+ const isRapidsnarkAvailable = () => {
77
+ return runtime_1.isReactNative && rapidsnarkModule !== null;
78
+ };
79
+ exports.isRapidsnarkAvailable = isRapidsnarkAvailable;
80
+ /**
81
+ * Generate proof using rapidsnark (React Native only)
82
+ */
83
+ const generateProofWithRapidsnark = async (zkeyPath, witnessBase64) => {
84
+ if (!(0, exports.isRapidsnarkAvailable)()) {
85
+ throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');
86
+ }
87
+ try {
88
+ console.log('๐Ÿ”„ Generating proof with rapidsnark...');
89
+ if (!rapidsnarkModule) {
90
+ throw new Error('Rapidsnark module not initialized');
91
+ }
92
+ const proof = await rapidsnarkModule.groth16Prove(zkeyPath, witnessBase64);
93
+ console.log('โœ… Proof generated successfully with rapidsnark');
94
+ return proof;
95
+ }
96
+ catch (error) {
97
+ console.error('โŒ Rapidsnark proof generation failed:', String(error));
98
+ throw new Error(`Rapidsnark proof generation failed: ${String(error)}`);
99
+ }
100
+ };
101
+ exports.generateProofWithRapidsnark = generateProofWithRapidsnark;
102
+ /**
103
+ * Verify proof using rapidsnark (React Native only)
104
+ */
105
+ const verifyProofWithRapidsnark = async (proof, publicSignals, verificationKeyBase64) => {
106
+ if (!(0, exports.isRapidsnarkAvailable)()) {
107
+ throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');
108
+ }
109
+ try {
110
+ console.log('๐Ÿ” Verifying proof with rapidsnark...');
111
+ if (!rapidsnarkModule) {
112
+ throw new Error('Rapidsnark module not initialized');
113
+ }
114
+ const isValid = rapidsnarkModule.groth16Verify(proof, publicSignals, verificationKeyBase64);
115
+ console.log('โœ… Proof verification completed:', isValid);
116
+ return isValid;
117
+ }
118
+ catch (error) {
119
+ console.error('โŒ Rapidsnark proof verification failed:', String(error));
120
+ throw new Error(`Rapidsnark proof verification failed: ${String(error)}`);
121
+ }
122
+ };
123
+ exports.verifyProofWithRapidsnark = verifyProofWithRapidsnark;
124
+ /**
125
+ * Get public buffer size for zkey (React Native only)
126
+ */
127
+ const getPublicBufferSize = async (zkeyPath) => {
128
+ if (!(0, exports.isRapidsnarkAvailable)()) {
129
+ throw new Error('Rapidsnark is not available. Please ensure @iden3/react-native-rapidsnark is installed and this is running in React Native.');
130
+ }
131
+ try {
132
+ if (!rapidsnarkModule) {
133
+ throw new Error('Rapidsnark module not initialized');
134
+ }
135
+ const bufferSize = await rapidsnarkModule.groth16PublicBufferSize(zkeyPath);
136
+ console.log('๐Ÿ“ Public buffer size calculated:', bufferSize);
137
+ return bufferSize;
138
+ }
139
+ catch (error) {
140
+ console.error('โŒ Failed to calculate public buffer size:', String(error));
141
+ throw new Error(`Failed to calculate public buffer size: ${String(error)}`);
142
+ }
143
+ };
144
+ exports.getPublicBufferSize = getPublicBufferSize;
145
+ /**
146
+ * Test rapidsnark functionality
147
+ */
148
+ const testRapidsnark = async () => {
149
+ try {
150
+ const initialized = await (0, exports.initializeRapidsnark)();
151
+ if (!initialized) {
152
+ console.log('โ„น๏ธ Rapidsnark not available in this environment');
153
+ return false;
154
+ }
155
+ console.log('๐Ÿงช Testing rapidsnark functionality...');
156
+ // Note: This is just initialization testing
157
+ // Actual proof generation requires circuit files (.zkey, .wtns)
158
+ console.log('โœ… Rapidsnark is ready for proof generation');
159
+ return true;
160
+ }
161
+ catch (error) {
162
+ console.error('โŒ Rapidsnark test failed:', error);
163
+ return false;
164
+ }
165
+ };
166
+ exports.testRapidsnark = testRapidsnark;
167
+ /**
168
+ * React Native-specific prover that uses rapidsnark when available
169
+ */
170
+ class ReactNativeProver {
171
+ initialized = false;
172
+ async initialize() {
173
+ if (this.initialized)
174
+ return;
175
+ if (runtime_1.isReactNative) {
176
+ await (0, exports.initializeRapidsnark)();
177
+ }
178
+ this.initialized = true;
179
+ }
180
+ async generateProof(zkeyPath, witnessBase64) {
181
+ await this.initialize();
182
+ if ((0, exports.isRapidsnarkAvailable)()) {
183
+ return (0, exports.generateProofWithRapidsnark)(zkeyPath, witnessBase64);
184
+ }
185
+ // Fallback to DOP Engine's prover
186
+ console.log('๐Ÿ“ Using DOP Engine prover as fallback');
187
+ throw new Error('Rapidsnark not available. Please ensure @iden3/react-native-rapidsnark is installed for React Native proof generation.');
188
+ }
189
+ async verifyProof(proof, publicSignals, verificationKey) {
190
+ await this.initialize();
191
+ if ((0, exports.isRapidsnarkAvailable)()) {
192
+ return (0, exports.verifyProofWithRapidsnark)(proof, publicSignals, verificationKey);
193
+ }
194
+ // Fallback to DOP Engine's verifier
195
+ console.log('๐Ÿ“ Using DOP Engine verifier as fallback');
196
+ throw new Error('Rapidsnark not available. Please ensure @iden3/react-native-rapidsnark is installed for React Native proof verification.');
197
+ }
198
+ }
199
+ exports.ReactNativeProver = ReactNativeProver;
200
+ // Export singleton instance
201
+ exports.reactNativeProver = new ReactNativeProver();
202
+ //# sourceMappingURL=react-native-rapidsnark-prover.js.map