dop-wallet-v6 1.3.1 → 1.3.31

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 (124) hide show
  1. package/.eslintrc.js +5 -0
  2. package/dist/services/dop/core/react-native-init.d.ts +2 -2
  3. package/dist/services/dop/core/react-native-init.js +36 -15
  4. package/dist/services/dop/core/react-native-init.js.map +1 -1
  5. package/dist/services/dop/crypto/react-native-crypto-provider.js +4 -2
  6. package/dist/services/dop/crypto/react-native-crypto-provider.js.map +1 -1
  7. package/dist/services/dop/wallets/balances.js +49 -2
  8. package/dist/services/dop/wallets/balances.js.map +1 -1
  9. package/dist/services/dop/wallets/wallets.js +12 -17
  10. package/dist/services/dop/wallets/wallets.js.map +1 -1
  11. package/package.json +6 -1
  12. package/patches/dop-engine-v3+1.4.9.patch +55 -33
  13. package/dist/__tests__/index.test.d.ts +0 -1
  14. package/dist/__tests__/index.test.js +0 -13
  15. package/dist/__tests__/index.test.js.map +0 -1
  16. package/dist/services/artifacts/__tests__/artifact-downloader.test.d.ts +0 -1
  17. package/dist/services/artifacts/__tests__/artifact-downloader.test.js +0 -70
  18. package/dist/services/artifacts/__tests__/artifact-downloader.test.js.map +0 -1
  19. package/dist/services/dop/__tests__/integration.test.d.ts +0 -1
  20. package/dist/services/dop/__tests__/integration.test.js +0 -378
  21. package/dist/services/dop/__tests__/integration.test.js.map +0 -1
  22. package/dist/services/dop/core/__tests__/engine.test.d.ts +0 -1
  23. package/dist/services/dop/core/__tests__/engine.test.js +0 -30
  24. package/dist/services/dop/core/__tests__/engine.test.js.map +0 -1
  25. package/dist/services/dop/core/__tests__/providers.test.d.ts +0 -1
  26. package/dist/services/dop/core/__tests__/providers.test.js +0 -69
  27. package/dist/services/dop/core/__tests__/providers.test.js.map +0 -1
  28. package/dist/services/dop/dop-txids/__tests__/dop-txid-sync-graph-v2.test.d.ts +0 -1
  29. package/dist/services/dop/dop-txids/__tests__/dop-txid-sync-graph-v2.test.js +0 -168
  30. package/dist/services/dop/dop-txids/__tests__/dop-txid-sync-graph-v2.test.js.map +0 -1
  31. package/dist/services/dop/history/__tests__/transaction-history.test.d.ts +0 -0
  32. package/dist/services/dop/history/__tests__/transaction-history.test.js +0 -2
  33. package/dist/services/dop/history/__tests__/transaction-history.test.js.map +0 -1
  34. package/dist/services/dop/profile/__tests__/profile-manager.test.d.ts +0 -1
  35. package/dist/services/dop/profile/__tests__/profile-manager.test.js +0 -170
  36. package/dist/services/dop/profile/__tests__/profile-manager.test.js.map +0 -1
  37. package/dist/services/dop/profile/__tests__/selective-transparency.test.d.ts +0 -1
  38. package/dist/services/dop/profile/__tests__/selective-transparency.test.js +0 -256
  39. package/dist/services/dop/profile/__tests__/selective-transparency.test.js.map +0 -1
  40. package/dist/services/dop/profile/__tests__/storage.test.d.ts +0 -1
  41. package/dist/services/dop/profile/__tests__/storage.test.js +0 -174
  42. package/dist/services/dop/profile/__tests__/storage.test.js.map +0 -1
  43. package/dist/services/dop/quick-sync/V2/__tests__/quick-sync-events-graph-v2.test.d.ts +0 -1
  44. package/dist/services/dop/quick-sync/V2/__tests__/quick-sync-events-graph-v2.test.js +0 -126
  45. package/dist/services/dop/quick-sync/V2/__tests__/quick-sync-events-graph-v2.test.js.map +0 -1
  46. package/dist/services/dop/quick-sync/V3/__tests__/quick-sync-events-graph-v3.test.d.ts +0 -1
  47. package/dist/services/dop/quick-sync/V3/__tests__/quick-sync-events-graph-v3.test.js +0 -63
  48. package/dist/services/dop/quick-sync/V3/__tests__/quick-sync-events-graph-v3.test.js.map +0 -1
  49. package/dist/services/dop/util/__tests__/bytes-util.test.d.ts +0 -1
  50. package/dist/services/dop/util/__tests__/bytes-util.test.js +0 -23
  51. package/dist/services/dop/util/__tests__/bytes-util.test.js.map +0 -1
  52. package/dist/services/dop/util/__tests__/crypto-util.test.d.ts +0 -1
  53. package/dist/services/dop/util/__tests__/crypto-util.test.js +0 -62
  54. package/dist/services/dop/util/__tests__/crypto-util.test.js.map +0 -1
  55. package/dist/services/dop/wallets/__tests__/balances-live.test.d.ts +0 -1
  56. package/dist/services/dop/wallets/__tests__/balances-live.test.js +0 -58
  57. package/dist/services/dop/wallets/__tests__/balances-live.test.js.map +0 -1
  58. package/dist/services/dop/wallets/__tests__/balances-update.test.d.ts +0 -1
  59. package/dist/services/dop/wallets/__tests__/balances-update.test.js +0 -90
  60. package/dist/services/dop/wallets/__tests__/balances-update.test.js.map +0 -1
  61. package/dist/services/dop/wallets/__tests__/balances.test.d.ts +0 -1
  62. package/dist/services/dop/wallets/__tests__/balances.test.js +0 -59
  63. package/dist/services/dop/wallets/__tests__/balances.test.js.map +0 -1
  64. package/dist/services/dop/wallets/__tests__/wallets.test.d.ts +0 -1
  65. package/dist/services/dop/wallets/__tests__/wallets.test.js +0 -80
  66. package/dist/services/dop/wallets/__tests__/wallets.test.js.map +0 -1
  67. package/dist/services/ethers/__tests__/ethers-util.test.d.ts +0 -1
  68. package/dist/services/ethers/__tests__/ethers-util.test.js +0 -19
  69. package/dist/services/ethers/__tests__/ethers-util.test.js.map +0 -1
  70. package/dist/services/transactions/__tests__/json/formatted-relay-adapt-error-logs.json +0 -216
  71. package/dist/services/transactions/__tests__/proof-cache.test.d.ts +0 -1
  72. package/dist/services/transactions/__tests__/proof-cache.test.js +0 -128
  73. package/dist/services/transactions/__tests__/proof-cache.test.js.map +0 -1
  74. package/dist/services/transactions/__tests__/tx-cross-contract-calls.test.d.ts +0 -1
  75. package/dist/services/transactions/__tests__/tx-cross-contract-calls.test.js +0 -385
  76. package/dist/services/transactions/__tests__/tx-cross-contract-calls.test.js.map +0 -1
  77. package/dist/services/transactions/__tests__/tx-decrypt.test.d.ts +0 -0
  78. package/dist/services/transactions/__tests__/tx-decrypt.test.js +0 -2
  79. package/dist/services/transactions/__tests__/tx-decrypt.test.js.map +0 -1
  80. package/dist/services/transactions/__tests__/tx-encrypt-base-token.test.d.ts +0 -1
  81. package/dist/services/transactions/__tests__/tx-encrypt-base-token.test.js +0 -101
  82. package/dist/services/transactions/__tests__/tx-encrypt-base-token.test.js.map +0 -1
  83. package/dist/services/transactions/__tests__/tx-encrypt.test.d.ts +0 -0
  84. package/dist/services/transactions/__tests__/tx-encrypt.test.js +0 -2
  85. package/dist/services/transactions/__tests__/tx-encrypt.test.js.map +0 -1
  86. package/dist/services/transactions/__tests__/tx-gas-details.test.d.ts +0 -1
  87. package/dist/services/transactions/__tests__/tx-gas-details.test.js +0 -112
  88. package/dist/services/transactions/__tests__/tx-gas-details.test.js.map +0 -1
  89. package/dist/services/transactions/__tests__/tx-notes.test.d.ts +0 -1
  90. package/dist/services/transactions/__tests__/tx-notes.test.js +0 -193
  91. package/dist/services/transactions/__tests__/tx-notes.test.js.map +0 -1
  92. package/dist/services/transactions/__tests__/tx-proof-transfer-with-data.test.d.ts +0 -1
  93. package/dist/services/transactions/__tests__/tx-proof-transfer-with-data.test.js +0 -50
  94. package/dist/services/transactions/__tests__/tx-proof-transfer-with-data.test.js.map +0 -1
  95. package/dist/services/transactions/__tests__/tx-transfer.test.d.ts +0 -1
  96. package/dist/services/transactions/__tests__/tx-transfer.test.js +0 -280
  97. package/dist/services/transactions/__tests__/tx-transfer.test.js.map +0 -1
  98. package/dist/tests/balances.test.d.ts +0 -1
  99. package/dist/tests/balances.test.js +0 -419
  100. package/dist/tests/balances.test.js.map +0 -1
  101. package/dist/tests/helper.test.d.ts +0 -3
  102. package/dist/tests/helper.test.js +0 -16
  103. package/dist/tests/helper.test.js.map +0 -1
  104. package/dist/tests/mocks.test.d.ts +0 -50
  105. package/dist/tests/mocks.test.js +0 -202
  106. package/dist/tests/mocks.test.js.map +0 -1
  107. package/dist/tests/poi/test-wallet-poi-requester.test.d.ts +0 -10
  108. package/dist/tests/poi/test-wallet-poi-requester.test.js +0 -15
  109. package/dist/tests/poi/test-wallet-poi-requester.test.js.map +0 -1
  110. package/dist/tests/setup.test.d.ts +0 -9
  111. package/dist/tests/setup.test.js +0 -110
  112. package/dist/tests/setup.test.js.map +0 -1
  113. package/dist/tests/stubs/engine-stubs.test.d.ts +0 -7
  114. package/dist/tests/stubs/engine-stubs.test.js +0 -75
  115. package/dist/tests/stubs/engine-stubs.test.js.map +0 -1
  116. package/dist/utils/__tests__/blocked-address.test.d.ts +0 -1
  117. package/dist/utils/__tests__/blocked-address.test.js +0 -23
  118. package/dist/utils/__tests__/blocked-address.test.js.map +0 -1
  119. package/dist/utils/__tests__/logger.test.d.ts +0 -1
  120. package/dist/utils/__tests__/logger.test.js +0 -28
  121. package/dist/utils/__tests__/logger.test.js.map +0 -1
  122. package/dist/utils/__tests__/utils.test.d.ts +0 -1
  123. package/dist/utils/__tests__/utils.test.js +0 -21
  124. package/dist/utils/__tests__/utils.test.js.map +0 -1
package/.eslintrc.js CHANGED
@@ -67,6 +67,11 @@ module.exports = {
67
67
  rules: {
68
68
  '@typescript-eslint/no-explicit-any': 0,
69
69
  '@typescript-eslint/no-unsafe-member-access': 0,
70
+ 'import/no-extraneous-dependencies': 0,
71
+ 'no-console': 0,
72
+ '@typescript-eslint/no-unused-vars': 0,
73
+ 'no-useless-concat': 0,
74
+ '@typescript-eslint/await-thenable': 0,
70
75
  },
71
76
  },
72
77
  ],
@@ -32,11 +32,11 @@ export declare class ReactNativeLevelDB {
32
32
  * This provides full database persistence while being compatible with React Native.
33
33
  *
34
34
  * @param walletSource - Name for your wallet implementation (max 16 chars, lowercase)
35
- * @param shouldDebug - Whether to forward Engine debug logs to Logger
35
+ * @param shouldDebug - Whether to forward Engine debug logs to console
36
36
  * @param artifactStore - Persistent store for downloading large artifact files
37
37
  * @param useNativeArtifacts - Whether to download native C++ artifacts (should be TRUE for mobile)
38
38
  * @param skipMerkletreeScans - Whether to skip merkletree syncs and private balance scans
39
39
  * @param verboseScanLogging - Enable verbose logging for scanning operations
40
40
  * @param databaseName - Name for the database (used as prefix in AsyncStorage)
41
41
  */
42
- export declare const startDopEngineReactNative: (walletSource: string, shouldDebug: boolean, artifactStore: ArtifactStore, useNativeArtifacts?: boolean, skipMerkletreeScans?: boolean, verboseScanLogging?: boolean, databaseName?: string) => Promise<void>;
42
+ export declare const startDopEngineReactNative: (walletSource: string, shouldDebug: boolean, artifactStore: ArtifactStore, useNativeArtifacts: boolean, skipMerkletreeScans: boolean, verboseScanLogging: boolean, databaseName?: string) => Promise<void>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.startDopEngineReactNative = exports.ReactNativeLevelDB = void 0;
4
4
  const init_1 = require("./init");
5
+ const logger_1 = require("../../../utils/logger");
5
6
  // Use memdown for React Native database - with error handling
6
7
  let memdown;
7
8
  try {
@@ -99,29 +100,38 @@ class ReactNativeLevelDB {
99
100
  catch (jsonError) {
100
101
  throw new Error(`JSON parse failed: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
101
102
  }
102
- // Restore data to memdown instance
103
+ // Restore data to memdown instance using batch operations
103
104
  const keys = Object.keys(data);
104
105
  console.log(`📦 Restoring ${keys.length} entries to database...`);
106
+ // Prepare batch operations
107
+ const operations = [];
105
108
  for (const [key, value] of Object.entries(data)) {
106
- await new Promise((resolve, reject) => {
107
- // Restore Buffer/Uint8Array types from base64 with type marker
108
- let restoredValue = value;
109
- if (value && typeof value === 'object' && '__type' in value) {
110
- const typedValue = value;
111
- if (typedValue.__type === 'Buffer' && typeof typedValue.data === 'string') {
112
- restoredValue = Buffer.from(typedValue.data, 'base64');
113
- }
114
- else if (typedValue.__type === 'Uint8Array' && typeof typedValue.data === 'string') {
115
- restoredValue = new Uint8Array(Buffer.from(typedValue.data, 'base64'));
116
- }
109
+ // Restore Buffer/Uint8Array types from base64 with type marker
110
+ let restoredValue = value;
111
+ if (value && typeof value === 'object' && '__type' in value) {
112
+ const typedValue = value;
113
+ if (typedValue.__type === 'Buffer' && typeof typedValue.data === 'string') {
114
+ restoredValue = Buffer.from(typedValue.data, 'base64');
115
+ }
116
+ else if (typedValue.__type === 'Uint8Array' && typeof typedValue.data === 'string') {
117
+ restoredValue = new Uint8Array(Buffer.from(typedValue.data, 'base64'));
117
118
  }
118
- this.db.put(key, restoredValue, (err) => {
119
+ }
120
+ operations.push({ type: 'put', key, value: restoredValue });
121
+ }
122
+ // Restore in batches of 500 for better performance
123
+ const batchSize = 500;
124
+ for (let i = 0; i < operations.length; i += batchSize) {
125
+ const batch = operations.slice(i, i + batchSize);
126
+ await new Promise((resolve, reject) => {
127
+ this.db.batch(batch, (err) => {
119
128
  if (err)
120
129
  reject(err);
121
130
  else
122
131
  resolve();
123
132
  });
124
133
  });
134
+ console.log(`📦 Restored ${Math.min(i + batchSize, operations.length)}/${operations.length} entries...`);
125
135
  }
126
136
  console.log('✅ Successfully restored database from AsyncStorage');
127
137
  }
@@ -552,14 +562,14 @@ exports.ReactNativeLevelDB = ReactNativeLevelDB;
552
562
  * This provides full database persistence while being compatible with React Native.
553
563
  *
554
564
  * @param walletSource - Name for your wallet implementation (max 16 chars, lowercase)
555
- * @param shouldDebug - Whether to forward Engine debug logs to Logger
565
+ * @param shouldDebug - Whether to forward Engine debug logs to console
556
566
  * @param artifactStore - Persistent store for downloading large artifact files
557
567
  * @param useNativeArtifacts - Whether to download native C++ artifacts (should be TRUE for mobile)
558
568
  * @param skipMerkletreeScans - Whether to skip merkletree syncs and private balance scans
559
569
  * @param verboseScanLogging - Enable verbose logging for scanning operations
560
570
  * @param databaseName - Name for the database (used as prefix in AsyncStorage)
561
571
  */
562
- const startDopEngineReactNative = async (walletSource, shouldDebug, artifactStore, useNativeArtifacts = true, skipMerkletreeScans = false, verboseScanLogging = false, databaseName = 'dop-wallet-db') => {
572
+ const startDopEngineReactNative = async (walletSource, shouldDebug, artifactStore, useNativeArtifacts, skipMerkletreeScans, verboseScanLogging, databaseName = 'dop-wallet-db') => {
563
573
  // Create React Native compatible database instance with AsyncStorage persistence
564
574
  const db = new ReactNativeLevelDB(databaseName);
565
575
  // Ensure database is opened before proceeding
@@ -571,6 +581,17 @@ const startDopEngineReactNative = async (walletSource, shouldDebug, artifactStor
571
581
  resolve();
572
582
  });
573
583
  });
584
+ // Set up console logging for React Native
585
+ if (shouldDebug) {
586
+ (0, logger_1.setLoggers)((msg) => console.log(`[DOP Wallet] ${msg}`), (err) => {
587
+ if (err instanceof Error) {
588
+ console.error(`[DOP Wallet Error] ${err.message}`, err);
589
+ }
590
+ else {
591
+ console.error(`[DOP Wallet Error] ${err}`);
592
+ }
593
+ });
594
+ }
574
595
  // Initialize the DOP Engine with the React Native database
575
596
  return (0, init_1.startDopEngine)(walletSource, db, // Cast to any since TypeScript doesn't know about our custom implementation
576
597
  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,MAAa,kBAAkB;IACrB,EAAE,CAAM;IACR,UAAU,CAAS;IACnB,YAAY,CAAM;IAClB,cAAc,GAAyC,IAAI,CAAC;IAC5D,OAAO,GAAG,KAAK,CAAC;IAExB,YAAY,IAAY;QACtB,IAAI,CAAC,UAAU,GAAG,WAAW,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;QAEpB,2DAA2D;QAC3D,IAAI;YACF,+DAA+D;YAC/D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC,OAAO,CAAC;SAClF;QAAC,OAAO,KAAK,EAAE;YACd,4EAA4E;YAC5E,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;IAED,wCAAwC;IACxC,K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BAAkB,GAAG,KAAK,EAC1B,YAAY,GAAG,eAAe,EACf,EAAE;IACjB,iFAAiF;IACjF,MAAM,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,KAAa,EAAE,EAAE;YACxB,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 */\nexport class ReactNativeLevelDB {\n private db: any;\n private storageKey: string;\n private AsyncStorage: any;\n private persistTimeout: ReturnType<typeof setTimeout> | null = null;\n private isDirty = false;\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(callbackOrOptions?: any, callback?: (error?: Error) => void): Promise<void> {\n // Handle both open(callback) and open(options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof callbackOrOptions === 'function') {\n // open(callback) signature\n cb = callbackOrOptions;\n } else if (typeof callback === 'function') {\n // open(options, callback) signature\n cb = callback;\n } else {\n // No callback provided - this shouldn't happen in AbstractLevelDOWN\n throw new Error('No callback provided to open method');\n }\n\n try {\n // Load persisted data from AsyncStorage (only if available)\n if (this.AsyncStorage) {\n try {\n let persistedData: string | null = null;\n \n // Check if data is stored in chunks\n const chunksCount = await this.AsyncStorage.getItem(`${this.storageKey}_chunks`);\n \n if (chunksCount) {\n console.log(`📦 Loading database from ${String(chunksCount)} chunks...`);\n // Reassemble from chunks\n const chunks: string[] = [];\n const count = parseInt(chunksCount, 10);\n \n if (Number.isNaN(count) || count < 0 || count > 1000) {\n throw new Error(`Invalid chunk count: ${String(chunksCount)}`);\n }\n \n for (let i = 0; i < count; i += 1) {\n const chunk = await this.AsyncStorage.getItem(`${this.storageKey}_chunk_${i}`);\n if (chunk) {\n chunks.push(chunk);\n } else {\n console.warn(`⚠️ Missing chunk ${i} of ${count}, data may be incomplete`);\n }\n }\n \n if (chunks.length === 0) {\n throw new Error('No chunks found, but chunk count was set');\n }\n \n persistedData = chunks.join('');\n console.log(`📦 Reassembled ${chunks.length}/${count} chunks (${(persistedData.length / 1024 / 1024).toFixed(2)}MB)`);\n } else {\n // Try to get data directly\n persistedData = await this.AsyncStorage.getItem(this.storageKey);\n if (persistedData) {\n console.log(`📦 Loading database directly (${(persistedData.length / 1024).toFixed(2)}KB)`);\n }\n }\n \n if (persistedData) {\n // Validate JSON before parsing\n if (!persistedData.trim().startsWith('{') || !persistedData.trim().endsWith('}')) {\n throw new Error('Persisted data does not look like valid JSON (missing braces)');\n }\n \n let data: Record<string, any>;\n try {\n data = JSON.parse(persistedData);\n } catch (jsonError) {\n throw new Error(`JSON parse failed: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);\n }\n \n // Restore data to memdown instance\n const keys = Object.keys(data);\n console.log(`📦 Restoring ${keys.length} entries to database...`);\n \n for (const [key, value] of Object.entries(data)) {\n await new Promise<void>((resolve, reject) => {\n // Restore Buffer/Uint8Array types from base64 with type marker\n let restoredValue = value;\n if (value && typeof value === 'object' && '__type' in value) {\n const typedValue = value as { __type: string; data: string };\n if (typedValue.__type === 'Buffer' && typeof typedValue.data === 'string') {\n restoredValue = Buffer.from(typedValue.data, 'base64');\n } else if (typedValue.__type === 'Uint8Array' && typeof typedValue.data === 'string') {\n restoredValue = new Uint8Array(Buffer.from(typedValue.data, 'base64'));\n }\n }\n \n this.db.put(key, restoredValue, (err: any) => {\n if (err) reject(err);\n else resolve();\n });\n });\n }\n console.log('✅ Successfully restored database from AsyncStorage');\n } else {\n console.log('ℹ️ No persisted data found, starting with empty database');\n }\n } catch (asyncStorageError) {\n console.error('❌ Failed to load from AsyncStorage, clearing corrupted data and starting fresh:', asyncStorageError);\n \n // Clear corrupted data\n try {\n await this.AsyncStorage.removeItem(this.storageKey);\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Try to remove chunks (up to 100 chunks max)\n for (let i = 0; i < 100; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (exists) {\n await this.AsyncStorage.removeItem(chunkKey);\n } else {\n break; // No more chunks\n }\n }\n console.log('🧹 Cleared corrupted AsyncStorage data');\n } catch (clearError) {\n console.warn('⚠️ Failed to clear corrupted data:', clearError);\n }\n }\n }\n \n // Open the memdown database\n this.db.open(cb);\n } catch (error) {\n cb(error as Error);\n }\n }\n\n close(callback: (error?: Error) => void): void {\n // Clear pending persistence timeout\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n this.persistTimeout = null;\n }\n \n // Force immediate persistence before closing if dirty\n if (this.isDirty && this.AsyncStorage) {\n console.log('💾 Persisting database before close...');\n this.isDirty = false;\n this._persistData()\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n .then(() => {\n console.log('✅ Database persisted, closing...');\n this.db.close(callback);\n })\n .catch((error) => {\n console.warn('⚠️ Failed to persist on close:', error);\n this.db.close(callback);\n });\n } else {\n this.db.close(callback);\n }\n }\n\n // Public method to force immediate persistence (useful after scan completes)\n async forcePersist(): Promise<void> {\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n this.persistTimeout = null;\n }\n if (this.isDirty && this.AsyncStorage) {\n this.isDirty = false;\n await this._persistData();\n }\n }\n\n // Public method to clear all persisted data (use when recovering from storage full errors)\n async clearPersistedData(): Promise<void> {\n console.log('🧹 Clearing all persisted database data from AsyncStorage...');\n await this._cleanupOldChunks();\n console.log('✅ Cleared all persisted data');\n }\n\n put(key: any, value: any, optionsOrCallback?: any, callback?: (error?: Error) => void): void {\n // Handle both put(key, value, callback) and put(key, value, options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // put(key, value, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // put(key, value, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to put method');\n }\n\n this.db.put(key, value, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n get(key: any, optionsOrCallback?: any, callback?: (error?: Error, value?: any) => void): void {\n // Handle both get(key, callback) and get(key, options, callback) signatures\n let cb: (error?: Error, value?: any) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // get(key, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // get(key, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to get method');\n }\n\n this.db.get(key, cb);\n }\n\n del(key: any, optionsOrCallback?: any, callback?: (error?: Error) => void): void {\n // Handle both del(key, callback) and del(key, options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // del(key, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // del(key, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to del method');\n }\n\n this.db.del(key, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n clear(options: any, callback: (error?: Error) => void): void {\n // Handle clear operation for deleting ranges of keys\n // This is required by dop-engine-v3's clearNamespace function\n const { gte, lte, gt, lt } = options || {};\n \n if (!gte && !gt) {\n callback(new Error('clear() requires gte or gt option'));\n return;\n }\n\n // Use iterator to find all keys in the range and delete them\n const keysToDelete: any[] = [];\n const iterator = this.db.iterator({\n gte,\n lte,\n gt,\n lt,\n keys: true,\n values: false,\n });\n\n const processNext = () => {\n iterator.next((err: any, key: any) => {\n if (err) {\n iterator.end(() => {\n callback(err);\n });\n return;\n }\n\n if (key === undefined) {\n // No more keys - now delete all collected keys\n iterator.end(() => {\n if (keysToDelete.length === 0) {\n callback();\n return;\n }\n\n // Delete keys in batch\n const operations = keysToDelete.map(k => ({ type: 'del', key: k }));\n this.db.batch(operations, (batchErr: any) => {\n if (!batchErr && this.AsyncStorage) {\n this._schedulePersistence();\n }\n callback(batchErr);\n });\n });\n return;\n }\n\n keysToDelete.push(key);\n processNext();\n });\n };\n\n processNext();\n }\n\n batch(operationsOrCallback?: any, optionsOrCallback?: any, callback?: (error?: Error) => void): any {\n // Handle multiple batch signatures:\n // batch() - returns chained batch\n // batch(operations, callback)\n // batch(operations, options, callback)\n \n if (arguments.length === 0) {\n // batch() - return chained batch (not commonly used in LevelUp)\n return this.db.batch();\n }\n\n // Handle batch operations with callback\n const operations = operationsOrCallback;\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // batch(operations, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // batch(operations, options, callback) signature \n cb = callback;\n } else {\n throw new Error('No callback provided to batch method');\n }\n\n this.db.batch(operations, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n iterator(options?: any): any {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.db.iterator(options);\n }\n\n private _schedulePersistence(): void {\n this.isDirty = true;\n \n // Clear existing timeout\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n }\n \n // Schedule persistence with longer throttling during heavy writes (every 30 seconds)\n // This dramatically improves scan performance by reducing serialization overhead\n this.persistTimeout = setTimeout(() => {\n if (this.isDirty) {\n this.isDirty = false;\n void this._persistData().catch((error) => {\n console.error('⚠️ Scheduled persistence failed:', error?.message || error);\n // Don't log full stack trace to avoid cluttering console\n });\n }\n }, 30000); // Increased from 5s to 30s\n }\n\n private async _persistData(): Promise<void> {\n if (!this.AsyncStorage) return;\n\n const startTime = Date.now();\n let entryCount = 0;\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 entryCount += 1;\n \n // Preserve Buffer/Uint8Array types by converting to base64 with type marker\n if (Buffer.isBuffer(value)) {\n data[key.toString()] = {\n __type: 'Buffer',\n data: value.toString('base64'),\n };\n } else if (value instanceof Uint8Array) {\n data[key.toString()] = {\n __type: 'Uint8Array',\n data: Buffer.from(value).toString('base64'),\n };\n } else {\n data[key.toString()] = value;\n }\n processNext();\n });\n };\n processNext();\n });\n\n // Serialize data\n let jsonData: string;\n try {\n jsonData = JSON.stringify(data);\n } catch (stringifyError) {\n throw new Error(`Failed to stringify data: ${stringifyError instanceof Error ? stringifyError.message : String(stringifyError)}`);\n }\n \n const serializeTime = Date.now() - startTime;\n const dataSizeMB = jsonData.length / 1024 / 1024;\n \n // React Native AsyncStorage has a 6MB per-item limit and total quota limits\n // Use 500KB chunks to stay well within limits and avoid SQLITE_FULL errors\n const chunkSize = 512 * 1024; // 500KB chunks (conservative for Android)\n \n if (jsonData.length > chunkSize) {\n // Split large data into chunks\n const chunks: string[] = [];\n for (let i = 0; i < jsonData.length; i += chunkSize) {\n chunks.push(jsonData.slice(i, i + chunkSize));\n }\n \n console.log(`💾 Writing ${chunks.length} chunks (${dataSizeMB.toFixed(2)}MB)...`);\n \n // Check if data is too large (warn if over 50MB)\n if (dataSizeMB > 50) {\n console.warn(`⚠️ Database is very large (${dataSizeMB.toFixed(2)}MB). Consider clearing old data.`);\n }\n \n // Write chunks sequentially to avoid overwhelming AsyncStorage\n // Parallel writes can cause SQLITE_FULL errors\n for (let i = 0; i < chunks.length; i += 1) {\n try {\n await this.AsyncStorage.setItem(`${this.storageKey}_chunk_${i}`, chunks[i]);\n } catch (chunkError: any) {\n // If we hit storage quota, clean up partial writes and throw\n console.error(`❌ Failed to write chunk ${i}/${chunks.length}:`, chunkError);\n if (chunkError?.message?.includes('full') || chunkError?.code === 13) {\n console.error('💥 Storage quota exceeded! Cleaning up partial writes...');\n // Only clean up the chunks we just tried to write\n for (let j = 0; j <= i; j += 1) {\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunk_${j}`).catch(() => {});\n }\n throw new Error('AsyncStorage quota exceeded. Please clear app data or restart the app.');\n }\n throw chunkError;\n }\n }\n \n // Clean up any extra chunks from previous saves (if we had more chunks before)\n await this._cleanupExtraChunks(chunks.length);\n \n // Only update chunk count after all chunks are written successfully\n await this.AsyncStorage.setItem(`${this.storageKey}_chunks`, chunks.length.toString());\n \n // Remove direct storage if it exists (migrating from direct to chunked)\n await this.AsyncStorage.removeItem(this.storageKey).catch(() => {});\n \n const totalTime = Date.now() - startTime;\n console.log(`✅ Persisted ${entryCount} entries (${dataSizeMB.toFixed(2)}MB in ${chunks.length} chunks) in ${totalTime}ms (serialize: ${serializeTime}ms)`);\n } else {\n // Small data, store directly\n await this.AsyncStorage.setItem(this.storageKey, jsonData);\n \n // Clean up chunked storage if it exists (migrating from chunked to direct)\n await this._cleanupAllChunks();\n \n const totalTime = Date.now() - startTime;\n console.log(`✅ Persisted ${entryCount} entries (${(jsonData.length / 1024).toFixed(2)}KB) in ${totalTime}ms (serialize: ${serializeTime}ms)`);\n }\n } catch (error: any) {\n console.error('❌ Failed to persist data to AsyncStorage:', error);\n console.error('Error details:', {\n message: error?.message,\n code: error?.code,\n stack: error?.stack?.split('\\n')[0]\n });\n \n // If quota exceeded, clear everything to recover\n if (error?.message?.includes('quota') || error?.message?.includes('full')) {\n console.error('💥 Storage full! Clearing all AsyncStorage data for recovery...');\n await this._cleanupAllChunks();\n }\n \n // Don't mark as dirty - if persistence fails, we don't want to retry infinitely\n // The data is still in memory (memdown) so the app can continue working\n // this.isDirty = true;\n \n // Don't throw - this allows the app to continue even if persistence fails\n // throw error;\n }\n }\n\n private async _cleanupExtraChunks(keepChunkCount: number): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunks beyond the new count (cleanup old data)\n for (let i = keepChunkCount; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (!exists) {\n break; // No more chunks to clean\n }\n await this.AsyncStorage.removeItem(chunkKey);\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during extra chunk cleanup:', cleanupError);\n }\n }\n\n private async _cleanupAllChunks(): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunk metadata\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Remove all chunk entries (try up to 200 chunks)\n for (let i = 0; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (!exists) {\n break; // No more chunks to clean\n }\n await this.AsyncStorage.removeItem(chunkKey);\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during chunk cleanup:', cleanupError);\n }\n }\n\n // Keep old method for clearing persisted data (full cleanup)\n private async _cleanupOldChunks(): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunk metadata\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Remove old direct storage (if exists)\n await this.AsyncStorage.removeItem(this.storageKey);\n \n // Remove all chunk entries (try up to 200 chunks)\n for (let i = 0; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n await this.AsyncStorage.removeItem(chunkKey).catch(() => {});\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during full cleanup:', cleanupError);\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 with AsyncStorage persistence\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?: 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;AACxC,kDAAmD;AAEnD,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,MAAa,kBAAkB;IACrB,EAAE,CAAM;IACR,UAAU,CAAS;IACnB,YAAY,CAAM;IAClB,cAAc,GAAyC,IAAI,CAAC;IAC5D,OAAO,GAAG,KAAK,CAAC;IAExB,YAAY,IAAY;QACtB,IAAI,CAAC,UAAU,GAAG,WAAW,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC;QAEpB,2DAA2D;QAC3D,IAAI;YACF,+DAA+D;YAC/D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,2CAA2C,CAAC,CAAC,OAAO,CAAC;SAClF;QAAC,OAAO,KAAK,EAAE;YACd,4EAA4E;YAC5E,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;SAC1B;IACH,CAAC;IAED,wCAAwC;IACxC,KAAK,CAAC,IAAI,CAAC,iBAAuB,EAAE,QAAkC;QACpE,oEAAoE;QACpE,IAAI,EAA2B,CAAC;QAEhC,IAAI,OAAO,iBAAiB,K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AC3D,OAAO,IAAA,qBAAc,EACnB,YAAY,EACZ,EAAS,EAAE,4EAA4E;IACvF,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,CACnB,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,yBAAyB,6BA4CpC","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';\nimport { setLoggers } from '../../../utils/logger';\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 private persistTimeout: ReturnType<typeof setTimeout> | null = null;\n private isDirty = false;\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(callbackOrOptions?: any, callback?: (error?: Error) => void): Promise<void> {\n // Handle both open(callback) and open(options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof callbackOrOptions === 'function') {\n // open(callback) signature\n cb = callbackOrOptions;\n } else if (typeof callback === 'function') {\n // open(options, callback) signature\n cb = callback;\n } else {\n // No callback provided - this shouldn't happen in AbstractLevelDOWN\n throw new Error('No callback provided to open method');\n }\n\n try {\n // Load persisted data from AsyncStorage (only if available)\n if (this.AsyncStorage) {\n try {\n let persistedData: string | null = null;\n \n // Check if data is stored in chunks\n const chunksCount = await this.AsyncStorage.getItem(`${this.storageKey}_chunks`);\n \n if (chunksCount) {\n console.log(`📦 Loading database from ${String(chunksCount)} chunks...`);\n // Reassemble from chunks\n const chunks: string[] = [];\n const count = parseInt(chunksCount, 10);\n \n if (Number.isNaN(count) || count < 0 || count > 1000) {\n throw new Error(`Invalid chunk count: ${String(chunksCount)}`);\n }\n \n for (let i = 0; i < count; i += 1) {\n const chunk = await this.AsyncStorage.getItem(`${this.storageKey}_chunk_${i}`);\n if (chunk) {\n chunks.push(chunk);\n } else {\n console.warn(`⚠️ Missing chunk ${i} of ${count}, data may be incomplete`);\n }\n }\n \n if (chunks.length === 0) {\n throw new Error('No chunks found, but chunk count was set');\n }\n \n persistedData = chunks.join('');\n console.log(`📦 Reassembled ${chunks.length}/${count} chunks (${(persistedData.length / 1024 / 1024).toFixed(2)}MB)`);\n } else {\n // Try to get data directly\n persistedData = await this.AsyncStorage.getItem(this.storageKey);\n if (persistedData) {\n console.log(`📦 Loading database directly (${(persistedData.length / 1024).toFixed(2)}KB)`);\n }\n }\n \n if (persistedData) {\n // Validate JSON before parsing\n if (!persistedData.trim().startsWith('{') || !persistedData.trim().endsWith('}')) {\n throw new Error('Persisted data does not look like valid JSON (missing braces)');\n }\n \n let data: Record<string, any>;\n try {\n data = JSON.parse(persistedData);\n } catch (jsonError) {\n throw new Error(`JSON parse failed: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);\n }\n \n // Restore data to memdown instance using batch operations\n const keys = Object.keys(data);\n console.log(`📦 Restoring ${keys.length} entries to database...`);\n \n // Prepare batch operations\n const operations: any[] = [];\n for (const [key, value] of Object.entries(data)) {\n // Restore Buffer/Uint8Array types from base64 with type marker\n let restoredValue = value;\n if (value && typeof value === 'object' && '__type' in value) {\n const typedValue = value as { __type: string; data: string };\n if (typedValue.__type === 'Buffer' && typeof typedValue.data === 'string') {\n restoredValue = Buffer.from(typedValue.data, 'base64');\n } else if (typedValue.__type === 'Uint8Array' && typeof typedValue.data === 'string') {\n restoredValue = new Uint8Array(Buffer.from(typedValue.data, 'base64'));\n }\n }\n \n operations.push({ type: 'put', key, value: restoredValue });\n }\n \n // Restore in batches of 500 for better performance\n const batchSize = 500;\n for (let i = 0; i < operations.length; i += batchSize) {\n const batch = operations.slice(i, i + batchSize);\n await new Promise<void>((resolve, reject) => {\n this.db.batch(batch, (err: any) => {\n if (err) reject(err);\n else resolve();\n });\n });\n console.log(`📦 Restored ${Math.min(i + batchSize, operations.length)}/${operations.length} entries...`);\n }\n \n console.log('✅ Successfully restored database from AsyncStorage');\n } else {\n console.log('ℹ️ No persisted data found, starting with empty database');\n }\n } catch (asyncStorageError) {\n console.error('❌ Failed to load from AsyncStorage, clearing corrupted data and starting fresh:', asyncStorageError);\n \n // Clear corrupted data\n try {\n await this.AsyncStorage.removeItem(this.storageKey);\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Try to remove chunks (up to 100 chunks max)\n for (let i = 0; i < 100; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (exists) {\n await this.AsyncStorage.removeItem(chunkKey);\n } else {\n break; // No more chunks\n }\n }\n console.log('🧹 Cleared corrupted AsyncStorage data');\n } catch (clearError) {\n console.warn('⚠️ Failed to clear corrupted data:', clearError);\n }\n }\n }\n \n // Open the memdown database\n this.db.open(cb);\n } catch (error) {\n cb(error as Error);\n }\n }\n\n close(callback: (error?: Error) => void): void {\n // Clear pending persistence timeout\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n this.persistTimeout = null;\n }\n \n // Force immediate persistence before closing if dirty\n if (this.isDirty && this.AsyncStorage) {\n console.log('💾 Persisting database before close...');\n this.isDirty = false;\n this._persistData()\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n .then(() => {\n console.log('✅ Database persisted, closing...');\n this.db.close(callback);\n })\n .catch((error) => {\n console.warn('⚠️ Failed to persist on close:', error);\n this.db.close(callback);\n });\n } else {\n this.db.close(callback);\n }\n }\n\n // Public method to force immediate persistence (useful after scan completes)\n async forcePersist(): Promise<void> {\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n this.persistTimeout = null;\n }\n if (this.isDirty && this.AsyncStorage) {\n this.isDirty = false;\n await this._persistData();\n }\n }\n\n // Public method to clear all persisted data (use when recovering from storage full errors)\n async clearPersistedData(): Promise<void> {\n console.log('🧹 Clearing all persisted database data from AsyncStorage...');\n await this._cleanupOldChunks();\n console.log('✅ Cleared all persisted data');\n }\n\n put(key: any, value: any, optionsOrCallback?: any, callback?: (error?: Error) => void): void {\n // Handle both put(key, value, callback) and put(key, value, options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // put(key, value, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // put(key, value, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to put method');\n }\n\n this.db.put(key, value, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n get(key: any, optionsOrCallback?: any, callback?: (error?: Error, value?: any) => void): void {\n // Handle both get(key, callback) and get(key, options, callback) signatures\n let cb: (error?: Error, value?: any) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // get(key, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // get(key, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to get method');\n }\n\n this.db.get(key, cb);\n }\n\n del(key: any, optionsOrCallback?: any, callback?: (error?: Error) => void): void {\n // Handle both del(key, callback) and del(key, options, callback) signatures\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // del(key, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // del(key, options, callback) signature\n cb = callback;\n } else {\n throw new Error('No callback provided to del method');\n }\n\n this.db.del(key, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n clear(options: any, callback: (error?: Error) => void): void {\n // Handle clear operation for deleting ranges of keys\n // This is required by dop-engine-v3's clearNamespace function\n const { gte, lte, gt, lt } = options || {};\n \n if (!gte && !gt) {\n callback(new Error('clear() requires gte or gt option'));\n return;\n }\n\n // Use iterator to find all keys in the range and delete them\n const keysToDelete: any[] = [];\n const iterator = this.db.iterator({\n gte,\n lte,\n gt,\n lt,\n keys: true,\n values: false,\n });\n\n const processNext = () => {\n iterator.next((err: any, key: any) => {\n if (err) {\n iterator.end(() => {\n callback(err);\n });\n return;\n }\n\n if (key === undefined) {\n // No more keys - now delete all collected keys\n iterator.end(() => {\n if (keysToDelete.length === 0) {\n callback();\n return;\n }\n\n // Delete keys in batch\n const operations = keysToDelete.map(k => ({ type: 'del', key: k }));\n this.db.batch(operations, (batchErr: any) => {\n if (!batchErr && this.AsyncStorage) {\n this._schedulePersistence();\n }\n callback(batchErr);\n });\n });\n return;\n }\n\n keysToDelete.push(key);\n processNext();\n });\n };\n\n processNext();\n }\n\n batch(operationsOrCallback?: any, optionsOrCallback?: any, callback?: (error?: Error) => void): any {\n // Handle multiple batch signatures:\n // batch() - returns chained batch\n // batch(operations, callback)\n // batch(operations, options, callback)\n \n if (arguments.length === 0) {\n // batch() - return chained batch (not commonly used in LevelUp)\n return this.db.batch();\n }\n\n // Handle batch operations with callback\n const operations = operationsOrCallback;\n let cb: (error?: Error) => void;\n \n if (typeof optionsOrCallback === 'function') {\n // batch(operations, callback) signature\n cb = optionsOrCallback;\n } else if (typeof callback === 'function') {\n // batch(operations, options, callback) signature \n cb = callback;\n } else {\n throw new Error('No callback provided to batch method');\n }\n\n this.db.batch(operations, (err: any) => {\n if (!err && this.AsyncStorage) {\n // Schedule throttled persistence\n this._schedulePersistence();\n }\n cb(err);\n });\n }\n\n iterator(options?: any): any {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return this.db.iterator(options);\n }\n\n private _schedulePersistence(): void {\n this.isDirty = true;\n \n // Clear existing timeout\n if (this.persistTimeout) {\n clearTimeout(this.persistTimeout);\n }\n \n // Schedule persistence with longer throttling during heavy writes (every 30 seconds)\n // This dramatically improves scan performance by reducing serialization overhead\n this.persistTimeout = setTimeout(() => {\n if (this.isDirty) {\n this.isDirty = false;\n void this._persistData().catch((error) => {\n console.error('⚠️ Scheduled persistence failed:', error?.message || error);\n // Don't log full stack trace to avoid cluttering console\n });\n }\n }, 30000); // Increased from 5s to 30s\n }\n\n private async _persistData(): Promise<void> {\n if (!this.AsyncStorage) return;\n\n const startTime = Date.now();\n let entryCount = 0;\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 entryCount += 1;\n \n // Preserve Buffer/Uint8Array types by converting to base64 with type marker\n if (Buffer.isBuffer(value)) {\n data[key.toString()] = {\n __type: 'Buffer',\n data: value.toString('base64'),\n };\n } else if (value instanceof Uint8Array) {\n data[key.toString()] = {\n __type: 'Uint8Array',\n data: Buffer.from(value).toString('base64'),\n };\n } else {\n data[key.toString()] = value;\n }\n processNext();\n });\n };\n processNext();\n });\n\n // Serialize data\n let jsonData: string;\n try {\n jsonData = JSON.stringify(data);\n } catch (stringifyError) {\n throw new Error(`Failed to stringify data: ${stringifyError instanceof Error ? stringifyError.message : String(stringifyError)}`);\n }\n \n const serializeTime = Date.now() - startTime;\n const dataSizeMB = jsonData.length / 1024 / 1024;\n \n // React Native AsyncStorage has a 6MB per-item limit and total quota limits\n // Use 500KB chunks to stay well within limits and avoid SQLITE_FULL errors\n const chunkSize = 512 * 1024; // 500KB chunks (conservative for Android)\n \n if (jsonData.length > chunkSize) {\n // Split large data into chunks\n const chunks: string[] = [];\n for (let i = 0; i < jsonData.length; i += chunkSize) {\n chunks.push(jsonData.slice(i, i + chunkSize));\n }\n \n console.log(`💾 Writing ${chunks.length} chunks (${dataSizeMB.toFixed(2)}MB)...`);\n \n // Check if data is too large (warn if over 50MB)\n if (dataSizeMB > 50) {\n console.warn(`⚠️ Database is very large (${dataSizeMB.toFixed(2)}MB). Consider clearing old data.`);\n }\n \n // Write chunks sequentially to avoid overwhelming AsyncStorage\n // Parallel writes can cause SQLITE_FULL errors\n for (let i = 0; i < chunks.length; i += 1) {\n try {\n await this.AsyncStorage.setItem(`${this.storageKey}_chunk_${i}`, chunks[i]);\n } catch (chunkError: any) {\n // If we hit storage quota, clean up partial writes and throw\n console.error(`❌ Failed to write chunk ${i}/${chunks.length}:`, chunkError);\n if (chunkError?.message?.includes('full') || chunkError?.code === 13) {\n console.error('💥 Storage quota exceeded! Cleaning up partial writes...');\n // Only clean up the chunks we just tried to write\n for (let j = 0; j <= i; j += 1) {\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunk_${j}`).catch(() => {});\n }\n throw new Error('AsyncStorage quota exceeded. Please clear app data or restart the app.');\n }\n throw chunkError;\n }\n }\n \n // Clean up any extra chunks from previous saves (if we had more chunks before)\n await this._cleanupExtraChunks(chunks.length);\n \n // Only update chunk count after all chunks are written successfully\n await this.AsyncStorage.setItem(`${this.storageKey}_chunks`, chunks.length.toString());\n \n // Remove direct storage if it exists (migrating from direct to chunked)\n await this.AsyncStorage.removeItem(this.storageKey).catch(() => {});\n \n const totalTime = Date.now() - startTime;\n console.log(`✅ Persisted ${entryCount} entries (${dataSizeMB.toFixed(2)}MB in ${chunks.length} chunks) in ${totalTime}ms (serialize: ${serializeTime}ms)`);\n } else {\n // Small data, store directly\n await this.AsyncStorage.setItem(this.storageKey, jsonData);\n \n // Clean up chunked storage if it exists (migrating from chunked to direct)\n await this._cleanupAllChunks();\n \n const totalTime = Date.now() - startTime;\n console.log(`✅ Persisted ${entryCount} entries (${(jsonData.length / 1024).toFixed(2)}KB) in ${totalTime}ms (serialize: ${serializeTime}ms)`);\n }\n } catch (error: any) {\n console.error('❌ Failed to persist data to AsyncStorage:', error);\n console.error('Error details:', {\n message: error?.message,\n code: error?.code,\n stack: error?.stack?.split('\\n')[0]\n });\n \n // If quota exceeded, clear everything to recover\n if (error?.message?.includes('quota') || error?.message?.includes('full')) {\n console.error('💥 Storage full! Clearing all AsyncStorage data for recovery...');\n await this._cleanupAllChunks();\n }\n \n // Don't mark as dirty - if persistence fails, we don't want to retry infinitely\n // The data is still in memory (memdown) so the app can continue working\n // this.isDirty = true;\n \n // Don't throw - this allows the app to continue even if persistence fails\n // throw error;\n }\n }\n\n private async _cleanupExtraChunks(keepChunkCount: number): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunks beyond the new count (cleanup old data)\n for (let i = keepChunkCount; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (!exists) {\n break; // No more chunks to clean\n }\n await this.AsyncStorage.removeItem(chunkKey);\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during extra chunk cleanup:', cleanupError);\n }\n }\n\n private async _cleanupAllChunks(): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunk metadata\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Remove all chunk entries (try up to 200 chunks)\n for (let i = 0; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n const exists = await this.AsyncStorage.getItem(chunkKey);\n if (!exists) {\n break; // No more chunks to clean\n }\n await this.AsyncStorage.removeItem(chunkKey);\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during chunk cleanup:', cleanupError);\n }\n }\n\n // Keep old method for clearing persisted data (full cleanup)\n private async _cleanupOldChunks(): Promise<void> {\n if (!this.AsyncStorage) return;\n \n try {\n // Remove chunk metadata\n await this.AsyncStorage.removeItem(`${this.storageKey}_chunks`);\n \n // Remove old direct storage (if exists)\n await this.AsyncStorage.removeItem(this.storageKey);\n \n // Remove all chunk entries (try up to 200 chunks)\n for (let i = 0; i < 200; i += 1) {\n const chunkKey = `${this.storageKey}_chunk_${i}`;\n await this.AsyncStorage.removeItem(chunkKey).catch(() => {});\n }\n } catch (cleanupError) {\n console.warn('⚠️ Error during full cleanup:', cleanupError);\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 console\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: boolean,\n skipMerkletreeScans: boolean,\n verboseScanLogging: boolean,\n databaseName = 'dop-wallet-db'\n): Promise<void> => {\n // Create React Native compatible database instance with AsyncStorage persistence\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?: Error) => {\n if (error) reject(error);\n else resolve();\n });\n });\n\n // Set up console logging for React Native\n if (shouldDebug) {\n setLoggers(\n (msg: string) => console.log(`[DOP Wallet] ${msg}`),\n (err: Error | string) => {\n if (err instanceof Error) {\n console.error(`[DOP Wallet Error] ${err.message}`, err);\n } else {\n console.error(`[DOP Wallet Error] ${err}`);\n }\n }\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"]}
@@ -156,8 +156,10 @@ const getCryptoProvider = async () => {
156
156
  // Use React Native crypto provider in React Native environment
157
157
  return exports.reactNativeCryptoProvider;
158
158
  }
159
- // Import circomlibjs for non-React Native environments
160
- const { poseidon, eddsa } = await Promise.resolve().then(() => __importStar(require('circomlibjs')));
159
+ // Import and build circomlibjs for non-React Native environments
160
+ const circomlibjs = await Promise.resolve().then(() => __importStar(require('circomlibjs')));
161
+ const poseidon = await circomlibjs.buildPoseidon();
162
+ const eddsa = await circomlibjs.buildEddsa();
161
163
  return { poseidon, eddsa };
162
164
  };
163
165
  exports.getCryptoProvider = getCryptoProvider;
@@ -1 +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,CAA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tC,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 | Uint8Array) => 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 * Helper function to convert Uint8Array to hex string without Buffer\n */\nconst uint8ArrayToHex = (uint8Array: Uint8Array): string => {\n return Array.from(uint8Array)\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('');\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 // Use direct conversion instead of Buffer.from to avoid React Native issues\n const privateKeyHex = uint8ArrayToHex(privateKey);\n const messageStr = message.toString();\n \n const signature = signMessage(privateKeyHex, messageStr);\n return signature;\n },\n \n prv2pub: (privateKey: Buffer | Uint8Array): unknown => {\n // Handle both Buffer and Uint8Array\n let privateKeyHex: string;\n if (privateKey instanceof Uint8Array && !(privateKey instanceof Buffer)) {\n // Pure Uint8Array (not Buffer which extends Uint8Array)\n privateKeyHex = uint8ArrayToHex(privateKey);\n } else {\n // Buffer has toString method\n privateKeyHex = (privateKey ).toString('hex');\n }\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};"]}
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;AA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CAAC,UAAU,EAAE,CAAC;IAC7C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC,CAAC;AAbW,QAAA,iBAAiB,qBAa5B","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 | Uint8Array) => 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 * Helper function to convert Uint8Array to hex string without Buffer\n */\nconst uint8ArrayToHex = (uint8Array: Uint8Array): string => {\n return Array.from(uint8Array)\n .map(byte => byte.toString(16).padStart(2, '0'))\n .join('');\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 // Use direct conversion instead of Buffer.from to avoid React Native issues\n const privateKeyHex = uint8ArrayToHex(privateKey);\n const messageStr = message.toString();\n \n const signature = signMessage(privateKeyHex, messageStr);\n return signature;\n },\n \n prv2pub: (privateKey: Buffer | Uint8Array): unknown => {\n // Handle both Buffer and Uint8Array\n let privateKeyHex: string;\n if (privateKey instanceof Uint8Array && !(privateKey instanceof Buffer)) {\n // Pure Uint8Array (not Buffer which extends Uint8Array)\n privateKeyHex = uint8ArrayToHex(privateKey);\n } else {\n // Buffer has toString method\n privateKeyHex = (privateKey ).toString('hex');\n }\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 and build circomlibjs for non-React Native environments\n const circomlibjs = await import('circomlibjs');\n const poseidon = await circomlibjs.buildPoseidon();\n const eddsa = await circomlibjs.buildEddsa();\n return { poseidon, eddsa };\n};"]}
@@ -3,30 +3,77 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resetFullTXIDMerkletreesV2 = exports.rescanFullUTXOMerkletreesAndWallets = exports.refreshBalances = void 0;
4
4
  const error_1 = require("../../../utils/error");
5
5
  const engine_1 = require("../core/engine");
6
+ // Track ongoing scans per chain to prevent concurrent scanning
7
+ const ongoingScans = new Map();
8
+ // Helper to create unique chain key
9
+ const getChainKey = (chain) => {
10
+ return `${chain.type}:${chain.id}`;
11
+ };
6
12
  const refreshBalances = async (chain, walletIdFilter) => {
13
+ const chainKey = getChainKey(chain);
14
+ // Check if a scan is already in progress for this chain
15
+ const existingScan = ongoingScans.get(chainKey);
16
+ if (existingScan) {
17
+ console.log(`⏸️ Scan already in progress for chain ${chainKey}, waiting for it to complete...`);
18
+ // Wait for the existing scan to complete instead of starting a new one
19
+ await existingScan;
20
+ console.log(`✅ Existing scan completed for chain ${chainKey}`);
21
+ return;
22
+ }
7
23
  try {
8
24
  // Wallet will trigger .emit('scanned', {chain}) event when finished,
9
25
  // which calls `onBalancesUpdate` (balance-update.ts).
10
26
  // Kick off a background merkletree scan.
11
27
  // This will call wallet.scanBalances when it's done, but may take some time.
28
+ console.log(`🔄 Starting new scan for chain ${chainKey}...`);
12
29
  const engine = (0, engine_1.getEngine)();
13
- await engine.scanContractHistory(chain, walletIdFilter);
30
+ // Create the scan promise and store it
31
+ const scanPromise = engine.scanContractHistory(chain, walletIdFilter);
32
+ ongoingScans.set(chainKey, scanPromise);
33
+ // Wait for the scan to complete
34
+ await scanPromise;
35
+ console.log(`✅ Scan completed successfully for chain ${chainKey}`);
14
36
  }
15
37
  catch (err) {
38
+ console.error(`❌ Scan failed for chain ${chainKey}:`, err);
16
39
  throw (0, error_1.reportAndSanitizeError)(exports.refreshBalances.name, err);
17
40
  }
41
+ finally {
42
+ // Always remove the scan from tracking when done (success or failure)
43
+ ongoingScans.delete(chainKey);
44
+ }
18
45
  };
19
46
  exports.refreshBalances = refreshBalances;
20
47
  const rescanFullUTXOMerkletreesAndWallets = async (chain, walletIdFilter) => {
48
+ const chainKey = getChainKey(chain);
49
+ // Check if a scan is already in progress for this chain
50
+ const existingScan = ongoingScans.get(chainKey);
51
+ if (existingScan) {
52
+ console.log(`⏸️ Full rescan already in progress for chain ${chainKey}, waiting for it to complete...`);
53
+ await existingScan;
54
+ console.log(`✅ Existing full rescan completed for chain ${chainKey}`);
55
+ return;
56
+ }
21
57
  try {
58
+ console.log(`🔄 Starting full rescan for chain ${chainKey}...`);
22
59
  const engine = (0, engine_1.getEngine)();
23
- await engine.fullRescanUTXOMerkletreesAndWallets(chain, walletIdFilter);
60
+ // Create the rescan promise and store it
61
+ const rescanPromise = engine.fullRescanUTXOMerkletreesAndWallets(chain, walletIdFilter);
62
+ ongoingScans.set(chainKey, rescanPromise);
63
+ // Wait for the rescan to complete
64
+ await rescanPromise;
65
+ console.log(`✅ Full rescan completed successfully for chain ${chainKey}`);
24
66
  // Wallet will trigger .emit('scanned', {chain}) event when finished,
25
67
  // which calls `onBalancesUpdate` (balance-update.ts).
26
68
  }
27
69
  catch (err) {
70
+ console.error(`❌ Full rescan failed for chain ${chainKey}:`, err);
28
71
  throw (0, error_1.reportAndSanitizeError)(exports.rescanFullUTXOMerkletreesAndWallets.name, err);
29
72
  }
73
+ finally {
74
+ // Always remove the rescan from tracking when done
75
+ ongoingScans.delete(chainKey);
76
+ }
30
77
  };
31
78
  exports.rescanFullUTXOMerkletreesAndWallets = rescanFullUTXOMerkletreesAndWallets;
32
79
  const resetFullTXIDMerkletreesV2 = async (chain) => {
@@ -1 +1 @@
1
- {"version":3,"file":"balances.js","sourceRoot":"","sources":["../../../../src/services/dop/wallets/balances.ts"],"names":[],"mappings":";;;AAEA,gDAA8D;AAC9D,2CAA2C;AAEpC,MAAM,eAAe,GAAG,KAAK,EAClC,KAAY,EACZ,cAAkC,EACnB,EAAE;IACjB,IAAI;QACF,qEAAqE;QACrE,sDAAsD;QAEtD,yCAAyC;QACzC,6EAA6E;QAE7E,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;QAC3B,MAAM,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;KACzD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,uBAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACzD;AACH,CAAC,CAAC;AAhBW,QAAA,eAAe,mBAgB1B;AAEK,MAAM,mCAAmC,GAAG,KAAK,EACtD,KAAY,EACZ,cAAkC,EACnB,EAAE;IACjB,IAAI;QACF,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;QAC3B,MAAM,MAAM,CAAC,mCAAmC,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QAExE,qEAAqE;QACrE,sDAAsD;KACvD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,2CAAmC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KAC7E;AACH,CAAC,CAAC;AAbW,QAAA,mCAAmC,uCAa9C;AAEK,MAAM,0BAA0B,GAAG,KAAK,EAC7C,KAAY,EACG,EAAE;IACjB,IAAI;QACF,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;QAC3B,MAAM,MAAM,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,kCAA0B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACpE;AACH,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC","sourcesContent":["import { Chain } from 'dop-engine-v3';\nimport { TXIDVersion } from 'dop-sharedmodels-v3';\nimport { reportAndSanitizeError } from '../../../utils/error';\nimport { getEngine } from '../core/engine';\n\nexport const refreshBalances = async (\n chain: Chain,\n walletIdFilter: Optional<string[]>,\n): Promise<void> => {\n try {\n // Wallet will trigger .emit('scanned', {chain}) event when finished,\n // which calls `onBalancesUpdate` (balance-update.ts).\n\n // Kick off a background merkletree scan.\n // This will call wallet.scanBalances when it's done, but may take some time.\n\n const engine = getEngine();\n await engine.scanContractHistory(chain, walletIdFilter);\n } catch (err) {\n throw reportAndSanitizeError(refreshBalances.name, err);\n }\n};\n\nexport const rescanFullUTXOMerkletreesAndWallets = async (\n chain: Chain,\n walletIdFilter: Optional<string[]>,\n): Promise<void> => {\n try {\n const engine = getEngine();\n await engine.fullRescanUTXOMerkletreesAndWallets(chain, walletIdFilter);\n\n // Wallet will trigger .emit('scanned', {chain}) event when finished,\n // which calls `onBalancesUpdate` (balance-update.ts).\n } catch (err) {\n throw reportAndSanitizeError(rescanFullUTXOMerkletreesAndWallets.name, err);\n }\n};\n\nexport const resetFullTXIDMerkletreesV2 = async (\n chain: Chain,\n): Promise<void> => {\n try {\n const engine = getEngine();\n await engine.fullResetTXIDMerkletreesV2(chain);\n } catch (err) {\n throw reportAndSanitizeError(resetFullTXIDMerkletreesV2.name, err);\n }\n};\n"]}
1
+ {"version":3,"file":"balances.js","sourceRoot":"","sources":["../../../../src/services/dop/wallets/balances.ts"],"names":[],"mappings":";;;AAEA,gDAA8D;AAC9D,2CAA2C;AAE3C,+DAA+D;AAC/D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEtD,oCAAoC;AACpC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAU,EAAE;IAC3C,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC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BAA0B,CAAC,KAAK,CAAC,CAAC;KAChD;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAA,8BAAsB,EAAC,kCAA0B,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;KACpE;AACH,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC","sourcesContent":["import { Chain } from 'dop-engine-v3';\nimport { TXIDVersion } from 'dop-sharedmodels-v3';\nimport { reportAndSanitizeError } from '../../../utils/error';\nimport { getEngine } from '../core/engine';\n\n// Track ongoing scans per chain to prevent concurrent scanning\nconst ongoingScans = new Map<string, Promise<void>>();\n\n// Helper to create unique chain key\nconst getChainKey = (chain: Chain): string => {\n return `${chain.type}:${chain.id}`;\n};\n\nexport const refreshBalances = async (\n chain: Chain,\n walletIdFilter: Optional<string[]>,\n): Promise<void> => {\n const chainKey = getChainKey(chain);\n \n // Check if a scan is already in progress for this chain\n const existingScan = ongoingScans.get(chainKey);\n if (existingScan) {\n console.log(`⏸️ Scan already in progress for chain ${chainKey}, waiting for it to complete...`);\n // Wait for the existing scan to complete instead of starting a new one\n await existingScan;\n console.log(`✅ Existing scan completed for chain ${chainKey}`);\n return;\n }\n\n try {\n // Wallet will trigger .emit('scanned', {chain}) event when finished,\n // which calls `onBalancesUpdate` (balance-update.ts).\n\n // Kick off a background merkletree scan.\n // This will call wallet.scanBalances when it's done, but may take some time.\n\n console.log(`🔄 Starting new scan for chain ${chainKey}...`);\n const engine = getEngine();\n \n // Create the scan promise and store it\n const scanPromise = engine.scanContractHistory(chain, walletIdFilter);\n ongoingScans.set(chainKey, scanPromise);\n \n // Wait for the scan to complete\n await scanPromise;\n \n console.log(`✅ Scan completed successfully for chain ${chainKey}`);\n } catch (err) {\n console.error(`❌ Scan failed for chain ${chainKey}:`, err);\n throw reportAndSanitizeError(refreshBalances.name, err);\n } finally {\n // Always remove the scan from tracking when done (success or failure)\n ongoingScans.delete(chainKey);\n }\n};\n\nexport const rescanFullUTXOMerkletreesAndWallets = async (\n chain: Chain,\n walletIdFilter: Optional<string[]>,\n): Promise<void> => {\n const chainKey = getChainKey(chain);\n \n // Check if a scan is already in progress for this chain\n const existingScan = ongoingScans.get(chainKey);\n if (existingScan) {\n console.log(`⏸️ Full rescan already in progress for chain ${chainKey}, waiting for it to complete...`);\n await existingScan;\n console.log(`✅ Existing full rescan completed for chain ${chainKey}`);\n return;\n }\n\n try {\n console.log(`🔄 Starting full rescan for chain ${chainKey}...`);\n const engine = getEngine();\n \n // Create the rescan promise and store it\n const rescanPromise = engine.fullRescanUTXOMerkletreesAndWallets(chain, walletIdFilter);\n ongoingScans.set(chainKey, rescanPromise);\n \n // Wait for the rescan to complete\n await rescanPromise;\n\n console.log(`✅ Full rescan completed successfully for chain ${chainKey}`);\n \n // Wallet will trigger .emit('scanned', {chain}) event when finished,\n // which calls `onBalancesUpdate` (balance-update.ts).\n } catch (err) {\n console.error(`❌ Full rescan failed for chain ${chainKey}:`, err);\n throw reportAndSanitizeError(rescanFullUTXOMerkletreesAndWallets.name, err);\n } finally {\n // Always remove the rescan from tracking when done\n ongoingScans.delete(chainKey);\n }\n};\n\nexport const resetFullTXIDMerkletreesV2 = async (\n chain: Chain,\n): Promise<void> => {\n try {\n const engine = getEngine();\n await engine.fullResetTXIDMerkletreesV2(chain);\n } catch (err) {\n throw reportAndSanitizeError(resetFullTXIDMerkletreesV2.name, err);\n }\n};\n"]}
@@ -33,25 +33,20 @@ const testCircomlibjs = async () => {
33
33
  const testResult = (cryptoProvider).poseidon([1n, 2n]);
34
34
  // eslint-disable-next-line no-console
35
35
  console.log('✅ Poseidon test result:', testResult.toString());
36
- // Test eddsa operations
36
+ // Test eddsa operations availability
37
37
  // eslint-disable-next-line no-console
38
- console.log('🔑 Testing EdDSA operations...');
39
- const testPrivateKey = new Uint8Array(32).fill(1);
40
- const testMessage = 12345n;
41
- // eslint-disable-next-line no-console
42
- console.log('🔑 Testing EdDSA signing...');
43
- const signature = (cryptoProvider).eddsa.signPoseidon(testPrivateKey, testMessage);
44
- // eslint-disable-next-line no-console
45
- console.log('🔑 Testing EdDSA public key derivation...');
46
- const publicKey = (cryptoProvider).eddsa.prv2pub(Buffer.from(testPrivateKey));
47
- // eslint-disable-next-line no-console
48
- console.log('🔍 Testing EdDSA verification...');
49
- const isValid = (cryptoProvider).eddsa.verifyPoseidon(testMessage, signature, publicKey);
50
- // eslint-disable-next-line no-console
51
- console.log('✅ EdDSA test result:', isValid);
52
- if (typeof isValid !== 'boolean' || !isValid) {
53
- throw new Error('EdDSA verification failed');
38
+ console.log('🔑 Testing EdDSA operations availability...');
39
+ if (typeof (cryptoProvider).eddsa.signPoseidon !== 'function') {
40
+ throw new Error('EdDSA signPoseidon function missing');
54
41
  }
42
+ if (typeof (cryptoProvider).eddsa.prv2pub !== 'function') {
43
+ throw new Error('EdDSA prv2pub function missing');
44
+ }
45
+ if (typeof (cryptoProvider).eddsa.verifyPoseidon !== 'function') {
46
+ throw new Error('EdDSA verifyPoseidon function missing');
47
+ }
48
+ // eslint-disable-next-line no-console
49
+ console.log('✅ EdDSA functions available');
55
50
  // eslint-disable-next-line no-console
56
51
  console.log('🎉 crypto provider initialization successful');
57
52
  return true;