@zubari/sdk 0.5.2 → 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 +339 -916
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +337 -914
- 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 +255 -826
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +253 -824
- 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 +179 -767
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +177 -765
- 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 +262 -854
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +260 -852
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -2,12 +2,9 @@ import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
|
2
2
|
import { Wallet, HDNodeWallet } from 'ethers';
|
|
3
3
|
import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
|
|
4
4
|
import { wordlist } from '@scure/bip39/wordlists/english';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { sha256, sha512 } from '@noble/hashes/sha2.js';
|
|
9
|
-
import { createView, concatBytes, abytes } from '@noble/hashes/utils.js';
|
|
10
|
-
import { sha256 as sha256$1 } from '@noble/hashes/sha256';
|
|
5
|
+
import { HDKey } from '@scure/bip32';
|
|
6
|
+
import { bech32, base58check } from '@scure/base';
|
|
7
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
11
8
|
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
12
9
|
import { createPublicClient, http, formatEther, getAddress } from 'viem';
|
|
13
10
|
import { mainnet, sepolia } from 'viem/chains';
|
|
@@ -135,8 +132,8 @@ var TESTNET_NETWORKS = {
|
|
|
135
132
|
var USDT_ADDRESSES = {
|
|
136
133
|
ethereum: {
|
|
137
134
|
mainnet: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
138
|
-
testnet: "
|
|
139
|
-
// Sepolia
|
|
135
|
+
testnet: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
|
|
136
|
+
// Sepolia (Test Tether USD)
|
|
140
137
|
},
|
|
141
138
|
tron: {
|
|
142
139
|
mainnet: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -154,7 +151,13 @@ var USDT_ADDRESSES = {
|
|
|
154
151
|
}
|
|
155
152
|
};
|
|
156
153
|
var DERIVATION_PATHS = {
|
|
157
|
-
|
|
154
|
+
bitcoin: "m/84'/0'/0'/0",
|
|
155
|
+
ethereum: "m/44'/60'/0'/0",
|
|
156
|
+
ton: "m/44'/607'/0'",
|
|
157
|
+
tron: "m/44'/195'/0'/0",
|
|
158
|
+
solana: "m/44'/501'/0'",
|
|
159
|
+
spark: "m/44'/998'/0'/0"
|
|
160
|
+
};
|
|
158
161
|
function getNetworkConfig(network, isTestnet = false) {
|
|
159
162
|
const mainnetConfig = NETWORKS[network];
|
|
160
163
|
if (!isTestnet) return mainnetConfig;
|
|
@@ -172,8 +175,27 @@ var WdkApiClient = class {
|
|
|
172
175
|
constructor(config) {
|
|
173
176
|
this.config = {
|
|
174
177
|
baseUrl: config.baseUrl,
|
|
175
|
-
timeout: config.timeout || 3e4
|
|
178
|
+
timeout: config.timeout || 3e4,
|
|
179
|
+
authToken: config.authToken
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Set or update the auth token for authenticated requests
|
|
184
|
+
*/
|
|
185
|
+
setAuthToken(token) {
|
|
186
|
+
this.config.authToken = token;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Build headers for API requests, including Authorization when available
|
|
190
|
+
*/
|
|
191
|
+
getHeaders() {
|
|
192
|
+
const headers = {
|
|
193
|
+
"Content-Type": "application/json"
|
|
176
194
|
};
|
|
195
|
+
if (this.config.authToken) {
|
|
196
|
+
headers["Authorization"] = `Bearer ${this.config.authToken}`;
|
|
197
|
+
}
|
|
198
|
+
return headers;
|
|
177
199
|
}
|
|
178
200
|
/**
|
|
179
201
|
* Generate a new BIP-39 seed phrase using Tether WDK
|
|
@@ -182,9 +204,7 @@ var WdkApiClient = class {
|
|
|
182
204
|
try {
|
|
183
205
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/generate-seed`, {
|
|
184
206
|
method: "POST",
|
|
185
|
-
headers:
|
|
186
|
-
"Content-Type": "application/json"
|
|
187
|
-
}
|
|
207
|
+
headers: this.getHeaders()
|
|
188
208
|
});
|
|
189
209
|
return await response.json();
|
|
190
210
|
} catch (error) {
|
|
@@ -201,9 +221,7 @@ var WdkApiClient = class {
|
|
|
201
221
|
try {
|
|
202
222
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/validate-seed`, {
|
|
203
223
|
method: "POST",
|
|
204
|
-
headers:
|
|
205
|
-
"Content-Type": "application/json"
|
|
206
|
-
},
|
|
224
|
+
headers: this.getHeaders(),
|
|
207
225
|
body: JSON.stringify({ seed })
|
|
208
226
|
});
|
|
209
227
|
return await response.json();
|
|
@@ -217,14 +235,12 @@ var WdkApiClient = class {
|
|
|
217
235
|
/**
|
|
218
236
|
* Derive address for a specific chain using Tether WDK
|
|
219
237
|
*/
|
|
220
|
-
async deriveAddress(seed,
|
|
238
|
+
async deriveAddress(seed, chain, network = "mainnet") {
|
|
221
239
|
try {
|
|
222
240
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
223
241
|
method: "POST",
|
|
224
|
-
headers:
|
|
225
|
-
|
|
226
|
-
},
|
|
227
|
-
body: JSON.stringify({ seed, chain: chain2, network })
|
|
242
|
+
headers: this.getHeaders(),
|
|
243
|
+
body: JSON.stringify({ seed, chain, network })
|
|
228
244
|
});
|
|
229
245
|
return await response.json();
|
|
230
246
|
} catch (error) {
|
|
@@ -241,9 +257,7 @@ var WdkApiClient = class {
|
|
|
241
257
|
try {
|
|
242
258
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-all`, {
|
|
243
259
|
method: "POST",
|
|
244
|
-
headers:
|
|
245
|
-
"Content-Type": "application/json"
|
|
246
|
-
},
|
|
260
|
+
headers: this.getHeaders(),
|
|
247
261
|
body: JSON.stringify({ seed, network })
|
|
248
262
|
});
|
|
249
263
|
return await response.json();
|
|
@@ -257,14 +271,12 @@ var WdkApiClient = class {
|
|
|
257
271
|
/**
|
|
258
272
|
* Send a transaction on a specific chain using Tether WDK
|
|
259
273
|
*/
|
|
260
|
-
async sendTransaction(seed,
|
|
274
|
+
async sendTransaction(seed, chain, to, amount, network = "mainnet") {
|
|
261
275
|
try {
|
|
262
276
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
263
277
|
method: "POST",
|
|
264
|
-
headers:
|
|
265
|
-
|
|
266
|
-
},
|
|
267
|
-
body: JSON.stringify({ seed, chain: chain2, to, amount, network })
|
|
278
|
+
headers: this.getHeaders(),
|
|
279
|
+
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
268
280
|
});
|
|
269
281
|
return await response.json();
|
|
270
282
|
} catch (error) {
|
|
@@ -278,14 +290,12 @@ var WdkApiClient = class {
|
|
|
278
290
|
* Get transaction history for an address on a specific chain
|
|
279
291
|
* Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
|
|
280
292
|
*/
|
|
281
|
-
async getTransactionHistory(seed,
|
|
293
|
+
async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
|
|
282
294
|
try {
|
|
283
295
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
284
296
|
method: "POST",
|
|
285
|
-
headers:
|
|
286
|
-
|
|
287
|
-
},
|
|
288
|
-
body: JSON.stringify({ seed, chain: chain2, network, limit })
|
|
297
|
+
headers: this.getHeaders(),
|
|
298
|
+
body: JSON.stringify({ seed, chain, network, limit })
|
|
289
299
|
});
|
|
290
300
|
return await response.json();
|
|
291
301
|
} catch (error) {
|
|
@@ -299,14 +309,12 @@ var WdkApiClient = class {
|
|
|
299
309
|
* Get transaction status by hash
|
|
300
310
|
* Fetches from blockchain explorers to check confirmation status
|
|
301
311
|
*/
|
|
302
|
-
async getTransactionStatus(txHash,
|
|
312
|
+
async getTransactionStatus(txHash, chain, network = "mainnet") {
|
|
303
313
|
try {
|
|
304
314
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
305
315
|
method: "POST",
|
|
306
|
-
headers:
|
|
307
|
-
|
|
308
|
-
},
|
|
309
|
-
body: JSON.stringify({ txHash, chain: chain2, network })
|
|
316
|
+
headers: this.getHeaders(),
|
|
317
|
+
body: JSON.stringify({ txHash, chain, network })
|
|
310
318
|
});
|
|
311
319
|
return await response.json();
|
|
312
320
|
} catch (error) {
|
|
@@ -319,605 +327,23 @@ var WdkApiClient = class {
|
|
|
319
327
|
};
|
|
320
328
|
var DEFAULT_API_URL = process.env.NEXT_PUBLIC_API_URL || "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
321
329
|
var wdkApiClient = null;
|
|
322
|
-
function getWdkApiClient(baseUrl) {
|
|
330
|
+
function getWdkApiClient(baseUrl, authToken) {
|
|
323
331
|
if (!wdkApiClient || baseUrl && wdkApiClient["config"].baseUrl !== baseUrl) {
|
|
324
332
|
wdkApiClient = new WdkApiClient({
|
|
325
|
-
baseUrl: baseUrl || DEFAULT_API_URL
|
|
333
|
+
baseUrl: baseUrl || DEFAULT_API_URL,
|
|
334
|
+
authToken
|
|
326
335
|
});
|
|
327
336
|
}
|
|
328
337
|
return wdkApiClient;
|
|
329
338
|
}
|
|
330
|
-
|
|
331
|
-
// node_modules/@scure/base/index.js
|
|
332
|
-
function isBytes(a) {
|
|
333
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
334
|
-
}
|
|
335
|
-
function isArrayOf(isString, arr) {
|
|
336
|
-
if (!Array.isArray(arr))
|
|
337
|
-
return false;
|
|
338
|
-
if (arr.length === 0)
|
|
339
|
-
return true;
|
|
340
|
-
if (isString) {
|
|
341
|
-
return arr.every((item) => typeof item === "string");
|
|
342
|
-
} else {
|
|
343
|
-
return arr.every((item) => Number.isSafeInteger(item));
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function afn(input) {
|
|
347
|
-
if (typeof input !== "function")
|
|
348
|
-
throw new Error("function expected");
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
function astr(label, input) {
|
|
352
|
-
if (typeof input !== "string")
|
|
353
|
-
throw new Error(`${label}: string expected`);
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
function anumber(n) {
|
|
357
|
-
if (!Number.isSafeInteger(n))
|
|
358
|
-
throw new Error(`invalid integer: ${n}`);
|
|
359
|
-
}
|
|
360
|
-
function aArr(input) {
|
|
361
|
-
if (!Array.isArray(input))
|
|
362
|
-
throw new Error("array expected");
|
|
363
|
-
}
|
|
364
|
-
function astrArr(label, input) {
|
|
365
|
-
if (!isArrayOf(true, input))
|
|
366
|
-
throw new Error(`${label}: array of strings expected`);
|
|
367
|
-
}
|
|
368
|
-
function anumArr(label, input) {
|
|
369
|
-
if (!isArrayOf(false, input))
|
|
370
|
-
throw new Error(`${label}: array of numbers expected`);
|
|
371
|
-
}
|
|
372
|
-
// @__NO_SIDE_EFFECTS__
|
|
373
|
-
function chain(...args) {
|
|
374
|
-
const id = (a) => a;
|
|
375
|
-
const wrap = (a, b) => (c) => a(b(c));
|
|
376
|
-
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
377
|
-
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
378
|
-
return { encode, decode };
|
|
379
|
-
}
|
|
380
|
-
// @__NO_SIDE_EFFECTS__
|
|
381
|
-
function alphabet(letters) {
|
|
382
|
-
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
383
|
-
const len = lettersA.length;
|
|
384
|
-
astrArr("alphabet", lettersA);
|
|
385
|
-
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
386
|
-
return {
|
|
387
|
-
encode: (digits) => {
|
|
388
|
-
aArr(digits);
|
|
389
|
-
return digits.map((i) => {
|
|
390
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
391
|
-
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
392
|
-
return lettersA[i];
|
|
393
|
-
});
|
|
394
|
-
},
|
|
395
|
-
decode: (input) => {
|
|
396
|
-
aArr(input);
|
|
397
|
-
return input.map((letter) => {
|
|
398
|
-
astr("alphabet.decode", letter);
|
|
399
|
-
const i = indexes.get(letter);
|
|
400
|
-
if (i === void 0)
|
|
401
|
-
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
402
|
-
return i;
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
// @__NO_SIDE_EFFECTS__
|
|
408
|
-
function join(separator = "") {
|
|
409
|
-
astr("join", separator);
|
|
410
|
-
return {
|
|
411
|
-
encode: (from) => {
|
|
412
|
-
astrArr("join.decode", from);
|
|
413
|
-
return from.join(separator);
|
|
414
|
-
},
|
|
415
|
-
decode: (to) => {
|
|
416
|
-
astr("join.decode", to);
|
|
417
|
-
return to.split(separator);
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
function convertRadix(data, from, to) {
|
|
422
|
-
if (from < 2)
|
|
423
|
-
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
424
|
-
if (to < 2)
|
|
425
|
-
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
426
|
-
aArr(data);
|
|
427
|
-
if (!data.length)
|
|
428
|
-
return [];
|
|
429
|
-
let pos = 0;
|
|
430
|
-
const res = [];
|
|
431
|
-
const digits = Array.from(data, (d) => {
|
|
432
|
-
anumber(d);
|
|
433
|
-
if (d < 0 || d >= from)
|
|
434
|
-
throw new Error(`invalid integer: ${d}`);
|
|
435
|
-
return d;
|
|
436
|
-
});
|
|
437
|
-
const dlen = digits.length;
|
|
438
|
-
while (true) {
|
|
439
|
-
let carry = 0;
|
|
440
|
-
let done = true;
|
|
441
|
-
for (let i = pos; i < dlen; i++) {
|
|
442
|
-
const digit = digits[i];
|
|
443
|
-
const fromCarry = from * carry;
|
|
444
|
-
const digitBase = fromCarry + digit;
|
|
445
|
-
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
446
|
-
throw new Error("convertRadix: carry overflow");
|
|
447
|
-
}
|
|
448
|
-
const div = digitBase / to;
|
|
449
|
-
carry = digitBase % to;
|
|
450
|
-
const rounded = Math.floor(div);
|
|
451
|
-
digits[i] = rounded;
|
|
452
|
-
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
453
|
-
throw new Error("convertRadix: carry overflow");
|
|
454
|
-
if (!done)
|
|
455
|
-
continue;
|
|
456
|
-
else if (!rounded)
|
|
457
|
-
pos = i;
|
|
458
|
-
else
|
|
459
|
-
done = false;
|
|
460
|
-
}
|
|
461
|
-
res.push(carry);
|
|
462
|
-
if (done)
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
|
466
|
-
res.push(0);
|
|
467
|
-
return res.reverse();
|
|
468
|
-
}
|
|
469
|
-
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
470
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
471
|
-
var powers = /* @__PURE__ */ (() => {
|
|
472
|
-
let res = [];
|
|
473
|
-
for (let i = 0; i < 40; i++)
|
|
474
|
-
res.push(2 ** i);
|
|
475
|
-
return res;
|
|
476
|
-
})();
|
|
477
|
-
function convertRadix2(data, from, to, padding) {
|
|
478
|
-
aArr(data);
|
|
479
|
-
if (from <= 0 || from > 32)
|
|
480
|
-
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
481
|
-
if (to <= 0 || to > 32)
|
|
482
|
-
throw new Error(`convertRadix2: wrong to=${to}`);
|
|
483
|
-
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
|
484
|
-
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
485
|
-
}
|
|
486
|
-
let carry = 0;
|
|
487
|
-
let pos = 0;
|
|
488
|
-
const max = powers[from];
|
|
489
|
-
const mask = powers[to] - 1;
|
|
490
|
-
const res = [];
|
|
491
|
-
for (const n of data) {
|
|
492
|
-
anumber(n);
|
|
493
|
-
if (n >= max)
|
|
494
|
-
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
495
|
-
carry = carry << from | n;
|
|
496
|
-
if (pos + from > 32)
|
|
497
|
-
throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
498
|
-
pos += from;
|
|
499
|
-
for (; pos >= to; pos -= to)
|
|
500
|
-
res.push((carry >> pos - to & mask) >>> 0);
|
|
501
|
-
const pow = powers[pos];
|
|
502
|
-
if (pow === void 0)
|
|
503
|
-
throw new Error("invalid carry");
|
|
504
|
-
carry &= pow - 1;
|
|
505
|
-
}
|
|
506
|
-
carry = carry << to - pos & mask;
|
|
507
|
-
if (!padding && pos >= from)
|
|
508
|
-
throw new Error("Excess padding");
|
|
509
|
-
if (!padding && carry > 0)
|
|
510
|
-
throw new Error(`Non-zero padding: ${carry}`);
|
|
511
|
-
if (padding && pos > 0)
|
|
512
|
-
res.push(carry >>> 0);
|
|
513
|
-
return res;
|
|
514
|
-
}
|
|
515
|
-
// @__NO_SIDE_EFFECTS__
|
|
516
|
-
function radix(num) {
|
|
517
|
-
anumber(num);
|
|
518
|
-
const _256 = 2 ** 8;
|
|
519
|
-
return {
|
|
520
|
-
encode: (bytes) => {
|
|
521
|
-
if (!isBytes(bytes))
|
|
522
|
-
throw new Error("radix.encode input should be Uint8Array");
|
|
523
|
-
return convertRadix(Array.from(bytes), _256, num);
|
|
524
|
-
},
|
|
525
|
-
decode: (digits) => {
|
|
526
|
-
anumArr("radix.decode", digits);
|
|
527
|
-
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
528
|
-
}
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
// @__NO_SIDE_EFFECTS__
|
|
532
|
-
function radix2(bits, revPadding = false) {
|
|
533
|
-
anumber(bits);
|
|
534
|
-
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
535
|
-
throw new Error("radix2: carry overflow");
|
|
536
|
-
return {
|
|
537
|
-
encode: (bytes) => {
|
|
538
|
-
if (!isBytes(bytes))
|
|
539
|
-
throw new Error("radix2.encode input should be Uint8Array");
|
|
540
|
-
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
541
|
-
},
|
|
542
|
-
decode: (digits) => {
|
|
543
|
-
anumArr("radix2.decode", digits);
|
|
544
|
-
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
function unsafeWrapper(fn) {
|
|
549
|
-
afn(fn);
|
|
550
|
-
return function(...args) {
|
|
551
|
-
try {
|
|
552
|
-
return fn.apply(null, args);
|
|
553
|
-
} catch (e) {
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function checksum(len, fn) {
|
|
558
|
-
anumber(len);
|
|
559
|
-
afn(fn);
|
|
560
|
-
return {
|
|
561
|
-
encode(data) {
|
|
562
|
-
if (!isBytes(data))
|
|
563
|
-
throw new Error("checksum.encode: input should be Uint8Array");
|
|
564
|
-
const sum = fn(data).slice(0, len);
|
|
565
|
-
const res = new Uint8Array(data.length + len);
|
|
566
|
-
res.set(data);
|
|
567
|
-
res.set(sum, data.length);
|
|
568
|
-
return res;
|
|
569
|
-
},
|
|
570
|
-
decode(data) {
|
|
571
|
-
if (!isBytes(data))
|
|
572
|
-
throw new Error("checksum.decode: input should be Uint8Array");
|
|
573
|
-
const payload = data.slice(0, -len);
|
|
574
|
-
const oldChecksum = data.slice(-len);
|
|
575
|
-
const newChecksum = fn(payload).slice(0, len);
|
|
576
|
-
for (let i = 0; i < len; i++)
|
|
577
|
-
if (newChecksum[i] !== oldChecksum[i])
|
|
578
|
-
throw new Error("Invalid checksum");
|
|
579
|
-
return payload;
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
584
|
-
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
585
|
-
var createBase58check = (sha2563) => /* @__PURE__ */ chain(checksum(4, (data) => sha2563(sha2563(data))), base58);
|
|
586
|
-
var base58check = createBase58check;
|
|
587
|
-
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
588
|
-
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
589
|
-
function bech32Polymod(pre) {
|
|
590
|
-
const b = pre >> 25;
|
|
591
|
-
let chk = (pre & 33554431) << 5;
|
|
592
|
-
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
|
|
593
|
-
if ((b >> i & 1) === 1)
|
|
594
|
-
chk ^= POLYMOD_GENERATORS[i];
|
|
595
|
-
}
|
|
596
|
-
return chk;
|
|
597
|
-
}
|
|
598
|
-
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
599
|
-
const len = prefix.length;
|
|
600
|
-
let chk = 1;
|
|
601
|
-
for (let i = 0; i < len; i++) {
|
|
602
|
-
const c = prefix.charCodeAt(i);
|
|
603
|
-
if (c < 33 || c > 126)
|
|
604
|
-
throw new Error(`Invalid prefix (${prefix})`);
|
|
605
|
-
chk = bech32Polymod(chk) ^ c >> 5;
|
|
606
|
-
}
|
|
607
|
-
chk = bech32Polymod(chk);
|
|
608
|
-
for (let i = 0; i < len; i++)
|
|
609
|
-
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
610
|
-
for (let v of words)
|
|
611
|
-
chk = bech32Polymod(chk) ^ v;
|
|
612
|
-
for (let i = 0; i < 6; i++)
|
|
613
|
-
chk = bech32Polymod(chk);
|
|
614
|
-
chk ^= encodingConst;
|
|
615
|
-
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
616
|
-
}
|
|
617
|
-
// @__NO_SIDE_EFFECTS__
|
|
618
|
-
function genBech32(encoding) {
|
|
619
|
-
const ENCODING_CONST = 1 ;
|
|
620
|
-
const _words = /* @__PURE__ */ radix2(5);
|
|
621
|
-
const fromWords = _words.decode;
|
|
622
|
-
const toWords = _words.encode;
|
|
623
|
-
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
624
|
-
function encode(prefix, words, limit = 90) {
|
|
625
|
-
astr("bech32.encode prefix", prefix);
|
|
626
|
-
if (isBytes(words))
|
|
627
|
-
words = Array.from(words);
|
|
628
|
-
anumArr("bech32.encode", words);
|
|
629
|
-
const plen = prefix.length;
|
|
630
|
-
if (plen === 0)
|
|
631
|
-
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
632
|
-
const actualLength = plen + 7 + words.length;
|
|
633
|
-
if (limit !== false && actualLength > limit)
|
|
634
|
-
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
635
|
-
const lowered = prefix.toLowerCase();
|
|
636
|
-
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
637
|
-
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
638
|
-
}
|
|
639
|
-
function decode(str, limit = 90) {
|
|
640
|
-
astr("bech32.decode input", str);
|
|
641
|
-
const slen = str.length;
|
|
642
|
-
if (slen < 8 || limit !== false && slen > limit)
|
|
643
|
-
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
644
|
-
const lowered = str.toLowerCase();
|
|
645
|
-
if (str !== lowered && str !== str.toUpperCase())
|
|
646
|
-
throw new Error(`String must be lowercase or uppercase`);
|
|
647
|
-
const sepIndex = lowered.lastIndexOf("1");
|
|
648
|
-
if (sepIndex === 0 || sepIndex === -1)
|
|
649
|
-
throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
650
|
-
const prefix = lowered.slice(0, sepIndex);
|
|
651
|
-
const data = lowered.slice(sepIndex + 1);
|
|
652
|
-
if (data.length < 6)
|
|
653
|
-
throw new Error("Data must be at least 6 characters long");
|
|
654
|
-
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
655
|
-
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
656
|
-
if (!data.endsWith(sum))
|
|
657
|
-
throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
658
|
-
return { prefix, words };
|
|
659
|
-
}
|
|
660
|
-
const decodeUnsafe = unsafeWrapper(decode);
|
|
661
|
-
function decodeToBytes(str) {
|
|
662
|
-
const { prefix, words } = decode(str, false);
|
|
663
|
-
return { prefix, words, bytes: fromWords(words) };
|
|
664
|
-
}
|
|
665
|
-
function encodeFromBytes(prefix, bytes) {
|
|
666
|
-
return encode(prefix, toWords(bytes));
|
|
667
|
-
}
|
|
668
|
-
return {
|
|
669
|
-
encode,
|
|
670
|
-
decode,
|
|
671
|
-
encodeFromBytes,
|
|
672
|
-
decodeToBytes,
|
|
673
|
-
decodeUnsafe,
|
|
674
|
-
fromWords,
|
|
675
|
-
fromWordsUnsafe,
|
|
676
|
-
toWords
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
var bech32 = /* @__PURE__ */ genBech32();
|
|
680
|
-
|
|
681
|
-
// node_modules/@scure/bip32/index.js
|
|
682
|
-
var Point = secp256k1.Point;
|
|
683
|
-
var { Fn } = Point;
|
|
684
|
-
var base58check2 = createBase58check(sha256);
|
|
685
|
-
var MASTER_SECRET = Uint8Array.from("Bitcoin seed".split(""), (char) => char.charCodeAt(0));
|
|
686
|
-
var BITCOIN_VERSIONS = { private: 76066276, public: 76067358 };
|
|
687
|
-
var HARDENED_OFFSET = 2147483648;
|
|
688
|
-
var hash160 = (data) => ripemd160$1(sha256(data));
|
|
689
|
-
var fromU32 = (data) => createView(data).getUint32(0, false);
|
|
690
|
-
var toU32 = (n) => {
|
|
691
|
-
if (!Number.isSafeInteger(n) || n < 0 || n > 2 ** 32 - 1) {
|
|
692
|
-
throw new Error("invalid number, should be from 0 to 2**32-1, got " + n);
|
|
693
|
-
}
|
|
694
|
-
const buf = new Uint8Array(4);
|
|
695
|
-
createView(buf).setUint32(0, n, false);
|
|
696
|
-
return buf;
|
|
697
|
-
};
|
|
698
|
-
var HDKey = class _HDKey {
|
|
699
|
-
get fingerprint() {
|
|
700
|
-
if (!this.pubHash) {
|
|
701
|
-
throw new Error("No publicKey set!");
|
|
702
|
-
}
|
|
703
|
-
return fromU32(this.pubHash);
|
|
704
|
-
}
|
|
705
|
-
get identifier() {
|
|
706
|
-
return this.pubHash;
|
|
707
|
-
}
|
|
708
|
-
get pubKeyHash() {
|
|
709
|
-
return this.pubHash;
|
|
710
|
-
}
|
|
711
|
-
get privateKey() {
|
|
712
|
-
return this._privateKey || null;
|
|
713
|
-
}
|
|
714
|
-
get publicKey() {
|
|
715
|
-
return this._publicKey || null;
|
|
716
|
-
}
|
|
717
|
-
get privateExtendedKey() {
|
|
718
|
-
const priv = this._privateKey;
|
|
719
|
-
if (!priv) {
|
|
720
|
-
throw new Error("No private key");
|
|
721
|
-
}
|
|
722
|
-
return base58check2.encode(this.serialize(this.versions.private, concatBytes(Uint8Array.of(0), priv)));
|
|
723
|
-
}
|
|
724
|
-
get publicExtendedKey() {
|
|
725
|
-
if (!this._publicKey) {
|
|
726
|
-
throw new Error("No public key");
|
|
727
|
-
}
|
|
728
|
-
return base58check2.encode(this.serialize(this.versions.public, this._publicKey));
|
|
729
|
-
}
|
|
730
|
-
static fromMasterSeed(seed, versions = BITCOIN_VERSIONS) {
|
|
731
|
-
abytes(seed);
|
|
732
|
-
if (8 * seed.length < 128 || 8 * seed.length > 512) {
|
|
733
|
-
throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got " + seed.length);
|
|
734
|
-
}
|
|
735
|
-
const I = hmac(sha512, MASTER_SECRET, seed);
|
|
736
|
-
const privateKey = I.slice(0, 32);
|
|
737
|
-
const chainCode = I.slice(32);
|
|
738
|
-
return new _HDKey({ versions, chainCode, privateKey });
|
|
739
|
-
}
|
|
740
|
-
static fromExtendedKey(base58key, versions = BITCOIN_VERSIONS) {
|
|
741
|
-
const keyBuffer = base58check2.decode(base58key);
|
|
742
|
-
const keyView = createView(keyBuffer);
|
|
743
|
-
const version = keyView.getUint32(0, false);
|
|
744
|
-
const opt = {
|
|
745
|
-
versions,
|
|
746
|
-
depth: keyBuffer[4],
|
|
747
|
-
parentFingerprint: keyView.getUint32(5, false),
|
|
748
|
-
index: keyView.getUint32(9, false),
|
|
749
|
-
chainCode: keyBuffer.slice(13, 45)
|
|
750
|
-
};
|
|
751
|
-
const key = keyBuffer.slice(45);
|
|
752
|
-
const isPriv = key[0] === 0;
|
|
753
|
-
if (version !== versions[isPriv ? "private" : "public"]) {
|
|
754
|
-
throw new Error("Version mismatch");
|
|
755
|
-
}
|
|
756
|
-
if (isPriv) {
|
|
757
|
-
return new _HDKey({ ...opt, privateKey: key.slice(1) });
|
|
758
|
-
} else {
|
|
759
|
-
return new _HDKey({ ...opt, publicKey: key });
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
static fromJSON(json) {
|
|
763
|
-
return _HDKey.fromExtendedKey(json.xpriv);
|
|
764
|
-
}
|
|
765
|
-
versions;
|
|
766
|
-
depth = 0;
|
|
767
|
-
index = 0;
|
|
768
|
-
chainCode = null;
|
|
769
|
-
parentFingerprint = 0;
|
|
770
|
-
_privateKey;
|
|
771
|
-
_publicKey;
|
|
772
|
-
pubHash;
|
|
773
|
-
constructor(opt) {
|
|
774
|
-
if (!opt || typeof opt !== "object") {
|
|
775
|
-
throw new Error("HDKey.constructor must not be called directly");
|
|
776
|
-
}
|
|
777
|
-
this.versions = opt.versions || BITCOIN_VERSIONS;
|
|
778
|
-
this.depth = opt.depth || 0;
|
|
779
|
-
this.chainCode = opt.chainCode || null;
|
|
780
|
-
this.index = opt.index || 0;
|
|
781
|
-
this.parentFingerprint = opt.parentFingerprint || 0;
|
|
782
|
-
if (!this.depth) {
|
|
783
|
-
if (this.parentFingerprint || this.index) {
|
|
784
|
-
throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
if (this.depth > 255) {
|
|
788
|
-
throw new Error("HDKey: depth exceeds the serializable value 255");
|
|
789
|
-
}
|
|
790
|
-
if (opt.publicKey && opt.privateKey) {
|
|
791
|
-
throw new Error("HDKey: publicKey and privateKey at same time.");
|
|
792
|
-
}
|
|
793
|
-
if (opt.privateKey) {
|
|
794
|
-
if (!secp256k1.utils.isValidSecretKey(opt.privateKey))
|
|
795
|
-
throw new Error("Invalid private key");
|
|
796
|
-
this._privateKey = opt.privateKey;
|
|
797
|
-
this._publicKey = secp256k1.getPublicKey(opt.privateKey, true);
|
|
798
|
-
} else if (opt.publicKey) {
|
|
799
|
-
this._publicKey = Point.fromBytes(opt.publicKey).toBytes(true);
|
|
800
|
-
} else {
|
|
801
|
-
throw new Error("HDKey: no public or private key provided");
|
|
802
|
-
}
|
|
803
|
-
this.pubHash = hash160(this._publicKey);
|
|
804
|
-
}
|
|
805
|
-
derive(path) {
|
|
806
|
-
if (!/^[mM]'?/.test(path)) {
|
|
807
|
-
throw new Error('Path must start with "m" or "M"');
|
|
808
|
-
}
|
|
809
|
-
if (/^[mM]'?$/.test(path)) {
|
|
810
|
-
return this;
|
|
811
|
-
}
|
|
812
|
-
const parts = path.replace(/^[mM]'?\//, "").split("/");
|
|
813
|
-
let child = this;
|
|
814
|
-
for (const c of parts) {
|
|
815
|
-
const m = /^(\d+)('?)$/.exec(c);
|
|
816
|
-
const m1 = m && m[1];
|
|
817
|
-
if (!m || m.length !== 3 || typeof m1 !== "string")
|
|
818
|
-
throw new Error("invalid child index: " + c);
|
|
819
|
-
let idx = +m1;
|
|
820
|
-
if (!Number.isSafeInteger(idx) || idx >= HARDENED_OFFSET) {
|
|
821
|
-
throw new Error("Invalid index");
|
|
822
|
-
}
|
|
823
|
-
if (m[2] === "'") {
|
|
824
|
-
idx += HARDENED_OFFSET;
|
|
825
|
-
}
|
|
826
|
-
child = child.deriveChild(idx);
|
|
827
|
-
}
|
|
828
|
-
return child;
|
|
829
|
-
}
|
|
830
|
-
deriveChild(index) {
|
|
831
|
-
if (!this._publicKey || !this.chainCode) {
|
|
832
|
-
throw new Error("No publicKey or chainCode set");
|
|
833
|
-
}
|
|
834
|
-
let data = toU32(index);
|
|
835
|
-
if (index >= HARDENED_OFFSET) {
|
|
836
|
-
const priv = this._privateKey;
|
|
837
|
-
if (!priv) {
|
|
838
|
-
throw new Error("Could not derive hardened child key");
|
|
839
|
-
}
|
|
840
|
-
data = concatBytes(Uint8Array.of(0), priv, data);
|
|
841
|
-
} else {
|
|
842
|
-
data = concatBytes(this._publicKey, data);
|
|
843
|
-
}
|
|
844
|
-
const I = hmac(sha512, this.chainCode, data);
|
|
845
|
-
const childTweak = I.slice(0, 32);
|
|
846
|
-
const chainCode = I.slice(32);
|
|
847
|
-
if (!secp256k1.utils.isValidSecretKey(childTweak)) {
|
|
848
|
-
throw new Error("Tweak bigger than curve order");
|
|
849
|
-
}
|
|
850
|
-
const opt = {
|
|
851
|
-
versions: this.versions,
|
|
852
|
-
chainCode,
|
|
853
|
-
depth: this.depth + 1,
|
|
854
|
-
parentFingerprint: this.fingerprint,
|
|
855
|
-
index
|
|
856
|
-
};
|
|
857
|
-
const ctweak = Fn.fromBytes(childTweak);
|
|
858
|
-
try {
|
|
859
|
-
if (this._privateKey) {
|
|
860
|
-
const added = Fn.create(Fn.fromBytes(this._privateKey) + ctweak);
|
|
861
|
-
if (!Fn.isValidNot0(added)) {
|
|
862
|
-
throw new Error("The tweak was out of range or the resulted private key is invalid");
|
|
863
|
-
}
|
|
864
|
-
opt.privateKey = Fn.toBytes(added);
|
|
865
|
-
} else {
|
|
866
|
-
const added = Point.fromBytes(this._publicKey).add(Point.BASE.multiply(ctweak));
|
|
867
|
-
if (added.equals(Point.ZERO)) {
|
|
868
|
-
throw new Error("The tweak was equal to negative P, which made the result key invalid");
|
|
869
|
-
}
|
|
870
|
-
opt.publicKey = added.toBytes(true);
|
|
871
|
-
}
|
|
872
|
-
return new _HDKey(opt);
|
|
873
|
-
} catch (err) {
|
|
874
|
-
return this.deriveChild(index + 1);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
sign(hash) {
|
|
878
|
-
if (!this._privateKey) {
|
|
879
|
-
throw new Error("No privateKey set!");
|
|
880
|
-
}
|
|
881
|
-
abytes(hash, 32);
|
|
882
|
-
return secp256k1.sign(hash, this._privateKey, { prehash: false });
|
|
883
|
-
}
|
|
884
|
-
verify(hash, signature) {
|
|
885
|
-
abytes(hash, 32);
|
|
886
|
-
abytes(signature, 64);
|
|
887
|
-
if (!this._publicKey) {
|
|
888
|
-
throw new Error("No publicKey set!");
|
|
889
|
-
}
|
|
890
|
-
return secp256k1.verify(signature, hash, this._publicKey, { prehash: false });
|
|
891
|
-
}
|
|
892
|
-
wipePrivateData() {
|
|
893
|
-
if (this._privateKey) {
|
|
894
|
-
this._privateKey.fill(0);
|
|
895
|
-
this._privateKey = void 0;
|
|
896
|
-
}
|
|
897
|
-
return this;
|
|
898
|
-
}
|
|
899
|
-
toJSON() {
|
|
900
|
-
return {
|
|
901
|
-
xpriv: this.privateExtendedKey,
|
|
902
|
-
xpub: this.publicExtendedKey
|
|
903
|
-
};
|
|
904
|
-
}
|
|
905
|
-
serialize(version, key) {
|
|
906
|
-
if (!this.chainCode) {
|
|
907
|
-
throw new Error("No chainCode set");
|
|
908
|
-
}
|
|
909
|
-
abytes(key, 33);
|
|
910
|
-
return concatBytes(toU32(version), new Uint8Array([this.depth]), toU32(this.parentFingerprint), toU32(this.index), this.chainCode, key);
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
339
|
var DERIVATION_PATHS2 = {
|
|
914
|
-
ethereum:
|
|
915
|
-
bitcoin_mainnet:
|
|
340
|
+
ethereum: `${DERIVATION_PATHS.ethereum}/0`,
|
|
341
|
+
bitcoin_mainnet: `${DERIVATION_PATHS.bitcoin}/0`,
|
|
916
342
|
bitcoin_testnet: "m/84'/1'/0'/0/0",
|
|
917
|
-
ton:
|
|
918
|
-
tron:
|
|
919
|
-
solana:
|
|
920
|
-
spark:
|
|
343
|
+
ton: `${DERIVATION_PATHS.ton}/0'/0'`,
|
|
344
|
+
tron: `${DERIVATION_PATHS.tron}/0`,
|
|
345
|
+
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
346
|
+
spark: `${DERIVATION_PATHS.spark}/0`
|
|
921
347
|
};
|
|
922
348
|
function deriveEthereumAddress(seed) {
|
|
923
349
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
@@ -932,7 +358,7 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
932
358
|
if (!child.publicKey) {
|
|
933
359
|
throw new Error("Failed to derive public key");
|
|
934
360
|
}
|
|
935
|
-
const pubKeyHash = ripemd160(sha256
|
|
361
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
936
362
|
const witnessVersion = 0;
|
|
937
363
|
const words = bech32.toWords(pubKeyHash);
|
|
938
364
|
words.unshift(witnessVersion);
|
|
@@ -973,7 +399,7 @@ async function deriveTonAddress(seed) {
|
|
|
973
399
|
const publicKey = keypair.publicKey;
|
|
974
400
|
const workchain = 0;
|
|
975
401
|
const flags = 17;
|
|
976
|
-
const hash = sha256
|
|
402
|
+
const hash = sha256(publicKey);
|
|
977
403
|
const addressData = new Uint8Array(34);
|
|
978
404
|
addressData[0] = flags;
|
|
979
405
|
addressData[1] = workchain;
|
|
@@ -1010,7 +436,7 @@ function deriveTronAddress(seed) {
|
|
|
1010
436
|
for (let i = 0; i < 20; i++) {
|
|
1011
437
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
1012
438
|
}
|
|
1013
|
-
const tronBase58check = base58check(sha256
|
|
439
|
+
const tronBase58check = base58check(sha256);
|
|
1014
440
|
return tronBase58check.encode(addressBytes);
|
|
1015
441
|
} catch (error) {
|
|
1016
442
|
console.error("TRON address derivation failed:", error);
|
|
@@ -1025,7 +451,7 @@ function deriveSparkAddress(seed, network = "mainnet") {
|
|
|
1025
451
|
if (!child.publicKey) {
|
|
1026
452
|
throw new Error("Failed to derive public key");
|
|
1027
453
|
}
|
|
1028
|
-
const pubKeyHash = ripemd160(sha256
|
|
454
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
1029
455
|
const witnessVersion = 0;
|
|
1030
456
|
const words = bech32.toWords(pubKeyHash);
|
|
1031
457
|
words.unshift(witnessVersion);
|
|
@@ -1126,9 +552,9 @@ var CHAIN_ERROR_MESSAGES = {
|
|
|
1126
552
|
"no route": "NETWORK_ERROR"
|
|
1127
553
|
}
|
|
1128
554
|
};
|
|
1129
|
-
function parseChainError(
|
|
555
|
+
function parseChainError(chain, errorMessage) {
|
|
1130
556
|
const errorLower = errorMessage.toLowerCase();
|
|
1131
|
-
const chainErrors = CHAIN_ERROR_MESSAGES[
|
|
557
|
+
const chainErrors = CHAIN_ERROR_MESSAGES[chain];
|
|
1132
558
|
for (const [pattern, code] of Object.entries(chainErrors)) {
|
|
1133
559
|
if (errorLower.includes(pattern)) {
|
|
1134
560
|
return code;
|
|
@@ -1266,38 +692,38 @@ var ZubariWdkService = class {
|
|
|
1266
692
|
* For Ethereum, falls back to local derivation if API fails.
|
|
1267
693
|
* For other chains, WDK API is required - no placeholder fallback.
|
|
1268
694
|
*/
|
|
1269
|
-
async deriveAddress(seed,
|
|
695
|
+
async deriveAddress(seed, chain) {
|
|
1270
696
|
await this.initialize();
|
|
1271
|
-
const path = this.getDerivationPath(
|
|
697
|
+
const path = this.getDerivationPath(chain);
|
|
1272
698
|
try {
|
|
1273
|
-
const response = await this.apiClient.deriveAddress(seed,
|
|
699
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
1274
700
|
if (response.success && response.address) {
|
|
1275
701
|
return {
|
|
1276
|
-
chain
|
|
702
|
+
chain,
|
|
1277
703
|
address: response.address,
|
|
1278
704
|
path: response.path || path
|
|
1279
705
|
};
|
|
1280
706
|
}
|
|
1281
707
|
} catch (error) {
|
|
1282
|
-
console.warn(`API address derivation failed for ${
|
|
1283
|
-
if (
|
|
1284
|
-
return this.deriveBrowserAddress(seed,
|
|
708
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
709
|
+
if (chain === "ethereum") {
|
|
710
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
1285
711
|
}
|
|
1286
712
|
}
|
|
1287
713
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1288
714
|
try {
|
|
1289
715
|
const wdk = this.nativeWdkService;
|
|
1290
716
|
await wdk.initialize(seed);
|
|
1291
|
-
return await wdk.deriveAddress(
|
|
717
|
+
return await wdk.deriveAddress(chain);
|
|
1292
718
|
} catch (error) {
|
|
1293
|
-
console.warn(`Native WDK address derivation failed for ${
|
|
719
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
1294
720
|
}
|
|
1295
721
|
}
|
|
1296
|
-
if (
|
|
1297
|
-
return this.deriveBrowserAddress(seed,
|
|
722
|
+
if (chain === "ethereum") {
|
|
723
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
1298
724
|
}
|
|
1299
725
|
throw new Error(
|
|
1300
|
-
`WDK API required for ${
|
|
726
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
1301
727
|
);
|
|
1302
728
|
}
|
|
1303
729
|
/**
|
|
@@ -1377,13 +803,13 @@ var ZubariWdkService = class {
|
|
|
1377
803
|
/**
|
|
1378
804
|
* Get fee rates for a chain
|
|
1379
805
|
*/
|
|
1380
|
-
async getFeeRates(seed,
|
|
806
|
+
async getFeeRates(seed, chain) {
|
|
1381
807
|
await this.initialize();
|
|
1382
808
|
try {
|
|
1383
809
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
1384
810
|
method: "POST",
|
|
1385
811
|
headers: { "Content-Type": "application/json" },
|
|
1386
|
-
body: JSON.stringify({ seed, chain
|
|
812
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
1387
813
|
});
|
|
1388
814
|
if (response.ok) {
|
|
1389
815
|
const data = await response.json();
|
|
@@ -1392,20 +818,20 @@ var ZubariWdkService = class {
|
|
|
1392
818
|
}
|
|
1393
819
|
}
|
|
1394
820
|
} catch (error) {
|
|
1395
|
-
console.warn(`Failed to fetch fee rates for ${
|
|
821
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
1396
822
|
}
|
|
1397
823
|
return { slow: "0", normal: "0", fast: "0" };
|
|
1398
824
|
}
|
|
1399
825
|
/**
|
|
1400
826
|
* Estimate transaction fee
|
|
1401
827
|
*/
|
|
1402
|
-
async estimateFee(seed,
|
|
828
|
+
async estimateFee(seed, chain, to, amount) {
|
|
1403
829
|
await this.initialize();
|
|
1404
830
|
try {
|
|
1405
831
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1406
832
|
method: "POST",
|
|
1407
833
|
headers: { "Content-Type": "application/json" },
|
|
1408
|
-
body: JSON.stringify({ seed, chain
|
|
834
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1409
835
|
});
|
|
1410
836
|
if (response.ok) {
|
|
1411
837
|
const data = await response.json();
|
|
@@ -1414,9 +840,9 @@ var ZubariWdkService = class {
|
|
|
1414
840
|
}
|
|
1415
841
|
}
|
|
1416
842
|
} catch (error) {
|
|
1417
|
-
console.warn(`Failed to estimate fee for ${
|
|
843
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
1418
844
|
}
|
|
1419
|
-
return { fee: "0", symbol: this.getChainSymbol(
|
|
845
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
1420
846
|
}
|
|
1421
847
|
/**
|
|
1422
848
|
* Send a transaction on any supported chain
|
|
@@ -1427,19 +853,14 @@ var ZubariWdkService = class {
|
|
|
1427
853
|
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
1428
854
|
* @returns Transaction result with hash on success, or error details on failure
|
|
1429
855
|
*/
|
|
1430
|
-
async sendTransaction(seed,
|
|
856
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
1431
857
|
await this.initialize();
|
|
1432
858
|
const startTime = Date.now();
|
|
1433
|
-
console.log(`[ZubariWdkService] Sending ${chain2} transaction`, {
|
|
1434
|
-
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
1435
|
-
amount,
|
|
1436
|
-
network: this.config.network
|
|
1437
|
-
});
|
|
1438
859
|
try {
|
|
1439
860
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1440
861
|
method: "POST",
|
|
1441
862
|
headers: { "Content-Type": "application/json" },
|
|
1442
|
-
body: JSON.stringify({ seed, chain
|
|
863
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1443
864
|
});
|
|
1444
865
|
const elapsed = Date.now() - startTime;
|
|
1445
866
|
if (response.ok) {
|
|
@@ -1449,22 +870,18 @@ var ZubariWdkService = class {
|
|
|
1449
870
|
txHash = txHash.hash;
|
|
1450
871
|
}
|
|
1451
872
|
if (txHash) {
|
|
1452
|
-
const isValid = this.validateTxHash(
|
|
873
|
+
const isValid = this.validateTxHash(chain, txHash);
|
|
1453
874
|
if (!isValid) {
|
|
1454
|
-
console.warn(`[ZubariWdkService] Invalid ${
|
|
875
|
+
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
1455
876
|
}
|
|
1456
877
|
}
|
|
1457
|
-
console.log(`[ZubariWdkService] ${chain2} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
1458
|
-
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
1459
|
-
elapsed: `${elapsed}ms`
|
|
1460
|
-
});
|
|
1461
878
|
if (!data.success) {
|
|
1462
|
-
const errorCode2 = parseChainError(
|
|
879
|
+
const errorCode2 = parseChainError(chain, data.error || "");
|
|
1463
880
|
return {
|
|
1464
881
|
success: false,
|
|
1465
882
|
error: data.error,
|
|
1466
883
|
errorCode: errorCode2,
|
|
1467
|
-
chain
|
|
884
|
+
chain
|
|
1468
885
|
};
|
|
1469
886
|
}
|
|
1470
887
|
return {
|
|
@@ -1473,47 +890,35 @@ var ZubariWdkService = class {
|
|
|
1473
890
|
from: data.from,
|
|
1474
891
|
to: data.to,
|
|
1475
892
|
amount: data.amount,
|
|
1476
|
-
chain: data.chain ||
|
|
893
|
+
chain: data.chain || chain,
|
|
1477
894
|
network: data.network || this.config.network
|
|
1478
895
|
};
|
|
1479
896
|
}
|
|
1480
897
|
const errorData = await response.json().catch(() => ({}));
|
|
1481
898
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
1482
|
-
const errorCode = parseChainError(
|
|
1483
|
-
console.error(`[ZubariWdkService] ${chain2} transaction FAILED`, {
|
|
1484
|
-
status: response.status,
|
|
1485
|
-
error: errorMessage,
|
|
1486
|
-
errorCode,
|
|
1487
|
-
elapsed: `${elapsed}ms`
|
|
1488
|
-
});
|
|
899
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1489
900
|
return {
|
|
1490
901
|
success: false,
|
|
1491
902
|
error: errorMessage,
|
|
1492
903
|
errorCode,
|
|
1493
|
-
chain
|
|
904
|
+
chain
|
|
1494
905
|
};
|
|
1495
906
|
} catch (error) {
|
|
1496
|
-
const elapsed = Date.now() - startTime;
|
|
1497
907
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
1498
|
-
const errorCode = parseChainError(
|
|
1499
|
-
console.error(`[ZubariWdkService] ${chain2} transaction ERROR`, {
|
|
1500
|
-
error: errorMessage,
|
|
1501
|
-
errorCode,
|
|
1502
|
-
elapsed: `${elapsed}ms`
|
|
1503
|
-
});
|
|
908
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1504
909
|
return {
|
|
1505
910
|
success: false,
|
|
1506
911
|
error: errorMessage,
|
|
1507
912
|
errorCode,
|
|
1508
|
-
chain
|
|
913
|
+
chain
|
|
1509
914
|
};
|
|
1510
915
|
}
|
|
1511
916
|
}
|
|
1512
917
|
/**
|
|
1513
918
|
* Validate transaction hash format for a specific chain
|
|
1514
919
|
*/
|
|
1515
|
-
validateTxHash(
|
|
1516
|
-
switch (
|
|
920
|
+
validateTxHash(chain, txHash) {
|
|
921
|
+
switch (chain) {
|
|
1517
922
|
case "ethereum":
|
|
1518
923
|
return /^0x[a-fA-F0-9]{64}$/.test(txHash);
|
|
1519
924
|
case "bitcoin":
|
|
@@ -1545,18 +950,25 @@ var ZubariWdkService = class {
|
|
|
1545
950
|
// ==========================================
|
|
1546
951
|
// Private Helper Methods
|
|
1547
952
|
// ==========================================
|
|
1548
|
-
getDerivationPath(
|
|
1549
|
-
const
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
953
|
+
getDerivationPath(chain) {
|
|
954
|
+
const basePath = DERIVATION_PATHS[chain];
|
|
955
|
+
if (chain === "bitcoin" && this.config.network === "testnet") {
|
|
956
|
+
return "m/84'/1'/0'/0/0";
|
|
957
|
+
}
|
|
958
|
+
switch (chain) {
|
|
959
|
+
case "ton":
|
|
960
|
+
return `${basePath}/0'/0'`;
|
|
961
|
+
case "solana":
|
|
962
|
+
return `${basePath}/0'`;
|
|
963
|
+
case "bitcoin":
|
|
964
|
+
case "ethereum":
|
|
965
|
+
case "tron":
|
|
966
|
+
case "spark":
|
|
967
|
+
default:
|
|
968
|
+
return `${basePath}/0`;
|
|
969
|
+
}
|
|
1558
970
|
}
|
|
1559
|
-
getChainSymbol(
|
|
971
|
+
getChainSymbol(chain) {
|
|
1560
972
|
const symbols = {
|
|
1561
973
|
ethereum: "ETH",
|
|
1562
974
|
bitcoin: "BTC",
|
|
@@ -1565,16 +977,16 @@ var ZubariWdkService = class {
|
|
|
1565
977
|
solana: "SOL",
|
|
1566
978
|
spark: "SAT"
|
|
1567
979
|
};
|
|
1568
|
-
return symbols[
|
|
980
|
+
return symbols[chain];
|
|
1569
981
|
}
|
|
1570
982
|
/**
|
|
1571
983
|
* Derive address using browser-compatible libraries
|
|
1572
984
|
*/
|
|
1573
|
-
async deriveBrowserAddress(seed,
|
|
1574
|
-
const path = this.getDerivationPath(
|
|
985
|
+
async deriveBrowserAddress(seed, chain) {
|
|
986
|
+
const path = this.getDerivationPath(chain);
|
|
1575
987
|
try {
|
|
1576
988
|
let address;
|
|
1577
|
-
switch (
|
|
989
|
+
switch (chain) {
|
|
1578
990
|
case "ethereum":
|
|
1579
991
|
address = deriveEthereumAddress(seed);
|
|
1580
992
|
break;
|
|
@@ -1594,11 +1006,11 @@ var ZubariWdkService = class {
|
|
|
1594
1006
|
address = await deriveTonAddress(seed);
|
|
1595
1007
|
break;
|
|
1596
1008
|
default:
|
|
1597
|
-
throw new Error(`Unsupported chain: ${
|
|
1009
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
1598
1010
|
}
|
|
1599
|
-
return { chain
|
|
1011
|
+
return { chain, address, path };
|
|
1600
1012
|
} catch (error) {
|
|
1601
|
-
console.error(`Browser derivation failed for ${
|
|
1013
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
1602
1014
|
throw error;
|
|
1603
1015
|
}
|
|
1604
1016
|
}
|
|
@@ -1611,7 +1023,7 @@ var ZubariWdkService = class {
|
|
|
1611
1023
|
};
|
|
1612
1024
|
var defaultService = null;
|
|
1613
1025
|
function getZubariWdkService(config) {
|
|
1614
|
-
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1026
|
+
if (!defaultService || config && (config.network !== defaultService.getNetwork() || config.apiUrl && config.apiUrl !== defaultService.getApiUrl())) {
|
|
1615
1027
|
defaultService = new ZubariWdkService(config);
|
|
1616
1028
|
}
|
|
1617
1029
|
return defaultService;
|
|
@@ -1623,7 +1035,10 @@ var KeyManager = class {
|
|
|
1623
1035
|
static KEY_LENGTH = 256;
|
|
1624
1036
|
static IV_LENGTH = 12;
|
|
1625
1037
|
static SALT_LENGTH = 16;
|
|
1626
|
-
|
|
1038
|
+
// OWASP 2023 recommends 600,000 iterations for PBKDF2-SHA256 to resist
|
|
1039
|
+
// brute-force attacks with modern GPU hardware.
|
|
1040
|
+
// See: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
|
|
1041
|
+
static PBKDF2_ITERATIONS = 6e5;
|
|
1627
1042
|
/**
|
|
1628
1043
|
* Encrypt a seed phrase with a password
|
|
1629
1044
|
*/
|
|
@@ -1862,7 +1277,7 @@ var WebEncryptedStorageAdapter = class {
|
|
|
1862
1277
|
{
|
|
1863
1278
|
name: "PBKDF2",
|
|
1864
1279
|
salt: salt.buffer,
|
|
1865
|
-
iterations:
|
|
1280
|
+
iterations: 6e5,
|
|
1866
1281
|
hash: "SHA-256"
|
|
1867
1282
|
},
|
|
1868
1283
|
keyMaterial,
|
|
@@ -2000,8 +1415,8 @@ async function fetchPrices() {
|
|
|
2000
1415
|
if (response.ok) {
|
|
2001
1416
|
const data = await response.json();
|
|
2002
1417
|
const prices = {};
|
|
2003
|
-
for (const [
|
|
2004
|
-
prices[
|
|
1418
|
+
for (const [chain, geckoId] of Object.entries(COINGECKO_IDS)) {
|
|
1419
|
+
prices[chain] = data[geckoId]?.usd || 0;
|
|
2005
1420
|
}
|
|
2006
1421
|
priceCache = { prices, timestamp: Date.now() };
|
|
2007
1422
|
return prices;
|
|
@@ -2011,9 +1426,22 @@ async function fetchPrices() {
|
|
|
2011
1426
|
}
|
|
2012
1427
|
return priceCache?.prices || {};
|
|
2013
1428
|
}
|
|
2014
|
-
async function getPriceForChain(
|
|
1429
|
+
async function getPriceForChain(chain) {
|
|
2015
1430
|
const prices = await fetchPrices();
|
|
2016
|
-
return prices[
|
|
1431
|
+
return prices[chain] || 0;
|
|
1432
|
+
}
|
|
1433
|
+
function tonFriendlyToRaw(addr) {
|
|
1434
|
+
if (addr.includes(":")) return addr;
|
|
1435
|
+
try {
|
|
1436
|
+
const b64 = addr.replace(/-/g, "+").replace(/_/g, "/");
|
|
1437
|
+
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
1438
|
+
if (bytes.length !== 36) return addr;
|
|
1439
|
+
const workchain = bytes[1] === 255 ? -1 : bytes[1];
|
|
1440
|
+
const hash = Array.from(bytes.slice(2, 34)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1441
|
+
return `${workchain}:${hash}`;
|
|
1442
|
+
} catch {
|
|
1443
|
+
return addr;
|
|
1444
|
+
}
|
|
2017
1445
|
}
|
|
2018
1446
|
var STORAGE_KEYS = {
|
|
2019
1447
|
ENCRYPTED_SEED: "encrypted_seed",
|
|
@@ -2162,6 +1590,16 @@ var WalletManager = class _WalletManager {
|
|
|
2162
1590
|
}
|
|
2163
1591
|
/**
|
|
2164
1592
|
* Lock wallet (clear seed from memory)
|
|
1593
|
+
*
|
|
1594
|
+
* SECURITY NOTE: JavaScript strings are immutable and cannot be overwritten
|
|
1595
|
+
* in place. Setting `this.currentSeed = null` removes the reference, but
|
|
1596
|
+
* the original string may persist in memory until garbage collected.
|
|
1597
|
+
* There is no reliable way to zero out a JS string.
|
|
1598
|
+
*
|
|
1599
|
+
* TODO: In a future version, store the seed as a Uint8Array instead of a
|
|
1600
|
+
* string. Uint8Array contents can be explicitly zeroed (e.g.,
|
|
1601
|
+
* `seedBytes.fill(0)`) before releasing the reference, which provides
|
|
1602
|
+
* stronger guarantees that sensitive material is scrubbed from memory.
|
|
2165
1603
|
*/
|
|
2166
1604
|
lock() {
|
|
2167
1605
|
this.currentSeed = null;
|
|
@@ -2219,9 +1657,9 @@ var WalletManager = class _WalletManager {
|
|
|
2219
1657
|
if (!this.derivedAddress) {
|
|
2220
1658
|
throw new Error("Wallet not initialized");
|
|
2221
1659
|
}
|
|
2222
|
-
const
|
|
1660
|
+
const chain = this.config.network === "mainnet" ? mainnet : sepolia;
|
|
2223
1661
|
const client = createPublicClient({
|
|
2224
|
-
chain
|
|
1662
|
+
chain,
|
|
2225
1663
|
transport: http(this.config.rpcUrl, {
|
|
2226
1664
|
timeout: 15e3,
|
|
2227
1665
|
// 15 second timeout
|
|
@@ -2243,9 +1681,9 @@ var WalletManager = class _WalletManager {
|
|
|
2243
1681
|
* Create viem public client for the current network
|
|
2244
1682
|
*/
|
|
2245
1683
|
getPublicClient() {
|
|
2246
|
-
const
|
|
1684
|
+
const chain = this.config.network === "mainnet" ? mainnet : sepolia;
|
|
2247
1685
|
return createPublicClient({
|
|
2248
|
-
chain
|
|
1686
|
+
chain,
|
|
2249
1687
|
transport: http(this.config.rpcUrl, {
|
|
2250
1688
|
timeout: 15e3,
|
|
2251
1689
|
// 15 second timeout
|
|
@@ -2299,11 +1737,11 @@ var WalletManager = class _WalletManager {
|
|
|
2299
1737
|
*
|
|
2300
1738
|
* No fallback to placeholder addresses - WDK API is required for real addresses.
|
|
2301
1739
|
*/
|
|
2302
|
-
static async deriveAddressForChainAsync(seed,
|
|
2303
|
-
if (
|
|
1740
|
+
static async deriveAddressForChainAsync(seed, chain, network = "mainnet", apiUrl) {
|
|
1741
|
+
if (chain === "ethereum") {
|
|
2304
1742
|
try {
|
|
2305
1743
|
const wdkService2 = getZubariWdkService({ network, apiUrl });
|
|
2306
|
-
const result2 = await wdkService2.deriveAddress(seed,
|
|
1744
|
+
const result2 = await wdkService2.deriveAddress(seed, chain);
|
|
2307
1745
|
return result2.address;
|
|
2308
1746
|
} catch (error) {
|
|
2309
1747
|
console.warn("WDK service failed for Ethereum, using local derivation:", error);
|
|
@@ -2311,7 +1749,7 @@ var WalletManager = class _WalletManager {
|
|
|
2311
1749
|
}
|
|
2312
1750
|
}
|
|
2313
1751
|
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
2314
|
-
const result = await wdkService.deriveAddress(seed,
|
|
1752
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
2315
1753
|
return result.address;
|
|
2316
1754
|
}
|
|
2317
1755
|
/**
|
|
@@ -2320,14 +1758,14 @@ var WalletManager = class _WalletManager {
|
|
|
2320
1758
|
*
|
|
2321
1759
|
* @throws Error for non-Ethereum chains - use WDK API instead
|
|
2322
1760
|
*/
|
|
2323
|
-
static deriveAddressForChain(seed,
|
|
2324
|
-
if (
|
|
1761
|
+
static deriveAddressForChain(seed, chain) {
|
|
1762
|
+
if (chain === "ethereum") {
|
|
2325
1763
|
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
2326
1764
|
const ethNode = HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
2327
1765
|
return ethNode.address;
|
|
2328
1766
|
}
|
|
2329
1767
|
throw new Error(
|
|
2330
|
-
`Sync derivation not supported for ${
|
|
1768
|
+
`Sync derivation not supported for ${chain}. Use deriveAddressForChainAsync() with WDK API.`
|
|
2331
1769
|
);
|
|
2332
1770
|
}
|
|
2333
1771
|
/**
|
|
@@ -2359,9 +1797,9 @@ var WalletManager = class _WalletManager {
|
|
|
2359
1797
|
const wdkAddresses = await this.wdkService.deriveAllAddresses(this.currentSeed);
|
|
2360
1798
|
const enabledChainsSet = new Set(this.config.enabledChains);
|
|
2361
1799
|
const addresses = {};
|
|
2362
|
-
for (const [
|
|
2363
|
-
if (enabledChainsSet.has(
|
|
2364
|
-
addresses[
|
|
1800
|
+
for (const [chain, address] of Object.entries(wdkAddresses)) {
|
|
1801
|
+
if (enabledChainsSet.has(chain) && address) {
|
|
1802
|
+
addresses[chain] = address;
|
|
2365
1803
|
}
|
|
2366
1804
|
}
|
|
2367
1805
|
this.derivedAddresses = addresses;
|
|
@@ -2378,7 +1816,6 @@ var WalletManager = class _WalletManager {
|
|
|
2378
1816
|
async saveAddressesToStorage(addresses) {
|
|
2379
1817
|
try {
|
|
2380
1818
|
await this.storage.setItem(STORAGE_KEYS.DERIVED_ADDRESSES, JSON.stringify(addresses));
|
|
2381
|
-
console.log("Saved derived addresses to storage:", Object.keys(addresses));
|
|
2382
1819
|
} catch (error) {
|
|
2383
1820
|
console.warn("Failed to save addresses to storage:", error);
|
|
2384
1821
|
}
|
|
@@ -2402,10 +1839,10 @@ var WalletManager = class _WalletManager {
|
|
|
2402
1839
|
*/
|
|
2403
1840
|
normalizeAddresses(addresses) {
|
|
2404
1841
|
const normalized = {};
|
|
2405
|
-
for (const [
|
|
1842
|
+
for (const [chain, value] of Object.entries(addresses)) {
|
|
2406
1843
|
const addr = this.normalizeAddress(value);
|
|
2407
1844
|
if (addr) {
|
|
2408
|
-
normalized[
|
|
1845
|
+
normalized[chain] = addr;
|
|
2409
1846
|
}
|
|
2410
1847
|
}
|
|
2411
1848
|
return normalized;
|
|
@@ -2418,9 +1855,7 @@ var WalletManager = class _WalletManager {
|
|
|
2418
1855
|
const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
|
|
2419
1856
|
if (stored) {
|
|
2420
1857
|
const rawAddresses = JSON.parse(stored);
|
|
2421
|
-
console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
|
|
2422
1858
|
const addresses = this.normalizeAddresses(rawAddresses);
|
|
2423
|
-
console.log("[WalletManager] Normalized addresses:", addresses);
|
|
2424
1859
|
await this.saveAddressesToStorage(addresses);
|
|
2425
1860
|
return addresses;
|
|
2426
1861
|
}
|
|
@@ -2445,11 +1880,8 @@ var WalletManager = class _WalletManager {
|
|
|
2445
1880
|
if (storedAddresses && Object.keys(storedAddresses).length > 1) {
|
|
2446
1881
|
const expectedEthAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
2447
1882
|
if (storedAddresses.ethereum === expectedEthAddress) {
|
|
2448
|
-
console.log("Using addresses from storage (verified by Ethereum address)");
|
|
2449
1883
|
this.derivedAddresses = storedAddresses;
|
|
2450
1884
|
return storedAddresses;
|
|
2451
|
-
} else {
|
|
2452
|
-
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
2453
1885
|
}
|
|
2454
1886
|
}
|
|
2455
1887
|
return await this.deriveAllAddressesWithWdk();
|
|
@@ -2458,20 +1890,18 @@ var WalletManager = class _WalletManager {
|
|
|
2458
1890
|
* Get address for a specific chain
|
|
2459
1891
|
* Returns cached address or null - use deriveAllAddressesAsync to derive addresses
|
|
2460
1892
|
*/
|
|
2461
|
-
getAddressForChain(
|
|
2462
|
-
const cachedValue = this.derivedAddresses[
|
|
1893
|
+
getAddressForChain(chain) {
|
|
1894
|
+
const cachedValue = this.derivedAddresses[chain];
|
|
2463
1895
|
if (cachedValue) {
|
|
2464
|
-
console.log(`[WalletManager] getAddressForChain(${chain2}) cached value:`, cachedValue, "type:", typeof cachedValue);
|
|
2465
1896
|
const addr = this.normalizeAddress(cachedValue);
|
|
2466
|
-
console.log(`[WalletManager] getAddressForChain(${chain2}) normalized:`, addr);
|
|
2467
1897
|
if (addr) {
|
|
2468
|
-
this.derivedAddresses[
|
|
1898
|
+
this.derivedAddresses[chain] = addr;
|
|
2469
1899
|
return addr;
|
|
2470
1900
|
}
|
|
2471
1901
|
}
|
|
2472
|
-
if (
|
|
2473
|
-
this.derivedAddresses[
|
|
2474
|
-
return this.derivedAddresses[
|
|
1902
|
+
if (chain === "ethereum" && this.currentSeed) {
|
|
1903
|
+
this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
|
|
1904
|
+
return this.derivedAddresses[chain];
|
|
2475
1905
|
}
|
|
2476
1906
|
return null;
|
|
2477
1907
|
}
|
|
@@ -2484,11 +1914,11 @@ var WalletManager = class _WalletManager {
|
|
|
2484
1914
|
/**
|
|
2485
1915
|
* Set the selected chain
|
|
2486
1916
|
*/
|
|
2487
|
-
setSelectedChain(
|
|
2488
|
-
if (!this.config.enabledChains.includes(
|
|
2489
|
-
throw new Error(`Chain ${
|
|
1917
|
+
setSelectedChain(chain) {
|
|
1918
|
+
if (!this.config.enabledChains.includes(chain)) {
|
|
1919
|
+
throw new Error(`Chain ${chain} is not enabled`);
|
|
2490
1920
|
}
|
|
2491
|
-
this.selectedChain =
|
|
1921
|
+
this.selectedChain = chain;
|
|
2492
1922
|
}
|
|
2493
1923
|
/**
|
|
2494
1924
|
* Get the currently selected chain
|
|
@@ -2505,22 +1935,22 @@ var WalletManager = class _WalletManager {
|
|
|
2505
1935
|
/**
|
|
2506
1936
|
* Get chain configuration
|
|
2507
1937
|
*/
|
|
2508
|
-
getChainConfig(
|
|
2509
|
-
return getNetworkConfig(
|
|
1938
|
+
getChainConfig(chain) {
|
|
1939
|
+
return getNetworkConfig(chain, this.config.network === "testnet");
|
|
2510
1940
|
}
|
|
2511
1941
|
/**
|
|
2512
1942
|
* Fetch balance for a specific chain
|
|
2513
1943
|
* Note: Currently only Ethereum is implemented
|
|
2514
1944
|
*/
|
|
2515
|
-
async fetchBalanceForChain(
|
|
2516
|
-
const address = this.getAddressForChain(
|
|
1945
|
+
async fetchBalanceForChain(chain) {
|
|
1946
|
+
const address = this.getAddressForChain(chain);
|
|
2517
1947
|
if (!address) {
|
|
2518
|
-
throw new Error(`No address for chain ${
|
|
1948
|
+
throw new Error(`No address for chain ${chain}`);
|
|
2519
1949
|
}
|
|
2520
|
-
const networkConfig = this.getChainConfig(
|
|
1950
|
+
const networkConfig = this.getChainConfig(chain);
|
|
2521
1951
|
let balance = "0";
|
|
2522
1952
|
const tokenBalances = {};
|
|
2523
|
-
if (
|
|
1953
|
+
if (chain === "ethereum") {
|
|
2524
1954
|
const viemChain = this.config.network === "mainnet" ? mainnet : sepolia;
|
|
2525
1955
|
const isTestnet = this.config.network !== "mainnet";
|
|
2526
1956
|
const client = createPublicClient({
|
|
@@ -2567,7 +1997,7 @@ var WalletManager = class _WalletManager {
|
|
|
2567
1997
|
} else if (usdtResult.status === "rejected") {
|
|
2568
1998
|
console.warn("[WalletManager] Failed to fetch ETH USDT balance:", usdtResult.reason);
|
|
2569
1999
|
}
|
|
2570
|
-
} else if (
|
|
2000
|
+
} else if (chain === "bitcoin") {
|
|
2571
2001
|
const isMainnet = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");
|
|
2572
2002
|
const apisToTry = isMainnet ? ["https://mempool.space/api"] : [
|
|
2573
2003
|
"https://mempool.space/testnet/api",
|
|
@@ -2590,16 +2020,14 @@ var WalletManager = class _WalletManager {
|
|
|
2590
2020
|
const mempoolSpent = data.mempool_stats?.spent_txo_sum || 0;
|
|
2591
2021
|
const satoshis = chainFunded - chainSpent + (mempoolFunded - mempoolSpent);
|
|
2592
2022
|
balance = (satoshis / 1e8).toFixed(8);
|
|
2593
|
-
console.log(`Bitcoin balance for ${address}: ${balance} BTC (${satoshis} sats) via ${apiUrl}`);
|
|
2594
2023
|
break;
|
|
2595
2024
|
}
|
|
2596
|
-
console.log(`No transactions found on ${apiUrl}, trying next...`);
|
|
2597
2025
|
}
|
|
2598
2026
|
} catch (error) {
|
|
2599
2027
|
console.warn(`Failed to fetch from ${apiUrl}:`, error);
|
|
2600
2028
|
}
|
|
2601
2029
|
}
|
|
2602
|
-
} else if (
|
|
2030
|
+
} else if (chain === "solana") {
|
|
2603
2031
|
const rpcUrl = this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com";
|
|
2604
2032
|
try {
|
|
2605
2033
|
const response = await fetch(rpcUrl, {
|
|
@@ -2619,7 +2047,7 @@ var WalletManager = class _WalletManager {
|
|
|
2619
2047
|
}
|
|
2620
2048
|
}
|
|
2621
2049
|
} catch (error) {
|
|
2622
|
-
console.warn(`Failed to fetch ${
|
|
2050
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2623
2051
|
}
|
|
2624
2052
|
const isTestnet = this.config.network !== "mainnet";
|
|
2625
2053
|
const usdtMint = USDT_ADDRESSES.solana?.[isTestnet ? "testnet" : "mainnet"];
|
|
@@ -2653,7 +2081,7 @@ var WalletManager = class _WalletManager {
|
|
|
2653
2081
|
console.warn("Failed to fetch Solana USDT balance:", error);
|
|
2654
2082
|
}
|
|
2655
2083
|
}
|
|
2656
|
-
} else if (
|
|
2084
|
+
} else if (chain === "tron") {
|
|
2657
2085
|
const tronConfig = getNetworkConfig("tron", this.config.network !== "mainnet");
|
|
2658
2086
|
const baseUrl = tronConfig.rpcUrl;
|
|
2659
2087
|
try {
|
|
@@ -2682,9 +2110,9 @@ var WalletManager = class _WalletManager {
|
|
|
2682
2110
|
}
|
|
2683
2111
|
}
|
|
2684
2112
|
} catch (error) {
|
|
2685
|
-
console.warn(`Failed to fetch ${
|
|
2113
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2686
2114
|
}
|
|
2687
|
-
} else if (
|
|
2115
|
+
} else if (chain === "ton") {
|
|
2688
2116
|
const isTestnet = this.config.network !== "mainnet";
|
|
2689
2117
|
const baseUrl = isTestnet ? "https://testnet.toncenter.com/api/v2" : "https://toncenter.com/api/v2";
|
|
2690
2118
|
try {
|
|
@@ -2696,29 +2124,39 @@ var WalletManager = class _WalletManager {
|
|
|
2696
2124
|
if (data.ok && data.result !== void 0) {
|
|
2697
2125
|
const nanotons = BigInt(data.result);
|
|
2698
2126
|
balance = (Number(nanotons) / 1e9).toFixed(9);
|
|
2699
|
-
console.log(`TON balance for ${address}: ${balance} TON`);
|
|
2700
2127
|
}
|
|
2701
2128
|
}
|
|
2702
2129
|
} catch (error) {
|
|
2703
|
-
console.warn(`Failed to fetch ${
|
|
2130
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2704
2131
|
}
|
|
2705
2132
|
const usdtJetton = USDT_ADDRESSES.ton?.[isTestnet ? "testnet" : "mainnet"];
|
|
2706
2133
|
if (usdtJetton) {
|
|
2707
|
-
const
|
|
2134
|
+
const tonapiBaseUrl = isTestnet ? "https://testnet.tonapi.io/v2" : "https://tonapi.io/v2";
|
|
2708
2135
|
try {
|
|
2136
|
+
const rawAddr = tonFriendlyToRaw(address);
|
|
2709
2137
|
const jettonResponse = await fetch(
|
|
2710
|
-
`${
|
|
2138
|
+
`${tonapiBaseUrl}/accounts/${encodeURIComponent(rawAddr)}/jettons?currencies=usd`,
|
|
2711
2139
|
{ headers: { "Accept": "application/json" } }
|
|
2712
2140
|
);
|
|
2713
2141
|
if (jettonResponse.ok) {
|
|
2714
2142
|
const jettonData = await jettonResponse.json();
|
|
2715
|
-
const
|
|
2716
|
-
if (
|
|
2717
|
-
const
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2143
|
+
const balances = jettonData.balances;
|
|
2144
|
+
if (balances && balances.length > 0) {
|
|
2145
|
+
for (const jb of balances) {
|
|
2146
|
+
const jettonAddr = jb.jetton?.address;
|
|
2147
|
+
if (jettonAddr) {
|
|
2148
|
+
const usdtRaw = tonFriendlyToRaw(usdtJetton);
|
|
2149
|
+
if (jettonAddr.toLowerCase() === usdtRaw.toLowerCase()) {
|
|
2150
|
+
const rawBalance = jb.balance;
|
|
2151
|
+
if (rawBalance) {
|
|
2152
|
+
const decimals = jb.jetton?.decimals || 6;
|
|
2153
|
+
const usdtAmount = Number(BigInt(rawBalance)) / Math.pow(10, decimals);
|
|
2154
|
+
if (usdtAmount > 0) {
|
|
2155
|
+
tokenBalances.USDT = { balance: usdtAmount.toFixed(6), balanceUsd: usdtAmount };
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2722
2160
|
}
|
|
2723
2161
|
}
|
|
2724
2162
|
}
|
|
@@ -2727,7 +2165,7 @@ var WalletManager = class _WalletManager {
|
|
|
2727
2165
|
console.warn("Failed to fetch TON USDT jetton balance:", error);
|
|
2728
2166
|
}
|
|
2729
2167
|
}
|
|
2730
|
-
} else if (
|
|
2168
|
+
} else if (chain === "spark") {
|
|
2731
2169
|
try {
|
|
2732
2170
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balance`, {
|
|
2733
2171
|
method: "POST",
|
|
@@ -2742,18 +2180,17 @@ var WalletManager = class _WalletManager {
|
|
|
2742
2180
|
const data = await response.json();
|
|
2743
2181
|
if (data.success && data.balance !== void 0) {
|
|
2744
2182
|
balance = (parseFloat(data.balance) / 1e8).toFixed(8);
|
|
2745
|
-
console.log(`Spark balance for ${address}: ${balance} BTC`);
|
|
2746
2183
|
}
|
|
2747
2184
|
}
|
|
2748
2185
|
} catch (error) {
|
|
2749
|
-
console.warn(`Failed to fetch ${
|
|
2186
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2750
2187
|
}
|
|
2751
2188
|
}
|
|
2752
|
-
const priceUsd = await getPriceForChain(
|
|
2189
|
+
const priceUsd = await getPriceForChain(chain);
|
|
2753
2190
|
const balanceNum = parseFloat(balance) || 0;
|
|
2754
2191
|
const balanceUsd = balanceNum * priceUsd;
|
|
2755
2192
|
return {
|
|
2756
|
-
chain
|
|
2193
|
+
chain,
|
|
2757
2194
|
symbol: networkConfig.nativeCurrency.symbol,
|
|
2758
2195
|
balance,
|
|
2759
2196
|
balanceUsd,
|
|
@@ -2763,28 +2200,29 @@ var WalletManager = class _WalletManager {
|
|
|
2763
2200
|
};
|
|
2764
2201
|
}
|
|
2765
2202
|
/**
|
|
2766
|
-
* Fetch balances for all enabled chains
|
|
2203
|
+
* Fetch balances for all enabled chains in parallel.
|
|
2204
|
+
* Uses Promise.allSettled so that one chain failing does not block others.
|
|
2767
2205
|
*/
|
|
2768
2206
|
async fetchAllBalances() {
|
|
2769
|
-
const
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
const networkConfig = this.getChainConfig(chain2);
|
|
2777
|
-
balances.push({
|
|
2778
|
-
chain: chain2,
|
|
2779
|
-
symbol: networkConfig.nativeCurrency.symbol,
|
|
2780
|
-
balance: "0",
|
|
2781
|
-
balanceUsd: 0,
|
|
2782
|
-
address: this.getAddressForChain(chain2) || "",
|
|
2783
|
-
decimals: networkConfig.nativeCurrency.decimals
|
|
2784
|
-
});
|
|
2207
|
+
const results = await Promise.allSettled(
|
|
2208
|
+
this.config.enabledChains.map((chain) => this.fetchBalanceForChain(chain))
|
|
2209
|
+
);
|
|
2210
|
+
return results.map((result, index) => {
|
|
2211
|
+
const chain = this.config.enabledChains[index];
|
|
2212
|
+
if (result.status === "fulfilled") {
|
|
2213
|
+
return result.value;
|
|
2785
2214
|
}
|
|
2786
|
-
|
|
2787
|
-
|
|
2215
|
+
console.error(`Failed to fetch balance for ${chain}:`, result.reason);
|
|
2216
|
+
const networkConfig = this.getChainConfig(chain);
|
|
2217
|
+
return {
|
|
2218
|
+
chain,
|
|
2219
|
+
symbol: networkConfig.nativeCurrency.symbol,
|
|
2220
|
+
balance: "0",
|
|
2221
|
+
balanceUsd: 0,
|
|
2222
|
+
address: this.getAddressForChain(chain) || "",
|
|
2223
|
+
decimals: networkConfig.nativeCurrency.decimals
|
|
2224
|
+
};
|
|
2225
|
+
});
|
|
2788
2226
|
}
|
|
2789
2227
|
/**
|
|
2790
2228
|
* Get extended wallet state with multi-chain info
|
|
@@ -2809,13 +2247,13 @@ var WalletManager = class _WalletManager {
|
|
|
2809
2247
|
* @param token - Optional token symbol (e.g., 'USDT' for stablecoins)
|
|
2810
2248
|
* @returns Transaction result with hash and status
|
|
2811
2249
|
*/
|
|
2812
|
-
async sendTransaction(
|
|
2250
|
+
async sendTransaction(chain, to, amount, token) {
|
|
2813
2251
|
if (!this.currentSeed) {
|
|
2814
2252
|
return { success: false, error: "Wallet is locked" };
|
|
2815
2253
|
}
|
|
2816
|
-
const fromAddress = this.getAddressForChain(
|
|
2254
|
+
const fromAddress = this.getAddressForChain(chain);
|
|
2817
2255
|
if (!fromAddress) {
|
|
2818
|
-
return { success: false, error: `No address for chain ${
|
|
2256
|
+
return { success: false, error: `No address for chain ${chain}` };
|
|
2819
2257
|
}
|
|
2820
2258
|
try {
|
|
2821
2259
|
const headers = {
|
|
@@ -2829,7 +2267,7 @@ var WalletManager = class _WalletManager {
|
|
|
2829
2267
|
headers,
|
|
2830
2268
|
body: JSON.stringify({
|
|
2831
2269
|
seed: this.currentSeed,
|
|
2832
|
-
chain
|
|
2270
|
+
chain,
|
|
2833
2271
|
to,
|
|
2834
2272
|
amount,
|
|
2835
2273
|
token,
|
|
@@ -2838,12 +2276,11 @@ var WalletManager = class _WalletManager {
|
|
|
2838
2276
|
});
|
|
2839
2277
|
if (response.ok) {
|
|
2840
2278
|
const data = await response.json();
|
|
2841
|
-
console.log(`Transaction sent on ${chain2}:`, data);
|
|
2842
2279
|
let txHash = data.txHash || data.transactionHash || data.hash;
|
|
2843
2280
|
if (txHash && typeof txHash === "object" && "hash" in txHash) {
|
|
2844
2281
|
txHash = txHash.hash;
|
|
2845
2282
|
}
|
|
2846
|
-
if (
|
|
2283
|
+
if (chain === "ethereum" && txHash && (typeof txHash !== "string" || !txHash.startsWith("0x") || txHash.length !== 66)) {
|
|
2847
2284
|
console.warn(`Invalid Ethereum tx hash format: ${txHash} (length: ${txHash?.length}, expected: 66)`);
|
|
2848
2285
|
}
|
|
2849
2286
|
return {
|
|
@@ -2852,7 +2289,7 @@ var WalletManager = class _WalletManager {
|
|
|
2852
2289
|
from: fromAddress,
|
|
2853
2290
|
to,
|
|
2854
2291
|
amount,
|
|
2855
|
-
chain
|
|
2292
|
+
chain
|
|
2856
2293
|
};
|
|
2857
2294
|
}
|
|
2858
2295
|
const errorData = await response.json().catch(() => ({}));
|
|
@@ -2861,7 +2298,7 @@ var WalletManager = class _WalletManager {
|
|
|
2861
2298
|
error: errorData.error || `HTTP ${response.status}`
|
|
2862
2299
|
};
|
|
2863
2300
|
} catch (error) {
|
|
2864
|
-
console.error(`Transaction failed on ${
|
|
2301
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
2865
2302
|
return {
|
|
2866
2303
|
success: false,
|
|
2867
2304
|
error: error instanceof Error ? error.message : "Transaction failed"
|
|
@@ -2871,7 +2308,7 @@ var WalletManager = class _WalletManager {
|
|
|
2871
2308
|
/**
|
|
2872
2309
|
* Estimate transaction fee using Tether WDK
|
|
2873
2310
|
*/
|
|
2874
|
-
async estimateFee(
|
|
2311
|
+
async estimateFee(chain, to, amount, token) {
|
|
2875
2312
|
try {
|
|
2876
2313
|
const headers = {
|
|
2877
2314
|
"Content-Type": "application/json"
|
|
@@ -2883,7 +2320,7 @@ var WalletManager = class _WalletManager {
|
|
|
2883
2320
|
method: "POST",
|
|
2884
2321
|
headers,
|
|
2885
2322
|
body: JSON.stringify({
|
|
2886
|
-
chain
|
|
2323
|
+
chain,
|
|
2887
2324
|
to,
|
|
2888
2325
|
amount,
|
|
2889
2326
|
token,
|
|
@@ -3092,12 +2529,12 @@ function useWalletManager(options = {}) {
|
|
|
3092
2529
|
setIsLoading(false);
|
|
3093
2530
|
}
|
|
3094
2531
|
}, [manager]);
|
|
3095
|
-
const setSelectedChain = useCallback((
|
|
3096
|
-
manager.setSelectedChain(
|
|
3097
|
-
setSelectedChainState(
|
|
2532
|
+
const setSelectedChain = useCallback((chain) => {
|
|
2533
|
+
manager.setSelectedChain(chain);
|
|
2534
|
+
setSelectedChainState(chain);
|
|
3098
2535
|
}, [manager]);
|
|
3099
2536
|
const getAddressForChain = useCallback(
|
|
3100
|
-
(
|
|
2537
|
+
(chain) => manager.getAddressForChain(chain),
|
|
3101
2538
|
[manager]
|
|
3102
2539
|
);
|
|
3103
2540
|
const getAllAddresses = useCallback(
|
|
@@ -3107,10 +2544,10 @@ function useWalletManager(options = {}) {
|
|
|
3107
2544
|
const hasWallet = useCallback(() => manager.hasWallet(), [manager]);
|
|
3108
2545
|
const getSeed = useCallback(() => manager.getSeed(), [manager]);
|
|
3109
2546
|
const sendTransaction = useCallback(
|
|
3110
|
-
async (
|
|
2547
|
+
async (chain, to, amount, token) => {
|
|
3111
2548
|
setIsLoading(true);
|
|
3112
2549
|
try {
|
|
3113
|
-
const result = await manager.sendTransaction(
|
|
2550
|
+
const result = await manager.sendTransaction(chain, to, amount, token);
|
|
3114
2551
|
if (result.success) {
|
|
3115
2552
|
try {
|
|
3116
2553
|
const balances = await manager.fetchAllBalances();
|
|
@@ -3127,8 +2564,8 @@ function useWalletManager(options = {}) {
|
|
|
3127
2564
|
[manager]
|
|
3128
2565
|
);
|
|
3129
2566
|
const estimateFee = useCallback(
|
|
3130
|
-
async (
|
|
3131
|
-
return manager.estimateFee(
|
|
2567
|
+
async (chain, to, amount, token) => {
|
|
2568
|
+
return manager.estimateFee(chain, to, amount, token);
|
|
3132
2569
|
},
|
|
3133
2570
|
[manager]
|
|
3134
2571
|
);
|
|
@@ -3162,14 +2599,6 @@ function useWalletManager(options = {}) {
|
|
|
3162
2599
|
manager
|
|
3163
2600
|
};
|
|
3164
2601
|
}
|
|
3165
|
-
/*! Bundled license information:
|
|
3166
|
-
|
|
3167
|
-
@scure/base/index.js:
|
|
3168
|
-
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
3169
|
-
|
|
3170
|
-
@scure/bip32/index.js:
|
|
3171
|
-
(*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
3172
|
-
*/
|
|
3173
2602
|
|
|
3174
2603
|
export { SUPPORTED_CHAINS, useWalletManager };
|
|
3175
2604
|
//# sourceMappingURL=index.mjs.map
|