@zubari/sdk 0.1.10 → 0.1.12
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/{WalletManager-CkGhJZDo.d.ts → WalletManager-DLN81Bpl.d.ts} +39 -17
- package/dist/{WalletManager-UG6taF_0.d.mts → WalletManager-DWLhos10.d.mts} +39 -17
- package/dist/{index-DS2d6LVD.d.mts → index-BmBHZP3D.d.mts} +1 -1
- package/dist/{index-Dk_dYBbp.d.ts → index-C47lb49r.d.ts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +172 -99
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +172 -99
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +22 -3
- package/dist/react/index.d.ts +22 -3
- package/dist/react/index.js +172 -99
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +172 -99
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +8 -2
- package/dist/services/index.d.ts +8 -2
- package/dist/services/index.js +20 -4
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +20 -4
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +143 -99
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +143 -99
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -820,7 +820,10 @@ var ZubariWdkService = class {
|
|
|
820
820
|
return isValidSeed(seed);
|
|
821
821
|
}
|
|
822
822
|
/**
|
|
823
|
-
* Derive address for a specific chain
|
|
823
|
+
* Derive address for a specific chain using WDK API
|
|
824
|
+
*
|
|
825
|
+
* For Ethereum, falls back to local derivation if API fails.
|
|
826
|
+
* For other chains, WDK API is required - no placeholder fallback.
|
|
824
827
|
*/
|
|
825
828
|
async deriveAddress(seed, chain) {
|
|
826
829
|
await this.initialize();
|
|
@@ -836,6 +839,9 @@ var ZubariWdkService = class {
|
|
|
836
839
|
}
|
|
837
840
|
} catch (error) {
|
|
838
841
|
console.warn(`API address derivation failed for ${chain}:`, error);
|
|
842
|
+
if (chain === "ethereum") {
|
|
843
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
844
|
+
}
|
|
839
845
|
}
|
|
840
846
|
if (this.useNativeWdk && this.nativeWdkService) {
|
|
841
847
|
try {
|
|
@@ -846,10 +852,18 @@ var ZubariWdkService = class {
|
|
|
846
852
|
console.warn(`Native WDK address derivation failed for ${chain}:`, error);
|
|
847
853
|
}
|
|
848
854
|
}
|
|
849
|
-
|
|
855
|
+
if (chain === "ethereum") {
|
|
856
|
+
return this.deriveBrowserAddress(seed, chain);
|
|
857
|
+
}
|
|
858
|
+
throw new Error(
|
|
859
|
+
`WDK API required for ${chain} address derivation. Ensure the backend is running.`
|
|
860
|
+
);
|
|
850
861
|
}
|
|
851
862
|
/**
|
|
852
|
-
* Derive addresses for all supported chains
|
|
863
|
+
* Derive addresses for all supported chains using WDK API
|
|
864
|
+
*
|
|
865
|
+
* Uses the backend WDK API for real cryptographically valid addresses.
|
|
866
|
+
* No placeholder fallback - WDK API is required for multi-chain addresses.
|
|
853
867
|
*/
|
|
854
868
|
async deriveAllAddresses(seed) {
|
|
855
869
|
await this.initialize();
|
|
@@ -877,7 +891,9 @@ var ZubariWdkService = class {
|
|
|
877
891
|
console.warn("Native WDK multi-chain derivation failed:", error);
|
|
878
892
|
}
|
|
879
893
|
}
|
|
880
|
-
|
|
894
|
+
throw new Error(
|
|
895
|
+
"WDK API required for multi-chain address derivation. Ensure the backend is running."
|
|
896
|
+
);
|
|
881
897
|
}
|
|
882
898
|
/**
|
|
883
899
|
* Get balances for all chains
|
|
@@ -1359,106 +1375,51 @@ var WalletManager = class _WalletManager {
|
|
|
1359
1375
|
* Uses the unified WDK service which:
|
|
1360
1376
|
* - In browser: Calls the backend API (which has Tether WDK)
|
|
1361
1377
|
* - In Node.js: Uses native WDK
|
|
1362
|
-
* - Falls back to browser-compatible derivation if needed
|
|
1363
|
-
*/
|
|
1364
|
-
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
1365
|
-
try {
|
|
1366
|
-
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1367
|
-
const result = await wdkService.deriveAddress(seed, chain);
|
|
1368
|
-
return result.address;
|
|
1369
|
-
} catch (error) {
|
|
1370
|
-
console.warn(`WDK service failed for ${chain}, using local derivation:`, error);
|
|
1371
|
-
}
|
|
1372
|
-
return _WalletManager.deriveAddressForChain(seed, chain);
|
|
1373
|
-
}
|
|
1374
|
-
/**
|
|
1375
|
-
* Format address for non-WDK chains (fallback)
|
|
1376
1378
|
*
|
|
1377
|
-
*
|
|
1378
|
-
* For real blockchain interaction, use the WDK API via deriveAddressForChainAsync().
|
|
1379
|
-
* These addresses should NOT be used for receiving funds without verification.
|
|
1379
|
+
* No fallback to placeholder addresses - WDK API is required for real addresses.
|
|
1380
1380
|
*/
|
|
1381
|
-
static
|
|
1381
|
+
static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
|
|
1382
1382
|
if (chain === "ethereum") {
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
for (let i = 0; i < 38; i++) {
|
|
1391
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % btcChars.length;
|
|
1392
|
-
btcAddr += btcChars[idx];
|
|
1393
|
-
}
|
|
1394
|
-
return btcAddr;
|
|
1395
|
-
}
|
|
1396
|
-
case "ton": {
|
|
1397
|
-
const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
1398
|
-
let tonAddr = "EQ";
|
|
1399
|
-
for (let i = 0; i < 46; i++) {
|
|
1400
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 4 % base64Chars.length;
|
|
1401
|
-
tonAddr += base64Chars[idx];
|
|
1402
|
-
}
|
|
1403
|
-
return tonAddr;
|
|
1404
|
-
}
|
|
1405
|
-
case "tron": {
|
|
1406
|
-
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1407
|
-
let tronAddr = "T";
|
|
1408
|
-
for (let i = 0; i < 33; i++) {
|
|
1409
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
|
|
1410
|
-
tronAddr += base58Chars[idx];
|
|
1411
|
-
}
|
|
1412
|
-
return tronAddr;
|
|
1413
|
-
}
|
|
1414
|
-
case "solana": {
|
|
1415
|
-
const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
1416
|
-
let solAddr = "";
|
|
1417
|
-
for (let i = 0; i < 44; i++) {
|
|
1418
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
|
|
1419
|
-
solAddr += base58Chars[idx];
|
|
1420
|
-
}
|
|
1421
|
-
return solAddr;
|
|
1422
|
-
}
|
|
1423
|
-
case "spark": {
|
|
1424
|
-
const bech32Chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
1425
|
-
let sparkAddr = "sp1q";
|
|
1426
|
-
for (let i = 0; i < 58; i++) {
|
|
1427
|
-
const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % bech32Chars.length;
|
|
1428
|
-
sparkAddr += bech32Chars[idx];
|
|
1429
|
-
}
|
|
1430
|
-
return sparkAddr;
|
|
1383
|
+
try {
|
|
1384
|
+
const wdkService2 = getZubariWdkService({ network, apiUrl });
|
|
1385
|
+
const result2 = await wdkService2.deriveAddress(seed, chain);
|
|
1386
|
+
return result2.address;
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
console.warn("WDK service failed for Ethereum, using local derivation:", error);
|
|
1389
|
+
return _WalletManager.deriveAddressForChain(seed, "ethereum");
|
|
1431
1390
|
}
|
|
1432
|
-
default:
|
|
1433
|
-
return address;
|
|
1434
1391
|
}
|
|
1392
|
+
const wdkService = getZubariWdkService({ network, apiUrl });
|
|
1393
|
+
const result = await wdkService.deriveAddress(seed, chain);
|
|
1394
|
+
return result.address;
|
|
1435
1395
|
}
|
|
1436
1396
|
/**
|
|
1437
|
-
* Derive address for a specific chain (sync version
|
|
1438
|
-
*
|
|
1397
|
+
* Derive address for a specific chain (sync version)
|
|
1398
|
+
* Only supports Ethereum - for other chains use deriveAddressForChainAsync with WDK API
|
|
1439
1399
|
*
|
|
1440
|
-
*
|
|
1441
|
-
* deterministic but not cryptographically valid. Use WDK API for real addresses.
|
|
1400
|
+
* @throws Error for non-Ethereum chains - use WDK API instead
|
|
1442
1401
|
*/
|
|
1443
1402
|
static deriveAddressForChain(seed, chain) {
|
|
1444
|
-
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
1445
|
-
const ethNode = HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
1446
1403
|
if (chain === "ethereum") {
|
|
1404
|
+
const ethPath = DERIVATION_PATHS["ethereum"];
|
|
1405
|
+
const ethNode = HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
|
|
1447
1406
|
return ethNode.address;
|
|
1448
1407
|
}
|
|
1449
|
-
|
|
1408
|
+
throw new Error(
|
|
1409
|
+
`Sync derivation not supported for ${chain}. Use deriveAddressForChainAsync() with WDK API.`
|
|
1410
|
+
);
|
|
1450
1411
|
}
|
|
1451
1412
|
/**
|
|
1452
1413
|
* Derive addresses for all enabled chains (sync version)
|
|
1414
|
+
* Only derives Ethereum address synchronously - use deriveAllAddressesAsync for all chains
|
|
1453
1415
|
*/
|
|
1454
1416
|
deriveAllAddresses() {
|
|
1455
1417
|
if (!this.currentSeed) {
|
|
1456
1418
|
throw new Error("Wallet is locked");
|
|
1457
1419
|
}
|
|
1458
|
-
const addresses = {
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1420
|
+
const addresses = {
|
|
1421
|
+
ethereum: _WalletManager.deriveAddressForChain(this.currentSeed, "ethereum")
|
|
1422
|
+
};
|
|
1462
1423
|
this.derivedAddresses = addresses;
|
|
1463
1424
|
return addresses;
|
|
1464
1425
|
}
|
|
@@ -1519,11 +1480,11 @@ var WalletManager = class _WalletManager {
|
|
|
1519
1480
|
}
|
|
1520
1481
|
/**
|
|
1521
1482
|
* Derive addresses for all enabled chains using Tether WDK
|
|
1522
|
-
* The unified WDK service handles all fallback strategies automatically:
|
|
1523
|
-
* - Browser: API backend -> Browser derivation
|
|
1524
|
-
* - Node.js: Native WDK -> API backend -> Browser derivation
|
|
1525
1483
|
*
|
|
1526
|
-
*
|
|
1484
|
+
* Uses the WDK API backend for real cryptographically valid addresses.
|
|
1485
|
+
* First tries to load from storage to avoid losing previously derived addresses.
|
|
1486
|
+
*
|
|
1487
|
+
* @throws Error if WDK API is unavailable and no cached addresses exist
|
|
1527
1488
|
*/
|
|
1528
1489
|
async deriveAllAddressesAsync() {
|
|
1529
1490
|
if (!this.currentSeed) {
|
|
@@ -1540,26 +1501,21 @@ var WalletManager = class _WalletManager {
|
|
|
1540
1501
|
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
1541
1502
|
}
|
|
1542
1503
|
}
|
|
1543
|
-
|
|
1544
|
-
return await this.deriveAllAddressesWithWdk();
|
|
1545
|
-
} catch (error) {
|
|
1546
|
-
console.error("All derivation strategies failed:", error);
|
|
1547
|
-
const ethAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
1548
|
-
this.derivedAddresses = { ethereum: ethAddress };
|
|
1549
|
-
return this.derivedAddresses;
|
|
1550
|
-
}
|
|
1504
|
+
return await this.deriveAllAddressesWithWdk();
|
|
1551
1505
|
}
|
|
1552
1506
|
/**
|
|
1553
1507
|
* Get address for a specific chain
|
|
1508
|
+
* Returns cached address or null - use deriveAllAddressesAsync to derive addresses
|
|
1554
1509
|
*/
|
|
1555
1510
|
getAddressForChain(chain) {
|
|
1556
|
-
if (
|
|
1557
|
-
return this.derivedAddresses[chain]
|
|
1511
|
+
if (this.derivedAddresses[chain]) {
|
|
1512
|
+
return this.derivedAddresses[chain];
|
|
1558
1513
|
}
|
|
1559
|
-
if (
|
|
1514
|
+
if (chain === "ethereum" && this.currentSeed) {
|
|
1560
1515
|
this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
|
|
1516
|
+
return this.derivedAddresses[chain];
|
|
1561
1517
|
}
|
|
1562
|
-
return
|
|
1518
|
+
return null;
|
|
1563
1519
|
}
|
|
1564
1520
|
/**
|
|
1565
1521
|
* Get all derived addresses
|
|
@@ -1781,6 +1737,94 @@ var WalletManager = class _WalletManager {
|
|
|
1781
1737
|
selectedChain: this.selectedChain
|
|
1782
1738
|
};
|
|
1783
1739
|
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Send a transaction using Tether WDK
|
|
1742
|
+
* Supports native tokens and USDT on all chains
|
|
1743
|
+
*
|
|
1744
|
+
* @param chain - Target blockchain (ethereum, bitcoin, ton, tron, solana, spark)
|
|
1745
|
+
* @param to - Recipient address
|
|
1746
|
+
* @param amount - Amount to send (in human-readable format)
|
|
1747
|
+
* @param token - Optional token symbol (e.g., 'USDT' for stablecoins)
|
|
1748
|
+
* @returns Transaction result with hash and status
|
|
1749
|
+
*/
|
|
1750
|
+
async sendTransaction(chain, to, amount, token) {
|
|
1751
|
+
if (!this.currentSeed) {
|
|
1752
|
+
return { success: false, error: "Wallet is locked" };
|
|
1753
|
+
}
|
|
1754
|
+
const fromAddress = this.getAddressForChain(chain);
|
|
1755
|
+
if (!fromAddress) {
|
|
1756
|
+
return { success: false, error: `No address for chain ${chain}` };
|
|
1757
|
+
}
|
|
1758
|
+
try {
|
|
1759
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1760
|
+
method: "POST",
|
|
1761
|
+
headers: { "Content-Type": "application/json" },
|
|
1762
|
+
body: JSON.stringify({
|
|
1763
|
+
seed: this.currentSeed,
|
|
1764
|
+
chain,
|
|
1765
|
+
to,
|
|
1766
|
+
amount,
|
|
1767
|
+
token,
|
|
1768
|
+
network: this.config.network
|
|
1769
|
+
})
|
|
1770
|
+
});
|
|
1771
|
+
if (response.ok) {
|
|
1772
|
+
const data = await response.json();
|
|
1773
|
+
console.log(`Transaction sent on ${chain}:`, data);
|
|
1774
|
+
return {
|
|
1775
|
+
success: data.success,
|
|
1776
|
+
txHash: data.txHash,
|
|
1777
|
+
from: fromAddress,
|
|
1778
|
+
to,
|
|
1779
|
+
amount,
|
|
1780
|
+
chain
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
const errorData = await response.json().catch(() => ({}));
|
|
1784
|
+
return {
|
|
1785
|
+
success: false,
|
|
1786
|
+
error: errorData.error || `HTTP ${response.status}`
|
|
1787
|
+
};
|
|
1788
|
+
} catch (error) {
|
|
1789
|
+
console.error(`Transaction failed on ${chain}:`, error);
|
|
1790
|
+
return {
|
|
1791
|
+
success: false,
|
|
1792
|
+
error: error instanceof Error ? error.message : "Transaction failed"
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
/**
|
|
1797
|
+
* Estimate transaction fee using Tether WDK
|
|
1798
|
+
*/
|
|
1799
|
+
async estimateFee(chain, to, amount, token) {
|
|
1800
|
+
try {
|
|
1801
|
+
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/estimate-fee`, {
|
|
1802
|
+
method: "POST",
|
|
1803
|
+
headers: { "Content-Type": "application/json" },
|
|
1804
|
+
body: JSON.stringify({
|
|
1805
|
+
chain,
|
|
1806
|
+
to,
|
|
1807
|
+
amount,
|
|
1808
|
+
token,
|
|
1809
|
+
network: this.config.network
|
|
1810
|
+
})
|
|
1811
|
+
});
|
|
1812
|
+
if (response.ok) {
|
|
1813
|
+
const data = await response.json();
|
|
1814
|
+
return {
|
|
1815
|
+
success: true,
|
|
1816
|
+
fee: data.fee,
|
|
1817
|
+
feeUsd: data.feeUsd
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
return { success: false, error: "Failed to estimate fee" };
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
return {
|
|
1823
|
+
success: false,
|
|
1824
|
+
error: error instanceof Error ? error.message : "Fee estimation failed"
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1784
1828
|
};
|
|
1785
1829
|
|
|
1786
1830
|
// src/react/useWalletManager.ts
|
|
@@ -1970,6 +2014,32 @@ function useWalletManager(options = {}) {
|
|
|
1970
2014
|
);
|
|
1971
2015
|
const hasWallet = useCallback(() => manager.hasWallet(), [manager]);
|
|
1972
2016
|
const getSeed = useCallback(() => manager.getSeed(), [manager]);
|
|
2017
|
+
const sendTransaction = useCallback(
|
|
2018
|
+
async (chain, to, amount, token) => {
|
|
2019
|
+
setIsLoading(true);
|
|
2020
|
+
try {
|
|
2021
|
+
const result = await manager.sendTransaction(chain, to, amount, token);
|
|
2022
|
+
if (result.success) {
|
|
2023
|
+
try {
|
|
2024
|
+
const balances = await manager.fetchAllBalances();
|
|
2025
|
+
setChainBalances(balances);
|
|
2026
|
+
} catch (err) {
|
|
2027
|
+
console.warn("Failed to refresh balances after transaction:", err);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
return result;
|
|
2031
|
+
} finally {
|
|
2032
|
+
setIsLoading(false);
|
|
2033
|
+
}
|
|
2034
|
+
},
|
|
2035
|
+
[manager]
|
|
2036
|
+
);
|
|
2037
|
+
const estimateFee = useCallback(
|
|
2038
|
+
async (chain, to, amount, token) => {
|
|
2039
|
+
return manager.estimateFee(chain, to, amount, token);
|
|
2040
|
+
},
|
|
2041
|
+
[manager]
|
|
2042
|
+
);
|
|
1973
2043
|
return {
|
|
1974
2044
|
state,
|
|
1975
2045
|
isLoading,
|
|
@@ -1988,6 +2058,9 @@ function useWalletManager(options = {}) {
|
|
|
1988
2058
|
getAddressForChain,
|
|
1989
2059
|
getAllAddresses,
|
|
1990
2060
|
supportedChains: SUPPORTED_CHAINS,
|
|
2061
|
+
// Transaction Actions (Powered by Tether WDK)
|
|
2062
|
+
sendTransaction,
|
|
2063
|
+
estimateFee,
|
|
1991
2064
|
// Utilities
|
|
1992
2065
|
hasWallet,
|
|
1993
2066
|
getSeed,
|