@zubari/sdk 0.1.8 → 0.1.10
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-YnFArqAt.d.ts → WalletManager-CkGhJZDo.d.ts} +11 -0
- package/dist/{WalletManager-zKc_xew_.d.mts → WalletManager-UG6taF_0.d.mts} +11 -0
- package/dist/{index-DXTHGOnP.d.mts → index-DS2d6LVD.d.mts} +1 -1
- package/dist/{index-CLssrNf2.d.ts → index-Dk_dYBbp.d.ts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +63 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +63 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +63 -1
- package/dist/react/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 +45 -1
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +45 -1
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1111,7 +1111,8 @@ async function getPriceForChain(chain) {
|
|
|
1111
1111
|
}
|
|
1112
1112
|
var STORAGE_KEYS = {
|
|
1113
1113
|
ENCRYPTED_SEED: "encrypted_seed",
|
|
1114
|
-
ACTIVE_WALLET: "active_wallet"
|
|
1114
|
+
ACTIVE_WALLET: "active_wallet",
|
|
1115
|
+
DERIVED_ADDRESSES: "derived_addresses"
|
|
1115
1116
|
};
|
|
1116
1117
|
var SUPPORTED_CHAINS = ["ethereum", "bitcoin", "ton", "tron", "solana", "spark"];
|
|
1117
1118
|
var WalletManager = class _WalletManager {
|
|
@@ -1252,6 +1253,7 @@ var WalletManager = class _WalletManager {
|
|
|
1252
1253
|
*/
|
|
1253
1254
|
async deleteWallet() {
|
|
1254
1255
|
await this.storage.removeItem(STORAGE_KEYS.ENCRYPTED_SEED);
|
|
1256
|
+
await this.storage.removeItem(STORAGE_KEYS.DERIVED_ADDRESSES);
|
|
1255
1257
|
this.currentSeed = null;
|
|
1256
1258
|
this.derivedAddress = null;
|
|
1257
1259
|
this.derivedAddresses = {};
|
|
@@ -1465,6 +1467,7 @@ var WalletManager = class _WalletManager {
|
|
|
1465
1467
|
* In browser: Uses the backend API (which has Tether WDK)
|
|
1466
1468
|
* In Node.js: Uses native WDK directly
|
|
1467
1469
|
* Returns REAL cryptographically valid addresses for all chains.
|
|
1470
|
+
* Addresses are persisted to storage for future use.
|
|
1468
1471
|
*/
|
|
1469
1472
|
async deriveAllAddressesWithWdk() {
|
|
1470
1473
|
if (!this.currentSeed) {
|
|
@@ -1480,22 +1483,63 @@ var WalletManager = class _WalletManager {
|
|
|
1480
1483
|
}
|
|
1481
1484
|
}
|
|
1482
1485
|
this.derivedAddresses = addresses;
|
|
1486
|
+
await this.saveAddressesToStorage(addresses);
|
|
1483
1487
|
return addresses;
|
|
1484
1488
|
} catch (error) {
|
|
1485
1489
|
console.error("WDK derivation failed:", error);
|
|
1486
1490
|
throw error;
|
|
1487
1491
|
}
|
|
1488
1492
|
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Save derived addresses to storage
|
|
1495
|
+
*/
|
|
1496
|
+
async saveAddressesToStorage(addresses) {
|
|
1497
|
+
try {
|
|
1498
|
+
await this.storage.setItem(STORAGE_KEYS.DERIVED_ADDRESSES, JSON.stringify(addresses));
|
|
1499
|
+
console.log("Saved derived addresses to storage:", Object.keys(addresses));
|
|
1500
|
+
} catch (error) {
|
|
1501
|
+
console.warn("Failed to save addresses to storage:", error);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Load derived addresses from storage
|
|
1506
|
+
*/
|
|
1507
|
+
async loadAddressesFromStorage() {
|
|
1508
|
+
try {
|
|
1509
|
+
const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
|
|
1510
|
+
if (stored) {
|
|
1511
|
+
const addresses = JSON.parse(stored);
|
|
1512
|
+
console.log("Loaded derived addresses from storage:", Object.keys(addresses));
|
|
1513
|
+
return addresses;
|
|
1514
|
+
}
|
|
1515
|
+
} catch (error) {
|
|
1516
|
+
console.warn("Failed to load addresses from storage:", error);
|
|
1517
|
+
}
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1489
1520
|
/**
|
|
1490
1521
|
* Derive addresses for all enabled chains using Tether WDK
|
|
1491
1522
|
* The unified WDK service handles all fallback strategies automatically:
|
|
1492
1523
|
* - Browser: API backend -> Browser derivation
|
|
1493
1524
|
* - Node.js: Native WDK -> API backend -> Browser derivation
|
|
1525
|
+
*
|
|
1526
|
+
* First tries to load from storage to avoid losing real WDK-derived addresses.
|
|
1494
1527
|
*/
|
|
1495
1528
|
async deriveAllAddressesAsync() {
|
|
1496
1529
|
if (!this.currentSeed) {
|
|
1497
1530
|
throw new Error("Wallet is locked");
|
|
1498
1531
|
}
|
|
1532
|
+
const storedAddresses = await this.loadAddressesFromStorage();
|
|
1533
|
+
if (storedAddresses && Object.keys(storedAddresses).length > 1) {
|
|
1534
|
+
const expectedEthAddress = _WalletManager.deriveAddress(this.currentSeed);
|
|
1535
|
+
if (storedAddresses.ethereum === expectedEthAddress) {
|
|
1536
|
+
console.log("Using addresses from storage (verified by Ethereum address)");
|
|
1537
|
+
this.derivedAddresses = storedAddresses;
|
|
1538
|
+
return storedAddresses;
|
|
1539
|
+
} else {
|
|
1540
|
+
console.log("Stored addresses do not match current seed, re-deriving...");
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1499
1543
|
try {
|
|
1500
1544
|
return await this.deriveAllAddressesWithWdk();
|
|
1501
1545
|
} catch (error) {
|
|
@@ -1785,6 +1829,12 @@ function useWalletManager(options = {}) {
|
|
|
1785
1829
|
manager.deriveAllAddresses();
|
|
1786
1830
|
}
|
|
1787
1831
|
updateState();
|
|
1832
|
+
try {
|
|
1833
|
+
const balances = await manager.fetchAllBalances();
|
|
1834
|
+
setChainBalances(balances);
|
|
1835
|
+
} catch (err) {
|
|
1836
|
+
console.warn("Failed to fetch balances after create:", err);
|
|
1837
|
+
}
|
|
1788
1838
|
return result;
|
|
1789
1839
|
} catch (err) {
|
|
1790
1840
|
const message = err instanceof Error ? err.message : "Failed to create wallet";
|
|
@@ -1809,6 +1859,12 @@ function useWalletManager(options = {}) {
|
|
|
1809
1859
|
manager.deriveAllAddresses();
|
|
1810
1860
|
}
|
|
1811
1861
|
updateState();
|
|
1862
|
+
try {
|
|
1863
|
+
const balances = await manager.fetchAllBalances();
|
|
1864
|
+
setChainBalances(balances);
|
|
1865
|
+
} catch (err) {
|
|
1866
|
+
console.warn("Failed to fetch balances after import:", err);
|
|
1867
|
+
}
|
|
1812
1868
|
} catch (err) {
|
|
1813
1869
|
const message = err instanceof Error ? err.message : "Failed to import wallet";
|
|
1814
1870
|
setError(message);
|
|
@@ -1832,6 +1888,12 @@ function useWalletManager(options = {}) {
|
|
|
1832
1888
|
manager.deriveAllAddresses();
|
|
1833
1889
|
}
|
|
1834
1890
|
updateState();
|
|
1891
|
+
try {
|
|
1892
|
+
const balances = await manager.fetchAllBalances();
|
|
1893
|
+
setChainBalances(balances);
|
|
1894
|
+
} catch (err) {
|
|
1895
|
+
console.warn("Failed to fetch balances after unlock:", err);
|
|
1896
|
+
}
|
|
1835
1897
|
} catch (err) {
|
|
1836
1898
|
const message = err instanceof Error ? err.message : "Invalid password";
|
|
1837
1899
|
setError(message);
|