@enclave-hq/wallet-sdk 1.1.3 → 1.1.5
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.d.mts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +132 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -33
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +7 -2
- package/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +158 -36
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +158 -36
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.mjs
CHANGED
|
@@ -150,6 +150,17 @@ var WalletAdapter = class extends EventEmitter {
|
|
|
150
150
|
this.state = "disconnected" /* DISCONNECTED */;
|
|
151
151
|
this.currentAccount = null;
|
|
152
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Get the signer's address (implements ISigner interface)
|
|
155
|
+
* Returns the native address of the current account
|
|
156
|
+
*/
|
|
157
|
+
async getAddress() {
|
|
158
|
+
this.ensureConnected();
|
|
159
|
+
if (!this.currentAccount) {
|
|
160
|
+
throw new WalletNotConnectedError(this.type);
|
|
161
|
+
}
|
|
162
|
+
return this.currentAccount.nativeAddress;
|
|
163
|
+
}
|
|
153
164
|
signTransaction(_transaction) {
|
|
154
165
|
throw new MethodNotSupportedError("signTransaction", this.type);
|
|
155
166
|
}
|
|
@@ -1564,9 +1575,6 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1564
1575
|
walletConnectProjectId: config.walletConnectProjectId ?? ""
|
|
1565
1576
|
};
|
|
1566
1577
|
this.registry = new AdapterRegistry();
|
|
1567
|
-
if (this.config.enableStorage) {
|
|
1568
|
-
this.restoreFromStorage();
|
|
1569
|
-
}
|
|
1570
1578
|
}
|
|
1571
1579
|
// ===== Connection Management =====
|
|
1572
1580
|
/**
|
|
@@ -1677,13 +1685,13 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1677
1685
|
return adapter.currentAccount;
|
|
1678
1686
|
}
|
|
1679
1687
|
/**
|
|
1680
|
-
*
|
|
1688
|
+
* Get primary wallet account
|
|
1681
1689
|
*/
|
|
1682
1690
|
getPrimaryAccount() {
|
|
1683
1691
|
return this.primaryWallet?.currentAccount || null;
|
|
1684
1692
|
}
|
|
1685
1693
|
/**
|
|
1686
|
-
*
|
|
1694
|
+
* Get all connected wallets
|
|
1687
1695
|
*/
|
|
1688
1696
|
getConnectedWallets() {
|
|
1689
1697
|
return Array.from(this.connectedWallets.values()).map((adapter) => ({
|
|
@@ -1696,14 +1704,14 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1696
1704
|
}));
|
|
1697
1705
|
}
|
|
1698
1706
|
/**
|
|
1699
|
-
*
|
|
1707
|
+
* Get wallet by chain type
|
|
1700
1708
|
*/
|
|
1701
1709
|
getWalletByChainType(chainType) {
|
|
1702
1710
|
return this.connectedWallets.get(chainType) || null;
|
|
1703
1711
|
}
|
|
1704
|
-
// =====
|
|
1712
|
+
// ===== Signing =====
|
|
1705
1713
|
/**
|
|
1706
|
-
*
|
|
1714
|
+
* Sign message with primary wallet
|
|
1707
1715
|
*/
|
|
1708
1716
|
async signMessage(message) {
|
|
1709
1717
|
if (!this.primaryWallet) {
|
|
@@ -1712,7 +1720,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1712
1720
|
return this.primaryWallet.signMessage(message);
|
|
1713
1721
|
}
|
|
1714
1722
|
/**
|
|
1715
|
-
*
|
|
1723
|
+
* Sign message with wallet of specified chain type
|
|
1716
1724
|
*/
|
|
1717
1725
|
async signMessageWithChainType(message, chainType) {
|
|
1718
1726
|
if (!chainType) {
|
|
@@ -1725,7 +1733,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1725
1733
|
return adapter.signMessage(message);
|
|
1726
1734
|
}
|
|
1727
1735
|
/**
|
|
1728
|
-
*
|
|
1736
|
+
* Sign TypedData (EVM only)
|
|
1729
1737
|
*/
|
|
1730
1738
|
async signTypedData(typedData, chainType) {
|
|
1731
1739
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1738,7 +1746,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1738
1746
|
return adapter.signTypedData(typedData);
|
|
1739
1747
|
}
|
|
1740
1748
|
/**
|
|
1741
|
-
*
|
|
1749
|
+
* Sign transaction (with primary wallet)
|
|
1742
1750
|
*/
|
|
1743
1751
|
async signTransaction(transaction) {
|
|
1744
1752
|
if (!this.primaryWallet) {
|
|
@@ -1750,7 +1758,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1750
1758
|
return this.primaryWallet.signTransaction(transaction);
|
|
1751
1759
|
}
|
|
1752
1760
|
/**
|
|
1753
|
-
*
|
|
1761
|
+
* Sign transaction with wallet of specified chain type
|
|
1754
1762
|
*/
|
|
1755
1763
|
async signTransactionWithChainType(transaction, chainType) {
|
|
1756
1764
|
if (!chainType) {
|
|
@@ -1765,9 +1773,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1765
1773
|
}
|
|
1766
1774
|
return adapter.signTransaction(transaction);
|
|
1767
1775
|
}
|
|
1768
|
-
// =====
|
|
1776
|
+
// ===== Chain Switching =====
|
|
1769
1777
|
/**
|
|
1770
|
-
*
|
|
1778
|
+
* Request chain switch (EVM only)
|
|
1771
1779
|
*/
|
|
1772
1780
|
async requestSwitchChain(chainId, options) {
|
|
1773
1781
|
if (!this.primaryWallet) {
|
|
@@ -1788,9 +1796,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1788
1796
|
throw error;
|
|
1789
1797
|
}
|
|
1790
1798
|
}
|
|
1791
|
-
// =====
|
|
1799
|
+
// ===== Contract Calls =====
|
|
1792
1800
|
/**
|
|
1793
|
-
*
|
|
1801
|
+
* Read contract
|
|
1794
1802
|
*/
|
|
1795
1803
|
async readContract(address, abi, functionName, args, chainType) {
|
|
1796
1804
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1803,7 +1811,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1803
1811
|
return adapter.readContract({ address, abi, functionName, args });
|
|
1804
1812
|
}
|
|
1805
1813
|
/**
|
|
1806
|
-
*
|
|
1814
|
+
* Write contract
|
|
1807
1815
|
*/
|
|
1808
1816
|
async writeContract(address, abi, functionName, args, options, chainType) {
|
|
1809
1817
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1822,7 +1830,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1822
1830
|
});
|
|
1823
1831
|
}
|
|
1824
1832
|
/**
|
|
1825
|
-
*
|
|
1833
|
+
* Estimate gas
|
|
1826
1834
|
*/
|
|
1827
1835
|
async estimateGas(address, abi, functionName, args, chainType) {
|
|
1828
1836
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1835,7 +1843,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1835
1843
|
return adapter.estimateGas({ address, abi, functionName, args });
|
|
1836
1844
|
}
|
|
1837
1845
|
/**
|
|
1838
|
-
*
|
|
1846
|
+
* Wait for transaction confirmation
|
|
1839
1847
|
*/
|
|
1840
1848
|
async waitForTransaction(txHash, confirmations, chainType) {
|
|
1841
1849
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1847,9 +1855,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1847
1855
|
}
|
|
1848
1856
|
return adapter.waitForTransaction(txHash, confirmations);
|
|
1849
1857
|
}
|
|
1850
|
-
// ===== Provider
|
|
1858
|
+
// ===== Provider Access =====
|
|
1851
1859
|
/**
|
|
1852
|
-
*
|
|
1860
|
+
* Get primary wallet Provider
|
|
1853
1861
|
*/
|
|
1854
1862
|
getProvider() {
|
|
1855
1863
|
if (!this.primaryWallet) {
|
|
@@ -1858,7 +1866,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1858
1866
|
return this.primaryWallet.getProvider();
|
|
1859
1867
|
}
|
|
1860
1868
|
/**
|
|
1861
|
-
*
|
|
1869
|
+
* Get Provider by chain type
|
|
1862
1870
|
*/
|
|
1863
1871
|
getProviderByChainType(chainType) {
|
|
1864
1872
|
const adapter = this.connectedWallets.get(chainType);
|
|
@@ -1867,21 +1875,21 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1867
1875
|
}
|
|
1868
1876
|
return adapter.getProvider();
|
|
1869
1877
|
}
|
|
1870
|
-
// =====
|
|
1878
|
+
// ===== Private Methods =====
|
|
1871
1879
|
/**
|
|
1872
|
-
*
|
|
1880
|
+
* Set primary wallet
|
|
1873
1881
|
*/
|
|
1874
1882
|
setPrimaryWallet(adapter) {
|
|
1875
1883
|
this.primaryWallet = adapter;
|
|
1876
1884
|
}
|
|
1877
1885
|
/**
|
|
1878
|
-
*
|
|
1886
|
+
* Check if wallet supports chain switching
|
|
1879
1887
|
*/
|
|
1880
1888
|
canSwitchChain(adapter) {
|
|
1881
1889
|
return !!adapter.switchChain;
|
|
1882
1890
|
}
|
|
1883
1891
|
/**
|
|
1884
|
-
*
|
|
1892
|
+
* Setup adapter event listeners
|
|
1885
1893
|
*/
|
|
1886
1894
|
setupAdapterListeners(adapter, isPrimary) {
|
|
1887
1895
|
adapter.on("accountChanged", (account) => {
|
|
@@ -1922,15 +1930,15 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1922
1930
|
});
|
|
1923
1931
|
}
|
|
1924
1932
|
/**
|
|
1925
|
-
*
|
|
1933
|
+
* Remove adapter event listeners
|
|
1926
1934
|
*/
|
|
1927
1935
|
removeAdapterListeners(adapter) {
|
|
1928
1936
|
if (!adapter) return;
|
|
1929
1937
|
adapter.removeAllListeners();
|
|
1930
1938
|
}
|
|
1931
|
-
// =====
|
|
1939
|
+
// ===== Storage =====
|
|
1932
1940
|
/**
|
|
1933
|
-
*
|
|
1941
|
+
* Save to storage
|
|
1934
1942
|
*/
|
|
1935
1943
|
saveToStorage() {
|
|
1936
1944
|
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
@@ -1938,6 +1946,8 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1938
1946
|
}
|
|
1939
1947
|
const data = {
|
|
1940
1948
|
current: this.primaryWallet?.currentAccount?.universalAddress || null,
|
|
1949
|
+
primaryWalletType: this.primaryWallet?.type,
|
|
1950
|
+
primaryChainId: this.primaryWallet?.currentAccount?.chainId,
|
|
1941
1951
|
history: this.getHistoryRecords()
|
|
1942
1952
|
};
|
|
1943
1953
|
try {
|
|
@@ -1950,12 +1960,101 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1950
1960
|
}
|
|
1951
1961
|
}
|
|
1952
1962
|
/**
|
|
1953
|
-
*
|
|
1963
|
+
* Restore from storage
|
|
1964
|
+
* Returns a Promise that can be used for auto-reconnection
|
|
1954
1965
|
*/
|
|
1955
|
-
restoreFromStorage() {
|
|
1966
|
+
async restoreFromStorage() {
|
|
1967
|
+
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
1968
|
+
return null;
|
|
1969
|
+
}
|
|
1970
|
+
try {
|
|
1971
|
+
const stored = localStorage.getItem(`${this.config.storagePrefix}data`);
|
|
1972
|
+
if (!stored) {
|
|
1973
|
+
console.debug("[WalletManager] No stored wallet data found");
|
|
1974
|
+
return null;
|
|
1975
|
+
}
|
|
1976
|
+
const data = JSON.parse(stored);
|
|
1977
|
+
console.debug("[WalletManager] Restoring from storage:", data);
|
|
1978
|
+
if (!data.primaryWalletType || !data.current) {
|
|
1979
|
+
console.debug("[WalletManager] Missing primary wallet info in storage");
|
|
1980
|
+
return null;
|
|
1981
|
+
}
|
|
1982
|
+
const adapter = this.registry.getAdapter(data.primaryWalletType);
|
|
1983
|
+
if (!adapter) {
|
|
1984
|
+
console.debug("[WalletManager] Adapter not found for type:", data.primaryWalletType);
|
|
1985
|
+
return null;
|
|
1986
|
+
}
|
|
1987
|
+
const isAvailable = await adapter.isAvailable();
|
|
1988
|
+
if (!isAvailable) {
|
|
1989
|
+
console.debug("[WalletManager] Wallet not available:", data.primaryWalletType);
|
|
1990
|
+
return null;
|
|
1991
|
+
}
|
|
1992
|
+
console.debug("[WalletManager] Wallet is available, attempting restoration");
|
|
1993
|
+
if (adapter.chainType === ChainType.EVM && data.primaryWalletType === "metamask" /* METAMASK */) {
|
|
1994
|
+
try {
|
|
1995
|
+
const provider = typeof window !== "undefined" ? window.ethereum : null;
|
|
1996
|
+
if (provider) {
|
|
1997
|
+
const accounts = await provider.request({
|
|
1998
|
+
method: "eth_accounts"
|
|
1999
|
+
});
|
|
2000
|
+
console.debug("[WalletManager] Checking authorized accounts:", accounts);
|
|
2001
|
+
if (accounts && accounts.length > 0) {
|
|
2002
|
+
const savedAddress = data.current.split(":")[1];
|
|
2003
|
+
const currentAddress = accounts[0].toLowerCase();
|
|
2004
|
+
console.debug("[WalletManager] Comparing addresses - saved:", savedAddress, "current:", currentAddress);
|
|
2005
|
+
if (currentAddress === savedAddress.toLowerCase()) {
|
|
2006
|
+
console.debug("[WalletManager] Address matches, attempting connect (should be silent if already authorized)");
|
|
2007
|
+
try {
|
|
2008
|
+
const account2 = await adapter.connect(data.primaryChainId);
|
|
2009
|
+
this.setPrimaryWallet(adapter);
|
|
2010
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2011
|
+
this.setupAdapterListeners(adapter, true);
|
|
2012
|
+
this.emit("accountChanged", account2);
|
|
2013
|
+
console.debug("[WalletManager] Connect successful");
|
|
2014
|
+
return account2;
|
|
2015
|
+
} catch (connectError) {
|
|
2016
|
+
console.debug("[WalletManager] Connect failed (might be user rejection):", connectError?.message);
|
|
2017
|
+
return null;
|
|
2018
|
+
}
|
|
2019
|
+
} else {
|
|
2020
|
+
console.debug("[WalletManager] Address mismatch, will try normal connect");
|
|
2021
|
+
}
|
|
2022
|
+
} else {
|
|
2023
|
+
console.debug("[WalletManager] No authorized accounts found");
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
} catch (silentError) {
|
|
2027
|
+
console.debug("Silent connection failed, trying normal connection:", silentError);
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
if (adapter.chainType === ChainType.TRON && data.primaryWalletType === "tronlink" /* TRONLINK */) {
|
|
2031
|
+
try {
|
|
2032
|
+
const tronWeb = adapter.getTronWeb?.();
|
|
2033
|
+
if (tronWeb && tronWeb.defaultAddress?.base58) {
|
|
2034
|
+
const account2 = await adapter.connect(data.primaryChainId);
|
|
2035
|
+
this.setPrimaryWallet(adapter);
|
|
2036
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2037
|
+
this.setupAdapterListeners(adapter, true);
|
|
2038
|
+
this.emit("accountChanged", account2);
|
|
2039
|
+
return account2;
|
|
2040
|
+
}
|
|
2041
|
+
} catch (silentError) {
|
|
2042
|
+
console.debug("Silent TronLink connection failed:", silentError);
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
const account = await adapter.connect(data.primaryChainId);
|
|
2046
|
+
this.setPrimaryWallet(adapter);
|
|
2047
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2048
|
+
this.setupAdapterListeners(adapter, true);
|
|
2049
|
+
this.emit("accountChanged", account);
|
|
2050
|
+
return account;
|
|
2051
|
+
} catch (error) {
|
|
2052
|
+
console.debug("Failed to restore wallet from storage:", error);
|
|
2053
|
+
return null;
|
|
2054
|
+
}
|
|
1956
2055
|
}
|
|
1957
2056
|
/**
|
|
1958
|
-
*
|
|
2057
|
+
* Clear storage
|
|
1959
2058
|
*/
|
|
1960
2059
|
clearStorage() {
|
|
1961
2060
|
if (typeof window === "undefined") {
|
|
@@ -1968,7 +2067,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1968
2067
|
}
|
|
1969
2068
|
}
|
|
1970
2069
|
/**
|
|
1971
|
-
*
|
|
2070
|
+
* Get history records
|
|
1972
2071
|
*/
|
|
1973
2072
|
getHistoryRecords() {
|
|
1974
2073
|
const records = [];
|