@web3auth/no-modal 11.0.0-beta.2 → 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 +47 -34
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +40 -31
- package/dist/lib.cjs/index.js +21 -16
- package/dist/lib.cjs/noModal.js +29 -11
- 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 +11 -4
- package/dist/lib.cjs/react/wagmi/index.js +6 -0
- package/dist/lib.cjs/react/wagmi/provider.js +60 -41
- 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 +2 -2
- 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/useWeb3AuthInnerContextValue.js +13 -6
- package/dist/lib.cjs/vue/wagmi/index.js +6 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +53 -26
- 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 +29 -15
- 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 +25 -5
- 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 +11 -4
- package/dist/lib.esm/react/wagmi/index.js +1 -1
- package/dist/lib.esm/react/wagmi/provider.js +59 -42
- 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 +48 -25
- package/package.json +19 -19
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
+
require('@segment/analytics-next');
|
|
6
|
+
require('../base/loglevel.js');
|
|
7
|
+
require('@toruslabs/base-controllers');
|
|
8
|
+
require('@toruslabs/session-manager');
|
|
9
|
+
require('@web3auth/auth');
|
|
10
|
+
var index = require('../base/errors/index.js');
|
|
11
|
+
require('@toruslabs/constants');
|
|
12
|
+
require('@toruslabs/http-helpers');
|
|
13
|
+
require('../base/constants.js');
|
|
14
|
+
require('../base/wallet/index.js');
|
|
15
|
+
require('../base/connector/connectorStatus.js');
|
|
16
|
+
require('../base/connector/constants.js');
|
|
17
|
+
require('jwt-decode');
|
|
18
|
+
require('../base/plugin/errors.js');
|
|
19
|
+
require('../base/plugin/IPlugin.js');
|
|
20
|
+
|
|
21
|
+
class AccountLinkingError extends index.Web3AuthError {
|
|
22
|
+
constructor(code, message, cause) {
|
|
23
|
+
super(code, message, cause);
|
|
24
|
+
Object.defineProperty(this, "name", {
|
|
25
|
+
value: "AccountLinkingError",
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static fromCode(code, extraMessage = "", cause) {
|
|
30
|
+
return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause);
|
|
31
|
+
}
|
|
32
|
+
static requestFailed(extraMessage = "", cause) {
|
|
33
|
+
return AccountLinkingError.fromCode(5401, extraMessage, cause);
|
|
34
|
+
}
|
|
35
|
+
static serverNotConfigured(extraMessage = "", cause) {
|
|
36
|
+
return AccountLinkingError.fromCode(5402, extraMessage, cause);
|
|
37
|
+
}
|
|
38
|
+
static primaryTokenNotAvailable(extraMessage = "", cause) {
|
|
39
|
+
return AccountLinkingError.fromCode(5403, extraMessage, cause);
|
|
40
|
+
}
|
|
41
|
+
static walletProofFailed(extraMessage = "", cause) {
|
|
42
|
+
return AccountLinkingError.fromCode(5404, extraMessage, cause);
|
|
43
|
+
}
|
|
44
|
+
static unsupportedConnector(extraMessage = "", cause) {
|
|
45
|
+
return AccountLinkingError.fromCode(5405, extraMessage, cause);
|
|
46
|
+
}
|
|
47
|
+
static cannotUnlinkActiveAccount() {
|
|
48
|
+
return AccountLinkingError.fromCode(5406);
|
|
49
|
+
}
|
|
50
|
+
static accountNotLinked(message = "", cause) {
|
|
51
|
+
return AccountLinkingError.fromCode(5407, message, cause);
|
|
52
|
+
}
|
|
53
|
+
static cannotUnlinkPrimaryAccount() {
|
|
54
|
+
return AccountLinkingError.fromCode(5408);
|
|
55
|
+
}
|
|
56
|
+
toString() {
|
|
57
|
+
return `[${this.code}] ${this.message}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
_defineProperty(AccountLinkingError, "messages", {
|
|
61
|
+
5000: "Custom",
|
|
62
|
+
5401: "Account linking request failed",
|
|
63
|
+
5402: "Citadel server URL is not configured",
|
|
64
|
+
5403: "Primary identity token is not available",
|
|
65
|
+
5404: "Failed to obtain wallet proof token",
|
|
66
|
+
5405: "Connector is not supported for wallet linking",
|
|
67
|
+
5406: "Cannot unlink active account",
|
|
68
|
+
5407: "Account not linked",
|
|
69
|
+
5408: "Cannot unlink primary account"
|
|
70
|
+
});
|
|
71
|
+
async function getAccountLinkingRequestError(error) {
|
|
72
|
+
if (error instanceof AccountLinkingError) {
|
|
73
|
+
return error;
|
|
74
|
+
}
|
|
75
|
+
if (error instanceof Response) {
|
|
76
|
+
if (error.status === 409) {
|
|
77
|
+
return AccountLinkingError.requestFailed("This wallet address is already registered on this dApp");
|
|
78
|
+
}
|
|
79
|
+
if (error.json && typeof error.json === "function") {
|
|
80
|
+
try {
|
|
81
|
+
var _json$message;
|
|
82
|
+
const json = await error.json();
|
|
83
|
+
return AccountLinkingError.requestFailed((_json$message = json.message) !== null && _json$message !== void 0 ? _json$message : "Failed to link account");
|
|
84
|
+
} catch {
|
|
85
|
+
// continue
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return AccountLinkingError.requestFailed(error instanceof Error ? error.message : JSON.stringify(error), error);
|
|
90
|
+
}
|
|
91
|
+
function formatAccountLinkingErrorMessage(error, fallbackMessage = "Unknown error during the operation.") {
|
|
92
|
+
if (error instanceof AccountLinkingError) {
|
|
93
|
+
return error.toString();
|
|
94
|
+
}
|
|
95
|
+
if (error instanceof index.Web3AuthError) {
|
|
96
|
+
return `[${error.code}] Account linking error: ${error.message || fallbackMessage}`;
|
|
97
|
+
}
|
|
98
|
+
if (error instanceof Error) {
|
|
99
|
+
return `Account linking error: ${error.message || fallbackMessage}`;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const stringifiedError = JSON.stringify(error);
|
|
103
|
+
return stringifiedError;
|
|
104
|
+
} catch {
|
|
105
|
+
return fallbackMessage;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
exports.AccountLinkingError = AccountLinkingError;
|
|
110
|
+
exports.formatAccountLinkingErrorMessage = formatAccountLinkingErrorMessage;
|
|
111
|
+
exports.getAccountLinkingRequestError = getAccountLinkingRequestError;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var errors = require('./errors.js');
|
|
3
4
|
var rest = require('./rest.js');
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
|
|
8
|
+
exports.AccountLinkingError = errors.AccountLinkingError;
|
|
9
|
+
exports.formatAccountLinkingErrorMessage = errors.formatAccountLinkingErrorMessage;
|
|
10
|
+
exports.getAccountLinkingRequestError = errors.getAccountLinkingRequestError;
|
|
7
11
|
exports.makeAccountLinkingRequest = rest.makeAccountLinkingRequest;
|
|
8
12
|
exports.makeAccountUnlinkingRequest = rest.makeAccountUnlinkingRequest;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var httpHelpers = require('@toruslabs/http-helpers');
|
|
4
|
-
var
|
|
4
|
+
var errors = require('./errors.js');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Send both identity proofs to the Citadel account-linking endpoint and
|
|
@@ -19,13 +19,13 @@ async function makeAccountLinkingRequest(authServerUrl, accessToken, payload) {
|
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
} catch (cause) {
|
|
22
|
-
const
|
|
23
|
-
throw
|
|
22
|
+
const accountLinkingError = await errors.getAccountLinkingRequestError(cause);
|
|
23
|
+
throw accountLinkingError;
|
|
24
24
|
}
|
|
25
25
|
if (!result.success) {
|
|
26
26
|
var _result$message;
|
|
27
27
|
const errMessage = (_result$message = result.message) !== null && _result$message !== void 0 ? _result$message : "Failed to link account";
|
|
28
|
-
throw
|
|
28
|
+
throw errors.AccountLinkingError.requestFailed(errMessage);
|
|
29
29
|
}
|
|
30
30
|
return result;
|
|
31
31
|
}
|
|
@@ -40,12 +40,12 @@ async function makeAccountUnlinkingRequest(authServerUrl, accessToken, payload)
|
|
|
40
40
|
});
|
|
41
41
|
} catch (cause) {
|
|
42
42
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
43
|
-
throw
|
|
43
|
+
throw errors.AccountLinkingError.requestFailed(message, cause);
|
|
44
44
|
}
|
|
45
45
|
if (!result.success) {
|
|
46
46
|
var _result$message2;
|
|
47
47
|
const errMessage = (_result$message2 = result.message) !== null && _result$message2 !== void 0 ? _result$message2 : "Failed to unlink account";
|
|
48
|
-
throw
|
|
48
|
+
throw errors.AccountLinkingError.requestFailed(errMessage);
|
|
49
49
|
}
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
4
|
|
|
5
|
+
const WEB3AUTH_CONNECTOR_ID = "web3auth";
|
|
5
6
|
const CONNECTOR_STATUS = {
|
|
6
7
|
NOT_READY: "not_ready",
|
|
7
8
|
READY: "ready",
|
|
@@ -37,3 +38,4 @@ exports.CONNECTOR_CATEGORY = CONNECTOR_CATEGORY;
|
|
|
37
38
|
exports.CONNECTOR_EVENTS = CONNECTOR_EVENTS;
|
|
38
39
|
exports.CONNECTOR_INITIAL_AUTHENTICATION_MODE = CONNECTOR_INITIAL_AUTHENTICATION_MODE;
|
|
39
40
|
exports.CONNECTOR_STATUS = CONNECTOR_STATUS;
|
|
41
|
+
exports.WEB3AUTH_CONNECTOR_ID = WEB3AUTH_CONNECTOR_ID;
|
|
@@ -183,7 +183,11 @@ class WalletOperationsError extends Web3AuthError {
|
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
static fromCode(code, extraMessage = "", cause) {
|
|
186
|
-
|
|
186
|
+
let message = WalletOperationsError.messages[code];
|
|
187
|
+
if (extraMessage) {
|
|
188
|
+
message = `${message}, ${extraMessage}`;
|
|
189
|
+
}
|
|
190
|
+
return new WalletOperationsError(code, message, cause);
|
|
187
191
|
}
|
|
188
192
|
// Custom methods
|
|
189
193
|
static chainIDNotAllowed(extraMessage = "", cause) {
|
|
@@ -195,58 +199,16 @@ class WalletOperationsError extends Web3AuthError {
|
|
|
195
199
|
static chainNamespaceNotAllowed(extraMessage = "", cause) {
|
|
196
200
|
return WalletOperationsError.fromCode(5203, extraMessage, cause);
|
|
197
201
|
}
|
|
202
|
+
static userRejected(extraMessage = "", cause) {
|
|
203
|
+
return WalletOperationsError.fromCode(5204, extraMessage, cause);
|
|
204
|
+
}
|
|
198
205
|
}
|
|
199
206
|
_defineProperty(WalletOperationsError, "messages", {
|
|
200
207
|
5000: "Custom",
|
|
201
208
|
5201: "Provided chainId is not allowed",
|
|
202
|
-
5202: "This operation is not allowed"
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
constructor(code, message, cause) {
|
|
206
|
-
super(code, message, cause);
|
|
207
|
-
Object.defineProperty(this, "name", {
|
|
208
|
-
value: "AccountLinkingError",
|
|
209
|
-
configurable: true
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
static fromCode(code, extraMessage = "", cause) {
|
|
213
|
-
return new AccountLinkingError(code, `${AccountLinkingError.messages[code]}. ${extraMessage}`, cause);
|
|
214
|
-
}
|
|
215
|
-
static requestFailed(extraMessage = "", cause) {
|
|
216
|
-
return AccountLinkingError.fromCode(5401, extraMessage, cause);
|
|
217
|
-
}
|
|
218
|
-
static serverNotConfigured(extraMessage = "", cause) {
|
|
219
|
-
return AccountLinkingError.fromCode(5402, extraMessage, cause);
|
|
220
|
-
}
|
|
221
|
-
static primaryTokenNotAvailable(extraMessage = "", cause) {
|
|
222
|
-
return AccountLinkingError.fromCode(5403, extraMessage, cause);
|
|
223
|
-
}
|
|
224
|
-
static walletProofFailed(extraMessage = "", cause) {
|
|
225
|
-
return AccountLinkingError.fromCode(5404, extraMessage, cause);
|
|
226
|
-
}
|
|
227
|
-
static unsupportedConnector(extraMessage = "", cause) {
|
|
228
|
-
return AccountLinkingError.fromCode(5405, extraMessage, cause);
|
|
229
|
-
}
|
|
230
|
-
static cannotUnlinkActiveAccount() {
|
|
231
|
-
return AccountLinkingError.fromCode(5406);
|
|
232
|
-
}
|
|
233
|
-
static accountNotLinked(message = "", cause) {
|
|
234
|
-
return AccountLinkingError.fromCode(5407, message, cause);
|
|
235
|
-
}
|
|
236
|
-
static cannotUnlinkPrimaryAccount() {
|
|
237
|
-
return AccountLinkingError.fromCode(5408);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
_defineProperty(AccountLinkingError, "messages", {
|
|
241
|
-
5000: "Custom",
|
|
242
|
-
5401: "Account linking request failed",
|
|
243
|
-
5402: "Citadel server URL is not configured",
|
|
244
|
-
5403: "Primary identity token is not available",
|
|
245
|
-
5404: "Failed to obtain wallet proof token",
|
|
246
|
-
5405: "Connector is not supported for wallet linking",
|
|
247
|
-
5406: "Cannot unlink active account",
|
|
248
|
-
5407: "Account not linked",
|
|
249
|
-
5408: "Cannot unlink primary account"
|
|
209
|
+
5202: "This operation is not allowed",
|
|
210
|
+
5203: "Chain namespace is not allowed",
|
|
211
|
+
5204: "User rejected the request"
|
|
250
212
|
});
|
|
251
213
|
class WalletProviderError extends Web3AuthError {
|
|
252
214
|
constructor(code, message, cause) {
|
|
@@ -278,10 +240,19 @@ _defineProperty(WalletProviderError, "messages", {
|
|
|
278
240
|
5302: "'args.method' must be a non-empty string.",
|
|
279
241
|
5303: "'args.params' must be an object or array if provided."
|
|
280
242
|
});
|
|
243
|
+
function isUserRejectedError(error) {
|
|
244
|
+
if (error instanceof Web3AuthError && error.code === 5203) return true;
|
|
245
|
+
if (error instanceof Error) {
|
|
246
|
+
var _error$message;
|
|
247
|
+
const normalizedMessage = ((_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) || "";
|
|
248
|
+
return normalizedMessage.includes("user rejected the request");
|
|
249
|
+
}
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
281
252
|
|
|
282
|
-
exports.AccountLinkingError = AccountLinkingError;
|
|
283
253
|
exports.WalletInitializationError = WalletInitializationError;
|
|
284
254
|
exports.WalletLoginError = WalletLoginError;
|
|
285
255
|
exports.WalletOperationsError = WalletOperationsError;
|
|
286
256
|
exports.WalletProviderError = WalletProviderError;
|
|
287
257
|
exports.Web3AuthError = Web3AuthError;
|
|
258
|
+
exports.isUserRejectedError = isUserRejectedError;
|
|
@@ -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
|
|
148
|
+
const sdkVersion = "11.0.0";
|
|
149
149
|
const getErrorAnalyticsProperties = error => {
|
|
150
150
|
try {
|
|
151
151
|
const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -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 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,8 @@ 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 errors = require('../../account-linking/errors.js');
|
|
27
28
|
var rest = require('../../account-linking/rest.js');
|
|
28
|
-
var baseControllers = require('@toruslabs/base-controllers');
|
|
29
29
|
|
|
30
30
|
// Auth connections that have been deprecated and are no longer supported by the SDK.
|
|
31
31
|
// Passing any of these as `authConnection` results in a hard error so consumers
|
|
@@ -315,6 +315,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
315
315
|
});
|
|
316
316
|
}
|
|
317
317
|
async getLinkedAccounts() {
|
|
318
|
+
var _citadelUserInfo$acco, _this$solanaWallet;
|
|
318
319
|
const accessToken = await this.authInstance.authSessionManager.getAccessToken();
|
|
319
320
|
if (!accessToken) throw index.WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
|
|
320
321
|
const citadelUserInfo = await httpHelpers.get(`${utils.citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
|
|
@@ -322,11 +323,27 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
322
323
|
Authorization: `Bearer ${accessToken}`
|
|
323
324
|
}
|
|
324
325
|
});
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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;
|
|
330
347
|
}
|
|
331
348
|
async switchChain(params, init = false) {
|
|
332
349
|
super.checkSwitchChainRequirements(params, init);
|
|
@@ -342,13 +359,11 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
342
359
|
if (newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
343
360
|
var _this$wsEmbedInstance;
|
|
344
361
|
if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw index.WalletInitializationError.notReady("Wallet embed is not ready");
|
|
345
|
-
const
|
|
346
|
-
// WsEmbed expects the chainId in hex format
|
|
347
|
-
const chainIdHex = viem.numberToHex(chainIdNum);
|
|
362
|
+
const caipChainId = baseControllers.getCaipChainId(newChainConfig);
|
|
348
363
|
await this.wsEmbedInstance.provider.request({
|
|
349
364
|
method: "wallet_switchChain",
|
|
350
365
|
params: {
|
|
351
|
-
chainId:
|
|
366
|
+
chainId: caipChainId
|
|
352
367
|
}
|
|
353
368
|
});
|
|
354
369
|
} else {
|
|
@@ -397,7 +412,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
397
412
|
const linkedAccounts = (_userInfo$linkedAccou = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou !== void 0 ? _userInfo$linkedAccou : [];
|
|
398
413
|
const targetAccount = linkedAccounts.find(candidate => candidate.id === account.id);
|
|
399
414
|
if (!targetAccount) {
|
|
400
|
-
throw
|
|
415
|
+
throw errors.AccountLinkingError.requestFailed(`No connected wallet matches account id "${account.id}". Refresh user info and try again.`);
|
|
401
416
|
}
|
|
402
417
|
const currentActiveAccount = context.activeAccount;
|
|
403
418
|
const isTargetAlreadyActive = currentActiveAccount ? currentActiveAccount.id === targetAccount.id : targetAccount.isPrimary;
|
|
@@ -411,7 +426,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
411
426
|
const ethereumProvider = this.provider;
|
|
412
427
|
const solanaWallet = this.solanaWallet;
|
|
413
428
|
if (!ethereumProvider && !solanaWallet) {
|
|
414
|
-
throw
|
|
429
|
+
throw errors.AccountLinkingError.requestFailed("Failed to restore the primary AUTH session for account switch.");
|
|
415
430
|
}
|
|
416
431
|
return {
|
|
417
432
|
kind: "primary",
|
|
@@ -459,14 +474,12 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
459
474
|
isAccountLinking: true
|
|
460
475
|
});
|
|
461
476
|
if (!connection) {
|
|
462
|
-
throw
|
|
477
|
+
throw errors.AccountLinkingError.walletProofFailed(`Failed to connect to "${params.connectorName}" for account linking.`);
|
|
463
478
|
}
|
|
464
479
|
}
|
|
465
480
|
} catch (error) {
|
|
466
|
-
if (error instanceof index.
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
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);
|
|
470
483
|
}
|
|
471
484
|
const trackData = {
|
|
472
485
|
connector: this.name,
|
|
@@ -565,7 +578,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
565
578
|
}
|
|
566
579
|
async assertSwitchAccountConnectorMatchesTarget(connector, account) {
|
|
567
580
|
if (!account.chainNamespace) {
|
|
568
|
-
throw
|
|
581
|
+
throw errors.AccountLinkingError.requestFailed(`Could not determine the chain namespace for linked account "${account.eoaAddress}".`);
|
|
569
582
|
}
|
|
570
583
|
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace);
|
|
571
584
|
let connectedAddress = null;
|
|
@@ -579,26 +592,26 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
579
592
|
var _connector$solanaWall, _connector$solanaWall2;
|
|
580
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;
|
|
581
594
|
} else {
|
|
582
|
-
throw
|
|
595
|
+
throw errors.AccountLinkingError.requestFailed(`Unsupported chain namespace "${account.chainNamespace}" for linked account "${account.eoaAddress}".`);
|
|
583
596
|
}
|
|
584
597
|
if (!connectedAddress) {
|
|
585
|
-
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.`);
|
|
586
599
|
}
|
|
587
600
|
const isExpectedAddress = chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 ? connectedAddress.toLowerCase() === account.eoaAddress.toLowerCase() : connectedAddress === account.eoaAddress;
|
|
588
601
|
if (!isExpectedAddress) {
|
|
589
|
-
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.`);
|
|
590
603
|
}
|
|
591
604
|
}
|
|
592
605
|
toSwitchAccountConnectorError(account, error) {
|
|
593
|
-
if (error instanceof
|
|
606
|
+
if (error instanceof errors.AccountLinkingError && error.code === 5401) {
|
|
594
607
|
return error;
|
|
595
608
|
}
|
|
596
609
|
const message = error instanceof Error ? error.message : String(error);
|
|
597
|
-
const isUnavailableConnectorError = error instanceof
|
|
610
|
+
const isUnavailableConnectorError = error instanceof errors.AccountLinkingError && error.code === 5405 || /not available|not initialized|not ready/i.test(message);
|
|
598
611
|
if (isUnavailableConnectorError) {
|
|
599
|
-
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);
|
|
600
613
|
}
|
|
601
|
-
return
|
|
614
|
+
return errors.AccountLinkingError.requestFailed(`Failed to connect connector "${account.connector}" for linked account "${account.eoaAddress}". ${message}`, error);
|
|
602
615
|
}
|
|
603
616
|
getSwitchAccountTrackData(account) {
|
|
604
617
|
var _account$eoaAddress;
|
|
@@ -639,7 +652,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
639
652
|
idToken = tokenInfo.idToken;
|
|
640
653
|
}
|
|
641
654
|
if (!accessToken || !idToken) {
|
|
642
|
-
throw
|
|
655
|
+
throw errors.AccountLinkingError.primaryTokenNotAvailable("Could not obtain an identity token from the current AUTH session.");
|
|
643
656
|
}
|
|
644
657
|
return {
|
|
645
658
|
accessToken,
|
|
@@ -657,10 +670,10 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
657
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;
|
|
658
671
|
});
|
|
659
672
|
if (!matchedAccount) {
|
|
660
|
-
throw
|
|
673
|
+
throw errors.AccountLinkingError.requestFailed(`No connected wallet matches address "${address}".`);
|
|
661
674
|
}
|
|
662
675
|
if (!matchedAccount.chainNamespace) {
|
|
663
|
-
throw
|
|
676
|
+
throw errors.AccountLinkingError.requestFailed(`Could not determine the chain namespace for address "${address}".`);
|
|
664
677
|
}
|
|
665
678
|
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(matchedAccount.chainNamespace);
|
|
666
679
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
@@ -669,7 +682,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
669
682
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
670
683
|
return "solana";
|
|
671
684
|
}
|
|
672
|
-
throw
|
|
685
|
+
throw errors.AccountLinkingError.requestFailed(`Unsupported chain namespace "${matchedAccount.chainNamespace}" for address "${address}".`);
|
|
673
686
|
}
|
|
674
687
|
async createWalletLinkingProof(connector) {
|
|
675
688
|
// Notify listeners that the linking wallet is about to be asked for a signature so the UI
|
|
@@ -703,25 +716,25 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
703
716
|
network: "solana"
|
|
704
717
|
};
|
|
705
718
|
}
|
|
706
|
-
throw
|
|
719
|
+
throw errors.AccountLinkingError.unsupportedConnector(`Connector "${connector.name}" returned unsupported chain namespace "${chainNamespace}".`);
|
|
707
720
|
}
|
|
708
721
|
async getLinkingWalletAddress(connector, chainNamespace) {
|
|
709
722
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
710
723
|
var _connector$solanaWall3;
|
|
711
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;
|
|
712
725
|
if (!address) {
|
|
713
|
-
throw
|
|
726
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected Solana account found for account linking.");
|
|
714
727
|
}
|
|
715
728
|
return address;
|
|
716
729
|
}
|
|
717
730
|
if (!connector.provider) {
|
|
718
|
-
throw
|
|
731
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
719
732
|
}
|
|
720
733
|
const accounts = await connector.provider.request({
|
|
721
734
|
method: "eth_accounts"
|
|
722
735
|
});
|
|
723
736
|
if (!(accounts !== null && accounts !== void 0 && accounts.length)) {
|
|
724
|
-
throw
|
|
737
|
+
throw errors.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
725
738
|
}
|
|
726
739
|
return accounts[0];
|
|
727
740
|
}
|
|
@@ -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
|
}
|