dop-wallet-v6 1.2.9 → 1.2.11

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.
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startDopEngineReactNative = void 0;
4
+ const init_1 = require("./init");
5
+ // Use memdown for React Native database - with error handling
6
+ let memdown;
7
+ try {
8
+ memdown = require('memdown');
9
+ }
10
+ catch (error) {
11
+ throw new Error('memdown dependency is required for React Native support. ' +
12
+ 'Please install it with: npm install memdown@^6.1.1');
13
+ }
14
+ /**
15
+ * React Native compatible LevelDB implementation using memdown with AsyncStorage persistence.
16
+ * This provides a persistent database solution that works reliably in React Native environments.
17
+ */
18
+ class ReactNativeLevelDB {
19
+ db;
20
+ storageKey;
21
+ AsyncStorage;
22
+ constructor(name) {
23
+ this.storageKey = `leveldb_${name}`;
24
+ this.db = memdown();
25
+ // Dynamically import AsyncStorage to avoid bundling issues
26
+ try {
27
+ this.AsyncStorage = require('@react-native-async-storage/async-storage').default;
28
+ }
29
+ catch (error) {
30
+ console.warn('AsyncStorage not available, data will not persist between app restarts');
31
+ this.AsyncStorage = null;
32
+ }
33
+ }
34
+ // Implement AbstractLevelDOWN interface
35
+ async open(callback) {
36
+ try {
37
+ // Load persisted data from AsyncStorage
38
+ 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();
50
+ });
51
+ });
52
+ }
53
+ }
54
+ }
55
+ // Open the memdown database
56
+ this.db.open(callback);
57
+ }
58
+ catch (error) {
59
+ callback(error);
60
+ }
61
+ }
62
+ close(callback) {
63
+ this.db.close(callback);
64
+ }
65
+ put(key, value, callback) {
66
+ this.db.put(key, value, (err) => {
67
+ if (!err && this.AsyncStorage) {
68
+ // Persist to AsyncStorage in background
69
+ void this._persistData().catch(console.warn);
70
+ }
71
+ callback(err);
72
+ });
73
+ }
74
+ get(key, callback) {
75
+ this.db.get(key, callback);
76
+ }
77
+ del(key, callback) {
78
+ this.db.del(key, (err) => {
79
+ if (!err && this.AsyncStorage) {
80
+ // Persist to AsyncStorage in background
81
+ void this._persistData().catch(console.warn);
82
+ }
83
+ callback(err);
84
+ });
85
+ }
86
+ batch(operations, callback) {
87
+ this.db.batch(operations, (err) => {
88
+ if (!err && this.AsyncStorage) {
89
+ // Persist to AsyncStorage in background
90
+ void this._persistData().catch(console.warn);
91
+ }
92
+ callback(err);
93
+ });
94
+ }
95
+ iterator(options) {
96
+ return this.db.iterator(options);
97
+ }
98
+ async _persistData() {
99
+ if (!this.AsyncStorage)
100
+ return;
101
+ try {
102
+ const data = {};
103
+ const iterator = this.db.iterator();
104
+ await new Promise((resolve, reject) => {
105
+ const processNext = () => {
106
+ iterator.next((err, key, value) => {
107
+ if (err) {
108
+ iterator.end(() => reject(err));
109
+ return;
110
+ }
111
+ if (key === undefined) {
112
+ iterator.end(() => resolve());
113
+ return;
114
+ }
115
+ data[key.toString()] = value;
116
+ processNext();
117
+ });
118
+ };
119
+ processNext();
120
+ });
121
+ await this.AsyncStorage.setItem(this.storageKey, JSON.stringify(data));
122
+ }
123
+ catch (error) {
124
+ console.warn('Failed to persist data to AsyncStorage:', error);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * Initialize DOP Engine specifically for React Native environments.
130
+ * Uses a custom LevelDB implementation that persists data to AsyncStorage.
131
+ * This provides full database persistence while being compatible with React Native.
132
+ *
133
+ * @param walletSource - Name for your wallet implementation (max 16 chars, lowercase)
134
+ * @param shouldDebug - Whether to forward Engine debug logs to Logger
135
+ * @param artifactStore - Persistent store for downloading large artifact files
136
+ * @param useNativeArtifacts - Whether to download native C++ artifacts (should be TRUE for mobile)
137
+ * @param skipMerkletreeScans - Whether to skip merkletree syncs and private balance scans
138
+ * @param verboseScanLogging - Enable verbose logging for scanning operations
139
+ * @param databaseName - Name for the database (used as prefix in AsyncStorage)
140
+ */
141
+ const startDopEngineReactNative = async (walletSource, shouldDebug, artifactStore, useNativeArtifacts = true, skipMerkletreeScans = false, verboseScanLogging = false, databaseName = 'dop-wallet-db') => {
142
+ // Create React Native compatible database instance
143
+ const db = new ReactNativeLevelDB(databaseName);
144
+ // 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
+ });
153
+ // Initialize the DOP Engine with the React Native database
154
+ return (0, init_1.startDopEngine)(walletSource, db, // Cast to any since TypeScript doesn't know about our custom implementation
155
+ shouldDebug, artifactStore, useNativeArtifacts, skipMerkletreeScans, verboseScanLogging);
156
+ };
157
+ exports.startDopEngineReactNative = startDopEngineReactNative;
158
+ //# sourceMappingURL=react-native-init.js.map
@@ -0,0 +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,2CAA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KAAK,EAC1B,YAAY,GAAG,eAAe,EACf,EAAE;IACjB,mDAAmD;IACnD,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,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"]}
@@ -47,7 +47,8 @@ exports.getSdk = exports.GetDopTransactionsByDecryptToAddressDocument = exports.
47
47
  const utils_1 = require("@graphql-mesh/utils");
48
48
  const utils_2 = require("@graphql-mesh/utils");
49
49
  const utils_3 = require("@graphql-mesh/utils");
50
- const cache_localforage_1 = __importDefault(require("@graphql-mesh/cache-localforage"));
50
+ // MODIFIED: Replaced cache-localforage with no cache for React Native compatibility
51
+ // import MeshCache from "@graphql-mesh/cache-localforage";
51
52
  const fetch_1 = require("@whatwg-node/fetch");
52
53
  const graphql_1 = __importDefault(require("@graphql-mesh/graphql"));
53
54
  const merger_bare_1 = __importDefault(require("@graphql-mesh/merger-bare"));
@@ -89,13 +90,8 @@ async function getMeshOptions() {
89
90
  const pubsub = new utils_2.PubSub();
90
91
  const sourcesStore = rootStore.child('sources');
91
92
  const logger = new utils_3.DefaultLogger("GraphClient");
92
- const cache = new cache_localforage_1.default({
93
- ...{},
94
- importFn,
95
- store: rootStore.child('cache'),
96
- pubsub,
97
- logger,
98
- });
93
+ // MODIFIED: Replaced MeshCache with undefined to disable caching for React Native compatibility
94
+ const cache = undefined;
99
95
  const sources = [];
100
96
  const transforms = [];
101
97
  const additionalEnvelopPlugins = [];