@web3auth/no-modal 11.1.0 → 11.3.0
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/lib.cjs/base/connector/baseConnector.js +42 -11
- package/dist/lib.cjs/base/errors/index.js +5 -1
- package/dist/lib.cjs/base/utils.js +1 -1
- package/dist/lib.cjs/base/wallet/index.js +3 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +13 -4
- package/dist/lib.cjs/connectors/base-account-connector/baseAccountConnector.js +211 -0
- package/dist/lib.cjs/connectors/base-account-connector/index.js +7 -0
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +5 -5
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +6 -5
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +6 -5
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +82 -31
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -6
- package/dist/lib.cjs/index.js +1 -0
- package/dist/lib.cjs/noModal.js +44 -21
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -2
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +10 -0
- package/dist/lib.cjs/react/solana/provider.js +65 -32
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +2 -1
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -0
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +3 -0
- package/dist/lib.cjs/types/base/errors/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +2 -1
- package/dist/lib.cjs/types/base/wallet/index.d.ts +3 -0
- package/dist/lib.cjs/types/connectors/base-account-connector/baseAccountConnector.d.ts +10 -0
- package/dist/lib.cjs/types/connectors/base-account-connector/index.d.ts +1 -0
- package/dist/lib.cjs/types/connectors/metamask-connector/metamaskConnector.d.ts +1 -0
- package/dist/lib.cjs/types/vue/solana/provider.d.ts +2 -2
- package/dist/lib.cjs/vue/solana/provider.js +55 -21
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +12 -2
- package/dist/lib.esm/base/connector/baseConnector.js +42 -11
- package/dist/lib.esm/base/errors/index.js +5 -1
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/base/wallet/index.js +3 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +13 -5
- package/dist/lib.esm/connectors/base-account-connector/baseAccountConnector.js +198 -0
- package/dist/lib.esm/connectors/base-account-connector/index.js +1 -0
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +5 -5
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +6 -5
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +6 -5
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +86 -31
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -7
- package/dist/lib.esm/index.js +1 -1
- package/dist/lib.esm/noModal.js +46 -22
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -2
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +10 -0
- package/dist/lib.esm/react/solana/provider.js +64 -30
- package/dist/lib.esm/vue/solana/provider.js +55 -19
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +10 -0
- package/package.json +15 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import { getSiteName, getSiteIcon } from '../utils.js';
|
|
4
|
+
import { BaseEvmConnector } from '../base-evm-connector/baseEvmConnector.js';
|
|
5
|
+
import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
|
|
6
|
+
import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
|
|
7
|
+
import { WalletLoginError, Web3AuthError } from '../../base/errors/index.js';
|
|
8
|
+
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
9
|
+
import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
10
|
+
|
|
11
|
+
class BaseAccountConnector extends BaseEvmConnector {
|
|
12
|
+
constructor(connectorOptions) {
|
|
13
|
+
super(connectorOptions);
|
|
14
|
+
_defineProperty(this, "connectorNamespace", CONNECTOR_NAMESPACES.EIP155);
|
|
15
|
+
_defineProperty(this, "currentChainNamespace", CHAIN_NAMESPACES.EIP155);
|
|
16
|
+
_defineProperty(this, "type", CONNECTOR_CATEGORY.EXTERNAL);
|
|
17
|
+
_defineProperty(this, "name", WALLET_CONNECTORS.BASE_ACCOUNT);
|
|
18
|
+
_defineProperty(this, "status", CONNECTOR_STATUS.NOT_READY);
|
|
19
|
+
_defineProperty(this, "baseAccountProvider", null);
|
|
20
|
+
_defineProperty(this, "baseAccountOptions", {
|
|
21
|
+
appName: "Web3Auth"
|
|
22
|
+
});
|
|
23
|
+
this.baseAccountOptions = _objectSpread(_objectSpread({}, this.baseAccountOptions), connectorOptions.connectorSettings);
|
|
24
|
+
}
|
|
25
|
+
get provider() {
|
|
26
|
+
if (this.status !== CONNECTOR_STATUS.NOT_READY && this.baseAccountProvider) {
|
|
27
|
+
return this.baseAccountProvider;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
set provider(_) {
|
|
32
|
+
throw new Error("Not implemented");
|
|
33
|
+
}
|
|
34
|
+
async init(options) {
|
|
35
|
+
await super.init(options);
|
|
36
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === options.chainId);
|
|
37
|
+
super.checkInitializationRequirements({
|
|
38
|
+
chainConfig
|
|
39
|
+
});
|
|
40
|
+
const {
|
|
41
|
+
createBaseAccountSDK
|
|
42
|
+
} = await import('@base-org/account');
|
|
43
|
+
let appName = this.baseAccountOptions.appName || "Web3Auth";
|
|
44
|
+
let appLogoUrl = this.baseAccountOptions.appLogoUrl || "";
|
|
45
|
+
if (typeof window !== "undefined") {
|
|
46
|
+
if (!this.baseAccountOptions.appName) {
|
|
47
|
+
appName = getSiteName(window) || "Web3Auth";
|
|
48
|
+
}
|
|
49
|
+
if (!this.baseAccountOptions.appLogoUrl) {
|
|
50
|
+
appLogoUrl = (await getSiteIcon(window)) || "";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const appChainIds = this.coreOptions.chains.filter(x => x.chainNamespace === CHAIN_NAMESPACES.EIP155).map(x => Number.parseInt(x.chainId, 16));
|
|
54
|
+
const sdk = createBaseAccountSDK(_objectSpread(_objectSpread({}, this.baseAccountOptions), {}, {
|
|
55
|
+
appName,
|
|
56
|
+
appLogoUrl: appLogoUrl || null,
|
|
57
|
+
appChainIds: this.baseAccountOptions.appChainIds || appChainIds
|
|
58
|
+
}));
|
|
59
|
+
this.baseAccountProvider = sdk.getProvider();
|
|
60
|
+
this.status = CONNECTOR_STATUS.READY;
|
|
61
|
+
this.emit(CONNECTOR_EVENTS.READY, WALLET_CONNECTORS.BASE_ACCOUNT);
|
|
62
|
+
try {
|
|
63
|
+
if (options.autoConnect) {
|
|
64
|
+
this.rehydrated = true;
|
|
65
|
+
const connection = await this.connect({
|
|
66
|
+
chainId: options.chainId,
|
|
67
|
+
getAuthTokenInfo: options.getAuthTokenInfo
|
|
68
|
+
});
|
|
69
|
+
if (!connection) {
|
|
70
|
+
this.rehydrated = false;
|
|
71
|
+
throw WalletLoginError.connectionError("Failed to rehydrate.");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async connect({
|
|
79
|
+
chainId,
|
|
80
|
+
getAuthTokenInfo
|
|
81
|
+
}) {
|
|
82
|
+
super.checkConnectionRequirements();
|
|
83
|
+
if (!this.baseAccountProvider) throw WalletLoginError.notConnectedError("Connector is not initialized");
|
|
84
|
+
this.status = CONNECTOR_STATUS.CONNECTING;
|
|
85
|
+
this.emit(CONNECTOR_EVENTS.CONNECTING, {
|
|
86
|
+
connector: WALLET_CONNECTORS.BASE_ACCOUNT
|
|
87
|
+
});
|
|
88
|
+
try {
|
|
89
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === chainId);
|
|
90
|
+
if (!chainConfig) throw WalletLoginError.connectionError("Chain config is not available");
|
|
91
|
+
await this.baseAccountProvider.request({
|
|
92
|
+
method: "eth_requestAccounts"
|
|
93
|
+
});
|
|
94
|
+
const currentChainId = await this.baseAccountProvider.request({
|
|
95
|
+
method: "eth_chainId"
|
|
96
|
+
});
|
|
97
|
+
if (currentChainId !== chainConfig.chainId) {
|
|
98
|
+
await this.switchChain(chainConfig, true);
|
|
99
|
+
}
|
|
100
|
+
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
101
|
+
if (!this.provider) throw WalletLoginError.notConnectedError("Failed to connect with provider");
|
|
102
|
+
this.provider.once("disconnect", () => {
|
|
103
|
+
this.disconnect();
|
|
104
|
+
});
|
|
105
|
+
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
106
|
+
connectorName: WALLET_CONNECTORS.BASE_ACCOUNT,
|
|
107
|
+
reconnected: this.rehydrated,
|
|
108
|
+
ethereumProvider: this.provider,
|
|
109
|
+
solanaWallet: null,
|
|
110
|
+
connectorNamespace: this.connectorNamespace
|
|
111
|
+
});
|
|
112
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
113
|
+
return {
|
|
114
|
+
ethereumProvider: this.provider,
|
|
115
|
+
solanaWallet: null,
|
|
116
|
+
connectorName: this.name,
|
|
117
|
+
connectorNamespace: this.connectorNamespace
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
this.status = CONNECTOR_STATUS.READY;
|
|
121
|
+
if (!this.rehydrated) this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
122
|
+
this.rehydrated = false;
|
|
123
|
+
if (error instanceof Web3AuthError) throw error;
|
|
124
|
+
throw WalletLoginError.connectionError("Failed to login with Base Account", error);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async disconnect(options = {
|
|
128
|
+
cleanup: false
|
|
129
|
+
}) {
|
|
130
|
+
var _this$provider;
|
|
131
|
+
await super.disconnectSession();
|
|
132
|
+
(_this$provider = this.provider) === null || _this$provider === void 0 || _this$provider.removeAllListeners();
|
|
133
|
+
if (options.cleanup) {
|
|
134
|
+
this.status = CONNECTOR_STATUS.NOT_READY;
|
|
135
|
+
this.baseAccountProvider = null;
|
|
136
|
+
} else {
|
|
137
|
+
this.status = CONNECTOR_STATUS.READY;
|
|
138
|
+
}
|
|
139
|
+
await super.disconnect();
|
|
140
|
+
}
|
|
141
|
+
async getUserInfo() {
|
|
142
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
143
|
+
return {};
|
|
144
|
+
}
|
|
145
|
+
async switchChain(params, init = false) {
|
|
146
|
+
super.checkSwitchChainRequirements(params, init);
|
|
147
|
+
try {
|
|
148
|
+
var _this$baseAccountProv;
|
|
149
|
+
await ((_this$baseAccountProv = this.baseAccountProvider) === null || _this$baseAccountProv === void 0 ? void 0 : _this$baseAccountProv.request({
|
|
150
|
+
method: "wallet_switchEthereumChain",
|
|
151
|
+
params: [{
|
|
152
|
+
chainId: params.chainId
|
|
153
|
+
}]
|
|
154
|
+
}));
|
|
155
|
+
} catch (switchError) {
|
|
156
|
+
if (switchError.code === 4902) {
|
|
157
|
+
var _this$baseAccountProv2;
|
|
158
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
159
|
+
if (!chainConfig) throw WalletLoginError.connectionError("Chain config is not available");
|
|
160
|
+
await ((_this$baseAccountProv2 = this.baseAccountProvider) === null || _this$baseAccountProv2 === void 0 ? void 0 : _this$baseAccountProv2.request({
|
|
161
|
+
method: "wallet_addEthereumChain",
|
|
162
|
+
params: [{
|
|
163
|
+
chainId: chainConfig.chainId,
|
|
164
|
+
rpcUrls: [chainConfig.rpcTarget],
|
|
165
|
+
chainName: chainConfig.displayName,
|
|
166
|
+
nativeCurrency: {
|
|
167
|
+
name: chainConfig.tickerName,
|
|
168
|
+
symbol: chainConfig.ticker,
|
|
169
|
+
decimals: chainConfig.decimals || 18
|
|
170
|
+
},
|
|
171
|
+
blockExplorerUrls: [chainConfig.blockExplorerUrl],
|
|
172
|
+
iconUrls: [chainConfig.logo]
|
|
173
|
+
}]
|
|
174
|
+
}));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
throw switchError;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async enableMFA() {
|
|
181
|
+
throw new Error("Method Not implemented");
|
|
182
|
+
}
|
|
183
|
+
async manageMFA() {
|
|
184
|
+
throw new Error("Method Not implemented");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const baseAccountConnector = params => {
|
|
188
|
+
return ({
|
|
189
|
+
coreOptions
|
|
190
|
+
}) => {
|
|
191
|
+
return new BaseAccountConnector({
|
|
192
|
+
connectorSettings: params,
|
|
193
|
+
coreOptions
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export { baseAccountConnector };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { baseAccountConnector } from './baseAccountConnector.js';
|
|
@@ -99,15 +99,15 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
99
99
|
connectorName: WALLET_CONNECTORS.COINBASE,
|
|
100
100
|
reconnected: this.rehydrated,
|
|
101
101
|
ethereumProvider: this.provider,
|
|
102
|
-
solanaWallet: null
|
|
102
|
+
solanaWallet: null,
|
|
103
|
+
connectorNamespace: this.connectorNamespace
|
|
103
104
|
});
|
|
104
|
-
|
|
105
|
-
await this.getAuthTokenInfo();
|
|
106
|
-
}
|
|
105
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
107
106
|
return {
|
|
108
107
|
ethereumProvider: this.provider,
|
|
109
108
|
solanaWallet: null,
|
|
110
|
-
connectorName: this.name
|
|
109
|
+
connectorName: this.name,
|
|
110
|
+
connectorNamespace: this.connectorNamespace
|
|
111
111
|
};
|
|
112
112
|
} catch (error) {
|
|
113
113
|
// ready again to be connected
|
|
@@ -89,19 +89,20 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
|
|
92
|
+
const connectorNamespace = this.connectorNamespace;
|
|
92
93
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
93
94
|
connectorName: this.name,
|
|
94
95
|
reconnected: this.rehydrated,
|
|
95
96
|
ethereumProvider: this.injectedProvider,
|
|
96
|
-
solanaWallet: null
|
|
97
|
+
solanaWallet: null,
|
|
98
|
+
connectorNamespace
|
|
97
99
|
});
|
|
98
|
-
|
|
99
|
-
await this.getAuthTokenInfo();
|
|
100
|
-
}
|
|
100
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
101
101
|
return {
|
|
102
102
|
ethereumProvider: this.injectedProvider,
|
|
103
103
|
solanaWallet: null,
|
|
104
|
-
connectorName: this.name
|
|
104
|
+
connectorName: this.name,
|
|
105
|
+
connectorNamespace
|
|
105
106
|
};
|
|
106
107
|
} catch (error) {
|
|
107
108
|
// ready again to be connected
|
|
@@ -76,19 +76,20 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
76
76
|
}
|
|
77
77
|
if (this.wallet.accounts.length === 0) throw WalletLoginError.connectionError();
|
|
78
78
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
79
|
+
const connectorNamespace = this.connectorNamespace;
|
|
79
80
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
80
81
|
connectorName: this.name,
|
|
81
82
|
reconnected: this.rehydrated,
|
|
82
83
|
ethereumProvider: null,
|
|
83
|
-
solanaWallet: this.solanaWallet
|
|
84
|
+
solanaWallet: this.solanaWallet,
|
|
85
|
+
connectorNamespace
|
|
84
86
|
});
|
|
85
|
-
|
|
86
|
-
await this.getAuthTokenInfo();
|
|
87
|
-
}
|
|
87
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
88
88
|
return {
|
|
89
89
|
ethereumProvider: null,
|
|
90
90
|
solanaWallet: this.solanaWallet,
|
|
91
|
-
connectorName: this.name
|
|
91
|
+
connectorName: this.name,
|
|
92
|
+
connectorNamespace
|
|
92
93
|
};
|
|
93
94
|
} catch (error) {
|
|
94
95
|
// ready again to be connected
|
|
@@ -15,6 +15,7 @@ import { getCaipChainId, citadelServerUrl } from '../../base/utils.js';
|
|
|
15
15
|
import { WalletLoginError, isUserRejectedError, WalletOperationsError, Web3AuthError } from '../../base/errors/index.js';
|
|
16
16
|
import { ANALYTICS_EVENTS } from '../../base/analytics.js';
|
|
17
17
|
import { getSolanaChainByChainConfig, walletSignMessage } from '../../base/wallet/solana.js';
|
|
18
|
+
import { log } from '../../base/loglevel.js';
|
|
18
19
|
import { BaseConnector } from '../../base/connector/baseConnector.js';
|
|
19
20
|
import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
20
21
|
|
|
@@ -22,6 +23,11 @@ import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../ba
|
|
|
22
23
|
* Configuration options for the MetaMask connector using \@metamask/connect-evm
|
|
23
24
|
*/
|
|
24
25
|
|
|
26
|
+
// `@metamask/connect-evm` announces its SDK-backed provider over EIP-6963 with this
|
|
27
|
+
// RDNS value. Web3Auth uses the dedicated `metaMaskConnector` for MetaMask, so MIPD
|
|
28
|
+
// discovery should ignore this provider to avoid treating the QR/deeplink transport
|
|
29
|
+
// as a native injected wallet.
|
|
30
|
+
const METAMASK_ERC_6963_PROVIDER_RDNS = "io.metamask.mmc";
|
|
25
31
|
class MetaMaskConnector extends BaseConnector {
|
|
26
32
|
constructor(connectorOptions) {
|
|
27
33
|
super(connectorOptions);
|
|
@@ -197,13 +203,25 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
197
203
|
if (coreStatus === "connected" && options.autoConnect) {
|
|
198
204
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
199
205
|
this.rehydrated = true;
|
|
206
|
+
|
|
207
|
+
// Force sync the chain state before connect with rehydrated state.
|
|
208
|
+
// during rehydration, `createEVMClient` (from above) cause re-creating session for connected the evm provider,
|
|
209
|
+
// triggering `switchChain` internally and unintentionally update the connector data with the new chain id.
|
|
210
|
+
// This creates issue in rehydration flow, where Web3Auth connects to the incorrect chain id, not the rehydrated chain id.
|
|
211
|
+
// Force sync the chain state with the rehydrated chain id to avoid this issue.
|
|
212
|
+
await this.forceSyncChainState(chainConfig);
|
|
200
213
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
201
214
|
connectorName: WALLET_CONNECTORS.METAMASK,
|
|
202
215
|
reconnected: true,
|
|
203
216
|
ethereumProvider: this.evmProvider,
|
|
204
|
-
solanaWallet: this.solanaProvider
|
|
217
|
+
solanaWallet: this.solanaProvider,
|
|
218
|
+
connectorNamespace: this.connectorNamespace
|
|
205
219
|
});
|
|
206
|
-
|
|
220
|
+
try {
|
|
221
|
+
await this.authorizeOrDisconnect(options.getAuthTokenInfo, options.chainId);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
224
|
+
}
|
|
207
225
|
} else if (coreStatus === "connected" || coreStatus === "loaded" || coreStatus === "disconnected" || coreStatus === "pending") {
|
|
208
226
|
this.status = CONNECTOR_STATUS.READY;
|
|
209
227
|
this.emit(CONNECTOR_EVENTS.READY, WALLET_CONNECTORS.METAMASK);
|
|
@@ -273,7 +291,7 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
273
291
|
|
|
274
292
|
// sync the chain state after connect
|
|
275
293
|
// metamask might not be connected to the requested chain, so we need to sync the chain state to/from Web3Auth state after connect.
|
|
276
|
-
await this.
|
|
294
|
+
await this.forceSyncChainState(chainConfig);
|
|
277
295
|
|
|
278
296
|
// check if connected
|
|
279
297
|
if (this.multichainClient.status !== "connected") {
|
|
@@ -293,15 +311,15 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
293
311
|
connectorName: WALLET_CONNECTORS.METAMASK,
|
|
294
312
|
reconnected: this.rehydrated,
|
|
295
313
|
ethereumProvider: this.evmProvider,
|
|
296
|
-
solanaWallet: this.solanaProvider
|
|
314
|
+
solanaWallet: this.solanaProvider,
|
|
315
|
+
connectorNamespace: this.connectorNamespace
|
|
297
316
|
});
|
|
298
|
-
|
|
299
|
-
await this.getAuthTokenInfo(chainId);
|
|
300
|
-
}
|
|
317
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo, chainId);
|
|
301
318
|
return {
|
|
302
319
|
ethereumProvider: this.evmProvider,
|
|
303
320
|
solanaWallet: this.solanaProvider,
|
|
304
|
-
connectorName: this.name
|
|
321
|
+
connectorName: this.name,
|
|
322
|
+
connectorNamespace: this.connectorNamespace
|
|
305
323
|
};
|
|
306
324
|
} catch (error) {
|
|
307
325
|
// Ready again to be connected
|
|
@@ -327,10 +345,12 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
327
345
|
}) {
|
|
328
346
|
if (!this.multichainClient) throw WalletLoginError.connectionError("Multichain client is not available");
|
|
329
347
|
this.checkDisconnectionRequirements();
|
|
330
|
-
await this.
|
|
348
|
+
await this.clearMultichainWalletSessions();
|
|
331
349
|
|
|
332
350
|
// Disconnect using the multichain client
|
|
333
|
-
|
|
351
|
+
if (this.multichainClient.status === "connected") {
|
|
352
|
+
await this.multichainClient.disconnect();
|
|
353
|
+
}
|
|
334
354
|
if (options.cleanup) {
|
|
335
355
|
this.status = CONNECTOR_STATUS.NOT_READY;
|
|
336
356
|
this.initializationPromise = null;
|
|
@@ -386,32 +406,41 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
386
406
|
}
|
|
387
407
|
async switchChain(params, init = false) {
|
|
388
408
|
super.checkSwitchChainRequirements(params, init);
|
|
409
|
+
await this.ensureInitialized();
|
|
389
410
|
const targetChainConfig = this.coreOptions.chains.find(c => c.chainId === params.chainId);
|
|
390
|
-
if (
|
|
391
|
-
|
|
411
|
+
if (!targetChainConfig) throw WalletLoginError.connectionError("Chain config is not available");
|
|
412
|
+
if (targetChainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
413
|
+
if (!this.solanaWallet) {
|
|
414
|
+
throw WalletLoginError.unsupportedOperation("switchChain requires a Solana client, but no Solana chains are configured.");
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// For solana case, we don't have the `switchChain` method like `evmClient`.
|
|
418
|
+
// So, we just need to sync with the connected solana chain to the Web3Auth state.
|
|
419
|
+
await this.forceSyncChainState(targetChainConfig);
|
|
392
420
|
return;
|
|
393
421
|
}
|
|
394
|
-
await this.ensureInitialized();
|
|
395
422
|
if (!this.evmClient) {
|
|
396
423
|
throw WalletLoginError.unsupportedOperation("switchChain requires an EVM client, but no EVM chains are configured.");
|
|
397
424
|
}
|
|
398
|
-
const
|
|
399
|
-
const chainConfiguration = chainConfig ? {
|
|
425
|
+
const chainConfiguration = targetChainConfig ? {
|
|
400
426
|
chainId: params.chainId,
|
|
401
|
-
chainName:
|
|
402
|
-
rpcUrls: [
|
|
403
|
-
blockExplorerUrls:
|
|
427
|
+
chainName: targetChainConfig.displayName,
|
|
428
|
+
rpcUrls: [targetChainConfig.rpcTarget],
|
|
429
|
+
blockExplorerUrls: targetChainConfig.blockExplorerUrl ? [targetChainConfig.blockExplorerUrl] : undefined,
|
|
404
430
|
nativeCurrency: {
|
|
405
|
-
name:
|
|
406
|
-
symbol:
|
|
407
|
-
decimals:
|
|
431
|
+
name: targetChainConfig.tickerName,
|
|
432
|
+
symbol: targetChainConfig.ticker,
|
|
433
|
+
decimals: targetChainConfig.decimals || 18
|
|
408
434
|
},
|
|
409
|
-
iconUrls:
|
|
435
|
+
iconUrls: targetChainConfig.logo ? [targetChainConfig.logo] : undefined
|
|
410
436
|
} : undefined;
|
|
411
437
|
await this.evmClient.switchChain({
|
|
412
438
|
chainId: params.chainId,
|
|
413
439
|
chainConfiguration
|
|
414
440
|
});
|
|
441
|
+
this.updateConnectorData({
|
|
442
|
+
chainId: params.chainId
|
|
443
|
+
});
|
|
415
444
|
}
|
|
416
445
|
async generateChallengeAndSign(authServerUrl, accounts, chainId) {
|
|
417
446
|
const activeChainConfig = this.resolveAuthChainConfig(chainId);
|
|
@@ -470,7 +499,12 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
470
499
|
}
|
|
471
500
|
await this.initializationPromise;
|
|
472
501
|
}
|
|
473
|
-
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Syncs the chain state with the Web3Auth state.
|
|
505
|
+
* @param chainConfig - The chain config to sync.
|
|
506
|
+
*/
|
|
507
|
+
async forceSyncChainState(chainConfig) {
|
|
474
508
|
var _this$evmProvider2;
|
|
475
509
|
// EVM connectors can switch chains, so align the wallet with the requested chain
|
|
476
510
|
// before Web3Auth persists the active chain in controller state.
|
|
@@ -491,13 +525,9 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
491
525
|
if (!connectedChainConfig) {
|
|
492
526
|
throw WalletLoginError.connectionError("Connected chain is not available in the chains config");
|
|
493
527
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
this.updateConnectorData({
|
|
498
|
-
chainId: connectedChainConfig.chainId
|
|
499
|
-
});
|
|
500
|
-
}
|
|
528
|
+
this.updateConnectorData({
|
|
529
|
+
chainId: chainConfig.chainId
|
|
530
|
+
});
|
|
501
531
|
}
|
|
502
532
|
}
|
|
503
533
|
}
|
|
@@ -512,6 +542,31 @@ class MetaMaskConnector extends BaseConnector {
|
|
|
512
542
|
// Keep the old fallback for callers that do not pass a chainId yet.
|
|
513
543
|
return isSolanaOnly ? this.coreOptions.chains.find(x => x.chainNamespace === CHAIN_NAMESPACES.SOLANA) : this.evmProvider ? this.coreOptions.chains.find(x => x.chainId === evmChainId) : undefined;
|
|
514
544
|
}
|
|
545
|
+
async clearMultichainWalletSessions() {
|
|
546
|
+
const addresses = new Set();
|
|
547
|
+
if (this.evmProvider) {
|
|
548
|
+
const evmAccounts = await this.evmProvider.request({
|
|
549
|
+
method: EVM_METHOD_TYPES.GET_ACCOUNTS
|
|
550
|
+
});
|
|
551
|
+
evmAccounts.forEach(account => addresses.add(account));
|
|
552
|
+
}
|
|
553
|
+
if (this.solanaProvider) {
|
|
554
|
+
this.solanaProvider.accounts.forEach(account => addresses.add(account.address));
|
|
555
|
+
}
|
|
556
|
+
if (addresses.size === 0) {
|
|
557
|
+
await this.clearWalletSession();
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// MetaMask can authorize both EVM and Solana accounts in one session, but BaseConnector
|
|
562
|
+
// caches SIWW tokens under one address at a time. Clear every connected address on disconnect.
|
|
563
|
+
for (const address of addresses) {
|
|
564
|
+
this.initSessionManager(address);
|
|
565
|
+
await this.clearWalletSession().catch(error => {
|
|
566
|
+
log.error("Failed to clear multichain wallet session", error);
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}
|
|
515
570
|
}
|
|
516
571
|
|
|
517
572
|
/**
|
|
@@ -541,4 +596,4 @@ const metaMaskConnector = params => {
|
|
|
541
596
|
};
|
|
542
597
|
};
|
|
543
598
|
|
|
544
|
-
export { metaMaskConnector };
|
|
599
|
+
export { METAMASK_ERC_6963_PROVIDER_RDNS, metaMaskConnector };
|
|
@@ -169,7 +169,7 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
169
169
|
}));
|
|
170
170
|
}
|
|
171
171
|
};
|
|
172
|
-
|
|
172
|
+
const connectorNamespace = this.connectorNamespace;
|
|
173
173
|
// if already connected
|
|
174
174
|
if (this.connected) {
|
|
175
175
|
await this.onConnectHandler({
|
|
@@ -179,7 +179,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
179
179
|
return {
|
|
180
180
|
ethereumProvider: this.provider,
|
|
181
181
|
solanaWallet: this._solanaWallet,
|
|
182
|
-
connectorName: this.name
|
|
182
|
+
connectorName: this.name,
|
|
183
|
+
connectorNamespace
|
|
183
184
|
};
|
|
184
185
|
}
|
|
185
186
|
if (this.status !== CONNECTOR_STATUS.CONNECTING) {
|
|
@@ -192,7 +193,8 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
192
193
|
return {
|
|
193
194
|
ethereumProvider: this.provider,
|
|
194
195
|
solanaWallet: this._solanaWallet,
|
|
195
|
-
connectorName: this.name
|
|
196
|
+
connectorName: this.name,
|
|
197
|
+
connectorNamespace
|
|
196
198
|
};
|
|
197
199
|
} catch (error) {
|
|
198
200
|
log.error("Wallet connect v2 connector error while connecting", error);
|
|
@@ -473,11 +475,10 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
473
475
|
connectorName: WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
474
476
|
reconnected: this.rehydrated,
|
|
475
477
|
ethereumProvider: this.provider,
|
|
476
|
-
solanaWallet: this._solanaWallet
|
|
478
|
+
solanaWallet: this._solanaWallet,
|
|
479
|
+
connectorNamespace: this.connectorNamespace
|
|
477
480
|
});
|
|
478
|
-
|
|
479
|
-
await this.getAuthTokenInfo();
|
|
480
|
-
}
|
|
481
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
481
482
|
}
|
|
482
483
|
subscribeEvents() {
|
|
483
484
|
if (!this.connector) throw WalletInitializationError.notReady("Wallet connector is not ready yet");
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { DEFAULT_EIP155_METHODS, DEFAULT_EIP_155_EVENTS, DEFAULT_SOLANA_EVENTS,
|
|
|
19
19
|
export { EIP1193_EVENTS } from './providers/base-provider/utils.js';
|
|
20
20
|
export { EIP_7702_SUPPORTED_SMART_ACCOUNTS, LOGIN_MODE, MODAL_SIGN_IN_METHODS, SMART_ACCOUNT_WALLET_SCOPE, SOLANA_CAIP_CHAIN_MAP, WALLET_REGISTRY_URL, WEB3AUTH_STATE_STORAGE_KEY, WIDGET_TYPE } from './base/constants.js';
|
|
21
21
|
export { EVM_PLUGINS, PLUGIN_EVENTS, PLUGIN_NAMESPACES, PLUGIN_STATUS, SOLANA_PLUGINS, WALLET_PLUGINS } from './base/plugin/IPlugin.js';
|
|
22
|
+
export { METAMASK_ERC_6963_PROVIDER_RDNS, metaMaskConnector } from './connectors/metamask-connector/metamaskConnector.js';
|
|
22
23
|
export { PROVIDER_EVENTS } from './base/provider/IProvider.js';
|
|
23
24
|
export { WalletConnectV2Provider } from './connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js';
|
|
24
25
|
export { WalletInitializationError, WalletLoginError, WalletOperationsError, WalletProviderError, Web3AuthError, isUserRejectedError } from './base/errors/index.js';
|
|
@@ -39,7 +40,6 @@ export { hasSolanaWalletStandardFeatures } from './connectors/injected-solana-co
|
|
|
39
40
|
export { injectedEvmConnector } from './connectors/injected-evm-connector/injectedEvmConnector.js';
|
|
40
41
|
export { log } from './base/loglevel.js';
|
|
41
42
|
export { makeAccountLinkingRequest, makeAccountUnlinkingRequest } from './account-linking/rest.js';
|
|
42
|
-
export { metaMaskConnector } from './connectors/metamask-connector/metamaskConnector.js';
|
|
43
43
|
export { walletConnectV2Connector } from './connectors/wallet-connect-v2-connector/walletConnectV2Connector.js';
|
|
44
44
|
export { walletServicesPlugin } from './plugins/wallet-services-plugin/plugin.js';
|
|
45
45
|
export { walletStandardConnector } from './connectors/injected-solana-connector/walletStandardConnector.js';
|