@web3auth/no-modal 11.0.0-beta.1 → 11.0.0-beta.2
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/utils.js +1 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +83 -29
- package/dist/lib.cjs/index.js +3 -3
- package/dist/lib.cjs/noModal.js +31 -15
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +9 -0
- package/dist/lib.cjs/react/solana/provider.js +6 -2
- package/dist/lib.cjs/react/wagmi/provider.js +37 -5
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +6 -0
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
- package/dist/lib.cjs/types/noModal.d.ts +1 -1
- package/dist/lib.cjs/vue/solana/provider.js +50 -26
- package/dist/lib.cjs/vue/wagmi/provider.js +34 -18
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +85 -31
- package/dist/lib.esm/noModal.js +31 -15
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +9 -0
- package/dist/lib.esm/react/solana/provider.js +6 -2
- package/dist/lib.esm/react/wagmi/provider.js +38 -6
- package/dist/lib.esm/vue/solana/provider.js +51 -28
- package/dist/lib.esm/vue/wagmi/provider.js +34 -18
- package/package.json +3 -3
|
@@ -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.0.0-beta.
|
|
148
|
+
const sdkVersion = "11.0.0-beta.2";
|
|
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;
|
|
@@ -8,7 +8,7 @@ var securePubSub = require('@toruslabs/secure-pub-sub');
|
|
|
8
8
|
var auth = require('@web3auth/auth');
|
|
9
9
|
var wsEmbed = require('@web3auth/ws-embed');
|
|
10
10
|
var deepmerge = require('deepmerge');
|
|
11
|
-
var
|
|
11
|
+
var viem = require('viem');
|
|
12
12
|
var analytics = require('../../base/analytics.js');
|
|
13
13
|
var IChainInterface = require('../../base/chain/IChainInterface.js');
|
|
14
14
|
var baseConnector = require('../../base/connector/baseConnector.js');
|
|
@@ -24,8 +24,18 @@ var utils = require('../../base/utils.js');
|
|
|
24
24
|
var index$1 = require('../../base/wallet/index.js');
|
|
25
25
|
var utils$1 = require('../utils.js');
|
|
26
26
|
var authSolanaWallet = require('./authSolanaWallet.js');
|
|
27
|
+
var rest = require('../../account-linking/rest.js');
|
|
27
28
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
28
29
|
|
|
30
|
+
// Auth connections that have been deprecated and are no longer supported by the SDK.
|
|
31
|
+
// Passing any of these as `authConnection` results in a hard error so consumers
|
|
32
|
+
// migrate off the removed providers instead of silently continuing.
|
|
33
|
+
const DEPRECATED_AUTH_CONNECTIONS = new Set(["farcaster"]);
|
|
34
|
+
function assertAuthConnectionSupported(authConnection) {
|
|
35
|
+
if (DEPRECATED_AUTH_CONNECTIONS.has(authConnection)) {
|
|
36
|
+
throw index.WalletInitializationError.invalidParams(`Auth connection "${authConnection}" has been deprecated and is no longer supported by the Web3Auth SDKs. ` + `Please use a different authConnection value.`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
29
39
|
class AuthConnector extends baseConnector.BaseConnector {
|
|
30
40
|
constructor(params) {
|
|
31
41
|
super(params);
|
|
@@ -43,8 +53,22 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
43
53
|
_defineProperty(this, "wsEmbedInstance", null);
|
|
44
54
|
_defineProperty(this, "authConnectionConfig", []);
|
|
45
55
|
_defineProperty(this, "wsEmbedInstancePromise", null);
|
|
56
|
+
_defineProperty(this, "wsEmbedProviderListenerTarget", null);
|
|
46
57
|
_defineProperty(this, "_solanaWallet", null);
|
|
47
58
|
_defineProperty(this, "analytics", void 0);
|
|
59
|
+
_defineProperty(this, "handleWsEmbedAccountsChanged", accounts => {
|
|
60
|
+
if (accounts.length === 0) {
|
|
61
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
loglevel.log.info("No accounts found in the wallet, disconnecting");
|
|
65
|
+
void this.disconnect({
|
|
66
|
+
cleanup: true
|
|
67
|
+
}).catch(error => {
|
|
68
|
+
loglevel.log.error("Failed to disconnect auth connector after wallet accounts changed", error);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
48
72
|
this.authOptions = params.connectorSettings;
|
|
49
73
|
this.loginSettings = params.loginSettings || {
|
|
50
74
|
authConnection: ""
|
|
@@ -57,10 +81,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
57
81
|
}
|
|
58
82
|
get provider() {
|
|
59
83
|
if (this.status !== constants.CONNECTOR_STATUS.NOT_READY) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return this.wsEmbedInstance.provider;
|
|
63
|
-
} else if (this.privateKeyProvider) return this.privateKeyProvider;
|
|
84
|
+
const wsEmbedProvider = this.getWsEmbedProvider();
|
|
85
|
+
return wsEmbedProvider || this.privateKeyProvider;
|
|
64
86
|
}
|
|
65
87
|
return null;
|
|
66
88
|
}
|
|
@@ -127,6 +149,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
127
149
|
buildEnv: this.authOptions.buildEnv,
|
|
128
150
|
whiteLabel: _objectSpread(_objectSpread({}, this.authOptions.whiteLabel), this.wsSettings.whiteLabel)
|
|
129
151
|
})).then(() => {
|
|
152
|
+
this.bindWsEmbedProviderEvents();
|
|
130
153
|
this.wsEmbedInstancePromise = null;
|
|
131
154
|
return;
|
|
132
155
|
});
|
|
@@ -175,6 +198,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
175
198
|
}
|
|
176
199
|
}
|
|
177
200
|
async connect(params) {
|
|
201
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
178
202
|
super.checkConnectionRequirements();
|
|
179
203
|
this.status = constants.CONNECTOR_STATUS.CONNECTING;
|
|
180
204
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTING, _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -204,6 +228,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
204
228
|
async enableMFA(params = {
|
|
205
229
|
authConnection: ""
|
|
206
230
|
}) {
|
|
231
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
207
232
|
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
208
233
|
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
209
234
|
try {
|
|
@@ -221,6 +246,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
221
246
|
async manageMFA(params = {
|
|
222
247
|
authConnection: ""
|
|
223
248
|
}) {
|
|
249
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
224
250
|
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
225
251
|
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
226
252
|
try {
|
|
@@ -252,6 +278,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
252
278
|
}
|
|
253
279
|
this.rehydrated = false;
|
|
254
280
|
this._solanaWallet = null;
|
|
281
|
+
this.unbindWsEmbedProviderEvents();
|
|
255
282
|
this.emit(constants.CONNECTOR_EVENTS.DISCONNECTED, {
|
|
256
283
|
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
257
284
|
});
|
|
@@ -313,13 +340,15 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
313
340
|
const newChainConfig = this.coreOptions.chains.find(c => c.chainId === newChainId);
|
|
314
341
|
if (!newChainConfig) throw index.WalletInitializationError.invalidParams("Chain config is not available");
|
|
315
342
|
if (newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
316
|
-
var _this$
|
|
317
|
-
if (!((_this$
|
|
318
|
-
const
|
|
343
|
+
var _this$wsEmbedInstance;
|
|
344
|
+
if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw index.WalletInitializationError.notReady("Wallet embed is not ready");
|
|
345
|
+
const chainIdNum = parseInt(newChainConfig.chainId, 16);
|
|
346
|
+
// WsEmbed expects the chainId in hex format
|
|
347
|
+
const chainIdHex = viem.numberToHex(chainIdNum);
|
|
319
348
|
await this.wsEmbedInstance.provider.request({
|
|
320
349
|
method: "wallet_switchChain",
|
|
321
350
|
params: {
|
|
322
|
-
chainId:
|
|
351
|
+
chainId: chainIdHex
|
|
323
352
|
}
|
|
324
353
|
});
|
|
325
354
|
} else {
|
|
@@ -333,6 +362,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
333
362
|
if (this.wsEmbedInstance) {
|
|
334
363
|
this.wsEmbedInstance.clearInit();
|
|
335
364
|
}
|
|
365
|
+
this._solanaWallet = null;
|
|
366
|
+
this.unbindWsEmbedProviderEvents();
|
|
336
367
|
}
|
|
337
368
|
getOAuthProviderConfig(params) {
|
|
338
369
|
const {
|
|
@@ -419,11 +450,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
419
450
|
const {
|
|
420
451
|
connectorName,
|
|
421
452
|
chainId,
|
|
422
|
-
|
|
453
|
+
connectorToLink
|
|
423
454
|
} = params;
|
|
424
455
|
try {
|
|
425
|
-
if (!
|
|
426
|
-
const connection = await
|
|
456
|
+
if (!connectorToLink.connected) {
|
|
457
|
+
const connection = await connectorToLink.connect({
|
|
427
458
|
chainId,
|
|
428
459
|
isAccountLinking: true
|
|
429
460
|
});
|
|
@@ -448,7 +479,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
448
479
|
accessToken,
|
|
449
480
|
idToken
|
|
450
481
|
} = await this.getPrimaryAuthSession(params.authSessionTokens);
|
|
451
|
-
const walletProof = await this.createWalletLinkingProof(params.
|
|
482
|
+
const walletProof = await this.createWalletLinkingProof(params.connectorToLink);
|
|
452
483
|
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
453
484
|
const result = await rest.makeAccountLinkingRequest(authServerUrl, accessToken, {
|
|
454
485
|
idToken,
|
|
@@ -468,9 +499,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
468
499
|
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
469
500
|
// disconnect the wallet connector to avoid any leftover state
|
|
470
501
|
try {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
502
|
+
if (connectorToLink.connected) {
|
|
503
|
+
await connectorToLink.disconnect({
|
|
504
|
+
cleanup: true
|
|
505
|
+
});
|
|
506
|
+
}
|
|
474
507
|
} catch (disconnectError) {
|
|
475
508
|
loglevel.log.debug("Failed to disconnect wallet connector after linking failure", disconnectError);
|
|
476
509
|
}
|
|
@@ -692,9 +725,35 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
692
725
|
}
|
|
693
726
|
return accounts[0];
|
|
694
727
|
}
|
|
728
|
+
getWsEmbedProvider() {
|
|
729
|
+
var _this$wsEmbedInstance2, _this$wsEmbedInstance3;
|
|
730
|
+
return (_this$wsEmbedInstance2 = (_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 ? void 0 : _this$wsEmbedInstance3.provider) !== null && _this$wsEmbedInstance2 !== void 0 ? _this$wsEmbedInstance2 : null;
|
|
731
|
+
}
|
|
732
|
+
bindWsEmbedProviderEvents() {
|
|
733
|
+
const rawProvider = this.getWsEmbedProvider();
|
|
734
|
+
if (this.wsEmbedProviderListenerTarget === rawProvider) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
this.unbindWsEmbedProviderEvents();
|
|
738
|
+
if (!rawProvider) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
rawProvider.on("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
742
|
+
this.wsEmbedProviderListenerTarget = rawProvider;
|
|
743
|
+
}
|
|
744
|
+
unbindWsEmbedProviderEvents() {
|
|
745
|
+
if (!this.wsEmbedProviderListenerTarget) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
this.wsEmbedProviderListenerTarget.removeListener("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
749
|
+
this.wsEmbedProviderListenerTarget = null;
|
|
750
|
+
}
|
|
695
751
|
setupSolanaWallet() {
|
|
696
752
|
const solanaChains = this.coreOptions.chains.filter(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
697
753
|
if (solanaChains.length === 0 || !this.provider) return;
|
|
754
|
+
if (this._solanaWallet instanceof authSolanaWallet.AuthSolanaWallet) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
698
757
|
this._solanaWallet = new authSolanaWallet.AuthSolanaWallet(this.provider, solanaChains);
|
|
699
758
|
}
|
|
700
759
|
_getFinalPrivKey() {
|
|
@@ -754,13 +813,13 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
754
813
|
} = this.authInstance || {};
|
|
755
814
|
if (sessionId) {
|
|
756
815
|
this.wsEmbedInstance.setAccessTokenProvider(this.accessTokenProvider.bind(this));
|
|
816
|
+
this.bindWsEmbedProviderEvents();
|
|
757
817
|
const isLoggedIn = await this.wsEmbedInstance.connectWithSession({
|
|
758
818
|
sessionId,
|
|
759
819
|
sessionNamespace,
|
|
760
820
|
idToken: await this.getIdToken()
|
|
761
821
|
});
|
|
762
822
|
if (isLoggedIn) {
|
|
763
|
-
var _this$wsEmbedInstance3;
|
|
764
823
|
this.setupSolanaWallet();
|
|
765
824
|
// if getAuthTokenInfo is true, then get auth token info
|
|
766
825
|
// No need to get auth token info for auth connector as it is already handled
|
|
@@ -774,12 +833,6 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
774
833
|
if (params.getAuthTokenInfo) {
|
|
775
834
|
await this.getAuthTokenInfo();
|
|
776
835
|
}
|
|
777
|
-
// handle disconnect from ws embed
|
|
778
|
-
(_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 || _this$wsEmbedInstance3.provider.on("accountsChanged", (accounts = []) => {
|
|
779
|
-
if (accounts.length === 0 && connectorStatus.CONNECTED_STATUSES.includes(this.status)) this.disconnect({
|
|
780
|
-
cleanup: false
|
|
781
|
-
});
|
|
782
|
-
});
|
|
783
836
|
}
|
|
784
837
|
}
|
|
785
838
|
} else {
|
|
@@ -879,9 +932,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
879
932
|
}).catch(error => {
|
|
880
933
|
// swallow the error, dont need to throw.
|
|
881
934
|
loglevel.log.error("Error during login with social", error);
|
|
882
|
-
this.
|
|
883
|
-
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
884
|
-
});
|
|
935
|
+
this.reportFailedOauthAudit(loginParams);
|
|
885
936
|
});
|
|
886
937
|
verifierWindow.once("close", () => {
|
|
887
938
|
if (!isClosedWindow) {
|
|
@@ -891,9 +942,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
891
942
|
}
|
|
892
943
|
});
|
|
893
944
|
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
|
|
894
|
-
this.
|
|
895
|
-
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
896
|
-
});
|
|
945
|
+
this.reportFailedOauthAudit(loginParams);
|
|
897
946
|
if (error instanceof index.Web3AuthError) {
|
|
898
947
|
throw error;
|
|
899
948
|
}
|
|
@@ -1007,6 +1056,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
1007
1056
|
}
|
|
1008
1057
|
await httpHelpers.put(auditServerUrl, auditPayload);
|
|
1009
1058
|
}
|
|
1059
|
+
reportFailedOauthAudit(loginParams) {
|
|
1060
|
+
void this.auditOAuditProgress(loginParams, "failed").catch(error => {
|
|
1061
|
+
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1010
1064
|
}
|
|
1011
1065
|
const authConnector = params => {
|
|
1012
1066
|
return ({
|
package/dist/lib.cjs/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var rest = require('./account-linking/rest.js');
|
|
4
3
|
var analytics = require('./base/analytics.js');
|
|
5
4
|
var IChainInterface = require('./base/chain/IChainInterface.js');
|
|
6
5
|
var index$2 = require('./base/composables/index.js');
|
|
@@ -43,12 +42,11 @@ var wsEmbed = require('@web3auth/ws-embed');
|
|
|
43
42
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
44
43
|
var app = require('@wallet-standard/app');
|
|
45
44
|
var solana = require('./base/wallet/solana.js');
|
|
45
|
+
var rest = require('./account-linking/rest.js');
|
|
46
46
|
var walletStandardConnector = require('./connectors/injected-solana-connector/walletStandardConnector.js');
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
51
|
-
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
52
50
|
exports.ANALYTICS_EVENTS = analytics.ANALYTICS_EVENTS;
|
|
53
51
|
exports.ANALYTICS_INTEGRATION_TYPE = analytics.ANALYTICS_INTEGRATION_TYPE;
|
|
54
52
|
exports.ANALYTICS_SDK_TYPE = analytics.ANALYTICS_SDK_TYPE;
|
|
@@ -239,4 +237,6 @@ exports.getSolanaChainByChainConfig = solana.getSolanaChainByChainConfig;
|
|
|
239
237
|
exports.walletSignAndSendTransaction = solana.walletSignAndSendTransaction;
|
|
240
238
|
exports.walletSignMessage = solana.walletSignMessage;
|
|
241
239
|
exports.walletSignTransaction = solana.walletSignTransaction;
|
|
240
|
+
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
241
|
+
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
242
242
|
exports.walletStandardConnector = walletStandardConnector.walletStandardConnector;
|
package/dist/lib.cjs/noModal.js
CHANGED
|
@@ -908,7 +908,6 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
908
908
|
}));
|
|
909
909
|
this.setActiveWalletConnectorKey();
|
|
910
910
|
this.connectionReconnected = data.reconnected;
|
|
911
|
-
const connectedChainId = ethereumProvider === null || ethereumProvider === void 0 ? void 0 : ethereumProvider.chainId;
|
|
912
911
|
// when ssr is enabled, we need to get the idToken from the connector.
|
|
913
912
|
if (this.coreOptions.ssr) {
|
|
914
913
|
try {
|
|
@@ -931,14 +930,15 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
931
930
|
}
|
|
932
931
|
// The following block only hits during rehydration
|
|
933
932
|
const {
|
|
934
|
-
activeAccount
|
|
933
|
+
activeAccount,
|
|
934
|
+
currentChainId
|
|
935
935
|
} = this.state;
|
|
936
936
|
// if the active account is not the primary account, i.e. not `null`, create an isolated connector and connect to the chain
|
|
937
937
|
if (activeAccount && !activeAccount.isPrimary && activeAccount.connector !== index$1.WALLET_CONNECTORS.AUTH) {
|
|
938
938
|
var _ref3, _walletConnector$prov, _linkedAccountConnect, _ref4, _walletConnector$sola, _linkedAccountConnect2;
|
|
939
939
|
const accountLinkingConnector = authConnector.isAuthConnector(connector) ? connector : this.getConnector(index$1.WALLET_CONNECTORS.AUTH);
|
|
940
940
|
authConnector.assertAuthConnector(accountLinkingConnector, "Account switching requires the AUTH connector to be available.");
|
|
941
|
-
const targetChainId = accountLinkingConnector.getChainIdForLinkedAccount(activeAccount,
|
|
941
|
+
const targetChainId = accountLinkingConnector.getChainIdForLinkedAccount(activeAccount, currentChainId);
|
|
942
942
|
const walletConnector = await this.createIsolatedWalletConnector(activeAccount.connector, targetChainId);
|
|
943
943
|
let linkedAccountConnection = null;
|
|
944
944
|
if (!this.hasUsableConnectedSwitchConnector(walletConnector)) {
|
|
@@ -970,23 +970,36 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
970
970
|
});
|
|
971
971
|
this.setConnectedWalletConnectorState(primaryConnectedWalletState);
|
|
972
972
|
await this.setState({
|
|
973
|
-
primaryConnectorName: data.connectorName
|
|
974
|
-
currentChainId: connectedChainId
|
|
973
|
+
primaryConnectorName: data.connectorName
|
|
975
974
|
});
|
|
976
975
|
this.cacheWallet(data.connectorName);
|
|
977
976
|
const isConnectAndSign = this.coreOptions.initialAuthenticationMode === constants.CONNECTOR_INITIAL_AUTHENTICATION_MODE.CONNECT_AND_SIGN;
|
|
978
|
-
|
|
977
|
+
const pendingUserConsent = this.consentRequired && !this.state.hasUserConsent;
|
|
978
|
+
if (pendingUserConsent && !isConnectAndSign) {
|
|
979
979
|
this.status = constants.CONNECTOR_STATUS.CONSENT_REQUIRING;
|
|
980
980
|
this.emit(constants.CONNECTOR_EVENTS.CONSENT_REQUIRING);
|
|
981
981
|
loglevel.log.debug("consent_requiring", this.status, this.primaryConnectorName);
|
|
982
982
|
} else {
|
|
983
|
-
this
|
|
983
|
+
// In CONNECT_AND_SIGN mode the AUTHORIZED handler can run before this point (e.g. when `ssr=true`
|
|
984
|
+
// this handler `await`s `connector.getAuthTokenInfo()` which fires AUTHORIZED mid-execution).
|
|
985
|
+
// Don't downgrade an already-advanced status (CONSENT_REQUIRING or AUTHORIZED) back to CONNECTED;
|
|
986
|
+
// otherwise `acceptConsent` would throw "Cannot accept consent: not in consent_requiring state".
|
|
987
|
+
if (this.status !== constants.CONNECTOR_STATUS.CONSENT_REQUIRING && this.status !== constants.CONNECTOR_STATUS.AUTHORIZED) {
|
|
988
|
+
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
989
|
+
}
|
|
984
990
|
loglevel.log.debug("connected", this.status, this.primaryConnectorName);
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
991
|
+
// Defer plugin connection until consent is accepted; otherwise plugins would start before the consent step completes.
|
|
992
|
+
// `completeConsentAcceptance` connects the plugins once the user accepts the consent.
|
|
993
|
+
if (!pendingUserConsent) {
|
|
994
|
+
this.connectToPlugins(_objectSpread(_objectSpread({}, data), {}, {
|
|
995
|
+
connector: data.connectorName
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
998
|
+
// `pendingUserConsent` signals listeners (LoginModal, React/Vue contexts) to skip processing this CONNECTED event,
|
|
999
|
+
// so the upcoming AUTHORIZED -> CONSENT_REQUIRING transition is not overridden by a late CONNECTED handler in CONNECT_AND_SIGN mode.
|
|
988
1000
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, _objectSpread(_objectSpread({}, data), {}, {
|
|
989
|
-
loginMode: this.loginMode
|
|
1001
|
+
loginMode: this.loginMode,
|
|
1002
|
+
pendingUserConsent
|
|
990
1003
|
}));
|
|
991
1004
|
}
|
|
992
1005
|
});
|
|
@@ -1357,12 +1370,12 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1357
1370
|
account
|
|
1358
1371
|
});
|
|
1359
1372
|
}
|
|
1360
|
-
async linkAccountWithConnector(connectorName, chainId,
|
|
1373
|
+
async linkAccountWithConnector(connectorName, chainId, connectorToLink) {
|
|
1361
1374
|
const authConnector = this.getMainAuthConnector();
|
|
1362
1375
|
const result = await authConnector.linkAccount({
|
|
1363
1376
|
connectorName,
|
|
1364
1377
|
chainId,
|
|
1365
|
-
|
|
1378
|
+
connectorToLink,
|
|
1366
1379
|
authSessionTokens: {
|
|
1367
1380
|
accessToken: this.accessToken,
|
|
1368
1381
|
idToken: this.idToken
|
|
@@ -1371,7 +1384,7 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1371
1384
|
await this.setState({
|
|
1372
1385
|
idToken: result.idToken
|
|
1373
1386
|
});
|
|
1374
|
-
await this.cacheConnectedLinkedWalletConnector(authConnector,
|
|
1387
|
+
await this.cacheConnectedLinkedWalletConnector(authConnector, connectorToLink);
|
|
1375
1388
|
return result;
|
|
1376
1389
|
}
|
|
1377
1390
|
getMainAuthConnector() {
|
|
@@ -1550,7 +1563,10 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
|
|
|
1550
1563
|
});
|
|
1551
1564
|
}
|
|
1552
1565
|
async setCurrentChain(chainId) {
|
|
1553
|
-
|
|
1566
|
+
const {
|
|
1567
|
+
currentChainId
|
|
1568
|
+
} = this.state;
|
|
1569
|
+
if (chainId === currentChainId) return;
|
|
1554
1570
|
const newChain = this.coreOptions.chains.find(chain => chain.chainId === chainId);
|
|
1555
1571
|
if (!newChain) throw index.WalletInitializationError.invalidParams(`Invalid chainId: ${chainId}`);
|
|
1556
1572
|
await this.setState({
|
|
@@ -161,6 +161,13 @@ function useWeb3AuthInnerContextValue({
|
|
|
161
161
|
const mfaEnabledListener = nextIsMFAEnabled => {
|
|
162
162
|
if (typeof nextIsMFAEnabled === "boolean") setIsMFAEnabled(nextIsMFAEnabled);
|
|
163
163
|
};
|
|
164
|
+
const connectionUpdatedListener = () => {
|
|
165
|
+
var _web3Auth$currentChai9, _web3Auth$currentChai0;
|
|
166
|
+
setStatus(web3Auth.status);
|
|
167
|
+
setConnection(web3Auth.connection);
|
|
168
|
+
setChainId(web3Auth.currentChainId);
|
|
169
|
+
setChainNamespace((_web3Auth$currentChai9 = (_web3Auth$currentChai0 = web3Auth.currentChain) === null || _web3Auth$currentChai0 === void 0 ? void 0 : _web3Auth$currentChai0.chainNamespace) !== null && _web3Auth$currentChai9 !== void 0 ? _web3Auth$currentChai9 : null);
|
|
170
|
+
};
|
|
164
171
|
if (web3Auth) {
|
|
165
172
|
web3Auth.on(constants.CONNECTOR_EVENTS.NOT_READY, notReadyListener);
|
|
166
173
|
web3Auth.on(constants.CONNECTOR_EVENTS.READY, readyListener);
|
|
@@ -171,6 +178,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
171
178
|
web3Auth.on(constants.CONNECTOR_EVENTS.ERRORED, errorListener);
|
|
172
179
|
web3Auth.on(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
173
180
|
web3Auth.on(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
181
|
+
web3Auth.on(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
174
182
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
175
183
|
web3Auth.on(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
176
184
|
}
|
|
@@ -186,6 +194,7 @@ function useWeb3AuthInnerContextValue({
|
|
|
186
194
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, rehydrationErrorListener);
|
|
187
195
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.MFA_ENABLED, mfaEnabledListener);
|
|
188
196
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.AUTHORIZED, authorizedListener);
|
|
197
|
+
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONNECTION_UPDATED, connectionUpdatedListener);
|
|
189
198
|
if (web3Auth.loginMode === constants$1.LOGIN_MODE.MODAL) {
|
|
190
199
|
web3Auth.removeListener(constants.CONNECTOR_EVENTS.CONSENT_ACCEPTED, consentAcceptedListener);
|
|
191
200
|
}
|
|
@@ -69,6 +69,7 @@ function useFrameworkKitSolanaClient() {
|
|
|
69
69
|
isInitialized
|
|
70
70
|
} = useWeb3Auth.useWeb3Auth();
|
|
71
71
|
const {
|
|
72
|
+
chainId,
|
|
72
73
|
chainNamespace
|
|
73
74
|
} = useChain.useChain();
|
|
74
75
|
const ref = react.useRef(null);
|
|
@@ -118,7 +119,10 @@ function useFrameworkKitSolanaClient() {
|
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
// only reconnect for the primary connector
|
|
121
|
-
if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName))
|
|
122
|
+
if (conn.connectorName !== (web3Auth === null || web3Auth === void 0 ? void 0 : web3Auth.primaryConnectorName)) {
|
|
123
|
+
adopt(makePlaceholder(rpc));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
122
126
|
try {
|
|
123
127
|
const solanaWalletId = "wallet-standard:" + conn.connectorName;
|
|
124
128
|
const connector = client.createWalletStandardConnector(solanaWallet, {
|
|
@@ -150,7 +154,7 @@ function useFrameworkKitSolanaClient() {
|
|
|
150
154
|
return () => {
|
|
151
155
|
stale = true;
|
|
152
156
|
};
|
|
153
|
-
}, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
|
|
157
|
+
}, [isConnected, connection === null || connection === void 0 ? void 0 : connection.solanaWallet, chainId, chainNamespace, web3Auth, isInitialized, connection === null || connection === void 0 ? void 0 : connection.connectorName]);
|
|
154
158
|
return client$1;
|
|
155
159
|
}
|
|
156
160
|
function SolanaProvider(_ref) {
|
|
@@ -92,7 +92,8 @@ function Web3AuthWagmiProvider({
|
|
|
92
92
|
}) {
|
|
93
93
|
const {
|
|
94
94
|
isConnected,
|
|
95
|
-
connection
|
|
95
|
+
connection,
|
|
96
|
+
chainNamespace
|
|
96
97
|
} = useWeb3Auth.useWeb3Auth();
|
|
97
98
|
const {
|
|
98
99
|
disconnect
|
|
@@ -101,10 +102,17 @@ function Web3AuthWagmiProvider({
|
|
|
101
102
|
const {
|
|
102
103
|
mutate: reconnect
|
|
103
104
|
} = wagmi.useReconnect();
|
|
105
|
+
const suppressWagmiDisconnect = react.useRef(false);
|
|
106
|
+
const lastSyncedBinding = react.useRef({
|
|
107
|
+
provider: null,
|
|
108
|
+
connectorName: null
|
|
109
|
+
});
|
|
104
110
|
wagmi.useConnectionEffect({
|
|
105
111
|
onDisconnect: async () => {
|
|
106
112
|
loglevel.log.info("Disconnected from wagmi");
|
|
107
|
-
|
|
113
|
+
const isSuppressed = suppressWagmiDisconnect.current;
|
|
114
|
+
suppressWagmiDisconnect.current = false;
|
|
115
|
+
if (!isSuppressed && isConnected) await disconnect();
|
|
108
116
|
const connector = getWeb3authConnector(wagmiConfig);
|
|
109
117
|
// reset wagmi connector state if the provider handles disconnection because of the accountsChanged event
|
|
110
118
|
// from the connected provider
|
|
@@ -115,20 +123,44 @@ function Web3AuthWagmiProvider({
|
|
|
115
123
|
});
|
|
116
124
|
react.useEffect(() => {
|
|
117
125
|
(async () => {
|
|
118
|
-
|
|
126
|
+
const shouldBindToWagmi = isConnected && chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 && Boolean(connection === null || connection === void 0 ? void 0 : connection.ethereumProvider);
|
|
127
|
+
if (shouldBindToWagmi) {
|
|
128
|
+
const hasSameBinding = lastSyncedBinding.current.provider === connection.ethereumProvider && lastSyncedBinding.current.connectorName === connection.connectorName;
|
|
129
|
+
if (hasSameBinding && wagmiConfig.state.status === "connected") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!hasSameBinding && getWeb3authConnector(wagmiConfig)) {
|
|
133
|
+
if (wagmiConfig.state.status === "connected") {
|
|
134
|
+
suppressWagmiDisconnect.current = true;
|
|
135
|
+
await disconnectWeb3AuthFromWagmi(wagmiConfig);
|
|
136
|
+
} else {
|
|
137
|
+
resetConnectorState(wagmiConfig);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
119
140
|
const connector = await setupConnector(connection.ethereumProvider, wagmiConfig);
|
|
120
141
|
if (!connector) {
|
|
121
142
|
throw new Error("Failed to setup connector");
|
|
122
143
|
}
|
|
123
144
|
await connectWeb3AuthWithWagmi(connector, wagmiConfig);
|
|
145
|
+
lastSyncedBinding.current = {
|
|
146
|
+
provider: connection.ethereumProvider,
|
|
147
|
+
connectorName: connection.connectorName
|
|
148
|
+
};
|
|
124
149
|
reconnect();
|
|
125
|
-
} else
|
|
150
|
+
} else {
|
|
151
|
+
lastSyncedBinding.current = {
|
|
152
|
+
provider: null,
|
|
153
|
+
connectorName: null
|
|
154
|
+
};
|
|
126
155
|
if (wagmiConfig.state.status === "connected") {
|
|
156
|
+
suppressWagmiDisconnect.current = true;
|
|
127
157
|
await disconnectWeb3AuthFromWagmi(wagmiConfig);
|
|
158
|
+
} else if (getWeb3authConnector(wagmiConfig)) {
|
|
159
|
+
resetConnectorState(wagmiConfig);
|
|
128
160
|
}
|
|
129
161
|
}
|
|
130
162
|
})();
|
|
131
|
-
}, [
|
|
163
|
+
}, [chainNamespace, connection, isConnected, reconnect, wagmiConfig]);
|
|
132
164
|
return react.createElement(react.Fragment, null, children);
|
|
133
165
|
}
|
|
134
166
|
function WagmiProvider(_ref) {
|
|
@@ -18,6 +18,7 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
|
|
|
18
18
|
private wsEmbedInstance;
|
|
19
19
|
private authConnectionConfig;
|
|
20
20
|
private wsEmbedInstancePromise;
|
|
21
|
+
private wsEmbedProviderListenerTarget;
|
|
21
22
|
private _solanaWallet;
|
|
22
23
|
private analytics;
|
|
23
24
|
constructor(params: AuthConnectorOptions);
|
|
@@ -60,6 +61,9 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
|
|
|
60
61
|
private getNetworkForUnlinkAddress;
|
|
61
62
|
private createWalletLinkingProof;
|
|
62
63
|
private getLinkingWalletAddress;
|
|
64
|
+
private getWsEmbedProvider;
|
|
65
|
+
private bindWsEmbedProviderEvents;
|
|
66
|
+
private unbindWsEmbedProviderEvents;
|
|
63
67
|
private setupSolanaWallet;
|
|
64
68
|
private _getFinalPrivKey;
|
|
65
69
|
private connectWithProvider;
|
|
@@ -69,6 +73,8 @@ declare class AuthConnector extends BaseConnector<AuthLoginParams> implements IA
|
|
|
69
73
|
private getOriginData;
|
|
70
74
|
private connectWithJwtLogin;
|
|
71
75
|
private auditOAuditProgress;
|
|
76
|
+
private reportFailedOauthAudit;
|
|
77
|
+
private readonly handleWsEmbedAccountsChanged;
|
|
72
78
|
}
|
|
73
79
|
type AuthConnectorFuncParams = Omit<AuthConnectorOptions, "coreOptions" | "authConnectionConfig" | "connectorSettings"> & {
|
|
74
80
|
connectorSettings?: Omit<AuthConnectorOptions["connectorSettings"], "buildEnv">;
|
|
@@ -14,7 +14,7 @@ export interface AuthConnectorSessionTokens {
|
|
|
14
14
|
}
|
|
15
15
|
export interface AuthConnectorLinkAccountParams {
|
|
16
16
|
authSessionTokens: AuthConnectorSessionTokens;
|
|
17
|
-
|
|
17
|
+
connectorToLink: IConnector<unknown>;
|
|
18
18
|
connectorName: WALLET_CONNECTOR_TYPE | string;
|
|
19
19
|
chainId?: string;
|
|
20
20
|
}
|
|
@@ -139,7 +139,7 @@ export declare class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEve
|
|
|
139
139
|
usePrimaryProxy: boolean;
|
|
140
140
|
account?: ConnectedWalletAccountRef;
|
|
141
141
|
}): Promise<ConnectedAccountsWithProviders>;
|
|
142
|
-
protected linkAccountWithConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string,
|
|
142
|
+
protected linkAccountWithConnector(connectorName: WALLET_CONNECTOR_TYPE | string, chainId: string, connectorToLink: IConnector<unknown>): Promise<LinkAccountResult>;
|
|
143
143
|
protected getMainAuthConnector(): AuthConnectorType;
|
|
144
144
|
/**
|
|
145
145
|
* Processes the result of a switch account operation.
|