@web3auth/no-modal 11.0.0-beta.1 → 11.0.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/errors.js +111 -0
- package/dist/lib.cjs/account-linking/index.js +4 -0
- package/dist/lib.cjs/account-linking/rest.js +6 -6
- package/dist/lib.cjs/account-linking/vue.js +0 -1
- package/dist/lib.cjs/base/connector/constants.js +2 -0
- package/dist/lib.cjs/base/errors/index.js +21 -50
- package/dist/lib.cjs/base/utils.js +1 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +125 -58
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
- package/dist/lib.cjs/index.js +24 -19
- package/dist/lib.cjs/noModal.js +60 -26
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +0 -17
- package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +15 -0
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +18 -2
- package/dist/lib.cjs/react/solana/provider.js +6 -2
- package/dist/lib.cjs/react/wagmi/index.js +6 -0
- package/dist/lib.cjs/react/wagmi/provider.js +74 -23
- package/dist/lib.cjs/types/account-linking/errors.d.ts +17 -0
- package/dist/lib.cjs/types/account-linking/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +1 -1
- package/dist/lib.cjs/types/base/errors/index.d.ts +2 -13
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +8 -2
- 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/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +1 -0
- package/dist/lib.cjs/types/react/wagmi/constants.d.ts +2 -0
- package/dist/lib.cjs/types/react/wagmi/provider.d.ts +7 -0
- package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +2 -0
- package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +7 -1
- package/dist/lib.cjs/vue/solana/provider.js +50 -26
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -6
- package/dist/lib.cjs/vue/wagmi/index.js +6 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +78 -35
- package/dist/lib.esm/account-linking/errors.js +92 -0
- package/dist/lib.esm/account-linking/index.js +1 -0
- package/dist/lib.esm/account-linking/rest.js +3 -3
- package/dist/lib.esm/account-linking/vue.js +0 -1
- package/dist/lib.esm/base/connector/constants.js +2 -1
- package/dist/lib.esm/base/errors/index.js +21 -50
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +109 -41
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +42 -33
- package/dist/lib.esm/index.js +3 -2
- package/dist/lib.esm/noModal.js +56 -20
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
- package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +0 -3
- package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +17 -3
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +18 -2
- package/dist/lib.esm/react/solana/provider.js +6 -2
- package/dist/lib.esm/react/wagmi/index.js +1 -1
- package/dist/lib.esm/react/wagmi/provider.js +74 -25
- package/dist/lib.esm/vue/solana/provider.js +51 -28
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +11 -4
- package/dist/lib.esm/vue/wagmi/index.js +1 -1
- package/dist/lib.esm/vue/wagmi/provider.js +73 -34
- package/package.json +20 -20
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
4
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
5
|
+
var baseControllers = require('@toruslabs/base-controllers');
|
|
5
6
|
var constants$1 = require('@toruslabs/constants');
|
|
6
7
|
var httpHelpers = require('@toruslabs/http-helpers');
|
|
7
8
|
var securePubSub = require('@toruslabs/secure-pub-sub');
|
|
8
9
|
var auth = require('@web3auth/auth');
|
|
9
10
|
var wsEmbed = require('@web3auth/ws-embed');
|
|
10
11
|
var deepmerge = require('deepmerge');
|
|
11
|
-
var rest = require('../../account-linking/rest.js');
|
|
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
|
|
27
|
+
var errors = require('../../account-linking/errors.js');
|
|
28
|
+
var rest = require('../../account-linking/rest.js');
|
|
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
|
});
|
|
@@ -288,6 +315,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
288
315
|
});
|
|
289
316
|
}
|
|
290
317
|
async getLinkedAccounts() {
|
|
318
|
+
var _citadelUserInfo$acco, _this$solanaWallet;
|
|
291
319
|
const accessToken = await this.authInstance.authSessionManager.getAccessToken();
|
|
292
320
|
if (!accessToken) throw index.WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
|
|
293
321
|
const citadelUserInfo = await httpHelpers.get(`${utils.citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
|
|
@@ -295,11 +323,27 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
295
323
|
Authorization: `Bearer ${accessToken}`
|
|
296
324
|
}
|
|
297
325
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
326
|
+
if (!(citadelUserInfo !== null && citadelUserInfo !== void 0 && (_citadelUserInfo$acco = citadelUserInfo.accounts) !== null && _citadelUserInfo$acco !== void 0 && _citadelUserInfo$acco.length)) return [];
|
|
327
|
+
const currentChainNamespace = ((_this$solanaWallet = this.solanaWallet) === null || _this$solanaWallet === void 0 ? void 0 : _this$solanaWallet.accounts.length) > 0 ? baseControllers.CHAIN_NAMESPACES.SOLANA : "evm"; // Note: citadel chain namespace is "evm" for EVM chains
|
|
328
|
+
const filteredLinkedAccounts = [];
|
|
329
|
+
for (const account of citadelUserInfo.accounts) {
|
|
330
|
+
const {
|
|
331
|
+
chainNamespace,
|
|
332
|
+
isPrimary,
|
|
333
|
+
accountType
|
|
334
|
+
} = account;
|
|
335
|
+
// for now, we will take all primary accounts as a **SINGLE** linked account
|
|
336
|
+
// we don't wanna populate the multiple primary accounts as different linked accounts
|
|
337
|
+
// so, we hide the primary accounts for other chain namespaces
|
|
338
|
+
// also, linked `account_abstraction` accounts are derived from the primary account, so we don't need to show them separately
|
|
339
|
+
// TODO: revisit this logic once we have a concrete plan for handling multiple primary accounts
|
|
340
|
+
if (isPrimary && chainNamespace && chainNamespace !== currentChainNamespace || accountType === "account_abstraction") continue;
|
|
341
|
+
filteredLinkedAccounts.push(_objectSpread(_objectSpread({}, account), {}, {
|
|
342
|
+
// by default, the primary account is the active account
|
|
343
|
+
active: isPrimary
|
|
344
|
+
}));
|
|
345
|
+
}
|
|
346
|
+
return filteredLinkedAccounts;
|
|
303
347
|
}
|
|
304
348
|
async switchChain(params, init = false) {
|
|
305
349
|
super.checkSwitchChainRequirements(params, init);
|
|
@@ -313,13 +357,13 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
313
357
|
const newChainConfig = this.coreOptions.chains.find(c => c.chainId === newChainId);
|
|
314
358
|
if (!newChainConfig) throw index.WalletInitializationError.invalidParams("Chain config is not available");
|
|
315
359
|
if (newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
316
|
-
var _this$
|
|
317
|
-
if (!((_this$
|
|
318
|
-
const
|
|
360
|
+
var _this$wsEmbedInstance;
|
|
361
|
+
if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw index.WalletInitializationError.notReady("Wallet embed is not ready");
|
|
362
|
+
const caipChainId = baseControllers.getCaipChainId(newChainConfig);
|
|
319
363
|
await this.wsEmbedInstance.provider.request({
|
|
320
364
|
method: "wallet_switchChain",
|
|
321
365
|
params: {
|
|
322
|
-
chainId:
|
|
366
|
+
chainId: caipChainId
|
|
323
367
|
}
|
|
324
368
|
});
|
|
325
369
|
} else {
|
|
@@ -333,6 +377,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
333
377
|
if (this.wsEmbedInstance) {
|
|
334
378
|
this.wsEmbedInstance.clearInit();
|
|
335
379
|
}
|
|
380
|
+
this._solanaWallet = null;
|
|
381
|
+
this.unbindWsEmbedProviderEvents();
|
|
336
382
|
}
|
|
337
383
|
getOAuthProviderConfig(params) {
|
|
338
384
|
const {
|
|
@@ -366,7 +412,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
366
412
|
const linkedAccounts = (_userInfo$linkedAccou = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou !== void 0 ? _userInfo$linkedAccou : [];
|
|
367
413
|
const targetAccount = linkedAccounts.find(candidate => candidate.id === account.id);
|
|
368
414
|
if (!targetAccount) {
|
|
369
|
-
throw
|
|
415
|
+
throw errors.AccountLinkingError.requestFailed(`No connected wallet matches account id "${account.id}". Refresh user info and try again.`);
|
|
370
416
|
}
|
|
371
417
|
const currentActiveAccount = context.activeAccount;
|
|
372
418
|
const isTargetAlreadyActive = currentActiveAccount ? currentActiveAccount.id === targetAccount.id : targetAccount.isPrimary;
|
|
@@ -380,7 +426,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
380
426
|
const ethereumProvider = this.provider;
|
|
381
427
|
const solanaWallet = this.solanaWallet;
|
|
382
428
|
if (!ethereumProvider && !solanaWallet) {
|
|
383
|
-
throw
|
|
429
|
+
throw errors.AccountLinkingError.requestFailed("Failed to restore the primary AUTH session for account switch.");
|
|
384
430
|
}
|
|
385
431
|
return {
|
|
386
432
|
kind: "primary",
|
|
@@ -419,23 +465,21 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
419
465
|
const {
|
|
420
466
|
connectorName,
|
|
421
467
|
chainId,
|
|
422
|
-
|
|
468
|
+
connectorToLink
|
|
423
469
|
} = params;
|
|
424
470
|
try {
|
|
425
|
-
if (!
|
|
426
|
-
const connection = await
|
|
471
|
+
if (!connectorToLink.connected) {
|
|
472
|
+
const connection = await connectorToLink.connect({
|
|
427
473
|
chainId,
|
|
428
474
|
isAccountLinking: true
|
|
429
475
|
});
|
|
430
476
|
if (!connection) {
|
|
431
|
-
throw
|
|
477
|
+
throw errors.AccountLinkingError.walletProofFailed(`Failed to connect to "${params.connectorName}" for account linking.`);
|
|
432
478
|
}
|
|
433
479
|
}
|
|
434
480
|
} catch (error) {
|
|
435
|
-
if (error instanceof index.
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
throw index.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
|
|
481
|
+
if (error instanceof index.Web3AuthError) throw error;
|
|
482
|
+
throw errors.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
|
|
439
483
|
}
|
|
440
484
|
const trackData = {
|
|
441
485
|
connector: this.name,
|
|
@@ -448,7 +492,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
448
492
|
accessToken,
|
|
449
493
|
idToken
|
|
450
494
|
} = await this.getPrimaryAuthSession(params.authSessionTokens);
|
|
451
|
-
const walletProof = await this.createWalletLinkingProof(params.
|
|
495
|
+
const walletProof = await this.createWalletLinkingProof(params.connectorToLink);
|
|
452
496
|
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
453
497
|
const result = await rest.makeAccountLinkingRequest(authServerUrl, accessToken, {
|
|
454
498
|
idToken,
|
|
@@ -468,9 +512,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
468
512
|
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
469
513
|
// disconnect the wallet connector to avoid any leftover state
|
|
470
514
|
try {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
515
|
+
if (connectorToLink.connected) {
|
|
516
|
+
await connectorToLink.disconnect({
|
|
517
|
+
cleanup: true
|
|
518
|
+
});
|
|
519
|
+
}
|
|
474
520
|
} catch (disconnectError) {
|
|
475
521
|
loglevel.log.debug("Failed to disconnect wallet connector after linking failure", disconnectError);
|
|
476
522
|
}
|
|
@@ -532,7 +578,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
532
578
|
}
|
|
533
579
|
async assertSwitchAccountConnectorMatchesTarget(connector, account) {
|
|
534
580
|
if (!account.chainNamespace) {
|
|
535
|
-
throw
|
|
581
|
+
throw errors.AccountLinkingError.requestFailed(`Could not determine the chain namespace for linked account "${account.eoaAddress}".`);
|
|
536
582
|
}
|
|
537
583
|
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace);
|
|
538
584
|
let connectedAddress = null;
|
|
@@ -546,26 +592,26 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
546
592
|
var _connector$solanaWall, _connector$solanaWall2;
|
|
547
593
|
connectedAddress = (_connector$solanaWall = (_connector$solanaWall2 = connector.solanaWallet) === null || _connector$solanaWall2 === void 0 || (_connector$solanaWall2 = _connector$solanaWall2.accounts) === null || _connector$solanaWall2 === void 0 || (_connector$solanaWall2 = _connector$solanaWall2[0]) === null || _connector$solanaWall2 === void 0 ? void 0 : _connector$solanaWall2.address) !== null && _connector$solanaWall !== void 0 ? _connector$solanaWall : null;
|
|
548
594
|
} else {
|
|
549
|
-
throw
|
|
595
|
+
throw errors.AccountLinkingError.requestFailed(`Unsupported chain namespace "${account.chainNamespace}" for linked account "${account.eoaAddress}".`);
|
|
550
596
|
}
|
|
551
597
|
if (!connectedAddress) {
|
|
552
|
-
throw
|
|
598
|
+
throw errors.AccountLinkingError.requestFailed(`Connector "${account.connector}" is not connected to linked account "${account.eoaAddress}". Connect the intended wallet account and try again.`);
|
|
553
599
|
}
|
|
554
600
|
const isExpectedAddress = chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 ? connectedAddress.toLowerCase() === account.eoaAddress.toLowerCase() : connectedAddress === account.eoaAddress;
|
|
555
601
|
if (!isExpectedAddress) {
|
|
556
|
-
throw
|
|
602
|
+
throw errors.AccountLinkingError.requestFailed(`Connector "${account.connector}" is connected to "${connectedAddress}" instead of linked account "${account.eoaAddress}". Connect the intended wallet account and try again.`);
|
|
557
603
|
}
|
|
558
604
|
}
|
|
559
605
|
toSwitchAccountConnectorError(account, error) {
|
|
560
|
-
if (error instanceof
|
|
606
|
+
if (error instanceof errors.AccountLinkingError && error.code === 5401) {
|
|
561
607
|
return error;
|
|
562
608
|
}
|
|
563
609
|
const message = error instanceof Error ? error.message : String(error);
|
|
564
|
-
const isUnavailableConnectorError = error instanceof
|
|
610
|
+
const isUnavailableConnectorError = error instanceof errors.AccountLinkingError && error.code === 5405 || /not available|not initialized|not ready/i.test(message);
|
|
565
611
|
if (isUnavailableConnectorError) {
|
|
566
|
-
return
|
|
612
|
+
return errors.AccountLinkingError.requestFailed(`Connector "${account.connector}" is not available for linked account "${account.eoaAddress}". Make sure the wallet is installed, unlocked, and accessible, then try again.`, error);
|
|
567
613
|
}
|
|
568
|
-
return
|
|
614
|
+
return errors.AccountLinkingError.requestFailed(`Failed to connect connector "${account.connector}" for linked account "${account.eoaAddress}". ${message}`, error);
|
|
569
615
|
}
|
|
570
616
|
getSwitchAccountTrackData(account) {
|
|
571
617
|
var _account$eoaAddress;
|
|
@@ -606,7 +652,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
606
652
|
idToken = tokenInfo.idToken;
|
|
607
653
|
}
|
|
608
654
|
if (!accessToken || !idToken) {
|
|
609
|
-
throw
|
|
655
|
+
throw errors.AccountLinkingError.primaryTokenNotAvailable("Could not obtain an identity token from the current AUTH session.");
|
|
610
656
|
}
|
|
611
657
|
return {
|
|
612
658
|
accessToken,
|
|
@@ -624,10 +670,10 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
624
670
|
return ((_account$address = account.address) === null || _account$address === void 0 ? void 0 : _account$address.toLowerCase()) === normalizedAddress || ((_account$eoaAddress2 = account.eoaAddress) === null || _account$eoaAddress2 === void 0 ? void 0 : _account$eoaAddress2.toLowerCase()) === normalizedAddress;
|
|
625
671
|
});
|
|
626
672
|
if (!matchedAccount) {
|
|
627
|
-
throw
|
|
673
|
+
throw errors.AccountLinkingError.requestFailed(`No connected wallet matches address "${address}".`);
|
|
628
674
|
}
|
|
629
675
|
if (!matchedAccount.chainNamespace) {
|
|
630
|
-
throw
|
|
676
|
+
throw errors.AccountLinkingError.requestFailed(`Could not determine the chain namespace for address "${address}".`);
|
|
631
677
|
}
|
|
632
678
|
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(matchedAccount.chainNamespace);
|
|
633
679
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
@@ -636,7 +682,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
636
682
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
637
683
|
return "solana";
|
|
638
684
|
}
|
|
639
|
-
throw
|
|
685
|
+
throw errors.AccountLinkingError.requestFailed(`Unsupported chain namespace "${matchedAccount.chainNamespace}" for address "${address}".`);
|
|
640
686
|
}
|
|
641
687
|
async createWalletLinkingProof(connector) {
|
|
642
688
|
// Notify listeners that the linking wallet is about to be asked for a signature so the UI
|
|
@@ -670,31 +716,57 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
670
716
|
network: "solana"
|
|
671
717
|
};
|
|
672
718
|
}
|
|
673
|
-
throw
|
|
719
|
+
throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connector.name}" returned unsupported chain namespace "${chainNamespace}".`);
|
|
674
720
|
}
|
|
675
721
|
async getLinkingWalletAddress(connector, chainNamespace) {
|
|
676
722
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
677
723
|
var _connector$solanaWall3;
|
|
678
724
|
const address = (_connector$solanaWall3 = connector.solanaWallet) === null || _connector$solanaWall3 === void 0 || (_connector$solanaWall3 = _connector$solanaWall3.accounts) === null || _connector$solanaWall3 === void 0 || (_connector$solanaWall3 = _connector$solanaWall3[0]) === null || _connector$solanaWall3 === void 0 ? void 0 : _connector$solanaWall3.address;
|
|
679
725
|
if (!address) {
|
|
680
|
-
throw
|
|
726
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected Solana account found for account linking.");
|
|
681
727
|
}
|
|
682
728
|
return address;
|
|
683
729
|
}
|
|
684
730
|
if (!connector.provider) {
|
|
685
|
-
throw
|
|
731
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
686
732
|
}
|
|
687
733
|
const accounts = await connector.provider.request({
|
|
688
734
|
method: "eth_accounts"
|
|
689
735
|
});
|
|
690
736
|
if (!(accounts !== null && accounts !== void 0 && accounts.length)) {
|
|
691
|
-
throw
|
|
737
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
692
738
|
}
|
|
693
739
|
return accounts[0];
|
|
694
740
|
}
|
|
741
|
+
getWsEmbedProvider() {
|
|
742
|
+
var _this$wsEmbedInstance2, _this$wsEmbedInstance3;
|
|
743
|
+
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;
|
|
744
|
+
}
|
|
745
|
+
bindWsEmbedProviderEvents() {
|
|
746
|
+
const rawProvider = this.getWsEmbedProvider();
|
|
747
|
+
if (this.wsEmbedProviderListenerTarget === rawProvider) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
this.unbindWsEmbedProviderEvents();
|
|
751
|
+
if (!rawProvider) {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
rawProvider.on("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
755
|
+
this.wsEmbedProviderListenerTarget = rawProvider;
|
|
756
|
+
}
|
|
757
|
+
unbindWsEmbedProviderEvents() {
|
|
758
|
+
if (!this.wsEmbedProviderListenerTarget) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
this.wsEmbedProviderListenerTarget.removeListener("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
762
|
+
this.wsEmbedProviderListenerTarget = null;
|
|
763
|
+
}
|
|
695
764
|
setupSolanaWallet() {
|
|
696
765
|
const solanaChains = this.coreOptions.chains.filter(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
697
766
|
if (solanaChains.length === 0 || !this.provider) return;
|
|
767
|
+
if (this._solanaWallet instanceof authSolanaWallet.AuthSolanaWallet) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
698
770
|
this._solanaWallet = new authSolanaWallet.AuthSolanaWallet(this.provider, solanaChains);
|
|
699
771
|
}
|
|
700
772
|
_getFinalPrivKey() {
|
|
@@ -754,13 +826,13 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
754
826
|
} = this.authInstance || {};
|
|
755
827
|
if (sessionId) {
|
|
756
828
|
this.wsEmbedInstance.setAccessTokenProvider(this.accessTokenProvider.bind(this));
|
|
829
|
+
this.bindWsEmbedProviderEvents();
|
|
757
830
|
const isLoggedIn = await this.wsEmbedInstance.connectWithSession({
|
|
758
831
|
sessionId,
|
|
759
832
|
sessionNamespace,
|
|
760
833
|
idToken: await this.getIdToken()
|
|
761
834
|
});
|
|
762
835
|
if (isLoggedIn) {
|
|
763
|
-
var _this$wsEmbedInstance3;
|
|
764
836
|
this.setupSolanaWallet();
|
|
765
837
|
// if getAuthTokenInfo is true, then get auth token info
|
|
766
838
|
// No need to get auth token info for auth connector as it is already handled
|
|
@@ -774,12 +846,6 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
774
846
|
if (params.getAuthTokenInfo) {
|
|
775
847
|
await this.getAuthTokenInfo();
|
|
776
848
|
}
|
|
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
849
|
}
|
|
784
850
|
}
|
|
785
851
|
} else {
|
|
@@ -879,9 +945,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
879
945
|
}).catch(error => {
|
|
880
946
|
// swallow the error, dont need to throw.
|
|
881
947
|
loglevel.log.error("Error during login with social", error);
|
|
882
|
-
this.
|
|
883
|
-
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
884
|
-
});
|
|
948
|
+
this.reportFailedOauthAudit(loginParams);
|
|
885
949
|
});
|
|
886
950
|
verifierWindow.once("close", () => {
|
|
887
951
|
if (!isClosedWindow) {
|
|
@@ -891,9 +955,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
891
955
|
}
|
|
892
956
|
});
|
|
893
957
|
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
|
|
894
|
-
this.
|
|
895
|
-
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
896
|
-
});
|
|
958
|
+
this.reportFailedOauthAudit(loginParams);
|
|
897
959
|
if (error instanceof index.Web3AuthError) {
|
|
898
960
|
throw error;
|
|
899
961
|
}
|
|
@@ -1007,6 +1069,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
1007
1069
|
}
|
|
1008
1070
|
await httpHelpers.put(auditServerUrl, auditPayload);
|
|
1009
1071
|
}
|
|
1072
|
+
reportFailedOauthAudit(loginParams) {
|
|
1073
|
+
void this.auditOAuditProgress(loginParams, "failed").catch(error => {
|
|
1074
|
+
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
1075
|
+
});
|
|
1076
|
+
}
|
|
1010
1077
|
}
|
|
1011
1078
|
const authConnector = params => {
|
|
1012
1079
|
return ({
|
|
@@ -114,7 +114,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
114
114
|
supportedNetworks: caipSupportedNetworks
|
|
115
115
|
},
|
|
116
116
|
ui,
|
|
117
|
-
debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug
|
|
117
|
+
debug: (_this$connectorSettin0 = this.connectorSettings) === null || _this$connectorSettin0 === void 0 ? void 0 : _this$connectorSettin0.debug,
|
|
118
|
+
analytics: {
|
|
119
|
+
integrationType: "web3auth",
|
|
120
|
+
enabled: !this.coreOptions.disableAnalytics
|
|
121
|
+
}
|
|
118
122
|
});
|
|
119
123
|
// Listen for QR code URI from the multichain client (for mobile wallet connection)
|
|
120
124
|
this.multichainClient.on("display_uri", uri => {
|
|
@@ -132,19 +136,27 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
132
136
|
dapp,
|
|
133
137
|
eventHandlers: {
|
|
134
138
|
accountsChanged: _accounts => {
|
|
135
|
-
if (_accounts.length === 0) {
|
|
139
|
+
if (_accounts.length === 0 && this.connected) {
|
|
136
140
|
this.disconnect();
|
|
137
141
|
}
|
|
138
142
|
},
|
|
139
143
|
chainChanged: _chainId => {},
|
|
140
144
|
connect: _result => {},
|
|
141
|
-
disconnect: () =>
|
|
145
|
+
disconnect: () => {
|
|
146
|
+
if (this.connected) {
|
|
147
|
+
this.disconnect();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
142
150
|
},
|
|
143
151
|
api: {
|
|
144
152
|
supportedNetworks: hexSupportedNetworks
|
|
145
153
|
},
|
|
146
154
|
ui,
|
|
147
|
-
debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug
|
|
155
|
+
debug: (_this$connectorSettin1 = this.connectorSettings) === null || _this$connectorSettin1 === void 0 ? void 0 : _this$connectorSettin1.debug,
|
|
156
|
+
analytics: {
|
|
157
|
+
integrationType: "web3auth",
|
|
158
|
+
enabled: !this.coreOptions.disableAnalytics
|
|
159
|
+
}
|
|
148
160
|
});
|
|
149
161
|
this.evmProvider = this.evmClient.getProvider();
|
|
150
162
|
}
|
|
@@ -155,7 +167,11 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
155
167
|
api: {
|
|
156
168
|
supportedNetworks: solanaSupportedNetworks
|
|
157
169
|
},
|
|
158
|
-
skipAutoRegister: true
|
|
170
|
+
skipAutoRegister: true,
|
|
171
|
+
analytics: {
|
|
172
|
+
integrationType: "web3auth",
|
|
173
|
+
enabled: !this.coreOptions.disableAnalytics
|
|
174
|
+
}
|
|
159
175
|
});
|
|
160
176
|
this.solanaProvider = this.solanaClient.getWallet();
|
|
161
177
|
}
|
|
@@ -170,32 +186,20 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
170
186
|
return;
|
|
171
187
|
}
|
|
172
188
|
const coreStatus = this.multichainClient.status;
|
|
173
|
-
if (
|
|
189
|
+
// only connect if the multichain client is connected and autoConnect is true (i.e during the rehydration)
|
|
190
|
+
if (coreStatus === "connected" && options.autoConnect) {
|
|
174
191
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
175
192
|
this.rehydrated = true;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
await this.getAuthTokenInfo();
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else if (coreStatus === "loaded" || coreStatus === "disconnected") {
|
|
188
|
-
this.status = constants.CONNECTOR_STATUS.READY;
|
|
189
|
-
this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.METAMASK);
|
|
190
|
-
} else if (coreStatus === "pending") {
|
|
191
|
-
// 'pending' implies that a transport failed to resume the connection
|
|
192
|
-
// if (options.autoConnect) {
|
|
193
|
-
// this.rehydrated = false;
|
|
194
|
-
// this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, new Error("Failed to resume existing MetaMask Connect session.") as Web3AuthError);
|
|
195
|
-
// } else {
|
|
193
|
+
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
194
|
+
connectorName: index.WALLET_CONNECTORS.METAMASK,
|
|
195
|
+
reconnected: true,
|
|
196
|
+
ethereumProvider: this.evmProvider,
|
|
197
|
+
solanaWallet: this.solanaProvider
|
|
198
|
+
});
|
|
199
|
+
if (options.getAuthTokenInfo) await this.getAuthTokenInfo();
|
|
200
|
+
} else if (coreStatus === "connected" || coreStatus === "loaded" || coreStatus === "disconnected" || coreStatus === "pending") {
|
|
196
201
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
197
202
|
this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.METAMASK);
|
|
198
|
-
// }
|
|
199
203
|
} else {
|
|
200
204
|
// Something unexpected happened
|
|
201
205
|
this.status = constants.CONNECTOR_STATUS.ERRORED;
|
|
@@ -231,11 +235,15 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
231
235
|
connector: index.WALLET_CONNECTORS.METAMASK
|
|
232
236
|
});
|
|
233
237
|
const evmConnectedPromise = new Promise(resolve => {
|
|
234
|
-
|
|
235
|
-
// Wait for EVM provider to be ready
|
|
236
|
-
(_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
|
|
238
|
+
if (this.evmClient.status === "connected") {
|
|
237
239
|
resolve();
|
|
238
|
-
}
|
|
240
|
+
} else {
|
|
241
|
+
var _this$evmProvider;
|
|
242
|
+
// Wait for EVM provider to be ready
|
|
243
|
+
(_this$evmProvider = this.evmProvider) === null || _this$evmProvider === void 0 || _this$evmProvider.once("connect", () => {
|
|
244
|
+
resolve();
|
|
245
|
+
});
|
|
246
|
+
}
|
|
239
247
|
});
|
|
240
248
|
// Connect using the multichain client
|
|
241
249
|
await this.multichainClient.connect(scopes, caipAccountIds, {
|
|
@@ -298,6 +306,7 @@ class MetaMaskConnector extends baseConnector.BaseConnector {
|
|
|
298
306
|
duration: Date.now() - startTime
|
|
299
307
|
}));
|
|
300
308
|
}
|
|
309
|
+
if (index$1.isUserRejectedError(error)) throw index$1.WalletOperationsError.userRejected();
|
|
301
310
|
if (error instanceof index$1.Web3AuthError) throw error;
|
|
302
311
|
throw index$1.WalletLoginError.connectionError("Failed to login with MetaMask wallet", error);
|
|
303
312
|
}
|