dop-wallet-v6 1.2.20 → 1.3.0

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.
@@ -1,8 +1,201 @@
1
+ diff --git a/node_modules/dop-engine-v3/dist/contracts/dop-smart-wallet/V2/dop-smart-wallet.js b/node_modules/dop-engine-v3/dist/contracts/dop-smart-wallet/V2/dop-smart-wallet.js
2
+ index 56b2ecb..e5f75b7 100644
3
+ --- a/node_modules/dop-engine-v3/dist/contracts/dop-smart-wallet/V2/dop-smart-wallet.js
4
+ +++ b/node_modules/dop-engine-v3/dist/contracts/dop-smart-wallet/V2/dop-smart-wallet.js
5
+ @@ -75,6 +75,7 @@ class DopSmartWalletContract extends events_1.default {
6
+ * @returns isValid
7
+ */
8
+ async validateMerkleroot(tree, root) {
9
+ + console.log(`Validating V2 merkleroot for tree ${tree} : ${root}`);
10
+ try {
11
+ const isValidMerkleroot = await this.contract.rootHistory(tree, bytes_1.ByteUtils.formatToByteLength(root, bytes_1.ByteLength.UINT_256, true));
12
+ // if (!isValidMerkleroot && EngineDebug.isTestRun()) {
13
+ diff --git a/node_modules/dop-engine-v3/dist/dop-engine.js b/node_modules/dop-engine-v3/dist/dop-engine.js
14
+ index d1e96e8..31c592d 100644
15
+ --- a/node_modules/dop-engine-v3/dist/dop-engine.js
16
+ +++ b/node_modules/dop-engine-v3/dist/dop-engine.js
17
+ @@ -254,14 +254,17 @@ class DopEngine extends events_1.default {
18
+ }
19
+ async performQuickSync(txidVersion, chain, endProgress, retryCount = 0) {
20
+ try {
21
+ + console.log("Starting quick sync...");
22
+ debugger_1.default.log(`[${txidVersion}] quickSync: chain ${chain.type}:${chain.id}`);
23
+ const utxoMerkletree = this.getUTXOMerkletree(txidVersion, chain);
24
+ const startScanningBlockQuickSync = await this.getStartScanningBlock(txidVersion, chain);
25
+ + console.log(`Quick syncing UTXO merkletree for txid version ${txidVersion} on chain ${chain.type}:${chain.id} from block ${startScanningBlockQuickSync}...`);
26
+ debugger_1.default.log(`[${txidVersion}] Start scanning block for QuickSync: ${startScanningBlockQuickSync}`);
27
+ this.emitUTXOMerkletreeScanUpdateEvent(txidVersion, chain, endProgress * 0.2); // 10% / 50%
28
+ // Fetch events
29
+ const { commitmentEvents, decryptEvents, nullifierEvents, dopTransactionEvents } = await this.quickSyncEvents(txidVersion, chain, startScanningBlockQuickSync);
30
+ if (dopTransactionEvents) {
31
+ + console.log(`QuickSync dopTransactionEvents: ${dopTransactionEvents.length}`);
32
+ debugger_1.default.log(`[${txidVersion}] QuickSync dopTransactionEvents: ${dopTransactionEvents.length}`);
33
+ await this.handleNewDopTransactionsV3(txidVersion, chain, dopTransactionEvents);
34
+ }
35
+ @@ -269,6 +272,7 @@ class DopEngine extends events_1.default {
36
+ await this.decryptListener(txidVersion, chain, decryptEvents);
37
+ this.emitUTXOMerkletreeScanUpdateEvent(txidVersion, chain, endProgress * 0.5); // 25% / 50%
38
+ await this.nullifierListener(txidVersion, chain, nullifierEvents);
39
+ + console.log(`QuickSync commitmentEvents: ${commitmentEvents.length}`);
40
+ debugger_1.default.log(`[${txidVersion}] QuickSync commitments: ${commitmentEvents.length}`);
41
+ // Make sure commitments are scanned after Decrypts and Nullifiers.
42
+ await this.commitmentListener(txidVersion, chain, commitmentEvents, false, // shouldUpdateTrees - wait until after all commitments added
43
+ @@ -285,6 +289,7 @@ class DopEngine extends events_1.default {
44
+ await this.performQuickSync(txidVersion, chain, endProgress, retryCount + 1);
45
+ return;
46
+ }
47
+ + console.error('Quick sync failed:', cause);
48
+ debugger_1.default.error(new Error('Failed to quick sync', { cause }));
49
+ }
50
+ }
51
+ @@ -327,8 +332,10 @@ class DopEngine extends events_1.default {
52
+ continue;
53
+ }
54
+ // eslint-disable-next-line no-await-in-loop
55
+ + console.log(`Scanning UTXO history for txid version ${txidVersion} on chain ${chain.type}:${chain.id}...`);
56
+ await this.scanUTXOHistory(txidVersion, chain, walletIdFilter);
57
+ }
58
+ + console.log("Finished scanning UTXO history");
59
+ await this.scanTXIDHistoryV2(chain);
60
+ }
61
+ /**
62
+ @@ -880,6 +887,7 @@ class DopEngine extends events_1.default {
63
+ await this.syncDopTransactionsV2(chain, 'reset after txid index');
64
+ }
65
+ static async validateMerkleroot(txidVersion, chain, tree, _index, merkleroot) {
66
+ +
67
+ switch (txidVersion) {
68
+ case poi_types_1.TXIDVersion.V2_PoseidonMerkle:
69
+ return contract_store_1.ContractStore.dopSmartWalletContracts
70
+ @@ -901,7 +909,9 @@ class DopEngine extends events_1.default {
71
+ */
72
+ async loadNetwork(chain, dopSmartWalletContractAddress, relayAdaptV2ContractAddress, poseidonMerkleAccumulatorV3Address, poseidonMerkleVerifierV3Address, tokenVaultV3Address, defaultProvider, pollingProvider, deploymentBlocks, supportsV3) {
73
+ debugger_1.default.log(`loadNetwork: ${chain.type}:${chain.id}`);
74
+ + console.log(`Loading network: ${chain.type}:${chain.id}`);
75
+ try {
76
+ + console.log(`Waiting for default RPC provider to connect...`);
77
+ await (0, promises_1.promiseTimeout)(defaultProvider.getBlockNumber(), 60_000, 'Timed out waiting for default RPC provider to connect.');
78
+ }
79
+ catch (cause) {
80
+ @@ -946,14 +956,19 @@ class DopEngine extends events_1.default {
81
+ contract_store_1.ContractStore.poseidonMerkleVerifierV3Contracts.set(null, chain, new poseidon_merkle_verifier_1.PoseidonMerkleVerifierContract(poseidonMerkleVerifierV3Address, defaultProvider));
82
+ contract_store_1.ContractStore.tokenVaultV3Contracts.set(null, chain, new token_vault_contract_1.TokenVaultContract(tokenVaultV3Address, defaultProvider));
83
+ }
84
+ + console.log(`Setting up merkletrees for ${chain.type}:${chain.id} ACTIVE_TXID_VERSIONS=${poi_types_1.ACTIVE_TXID_VERSIONS.join(', ')} `);
85
+ for (const txidVersion of poi_types_1.ACTIVE_UTXO_MERKLETREE_TXID_VERSIONS) {
86
+ // eslint-disable-next-line no-await-in-loop
87
+ + console.log(`Setting up UTXO merkletree for ${chain.type}:${chain.id} - ${txidVersion}`);
88
+ + console.log(`Validating UTXO merkleroot for ${chain.type}:${chain.id} - ${txidVersion}`);
89
+ const utxoMerkletree = await utxo_merkletree_1.UTXOMerkletree.create(this.db, chain, txidVersion,
90
+ // eslint-disable-next-line @typescript-eslint/no-shadow
91
+ (txidVersion, chain, tree, index, merkleroot) => DopEngine.validateMerkleroot(txidVersion, chain, tree, index, merkleroot));
92
+ + console.log(`UTXO merkletree created for ${chain.type}:${chain.id} - ${txidVersion}`);
93
+ this.utxoMerkletrees.set(txidVersion, chain, utxoMerkletree);
94
+ // Load utxo merkletree to all wallets
95
+ // eslint-disable-next-line no-await-in-loop
96
+ + console.log(`Loading UTXO merkletree to wallets for ${chain.type}:${chain.id} - ${txidVersion}`);
97
+ await Promise.all(Object.values(this.wallets).map(async (wallet) => {
98
+ await wallet.loadUTXOMerkletree(txidVersion, utxoMerkletree);
99
+ }));
100
+ @@ -962,6 +977,7 @@ class DopEngine extends events_1.default {
101
+ // Wallet Txid merkletree
102
+ const autoValidate = async () => true;
103
+ // eslint-disable-next-line no-await-in-loop
104
+ + console.log(`Setting up TXID merkletree for ${chain.type}:${chain.id} - ${txidVersion}`);
105
+ txidMerkletree = await txid_merkletree_1.TXIDMerkletree.createForWallet(this.db, chain, txidVersion,
106
+ // For V3, we receive events in realtime, and validation is done via on-chain verificationHash field.
107
+ supportsV3 ? autoValidate : this.validateDopTxidMerkleroot);
108
+ @@ -978,6 +994,7 @@ class DopEngine extends events_1.default {
109
+ if (this.skipMerkletreeScans) {
110
+ return;
111
+ }
112
+ + console.log(`Setting up merkletrees for ${chain.type}:${chain.id}`);
113
+ // Set up listeners
114
+ const commitmentListener = async (txidVersion, commitmentEvents) => {
115
+ await this.commitmentListener(txidVersion, chain, commitmentEvents, true, // shouldUpdateTrees
116
+ @@ -990,6 +1007,7 @@ class DopEngine extends events_1.default {
117
+ false);
118
+ }
119
+ };
120
+ + console.log(`Setting commitment listener for ${chain.type}:${chain.id}`);
121
+ const nullifierListener = async (txidVersion, nullifiers) => {
122
+ await this.nullifierListener(txidVersion, chain, nullifiers);
123
+ // Only start wallet balance decryption if utxoMerkletree is not already scanning
124
+ @@ -1003,6 +1021,7 @@ class DopEngine extends events_1.default {
125
+ const decryptListener = async (txidVersion, decrypts) => {
126
+ await this.decryptListener(txidVersion, chain, decrypts);
127
+ };
128
+ + console.log(`Setting merkletree listeners for ${chain.type}:${chain.id}`);
129
+ await contract_store_1.ContractStore.dopSmartWalletContracts
130
+ .get(null, chain)
131
+ ?.setTreeUpdateListeners(commitmentListener, nullifierListener, decryptListener);
132
+ @@ -1025,6 +1044,7 @@ class DopEngine extends events_1.default {
133
+ false);
134
+ }
135
+ };
136
+ + console.log(`Setting V3 merkletree listeners for ${chain.type}:${chain.id}`);
137
+ await contract_store_1.ContractStore.poseidonMerkleAccumulatorV3Contracts
138
+ .get(null, chain)
139
+ ?.setTreeUpdateListeners(commitmentListenerV3, // No wallet scans
140
+ @@ -1293,7 +1313,9 @@ class DopEngine extends events_1.default {
141
+ * @returns id
142
+ */
143
+ async createWalletFromMnemonic(encryptionKey, mnemonic, index = 0, creationBlockNumbers = undefined) {
144
+ + console.log('Creating wallet from mnemonic...');
145
+ const wallet = await dop_wallet_1.DopWallet.fromMnemonic(this.db, encryptionKey, mnemonic, index, creationBlockNumbers, this.prover);
146
+ + console.log('Wallet created. Loading wallet...');
147
+ await this.loadWallet(wallet);
148
+ return wallet;
149
+ }
150
+ diff --git a/node_modules/dop-engine-v3/dist/merkletree/merkletree.js b/node_modules/dop-engine-v3/dist/merkletree/merkletree.js
151
+ index 8ca9cd7..aa1b812 100644
152
+ --- a/node_modules/dop-engine-v3/dist/merkletree/merkletree.js
153
+ +++ b/node_modules/dop-engine-v3/dist/merkletree/merkletree.js
154
+ @@ -272,9 +272,19 @@ class Merkletree {
155
+ }
156
+ async getMetadataFromStorage() {
157
+ const storedMetadata = await this.getMerkletreesMetadata();
158
+ +
159
+ if (!storedMetadata) {
160
+ + console.warn('No metadata found, starting fresh');
161
+ return;
162
+ }
163
+ +
164
+ + // Validate metadata structure
165
+ + if (typeof storedMetadata !== 'object' || !storedMetadata.trees) {
166
+ + console.warn('Invalid metadata format (expected object with trees property), got:', typeof storedMetadata, storedMetadata);
167
+ + console.log('Clearing corrupted metadata and starting fresh');
168
+ + return;
169
+ + }
170
+ +
171
+ const treeKeys = Object.keys(storedMetadata.trees);
172
+ for (const treeKey of treeKeys) {
173
+ const tree = Number(treeKey);
174
+ @@ -292,10 +302,17 @@ class Merkletree {
175
+ */
176
+ async getMerkletreesMetadata() {
177
+ try {
178
+ - const metadata = msgpack_lite_1.default.decode(bytes_1.ByteUtils.arrayify((await this.db.get(this.getMerkletreeDBPrefix()))));
179
+ + const rawData = await this.db.get(this.getMerkletreeDBPrefix());
180
+ + if (rawData == null || rawData === undefined) {
181
+ + console.warn('No merkletree metadata found in DB (first time setup)');
182
+ + return undefined;
183
+ + }
184
+ + const metadata = msgpack_lite_1.default.decode(bytes_1.ByteUtils.arrayify(rawData));
185
+ + console.log('Successfully decoded merkletree metadata');
186
+ return metadata;
187
+ }
188
+ - catch {
189
+ + catch (err) {
190
+ + console.log('Error fetching merkletree metadata:', err);
191
+ return undefined;
192
+ }
193
+ }
1
194
  diff --git a/node_modules/dop-engine-v3/dist/utils/keys-utils.js b/node_modules/dop-engine-v3/dist/utils/keys-utils.js
2
- index c6e9aca..653041a 100644
195
+ index c6e9aca..dd634ae 100644
3
196
  --- a/node_modules/dop-engine-v3/dist/utils/keys-utils.js
4
197
  +++ b/node_modules/dop-engine-v3/dist/utils/keys-utils.js
5
- @@ -7,6 +7,11 @@ const poseidon_1 = require("./poseidon");
198
+ @@ -7,11 +7,30 @@ const poseidon_1 = require("./poseidon");
6
199
  const bytes_1 = require("./bytes");
7
200
  const hash_1 = require("./hash");
8
201
  const scalar_multiply_1 = require("./scalar-multiply");
@@ -10,7 +203,64 @@ index c6e9aca..653041a 100644
10
203
  +
11
204
  +ed25519_1.utils.sha512 = hashes.sha512;
12
205
  +ed25519_1.utils.sha512Async = (m) => Promise.resolve(hashes.sha512(m));
206
+ +
207
+ +// Helper function to convert Uint8Array to Buffer without causing React Native issues
208
+ +// This handles the case where Buffer polyfill may not work properly with Uint8Array
209
+ +function safeUint8ArrayToBuffer(uint8Array) {
210
+ + if (Buffer.isBuffer(uint8Array)) {
211
+ + return uint8Array;
212
+ + }
213
+ + // Create buffer using array notation instead of Buffer.from to avoid to-buffer module issues
214
+ + const buffer = Buffer.allocUnsafe(uint8Array.length);
215
+ + for (let i = 0; i < uint8Array.length; i++) {
216
+ + buffer[i] = uint8Array[i];
217
+ + }
218
+ + return buffer;
219
+ +}
13
220
  +
14
221
  const { bytesToHex, randomBytes } = ed25519_1.utils;
15
222
  function getPublicSpendingKey(privateKey) {
16
223
  if (privateKey.length !== 32)
224
+ throw Error('Invalid private key length');
225
+ - return circomlibjs_1.eddsa.prv2pub(Buffer.from(privateKey));
226
+ + return circomlibjs_1.eddsa.prv2pub(safeUint8ArrayToBuffer(privateKey));
227
+ }
228
+ exports.getPublicSpendingKey = getPublicSpendingKey;
229
+ async function getPublicViewingKey(privateViewingKey) {
230
+ @@ -23,7 +42,7 @@ function getRandomScalar() {
231
+ }
232
+ exports.getRandomScalar = getRandomScalar;
233
+ function signEDDSA(privateKey, message) {
234
+ - return circomlibjs_1.eddsa.signPoseidon(Buffer.from(privateKey), message);
235
+ + return circomlibjs_1.eddsa.signPoseidon(safeUint8ArrayToBuffer(privateKey), message);
236
+ }
237
+ exports.signEDDSA = signEDDSA;
238
+ function verifyEDDSA(message, signature, pubkey) {
239
+ diff --git a/node_modules/dop-engine-v3/dist/wallet/abstract-wallet.js b/node_modules/dop-engine-v3/dist/wallet/abstract-wallet.js
240
+ index f80d71f..d7b13da 100644
241
+ --- a/node_modules/dop-engine-v3/dist/wallet/abstract-wallet.js
242
+ +++ b/node_modules/dop-engine-v3/dist/wallet/abstract-wallet.js
243
+ @@ -1695,6 +1695,7 @@ class AbstractWallet extends events_1.default {
244
+ return msgpack_lite_1.default.decode(bytes_1.ByteUtils.fastHexToBytes(await db.getEncrypted(AbstractWallet.dbPath(id), encryptionKey)));
245
+ }
246
+ static async write(db, id, encryptionKey, data) {
247
+ + console.log('Writing wallet data to db...');
248
+ await db.putEncrypted(AbstractWallet.dbPath(id), encryptionKey, msgpack_lite_1.default.encode(data));
249
+ }
250
+ static async delete(db, id) {
251
+ diff --git a/node_modules/dop-engine-v3/dist/wallet/dop-wallet.js b/node_modules/dop-engine-v3/dist/wallet/dop-wallet.js
252
+ index d0dcdad..55c1fad 100644
253
+ --- a/node_modules/dop-engine-v3/dist/wallet/dop-wallet.js
254
+ +++ b/node_modules/dop-engine-v3/dist/wallet/dop-wallet.js
255
+ @@ -63,7 +63,10 @@ class DopWallet extends abstract_wallet_1.AbstractWallet {
256
+ static async fromMnemonic(db, encryptionKey, mnemonic, index, creationBlockNumbers, prover) {
257
+ const id = DopWallet.generateID(mnemonic, index);
258
+ // Write encrypted mnemonic to DB
259
+ - await abstract_wallet_1.AbstractWallet.write(db, id, encryptionKey, { mnemonic, index, creationBlockNumbers });
260
+ + try {
261
+ + await abstract_wallet_1.AbstractWallet.write(db, id, encryptionKey, { mnemonic, index, creationBlockNumbers });
262
+ + } catch (error) {
263
+ + }
264
+ return this.createWallet(id, db, mnemonic, index, creationBlockNumbers, prover);
265
+ }
266
+ /**