@zubari/sdk 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PayoutsProtocol-B5z8SEA-.d.ts → PayoutsProtocol-DAa-9A5C.d.ts} +8 -1
- package/dist/{PayoutsProtocol-CLiMFe54.d.mts → PayoutsProtocol-DKEQhwYH.d.mts} +8 -1
- package/dist/{TransactionService-BtWUjKt_.d.ts → TransactionService-BEkgF1T6.d.ts} +12 -2
- package/dist/{TransactionService-Lr_WS6iR.d.mts → TransactionService-CF_C3Kqm.d.mts} +12 -2
- package/dist/{WalletManager-DQQwVkoa.d.ts → WalletManager-CeLlZo2y.d.ts} +23 -2
- package/dist/{WalletManager-Sbpx4E1-.d.mts → WalletManager-DIx8nENh.d.mts} +23 -2
- package/dist/{contracts-B842YprC.d.mts → contracts-JfZDzaV7.d.ts} +11 -2
- package/dist/{contracts-s_CDIruh.d.ts → contracts-pugJnFzl.d.mts} +11 -2
- package/dist/{index-CTyZlHKg.d.mts → index-c90msmwW.d.mts} +2 -1
- package/dist/{index-CTyZlHKg.d.ts → index-c90msmwW.d.ts} +2 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +129 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -136
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.d.mts +2 -2
- package/dist/protocols/index.d.ts +2 -2
- package/dist/protocols/index.js +24 -11
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +24 -11
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +94 -95
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +94 -95
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +2 -2
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.js +72 -66
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +72 -66
- package/dist/services/index.mjs.map +1 -1
- package/dist/storage/index.js +5 -2
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/index.mjs +5 -2
- package/dist/storage/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +3 -3
- package/dist/wallet/index.d.ts +3 -3
- package/dist/wallet/index.js +103 -125
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +103 -125
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/wallet/index.mjs
CHANGED
|
@@ -148,11 +148,11 @@ var USDT_ADDRESSES = {
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
var DERIVATION_PATHS = {
|
|
151
|
-
bitcoin: "m/
|
|
151
|
+
bitcoin: "m/84'/0'/0'/0",
|
|
152
152
|
ethereum: "m/44'/60'/0'/0",
|
|
153
|
-
ton: "m/44'/607'/0'
|
|
153
|
+
ton: "m/44'/607'/0'",
|
|
154
154
|
tron: "m/44'/195'/0'/0",
|
|
155
|
-
solana: "m/44'/501'/0'
|
|
155
|
+
solana: "m/44'/501'/0'",
|
|
156
156
|
spark: "m/44'/998'/0'/0"
|
|
157
157
|
};
|
|
158
158
|
function getNetworkConfig(network, isTestnet = false) {
|
|
@@ -230,9 +230,28 @@ var WdkApiClient = class {
|
|
|
230
230
|
constructor(config) {
|
|
231
231
|
this.config = {
|
|
232
232
|
baseUrl: config.baseUrl,
|
|
233
|
-
timeout: config.timeout || 3e4
|
|
233
|
+
timeout: config.timeout || 3e4,
|
|
234
|
+
authToken: config.authToken
|
|
234
235
|
};
|
|
235
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Set or update the auth token for authenticated requests
|
|
239
|
+
*/
|
|
240
|
+
setAuthToken(token) {
|
|
241
|
+
this.config.authToken = token;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Build headers for API requests, including Authorization when available
|
|
245
|
+
*/
|
|
246
|
+
getHeaders() {
|
|
247
|
+
const headers = {
|
|
248
|
+
"Content-Type": "application/json"
|
|
249
|
+
};
|
|
250
|
+
if (this.config.authToken) {
|
|
251
|
+
headers["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
252
|
+
}
|
|
253
|
+
return headers;
|
|
254
|
+
}
|
|
236
255
|
/**
|
|
237
256
|
* Generate a new BIP-39 seed phrase using Tether WDK
|
|
238
257
|
*/
|
|
@@ -240,9 +259,7 @@ var WdkApiClient = class {
|
|
|
240
259
|
try {
|
|
241
260
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/generate-seed`, {
|
|
242
261
|
method: "POST",
|
|
243
|
-
headers:
|
|
244
|
-
"Content-Type": "application/json"
|
|
245
|
-
}
|
|
262
|
+
headers: this.getHeaders()
|
|
246
263
|
});
|
|
247
264
|
return await response.json();
|
|
248
265
|
} catch (error) {
|
|
@@ -259,9 +276,7 @@ var WdkApiClient = class {
|
|
|
259
276
|
try {
|
|
260
277
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/validate-seed`, {
|
|
261
278
|
method: "POST",
|
|
262
|
-
headers:
|
|
263
|
-
"Content-Type": "application/json"
|
|
264
|
-
},
|
|
279
|
+
headers: this.getHeaders(),
|
|
265
280
|
body: JSON.stringify({ seed })
|
|
266
281
|
});
|
|
267
282
|
return await response.json();
|
|
@@ -279,9 +294,7 @@ var WdkApiClient = class {
|
|
|
279
294
|
try {
|
|
280
295
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
281
296
|
method: "POST",
|
|
282
|
-
headers:
|
|
283
|
-
"Content-Type": "application/json"
|
|
284
|
-
},
|
|
297
|
+
headers: this.getHeaders(),
|
|
285
298
|
body: JSON.stringify({ seed, chain, network })
|
|
286
299
|
});
|
|
287
300
|
return await response.json();
|
|
@@ -299,9 +312,7 @@ var WdkApiClient = class {
|
|
|
299
312
|
try {
|
|
300
313
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
301
314
|
method: "POST",
|
|
302
|
-
headers:
|
|
303
|
-
"Content-Type": "application/json"
|
|
304
|
-
},
|
|
315
|
+
headers: this.getHeaders(),
|
|
305
316
|
body: JSON.stringify({ seed, network })
|
|
306
317
|
});
|
|
307
318
|
return await response.json();
|
|
@@ -319,9 +330,7 @@ var WdkApiClient = class {
|
|
|
319
330
|
try {
|
|
320
331
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
321
332
|
method: "POST",
|
|
322
|
-
headers:
|
|
323
|
-
"Content-Type": "application/json"
|
|
324
|
-
},
|
|
333
|
+
headers: this.getHeaders(),
|
|
325
334
|
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
326
335
|
});
|
|
327
336
|
return await response.json();
|
|
@@ -340,9 +349,7 @@ var WdkApiClient = class {
|
|
|
340
349
|
try {
|
|
341
350
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
342
351
|
method: "POST",
|
|
343
|
-
headers:
|
|
344
|
-
"Content-Type": "application/json"
|
|
345
|
-
},
|
|
352
|
+
headers: this.getHeaders(),
|
|
346
353
|
body: JSON.stringify({ seed, chain, network, limit })
|
|
347
354
|
});
|
|
348
355
|
return await response.json();
|
|
@@ -361,9 +368,7 @@ var WdkApiClient = class {
|
|
|
361
368
|
try {
|
|
362
369
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
363
370
|
method: "POST",
|
|
364
|
-
headers:
|
|
365
|
-
"Content-Type": "application/json"
|
|
366
|
-
},
|
|
371
|
+
headers: this.getHeaders(),
|
|
367
372
|
body: JSON.stringify({ txHash, chain, network })
|
|
368
373
|
});
|
|
369
374
|
return await response.json();
|
|
@@ -377,22 +382,23 @@ var WdkApiClient = class {
|
|
|
377
382
|
};
|
|
378
383
|
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
379
384
|
var wdkApiClient = null;
|
|
380
|
-
function getWdkApiClient(baseUrl) {
|
|
385
|
+
function getWdkApiClient(baseUrl, authToken) {
|
|
381
386
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
382
387
|
wdkApiClient = new WdkApiClient({
|
|
383
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
388
|
+
baseUrl: baseUrl || DEFAULT_API_URL,
|
|
389
|
+
authToken
|
|
384
390
|
});
|
|
385
391
|
}
|
|
386
392
|
return wdkApiClient;
|
|
387
393
|
}
|
|
388
394
|
var DERIVATION_PATHS2 = {
|
|
389
|
-
ethereum:
|
|
390
|
-
bitcoin_mainnet:
|
|
395
|
+
ethereum: `${DERIVATION_PATHS.ethereum}/0`,
|
|
396
|
+
bitcoin_mainnet: `${DERIVATION_PATHS.bitcoin}/0`,
|
|
391
397
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
392
|
-
ton:
|
|
393
|
-
tron:
|
|
394
|
-
solana:
|
|
395
|
-
spark:
|
|
398
|
+
ton: `${DERIVATION_PATHS.ton}/0'/0'`,
|
|
399
|
+
tron: `${DERIVATION_PATHS.tron}/0`,
|
|
400
|
+
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
401
|
+
spark: `${DERIVATION_PATHS.spark}/0`
|
|
396
402
|
};
|
|
397
403
|
function deriveEthereumAddress(seed) {
|
|
398
404
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
@@ -905,11 +911,6 @@ var ZubariWdkService = class {
|
|
|
905
911
|
async sendTransaction(seed, chain, to, amount) {
|
|
906
912
|
await this.initialize();
|
|
907
913
|
const startTime = Date.now();
|
|
908
|
-
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
909
|
-
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
910
|
-
amount,
|
|
911
|
-
network: this.config.network
|
|
912
|
-
});
|
|
913
914
|
try {
|
|
914
915
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
915
916
|
method: "POST",
|
|
@@ -929,10 +930,6 @@ var ZubariWdkService = class {
|
|
|
929
930
|
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
930
931
|
}
|
|
931
932
|
}
|
|
932
|
-
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
933
|
-
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
934
|
-
elapsed: `${elapsed}ms`
|
|
935
|
-
});
|
|
936
933
|
if (!data.success) {
|
|
937
934
|
const errorCode2 = parseChainError(chain, data.error || "");
|
|
938
935
|
return {
|
|
@@ -955,12 +952,6 @@ var ZubariWdkService = class {
|
|
|
955
952
|
const errorData = await response.json().catch(() => ({}));
|
|
956
953
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
957
954
|
const errorCode = parseChainError(chain, errorMessage);
|
|
958
|
-
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
959
|
-
status: response.status,
|
|
960
|
-
error: errorMessage,
|
|
961
|
-
errorCode,
|
|
962
|
-
elapsed: `${elapsed}ms`
|
|
963
|
-
});
|
|
964
955
|
return {
|
|
965
956
|
success: false,
|
|
966
957
|
error: errorMessage,
|
|
@@ -968,14 +959,8 @@ var ZubariWdkService = class {
|
|
|
968
959
|
chain
|
|
969
960
|
};
|
|
970
961
|
} catch (error) {
|
|
971
|
-
const elapsed = Date.now() - startTime;
|
|
972
962
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
973
963
|
const errorCode = parseChainError(chain, errorMessage);
|
|
974
|
-
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
975
|
-
error: errorMessage,
|
|
976
|
-
errorCode,
|
|
977
|
-
elapsed: `${elapsed}ms`
|
|
978
|
-
});
|
|
979
964
|
return {
|
|
980
965
|
success: false,
|
|
981
966
|
error: errorMessage,
|
|
@@ -1021,15 +1006,22 @@ var ZubariWdkService = class {
|
|
|
1021
1006
|
// Private Helper Methods
|
|
1022
1007
|
// ==========================================
|
|
1023
1008
|
getDerivationPath(chain) {
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1009
|
+
const basePath = DERIVATION_PATHS[chain];
|
|
1010
|
+
if (chain === "bitcoin" && this.config.network === "testnet") {
|
|
1011
|
+
return "m/84'/1'/0'/0/0";
|
|
1012
|
+
}
|
|
1013
|
+
switch (chain) {
|
|
1014
|
+
case "ton":
|
|
1015
|
+
return `${basePath}/0'/0'`;
|
|
1016
|
+
case "solana":
|
|
1017
|
+
return `${basePath}/0'`;
|
|
1018
|
+
case "bitcoin":
|
|
1019
|
+
case "ethereum":
|
|
1020
|
+
case "tron":
|
|
1021
|
+
case "spark":
|
|
1022
|
+
default:
|
|
1023
|
+
return `${basePath}/0`;
|
|
1024
|
+
}
|
|
1033
1025
|
}
|
|
1034
1026
|
getChainSymbol(chain) {
|
|
1035
1027
|
const symbols = {
|
|
@@ -1093,12 +1085,21 @@ function getZubariWdkService(config) {
|
|
|
1093
1085
|
}
|
|
1094
1086
|
|
|
1095
1087
|
// src/wallet/ZubariWallet.ts
|
|
1096
|
-
var ZubariWallet = class {
|
|
1088
|
+
var ZubariWallet = class _ZubariWallet {
|
|
1097
1089
|
seed;
|
|
1098
1090
|
config;
|
|
1099
1091
|
accounts = /* @__PURE__ */ new Map();
|
|
1100
1092
|
wdkService;
|
|
1101
1093
|
initialized = false;
|
|
1094
|
+
/** Mapping from NetworkType to SupportedChain (identity map, shared across methods) */
|
|
1095
|
+
static CHAIN_MAP = {
|
|
1096
|
+
ethereum: "ethereum",
|
|
1097
|
+
bitcoin: "bitcoin",
|
|
1098
|
+
ton: "ton",
|
|
1099
|
+
tron: "tron",
|
|
1100
|
+
solana: "solana",
|
|
1101
|
+
spark: "spark"
|
|
1102
|
+
};
|
|
1102
1103
|
constructor(seed, config) {
|
|
1103
1104
|
this.seed = seed;
|
|
1104
1105
|
this.config = {
|
|
@@ -1131,15 +1132,7 @@ var ZubariWallet = class {
|
|
|
1131
1132
|
async deriveAccount(network, index = 0) {
|
|
1132
1133
|
const basePath = DERIVATION_PATHS[network];
|
|
1133
1134
|
const derivationPath = `${basePath}/${index}`;
|
|
1134
|
-
const
|
|
1135
|
-
ethereum: "ethereum",
|
|
1136
|
-
bitcoin: "bitcoin",
|
|
1137
|
-
ton: "ton",
|
|
1138
|
-
tron: "tron",
|
|
1139
|
-
solana: "solana",
|
|
1140
|
-
spark: "spark"
|
|
1141
|
-
};
|
|
1142
|
-
const chain = chainMap[network];
|
|
1135
|
+
const chain = _ZubariWallet.CHAIN_MAP[network];
|
|
1143
1136
|
if (!chain) {
|
|
1144
1137
|
throw new Error(`Unsupported network: ${network}`);
|
|
1145
1138
|
}
|
|
@@ -1191,15 +1184,7 @@ var ZubariWallet = class {
|
|
|
1191
1184
|
*/
|
|
1192
1185
|
async getBalance(network) {
|
|
1193
1186
|
const networkConfig = getNetworkConfig(network, this.config.network === "testnet");
|
|
1194
|
-
const
|
|
1195
|
-
ethereum: "ethereum",
|
|
1196
|
-
bitcoin: "bitcoin",
|
|
1197
|
-
ton: "ton",
|
|
1198
|
-
tron: "tron",
|
|
1199
|
-
solana: "solana",
|
|
1200
|
-
spark: "spark"
|
|
1201
|
-
};
|
|
1202
|
-
const chain = chainMap[network];
|
|
1187
|
+
const chain = _ZubariWallet.CHAIN_MAP[network];
|
|
1203
1188
|
if (!chain) {
|
|
1204
1189
|
throw new Error(`Unsupported network: ${network}`);
|
|
1205
1190
|
}
|
|
@@ -1286,15 +1271,7 @@ var ZubariWallet = class {
|
|
|
1286
1271
|
*/
|
|
1287
1272
|
async send(network, params) {
|
|
1288
1273
|
const { to, amount } = params;
|
|
1289
|
-
const
|
|
1290
|
-
ethereum: "ethereum",
|
|
1291
|
-
bitcoin: "bitcoin",
|
|
1292
|
-
ton: "ton",
|
|
1293
|
-
tron: "tron",
|
|
1294
|
-
solana: "solana",
|
|
1295
|
-
spark: "spark"
|
|
1296
|
-
};
|
|
1297
|
-
const chain = chainMap[network];
|
|
1274
|
+
const chain = _ZubariWallet.CHAIN_MAP[network];
|
|
1298
1275
|
if (!chain) {
|
|
1299
1276
|
throw new Error(`Unsupported network: ${network}`);
|
|
1300
1277
|
}
|
|
@@ -1599,7 +1576,10 @@ var KeyManager = class {
|
|
|
1599
1576
|
static KEY_LENGTH = 256;
|
|
1600
1577
|
static IV_LENGTH = 12;
|
|
1601
1578
|
static SALT_LENGTH = 16;
|
|
1602
|
-
|
|
1579
|
+
// OWASP 2023 recommends 600,000 iterations for PBKDF2-SHA256 to resist
|
|
1580
|
+
// brute-force attacks with modern GPU hardware.
|
|
1581
|
+
// See: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
|
|
1582
|
+
static PBKDF2_ITERATIONS = 6e5;
|
|
1603
1583
|
/**
|
|
1604
1584
|
* Encrypt a seed phrase with a password
|
|
1605
1585
|
*/
|
|
@@ -1838,7 +1818,7 @@ var WebEncryptedStorageAdapter = class {
|
|
|
1838
1818
|
{
|
|
1839
1819
|
name: "PBKDF2",
|
|
1840
1820
|
salt: salt.buffer,
|
|
1841
|
-
iterations:
|
|
1821
|
+
iterations: 6e5,
|
|
1842
1822
|
hash: "SHA-256"
|
|
1843
1823
|
},
|
|
1844
1824
|
keyMaterial,
|
|
@@ -2151,6 +2131,16 @@ var WalletManager = class _WalletManager {
|
|
|
2151
2131
|
}
|
|
2152
2132
|
/**
|
|
2153
2133
|
* Lock wallet (clear seed from memory)
|
|
2134
|
+
*
|
|
2135
|
+
* SECURITY NOTE: JavaScript strings are immutable and cannot be overwritten
|
|
2136
|
+
* in place. Setting `this.currentSeed = null` removes the reference, but
|
|
2137
|
+
* the original string may persist in memory until garbage collected.
|
|
2138
|
+
* There is no reliable way to zero out a JS string.
|
|
2139
|
+
*
|
|
2140
|
+
* TODO: In a future version, store the seed as a Uint8Array instead of a
|
|
2141
|
+
* string. Uint8Array contents can be explicitly zeroed (e.g.,
|
|
2142
|
+
* `seedBytes.fill(0)`) before releasing the reference, which provides
|
|
2143
|
+
* stronger guarantees that sensitive material is scrubbed from memory.
|
|
2154
2144
|
*/
|
|
2155
2145
|
lock() {
|
|
2156
2146
|
this.currentSeed = null;
|
|
@@ -2367,7 +2357,6 @@ var WalletManager = class _WalletManager {
|
|
|
2367
2357
|
async saveAddressesToStorage(addresses) {
|
|
2368
2358
|
try {
|
|
2369
2359
|
await this.storage.setItem(STORAGE_KEYS.DERIVED_ADDRESSES, JSON.stringify(addresses));
|
|
2370
|
-
console.log("Saved derived addresses to storage:", Object.keys(addresses));
|
|
2371
2360
|
} catch (error) {
|
|
2372
2361
|
console.warn("Failed to save addresses to storage:", error);
|
|
2373
2362
|
}
|
|
@@ -2407,9 +2396,7 @@ var WalletManager = class _WalletManager {
|
|
|
2407
2396
|
const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
|
|
2408
2397
|
if (stored) {
|
|
2409
2398
|
const rawAddresses = JSON.parse(stored);
|
|
2410
|
-
console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
|
|
2411
2399
|
const addresses = this.normalizeAddresses(rawAddresses);
|
|
2412
|
-
console.log("[WalletManager] Normalized addresses:", addresses);
|
|
2413
2400
|
await this.saveAddressesToStorage(addresses);
|
|
2414
2401
|
return addresses;
|
|
2415
2402
|
}
|
|
@@ -2434,11 +2421,8 @@ var WalletManager = class _WalletManager {
|
|
|
2434
2421
|
if (storedAddresses && Object.keys(storedAddresses).length > 1) {
|
|
2435
2422
|
const expectedEthAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
2436
2423
|
if (storedAddresses.ethereum === expectedEthAddress) {
|
|
2437
|
-
console.log("Using addresses from storage (verified by Ethereum address)");
|
|
2438
2424
|
this.derivedAddresses = storedAddresses;
|
|
2439
2425
|
return storedAddresses;
|
|
2440
|
-
} else {
|
|
2441
|
-
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
2442
2426
|
}
|
|
2443
2427
|
}
|
|
2444
2428
|
return await this.deriveAllAddressesWithWdk();
|
|
@@ -2450,9 +2434,7 @@ var WalletManager = class _WalletManager {
|
|
|
2450
2434
|
getAddressForChain(chain) {
|
|
2451
2435
|
const cachedValue = this.derivedAddresses[chain];
|
|
2452
2436
|
if (cachedValue) {
|
|
2453
|
-
console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
|
|
2454
2437
|
const addr = this.normalizeAddress(cachedValue);
|
|
2455
|
-
console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
|
|
2456
2438
|
if (addr) {
|
|
2457
2439
|
this.derivedAddresses[chain] = addr;
|
|
2458
2440
|
return addr;
|
|
@@ -2579,10 +2561,8 @@ var WalletManager = class _WalletManager {
|
|
|
2579
2561
|
const mempoolSpent = data.mempool_stats?.spent_txo_sum || 0;
|
|
2580
2562
|
const satoshis = chainFunded - chainSpent + (mempoolFunded - mempoolSpent);
|
|
2581
2563
|
balance = (satoshis / 1e8).toFixed(8);
|
|
2582
|
-
console.log(`Bitcoin balance for ${address}: ${balance} BTC (${satoshis} sats) via ${apiUrl}`);
|
|
2583
2564
|
break;
|
|
2584
2565
|
}
|
|
2585
|
-
console.log(`No transactions found on ${apiUrl}, trying next...`);
|
|
2586
2566
|
}
|
|
2587
2567
|
} catch (error) {
|
|
2588
2568
|
console.warn(`Failed to fetch from ${apiUrl}:`, error);
|
|
@@ -2685,7 +2665,6 @@ var WalletManager = class _WalletManager {
|
|
|
2685
2665
|
if (data.ok && data.result !== void 0) {
|
|
2686
2666
|
const nanotons = BigInt(data.result);
|
|
2687
2667
|
balance = (Number(nanotons) / 1e9).toFixed(9);
|
|
2688
|
-
console.log(`TON balance for ${address}: ${balance} TON`);
|
|
2689
2668
|
}
|
|
2690
2669
|
}
|
|
2691
2670
|
} catch (error) {
|
|
@@ -2742,7 +2721,6 @@ var WalletManager = class _WalletManager {
|
|
|
2742
2721
|
const data = await response.json();
|
|
2743
2722
|
if (data.success && data.balance !== void 0) {
|
|
2744
2723
|
balance = (parseFloat(data.balance) / 1e8).toFixed(8);
|
|
2745
|
-
console.log(`Spark balance for ${address}: ${balance} BTC`);
|
|
2746
2724
|
}
|
|
2747
2725
|
}
|
|
2748
2726
|
} catch (error) {
|
|
@@ -2763,28 +2741,29 @@ var WalletManager = class _WalletManager {
|
|
|
2763
2741
|
};
|
|
2764
2742
|
}
|
|
2765
2743
|
/**
|
|
2766
|
-
* Fetch balances for all enabled chains
|
|
2744
|
+
* Fetch balances for all enabled chains in parallel.
|
|
2745
|
+
* Uses Promise.allSettled so that one chain failing does not block others.
|
|
2767
2746
|
*/
|
|
2768
2747
|
async fetchAllBalances() {
|
|
2769
|
-
const
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
const networkConfig = this.getChainConfig(chain);
|
|
2777
|
-
balances.push({
|
|
2778
|
-
chain,
|
|
2779
|
-
symbol: networkConfig.nativeCurrency.symbol,
|
|
2780
|
-
balance: "0",
|
|
2781
|
-
balanceUsd: 0,
|
|
2782
|
-
address: this.getAddressForChain(chain) || "",
|
|
2783
|
-
decimals: networkConfig.nativeCurrency.decimals
|
|
2784
|
-
});
|
|
2748
|
+
const results = await Promise.allSettled(
|
|
2749
|
+
this.config.enabledChains.map((chain) => this.fetchBalanceForChain(chain))
|
|
2750
|
+
);
|
|
2751
|
+
return results.map((result, index) => {
|
|
2752
|
+
const chain = this.config.enabledChains[index];
|
|
2753
|
+
if (result.status === "fulfilled") {
|
|
2754
|
+
return result.value;
|
|
2785
2755
|
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2756
|
+
console.error(`Failed to fetch balance for ${chain}:`, result.reason);
|
|
2757
|
+
const networkConfig = this.getChainConfig(chain);
|
|
2758
|
+
return {
|
|
2759
|
+
chain,
|
|
2760
|
+
symbol: networkConfig.nativeCurrency.symbol,
|
|
2761
|
+
balance: "0",
|
|
2762
|
+
balanceUsd: 0,
|
|
2763
|
+
address: this.getAddressForChain(chain) || "",
|
|
2764
|
+
decimals: networkConfig.nativeCurrency.decimals
|
|
2765
|
+
};
|
|
2766
|
+
});
|
|
2788
2767
|
}
|
|
2789
2768
|
/**
|
|
2790
2769
|
* Get extended wallet state with multi-chain info
|
|
@@ -2838,7 +2817,6 @@ var WalletManager = class _WalletManager {
|
|
|
2838
2817
|
});
|
|
2839
2818
|
if (response.ok) {
|
|
2840
2819
|
const data = await response.json();
|
|
2841
|
-
console.log(`Transaction sent on ${chain}:`, data);
|
|
2842
2820
|
let txHash = data.txHash || data.transactionHash || data.hash;
|
|
2843
2821
|
if (txHash && typeof txHash === "object" && "hash" in txHash) {
|
|
2844
2822
|
txHash = txHash.hash;
|