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