@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.d.mts
CHANGED
|
@@ -37,7 +37,11 @@ interface Account {
|
|
|
37
37
|
balance?: string;
|
|
38
38
|
name?: string;
|
|
39
39
|
}
|
|
40
|
-
interface
|
|
40
|
+
interface ISigner {
|
|
41
|
+
signMessage(message: string): Promise<string>;
|
|
42
|
+
getAddress(): Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
interface IWalletAdapter extends ISigner {
|
|
41
45
|
readonly type: WalletType;
|
|
42
46
|
readonly chainType: ChainType$1;
|
|
43
47
|
readonly name: string;
|
|
@@ -150,6 +154,8 @@ interface WalletHistoryRecord {
|
|
|
150
154
|
}
|
|
151
155
|
interface StorageData {
|
|
152
156
|
current: UniversalAddress | null;
|
|
157
|
+
primaryWalletType?: WalletType;
|
|
158
|
+
primaryChainId?: number;
|
|
153
159
|
history: WalletHistoryRecord[];
|
|
154
160
|
}
|
|
155
161
|
interface WalletAvailability {
|
|
@@ -199,7 +205,7 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
|
|
|
199
205
|
private setupAdapterListeners;
|
|
200
206
|
private removeAdapterListeners;
|
|
201
207
|
private saveToStorage;
|
|
202
|
-
|
|
208
|
+
restoreFromStorage(): Promise<Account | null>;
|
|
203
209
|
private clearStorage;
|
|
204
210
|
private getHistoryRecords;
|
|
205
211
|
}
|
|
@@ -259,6 +265,7 @@ declare abstract class WalletAdapter extends EventEmitter implements IWalletAdap
|
|
|
259
265
|
abstract disconnect(): Promise<void>;
|
|
260
266
|
abstract isAvailable(): Promise<boolean>;
|
|
261
267
|
abstract signMessage(message: string): Promise<string>;
|
|
268
|
+
getAddress(): Promise<string>;
|
|
262
269
|
signTransaction?(_transaction: any): Promise<string>;
|
|
263
270
|
signTypedData?(_typedData: any): Promise<string>;
|
|
264
271
|
switchChain?(_chainId: number): Promise<void>;
|
|
@@ -463,4 +470,4 @@ declare function hexToNumber(hex: string): number;
|
|
|
463
470
|
declare function ensureHexPrefix(value: string): string;
|
|
464
471
|
declare function removeHexPrefix(value: string): string;
|
|
465
472
|
|
|
466
|
-
export { type Account, AdapterRegistry, type AddChainParams, AuthMessageGenerator, type AuthMessageParams, BrowserWalletAdapter, CHAIN_INFO, type ChainInfo, ChainNotSupportedError, ChainType$1 as ChainType, ConfigurationError, type ConnectedWallet, ConnectionRejectedError, type ContractReadParams, type ContractWriteParams, EVMPrivateKeyAdapter, type EVMTransaction, type IWalletAdapter, MetaMaskAdapter, MethodNotSupportedError, NetworkError, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, type StorageData, type Transaction, TransactionFailedError, type TransactionReceipt, TronLinkAdapter, type TronTransaction, type UniversalAddress, WalletAdapter, type WalletAvailability, WalletDetector, type WalletHistoryRecord, WalletManager, type WalletManagerConfig, type WalletManagerEvents, type WalletMetadata, WalletNotAvailableError, WalletNotConnectedError, WalletSDKError, WalletState, WalletType, compareEVMAddresses, compareTronAddresses, compareUniversalAddresses, createUniversalAddress, WalletManager as default, ensureHexPrefix, formatEVMAddress, fromHex, getAddressFromUniversalAddress, getChainIdFromUniversalAddress, getChainInfo, getChainType, getEVMWallets, getTronWallets, getWalletMetadata, hexToNumber, isEVMChain, isHex, isTronChain, isValidChainId, isValidEVMAddress, isValidSignature, isValidTransactionHash, isValidTronAddress, isValidTronHexAddress, isValidUniversalAddress, numberToHex, parseUniversalAddress, removeHexPrefix, shortenAddress, shortenTronAddress, toHex, validateAddress, validateAddressForChain };
|
|
473
|
+
export { type Account, AdapterRegistry, type AddChainParams, AuthMessageGenerator, type AuthMessageParams, BrowserWalletAdapter, CHAIN_INFO, type ChainInfo, ChainNotSupportedError, ChainType$1 as ChainType, ConfigurationError, type ConnectedWallet, ConnectionRejectedError, type ContractReadParams, type ContractWriteParams, EVMPrivateKeyAdapter, type EVMTransaction, type ISigner, type IWalletAdapter, MetaMaskAdapter, MethodNotSupportedError, NetworkError, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, type StorageData, type Transaction, TransactionFailedError, type TransactionReceipt, TronLinkAdapter, type TronTransaction, type UniversalAddress, WalletAdapter, type WalletAvailability, WalletDetector, type WalletHistoryRecord, WalletManager, type WalletManagerConfig, type WalletManagerEvents, type WalletMetadata, WalletNotAvailableError, WalletNotConnectedError, WalletSDKError, WalletState, WalletType, compareEVMAddresses, compareTronAddresses, compareUniversalAddresses, createUniversalAddress, WalletManager as default, ensureHexPrefix, formatEVMAddress, fromHex, getAddressFromUniversalAddress, getChainIdFromUniversalAddress, getChainInfo, getChainType, getEVMWallets, getTronWallets, getWalletMetadata, hexToNumber, isEVMChain, isHex, isTronChain, isValidChainId, isValidEVMAddress, isValidSignature, isValidTransactionHash, isValidTronAddress, isValidTronHexAddress, isValidUniversalAddress, numberToHex, parseUniversalAddress, removeHexPrefix, shortenAddress, shortenTronAddress, toHex, validateAddress, validateAddressForChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,11 @@ interface Account {
|
|
|
37
37
|
balance?: string;
|
|
38
38
|
name?: string;
|
|
39
39
|
}
|
|
40
|
-
interface
|
|
40
|
+
interface ISigner {
|
|
41
|
+
signMessage(message: string): Promise<string>;
|
|
42
|
+
getAddress(): Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
interface IWalletAdapter extends ISigner {
|
|
41
45
|
readonly type: WalletType;
|
|
42
46
|
readonly chainType: ChainType$1;
|
|
43
47
|
readonly name: string;
|
|
@@ -150,6 +154,8 @@ interface WalletHistoryRecord {
|
|
|
150
154
|
}
|
|
151
155
|
interface StorageData {
|
|
152
156
|
current: UniversalAddress | null;
|
|
157
|
+
primaryWalletType?: WalletType;
|
|
158
|
+
primaryChainId?: number;
|
|
153
159
|
history: WalletHistoryRecord[];
|
|
154
160
|
}
|
|
155
161
|
interface WalletAvailability {
|
|
@@ -199,7 +205,7 @@ declare class WalletManager extends TypedEventEmitter<WalletManagerEvents> {
|
|
|
199
205
|
private setupAdapterListeners;
|
|
200
206
|
private removeAdapterListeners;
|
|
201
207
|
private saveToStorage;
|
|
202
|
-
|
|
208
|
+
restoreFromStorage(): Promise<Account | null>;
|
|
203
209
|
private clearStorage;
|
|
204
210
|
private getHistoryRecords;
|
|
205
211
|
}
|
|
@@ -259,6 +265,7 @@ declare abstract class WalletAdapter extends EventEmitter implements IWalletAdap
|
|
|
259
265
|
abstract disconnect(): Promise<void>;
|
|
260
266
|
abstract isAvailable(): Promise<boolean>;
|
|
261
267
|
abstract signMessage(message: string): Promise<string>;
|
|
268
|
+
getAddress(): Promise<string>;
|
|
262
269
|
signTransaction?(_transaction: any): Promise<string>;
|
|
263
270
|
signTypedData?(_typedData: any): Promise<string>;
|
|
264
271
|
switchChain?(_chainId: number): Promise<void>;
|
|
@@ -463,4 +470,4 @@ declare function hexToNumber(hex: string): number;
|
|
|
463
470
|
declare function ensureHexPrefix(value: string): string;
|
|
464
471
|
declare function removeHexPrefix(value: string): string;
|
|
465
472
|
|
|
466
|
-
export { type Account, AdapterRegistry, type AddChainParams, AuthMessageGenerator, type AuthMessageParams, BrowserWalletAdapter, CHAIN_INFO, type ChainInfo, ChainNotSupportedError, ChainType$1 as ChainType, ConfigurationError, type ConnectedWallet, ConnectionRejectedError, type ContractReadParams, type ContractWriteParams, EVMPrivateKeyAdapter, type EVMTransaction, type IWalletAdapter, MetaMaskAdapter, MethodNotSupportedError, NetworkError, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, type StorageData, type Transaction, TransactionFailedError, type TransactionReceipt, TronLinkAdapter, type TronTransaction, type UniversalAddress, WalletAdapter, type WalletAvailability, WalletDetector, type WalletHistoryRecord, WalletManager, type WalletManagerConfig, type WalletManagerEvents, type WalletMetadata, WalletNotAvailableError, WalletNotConnectedError, WalletSDKError, WalletState, WalletType, compareEVMAddresses, compareTronAddresses, compareUniversalAddresses, createUniversalAddress, WalletManager as default, ensureHexPrefix, formatEVMAddress, fromHex, getAddressFromUniversalAddress, getChainIdFromUniversalAddress, getChainInfo, getChainType, getEVMWallets, getTronWallets, getWalletMetadata, hexToNumber, isEVMChain, isHex, isTronChain, isValidChainId, isValidEVMAddress, isValidSignature, isValidTransactionHash, isValidTronAddress, isValidTronHexAddress, isValidUniversalAddress, numberToHex, parseUniversalAddress, removeHexPrefix, shortenAddress, shortenTronAddress, toHex, validateAddress, validateAddressForChain };
|
|
473
|
+
export { type Account, AdapterRegistry, type AddChainParams, AuthMessageGenerator, type AuthMessageParams, BrowserWalletAdapter, CHAIN_INFO, type ChainInfo, ChainNotSupportedError, ChainType$1 as ChainType, ConfigurationError, type ConnectedWallet, ConnectionRejectedError, type ContractReadParams, type ContractWriteParams, EVMPrivateKeyAdapter, type EVMTransaction, type ISigner, type IWalletAdapter, MetaMaskAdapter, MethodNotSupportedError, NetworkError, SUPPORTED_WALLETS, SignatureRejectedError, SignatureVerifier, type StorageData, type Transaction, TransactionFailedError, type TransactionReceipt, TronLinkAdapter, type TronTransaction, type UniversalAddress, WalletAdapter, type WalletAvailability, WalletDetector, type WalletHistoryRecord, WalletManager, type WalletManagerConfig, type WalletManagerEvents, type WalletMetadata, WalletNotAvailableError, WalletNotConnectedError, WalletSDKError, WalletState, WalletType, compareEVMAddresses, compareTronAddresses, compareUniversalAddresses, createUniversalAddress, WalletManager as default, ensureHexPrefix, formatEVMAddress, fromHex, getAddressFromUniversalAddress, getChainIdFromUniversalAddress, getChainInfo, getChainType, getEVMWallets, getTronWallets, getWalletMetadata, hexToNumber, isEVMChain, isHex, isTronChain, isValidChainId, isValidEVMAddress, isValidSignature, isValidTransactionHash, isValidTronAddress, isValidTronHexAddress, isValidUniversalAddress, numberToHex, parseUniversalAddress, removeHexPrefix, shortenAddress, shortenTronAddress, toHex, validateAddress, validateAddressForChain };
|
package/dist/index.js
CHANGED
|
@@ -158,6 +158,17 @@ var WalletAdapter = class extends EventEmitter__default.default {
|
|
|
158
158
|
this.state = "disconnected" /* DISCONNECTED */;
|
|
159
159
|
this.currentAccount = null;
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Get the signer's address (implements ISigner interface)
|
|
163
|
+
* Returns the native address of the current account
|
|
164
|
+
*/
|
|
165
|
+
async getAddress() {
|
|
166
|
+
this.ensureConnected();
|
|
167
|
+
if (!this.currentAccount) {
|
|
168
|
+
throw new WalletNotConnectedError(this.type);
|
|
169
|
+
}
|
|
170
|
+
return this.currentAccount.nativeAddress;
|
|
171
|
+
}
|
|
161
172
|
signTransaction(_transaction) {
|
|
162
173
|
throw new MethodNotSupportedError("signTransaction", this.type);
|
|
163
174
|
}
|
|
@@ -1572,9 +1583,6 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1572
1583
|
walletConnectProjectId: config.walletConnectProjectId ?? ""
|
|
1573
1584
|
};
|
|
1574
1585
|
this.registry = new AdapterRegistry();
|
|
1575
|
-
if (this.config.enableStorage) {
|
|
1576
|
-
this.restoreFromStorage();
|
|
1577
|
-
}
|
|
1578
1586
|
}
|
|
1579
1587
|
// ===== Connection Management =====
|
|
1580
1588
|
/**
|
|
@@ -1685,13 +1693,13 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1685
1693
|
return adapter.currentAccount;
|
|
1686
1694
|
}
|
|
1687
1695
|
/**
|
|
1688
|
-
*
|
|
1696
|
+
* Get primary wallet account
|
|
1689
1697
|
*/
|
|
1690
1698
|
getPrimaryAccount() {
|
|
1691
1699
|
return this.primaryWallet?.currentAccount || null;
|
|
1692
1700
|
}
|
|
1693
1701
|
/**
|
|
1694
|
-
*
|
|
1702
|
+
* Get all connected wallets
|
|
1695
1703
|
*/
|
|
1696
1704
|
getConnectedWallets() {
|
|
1697
1705
|
return Array.from(this.connectedWallets.values()).map((adapter) => ({
|
|
@@ -1704,14 +1712,14 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1704
1712
|
}));
|
|
1705
1713
|
}
|
|
1706
1714
|
/**
|
|
1707
|
-
*
|
|
1715
|
+
* Get wallet by chain type
|
|
1708
1716
|
*/
|
|
1709
1717
|
getWalletByChainType(chainType) {
|
|
1710
1718
|
return this.connectedWallets.get(chainType) || null;
|
|
1711
1719
|
}
|
|
1712
|
-
// =====
|
|
1720
|
+
// ===== Signing =====
|
|
1713
1721
|
/**
|
|
1714
|
-
*
|
|
1722
|
+
* Sign message with primary wallet
|
|
1715
1723
|
*/
|
|
1716
1724
|
async signMessage(message) {
|
|
1717
1725
|
if (!this.primaryWallet) {
|
|
@@ -1720,7 +1728,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1720
1728
|
return this.primaryWallet.signMessage(message);
|
|
1721
1729
|
}
|
|
1722
1730
|
/**
|
|
1723
|
-
*
|
|
1731
|
+
* Sign message with wallet of specified chain type
|
|
1724
1732
|
*/
|
|
1725
1733
|
async signMessageWithChainType(message, chainType) {
|
|
1726
1734
|
if (!chainType) {
|
|
@@ -1733,7 +1741,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1733
1741
|
return adapter.signMessage(message);
|
|
1734
1742
|
}
|
|
1735
1743
|
/**
|
|
1736
|
-
*
|
|
1744
|
+
* Sign TypedData (EVM only)
|
|
1737
1745
|
*/
|
|
1738
1746
|
async signTypedData(typedData, chainType) {
|
|
1739
1747
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1746,7 +1754,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1746
1754
|
return adapter.signTypedData(typedData);
|
|
1747
1755
|
}
|
|
1748
1756
|
/**
|
|
1749
|
-
*
|
|
1757
|
+
* Sign transaction (with primary wallet)
|
|
1750
1758
|
*/
|
|
1751
1759
|
async signTransaction(transaction) {
|
|
1752
1760
|
if (!this.primaryWallet) {
|
|
@@ -1758,7 +1766,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1758
1766
|
return this.primaryWallet.signTransaction(transaction);
|
|
1759
1767
|
}
|
|
1760
1768
|
/**
|
|
1761
|
-
*
|
|
1769
|
+
* Sign transaction with wallet of specified chain type
|
|
1762
1770
|
*/
|
|
1763
1771
|
async signTransactionWithChainType(transaction, chainType) {
|
|
1764
1772
|
if (!chainType) {
|
|
@@ -1773,9 +1781,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1773
1781
|
}
|
|
1774
1782
|
return adapter.signTransaction(transaction);
|
|
1775
1783
|
}
|
|
1776
|
-
// =====
|
|
1784
|
+
// ===== Chain Switching =====
|
|
1777
1785
|
/**
|
|
1778
|
-
*
|
|
1786
|
+
* Request chain switch (EVM only)
|
|
1779
1787
|
*/
|
|
1780
1788
|
async requestSwitchChain(chainId, options) {
|
|
1781
1789
|
if (!this.primaryWallet) {
|
|
@@ -1796,9 +1804,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1796
1804
|
throw error;
|
|
1797
1805
|
}
|
|
1798
1806
|
}
|
|
1799
|
-
// =====
|
|
1807
|
+
// ===== Contract Calls =====
|
|
1800
1808
|
/**
|
|
1801
|
-
*
|
|
1809
|
+
* Read contract
|
|
1802
1810
|
*/
|
|
1803
1811
|
async readContract(address, abi, functionName, args, chainType) {
|
|
1804
1812
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1811,7 +1819,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1811
1819
|
return adapter.readContract({ address, abi, functionName, args });
|
|
1812
1820
|
}
|
|
1813
1821
|
/**
|
|
1814
|
-
*
|
|
1822
|
+
* Write contract
|
|
1815
1823
|
*/
|
|
1816
1824
|
async writeContract(address, abi, functionName, args, options, chainType) {
|
|
1817
1825
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1830,7 +1838,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1830
1838
|
});
|
|
1831
1839
|
}
|
|
1832
1840
|
/**
|
|
1833
|
-
*
|
|
1841
|
+
* Estimate gas
|
|
1834
1842
|
*/
|
|
1835
1843
|
async estimateGas(address, abi, functionName, args, chainType) {
|
|
1836
1844
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1843,7 +1851,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1843
1851
|
return adapter.estimateGas({ address, abi, functionName, args });
|
|
1844
1852
|
}
|
|
1845
1853
|
/**
|
|
1846
|
-
*
|
|
1854
|
+
* Wait for transaction confirmation
|
|
1847
1855
|
*/
|
|
1848
1856
|
async waitForTransaction(txHash, confirmations, chainType) {
|
|
1849
1857
|
const adapter = chainType ? this.connectedWallets.get(chainType) : this.primaryWallet;
|
|
@@ -1855,9 +1863,9 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1855
1863
|
}
|
|
1856
1864
|
return adapter.waitForTransaction(txHash, confirmations);
|
|
1857
1865
|
}
|
|
1858
|
-
// ===== Provider
|
|
1866
|
+
// ===== Provider Access =====
|
|
1859
1867
|
/**
|
|
1860
|
-
*
|
|
1868
|
+
* Get primary wallet Provider
|
|
1861
1869
|
*/
|
|
1862
1870
|
getProvider() {
|
|
1863
1871
|
if (!this.primaryWallet) {
|
|
@@ -1866,7 +1874,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1866
1874
|
return this.primaryWallet.getProvider();
|
|
1867
1875
|
}
|
|
1868
1876
|
/**
|
|
1869
|
-
*
|
|
1877
|
+
* Get Provider by chain type
|
|
1870
1878
|
*/
|
|
1871
1879
|
getProviderByChainType(chainType) {
|
|
1872
1880
|
const adapter = this.connectedWallets.get(chainType);
|
|
@@ -1875,21 +1883,21 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1875
1883
|
}
|
|
1876
1884
|
return adapter.getProvider();
|
|
1877
1885
|
}
|
|
1878
|
-
// =====
|
|
1886
|
+
// ===== Private Methods =====
|
|
1879
1887
|
/**
|
|
1880
|
-
*
|
|
1888
|
+
* Set primary wallet
|
|
1881
1889
|
*/
|
|
1882
1890
|
setPrimaryWallet(adapter) {
|
|
1883
1891
|
this.primaryWallet = adapter;
|
|
1884
1892
|
}
|
|
1885
1893
|
/**
|
|
1886
|
-
*
|
|
1894
|
+
* Check if wallet supports chain switching
|
|
1887
1895
|
*/
|
|
1888
1896
|
canSwitchChain(adapter) {
|
|
1889
1897
|
return !!adapter.switchChain;
|
|
1890
1898
|
}
|
|
1891
1899
|
/**
|
|
1892
|
-
*
|
|
1900
|
+
* Setup adapter event listeners
|
|
1893
1901
|
*/
|
|
1894
1902
|
setupAdapterListeners(adapter, isPrimary) {
|
|
1895
1903
|
adapter.on("accountChanged", (account) => {
|
|
@@ -1930,15 +1938,15 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1930
1938
|
});
|
|
1931
1939
|
}
|
|
1932
1940
|
/**
|
|
1933
|
-
*
|
|
1941
|
+
* Remove adapter event listeners
|
|
1934
1942
|
*/
|
|
1935
1943
|
removeAdapterListeners(adapter) {
|
|
1936
1944
|
if (!adapter) return;
|
|
1937
1945
|
adapter.removeAllListeners();
|
|
1938
1946
|
}
|
|
1939
|
-
// =====
|
|
1947
|
+
// ===== Storage =====
|
|
1940
1948
|
/**
|
|
1941
|
-
*
|
|
1949
|
+
* Save to storage
|
|
1942
1950
|
*/
|
|
1943
1951
|
saveToStorage() {
|
|
1944
1952
|
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
@@ -1946,6 +1954,8 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1946
1954
|
}
|
|
1947
1955
|
const data = {
|
|
1948
1956
|
current: this.primaryWallet?.currentAccount?.universalAddress || null,
|
|
1957
|
+
primaryWalletType: this.primaryWallet?.type,
|
|
1958
|
+
primaryChainId: this.primaryWallet?.currentAccount?.chainId,
|
|
1949
1959
|
history: this.getHistoryRecords()
|
|
1950
1960
|
};
|
|
1951
1961
|
try {
|
|
@@ -1958,12 +1968,101 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1958
1968
|
}
|
|
1959
1969
|
}
|
|
1960
1970
|
/**
|
|
1961
|
-
*
|
|
1971
|
+
* Restore from storage
|
|
1972
|
+
* Returns a Promise that can be used for auto-reconnection
|
|
1962
1973
|
*/
|
|
1963
|
-
restoreFromStorage() {
|
|
1974
|
+
async restoreFromStorage() {
|
|
1975
|
+
if (typeof window === "undefined" || !this.config.enableStorage) {
|
|
1976
|
+
return null;
|
|
1977
|
+
}
|
|
1978
|
+
try {
|
|
1979
|
+
const stored = localStorage.getItem(`${this.config.storagePrefix}data`);
|
|
1980
|
+
if (!stored) {
|
|
1981
|
+
console.debug("[WalletManager] No stored wallet data found");
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
const data = JSON.parse(stored);
|
|
1985
|
+
console.debug("[WalletManager] Restoring from storage:", data);
|
|
1986
|
+
if (!data.primaryWalletType || !data.current) {
|
|
1987
|
+
console.debug("[WalletManager] Missing primary wallet info in storage");
|
|
1988
|
+
return null;
|
|
1989
|
+
}
|
|
1990
|
+
const adapter = this.registry.getAdapter(data.primaryWalletType);
|
|
1991
|
+
if (!adapter) {
|
|
1992
|
+
console.debug("[WalletManager] Adapter not found for type:", data.primaryWalletType);
|
|
1993
|
+
return null;
|
|
1994
|
+
}
|
|
1995
|
+
const isAvailable = await adapter.isAvailable();
|
|
1996
|
+
if (!isAvailable) {
|
|
1997
|
+
console.debug("[WalletManager] Wallet not available:", data.primaryWalletType);
|
|
1998
|
+
return null;
|
|
1999
|
+
}
|
|
2000
|
+
console.debug("[WalletManager] Wallet is available, attempting restoration");
|
|
2001
|
+
if (adapter.chainType === ChainType.EVM && data.primaryWalletType === "metamask" /* METAMASK */) {
|
|
2002
|
+
try {
|
|
2003
|
+
const provider = typeof window !== "undefined" ? window.ethereum : null;
|
|
2004
|
+
if (provider) {
|
|
2005
|
+
const accounts = await provider.request({
|
|
2006
|
+
method: "eth_accounts"
|
|
2007
|
+
});
|
|
2008
|
+
console.debug("[WalletManager] Checking authorized accounts:", accounts);
|
|
2009
|
+
if (accounts && accounts.length > 0) {
|
|
2010
|
+
const savedAddress = data.current.split(":")[1];
|
|
2011
|
+
const currentAddress = accounts[0].toLowerCase();
|
|
2012
|
+
console.debug("[WalletManager] Comparing addresses - saved:", savedAddress, "current:", currentAddress);
|
|
2013
|
+
if (currentAddress === savedAddress.toLowerCase()) {
|
|
2014
|
+
console.debug("[WalletManager] Address matches, attempting connect (should be silent if already authorized)");
|
|
2015
|
+
try {
|
|
2016
|
+
const account2 = await adapter.connect(data.primaryChainId);
|
|
2017
|
+
this.setPrimaryWallet(adapter);
|
|
2018
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2019
|
+
this.setupAdapterListeners(adapter, true);
|
|
2020
|
+
this.emit("accountChanged", account2);
|
|
2021
|
+
console.debug("[WalletManager] Connect successful");
|
|
2022
|
+
return account2;
|
|
2023
|
+
} catch (connectError) {
|
|
2024
|
+
console.debug("[WalletManager] Connect failed (might be user rejection):", connectError?.message);
|
|
2025
|
+
return null;
|
|
2026
|
+
}
|
|
2027
|
+
} else {
|
|
2028
|
+
console.debug("[WalletManager] Address mismatch, will try normal connect");
|
|
2029
|
+
}
|
|
2030
|
+
} else {
|
|
2031
|
+
console.debug("[WalletManager] No authorized accounts found");
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
} catch (silentError) {
|
|
2035
|
+
console.debug("Silent connection failed, trying normal connection:", silentError);
|
|
2036
|
+
}
|
|
2037
|
+
}
|
|
2038
|
+
if (adapter.chainType === ChainType.TRON && data.primaryWalletType === "tronlink" /* TRONLINK */) {
|
|
2039
|
+
try {
|
|
2040
|
+
const tronWeb = adapter.getTronWeb?.();
|
|
2041
|
+
if (tronWeb && tronWeb.defaultAddress?.base58) {
|
|
2042
|
+
const account2 = 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", account2);
|
|
2047
|
+
return account2;
|
|
2048
|
+
}
|
|
2049
|
+
} catch (silentError) {
|
|
2050
|
+
console.debug("Silent TronLink connection failed:", silentError);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
const account = await adapter.connect(data.primaryChainId);
|
|
2054
|
+
this.setPrimaryWallet(adapter);
|
|
2055
|
+
this.connectedWallets.set(adapter.chainType, adapter);
|
|
2056
|
+
this.setupAdapterListeners(adapter, true);
|
|
2057
|
+
this.emit("accountChanged", account);
|
|
2058
|
+
return account;
|
|
2059
|
+
} catch (error) {
|
|
2060
|
+
console.debug("Failed to restore wallet from storage:", error);
|
|
2061
|
+
return null;
|
|
2062
|
+
}
|
|
1964
2063
|
}
|
|
1965
2064
|
/**
|
|
1966
|
-
*
|
|
2065
|
+
* Clear storage
|
|
1967
2066
|
*/
|
|
1968
2067
|
clearStorage() {
|
|
1969
2068
|
if (typeof window === "undefined") {
|
|
@@ -1976,7 +2075,7 @@ var WalletManager = class extends TypedEventEmitter {
|
|
|
1976
2075
|
}
|
|
1977
2076
|
}
|
|
1978
2077
|
/**
|
|
1979
|
-
*
|
|
2078
|
+
* Get history records
|
|
1980
2079
|
*/
|
|
1981
2080
|
getHistoryRecords() {
|
|
1982
2081
|
const records = [];
|