@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
|
@@ -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
|
@@ -148,6 +148,7 @@ Object.defineProperty(exports, "createMipd", {
|
|
|
148
148
|
get: function () { return mipd.createStore; }
|
|
149
149
|
});
|
|
150
150
|
exports.hasSolanaWalletStandardFeatures = index$3.hasSolanaWalletStandardFeatures;
|
|
151
|
+
exports.METAMASK_ERC_6963_PROVIDER_RDNS = metamaskConnector.METAMASK_ERC_6963_PROVIDER_RDNS;
|
|
151
152
|
exports.metaMaskConnector = metamaskConnector.metaMaskConnector;
|
|
152
153
|
Object.defineProperty(exports, "DEFAULT_EIP155_METHODS", {
|
|
153
154
|
enumerable: true,
|
package/dist/lib.cjs/noModal.js
CHANGED
|
@@ -56,7 +56,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
56
56
|
idToken: null,
|
|
57
57
|
accessToken: null,
|
|
58
58
|
refreshToken: null,
|
|
59
|
-
activeAccount: null
|
|
59
|
+
activeAccount: null,
|
|
60
|
+
cachedConnectorNamespace: null
|
|
60
61
|
});
|
|
61
62
|
if (!options.clientId) throw index.WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
62
63
|
if (options.enableLogging) loglevel.log.enableAll();else loglevel.log.setLevel("error");
|
|
@@ -248,6 +249,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
248
249
|
await this.setState({
|
|
249
250
|
primaryConnectorName: null,
|
|
250
251
|
cachedConnector: null,
|
|
252
|
+
cachedConnectorNamespace: null,
|
|
251
253
|
currentChainId: null,
|
|
252
254
|
idToken: null,
|
|
253
255
|
accessToken: null,
|
|
@@ -783,7 +785,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
783
785
|
chains: this.coreOptions.chains
|
|
784
786
|
});
|
|
785
787
|
// sync chainId
|
|
786
|
-
this.commonJRPCProvider.on("chainChanged", async chainId =>
|
|
788
|
+
this.commonJRPCProvider.on("chainChanged", async chainId => {
|
|
789
|
+
await this.setCurrentChain(chainId);
|
|
790
|
+
});
|
|
787
791
|
}
|
|
788
792
|
async setupConnector(connector) {
|
|
789
793
|
this.subscribeToConnectorEvents(connector);
|
|
@@ -847,12 +851,19 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
847
851
|
injectedEvmConnector
|
|
848
852
|
} = await Promise.resolve().then(function () { return require('./connectors/injected-evm-connector/index.js'); });
|
|
849
853
|
const evmMipd = createMipd();
|
|
854
|
+
// `@metamask/connect-evm` SDK announces its own EIP-6963 provider (`io.metamask.mmc`) so
|
|
855
|
+
// it can be discovered by generic wallet pickers. We already register MetaMask via
|
|
856
|
+
// `metaMaskConnector`, so we must exclude the SDK-announced provider here; otherwise
|
|
857
|
+
// it is misclassified as an injected wallet and the modal shows MetaMask as installed,
|
|
858
|
+
// even when the user does not have the extension installed.
|
|
859
|
+
const isNonSdkAnnouncedProvider = providerDetail => providerDetail.info.rdns !== metamaskConnector.METAMASK_ERC_6963_PROVIDER_RDNS;
|
|
850
860
|
// subscribe to new injected connectors
|
|
851
861
|
evmMipd.subscribe(providerDetails => {
|
|
852
|
-
const
|
|
862
|
+
const filteredProviderDetails = providerDetails.filter(isNonSdkAnnouncedProvider);
|
|
863
|
+
const newConnectors = filteredProviderDetails.map(providerDetail => injectedEvmConnector(providerDetail)(config));
|
|
853
864
|
this.setConnectors(newConnectors);
|
|
854
865
|
});
|
|
855
|
-
connectorFns.push(...evmMipd.getProviders().map(injectedEvmConnector));
|
|
866
|
+
connectorFns.push(...evmMipd.getProviders().filter(isNonSdkAnnouncedProvider).map(injectedEvmConnector));
|
|
856
867
|
}
|
|
857
868
|
}
|
|
858
869
|
// add WalletConnectV2 connector if external wallets are enabled
|
|
@@ -984,7 +995,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
984
995
|
await this.setState({
|
|
985
996
|
primaryConnectorName: data.connectorName
|
|
986
997
|
});
|
|
987
|
-
this.cacheWallet(data.connectorName);
|
|
998
|
+
this.cacheWallet(data.connectorName, data.connectorNamespace);
|
|
988
999
|
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
989
1000
|
const pendingUserConsent = this.consentRequired && !this.state.hasUserConsent;
|
|
990
1001
|
if (pendingUserConsent && !isConnectAndSign) {
|
|
@@ -999,7 +1010,6 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
999
1010
|
if (this.status !== constants.CONNECTOR_STATUS.CONSENT_REQUIRING && this.status !== constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
1000
1011
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
1001
1012
|
}
|
|
1002
|
-
loglevel.log.debug("connected", this.status, this.primaryConnectorName);
|
|
1003
1013
|
// Defer plugin connection until consent is accepted; otherwise plugins would start before the consent step completes.
|
|
1004
1014
|
// `completeConsentAcceptance` connects the plugins once the user accepts the consent.
|
|
1005
1015
|
if (!pendingUserConsent) {
|
|
@@ -1114,7 +1124,14 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1114
1124
|
// External wallets can resolve to a different active chain than the requested one,
|
|
1115
1125
|
// so let connector-reported chain updates reconcile Web3Auth state after connect.
|
|
1116
1126
|
if (typeof (data === null || data === void 0 ? void 0 : data.data) === "object" && (data === null || data === void 0 ? void 0 : data.data) !== null && "chainId" in data.data && typeof data.data.chainId === "string") {
|
|
1127
|
+
const previousChain = this.currentChain;
|
|
1117
1128
|
await this.setCurrentChain(data.data.chainId);
|
|
1129
|
+
const currentChain = this.currentChain;
|
|
1130
|
+
const connectorEthereumProvider = connector.provider;
|
|
1131
|
+
if ((previousChain === null || previousChain === void 0 ? void 0 : previousChain.chainNamespace) !== (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) && (currentChain === null || currentChain === void 0 ? void 0 : currentChain.chainNamespace) === baseControllers.CHAIN_NAMESPACES.EIP155 && connectorEthereumProvider) {
|
|
1132
|
+
// from sol -> evm namespace switch, we need to re-create AccountAbstractionProvider
|
|
1133
|
+
await this.bindPrimaryEthereumSigningProxy(connectorEthereumProvider, connector.name);
|
|
1134
|
+
}
|
|
1118
1135
|
}
|
|
1119
1136
|
loglevel.log.debug("connector data updated", data);
|
|
1120
1137
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, data);
|
|
@@ -1168,7 +1185,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1168
1185
|
}
|
|
1169
1186
|
checkIfAutoConnect(connector) {
|
|
1170
1187
|
var _this$currentChain3;
|
|
1171
|
-
let autoConnect = this.cachedConnector === connector.name;
|
|
1188
|
+
let autoConnect = this.cachedConnector === connector.name && this.state.cachedConnectorNamespace === connector.connectorNamespace;
|
|
1172
1189
|
if (autoConnect && (_this$currentChain3 = this.currentChain) !== null && _this$currentChain3 !== void 0 && _this$currentChain3.chainNamespace) {
|
|
1173
1190
|
if (connector.connectorNamespace === IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN) autoConnect = true;else autoConnect = connector.connectorNamespace === this.currentChain.chainNamespace;
|
|
1174
1191
|
}
|
|
@@ -1181,10 +1198,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1181
1198
|
getInitialChainIdForConnector(connector) {
|
|
1182
1199
|
var _initialChain;
|
|
1183
1200
|
let initialChain = this.currentChain;
|
|
1184
|
-
|
|
1201
|
+
const defaultChainId = this.coreOptions.defaultChainId;
|
|
1202
|
+
const isMultiChainConnector = connector.connectorNamespace === IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN;
|
|
1203
|
+
// if the connector is a multi-chain connector and a default chain id is set, use the default chain id
|
|
1204
|
+
if (isMultiChainConnector && defaultChainId) {
|
|
1205
|
+
initialChain = this.coreOptions.chains.find(chain => chain.chainId === defaultChainId) || this.currentChain;
|
|
1206
|
+
} else if (((_initialChain = initialChain) === null || _initialChain === void 0 ? void 0 : _initialChain.chainNamespace) !== connector.connectorNamespace && connector.connectorNamespace !== IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN) {
|
|
1185
1207
|
initialChain = this.coreOptions.chains.find(x => x.chainNamespace === connector.connectorNamespace);
|
|
1186
|
-
if (!initialChain) throw index.WalletInitializationError.invalidParams(`No chain found for ${connector.connectorNamespace}`);
|
|
1187
1208
|
}
|
|
1209
|
+
if (!initialChain) throw index.WalletInitializationError.invalidParams(`No chain found for ${connector.connectorNamespace}`);
|
|
1188
1210
|
return initialChain;
|
|
1189
1211
|
}
|
|
1190
1212
|
async completeConsentAcceptance() {
|
|
@@ -1368,7 +1390,8 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1368
1390
|
return {
|
|
1369
1391
|
ethereumProvider: connectedWallet.signingProvider,
|
|
1370
1392
|
solanaWallet: (_connectedWallet$sola = connectedWallet.solanaWallet) !== null && _connectedWallet$sola !== void 0 ? _connectedWallet$sola : null,
|
|
1371
|
-
connectorName: connectedWallet.connector.name
|
|
1393
|
+
connectorName: connectedWallet.connector.name,
|
|
1394
|
+
connectorNamespace: connectedWallet.connector.connectorNamespace
|
|
1372
1395
|
};
|
|
1373
1396
|
}
|
|
1374
1397
|
buildImmediateConnectedWalletConnectorState(params) {
|
|
@@ -1505,11 +1528,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1505
1528
|
if (!connection) {
|
|
1506
1529
|
throw index.WalletLoginError.connectionError("Failed to resolve the active connection after switching accounts.");
|
|
1507
1530
|
}
|
|
1508
|
-
this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED,
|
|
1509
|
-
ethereumProvider: connection.ethereumProvider,
|
|
1510
|
-
solanaWallet: connection.solanaWallet,
|
|
1511
|
-
connectorName: connection.connectorName
|
|
1512
|
-
});
|
|
1531
|
+
this.emit(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connection);
|
|
1513
1532
|
}
|
|
1514
1533
|
isActiveConnectorEventSource(connector) {
|
|
1515
1534
|
if (!this.primaryConnectorName) return true;
|
|
@@ -1592,9 +1611,10 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1592
1611
|
loglevel.log.debug("Failed to cache connected linked wallet connector", error);
|
|
1593
1612
|
}
|
|
1594
1613
|
}
|
|
1595
|
-
async cacheWallet(walletName) {
|
|
1614
|
+
async cacheWallet(walletName, connectorNamespace) {
|
|
1596
1615
|
await this.setState({
|
|
1597
|
-
cachedConnector: walletName
|
|
1616
|
+
cachedConnector: walletName,
|
|
1617
|
+
cachedConnectorNamespace: connectorNamespace
|
|
1598
1618
|
});
|
|
1599
1619
|
}
|
|
1600
1620
|
async setCurrentChain(chainId) {
|
|
@@ -1630,9 +1650,11 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1630
1650
|
});
|
|
1631
1651
|
}
|
|
1632
1652
|
async bindPrimaryEthereumSigningProxy(ethereumProvider, connectorName) {
|
|
1633
|
-
var _this$currentChain5, _accountAbstractionCo;
|
|
1653
|
+
var _this$primaryConnecto2, _this$currentChain5, _accountAbstractionCo;
|
|
1634
1654
|
if (!this.commonJRPCProvider) throw index.WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
1635
|
-
|
|
1655
|
+
const primaryConnectorProvider = connectorName === this.primaryConnectorName ? (_this$primaryConnecto2 = this.primaryConnector) === null || _this$primaryConnecto2 === void 0 ? void 0 : _this$primaryConnecto2.provider : null;
|
|
1656
|
+
const baseEthereumProvider = ethereumProvider === this.commonJRPCProvider || ethereumProvider === this.aaProvider ? primaryConnectorProvider !== null && primaryConnectorProvider !== void 0 ? primaryConnectorProvider : ethereumProvider : ethereumProvider;
|
|
1657
|
+
let finalProvider = (baseEthereumProvider === null || baseEthereumProvider === void 0 ? void 0 : baseEthereumProvider.provider) || baseEthereumProvider;
|
|
1636
1658
|
const {
|
|
1637
1659
|
accountAbstractionConfig
|
|
1638
1660
|
} = this.coreOptions;
|
|
@@ -1642,13 +1664,14 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1642
1664
|
return chain.chainId === ((_this$currentChain6 = this.currentChain) === null || _this$currentChain6 === void 0 ? void 0 : _this$currentChain6.chainId);
|
|
1643
1665
|
}));
|
|
1644
1666
|
// setup AA provider if AA is enabled (skip for EIP-7702; 7702 uses EOA + 5792/7702 RPC only)
|
|
1645
|
-
|
|
1667
|
+
// Skip AA wrapping for Base Account as it's already a smart account provider
|
|
1668
|
+
if (!is7702 && isAaSupportedForCurrentChain && (connectorName === index$1.WALLET_CONNECTORS.AUTH || this.coreOptions.useAAWithExternalWallet && connectorName !== index$1.WALLET_CONNECTORS.BASE_ACCOUNT)) {
|
|
1646
1669
|
var _accountAbstractionCo2;
|
|
1647
1670
|
const {
|
|
1648
1671
|
accountAbstractionProvider,
|
|
1649
1672
|
toEoaProvider
|
|
1650
1673
|
} = await Promise.resolve().then(function () { return require('./providers/account-abstraction-provider/index.js'); });
|
|
1651
|
-
const eoaProvider = connectorName === index$1.WALLET_CONNECTORS.AUTH ? await toEoaProvider(
|
|
1674
|
+
const eoaProvider = connectorName === index$1.WALLET_CONNECTORS.AUTH ? await toEoaProvider(baseEthereumProvider) : baseEthereumProvider;
|
|
1652
1675
|
const aaChainIds = new Set((accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo2 = accountAbstractionConfig.chains) === null || _accountAbstractionCo2 === void 0 ? void 0 : _accountAbstractionCo2.map(chain => chain.chainId)) || []);
|
|
1653
1676
|
const aaProvider = await accountAbstractionProvider({
|
|
1654
1677
|
accountAbstractionConfig,
|
package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js
CHANGED
|
@@ -70,7 +70,7 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
async setupProvider(eoaProvider) {
|
|
73
|
-
var _bundlerConfig$transp;
|
|
73
|
+
var _await$eoaProvider$re, _bundlerConfig$transp;
|
|
74
74
|
const currentChain = this.currentChain;
|
|
75
75
|
if (!currentChain) {
|
|
76
76
|
throw index.WalletInitializationError.invalidProviderConfigError(`AA chain config not found for chain ${this.chainId}`);
|
|
@@ -113,7 +113,14 @@ class AccountAbstractionProvider extends baseProvider.BaseProvider {
|
|
|
113
113
|
chain,
|
|
114
114
|
transport: viem.http(currentChain.rpcTarget)
|
|
115
115
|
});
|
|
116
|
-
|
|
116
|
+
// Firstly, try to get the accounts from the existing connected provider with `eth_accounts` method.
|
|
117
|
+
// We don't wanna do `eth_requestAccounts` method here, coz if the wallet is already connected, it will trigger chainChanged event and unintentionally update the AaProvider re-bind and
|
|
118
|
+
// re-bind run this again, so we will end up in infinite loop.
|
|
119
|
+
const existingAccounts = (_await$eoaProvider$re = await eoaProvider.request({
|
|
120
|
+
method: ethereumControllers.METHOD_TYPES.GET_ACCOUNTS
|
|
121
|
+
})) !== null && _await$eoaProvider$re !== void 0 ? _await$eoaProvider$re : [];
|
|
122
|
+
// only if the existing accounts are not found (that means wallet isn't connected), then we will trigger `eth_requestAccounts` method to get the accounts.
|
|
123
|
+
const [eoaAddress] = existingAccounts.length > 0 ? existingAccounts : await eoaProvider.request({
|
|
117
124
|
method: ethereumControllers.METHOD_TYPES.ETH_REQUEST_ACCOUNTS
|
|
118
125
|
});
|
|
119
126
|
const walletClient = viem.createWalletClient({
|
|
@@ -175,6 +175,14 @@ function useWeb3AuthInnerContextValue({
|
|
|
175
175
|
setChainId(web3Auth.currentChainId);
|
|
176
176
|
setChainNamespace((_web3Auth$currentChai1 = (_web3Auth$currentChai10 = web3Auth.currentChain) === null || _web3Auth$currentChai10 === void 0 ? void 0 : _web3Auth$currentChai10.chainNamespace) !== null && _web3Auth$currentChai1 !== void 0 ? _web3Auth$currentChai1 : null);
|
|
177
177
|
};
|
|
178
|
+
const connectorDataUpdatedListener = data => {
|
|
179
|
+
const updatedData = data.data;
|
|
180
|
+
if (updatedData.chainId) {
|
|
181
|
+
var _web3Auth$currentChai11;
|
|
182
|
+
setChainId(updatedData.chainId);
|
|
183
|
+
setChainNamespace((_web3Auth$currentChai11 = web3Auth.currentChain) === null || _web3Auth$currentChai11 === void 0 ? void 0 : _web3Auth$currentChai11.chainNamespace);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
178
186
|
if (web3Auth) {
|
|
179
187
|
web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
180
188
|
web3Auth.on(constants.CONNECTOR_EVENTS.READY, readyListener);
|
|
@@ -186,6 +194,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
186
194
|
web3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
187
195
|
web3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
188
196
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
197
|
+
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, connectorDataUpdatedListener);
|
|
189
198
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
190
199
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
191
200
|
}
|
|
@@ -202,6 +211,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
202
211
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
203
212
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.AUTHORIZED, authorizedListener);
|
|
204
213
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
214
|
+
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTOR_DATA_UPDATED, connectorDataUpdatedListener);
|
|
205
215
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
206
216
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
207
217
|
}
|