@zubari/sdk 0.5.2 → 0.5.3
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/index.js +227 -797
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -795
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.js +175 -745
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +173 -743
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.js +113 -707
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +111 -705
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.js +176 -746
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +174 -744
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
var ethers = require('ethers');
|
|
4
4
|
var bip39 = require('@scure/bip39');
|
|
5
5
|
var english = require('@scure/bip39/wordlists/english');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var legacy_js = require('@noble/hashes/legacy.js');
|
|
9
|
-
var sha2_js = require('@noble/hashes/sha2.js');
|
|
10
|
-
var utils_js = require('@noble/hashes/utils.js');
|
|
6
|
+
var bip32 = require('@scure/bip32');
|
|
7
|
+
var base = require('@scure/base');
|
|
11
8
|
var sha256 = require('@noble/hashes/sha256');
|
|
12
9
|
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
13
10
|
var viem = require('viem');
|
|
@@ -140,8 +137,8 @@ var TESTNET_NETWORKS = {
|
|
|
140
137
|
var USDT_ADDRESSES = {
|
|
141
138
|
ethereum: {
|
|
142
139
|
mainnet: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
143
|
-
testnet: "
|
|
144
|
-
// Sepolia
|
|
140
|
+
testnet: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
|
|
141
|
+
// Sepolia (Test Tether USD)
|
|
145
142
|
},
|
|
146
143
|
tron: {
|
|
147
144
|
mainnet: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -398,8 +395,8 @@ var TESTNET_FEE_WALLETS = {
|
|
|
398
395
|
network: "tron-nile"
|
|
399
396
|
}
|
|
400
397
|
};
|
|
401
|
-
function getFeeWallet(
|
|
402
|
-
return isMainnet2 ? MAINNET_FEE_WALLETS[
|
|
398
|
+
function getFeeWallet(chain, isMainnet2 = true) {
|
|
399
|
+
return isMainnet2 ? MAINNET_FEE_WALLETS[chain] : TESTNET_FEE_WALLETS[chain];
|
|
403
400
|
}
|
|
404
401
|
function getAllFeeWallets(useMainnet = false) {
|
|
405
402
|
return useMainnet ? MAINNET_FEE_WALLETS : TESTNET_FEE_WALLETS;
|
|
@@ -416,8 +413,8 @@ function getDefaultSubscriptionAddress() {
|
|
|
416
413
|
function getCurrentFeeWallets() {
|
|
417
414
|
return isMainnet() ? MAINNET_FEE_WALLETS : TESTNET_FEE_WALLETS;
|
|
418
415
|
}
|
|
419
|
-
function getCurrentFeeWallet(
|
|
420
|
-
return getCurrentFeeWallets()[
|
|
416
|
+
function getCurrentFeeWallet(chain) {
|
|
417
|
+
return getCurrentFeeWallets()[chain];
|
|
421
418
|
}
|
|
422
419
|
function getCurrentCurrencyAddresses() {
|
|
423
420
|
return CURRENCY_ADDRESSES[getZubariNetwork()];
|
|
@@ -474,14 +471,14 @@ var WdkApiClient = class {
|
|
|
474
471
|
/**
|
|
475
472
|
* Derive address for a specific chain using Tether WDK
|
|
476
473
|
*/
|
|
477
|
-
async deriveAddress(seed,
|
|
474
|
+
async deriveAddress(seed, chain, network = "mainnet") {
|
|
478
475
|
try {
|
|
479
476
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/derive-address`, {
|
|
480
477
|
method: "POST",
|
|
481
478
|
headers: {
|
|
482
479
|
"Content-Type": "application/json"
|
|
483
480
|
},
|
|
484
|
-
body: JSON.stringify({ seed, chain
|
|
481
|
+
body: JSON.stringify({ seed, chain, network })
|
|
485
482
|
});
|
|
486
483
|
return await response.json();
|
|
487
484
|
} catch (error) {
|
|
@@ -514,14 +511,14 @@ var WdkApiClient = class {
|
|
|
514
511
|
/**
|
|
515
512
|
* Send a transaction on a specific chain using Tether WDK
|
|
516
513
|
*/
|
|
517
|
-
async sendTransaction(seed,
|
|
514
|
+
async sendTransaction(seed, chain, to, amount, network = "mainnet") {
|
|
518
515
|
try {
|
|
519
516
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/send`, {
|
|
520
517
|
method: "POST",
|
|
521
518
|
headers: {
|
|
522
519
|
"Content-Type": "application/json"
|
|
523
520
|
},
|
|
524
|
-
body: JSON.stringify({ seed, chain
|
|
521
|
+
body: JSON.stringify({ seed, chain, to, amount, network })
|
|
525
522
|
});
|
|
526
523
|
return await response.json();
|
|
527
524
|
} catch (error) {
|
|
@@ -535,14 +532,14 @@ var WdkApiClient = class {
|
|
|
535
532
|
* Get transaction history for an address on a specific chain
|
|
536
533
|
* Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
|
|
537
534
|
*/
|
|
538
|
-
async getTransactionHistory(seed,
|
|
535
|
+
async getTransactionHistory(seed, chain, network = "mainnet", limit = 10) {
|
|
539
536
|
try {
|
|
540
537
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/history`, {
|
|
541
538
|
method: "POST",
|
|
542
539
|
headers: {
|
|
543
540
|
"Content-Type": "application/json"
|
|
544
541
|
},
|
|
545
|
-
body: JSON.stringify({ seed, chain
|
|
542
|
+
body: JSON.stringify({ seed, chain, network, limit })
|
|
546
543
|
});
|
|
547
544
|
return await response.json();
|
|
548
545
|
} catch (error) {
|
|
@@ -556,14 +553,14 @@ var WdkApiClient = class {
|
|
|
556
553
|
* Get transaction status by hash
|
|
557
554
|
* Fetches from blockchain explorers to check confirmation status
|
|
558
555
|
*/
|
|
559
|
-
async getTransactionStatus(txHash,
|
|
556
|
+
async getTransactionStatus(txHash, chain, network = "mainnet") {
|
|
560
557
|
try {
|
|
561
558
|
const response = await fetch(`${this.config.baseUrl}/api/wallets/wdk/tx-status`, {
|
|
562
559
|
method: "POST",
|
|
563
560
|
headers: {
|
|
564
561
|
"Content-Type": "application/json"
|
|
565
562
|
},
|
|
566
|
-
body: JSON.stringify({ txHash, chain
|
|
563
|
+
body: JSON.stringify({ txHash, chain, network })
|
|
567
564
|
});
|
|
568
565
|
return await response.json();
|
|
569
566
|
} catch (error) {
|
|
@@ -598,589 +595,6 @@ __export(BrowserAddressDerivation_exports, {
|
|
|
598
595
|
generateSeedPhrase: () => generateSeedPhrase,
|
|
599
596
|
isValidSeed: () => isValidSeed
|
|
600
597
|
});
|
|
601
|
-
|
|
602
|
-
// node_modules/@scure/base/index.js
|
|
603
|
-
function isBytes(a) {
|
|
604
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
605
|
-
}
|
|
606
|
-
function isArrayOf(isString, arr) {
|
|
607
|
-
if (!Array.isArray(arr))
|
|
608
|
-
return false;
|
|
609
|
-
if (arr.length === 0)
|
|
610
|
-
return true;
|
|
611
|
-
if (isString) {
|
|
612
|
-
return arr.every((item) => typeof item === "string");
|
|
613
|
-
} else {
|
|
614
|
-
return arr.every((item) => Number.isSafeInteger(item));
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
function afn(input) {
|
|
618
|
-
if (typeof input !== "function")
|
|
619
|
-
throw new Error("function expected");
|
|
620
|
-
return true;
|
|
621
|
-
}
|
|
622
|
-
function astr(label, input) {
|
|
623
|
-
if (typeof input !== "string")
|
|
624
|
-
throw new Error(`${label}: string expected`);
|
|
625
|
-
return true;
|
|
626
|
-
}
|
|
627
|
-
function anumber(n) {
|
|
628
|
-
if (!Number.isSafeInteger(n))
|
|
629
|
-
throw new Error(`invalid integer: ${n}`);
|
|
630
|
-
}
|
|
631
|
-
function aArr(input) {
|
|
632
|
-
if (!Array.isArray(input))
|
|
633
|
-
throw new Error("array expected");
|
|
634
|
-
}
|
|
635
|
-
function astrArr(label, input) {
|
|
636
|
-
if (!isArrayOf(true, input))
|
|
637
|
-
throw new Error(`${label}: array of strings expected`);
|
|
638
|
-
}
|
|
639
|
-
function anumArr(label, input) {
|
|
640
|
-
if (!isArrayOf(false, input))
|
|
641
|
-
throw new Error(`${label}: array of numbers expected`);
|
|
642
|
-
}
|
|
643
|
-
// @__NO_SIDE_EFFECTS__
|
|
644
|
-
function chain(...args) {
|
|
645
|
-
const id = (a) => a;
|
|
646
|
-
const wrap = (a, b) => (c) => a(b(c));
|
|
647
|
-
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
648
|
-
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
649
|
-
return { encode, decode };
|
|
650
|
-
}
|
|
651
|
-
// @__NO_SIDE_EFFECTS__
|
|
652
|
-
function alphabet(letters) {
|
|
653
|
-
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
654
|
-
const len = lettersA.length;
|
|
655
|
-
astrArr("alphabet", lettersA);
|
|
656
|
-
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
657
|
-
return {
|
|
658
|
-
encode: (digits) => {
|
|
659
|
-
aArr(digits);
|
|
660
|
-
return digits.map((i) => {
|
|
661
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
662
|
-
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
663
|
-
return lettersA[i];
|
|
664
|
-
});
|
|
665
|
-
},
|
|
666
|
-
decode: (input) => {
|
|
667
|
-
aArr(input);
|
|
668
|
-
return input.map((letter) => {
|
|
669
|
-
astr("alphabet.decode", letter);
|
|
670
|
-
const i = indexes.get(letter);
|
|
671
|
-
if (i === void 0)
|
|
672
|
-
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
673
|
-
return i;
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
// @__NO_SIDE_EFFECTS__
|
|
679
|
-
function join(separator = "") {
|
|
680
|
-
astr("join", separator);
|
|
681
|
-
return {
|
|
682
|
-
encode: (from) => {
|
|
683
|
-
astrArr("join.decode", from);
|
|
684
|
-
return from.join(separator);
|
|
685
|
-
},
|
|
686
|
-
decode: (to) => {
|
|
687
|
-
astr("join.decode", to);
|
|
688
|
-
return to.split(separator);
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
function convertRadix(data, from, to) {
|
|
693
|
-
if (from < 2)
|
|
694
|
-
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
695
|
-
if (to < 2)
|
|
696
|
-
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
697
|
-
aArr(data);
|
|
698
|
-
if (!data.length)
|
|
699
|
-
return [];
|
|
700
|
-
let pos = 0;
|
|
701
|
-
const res = [];
|
|
702
|
-
const digits = Array.from(data, (d) => {
|
|
703
|
-
anumber(d);
|
|
704
|
-
if (d < 0 || d >= from)
|
|
705
|
-
throw new Error(`invalid integer: ${d}`);
|
|
706
|
-
return d;
|
|
707
|
-
});
|
|
708
|
-
const dlen = digits.length;
|
|
709
|
-
while (true) {
|
|
710
|
-
let carry = 0;
|
|
711
|
-
let done = true;
|
|
712
|
-
for (let i = pos; i < dlen; i++) {
|
|
713
|
-
const digit = digits[i];
|
|
714
|
-
const fromCarry = from * carry;
|
|
715
|
-
const digitBase = fromCarry + digit;
|
|
716
|
-
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
717
|
-
throw new Error("convertRadix: carry overflow");
|
|
718
|
-
}
|
|
719
|
-
const div = digitBase / to;
|
|
720
|
-
carry = digitBase % to;
|
|
721
|
-
const rounded = Math.floor(div);
|
|
722
|
-
digits[i] = rounded;
|
|
723
|
-
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
724
|
-
throw new Error("convertRadix: carry overflow");
|
|
725
|
-
if (!done)
|
|
726
|
-
continue;
|
|
727
|
-
else if (!rounded)
|
|
728
|
-
pos = i;
|
|
729
|
-
else
|
|
730
|
-
done = false;
|
|
731
|
-
}
|
|
732
|
-
res.push(carry);
|
|
733
|
-
if (done)
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
|
737
|
-
res.push(0);
|
|
738
|
-
return res.reverse();
|
|
739
|
-
}
|
|
740
|
-
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
741
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
742
|
-
var powers = /* @__PURE__ */ (() => {
|
|
743
|
-
let res = [];
|
|
744
|
-
for (let i = 0; i < 40; i++)
|
|
745
|
-
res.push(2 ** i);
|
|
746
|
-
return res;
|
|
747
|
-
})();
|
|
748
|
-
function convertRadix2(data, from, to, padding) {
|
|
749
|
-
aArr(data);
|
|
750
|
-
if (from <= 0 || from > 32)
|
|
751
|
-
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
752
|
-
if (to <= 0 || to > 32)
|
|
753
|
-
throw new Error(`convertRadix2: wrong to=${to}`);
|
|
754
|
-
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
|
755
|
-
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
756
|
-
}
|
|
757
|
-
let carry = 0;
|
|
758
|
-
let pos = 0;
|
|
759
|
-
const max = powers[from];
|
|
760
|
-
const mask = powers[to] - 1;
|
|
761
|
-
const res = [];
|
|
762
|
-
for (const n of data) {
|
|
763
|
-
anumber(n);
|
|
764
|
-
if (n >= max)
|
|
765
|
-
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
766
|
-
carry = carry << from | n;
|
|
767
|
-
if (pos + from > 32)
|
|
768
|
-
throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
769
|
-
pos += from;
|
|
770
|
-
for (; pos >= to; pos -= to)
|
|
771
|
-
res.push((carry >> pos - to & mask) >>> 0);
|
|
772
|
-
const pow = powers[pos];
|
|
773
|
-
if (pow === void 0)
|
|
774
|
-
throw new Error("invalid carry");
|
|
775
|
-
carry &= pow - 1;
|
|
776
|
-
}
|
|
777
|
-
carry = carry << to - pos & mask;
|
|
778
|
-
if (!padding && pos >= from)
|
|
779
|
-
throw new Error("Excess padding");
|
|
780
|
-
if (!padding && carry > 0)
|
|
781
|
-
throw new Error(`Non-zero padding: ${carry}`);
|
|
782
|
-
if (padding && pos > 0)
|
|
783
|
-
res.push(carry >>> 0);
|
|
784
|
-
return res;
|
|
785
|
-
}
|
|
786
|
-
// @__NO_SIDE_EFFECTS__
|
|
787
|
-
function radix(num) {
|
|
788
|
-
anumber(num);
|
|
789
|
-
const _256 = 2 ** 8;
|
|
790
|
-
return {
|
|
791
|
-
encode: (bytes) => {
|
|
792
|
-
if (!isBytes(bytes))
|
|
793
|
-
throw new Error("radix.encode input should be Uint8Array");
|
|
794
|
-
return convertRadix(Array.from(bytes), _256, num);
|
|
795
|
-
},
|
|
796
|
-
decode: (digits) => {
|
|
797
|
-
anumArr("radix.decode", digits);
|
|
798
|
-
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
// @__NO_SIDE_EFFECTS__
|
|
803
|
-
function radix2(bits, revPadding = false) {
|
|
804
|
-
anumber(bits);
|
|
805
|
-
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
806
|
-
throw new Error("radix2: carry overflow");
|
|
807
|
-
return {
|
|
808
|
-
encode: (bytes) => {
|
|
809
|
-
if (!isBytes(bytes))
|
|
810
|
-
throw new Error("radix2.encode input should be Uint8Array");
|
|
811
|
-
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
812
|
-
},
|
|
813
|
-
decode: (digits) => {
|
|
814
|
-
anumArr("radix2.decode", digits);
|
|
815
|
-
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
816
|
-
}
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
function unsafeWrapper(fn) {
|
|
820
|
-
afn(fn);
|
|
821
|
-
return function(...args) {
|
|
822
|
-
try {
|
|
823
|
-
return fn.apply(null, args);
|
|
824
|
-
} catch (e) {
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
function checksum(len, fn) {
|
|
829
|
-
anumber(len);
|
|
830
|
-
afn(fn);
|
|
831
|
-
return {
|
|
832
|
-
encode(data) {
|
|
833
|
-
if (!isBytes(data))
|
|
834
|
-
throw new Error("checksum.encode: input should be Uint8Array");
|
|
835
|
-
const sum = fn(data).slice(0, len);
|
|
836
|
-
const res = new Uint8Array(data.length + len);
|
|
837
|
-
res.set(data);
|
|
838
|
-
res.set(sum, data.length);
|
|
839
|
-
return res;
|
|
840
|
-
},
|
|
841
|
-
decode(data) {
|
|
842
|
-
if (!isBytes(data))
|
|
843
|
-
throw new Error("checksum.decode: input should be Uint8Array");
|
|
844
|
-
const payload = data.slice(0, -len);
|
|
845
|
-
const oldChecksum = data.slice(-len);
|
|
846
|
-
const newChecksum = fn(payload).slice(0, len);
|
|
847
|
-
for (let i = 0; i < len; i++)
|
|
848
|
-
if (newChecksum[i] !== oldChecksum[i])
|
|
849
|
-
throw new Error("Invalid checksum");
|
|
850
|
-
return payload;
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
var genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
855
|
-
var base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
856
|
-
var createBase58check = (sha2563) => /* @__PURE__ */ chain(checksum(4, (data) => sha2563(sha2563(data))), base58);
|
|
857
|
-
var base58check = createBase58check;
|
|
858
|
-
var BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
859
|
-
var POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
860
|
-
function bech32Polymod(pre) {
|
|
861
|
-
const b = pre >> 25;
|
|
862
|
-
let chk = (pre & 33554431) << 5;
|
|
863
|
-
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
|
|
864
|
-
if ((b >> i & 1) === 1)
|
|
865
|
-
chk ^= POLYMOD_GENERATORS[i];
|
|
866
|
-
}
|
|
867
|
-
return chk;
|
|
868
|
-
}
|
|
869
|
-
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
870
|
-
const len = prefix.length;
|
|
871
|
-
let chk = 1;
|
|
872
|
-
for (let i = 0; i < len; i++) {
|
|
873
|
-
const c = prefix.charCodeAt(i);
|
|
874
|
-
if (c < 33 || c > 126)
|
|
875
|
-
throw new Error(`Invalid prefix (${prefix})`);
|
|
876
|
-
chk = bech32Polymod(chk) ^ c >> 5;
|
|
877
|
-
}
|
|
878
|
-
chk = bech32Polymod(chk);
|
|
879
|
-
for (let i = 0; i < len; i++)
|
|
880
|
-
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
881
|
-
for (let v of words)
|
|
882
|
-
chk = bech32Polymod(chk) ^ v;
|
|
883
|
-
for (let i = 0; i < 6; i++)
|
|
884
|
-
chk = bech32Polymod(chk);
|
|
885
|
-
chk ^= encodingConst;
|
|
886
|
-
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
887
|
-
}
|
|
888
|
-
// @__NO_SIDE_EFFECTS__
|
|
889
|
-
function genBech32(encoding) {
|
|
890
|
-
const ENCODING_CONST = 1 ;
|
|
891
|
-
const _words = /* @__PURE__ */ radix2(5);
|
|
892
|
-
const fromWords = _words.decode;
|
|
893
|
-
const toWords = _words.encode;
|
|
894
|
-
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
895
|
-
function encode(prefix, words, limit = 90) {
|
|
896
|
-
astr("bech32.encode prefix", prefix);
|
|
897
|
-
if (isBytes(words))
|
|
898
|
-
words = Array.from(words);
|
|
899
|
-
anumArr("bech32.encode", words);
|
|
900
|
-
const plen = prefix.length;
|
|
901
|
-
if (plen === 0)
|
|
902
|
-
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
903
|
-
const actualLength = plen + 7 + words.length;
|
|
904
|
-
if (limit !== false && actualLength > limit)
|
|
905
|
-
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
906
|
-
const lowered = prefix.toLowerCase();
|
|
907
|
-
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
908
|
-
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
909
|
-
}
|
|
910
|
-
function decode(str, limit = 90) {
|
|
911
|
-
astr("bech32.decode input", str);
|
|
912
|
-
const slen = str.length;
|
|
913
|
-
if (slen < 8 || limit !== false && slen > limit)
|
|
914
|
-
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
915
|
-
const lowered = str.toLowerCase();
|
|
916
|
-
if (str !== lowered && str !== str.toUpperCase())
|
|
917
|
-
throw new Error(`String must be lowercase or uppercase`);
|
|
918
|
-
const sepIndex = lowered.lastIndexOf("1");
|
|
919
|
-
if (sepIndex === 0 || sepIndex === -1)
|
|
920
|
-
throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
921
|
-
const prefix = lowered.slice(0, sepIndex);
|
|
922
|
-
const data = lowered.slice(sepIndex + 1);
|
|
923
|
-
if (data.length < 6)
|
|
924
|
-
throw new Error("Data must be at least 6 characters long");
|
|
925
|
-
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
926
|
-
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
927
|
-
if (!data.endsWith(sum))
|
|
928
|
-
throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
929
|
-
return { prefix, words };
|
|
930
|
-
}
|
|
931
|
-
const decodeUnsafe = unsafeWrapper(decode);
|
|
932
|
-
function decodeToBytes(str) {
|
|
933
|
-
const { prefix, words } = decode(str, false);
|
|
934
|
-
return { prefix, words, bytes: fromWords(words) };
|
|
935
|
-
}
|
|
936
|
-
function encodeFromBytes(prefix, bytes) {
|
|
937
|
-
return encode(prefix, toWords(bytes));
|
|
938
|
-
}
|
|
939
|
-
return {
|
|
940
|
-
encode,
|
|
941
|
-
decode,
|
|
942
|
-
encodeFromBytes,
|
|
943
|
-
decodeToBytes,
|
|
944
|
-
decodeUnsafe,
|
|
945
|
-
fromWords,
|
|
946
|
-
fromWordsUnsafe,
|
|
947
|
-
toWords
|
|
948
|
-
};
|
|
949
|
-
}
|
|
950
|
-
var bech32 = /* @__PURE__ */ genBech32();
|
|
951
|
-
|
|
952
|
-
// node_modules/@scure/bip32/index.js
|
|
953
|
-
var Point = secp256k1_js.secp256k1.Point;
|
|
954
|
-
var { Fn } = Point;
|
|
955
|
-
var base58check2 = createBase58check(sha2_js.sha256);
|
|
956
|
-
var MASTER_SECRET = Uint8Array.from("Bitcoin seed".split(""), (char) => char.charCodeAt(0));
|
|
957
|
-
var BITCOIN_VERSIONS = { private: 76066276, public: 76067358 };
|
|
958
|
-
var HARDENED_OFFSET = 2147483648;
|
|
959
|
-
var hash160 = (data) => legacy_js.ripemd160(sha2_js.sha256(data));
|
|
960
|
-
var fromU32 = (data) => utils_js.createView(data).getUint32(0, false);
|
|
961
|
-
var toU32 = (n) => {
|
|
962
|
-
if (!Number.isSafeInteger(n) || n < 0 || n > 2 ** 32 - 1) {
|
|
963
|
-
throw new Error("invalid number, should be from 0 to 2**32-1, got " + n);
|
|
964
|
-
}
|
|
965
|
-
const buf = new Uint8Array(4);
|
|
966
|
-
utils_js.createView(buf).setUint32(0, n, false);
|
|
967
|
-
return buf;
|
|
968
|
-
};
|
|
969
|
-
var HDKey = class _HDKey {
|
|
970
|
-
get fingerprint() {
|
|
971
|
-
if (!this.pubHash) {
|
|
972
|
-
throw new Error("No publicKey set!");
|
|
973
|
-
}
|
|
974
|
-
return fromU32(this.pubHash);
|
|
975
|
-
}
|
|
976
|
-
get identifier() {
|
|
977
|
-
return this.pubHash;
|
|
978
|
-
}
|
|
979
|
-
get pubKeyHash() {
|
|
980
|
-
return this.pubHash;
|
|
981
|
-
}
|
|
982
|
-
get privateKey() {
|
|
983
|
-
return this._privateKey || null;
|
|
984
|
-
}
|
|
985
|
-
get publicKey() {
|
|
986
|
-
return this._publicKey || null;
|
|
987
|
-
}
|
|
988
|
-
get privateExtendedKey() {
|
|
989
|
-
const priv = this._privateKey;
|
|
990
|
-
if (!priv) {
|
|
991
|
-
throw new Error("No private key");
|
|
992
|
-
}
|
|
993
|
-
return base58check2.encode(this.serialize(this.versions.private, utils_js.concatBytes(Uint8Array.of(0), priv)));
|
|
994
|
-
}
|
|
995
|
-
get publicExtendedKey() {
|
|
996
|
-
if (!this._publicKey) {
|
|
997
|
-
throw new Error("No public key");
|
|
998
|
-
}
|
|
999
|
-
return base58check2.encode(this.serialize(this.versions.public, this._publicKey));
|
|
1000
|
-
}
|
|
1001
|
-
static fromMasterSeed(seed, versions = BITCOIN_VERSIONS) {
|
|
1002
|
-
utils_js.abytes(seed);
|
|
1003
|
-
if (8 * seed.length < 128 || 8 * seed.length > 512) {
|
|
1004
|
-
throw new Error("HDKey: seed length must be between 128 and 512 bits; 256 bits is advised, got " + seed.length);
|
|
1005
|
-
}
|
|
1006
|
-
const I = hmac_js.hmac(sha2_js.sha512, MASTER_SECRET, seed);
|
|
1007
|
-
const privateKey = I.slice(0, 32);
|
|
1008
|
-
const chainCode = I.slice(32);
|
|
1009
|
-
return new _HDKey({ versions, chainCode, privateKey });
|
|
1010
|
-
}
|
|
1011
|
-
static fromExtendedKey(base58key, versions = BITCOIN_VERSIONS) {
|
|
1012
|
-
const keyBuffer = base58check2.decode(base58key);
|
|
1013
|
-
const keyView = utils_js.createView(keyBuffer);
|
|
1014
|
-
const version = keyView.getUint32(0, false);
|
|
1015
|
-
const opt = {
|
|
1016
|
-
versions,
|
|
1017
|
-
depth: keyBuffer[4],
|
|
1018
|
-
parentFingerprint: keyView.getUint32(5, false),
|
|
1019
|
-
index: keyView.getUint32(9, false),
|
|
1020
|
-
chainCode: keyBuffer.slice(13, 45)
|
|
1021
|
-
};
|
|
1022
|
-
const key = keyBuffer.slice(45);
|
|
1023
|
-
const isPriv = key[0] === 0;
|
|
1024
|
-
if (version !== versions[isPriv ? "private" : "public"]) {
|
|
1025
|
-
throw new Error("Version mismatch");
|
|
1026
|
-
}
|
|
1027
|
-
if (isPriv) {
|
|
1028
|
-
return new _HDKey({ ...opt, privateKey: key.slice(1) });
|
|
1029
|
-
} else {
|
|
1030
|
-
return new _HDKey({ ...opt, publicKey: key });
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
static fromJSON(json) {
|
|
1034
|
-
return _HDKey.fromExtendedKey(json.xpriv);
|
|
1035
|
-
}
|
|
1036
|
-
versions;
|
|
1037
|
-
depth = 0;
|
|
1038
|
-
index = 0;
|
|
1039
|
-
chainCode = null;
|
|
1040
|
-
parentFingerprint = 0;
|
|
1041
|
-
_privateKey;
|
|
1042
|
-
_publicKey;
|
|
1043
|
-
pubHash;
|
|
1044
|
-
constructor(opt) {
|
|
1045
|
-
if (!opt || typeof opt !== "object") {
|
|
1046
|
-
throw new Error("HDKey.constructor must not be called directly");
|
|
1047
|
-
}
|
|
1048
|
-
this.versions = opt.versions || BITCOIN_VERSIONS;
|
|
1049
|
-
this.depth = opt.depth || 0;
|
|
1050
|
-
this.chainCode = opt.chainCode || null;
|
|
1051
|
-
this.index = opt.index || 0;
|
|
1052
|
-
this.parentFingerprint = opt.parentFingerprint || 0;
|
|
1053
|
-
if (!this.depth) {
|
|
1054
|
-
if (this.parentFingerprint || this.index) {
|
|
1055
|
-
throw new Error("HDKey: zero depth with non-zero index/parent fingerprint");
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
if (this.depth > 255) {
|
|
1059
|
-
throw new Error("HDKey: depth exceeds the serializable value 255");
|
|
1060
|
-
}
|
|
1061
|
-
if (opt.publicKey && opt.privateKey) {
|
|
1062
|
-
throw new Error("HDKey: publicKey and privateKey at same time.");
|
|
1063
|
-
}
|
|
1064
|
-
if (opt.privateKey) {
|
|
1065
|
-
if (!secp256k1_js.secp256k1.utils.isValidSecretKey(opt.privateKey))
|
|
1066
|
-
throw new Error("Invalid private key");
|
|
1067
|
-
this._privateKey = opt.privateKey;
|
|
1068
|
-
this._publicKey = secp256k1_js.secp256k1.getPublicKey(opt.privateKey, true);
|
|
1069
|
-
} else if (opt.publicKey) {
|
|
1070
|
-
this._publicKey = Point.fromBytes(opt.publicKey).toBytes(true);
|
|
1071
|
-
} else {
|
|
1072
|
-
throw new Error("HDKey: no public or private key provided");
|
|
1073
|
-
}
|
|
1074
|
-
this.pubHash = hash160(this._publicKey);
|
|
1075
|
-
}
|
|
1076
|
-
derive(path) {
|
|
1077
|
-
if (!/^[mM]'?/.test(path)) {
|
|
1078
|
-
throw new Error('Path must start with "m" or "M"');
|
|
1079
|
-
}
|
|
1080
|
-
if (/^[mM]'?$/.test(path)) {
|
|
1081
|
-
return this;
|
|
1082
|
-
}
|
|
1083
|
-
const parts = path.replace(/^[mM]'?\//, "").split("/");
|
|
1084
|
-
let child = this;
|
|
1085
|
-
for (const c of parts) {
|
|
1086
|
-
const m = /^(\d+)('?)$/.exec(c);
|
|
1087
|
-
const m1 = m && m[1];
|
|
1088
|
-
if (!m || m.length !== 3 || typeof m1 !== "string")
|
|
1089
|
-
throw new Error("invalid child index: " + c);
|
|
1090
|
-
let idx = +m1;
|
|
1091
|
-
if (!Number.isSafeInteger(idx) || idx >= HARDENED_OFFSET) {
|
|
1092
|
-
throw new Error("Invalid index");
|
|
1093
|
-
}
|
|
1094
|
-
if (m[2] === "'") {
|
|
1095
|
-
idx += HARDENED_OFFSET;
|
|
1096
|
-
}
|
|
1097
|
-
child = child.deriveChild(idx);
|
|
1098
|
-
}
|
|
1099
|
-
return child;
|
|
1100
|
-
}
|
|
1101
|
-
deriveChild(index) {
|
|
1102
|
-
if (!this._publicKey || !this.chainCode) {
|
|
1103
|
-
throw new Error("No publicKey or chainCode set");
|
|
1104
|
-
}
|
|
1105
|
-
let data = toU32(index);
|
|
1106
|
-
if (index >= HARDENED_OFFSET) {
|
|
1107
|
-
const priv = this._privateKey;
|
|
1108
|
-
if (!priv) {
|
|
1109
|
-
throw new Error("Could not derive hardened child key");
|
|
1110
|
-
}
|
|
1111
|
-
data = utils_js.concatBytes(Uint8Array.of(0), priv, data);
|
|
1112
|
-
} else {
|
|
1113
|
-
data = utils_js.concatBytes(this._publicKey, data);
|
|
1114
|
-
}
|
|
1115
|
-
const I = hmac_js.hmac(sha2_js.sha512, this.chainCode, data);
|
|
1116
|
-
const childTweak = I.slice(0, 32);
|
|
1117
|
-
const chainCode = I.slice(32);
|
|
1118
|
-
if (!secp256k1_js.secp256k1.utils.isValidSecretKey(childTweak)) {
|
|
1119
|
-
throw new Error("Tweak bigger than curve order");
|
|
1120
|
-
}
|
|
1121
|
-
const opt = {
|
|
1122
|
-
versions: this.versions,
|
|
1123
|
-
chainCode,
|
|
1124
|
-
depth: this.depth + 1,
|
|
1125
|
-
parentFingerprint: this.fingerprint,
|
|
1126
|
-
index
|
|
1127
|
-
};
|
|
1128
|
-
const ctweak = Fn.fromBytes(childTweak);
|
|
1129
|
-
try {
|
|
1130
|
-
if (this._privateKey) {
|
|
1131
|
-
const added = Fn.create(Fn.fromBytes(this._privateKey) + ctweak);
|
|
1132
|
-
if (!Fn.isValidNot0(added)) {
|
|
1133
|
-
throw new Error("The tweak was out of range or the resulted private key is invalid");
|
|
1134
|
-
}
|
|
1135
|
-
opt.privateKey = Fn.toBytes(added);
|
|
1136
|
-
} else {
|
|
1137
|
-
const added = Point.fromBytes(this._publicKey).add(Point.BASE.multiply(ctweak));
|
|
1138
|
-
if (added.equals(Point.ZERO)) {
|
|
1139
|
-
throw new Error("The tweak was equal to negative P, which made the result key invalid");
|
|
1140
|
-
}
|
|
1141
|
-
opt.publicKey = added.toBytes(true);
|
|
1142
|
-
}
|
|
1143
|
-
return new _HDKey(opt);
|
|
1144
|
-
} catch (err) {
|
|
1145
|
-
return this.deriveChild(index + 1);
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
sign(hash) {
|
|
1149
|
-
if (!this._privateKey) {
|
|
1150
|
-
throw new Error("No privateKey set!");
|
|
1151
|
-
}
|
|
1152
|
-
utils_js.abytes(hash, 32);
|
|
1153
|
-
return secp256k1_js.secp256k1.sign(hash, this._privateKey, { prehash: false });
|
|
1154
|
-
}
|
|
1155
|
-
verify(hash, signature) {
|
|
1156
|
-
utils_js.abytes(hash, 32);
|
|
1157
|
-
utils_js.abytes(signature, 64);
|
|
1158
|
-
if (!this._publicKey) {
|
|
1159
|
-
throw new Error("No publicKey set!");
|
|
1160
|
-
}
|
|
1161
|
-
return secp256k1_js.secp256k1.verify(signature, hash, this._publicKey, { prehash: false });
|
|
1162
|
-
}
|
|
1163
|
-
wipePrivateData() {
|
|
1164
|
-
if (this._privateKey) {
|
|
1165
|
-
this._privateKey.fill(0);
|
|
1166
|
-
this._privateKey = void 0;
|
|
1167
|
-
}
|
|
1168
|
-
return this;
|
|
1169
|
-
}
|
|
1170
|
-
toJSON() {
|
|
1171
|
-
return {
|
|
1172
|
-
xpriv: this.privateExtendedKey,
|
|
1173
|
-
xpub: this.publicExtendedKey
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
serialize(version, key) {
|
|
1177
|
-
if (!this.chainCode) {
|
|
1178
|
-
throw new Error("No chainCode set");
|
|
1179
|
-
}
|
|
1180
|
-
utils_js.abytes(key, 33);
|
|
1181
|
-
return utils_js.concatBytes(toU32(version), new Uint8Array([this.depth]), toU32(this.parentFingerprint), toU32(this.index), this.chainCode, key);
|
|
1182
|
-
}
|
|
1183
|
-
};
|
|
1184
598
|
var DERIVATION_PATHS2 = {
|
|
1185
599
|
ethereum: "m/44'/60'/0'/0/0",
|
|
1186
600
|
bitcoin_mainnet: "m/84'/0'/0'/0/0",
|
|
@@ -1197,7 +611,7 @@ function deriveEthereumAddress(seed) {
|
|
|
1197
611
|
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
1198
612
|
try {
|
|
1199
613
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1200
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
614
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1201
615
|
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
1202
616
|
const child = hdKey.derive(path);
|
|
1203
617
|
if (!child.publicKey) {
|
|
@@ -1205,10 +619,10 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
1205
619
|
}
|
|
1206
620
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1207
621
|
const witnessVersion = 0;
|
|
1208
|
-
const words = bech32.toWords(pubKeyHash);
|
|
622
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1209
623
|
words.unshift(witnessVersion);
|
|
1210
624
|
const hrp = network === "testnet" ? "tb" : "bc";
|
|
1211
|
-
const address = bech32.encode(hrp, words);
|
|
625
|
+
const address = base.bech32.encode(hrp, words);
|
|
1212
626
|
return address;
|
|
1213
627
|
} catch (error) {
|
|
1214
628
|
console.error("Bitcoin address derivation failed:", error);
|
|
@@ -1281,7 +695,7 @@ function deriveTronAddress(seed) {
|
|
|
1281
695
|
for (let i = 0; i < 20; i++) {
|
|
1282
696
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
1283
697
|
}
|
|
1284
|
-
const tronBase58check = base58check(sha256.sha256);
|
|
698
|
+
const tronBase58check = base.base58check(sha256.sha256);
|
|
1285
699
|
return tronBase58check.encode(addressBytes);
|
|
1286
700
|
} catch (error) {
|
|
1287
701
|
console.error("TRON address derivation failed:", error);
|
|
@@ -1291,17 +705,17 @@ function deriveTronAddress(seed) {
|
|
|
1291
705
|
function deriveSparkAddress(seed, network = "mainnet") {
|
|
1292
706
|
try {
|
|
1293
707
|
const seedBytes = bip39.mnemonicToSeedSync(seed);
|
|
1294
|
-
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
708
|
+
const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
|
|
1295
709
|
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
1296
710
|
if (!child.publicKey) {
|
|
1297
711
|
throw new Error("Failed to derive public key");
|
|
1298
712
|
}
|
|
1299
713
|
const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
|
|
1300
714
|
const witnessVersion = 0;
|
|
1301
|
-
const words = bech32.toWords(pubKeyHash);
|
|
715
|
+
const words = base.bech32.toWords(pubKeyHash);
|
|
1302
716
|
words.unshift(witnessVersion);
|
|
1303
717
|
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
1304
|
-
const address = bech32.encode(hrp, words);
|
|
718
|
+
const address = base.bech32.encode(hrp, words);
|
|
1305
719
|
return address;
|
|
1306
720
|
} catch (error) {
|
|
1307
721
|
console.error("Spark address derivation failed:", error);
|
|
@@ -1397,9 +811,9 @@ var CHAIN_ERROR_MESSAGES = {
|
|
|
1397
811
|
"no route": "NETWORK_ERROR"
|
|
1398
812
|
}
|
|
1399
813
|
};
|
|
1400
|
-
function parseChainError(
|
|
814
|
+
function parseChainError(chain, errorMessage) {
|
|
1401
815
|
const errorLower = errorMessage.toLowerCase();
|
|
1402
|
-
const chainErrors = CHAIN_ERROR_MESSAGES[
|
|
816
|
+
const chainErrors = CHAIN_ERROR_MESSAGES[chain];
|
|
1403
817
|
for (const [pattern, code] of Object.entries(chainErrors)) {
|
|
1404
818
|
if (errorLower.includes(pattern)) {
|
|
1405
819
|
return code;
|
|
@@ -1537,38 +951,38 @@ var ZubariWdkService = class {
|
|
|
1537
951
|
* For Ethereum, falls back to local derivation if API fails.
|
|
1538
952
|
* For other chains, WDK API is required - no placeholder fallback.
|
|
1539
953
|
*/
|
|
1540
|
-
async deriveAddress(seed,
|
|
954
|
+
async deriveAddress(seed, chain) {
|
|
1541
955
|
await this.initialize();
|
|
1542
|
-
const path = this.getDerivationPath(
|
|
956
|
+
const path = this.getDerivationPath(chain);
|
|
1543
957
|
try {
|
|
1544
|
-
const response = await this.apiClient.deriveAddress(seed,
|
|
958
|
+
const response = await this.apiClient.deriveAddress(seed, chain, this.config.network);
|
|
1545
959
|
if (response.success && response.address) {
|
|
1546
960
|
return {
|
|
1547
|
-
chain
|
|
961
|
+
chain,
|
|
1548
962
|
address: response.address,
|
|
1549
963
|
path: response.path || path
|
|
1550
964
|
};
|
|
1551
965
|
}
|
|
1552
966
|
} catch (error) {
|
|
1553
|
-
console.warn(`API address derivation failed for ${
|
|
1554
|
-
if (
|
|
1555
|
-
return this.deriveBrowserAddress(seed,
|
|
967
|
+
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
968
|
+
if (chain === "ethereum") {
|
|
969
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
1556
970
|
}
|
|
1557
971
|
}
|
|
1558
972
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
1559
973
|
try {
|
|
1560
974
|
const wdk = this.nativeWdkService;
|
|
1561
975
|
await wdk.initialize(seed);
|
|
1562
|
-
return await wdk.deriveAddress(
|
|
976
|
+
return await wdk.deriveAddress(chain);
|
|
1563
977
|
} catch (error) {
|
|
1564
|
-
console.warn(`Native WDK address derivation failed for ${
|
|
978
|
+
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
1565
979
|
}
|
|
1566
980
|
}
|
|
1567
|
-
if (
|
|
1568
|
-
return this.deriveBrowserAddress(seed,
|
|
981
|
+
if (chain === "ethereum") {
|
|
982
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
1569
983
|
}
|
|
1570
984
|
throw new Error(
|
|
1571
|
-
`WDK API required for ${
|
|
985
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
1572
986
|
);
|
|
1573
987
|
}
|
|
1574
988
|
/**
|
|
@@ -1648,13 +1062,13 @@ var ZubariWdkService = class {
|
|
|
1648
1062
|
/**
|
|
1649
1063
|
* Get fee rates for a chain
|
|
1650
1064
|
*/
|
|
1651
|
-
async getFeeRates(seed,
|
|
1065
|
+
async getFeeRates(seed, chain) {
|
|
1652
1066
|
await this.initialize();
|
|
1653
1067
|
try {
|
|
1654
1068
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/fee-rates`, {
|
|
1655
1069
|
method: "POST",
|
|
1656
1070
|
headers: { "Content-Type": "application/json" },
|
|
1657
|
-
body: JSON.stringify({ seed, chain
|
|
1071
|
+
body: JSON.stringify({ seed, chain, network: this.config.network })
|
|
1658
1072
|
});
|
|
1659
1073
|
if (response.ok) {
|
|
1660
1074
|
const data = await response.json();
|
|
@@ -1663,20 +1077,20 @@ var ZubariWdkService = class {
|
|
|
1663
1077
|
}
|
|
1664
1078
|
}
|
|
1665
1079
|
} catch (error) {
|
|
1666
|
-
console.warn(`Failed to fetch fee rates for ${
|
|
1080
|
+
console.warn(`Failed to fetch fee rates for ${chain}:`, error);
|
|
1667
1081
|
}
|
|
1668
1082
|
return { slow: "0", normal: "0", fast: "0" };
|
|
1669
1083
|
}
|
|
1670
1084
|
/**
|
|
1671
1085
|
* Estimate transaction fee
|
|
1672
1086
|
*/
|
|
1673
|
-
async estimateFee(seed,
|
|
1087
|
+
async estimateFee(seed, chain, to, amount) {
|
|
1674
1088
|
await this.initialize();
|
|
1675
1089
|
try {
|
|
1676
1090
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1677
1091
|
method: "POST",
|
|
1678
1092
|
headers: { "Content-Type": "application/json" },
|
|
1679
|
-
body: JSON.stringify({ seed, chain
|
|
1093
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1680
1094
|
});
|
|
1681
1095
|
if (response.ok) {
|
|
1682
1096
|
const data = await response.json();
|
|
@@ -1685,9 +1099,9 @@ var ZubariWdkService = class {
|
|
|
1685
1099
|
}
|
|
1686
1100
|
}
|
|
1687
1101
|
} catch (error) {
|
|
1688
|
-
console.warn(`Failed to estimate fee for ${
|
|
1102
|
+
console.warn(`Failed to estimate fee for ${chain}:`, error);
|
|
1689
1103
|
}
|
|
1690
|
-
return { fee: "0", symbol: this.getChainSymbol(
|
|
1104
|
+
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
1691
1105
|
}
|
|
1692
1106
|
/**
|
|
1693
1107
|
* Send a transaction on any supported chain
|
|
@@ -1698,10 +1112,10 @@ var ZubariWdkService = class {
|
|
|
1698
1112
|
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
1699
1113
|
* @returns Transaction result with hash on success, or error details on failure
|
|
1700
1114
|
*/
|
|
1701
|
-
async sendTransaction(seed,
|
|
1115
|
+
async sendTransaction(seed, chain, to, amount) {
|
|
1702
1116
|
await this.initialize();
|
|
1703
1117
|
const startTime = Date.now();
|
|
1704
|
-
console.log(`[ZubariWdkService] Sending ${
|
|
1118
|
+
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
1705
1119
|
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
1706
1120
|
amount,
|
|
1707
1121
|
network: this.config.network
|
|
@@ -1710,7 +1124,7 @@ var ZubariWdkService = class {
|
|
|
1710
1124
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1711
1125
|
method: "POST",
|
|
1712
1126
|
headers: { "Content-Type": "application/json" },
|
|
1713
|
-
body: JSON.stringify({ seed, chain
|
|
1127
|
+
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1714
1128
|
});
|
|
1715
1129
|
const elapsed = Date.now() - startTime;
|
|
1716
1130
|
if (response.ok) {
|
|
@@ -1720,22 +1134,22 @@ var ZubariWdkService = class {
|
|
|
1720
1134
|
txHash = txHash.hash;
|
|
1721
1135
|
}
|
|
1722
1136
|
if (txHash) {
|
|
1723
|
-
const isValid = this.validateTxHash(
|
|
1137
|
+
const isValid = this.validateTxHash(chain, txHash);
|
|
1724
1138
|
if (!isValid) {
|
|
1725
|
-
console.warn(`[ZubariWdkService] Invalid ${
|
|
1139
|
+
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
1726
1140
|
}
|
|
1727
1141
|
}
|
|
1728
|
-
console.log(`[ZubariWdkService] ${
|
|
1142
|
+
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
1729
1143
|
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
1730
1144
|
elapsed: `${elapsed}ms`
|
|
1731
1145
|
});
|
|
1732
1146
|
if (!data.success) {
|
|
1733
|
-
const errorCode2 = parseChainError(
|
|
1147
|
+
const errorCode2 = parseChainError(chain, data.error || "");
|
|
1734
1148
|
return {
|
|
1735
1149
|
success: false,
|
|
1736
1150
|
error: data.error,
|
|
1737
1151
|
errorCode: errorCode2,
|
|
1738
|
-
chain
|
|
1152
|
+
chain
|
|
1739
1153
|
};
|
|
1740
1154
|
}
|
|
1741
1155
|
return {
|
|
@@ -1744,14 +1158,14 @@ var ZubariWdkService = class {
|
|
|
1744
1158
|
from: data.from,
|
|
1745
1159
|
to: data.to,
|
|
1746
1160
|
amount: data.amount,
|
|
1747
|
-
chain: data.chain ||
|
|
1161
|
+
chain: data.chain || chain,
|
|
1748
1162
|
network: data.network || this.config.network
|
|
1749
1163
|
};
|
|
1750
1164
|
}
|
|
1751
1165
|
const errorData = await response.json().catch(() => ({}));
|
|
1752
1166
|
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
1753
|
-
const errorCode = parseChainError(
|
|
1754
|
-
console.error(`[ZubariWdkService] ${
|
|
1167
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1168
|
+
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
1755
1169
|
status: response.status,
|
|
1756
1170
|
error: errorMessage,
|
|
1757
1171
|
errorCode,
|
|
@@ -1761,13 +1175,13 @@ var ZubariWdkService = class {
|
|
|
1761
1175
|
success: false,
|
|
1762
1176
|
error: errorMessage,
|
|
1763
1177
|
errorCode,
|
|
1764
|
-
chain
|
|
1178
|
+
chain
|
|
1765
1179
|
};
|
|
1766
1180
|
} catch (error) {
|
|
1767
1181
|
const elapsed = Date.now() - startTime;
|
|
1768
1182
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
1769
|
-
const errorCode = parseChainError(
|
|
1770
|
-
console.error(`[ZubariWdkService] ${
|
|
1183
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1184
|
+
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
1771
1185
|
error: errorMessage,
|
|
1772
1186
|
errorCode,
|
|
1773
1187
|
elapsed: `${elapsed}ms`
|
|
@@ -1776,15 +1190,15 @@ var ZubariWdkService = class {
|
|
|
1776
1190
|
success: false,
|
|
1777
1191
|
error: errorMessage,
|
|
1778
1192
|
errorCode,
|
|
1779
|
-
chain
|
|
1193
|
+
chain
|
|
1780
1194
|
};
|
|
1781
1195
|
}
|
|
1782
1196
|
}
|
|
1783
1197
|
/**
|
|
1784
1198
|
* Validate transaction hash format for a specific chain
|
|
1785
1199
|
*/
|
|
1786
|
-
validateTxHash(
|
|
1787
|
-
switch (
|
|
1200
|
+
validateTxHash(chain, txHash) {
|
|
1201
|
+
switch (chain) {
|
|
1788
1202
|
case "ethereum":
|
|
1789
1203
|
return /^0x[a-fA-F0-9]{64}$/.test(txHash);
|
|
1790
1204
|
case "bitcoin":
|
|
@@ -1816,7 +1230,7 @@ var ZubariWdkService = class {
|
|
|
1816
1230
|
// ==========================================
|
|
1817
1231
|
// Private Helper Methods
|
|
1818
1232
|
// ==========================================
|
|
1819
|
-
getDerivationPath(
|
|
1233
|
+
getDerivationPath(chain) {
|
|
1820
1234
|
const paths = {
|
|
1821
1235
|
bitcoin: this.config.network === "testnet" ? "m/84'/1'/0'/0/0" : "m/84'/0'/0'/0/0",
|
|
1822
1236
|
ethereum: "m/44'/60'/0'/0/0",
|
|
@@ -1825,9 +1239,9 @@ var ZubariWdkService = class {
|
|
|
1825
1239
|
solana: "m/44'/501'/0'/0'",
|
|
1826
1240
|
spark: "m/44'/998'/0'/0/0"
|
|
1827
1241
|
};
|
|
1828
|
-
return paths[
|
|
1242
|
+
return paths[chain];
|
|
1829
1243
|
}
|
|
1830
|
-
getChainSymbol(
|
|
1244
|
+
getChainSymbol(chain) {
|
|
1831
1245
|
const symbols = {
|
|
1832
1246
|
ethereum: "ETH",
|
|
1833
1247
|
bitcoin: "BTC",
|
|
@@ -1836,16 +1250,16 @@ var ZubariWdkService = class {
|
|
|
1836
1250
|
solana: "SOL",
|
|
1837
1251
|
spark: "SAT"
|
|
1838
1252
|
};
|
|
1839
|
-
return symbols[
|
|
1253
|
+
return symbols[chain];
|
|
1840
1254
|
}
|
|
1841
1255
|
/**
|
|
1842
1256
|
* Derive address using browser-compatible libraries
|
|
1843
1257
|
*/
|
|
1844
|
-
async deriveBrowserAddress(seed,
|
|
1845
|
-
const path = this.getDerivationPath(
|
|
1258
|
+
async deriveBrowserAddress(seed, chain) {
|
|
1259
|
+
const path = this.getDerivationPath(chain);
|
|
1846
1260
|
try {
|
|
1847
1261
|
let address;
|
|
1848
|
-
switch (
|
|
1262
|
+
switch (chain) {
|
|
1849
1263
|
case "ethereum":
|
|
1850
1264
|
address = deriveEthereumAddress(seed);
|
|
1851
1265
|
break;
|
|
@@ -1865,11 +1279,11 @@ var ZubariWdkService = class {
|
|
|
1865
1279
|
address = await deriveTonAddress(seed);
|
|
1866
1280
|
break;
|
|
1867
1281
|
default:
|
|
1868
|
-
throw new Error(`Unsupported chain: ${
|
|
1282
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
1869
1283
|
}
|
|
1870
|
-
return { chain
|
|
1284
|
+
return { chain, address, path };
|
|
1871
1285
|
} catch (error) {
|
|
1872
|
-
console.error(`Browser derivation failed for ${
|
|
1286
|
+
console.error(`Browser derivation failed for ${chain}:`, error);
|
|
1873
1287
|
throw error;
|
|
1874
1288
|
}
|
|
1875
1289
|
}
|
|
@@ -1882,7 +1296,7 @@ var ZubariWdkService = class {
|
|
|
1882
1296
|
};
|
|
1883
1297
|
var defaultService = null;
|
|
1884
1298
|
function getZubariWdkService(config) {
|
|
1885
|
-
if (!defaultService || config && config.network !== defaultService.getNetwork()) {
|
|
1299
|
+
if (!defaultService || config && (config.network !== defaultService.getNetwork() || config.apiUrl && config.apiUrl !== defaultService.getApiUrl())) {
|
|
1886
1300
|
defaultService = new ZubariWdkService(config);
|
|
1887
1301
|
}
|
|
1888
1302
|
return defaultService;
|
|
@@ -1938,12 +1352,12 @@ var ZubariWallet = class {
|
|
|
1938
1352
|
solana: "solana",
|
|
1939
1353
|
spark: "spark"
|
|
1940
1354
|
};
|
|
1941
|
-
const
|
|
1942
|
-
if (!
|
|
1355
|
+
const chain = chainMap[network];
|
|
1356
|
+
if (!chain) {
|
|
1943
1357
|
throw new Error(`Unsupported network: ${network}`);
|
|
1944
1358
|
}
|
|
1945
1359
|
try {
|
|
1946
|
-
const result = await this.wdkService.deriveAddress(this.seed,
|
|
1360
|
+
const result = await this.wdkService.deriveAddress(this.seed, chain);
|
|
1947
1361
|
const account = {
|
|
1948
1362
|
network,
|
|
1949
1363
|
address: result.address,
|
|
@@ -1998,13 +1412,13 @@ var ZubariWallet = class {
|
|
|
1998
1412
|
solana: "solana",
|
|
1999
1413
|
spark: "spark"
|
|
2000
1414
|
};
|
|
2001
|
-
const
|
|
2002
|
-
if (!
|
|
1415
|
+
const chain = chainMap[network];
|
|
1416
|
+
if (!chain) {
|
|
2003
1417
|
throw new Error(`Unsupported network: ${network}`);
|
|
2004
1418
|
}
|
|
2005
1419
|
try {
|
|
2006
1420
|
const balances = await this.wdkService.getAllBalances(this.seed);
|
|
2007
|
-
const chainBalance = balances[
|
|
1421
|
+
const chainBalance = balances[chain];
|
|
2008
1422
|
if (chainBalance) {
|
|
2009
1423
|
const balanceValue = BigInt(chainBalance.balance || "0");
|
|
2010
1424
|
const decimals = networkConfig.nativeCurrency.decimals;
|
|
@@ -2093,14 +1507,14 @@ var ZubariWallet = class {
|
|
|
2093
1507
|
solana: "solana",
|
|
2094
1508
|
spark: "spark"
|
|
2095
1509
|
};
|
|
2096
|
-
const
|
|
2097
|
-
if (!
|
|
1510
|
+
const chain = chainMap[network];
|
|
1511
|
+
if (!chain) {
|
|
2098
1512
|
throw new Error(`Unsupported network: ${network}`);
|
|
2099
1513
|
}
|
|
2100
1514
|
try {
|
|
2101
1515
|
const result = await this.wdkService.sendTransaction(
|
|
2102
1516
|
this.seed,
|
|
2103
|
-
|
|
1517
|
+
chain,
|
|
2104
1518
|
to,
|
|
2105
1519
|
amount.toString()
|
|
2106
1520
|
);
|
|
@@ -2775,8 +2189,8 @@ async function fetchPrices() {
|
|
|
2775
2189
|
if (response.ok) {
|
|
2776
2190
|
const data = await response.json();
|
|
2777
2191
|
const prices = {};
|
|
2778
|
-
for (const [
|
|
2779
|
-
prices[
|
|
2192
|
+
for (const [chain, geckoId] of Object.entries(COINGECKO_IDS)) {
|
|
2193
|
+
prices[chain] = data[geckoId]?.usd || 0;
|
|
2780
2194
|
}
|
|
2781
2195
|
priceCache = { prices, timestamp: Date.now() };
|
|
2782
2196
|
return prices;
|
|
@@ -2786,9 +2200,22 @@ async function fetchPrices() {
|
|
|
2786
2200
|
}
|
|
2787
2201
|
return priceCache?.prices || {};
|
|
2788
2202
|
}
|
|
2789
|
-
async function getPriceForChain(
|
|
2203
|
+
async function getPriceForChain(chain) {
|
|
2790
2204
|
const prices = await fetchPrices();
|
|
2791
|
-
return prices[
|
|
2205
|
+
return prices[chain] || 0;
|
|
2206
|
+
}
|
|
2207
|
+
function tonFriendlyToRaw(addr) {
|
|
2208
|
+
if (addr.includes(":")) return addr;
|
|
2209
|
+
try {
|
|
2210
|
+
const b64 = addr.replace(/-/g, "+").replace(/_/g, "/");
|
|
2211
|
+
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
2212
|
+
if (bytes.length !== 36) return addr;
|
|
2213
|
+
const workchain = bytes[1] === 255 ? -1 : bytes[1];
|
|
2214
|
+
const hash = Array.from(bytes.slice(2, 34)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2215
|
+
return `${workchain}:${hash}`;
|
|
2216
|
+
} catch {
|
|
2217
|
+
return addr;
|
|
2218
|
+
}
|
|
2792
2219
|
}
|
|
2793
2220
|
var STORAGE_KEYS = {
|
|
2794
2221
|
ENCRYPTED_SEED: "encrypted_seed",
|
|
@@ -2994,9 +2421,9 @@ var WalletManager = class _WalletManager {
|
|
|
2994
2421
|
if (!this.derivedAddress) {
|
|
2995
2422
|
throw new Error("Wallet not initialized");
|
|
2996
2423
|
}
|
|
2997
|
-
const
|
|
2424
|
+
const chain = this.config.network === "mainnet" ? chains.mainnet : chains.sepolia;
|
|
2998
2425
|
const client = viem.createPublicClient({
|
|
2999
|
-
chain
|
|
2426
|
+
chain,
|
|
3000
2427
|
transport: viem.http(this.config.rpcUrl, {
|
|
3001
2428
|
timeout: 15e3,
|
|
3002
2429
|
// 15 second timeout
|
|
@@ -3018,9 +2445,9 @@ var WalletManager = class _WalletManager {
|
|
|
3018
2445
|
* Create viem public client for the current network
|
|
3019
2446
|
*/
|
|
3020
2447
|
getPublicClient() {
|
|
3021
|
-
const
|
|
2448
|
+
const chain = this.config.network === "mainnet" ? chains.mainnet : chains.sepolia;
|
|
3022
2449
|
return viem.createPublicClient({
|
|
3023
|
-
chain
|
|
2450
|
+
chain,
|
|
3024
2451
|
transport: viem.http(this.config.rpcUrl, {
|
|
3025
2452
|
timeout: 15e3,
|
|
3026
2453
|
// 15 second timeout
|
|
@@ -3074,11 +2501,11 @@ var WalletManager = class _WalletManager {
|
|
|
3074
2501
|
*
|
|
3075
2502
|
* No fallback to placeholder addresses - WDK API is required for real addresses.
|
|
3076
2503
|
*/
|
|
3077
|
-
static async deriveAddressForChainAsync(seed,
|
|
3078
|
-
if (
|
|
2504
|
+
static async deriveAddressForChainAsync(seed, chain, network = "mainnet", apiUrl) {
|
|
2505
|
+
if (chain === "ethereum") {
|
|
3079
2506
|
try {
|
|
3080
2507
|
const wdkService2 = getZubariWdkService({ network, apiUrl });
|
|
3081
|
-
const result2 = await wdkService2.deriveAddress(seed,
|
|
2508
|
+
const result2 = await wdkService2.deriveAddress(seed, chain);
|
|
3082
2509
|
return result2.address;
|
|
3083
2510
|
} catch (error) {
|
|
3084
2511
|
console.warn("WDK service failed for Ethereum, using local derivation:", error);
|
|
@@ -3086,7 +2513,7 @@ var WalletManager = class _WalletManager {
|
|
|
3086
2513
|
}
|
|
3087
2514
|
}
|
|
3088
2515
|
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
3089
|
-
const result = await wdkService.deriveAddress(seed,
|
|
2516
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
3090
2517
|
return result.address;
|
|
3091
2518
|
}
|
|
3092
2519
|
/**
|
|
@@ -3095,14 +2522,14 @@ var WalletManager = class _WalletManager {
|
|
|
3095
2522
|
*
|
|
3096
2523
|
* @throws Error for non-Ethereum chains - use WDK API instead
|
|
3097
2524
|
*/
|
|
3098
|
-
static deriveAddressForChain(seed,
|
|
3099
|
-
if (
|
|
2525
|
+
static deriveAddressForChain(seed, chain) {
|
|
2526
|
+
if (chain === "ethereum") {
|
|
3100
2527
|
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
3101
2528
|
const ethNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
3102
2529
|
return ethNode.address;
|
|
3103
2530
|
}
|
|
3104
2531
|
throw new Error(
|
|
3105
|
-
`Sync derivation not supported for ${
|
|
2532
|
+
`Sync derivation not supported for ${chain}. Use deriveAddressForChainAsync() with WDK API.`
|
|
3106
2533
|
);
|
|
3107
2534
|
}
|
|
3108
2535
|
/**
|
|
@@ -3134,9 +2561,9 @@ var WalletManager = class _WalletManager {
|
|
|
3134
2561
|
const wdkAddresses = await this.wdkService.deriveAllAddresses(this.currentSeed);
|
|
3135
2562
|
const enabledChainsSet = new Set(this.config.enabledChains);
|
|
3136
2563
|
const addresses = {};
|
|
3137
|
-
for (const [
|
|
3138
|
-
if (enabledChainsSet.has(
|
|
3139
|
-
addresses[
|
|
2564
|
+
for (const [chain, address] of Object.entries(wdkAddresses)) {
|
|
2565
|
+
if (enabledChainsSet.has(chain) && address) {
|
|
2566
|
+
addresses[chain] = address;
|
|
3140
2567
|
}
|
|
3141
2568
|
}
|
|
3142
2569
|
this.derivedAddresses = addresses;
|
|
@@ -3177,10 +2604,10 @@ var WalletManager = class _WalletManager {
|
|
|
3177
2604
|
*/
|
|
3178
2605
|
normalizeAddresses(addresses) {
|
|
3179
2606
|
const normalized = {};
|
|
3180
|
-
for (const [
|
|
2607
|
+
for (const [chain, value] of Object.entries(addresses)) {
|
|
3181
2608
|
const addr = this.normalizeAddress(value);
|
|
3182
2609
|
if (addr) {
|
|
3183
|
-
normalized[
|
|
2610
|
+
normalized[chain] = addr;
|
|
3184
2611
|
}
|
|
3185
2612
|
}
|
|
3186
2613
|
return normalized;
|
|
@@ -3233,20 +2660,20 @@ var WalletManager = class _WalletManager {
|
|
|
3233
2660
|
* Get address for a specific chain
|
|
3234
2661
|
* Returns cached address or null - use deriveAllAddressesAsync to derive addresses
|
|
3235
2662
|
*/
|
|
3236
|
-
getAddressForChain(
|
|
3237
|
-
const cachedValue = this.derivedAddresses[
|
|
2663
|
+
getAddressForChain(chain) {
|
|
2664
|
+
const cachedValue = this.derivedAddresses[chain];
|
|
3238
2665
|
if (cachedValue) {
|
|
3239
|
-
console.log(`[WalletManager] getAddressForChain(${
|
|
2666
|
+
console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
|
|
3240
2667
|
const addr = this.normalizeAddress(cachedValue);
|
|
3241
|
-
console.log(`[WalletManager] getAddressForChain(${
|
|
2668
|
+
console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
|
|
3242
2669
|
if (addr) {
|
|
3243
|
-
this.derivedAddresses[
|
|
2670
|
+
this.derivedAddresses[chain] = addr;
|
|
3244
2671
|
return addr;
|
|
3245
2672
|
}
|
|
3246
2673
|
}
|
|
3247
|
-
if (
|
|
3248
|
-
this.derivedAddresses[
|
|
3249
|
-
return this.derivedAddresses[
|
|
2674
|
+
if (chain === "ethereum" && this.currentSeed) {
|
|
2675
|
+
this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
|
|
2676
|
+
return this.derivedAddresses[chain];
|
|
3250
2677
|
}
|
|
3251
2678
|
return null;
|
|
3252
2679
|
}
|
|
@@ -3259,11 +2686,11 @@ var WalletManager = class _WalletManager {
|
|
|
3259
2686
|
/**
|
|
3260
2687
|
* Set the selected chain
|
|
3261
2688
|
*/
|
|
3262
|
-
setSelectedChain(
|
|
3263
|
-
if (!this.config.enabledChains.includes(
|
|
3264
|
-
throw new Error(`Chain ${
|
|
2689
|
+
setSelectedChain(chain) {
|
|
2690
|
+
if (!this.config.enabledChains.includes(chain)) {
|
|
2691
|
+
throw new Error(`Chain ${chain} is not enabled`);
|
|
3265
2692
|
}
|
|
3266
|
-
this.selectedChain =
|
|
2693
|
+
this.selectedChain = chain;
|
|
3267
2694
|
}
|
|
3268
2695
|
/**
|
|
3269
2696
|
* Get the currently selected chain
|
|
@@ -3280,22 +2707,22 @@ var WalletManager = class _WalletManager {
|
|
|
3280
2707
|
/**
|
|
3281
2708
|
* Get chain configuration
|
|
3282
2709
|
*/
|
|
3283
|
-
getChainConfig(
|
|
3284
|
-
return getNetworkConfig(
|
|
2710
|
+
getChainConfig(chain) {
|
|
2711
|
+
return getNetworkConfig(chain, this.config.network === "testnet");
|
|
3285
2712
|
}
|
|
3286
2713
|
/**
|
|
3287
2714
|
* Fetch balance for a specific chain
|
|
3288
2715
|
* Note: Currently only Ethereum is implemented
|
|
3289
2716
|
*/
|
|
3290
|
-
async fetchBalanceForChain(
|
|
3291
|
-
const address = this.getAddressForChain(
|
|
2717
|
+
async fetchBalanceForChain(chain) {
|
|
2718
|
+
const address = this.getAddressForChain(chain);
|
|
3292
2719
|
if (!address) {
|
|
3293
|
-
throw new Error(`No address for chain ${
|
|
2720
|
+
throw new Error(`No address for chain ${chain}`);
|
|
3294
2721
|
}
|
|
3295
|
-
const networkConfig = this.getChainConfig(
|
|
2722
|
+
const networkConfig = this.getChainConfig(chain);
|
|
3296
2723
|
let balance = "0";
|
|
3297
2724
|
const tokenBalances = {};
|
|
3298
|
-
if (
|
|
2725
|
+
if (chain === "ethereum") {
|
|
3299
2726
|
const viemChain = this.config.network === "mainnet" ? chains.mainnet : chains.sepolia;
|
|
3300
2727
|
const isTestnet2 = this.config.network !== "mainnet";
|
|
3301
2728
|
const client = viem.createPublicClient({
|
|
@@ -3342,7 +2769,7 @@ var WalletManager = class _WalletManager {
|
|
|
3342
2769
|
} else if (usdtResult.status === "rejected") {
|
|
3343
2770
|
console.warn("[WalletManager] Failed to fetch ETH USDT balance:", usdtResult.reason);
|
|
3344
2771
|
}
|
|
3345
|
-
} else if (
|
|
2772
|
+
} else if (chain === "bitcoin") {
|
|
3346
2773
|
const isMainnet2 = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");
|
|
3347
2774
|
const apisToTry = isMainnet2 ? ["https://mempool.space/api"] : [
|
|
3348
2775
|
"https://mempool.space/testnet/api",
|
|
@@ -3374,7 +2801,7 @@ var WalletManager = class _WalletManager {
|
|
|
3374
2801
|
console.warn(`Failed to fetch from ${apiUrl}:`, error);
|
|
3375
2802
|
}
|
|
3376
2803
|
}
|
|
3377
|
-
} else if (
|
|
2804
|
+
} else if (chain === "solana") {
|
|
3378
2805
|
const rpcUrl = this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com";
|
|
3379
2806
|
try {
|
|
3380
2807
|
const response = await fetch(rpcUrl, {
|
|
@@ -3394,7 +2821,7 @@ var WalletManager = class _WalletManager {
|
|
|
3394
2821
|
}
|
|
3395
2822
|
}
|
|
3396
2823
|
} catch (error) {
|
|
3397
|
-
console.warn(`Failed to fetch ${
|
|
2824
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3398
2825
|
}
|
|
3399
2826
|
const isTestnet2 = this.config.network !== "mainnet";
|
|
3400
2827
|
const usdtMint = USDT_ADDRESSES.solana?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
@@ -3428,7 +2855,7 @@ var WalletManager = class _WalletManager {
|
|
|
3428
2855
|
console.warn("Failed to fetch Solana USDT balance:", error);
|
|
3429
2856
|
}
|
|
3430
2857
|
}
|
|
3431
|
-
} else if (
|
|
2858
|
+
} else if (chain === "tron") {
|
|
3432
2859
|
const tronConfig = getNetworkConfig("tron", this.config.network !== "mainnet");
|
|
3433
2860
|
const baseUrl = tronConfig.rpcUrl;
|
|
3434
2861
|
try {
|
|
@@ -3457,9 +2884,9 @@ var WalletManager = class _WalletManager {
|
|
|
3457
2884
|
}
|
|
3458
2885
|
}
|
|
3459
2886
|
} catch (error) {
|
|
3460
|
-
console.warn(`Failed to fetch ${
|
|
2887
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3461
2888
|
}
|
|
3462
|
-
} else if (
|
|
2889
|
+
} else if (chain === "ton") {
|
|
3463
2890
|
const isTestnet2 = this.config.network !== "mainnet";
|
|
3464
2891
|
const baseUrl = isTestnet2 ? "https://testnet.toncenter.com/api/v2" : "https://toncenter.com/api/v2";
|
|
3465
2892
|
try {
|
|
@@ -3475,25 +2902,36 @@ var WalletManager = class _WalletManager {
|
|
|
3475
2902
|
}
|
|
3476
2903
|
}
|
|
3477
2904
|
} catch (error) {
|
|
3478
|
-
console.warn(`Failed to fetch ${
|
|
2905
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3479
2906
|
}
|
|
3480
2907
|
const usdtJetton = USDT_ADDRESSES.ton?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
3481
2908
|
if (usdtJetton) {
|
|
3482
|
-
const
|
|
2909
|
+
const tonapiBaseUrl = isTestnet2 ? "https://testnet.tonapi.io/v2" : "https://tonapi.io/v2";
|
|
3483
2910
|
try {
|
|
2911
|
+
const rawAddr = tonFriendlyToRaw(address);
|
|
3484
2912
|
const jettonResponse = await fetch(
|
|
3485
|
-
`${
|
|
2913
|
+
`${tonapiBaseUrl}/accounts/${encodeURIComponent(rawAddr)}/jettons?currencies=usd`,
|
|
3486
2914
|
{ headers: { "Accept": "application/json" } }
|
|
3487
2915
|
);
|
|
3488
2916
|
if (jettonResponse.ok) {
|
|
3489
2917
|
const jettonData = await jettonResponse.json();
|
|
3490
|
-
const
|
|
3491
|
-
if (
|
|
3492
|
-
const
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
2918
|
+
const balances = jettonData.balances;
|
|
2919
|
+
if (balances && balances.length > 0) {
|
|
2920
|
+
for (const jb of balances) {
|
|
2921
|
+
const jettonAddr = jb.jetton?.address;
|
|
2922
|
+
if (jettonAddr) {
|
|
2923
|
+
const usdtRaw = tonFriendlyToRaw(usdtJetton);
|
|
2924
|
+
if (jettonAddr.toLowerCase() === usdtRaw.toLowerCase()) {
|
|
2925
|
+
const rawBalance = jb.balance;
|
|
2926
|
+
if (rawBalance) {
|
|
2927
|
+
const decimals = jb.jetton?.decimals || 6;
|
|
2928
|
+
const usdtAmount = Number(BigInt(rawBalance)) / Math.pow(10, decimals);
|
|
2929
|
+
if (usdtAmount > 0) {
|
|
2930
|
+
tokenBalances.USDT = { balance: usdtAmount.toFixed(6), balanceUsd: usdtAmount };
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
break;
|
|
2934
|
+
}
|
|
3497
2935
|
}
|
|
3498
2936
|
}
|
|
3499
2937
|
}
|
|
@@ -3502,7 +2940,7 @@ var WalletManager = class _WalletManager {
|
|
|
3502
2940
|
console.warn("Failed to fetch TON USDT jetton balance:", error);
|
|
3503
2941
|
}
|
|
3504
2942
|
}
|
|
3505
|
-
} else if (
|
|
2943
|
+
} else if (chain === "spark") {
|
|
3506
2944
|
try {
|
|
3507
2945
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balance`, {
|
|
3508
2946
|
method: "POST",
|
|
@@ -3521,14 +2959,14 @@ var WalletManager = class _WalletManager {
|
|
|
3521
2959
|
}
|
|
3522
2960
|
}
|
|
3523
2961
|
} catch (error) {
|
|
3524
|
-
console.warn(`Failed to fetch ${
|
|
2962
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3525
2963
|
}
|
|
3526
2964
|
}
|
|
3527
|
-
const priceUsd = await getPriceForChain(
|
|
2965
|
+
const priceUsd = await getPriceForChain(chain);
|
|
3528
2966
|
const balanceNum = parseFloat(balance) || 0;
|
|
3529
2967
|
const balanceUsd = balanceNum * priceUsd;
|
|
3530
2968
|
return {
|
|
3531
|
-
chain
|
|
2969
|
+
chain,
|
|
3532
2970
|
symbol: networkConfig.nativeCurrency.symbol,
|
|
3533
2971
|
balance,
|
|
3534
2972
|
balanceUsd,
|
|
@@ -3542,19 +2980,19 @@ var WalletManager = class _WalletManager {
|
|
|
3542
2980
|
*/
|
|
3543
2981
|
async fetchAllBalances() {
|
|
3544
2982
|
const balances = [];
|
|
3545
|
-
for (const
|
|
2983
|
+
for (const chain of this.config.enabledChains) {
|
|
3546
2984
|
try {
|
|
3547
|
-
const balance = await this.fetchBalanceForChain(
|
|
2985
|
+
const balance = await this.fetchBalanceForChain(chain);
|
|
3548
2986
|
balances.push(balance);
|
|
3549
2987
|
} catch (error) {
|
|
3550
|
-
console.error(`Failed to fetch balance for ${
|
|
3551
|
-
const networkConfig = this.getChainConfig(
|
|
2988
|
+
console.error(`Failed to fetch balance for ${chain}:`, error);
|
|
2989
|
+
const networkConfig = this.getChainConfig(chain);
|
|
3552
2990
|
balances.push({
|
|
3553
|
-
chain
|
|
2991
|
+
chain,
|
|
3554
2992
|
symbol: networkConfig.nativeCurrency.symbol,
|
|
3555
2993
|
balance: "0",
|
|
3556
2994
|
balanceUsd: 0,
|
|
3557
|
-
address: this.getAddressForChain(
|
|
2995
|
+
address: this.getAddressForChain(chain) || "",
|
|
3558
2996
|
decimals: networkConfig.nativeCurrency.decimals
|
|
3559
2997
|
});
|
|
3560
2998
|
}
|
|
@@ -3584,13 +3022,13 @@ var WalletManager = class _WalletManager {
|
|
|
3584
3022
|
* @param token - Optional token symbol (e.g., 'USDT' for stablecoins)
|
|
3585
3023
|
* @returns Transaction result with hash and status
|
|
3586
3024
|
*/
|
|
3587
|
-
async sendTransaction(
|
|
3025
|
+
async sendTransaction(chain, to, amount, token) {
|
|
3588
3026
|
if (!this.currentSeed) {
|
|
3589
3027
|
return { success: false, error: "Wallet is locked" };
|
|
3590
3028
|
}
|
|
3591
|
-
const fromAddress = this.getAddressForChain(
|
|
3029
|
+
const fromAddress = this.getAddressForChain(chain);
|
|
3592
3030
|
if (!fromAddress) {
|
|
3593
|
-
return { success: false, error: `No address for chain ${
|
|
3031
|
+
return { success: false, error: `No address for chain ${chain}` };
|
|
3594
3032
|
}
|
|
3595
3033
|
try {
|
|
3596
3034
|
const headers = {
|
|
@@ -3604,7 +3042,7 @@ var WalletManager = class _WalletManager {
|
|
|
3604
3042
|
headers,
|
|
3605
3043
|
body: JSON.stringify({
|
|
3606
3044
|
seed: this.currentSeed,
|
|
3607
|
-
chain
|
|
3045
|
+
chain,
|
|
3608
3046
|
to,
|
|
3609
3047
|
amount,
|
|
3610
3048
|
token,
|
|
@@ -3613,12 +3051,12 @@ var WalletManager = class _WalletManager {
|
|
|
3613
3051
|
});
|
|
3614
3052
|
if (response.ok) {
|
|
3615
3053
|
const data = await response.json();
|
|
3616
|
-
console.log(`Transaction sent on ${
|
|
3054
|
+
console.log(`Transaction sent on ${chain}:`, data);
|
|
3617
3055
|
let txHash = data.txHash || data.transactionHash || data.hash;
|
|
3618
3056
|
if (txHash && typeof txHash === "object" && "hash" in txHash) {
|
|
3619
3057
|
txHash = txHash.hash;
|
|
3620
3058
|
}
|
|
3621
|
-
if (
|
|
3059
|
+
if (chain === "ethereum" && txHash && (typeof txHash !== "string" || !txHash.startsWith("0x") || txHash.length !== 66)) {
|
|
3622
3060
|
console.warn(`Invalid Ethereum tx hash format: ${txHash} (length: ${txHash?.length}, expected: 66)`);
|
|
3623
3061
|
}
|
|
3624
3062
|
return {
|
|
@@ -3627,7 +3065,7 @@ var WalletManager = class _WalletManager {
|
|
|
3627
3065
|
from: fromAddress,
|
|
3628
3066
|
to,
|
|
3629
3067
|
amount,
|
|
3630
|
-
chain
|
|
3068
|
+
chain
|
|
3631
3069
|
};
|
|
3632
3070
|
}
|
|
3633
3071
|
const errorData = await response.json().catch(() => ({}));
|
|
@@ -3636,7 +3074,7 @@ var WalletManager = class _WalletManager {
|
|
|
3636
3074
|
error: errorData.error || `HTTP ${response.status}`
|
|
3637
3075
|
};
|
|
3638
3076
|
} catch (error) {
|
|
3639
|
-
console.error(`Transaction failed on ${
|
|
3077
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
3640
3078
|
return {
|
|
3641
3079
|
success: false,
|
|
3642
3080
|
error: error instanceof Error ? error.message : "Transaction failed"
|
|
@@ -3646,7 +3084,7 @@ var WalletManager = class _WalletManager {
|
|
|
3646
3084
|
/**
|
|
3647
3085
|
* Estimate transaction fee using Tether WDK
|
|
3648
3086
|
*/
|
|
3649
|
-
async estimateFee(
|
|
3087
|
+
async estimateFee(chain, to, amount, token) {
|
|
3650
3088
|
try {
|
|
3651
3089
|
const headers = {
|
|
3652
3090
|
"Content-Type": "application/json"
|
|
@@ -3658,7 +3096,7 @@ var WalletManager = class _WalletManager {
|
|
|
3658
3096
|
method: "POST",
|
|
3659
3097
|
headers,
|
|
3660
3098
|
body: JSON.stringify({
|
|
3661
|
-
chain
|
|
3099
|
+
chain,
|
|
3662
3100
|
to,
|
|
3663
3101
|
amount,
|
|
3664
3102
|
token,
|
|
@@ -8142,8 +7580,8 @@ async function fetchPrices2() {
|
|
|
8142
7580
|
if (response.ok) {
|
|
8143
7581
|
const data = await response.json();
|
|
8144
7582
|
const prices = {};
|
|
8145
|
-
for (const [
|
|
8146
|
-
prices[
|
|
7583
|
+
for (const [chain, geckoId] of Object.entries(COINGECKO_IDS2)) {
|
|
7584
|
+
prices[chain] = data[geckoId]?.usd || 0;
|
|
8147
7585
|
}
|
|
8148
7586
|
priceCache2 = { prices, timestamp: Date.now() };
|
|
8149
7587
|
return prices;
|
|
@@ -8153,9 +7591,9 @@ async function fetchPrices2() {
|
|
|
8153
7591
|
}
|
|
8154
7592
|
return priceCache2?.prices || {};
|
|
8155
7593
|
}
|
|
8156
|
-
async function getPriceForChain2(
|
|
7594
|
+
async function getPriceForChain2(chain) {
|
|
8157
7595
|
const prices = await fetchPrices2();
|
|
8158
|
-
return prices[
|
|
7596
|
+
return prices[chain] || 0;
|
|
8159
7597
|
}
|
|
8160
7598
|
var dynamicImport2 = new Function("specifier", "return import(specifier)");
|
|
8161
7599
|
async function loadWdkModules() {
|
|
@@ -8245,19 +7683,19 @@ var TransactionService = class {
|
|
|
8245
7683
|
/**
|
|
8246
7684
|
* Get RPC URL for a chain
|
|
8247
7685
|
*/
|
|
8248
|
-
getRpcUrl(
|
|
7686
|
+
getRpcUrl(chain) {
|
|
8249
7687
|
const networkUrls = DEFAULT_RPC_URLS[this.config.network];
|
|
8250
|
-
if (this.config.rpcUrls?.[
|
|
8251
|
-
return this.config.rpcUrls[
|
|
7688
|
+
if (this.config.rpcUrls?.[chain]) {
|
|
7689
|
+
return this.config.rpcUrls[chain];
|
|
8252
7690
|
}
|
|
8253
|
-
return networkUrls[
|
|
7691
|
+
return networkUrls[chain] || "";
|
|
8254
7692
|
}
|
|
8255
7693
|
/**
|
|
8256
7694
|
* Get explorer URL for a transaction
|
|
8257
7695
|
*/
|
|
8258
|
-
getExplorerUrl(
|
|
7696
|
+
getExplorerUrl(chain, txHash) {
|
|
8259
7697
|
const explorers = EXPLORER_URLS[this.config.network];
|
|
8260
|
-
const baseUrl = explorers[
|
|
7698
|
+
const baseUrl = explorers[chain] || "";
|
|
8261
7699
|
return `${baseUrl}${txHash}`;
|
|
8262
7700
|
}
|
|
8263
7701
|
/**
|
|
@@ -8281,27 +7719,27 @@ var TransactionService = class {
|
|
|
8281
7719
|
* Get or create wallet instance for a specific chain
|
|
8282
7720
|
*/
|
|
8283
7721
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8284
|
-
async getWallet(
|
|
7722
|
+
async getWallet(chain) {
|
|
8285
7723
|
if (!this.seed) {
|
|
8286
7724
|
throw new Error("TransactionService not initialized. Call initialize() first.");
|
|
8287
7725
|
}
|
|
8288
|
-
if (this.wallets[
|
|
8289
|
-
return this.wallets[
|
|
7726
|
+
if (this.wallets[chain]) {
|
|
7727
|
+
return this.wallets[chain];
|
|
8290
7728
|
}
|
|
8291
7729
|
const isTestnet2 = this.config.network === "testnet";
|
|
8292
7730
|
try {
|
|
8293
|
-
switch (
|
|
7731
|
+
switch (chain) {
|
|
8294
7732
|
case "ethereum": {
|
|
8295
7733
|
const rpcUrl = this.getRpcUrl("ethereum");
|
|
8296
7734
|
const wallet = new WalletManagerEvm(this.seed, { provider: rpcUrl });
|
|
8297
|
-
this.wallets[
|
|
7735
|
+
this.wallets[chain] = wallet;
|
|
8298
7736
|
return wallet;
|
|
8299
7737
|
}
|
|
8300
7738
|
case "bitcoin": {
|
|
8301
7739
|
const wallet = new WalletManagerBtc(this.seed, {
|
|
8302
7740
|
network: isTestnet2 ? "testnet" : "bitcoin"
|
|
8303
7741
|
});
|
|
8304
|
-
this.wallets[
|
|
7742
|
+
this.wallets[chain] = wallet;
|
|
8305
7743
|
return wallet;
|
|
8306
7744
|
}
|
|
8307
7745
|
case "solana": {
|
|
@@ -8309,7 +7747,7 @@ var TransactionService = class {
|
|
|
8309
7747
|
const wallet = new WalletManagerSolana(this.seed, {
|
|
8310
7748
|
rpcUrl
|
|
8311
7749
|
});
|
|
8312
|
-
this.wallets[
|
|
7750
|
+
this.wallets[chain] = wallet;
|
|
8313
7751
|
return wallet;
|
|
8314
7752
|
}
|
|
8315
7753
|
case "ton": {
|
|
@@ -8317,7 +7755,7 @@ var TransactionService = class {
|
|
|
8317
7755
|
const wallet = new WalletManagerTon(this.seed, {
|
|
8318
7756
|
tonClient: { url }
|
|
8319
7757
|
});
|
|
8320
|
-
this.wallets[
|
|
7758
|
+
this.wallets[chain] = wallet;
|
|
8321
7759
|
return wallet;
|
|
8322
7760
|
}
|
|
8323
7761
|
case "tron": {
|
|
@@ -8325,32 +7763,32 @@ var TransactionService = class {
|
|
|
8325
7763
|
const wallet = new WalletManagerTron(this.seed, {
|
|
8326
7764
|
provider: fullHost
|
|
8327
7765
|
});
|
|
8328
|
-
this.wallets[
|
|
7766
|
+
this.wallets[chain] = wallet;
|
|
8329
7767
|
return wallet;
|
|
8330
7768
|
}
|
|
8331
7769
|
case "spark": {
|
|
8332
7770
|
const wallet = new WalletManagerSpark(this.seed, {
|
|
8333
7771
|
network: isTestnet2 ? "TESTNET" : "MAINNET"
|
|
8334
7772
|
});
|
|
8335
|
-
this.wallets[
|
|
7773
|
+
this.wallets[chain] = wallet;
|
|
8336
7774
|
return wallet;
|
|
8337
7775
|
}
|
|
8338
7776
|
default:
|
|
8339
|
-
throw new Error(`Unsupported chain: ${
|
|
7777
|
+
throw new Error(`Unsupported chain: ${chain}`);
|
|
8340
7778
|
}
|
|
8341
7779
|
} catch (error) {
|
|
8342
|
-
console.error(`Failed to initialize ${
|
|
7780
|
+
console.error(`Failed to initialize ${chain} wallet:`, error);
|
|
8343
7781
|
throw error;
|
|
8344
7782
|
}
|
|
8345
7783
|
}
|
|
8346
7784
|
/**
|
|
8347
7785
|
* Estimate transaction fee
|
|
8348
7786
|
*/
|
|
8349
|
-
async estimateFee(
|
|
8350
|
-
const wallet = await this.getWallet(
|
|
7787
|
+
async estimateFee(chain, params) {
|
|
7788
|
+
const wallet = await this.getWallet(chain);
|
|
8351
7789
|
try {
|
|
8352
7790
|
const feeRates = await wallet.getFeeRates();
|
|
8353
|
-
if (
|
|
7791
|
+
if (chain === "ethereum") {
|
|
8354
7792
|
return {
|
|
8355
7793
|
slow: {
|
|
8356
7794
|
fee: `${feeRates.slow || "0"} Gwei`,
|
|
@@ -8365,7 +7803,7 @@ var TransactionService = class {
|
|
|
8365
7803
|
estimatedTime: "~30 sec"
|
|
8366
7804
|
}
|
|
8367
7805
|
};
|
|
8368
|
-
} else if (
|
|
7806
|
+
} else if (chain === "bitcoin") {
|
|
8369
7807
|
return {
|
|
8370
7808
|
slow: {
|
|
8371
7809
|
fee: `${feeRates.slow || feeRates.low || "0"} sat/vB`,
|
|
@@ -8397,7 +7835,7 @@ var TransactionService = class {
|
|
|
8397
7835
|
};
|
|
8398
7836
|
}
|
|
8399
7837
|
} catch (error) {
|
|
8400
|
-
console.error(`Error estimating fee for ${
|
|
7838
|
+
console.error(`Error estimating fee for ${chain}:`, error);
|
|
8401
7839
|
return {
|
|
8402
7840
|
slow: { fee: "0", estimatedTime: "Unknown" },
|
|
8403
7841
|
medium: { fee: "0", estimatedTime: "Unknown" },
|
|
@@ -8408,8 +7846,8 @@ var TransactionService = class {
|
|
|
8408
7846
|
/**
|
|
8409
7847
|
* Send a transaction
|
|
8410
7848
|
*/
|
|
8411
|
-
async send(
|
|
8412
|
-
const wallet = await this.getWallet(
|
|
7849
|
+
async send(chain, params) {
|
|
7850
|
+
const wallet = await this.getWallet(chain);
|
|
8413
7851
|
const account = await wallet.getAccount(0);
|
|
8414
7852
|
const timestamp = Date.now();
|
|
8415
7853
|
try {
|
|
@@ -8429,17 +7867,17 @@ var TransactionService = class {
|
|
|
8429
7867
|
}
|
|
8430
7868
|
return {
|
|
8431
7869
|
hash: txHash,
|
|
8432
|
-
network:
|
|
7870
|
+
network: chain,
|
|
8433
7871
|
status: "pending",
|
|
8434
|
-
explorerUrl: this.getExplorerUrl(
|
|
7872
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
8435
7873
|
timestamp
|
|
8436
7874
|
};
|
|
8437
7875
|
} catch (error) {
|
|
8438
7876
|
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
8439
|
-
console.error(`Transaction failed on ${
|
|
7877
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
8440
7878
|
return {
|
|
8441
7879
|
hash: "",
|
|
8442
|
-
network:
|
|
7880
|
+
network: chain,
|
|
8443
7881
|
status: "failed",
|
|
8444
7882
|
error: errorMessage,
|
|
8445
7883
|
timestamp
|
|
@@ -8449,27 +7887,27 @@ var TransactionService = class {
|
|
|
8449
7887
|
/**
|
|
8450
7888
|
* Get transaction status
|
|
8451
7889
|
*/
|
|
8452
|
-
async getTransactionStatus(
|
|
8453
|
-
const wallet = await this.getWallet(
|
|
7890
|
+
async getTransactionStatus(chain, txHash) {
|
|
7891
|
+
const wallet = await this.getWallet(chain);
|
|
8454
7892
|
try {
|
|
8455
7893
|
const tx = await wallet.getTransaction(txHash);
|
|
8456
7894
|
return {
|
|
8457
7895
|
hash: txHash,
|
|
8458
|
-
network:
|
|
7896
|
+
network: chain,
|
|
8459
7897
|
status: tx.confirmed ? "confirmed" : "pending",
|
|
8460
7898
|
blockNumber: tx.blockNumber,
|
|
8461
7899
|
gasUsed: tx.gasUsed?.toString(),
|
|
8462
7900
|
fee: tx.fee?.toString(),
|
|
8463
|
-
explorerUrl: this.getExplorerUrl(
|
|
7901
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
8464
7902
|
timestamp: tx.timestamp || Date.now()
|
|
8465
7903
|
};
|
|
8466
7904
|
} catch (error) {
|
|
8467
7905
|
console.error(`Error getting transaction status for ${txHash}:`, error);
|
|
8468
7906
|
return {
|
|
8469
7907
|
hash: txHash,
|
|
8470
|
-
network:
|
|
7908
|
+
network: chain,
|
|
8471
7909
|
status: "pending",
|
|
8472
|
-
explorerUrl: this.getExplorerUrl(
|
|
7910
|
+
explorerUrl: this.getExplorerUrl(chain, txHash),
|
|
8473
7911
|
timestamp: Date.now()
|
|
8474
7912
|
};
|
|
8475
7913
|
}
|
|
@@ -8477,14 +7915,14 @@ var TransactionService = class {
|
|
|
8477
7915
|
/**
|
|
8478
7916
|
* Get transaction history for an address
|
|
8479
7917
|
*/
|
|
8480
|
-
async getTransactionHistory(
|
|
8481
|
-
const wallet = await this.getWallet(
|
|
7918
|
+
async getTransactionHistory(chain, limit = 10) {
|
|
7919
|
+
const wallet = await this.getWallet(chain);
|
|
8482
7920
|
const account = await wallet.getAccount(0);
|
|
8483
7921
|
try {
|
|
8484
7922
|
const history = await account.getTransactions({ limit });
|
|
8485
7923
|
return history.map((tx) => ({
|
|
8486
7924
|
hash: tx.hash || tx.txHash,
|
|
8487
|
-
network:
|
|
7925
|
+
network: chain,
|
|
8488
7926
|
type: tx.type || (tx.from === account.address ? "send" : "receive"),
|
|
8489
7927
|
from: tx.from,
|
|
8490
7928
|
to: tx.to,
|
|
@@ -8496,20 +7934,20 @@ var TransactionService = class {
|
|
|
8496
7934
|
blockNumber: tx.blockNumber
|
|
8497
7935
|
}));
|
|
8498
7936
|
} catch (error) {
|
|
8499
|
-
console.error(`Error getting transaction history for ${
|
|
7937
|
+
console.error(`Error getting transaction history for ${chain}:`, error);
|
|
8500
7938
|
return [];
|
|
8501
7939
|
}
|
|
8502
7940
|
}
|
|
8503
7941
|
/**
|
|
8504
7942
|
* Get balance for a specific chain
|
|
8505
7943
|
*/
|
|
8506
|
-
async getBalance(
|
|
8507
|
-
const wallet = await this.getWallet(
|
|
7944
|
+
async getBalance(chain) {
|
|
7945
|
+
const wallet = await this.getWallet(chain);
|
|
8508
7946
|
const account = await wallet.getAccount(0);
|
|
8509
7947
|
try {
|
|
8510
7948
|
const balance = await account.getBalance();
|
|
8511
7949
|
const balanceStr = balance.toString();
|
|
8512
|
-
const priceUsd = await getPriceForChain2(
|
|
7950
|
+
const priceUsd = await getPriceForChain2(chain);
|
|
8513
7951
|
const balanceNum = parseFloat(balanceStr) || 0;
|
|
8514
7952
|
const balanceUsd = balanceNum * priceUsd;
|
|
8515
7953
|
return {
|
|
@@ -8517,7 +7955,7 @@ var TransactionService = class {
|
|
|
8517
7955
|
balanceUsd
|
|
8518
7956
|
};
|
|
8519
7957
|
} catch (error) {
|
|
8520
|
-
console.error(`Error getting balance for ${
|
|
7958
|
+
console.error(`Error getting balance for ${chain}:`, error);
|
|
8521
7959
|
return { balance: "0", balanceUsd: 0 };
|
|
8522
7960
|
}
|
|
8523
7961
|
}
|
|
@@ -8585,14 +8023,6 @@ function normalizeAddress(address) {
|
|
|
8585
8023
|
}
|
|
8586
8024
|
return address.toLowerCase();
|
|
8587
8025
|
}
|
|
8588
|
-
/*! Bundled license information:
|
|
8589
|
-
|
|
8590
|
-
@scure/base/index.js:
|
|
8591
|
-
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8592
|
-
|
|
8593
|
-
@scure/bip32/index.js:
|
|
8594
|
-
(*! scure-bip32 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
8595
|
-
*/
|
|
8596
8026
|
|
|
8597
8027
|
exports.BrowserAddressDerivation = BrowserAddressDerivation_exports;
|
|
8598
8028
|
exports.CURRENCY_ADDRESSES = CURRENCY_ADDRESSES;
|