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