@web3auth/no-modal 11.1.0 → 11.2.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/account-linking/react.js +1 -0
- package/dist/lib.cjs/account-linking/vue.js +1 -0
- 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/connectors/auth-connector/authConnector.js +15 -6
- 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 +8 -7
- 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/errors/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +2 -1
- 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/connectors/auth-connector/authConnector.js +13 -5
- 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 +44 -21
- 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 +2 -2
|
@@ -19,6 +19,7 @@ require('jwt-decode');
|
|
|
19
19
|
require('../base/plugin/errors.js');
|
|
20
20
|
require('../base/plugin/IPlugin.js');
|
|
21
21
|
var useWeb3AuthInner = require('../react/hooks/useWeb3AuthInner.js');
|
|
22
|
+
require('./errors.js');
|
|
22
23
|
var rest = require('./rest.js');
|
|
23
24
|
|
|
24
25
|
const useLinkAccount = () => {
|
|
@@ -19,6 +19,7 @@ require('jwt-decode');
|
|
|
19
19
|
require('../base/plugin/errors.js');
|
|
20
20
|
require('../base/plugin/IPlugin.js');
|
|
21
21
|
var useWeb3AuthInner = require('../vue/composables/useWeb3AuthInner.js');
|
|
22
|
+
require('./errors.js');
|
|
22
23
|
var rest = require('./rest.js');
|
|
23
24
|
|
|
24
25
|
const useLinkAccount = () => {
|
|
@@ -128,17 +128,28 @@ class BaseConnector extends auth.SafeEventEmitter {
|
|
|
128
128
|
return cached;
|
|
129
129
|
}
|
|
130
130
|
async verifyAndAuthorize(params) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
let tokens;
|
|
132
|
+
try {
|
|
133
|
+
tokens = await baseControllers.verifySignedChallenge({
|
|
134
|
+
chainNamespace: params.chainNamespace,
|
|
135
|
+
signedMessage: params.signedMessage,
|
|
136
|
+
challenge: params.challenge,
|
|
137
|
+
connector: this.name,
|
|
138
|
+
authServer: params.authServer,
|
|
139
|
+
web3AuthClientId: this.coreOptions.clientId,
|
|
140
|
+
web3AuthNetwork: this.coreOptions.web3AuthNetwork,
|
|
141
|
+
sessionTimeout: this.coreOptions.sessionTime,
|
|
142
|
+
deviceInfo: baseControllers.getDeviceInfo()
|
|
143
|
+
});
|
|
144
|
+
} catch (error) {
|
|
145
|
+
if (error instanceof Response && error.status === 401) {
|
|
146
|
+
const body = await error.clone().json().catch(() => ({}));
|
|
147
|
+
if (body.message === "ACCESS_CONTROL_DENIED") {
|
|
148
|
+
throw index$1.WalletLoginError.userBlocked("User is blocked by the application", error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
142
153
|
await this.saveAuthTokenInfo(tokens);
|
|
143
154
|
const tokenInfo = {
|
|
144
155
|
idToken: tokens.idToken,
|
|
@@ -152,6 +163,26 @@ class BaseConnector extends auth.SafeEventEmitter {
|
|
|
152
163
|
});
|
|
153
164
|
return tokenInfo;
|
|
154
165
|
}
|
|
166
|
+
async authorizeOrDisconnect(getAuthTokenInfo, chainId) {
|
|
167
|
+
if (!getAuthTokenInfo) return;
|
|
168
|
+
try {
|
|
169
|
+
await this.getAuthTokenInfo(chainId);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
loglevel.log.error("Authorization failed after connect; disconnecting wallet to keep state consistent", error);
|
|
172
|
+
const wasRehydrated = this.rehydrated;
|
|
173
|
+
try {
|
|
174
|
+
// getAuthTokenInfo moved status to AUTHORIZING; restore CONNECTED so disconnect requirements pass.
|
|
175
|
+
if (!this.connected) this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
176
|
+
await this.disconnect();
|
|
177
|
+
} catch (disconnectError) {
|
|
178
|
+
loglevel.log.error("Failed to disconnect wallet after authorization error", disconnectError);
|
|
179
|
+
} finally {
|
|
180
|
+
// disconnect() resets rehydrated=false; restore so caller catch emits the right event.
|
|
181
|
+
this.rehydrated = wasRehydrated;
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
155
186
|
async clearWalletSession() {
|
|
156
187
|
if (!this.authSessionManager) return;
|
|
157
188
|
try {
|
|
@@ -159,6 +159,9 @@ class WalletLoginError extends Web3AuthError {
|
|
|
159
159
|
static userNotLoggedIn(extraMessage = "", cause) {
|
|
160
160
|
return WalletLoginError.fromCode(5119, extraMessage, cause);
|
|
161
161
|
}
|
|
162
|
+
static userBlocked(extraMessage = "", cause) {
|
|
163
|
+
return WalletLoginError.fromCode(5120, extraMessage, cause);
|
|
164
|
+
}
|
|
162
165
|
}
|
|
163
166
|
_defineProperty(WalletLoginError, "messages", {
|
|
164
167
|
5000: "Custom",
|
|
@@ -170,7 +173,8 @@ _defineProperty(WalletLoginError, "messages", {
|
|
|
170
173
|
5116: "Chain config has not been added. Please add the chain config before calling switchChain",
|
|
171
174
|
5117: "Unsupported operation",
|
|
172
175
|
5118: "useSFAKey flag is enabled but SFA key is not available",
|
|
173
|
-
5119: "User not logged in."
|
|
176
|
+
5119: "User not logged in.",
|
|
177
|
+
5120: "User is blocked by the application"
|
|
174
178
|
});
|
|
175
179
|
class WalletOperationsError extends Web3AuthError {
|
|
176
180
|
constructor(code, message, cause) {
|
|
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
145
145
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
|
|
146
146
|
};
|
|
147
147
|
};
|
|
148
|
-
const sdkVersion = "11.
|
|
148
|
+
const sdkVersion = "11.2.0";
|
|
149
149
|
const getErrorAnalyticsProperties = error => {
|
|
150
150
|
try {
|
|
151
151
|
const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -9,6 +9,8 @@ var securePubSub = require('@toruslabs/secure-pub-sub');
|
|
|
9
9
|
var auth = require('@web3auth/auth');
|
|
10
10
|
var wsEmbed = require('@web3auth/ws-embed');
|
|
11
11
|
var deepmerge = require('deepmerge');
|
|
12
|
+
var errors = require('../../account-linking/errors.js');
|
|
13
|
+
var rest = require('../../account-linking/rest.js');
|
|
12
14
|
var analytics = require('../../base/analytics.js');
|
|
13
15
|
var IChainInterface = require('../../base/chain/IChainInterface.js');
|
|
14
16
|
var baseConnector = require('../../base/connector/baseConnector.js');
|
|
@@ -24,8 +26,6 @@ var utils = require('../../base/utils.js');
|
|
|
24
26
|
var index$1 = require('../../base/wallet/index.js');
|
|
25
27
|
var utils$1 = require('../utils.js');
|
|
26
28
|
var authSolanaWallet = require('./authSolanaWallet.js');
|
|
27
|
-
var errors = require('../../account-linking/errors.js');
|
|
28
|
-
var rest = require('../../account-linking/rest.js');
|
|
29
29
|
|
|
30
30
|
// Auth connections that have been deprecated and are no longer supported by the SDK.
|
|
31
31
|
// Passing any of these as `authConnection` results in a hard error so consumers
|
|
@@ -209,7 +209,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
209
209
|
return {
|
|
210
210
|
ethereumProvider: this.provider,
|
|
211
211
|
solanaWallet: this._solanaWallet,
|
|
212
|
-
connectorName: this.name
|
|
212
|
+
connectorName: this.name,
|
|
213
|
+
connectorNamespace: this.connectorNamespace
|
|
213
214
|
};
|
|
214
215
|
} catch (error) {
|
|
215
216
|
var _error$message;
|
|
@@ -816,6 +817,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
816
817
|
}
|
|
817
818
|
throw index.WalletLoginError.sfaKeyNotFound("This typically occurs when the authentication method used does not provide SFA keys (e.g., default auth connection).");
|
|
818
819
|
}
|
|
820
|
+
const connectorNamespace = this.connectorNamespace;
|
|
819
821
|
// setup WS embed if chainNamespace is EIP155 or SOLANA
|
|
820
822
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 || chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
821
823
|
// wait for ws embed instance to be ready.
|
|
@@ -841,7 +843,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
841
843
|
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
842
844
|
reconnected: this.rehydrated,
|
|
843
845
|
ethereumProvider: this.provider,
|
|
844
|
-
solanaWallet: this._solanaWallet
|
|
846
|
+
solanaWallet: this._solanaWallet,
|
|
847
|
+
connectorNamespace
|
|
845
848
|
});
|
|
846
849
|
if (params.getAuthTokenInfo) {
|
|
847
850
|
await this.getAuthTokenInfo();
|
|
@@ -858,7 +861,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
858
861
|
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
859
862
|
ethereumProvider: this.provider,
|
|
860
863
|
solanaWallet: this._solanaWallet,
|
|
861
|
-
reconnected: this.rehydrated
|
|
864
|
+
reconnected: this.rehydrated,
|
|
865
|
+
connectorNamespace
|
|
862
866
|
});
|
|
863
867
|
}
|
|
864
868
|
}
|
|
@@ -959,7 +963,12 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
959
963
|
if (error instanceof index.Web3AuthError) {
|
|
960
964
|
throw error;
|
|
961
965
|
}
|
|
962
|
-
|
|
966
|
+
const errorMessage = error instanceof Error ? error.message : error;
|
|
967
|
+
if (errorMessage === "Access control denied") {
|
|
968
|
+
reject(index.WalletLoginError.userBlocked(errorMessage, error));
|
|
969
|
+
return;
|
|
970
|
+
}
|
|
971
|
+
reject(index.WalletLoginError.connectionError(errorMessage || "Failed to login with social"));
|
|
963
972
|
});
|
|
964
973
|
});
|
|
965
974
|
}
|
|
@@ -112,15 +112,15 @@ class CoinbaseConnector extends baseEvmConnector.BaseEvmConnector {
|
|
|
112
112
|
connectorName: index.WALLET_CONNECTORS.COINBASE,
|
|
113
113
|
reconnected: this.rehydrated,
|
|
114
114
|
ethereumProvider: this.provider,
|
|
115
|
-
solanaWallet: null
|
|
115
|
+
solanaWallet: null,
|
|
116
|
+
connectorNamespace: this.connectorNamespace
|
|
116
117
|
});
|
|
117
|
-
|
|
118
|
-
await this.getAuthTokenInfo();
|
|
119
|
-
}
|
|
118
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
120
119
|
return {
|
|
121
120
|
ethereumProvider: this.provider,
|
|
122
121
|
solanaWallet: null,
|
|
123
|
-
connectorName: this.name
|
|
122
|
+
connectorName: this.name,
|
|
123
|
+
connectorNamespace: this.connectorNamespace
|
|
124
124
|
};
|
|
125
125
|
} catch (error) {
|
|
126
126
|
// ready again to be connected
|
|
@@ -101,19 +101,20 @@ class InjectedEvmConnector extends baseEvmConnector.BaseEvmConnector {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
|
|
104
|
+
const connectorNamespace = this.connectorNamespace;
|
|
104
105
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
105
106
|
connectorName: this.name,
|
|
106
107
|
reconnected: this.rehydrated,
|
|
107
108
|
ethereumProvider: this.injectedProvider,
|
|
108
|
-
solanaWallet: null
|
|
109
|
+
solanaWallet: null,
|
|
110
|
+
connectorNamespace
|
|
109
111
|
});
|
|
110
|
-
|
|
111
|
-
await this.getAuthTokenInfo();
|
|
112
|
-
}
|
|
112
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
113
113
|
return {
|
|
114
114
|
ethereumProvider: this.injectedProvider,
|
|
115
115
|
solanaWallet: null,
|
|
116
|
-
connectorName: this.name
|
|
116
|
+
connectorName: this.name,
|
|
117
|
+
connectorNamespace
|
|
117
118
|
};
|
|
118
119
|
} catch (error) {
|
|
119
120
|
// ready again to be connected
|
|
@@ -88,19 +88,20 @@ class WalletStandardConnector extends baseSolanaConnector.BaseSolanaConnector {
|
|
|
88
88
|
}
|
|
89
89
|
if (this.wallet.accounts.length === 0) throw index.WalletLoginError.connectionError();
|
|
90
90
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
91
|
+
const connectorNamespace = this.connectorNamespace;
|
|
91
92
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
92
93
|
connectorName: this.name,
|
|
93
94
|
reconnected: this.rehydrated,
|
|
94
95
|
ethereumProvider: null,
|
|
95
|
-
solanaWallet: this.solanaWallet
|
|
96
|
+
solanaWallet: this.solanaWallet,
|
|
97
|
+
connectorNamespace
|
|
96
98
|
});
|
|
97
|
-
|
|
98
|
-
await this.getAuthTokenInfo();
|
|
99
|
-
}
|
|
99
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
100
100
|
return {
|
|
101
101
|
ethereumProvider: null,
|
|
102
102
|
solanaWallet: this.solanaWallet,
|
|
103
|
-
connectorName: this.name
|
|
103
|
+
connectorName: this.name,
|
|
104
|
+
connectorNamespace
|
|
104
105
|
};
|
|
105
106
|
} catch (error) {
|
|
106
107
|
// ready again to be connected
|
|
@@ -19,7 +19,7 @@ require('@web3auth/auth');
|
|
|
19
19
|
require('jwt-decode');
|
|
20
20
|
require('../../base/constants.js');
|
|
21
21
|
var index$1 = require('../../base/errors/index.js');
|
|
22
|
-
require('../../base/loglevel.js');
|
|
22
|
+
var loglevel = require('../../base/loglevel.js');
|
|
23
23
|
require('../../base/plugin/errors.js');
|
|
24
24
|
require('../../base/plugin/IPlugin.js');
|
|
25
25
|
var utils = require('../../base/utils.js');
|
|
@@ -27,6 +27,11 @@ var index = require('../../base/wallet/index.js');
|
|
|
27
27
|
var utils$1 = require('../utils.js');
|
|
28
28
|
var solana = require('../../base/wallet/solana.js');
|
|
29
29
|
|
|
30
|
+
// `@metamask/connect-evm` announces its SDK-backed provider over EIP-6963 with this
|
|
31
|
+
// RDNS value. Web3Auth uses the dedicated `metaMaskConnector` for MetaMask, so MIPD
|
|
32
|
+
// discovery should ignore this provider to avoid treating the QR/deeplink transport
|
|
33
|
+
// as a native injected wallet.
|
|
34
|
+
const METAMASK_ERC_6963_PROVIDER_RDNS = "io.metamask.mmc";
|
|
30
35
|
class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
31
36
|
constructor(connectorOptions) {
|
|
32
37
|
super(connectorOptions);
|
|
@@ -195,13 +200,24 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
195
200
|
if (coreStatus === "connected" && options.autoConnect) {
|
|
196
201
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
197
202
|
this.rehydrated = true;
|
|
203
|
+
// Force sync the chain state before connect with rehydrated state.
|
|
204
|
+
// during rehydration, `createEVMClient` (from above) cause re-creating session for connected the evm provider,
|
|
205
|
+
// triggering `switchChain` internally and unintentionally update the connector data with the new chain id.
|
|
206
|
+
// This creates issue in rehydration flow, where Web3Auth connects to the incorrect chain id, not the rehydrated chain id.
|
|
207
|
+
// Force sync the chain state with the rehydrated chain id to avoid this issue.
|
|
208
|
+
await this.forceSyncChainState(chainConfig);
|
|
198
209
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
199
210
|
connectorName: index.WALLET_CONNECTORS.METAMASK,
|
|
200
211
|
reconnected: true,
|
|
201
212
|
ethereumProvider: this.evmProvider,
|
|
202
|
-
solanaWallet: this.solanaProvider
|
|
213
|
+
solanaWallet: this.solanaProvider,
|
|
214
|
+
connectorNamespace: this.connectorNamespace
|
|
203
215
|
});
|
|
204
|
-
|
|
216
|
+
try {
|
|
217
|
+
await this.authorizeOrDisconnect(options.getAuthTokenInfo, options.chainId);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
this.emit(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
220
|
+
}
|
|
205
221
|
} else if (coreStatus === "connected" || coreStatus === "loaded" || coreStatus === "disconnected" || coreStatus === "pending") {
|
|
206
222
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
207
223
|
this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.METAMASK);
|
|
@@ -266,7 +282,7 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
266
282
|
}
|
|
267
283
|
// sync the chain state after connect
|
|
268
284
|
// metamask might not be connected to the requested chain, so we need to sync the chain state to/from Web3Auth state after connect.
|
|
269
|
-
await this.
|
|
285
|
+
await this.forceSyncChainState(chainConfig);
|
|
270
286
|
// check if connected
|
|
271
287
|
if (this.multichainClient.status !== "connected") {
|
|
272
288
|
throw index$1.WalletLoginError.notConnectedError("Failed to connect with MetaMask wallet");
|
|
@@ -284,15 +300,15 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
284
300
|
connectorName: index.WALLET_CONNECTORS.METAMASK,
|
|
285
301
|
reconnected: this.rehydrated,
|
|
286
302
|
ethereumProvider: this.evmProvider,
|
|
287
|
-
solanaWallet: this.solanaProvider
|
|
303
|
+
solanaWallet: this.solanaProvider,
|
|
304
|
+
connectorNamespace: this.connectorNamespace
|
|
288
305
|
});
|
|
289
|
-
|
|
290
|
-
await this.getAuthTokenInfo(chainId);
|
|
291
|
-
}
|
|
306
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo, chainId);
|
|
292
307
|
return {
|
|
293
308
|
ethereumProvider: this.evmProvider,
|
|
294
309
|
solanaWallet: this.solanaProvider,
|
|
295
|
-
connectorName: this.name
|
|
310
|
+
connectorName: this.name,
|
|
311
|
+
connectorNamespace: this.connectorNamespace
|
|
296
312
|
};
|
|
297
313
|
} catch (error) {
|
|
298
314
|
// Ready again to be connected
|
|
@@ -317,9 +333,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
317
333
|
}) {
|
|
318
334
|
if (!this.multichainClient) throw index$1.WalletLoginError.connectionError("Multichain client is not available");
|
|
319
335
|
this.checkDisconnectionRequirements();
|
|
320
|
-
await this.
|
|
336
|
+
await this.clearMultichainWalletSessions();
|
|
321
337
|
// Disconnect using the multichain client
|
|
322
|
-
|
|
338
|
+
if (this.multichainClient.status === "connected") {
|
|
339
|
+
await this.multichainClient.disconnect();
|
|
340
|
+
}
|
|
323
341
|
if (options.cleanup) {
|
|
324
342
|
this.status = constants.CONNECTOR_STATUS.NOT_READY;
|
|
325
343
|
this.initializationPromise = null;
|
|
@@ -375,32 +393,40 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
375
393
|
}
|
|
376
394
|
async switchChain(params, init = false) {
|
|
377
395
|
super.checkSwitchChainRequirements(params, init);
|
|
396
|
+
await this.ensureInitialized();
|
|
378
397
|
const targetChainConfig = this.coreOptions.chains.find(c => c.chainId === params.chainId);
|
|
379
|
-
if (
|
|
380
|
-
|
|
398
|
+
if (!targetChainConfig) throw index$1.WalletLoginError.connectionError("Chain config is not available");
|
|
399
|
+
if (targetChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
400
|
+
if (!this.solanaWallet) {
|
|
401
|
+
throw index$1.WalletLoginError.unsupportedOperation("switchChain requires a Solana client, but no Solana chains are configured.");
|
|
402
|
+
}
|
|
403
|
+
// For solana case, we don't have the `switchChain` method like `evmClient`.
|
|
404
|
+
// So, we just need to sync with the connected solana chain to the Web3Auth state.
|
|
405
|
+
await this.forceSyncChainState(targetChainConfig);
|
|
381
406
|
return;
|
|
382
407
|
}
|
|
383
|
-
await this.ensureInitialized();
|
|
384
408
|
if (!this.evmClient) {
|
|
385
409
|
throw index$1.WalletLoginError.unsupportedOperation("switchChain requires an EVM client, but no EVM chains are configured.");
|
|
386
410
|
}
|
|
387
|
-
const
|
|
388
|
-
const chainConfiguration = chainConfig ? {
|
|
411
|
+
const chainConfiguration = targetChainConfig ? {
|
|
389
412
|
chainId: params.chainId,
|
|
390
|
-
chainName:
|
|
391
|
-
rpcUrls: [
|
|
392
|
-
blockExplorerUrls:
|
|
413
|
+
chainName: targetChainConfig.displayName,
|
|
414
|
+
rpcUrls: [targetChainConfig.rpcTarget],
|
|
415
|
+
blockExplorerUrls: targetChainConfig.blockExplorerUrl ? [targetChainConfig.blockExplorerUrl] : undefined,
|
|
393
416
|
nativeCurrency: {
|
|
394
|
-
name:
|
|
395
|
-
symbol:
|
|
396
|
-
decimals:
|
|
417
|
+
name: targetChainConfig.tickerName,
|
|
418
|
+
symbol: targetChainConfig.ticker,
|
|
419
|
+
decimals: targetChainConfig.decimals || 18
|
|
397
420
|
},
|
|
398
|
-
iconUrls:
|
|
421
|
+
iconUrls: targetChainConfig.logo ? [targetChainConfig.logo] : undefined
|
|
399
422
|
} : undefined;
|
|
400
423
|
await this.evmClient.switchChain({
|
|
401
424
|
chainId: params.chainId,
|
|
402
425
|
chainConfiguration
|
|
403
426
|
});
|
|
427
|
+
this.updateConnectorData({
|
|
428
|
+
chainId: params.chainId
|
|
429
|
+
});
|
|
404
430
|
}
|
|
405
431
|
async generateChallengeAndSign(authServerUrl, accounts, chainId) {
|
|
406
432
|
const activeChainConfig = this.resolveAuthChainConfig(chainId);
|
|
@@ -458,7 +484,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
458
484
|
}
|
|
459
485
|
await this.initializationPromise;
|
|
460
486
|
}
|
|
461
|
-
|
|
487
|
+
/**
|
|
488
|
+
* Syncs the chain state with the Web3Auth state.
|
|
489
|
+
* @param chainConfig - The chain config to sync.
|
|
490
|
+
*/
|
|
491
|
+
async forceSyncChainState(chainConfig) {
|
|
462
492
|
var _this$evmProvider2;
|
|
463
493
|
// EVM connectors can switch chains, so align the wallet with the requested chain
|
|
464
494
|
// before Web3Auth persists the active chain in controller state.
|
|
@@ -479,13 +509,9 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
479
509
|
if (!connectedChainConfig) {
|
|
480
510
|
throw index$1.WalletLoginError.connectionError("Connected chain is not available in the chains config");
|
|
481
511
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
this.updateConnectorData({
|
|
486
|
-
chainId: connectedChainConfig.chainId
|
|
487
|
-
});
|
|
488
|
-
}
|
|
512
|
+
this.updateConnectorData({
|
|
513
|
+
chainId: chainConfig.chainId
|
|
514
|
+
});
|
|
489
515
|
}
|
|
490
516
|
}
|
|
491
517
|
}
|
|
@@ -499,6 +525,30 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
499
525
|
// Keep the old fallback for callers that do not pass a chainId yet.
|
|
500
526
|
return isSolanaOnly ? this.coreOptions.chains.find(x => x.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) : this.evmProvider ? this.coreOptions.chains.find(x => x.chainId === evmChainId) : undefined;
|
|
501
527
|
}
|
|
528
|
+
async clearMultichainWalletSessions() {
|
|
529
|
+
const addresses = new Set();
|
|
530
|
+
if (this.evmProvider) {
|
|
531
|
+
const evmAccounts = await this.evmProvider.request({
|
|
532
|
+
method: wsEmbed.EVM_METHOD_TYPES.GET_ACCOUNTS
|
|
533
|
+
});
|
|
534
|
+
evmAccounts.forEach(account => addresses.add(account));
|
|
535
|
+
}
|
|
536
|
+
if (this.solanaProvider) {
|
|
537
|
+
this.solanaProvider.accounts.forEach(account => addresses.add(account.address));
|
|
538
|
+
}
|
|
539
|
+
if (addresses.size === 0) {
|
|
540
|
+
await this.clearWalletSession();
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
// MetaMask can authorize both EVM and Solana accounts in one session, but BaseConnector
|
|
544
|
+
// caches SIWW tokens under one address at a time. Clear every connected address on disconnect.
|
|
545
|
+
for (const address of addresses) {
|
|
546
|
+
this.initSessionManager(address);
|
|
547
|
+
await this.clearWalletSession().catch(error => {
|
|
548
|
+
loglevel.log.error("Failed to clear multichain wallet session", error);
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}
|
|
502
552
|
}
|
|
503
553
|
/**
|
|
504
554
|
* Factory function to create a MetaMask connector
|
|
@@ -527,4 +577,5 @@ const metaMaskConnector = params => {
|
|
|
527
577
|
};
|
|
528
578
|
};
|
|
529
579
|
|
|
580
|
+
exports.METAMASK_ERC_6963_PROVIDER_RDNS = METAMASK_ERC_6963_PROVIDER_RDNS;
|
|
530
581
|
exports.metaMaskConnector = metaMaskConnector;
|
|
@@ -175,6 +175,7 @@ class WalletConnectV2Connector extends baseConnector.BaseConnector {
|
|
|
175
175
|
}));
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
|
+
const connectorNamespace = this.connectorNamespace;
|
|
178
179
|
// if already connected
|
|
179
180
|
if (this.connected) {
|
|
180
181
|
await this.onConnectHandler({
|
|
@@ -184,7 +185,8 @@ class WalletConnectV2Connector extends baseConnector.BaseConnector {
|
|
|
184
185
|
return {
|
|
185
186
|
ethereumProvider: this.provider,
|
|
186
187
|
solanaWallet: this._solanaWallet,
|
|
187
|
-
connectorName: this.name
|
|
188
|
+
connectorName: this.name,
|
|
189
|
+
connectorNamespace
|
|
188
190
|
};
|
|
189
191
|
}
|
|
190
192
|
if (this.status !== constants.CONNECTOR_STATUS.CONNECTING) {
|
|
@@ -197,7 +199,8 @@ class WalletConnectV2Connector extends baseConnector.BaseConnector {
|
|
|
197
199
|
return {
|
|
198
200
|
ethereumProvider: this.provider,
|
|
199
201
|
solanaWallet: this._solanaWallet,
|
|
200
|
-
connectorName: this.name
|
|
202
|
+
connectorName: this.name,
|
|
203
|
+
connectorNamespace
|
|
201
204
|
};
|
|
202
205
|
} catch (error) {
|
|
203
206
|
loglevel.log.error("Wallet connect v2 connector error while connecting", error);
|
|
@@ -475,11 +478,10 @@ class WalletConnectV2Connector extends baseConnector.BaseConnector {
|
|
|
475
478
|
connectorName: index.WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
476
479
|
reconnected: this.rehydrated,
|
|
477
480
|
ethereumProvider: this.provider,
|
|
478
|
-
solanaWallet: this._solanaWallet
|
|
481
|
+
solanaWallet: this._solanaWallet,
|
|
482
|
+
connectorNamespace: this.connectorNamespace
|
|
479
483
|
});
|
|
480
|
-
|
|
481
|
-
await this.getAuthTokenInfo();
|
|
482
|
-
}
|
|
484
|
+
await this.authorizeOrDisconnect(getAuthTokenInfo);
|
|
483
485
|
}
|
|
484
486
|
subscribeEvents() {
|
|
485
487
|
if (!this.connector) throw index$1.WalletInitializationError.notReady("Wallet connector is not ready yet");
|
package/dist/lib.cjs/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var errors = require('./account-linking/errors.js');
|
|
4
|
+
var rest = require('./account-linking/rest.js');
|
|
3
5
|
var analytics = require('./base/analytics.js');
|
|
4
6
|
var IChainInterface = require('./base/chain/IChainInterface.js');
|
|
5
7
|
var index$2 = require('./base/composables/index.js');
|
|
@@ -38,16 +40,19 @@ var utils = require('./providers/base-provider/utils.js');
|
|
|
38
40
|
var ethRpcMiddlewares = require('./providers/ethereum-provider/rpc/ethRpcMiddlewares.js');
|
|
39
41
|
var jrpcClient = require('./providers/ethereum-provider/rpc/jrpcClient.js');
|
|
40
42
|
var walletMiddleware = require('./providers/ethereum-provider/rpc/walletMiddleware.js');
|
|
41
|
-
var errors = require('./account-linking/errors.js');
|
|
42
43
|
var wsEmbed = require('@web3auth/ws-embed');
|
|
43
44
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
44
45
|
var app = require('@wallet-standard/app');
|
|
45
46
|
var solana = require('./base/wallet/solana.js');
|
|
46
|
-
var rest = require('./account-linking/rest.js');
|
|
47
47
|
var walletStandardConnector = require('./connectors/injected-solana-connector/walletStandardConnector.js');
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
exports.AccountLinkingError = errors.AccountLinkingError;
|
|
52
|
+
exports.formatAccountLinkingErrorMessage = errors.formatAccountLinkingErrorMessage;
|
|
53
|
+
exports.getAccountLinkingRequestError = errors.getAccountLinkingRequestError;
|
|
54
|
+
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
55
|
+
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
51
56
|
exports.ANALYTICS_EVENTS = analytics.ANALYTICS_EVENTS;
|
|
52
57
|
exports.ANALYTICS_INTEGRATION_TYPE = analytics.ANALYTICS_INTEGRATION_TYPE;
|
|
53
58
|
exports.ANALYTICS_SDK_TYPE = analytics.ANALYTICS_SDK_TYPE;
|
|
@@ -148,6 +153,7 @@ Object.defineProperty(exports, "createMipd", {
|
|
|
148
153
|
get: function () { return mipd.createStore; }
|
|
149
154
|
});
|
|
150
155
|
exports.hasSolanaWalletStandardFeatures = index$3.hasSolanaWalletStandardFeatures;
|
|
156
|
+
exports.METAMASK_ERC_6963_PROVIDER_RDNS = metamaskConnector.METAMASK_ERC_6963_PROVIDER_RDNS;
|
|
151
157
|
exports.metaMaskConnector = metamaskConnector.metaMaskConnector;
|
|
152
158
|
Object.defineProperty(exports, "DEFAULT_EIP155_METHODS", {
|
|
153
159
|
enumerable: true,
|
|
@@ -215,9 +221,6 @@ exports.createEthChainSwitchMiddleware = ethRpcMiddlewares.createEthChainSwitchM
|
|
|
215
221
|
exports.createEthMiddleware = ethRpcMiddlewares.createEthMiddleware;
|
|
216
222
|
exports.createEthJsonRpcClient = jrpcClient.createEthJsonRpcClient;
|
|
217
223
|
exports.createWalletMiddlewareV2 = walletMiddleware.createWalletMiddlewareV2;
|
|
218
|
-
exports.AccountLinkingError = errors.AccountLinkingError;
|
|
219
|
-
exports.formatAccountLinkingErrorMessage = errors.formatAccountLinkingErrorMessage;
|
|
220
|
-
exports.getAccountLinkingRequestError = errors.getAccountLinkingRequestError;
|
|
221
224
|
Object.defineProperty(exports, "BUTTON_POSITION", {
|
|
222
225
|
enumerable: true,
|
|
223
226
|
get: function () { return wsEmbed.BUTTON_POSITION; }
|
|
@@ -242,6 +245,4 @@ exports.getSolanaChainByChainConfig = solana.getSolanaChainByChainConfig;
|
|
|
242
245
|
exports.walletSignAndSendTransaction = solana.walletSignAndSendTransaction;
|
|
243
246
|
exports.walletSignMessage = solana.walletSignMessage;
|
|
244
247
|
exports.walletSignTransaction = solana.walletSignTransaction;
|
|
245
|
-
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
246
|
-
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
247
248
|
exports.walletStandardConnector = walletStandardConnector.walletStandardConnector;
|