@web3auth/no-modal 11.0.0-beta.0 → 11.0.0-beta.1
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/index.js +8 -0
- package/dist/lib.cjs/account-linking/react.js +95 -0
- package/dist/lib.cjs/account-linking/rest.js +54 -0
- package/dist/lib.cjs/account-linking/vue.js +98 -0
- package/dist/lib.cjs/base/analytics.js +17 -2
- package/dist/lib.cjs/base/connector/constants.js +2 -0
- package/dist/lib.cjs/base/errors/index.js +48 -0
- package/dist/lib.cjs/base/utils.js +15 -3
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +427 -50
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +42 -23
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +41 -24
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +76 -45
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +41 -13
- package/dist/lib.cjs/index.js +20 -13
- package/dist/lib.cjs/noModal.js +811 -110
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +1 -1
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +65 -33
- package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +34 -20
- package/dist/lib.cjs/react/hooks/useWallets.js +51 -0
- package/dist/lib.cjs/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.cjs/react/index.js +2 -0
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +2 -2
- package/dist/lib.cjs/react/solana/provider.js +2 -0
- package/dist/lib.cjs/types/account-linking/index.d.ts +2 -0
- package/dist/lib.cjs/types/account-linking/interfaces.d.ts +90 -0
- package/dist/lib.cjs/types/account-linking/react.d.ts +19 -0
- package/dist/lib.cjs/types/account-linking/rest.d.ts +9 -0
- package/dist/lib.cjs/types/account-linking/vue.d.ts +20 -0
- package/dist/lib.cjs/types/base/analytics.d.ts +9 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +5 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +2 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +51 -6
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +39 -2
- package/dist/lib.cjs/types/base/errors/index.d.ts +13 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +3 -1
- package/dist/lib.cjs/types/base/utils.d.ts +7 -1
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +27 -3
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +77 -2
- package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +6 -0
- package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +6 -0
- package/dist/lib.cjs/types/index.d.ts +1 -0
- package/dist/lib.cjs/types/noModal.d.ts +104 -5
- package/dist/lib.cjs/types/providers/base-provider/baseProvider.d.ts +7 -0
- package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -0
- package/dist/lib.cjs/types/react/hooks/useWallets.d.ts +8 -0
- package/dist/lib.cjs/types/vue/composables/index.d.ts +1 -0
- package/dist/lib.cjs/types/vue/composables/useWallets.d.ts +9 -0
- package/dist/lib.cjs/vue/composables/useWallets.js +52 -0
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +2 -2
- package/dist/lib.cjs/vue/index.js +2 -0
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +2 -2
- package/dist/lib.cjs/vue/solana/provider.js +3 -0
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
- package/dist/lib.cjs/vue/wagmi/provider.js +19 -7
- package/dist/lib.esm/account-linking/index.js +1 -0
- package/dist/lib.esm/account-linking/react.js +74 -0
- package/dist/lib.esm/account-linking/rest.js +51 -0
- package/dist/lib.esm/account-linking/vue.js +78 -0
- package/dist/lib.esm/base/analytics.js +17 -2
- package/dist/lib.esm/base/connector/constants.js +2 -0
- package/dist/lib.esm/base/errors/index.js +48 -1
- package/dist/lib.esm/base/utils.js +16 -4
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +386 -9
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +43 -24
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +43 -26
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +2 -2
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +2 -2
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +3 -3
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +80 -49
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -2
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +43 -15
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +1 -1
- package/dist/lib.esm/index.js +4 -3
- package/dist/lib.esm/noModal.js +828 -119
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +3 -3
- package/dist/lib.esm/providers/base-provider/baseProvider.js +68 -38
- package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +36 -21
- package/dist/lib.esm/react/hooks/useWallets.js +33 -0
- package/dist/lib.esm/react/hooks/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/react/index.js +1 -0
- package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +2 -2
- package/dist/lib.esm/react/solana/provider.js +4 -1
- package/dist/lib.esm/react/wagmi/provider.js +1 -1
- package/dist/lib.esm/vue/composables/useCheckout.js +1 -1
- package/dist/lib.esm/vue/composables/useFunding.js +1 -1
- package/dist/lib.esm/vue/composables/useReceive.js +1 -1
- package/dist/lib.esm/vue/composables/useSwap.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +1 -1
- package/dist/lib.esm/vue/composables/useWalletUI.js +1 -1
- package/dist/lib.esm/vue/composables/useWallets.js +35 -0
- package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -2
- package/dist/lib.esm/vue/index.js +1 -0
- package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSignMessage.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +2 -2
- package/dist/lib.esm/vue/solana/provider.js +4 -0
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
- package/dist/lib.esm/vue/wagmi/provider.js +20 -8
- package/package.json +43 -19
|
@@ -8,19 +8,20 @@ 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
|
-
require('
|
|
12
|
-
var
|
|
11
|
+
var rest = require('../../account-linking/rest.js');
|
|
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');
|
|
15
15
|
var connectorStatus = require('../../base/connector/connectorStatus.js');
|
|
16
16
|
var constants = require('../../base/connector/constants.js');
|
|
17
17
|
require('jwt-decode');
|
|
18
18
|
require('../../base/constants.js');
|
|
19
|
-
var index
|
|
19
|
+
var index = require('../../base/errors/index.js');
|
|
20
|
+
var loglevel = require('../../base/loglevel.js');
|
|
20
21
|
require('../../base/plugin/errors.js');
|
|
21
22
|
require('../../base/plugin/IPlugin.js');
|
|
22
23
|
var utils = require('../../base/utils.js');
|
|
23
|
-
var index = require('../../base/wallet/index.js');
|
|
24
|
+
var index$1 = require('../../base/wallet/index.js');
|
|
24
25
|
var utils$1 = require('../utils.js');
|
|
25
26
|
var authSolanaWallet = require('./authSolanaWallet.js');
|
|
26
27
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
@@ -28,7 +29,7 @@ var baseControllers = require('@toruslabs/base-controllers');
|
|
|
28
29
|
class AuthConnector extends baseConnector.BaseConnector {
|
|
29
30
|
constructor(params) {
|
|
30
31
|
super(params);
|
|
31
|
-
_defineProperty(this, "name", index.WALLET_CONNECTORS.AUTH);
|
|
32
|
+
_defineProperty(this, "name", index$1.WALLET_CONNECTORS.AUTH);
|
|
32
33
|
_defineProperty(this, "connectorNamespace", IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN);
|
|
33
34
|
_defineProperty(this, "type", constants.CONNECTOR_CATEGORY.IN_APP);
|
|
34
35
|
_defineProperty(this, "authInstance", null);
|
|
@@ -43,6 +44,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
43
44
|
_defineProperty(this, "authConnectionConfig", []);
|
|
44
45
|
_defineProperty(this, "wsEmbedInstancePromise", null);
|
|
45
46
|
_defineProperty(this, "_solanaWallet", null);
|
|
47
|
+
_defineProperty(this, "analytics", void 0);
|
|
46
48
|
this.authOptions = params.connectorSettings;
|
|
47
49
|
this.loginSettings = params.loginSettings || {
|
|
48
50
|
authConnection: ""
|
|
@@ -51,6 +53,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
51
53
|
loginMode: wsEmbed.WS_EMBED_LOGIN_MODE.PLUGIN
|
|
52
54
|
};
|
|
53
55
|
this.authConnectionConfig = params.authConnectionConfig || [];
|
|
56
|
+
this.analytics = params.analytics || new analytics.Analytics();
|
|
54
57
|
}
|
|
55
58
|
get provider() {
|
|
56
59
|
if (this.status !== constants.CONNECTOR_STATUS.NOT_READY) {
|
|
@@ -81,9 +84,9 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
81
84
|
super.checkInitializationRequirements({
|
|
82
85
|
chainConfig
|
|
83
86
|
});
|
|
84
|
-
if (!this.coreOptions.clientId) throw index
|
|
85
|
-
if (!this.authOptions) throw index
|
|
86
|
-
if (this.authConnectionConfig.length === 0) throw index
|
|
87
|
+
if (!this.coreOptions.clientId) throw index.WalletInitializationError.invalidParams("clientId is required before auth's initialization");
|
|
88
|
+
if (!this.authOptions) throw index.WalletInitializationError.invalidParams("authOptions is required before auth's initialization");
|
|
89
|
+
if (this.authConnectionConfig.length === 0) throw index.WalletInitializationError.invalidParams("authConnectionConfig is required before auth's initialization");
|
|
87
90
|
const isRedirectResult = this.authOptions.uxMode === auth.UX_MODE.REDIRECT;
|
|
88
91
|
this.authOptions = _objectSpread(_objectSpread({}, this.authOptions), {}, {
|
|
89
92
|
replaceUrlOnRedirect: isRedirectResult,
|
|
@@ -130,7 +133,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
130
133
|
break;
|
|
131
134
|
}
|
|
132
135
|
case baseControllers.CHAIN_NAMESPACES.XRPL:
|
|
133
|
-
throw index
|
|
136
|
+
throw index.WalletLoginError.connectionError("Private key provider is required for XRPL");
|
|
134
137
|
default:
|
|
135
138
|
{
|
|
136
139
|
const {
|
|
@@ -149,7 +152,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
149
152
|
loglevel.log.debug("initializing auth connector");
|
|
150
153
|
await authInstancePromise;
|
|
151
154
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
152
|
-
this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.AUTH);
|
|
155
|
+
this.emit(constants.CONNECTOR_EVENTS.READY, index$1.WALLET_CONNECTORS.AUTH);
|
|
153
156
|
try {
|
|
154
157
|
const {
|
|
155
158
|
sessionId
|
|
@@ -165,7 +168,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
165
168
|
// if here, this means that the connector is cached but the sessionId is not available.
|
|
166
169
|
// this can happen if the sessionId has expired.
|
|
167
170
|
// we are throwing an error to reset the cached state.
|
|
168
|
-
throw index
|
|
171
|
+
throw index.WalletLoginError.connectionError("Failed to rehydrate");
|
|
169
172
|
}
|
|
170
173
|
} catch (error) {
|
|
171
174
|
this.emit(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
@@ -175,7 +178,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
175
178
|
super.checkConnectionRequirements();
|
|
176
179
|
this.status = constants.CONNECTOR_STATUS.CONNECTING;
|
|
177
180
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTING, _objectSpread(_objectSpread({}, params), {}, {
|
|
178
|
-
connector: index.WALLET_CONNECTORS.AUTH
|
|
181
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
179
182
|
}));
|
|
180
183
|
try {
|
|
181
184
|
await this.connectWithProvider(params);
|
|
@@ -191,50 +194,50 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
191
194
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
192
195
|
this.emit(constants.CONNECTOR_EVENTS.ERRORED, error);
|
|
193
196
|
if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes("user closed popup")) {
|
|
194
|
-
throw index
|
|
195
|
-
} else if (error instanceof index
|
|
197
|
+
throw index.WalletLoginError.popupClosed();
|
|
198
|
+
} else if (error instanceof index.Web3AuthError) {
|
|
196
199
|
throw error;
|
|
197
200
|
}
|
|
198
|
-
throw index
|
|
201
|
+
throw index.WalletLoginError.connectionError("Failed to login with auth", error);
|
|
199
202
|
}
|
|
200
203
|
}
|
|
201
204
|
async enableMFA(params = {
|
|
202
205
|
authConnection: ""
|
|
203
206
|
}) {
|
|
204
|
-
if (!this.connected) throw index
|
|
205
|
-
if (!this.authInstance) throw index
|
|
207
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
208
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
206
209
|
try {
|
|
207
210
|
const result = await this.authInstance.enableMFA(params);
|
|
208
211
|
// In redirect mode, the result is not available immediately, so we emit the event when the result is available.
|
|
209
212
|
if (result) this.emit(constants.CONNECTOR_EVENTS.MFA_ENABLED, result);
|
|
210
213
|
} catch (error) {
|
|
211
214
|
loglevel.log.error("Failed to enable MFA with auth provider", error);
|
|
212
|
-
if (error instanceof index
|
|
215
|
+
if (error instanceof index.Web3AuthError) {
|
|
213
216
|
throw error;
|
|
214
217
|
}
|
|
215
|
-
throw index
|
|
218
|
+
throw index.WalletLoginError.connectionError("Failed to enable MFA with auth", error);
|
|
216
219
|
}
|
|
217
220
|
}
|
|
218
221
|
async manageMFA(params = {
|
|
219
222
|
authConnection: ""
|
|
220
223
|
}) {
|
|
221
|
-
if (!this.connected) throw index
|
|
222
|
-
if (!this.authInstance) throw index
|
|
224
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
225
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
223
226
|
try {
|
|
224
227
|
await this.authInstance.manageMFA(params);
|
|
225
228
|
} catch (error) {
|
|
226
229
|
loglevel.log.error("Failed to manage MFA with auth provider", error);
|
|
227
|
-
if (error instanceof index
|
|
230
|
+
if (error instanceof index.Web3AuthError) {
|
|
228
231
|
throw error;
|
|
229
232
|
}
|
|
230
|
-
throw index
|
|
233
|
+
throw index.WalletLoginError.connectionError("Failed to manage MFA with auth", error);
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
async disconnect(options = {
|
|
234
237
|
cleanup: false
|
|
235
238
|
}) {
|
|
236
|
-
if (!this.connected) throw index
|
|
237
|
-
if (!this.authInstance) throw index
|
|
239
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
240
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
238
241
|
this.status = constants.CONNECTOR_STATUS.DISCONNECTING;
|
|
239
242
|
await this.authInstance.logout();
|
|
240
243
|
if (this.wsEmbedInstance) await this.wsEmbedInstance.logout();
|
|
@@ -249,19 +252,21 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
249
252
|
}
|
|
250
253
|
this.rehydrated = false;
|
|
251
254
|
this._solanaWallet = null;
|
|
252
|
-
this.emit(constants.CONNECTOR_EVENTS.DISCONNECTED
|
|
255
|
+
this.emit(constants.CONNECTOR_EVENTS.DISCONNECTED, {
|
|
256
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
257
|
+
});
|
|
253
258
|
}
|
|
254
259
|
async getAuthTokenInfo() {
|
|
255
|
-
if (!this.canAuthorize) throw index
|
|
260
|
+
if (!this.canAuthorize) throw index.WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
256
261
|
this.status = constants.CONNECTOR_STATUS.AUTHORIZING;
|
|
257
262
|
this.emit(constants.CONNECTOR_EVENTS.AUTHORIZING, {
|
|
258
|
-
connector: index.WALLET_CONNECTORS.AUTH
|
|
263
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
259
264
|
});
|
|
260
265
|
const userInfo = await this.getUserInfo();
|
|
261
266
|
this.status = constants.CONNECTOR_STATUS.AUTHORIZED;
|
|
262
267
|
const [accessToken, refreshToken] = await Promise.all([this.authInstance.authSessionManager.getAccessToken(), this.authInstance.authSessionManager.getRefreshToken()]);
|
|
263
268
|
this.emit(constants.CONNECTOR_EVENTS.AUTHORIZED, {
|
|
264
|
-
connector: index.WALLET_CONNECTORS.AUTH,
|
|
269
|
+
connector: index$1.WALLET_CONNECTORS.AUTH,
|
|
265
270
|
authTokenInfo: {
|
|
266
271
|
idToken: userInfo.idToken,
|
|
267
272
|
accessToken,
|
|
@@ -275,10 +280,26 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
275
280
|
};
|
|
276
281
|
}
|
|
277
282
|
async getUserInfo() {
|
|
278
|
-
if (!this.canAuthorize) throw index
|
|
279
|
-
if (!this.authInstance) throw index
|
|
280
|
-
const userInfo = this.authInstance.getUserInfo();
|
|
281
|
-
return userInfo
|
|
283
|
+
if (!this.canAuthorize) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
284
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
285
|
+
const [userInfo, linkedAccounts] = await Promise.all([this.authInstance.getUserInfo(), this.getLinkedAccounts()]);
|
|
286
|
+
return _objectSpread(_objectSpread({}, userInfo), {}, {
|
|
287
|
+
linkedAccounts
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
async getLinkedAccounts() {
|
|
291
|
+
const accessToken = await this.authInstance.authSessionManager.getAccessToken();
|
|
292
|
+
if (!accessToken) throw index.WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
|
|
293
|
+
const citadelUserInfo = await httpHelpers.get(`${utils.citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
|
|
294
|
+
headers: {
|
|
295
|
+
Authorization: `Bearer ${accessToken}`
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
const linkedAccounts = (citadelUserInfo === null || citadelUserInfo === void 0 ? void 0 : citadelUserInfo.accounts) || [];
|
|
299
|
+
return linkedAccounts.map(account => _objectSpread(_objectSpread({}, account), {}, {
|
|
300
|
+
// by default, the primary account is the active account
|
|
301
|
+
active: account.isPrimary
|
|
302
|
+
}));
|
|
282
303
|
}
|
|
283
304
|
async switchChain(params, init = false) {
|
|
284
305
|
super.checkSwitchChainRequirements(params, init);
|
|
@@ -290,10 +311,10 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
290
311
|
} = this.provider;
|
|
291
312
|
if (currentChainId === newChainId) return;
|
|
292
313
|
const newChainConfig = this.coreOptions.chains.find(c => c.chainId === newChainId);
|
|
293
|
-
if (!newChainConfig) throw index
|
|
314
|
+
if (!newChainConfig) throw index.WalletInitializationError.invalidParams("Chain config is not available");
|
|
294
315
|
if (newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
295
316
|
var _this$wsEmbedInstance2;
|
|
296
|
-
if (!((_this$wsEmbedInstance2 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance2 !== void 0 && _this$wsEmbedInstance2.provider)) throw index
|
|
317
|
+
if (!((_this$wsEmbedInstance2 = this.wsEmbedInstance) !== null && _this$wsEmbedInstance2 !== void 0 && _this$wsEmbedInstance2.provider)) throw index.WalletInitializationError.notReady("Wallet embed is not ready");
|
|
297
318
|
const fullChainId = utils.getCaipChainId(newChainConfig);
|
|
298
319
|
await this.wsEmbedInstance.provider.request({
|
|
299
320
|
method: "wallet_switchChain",
|
|
@@ -307,7 +328,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
307
328
|
}
|
|
308
329
|
}
|
|
309
330
|
async cleanup() {
|
|
310
|
-
if (!this.authInstance) throw index
|
|
331
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
311
332
|
await this.authInstance.cleanup();
|
|
312
333
|
if (this.wsEmbedInstance) {
|
|
313
334
|
this.wsEmbedInstance.clearInit();
|
|
@@ -331,6 +352,346 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
331
352
|
});
|
|
332
353
|
return providerConfig;
|
|
333
354
|
}
|
|
355
|
+
async generateChallengeAndSign() {
|
|
356
|
+
// we do not support this for auth connector, as of now. since auth login returns a valid idToken
|
|
357
|
+
throw new Error("Not implemented");
|
|
358
|
+
}
|
|
359
|
+
async switchAccount(account, context) {
|
|
360
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
361
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before switching accounts.");
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
var _userInfo$linkedAccou;
|
|
365
|
+
const userInfo = await this.getUserInfo();
|
|
366
|
+
const linkedAccounts = (_userInfo$linkedAccou = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou !== void 0 ? _userInfo$linkedAccou : [];
|
|
367
|
+
const targetAccount = linkedAccounts.find(candidate => candidate.id === account.id);
|
|
368
|
+
if (!targetAccount) {
|
|
369
|
+
throw index.AccountLinkingError.requestFailed(`No connected wallet matches account id "${account.id}". Refresh user info and try again.`);
|
|
370
|
+
}
|
|
371
|
+
const currentActiveAccount = context.activeAccount;
|
|
372
|
+
const isTargetAlreadyActive = currentActiveAccount ? currentActiveAccount.id === targetAccount.id : targetAccount.isPrimary;
|
|
373
|
+
if (isTargetAlreadyActive) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_STARTED, this.getSwitchAccountTrackData(targetAccount));
|
|
377
|
+
if (targetAccount.connector === index$1.WALLET_CONNECTORS.AUTH && targetAccount.isPrimary) {
|
|
378
|
+
var _this$provider$chainI, _this$provider;
|
|
379
|
+
const activeChainId = this.getChainIdForLinkedAccount(targetAccount, (_this$provider$chainI = (_this$provider = this.provider) === null || _this$provider === void 0 ? void 0 : _this$provider.chainId) !== null && _this$provider$chainI !== void 0 ? _this$provider$chainI : context.currentChainId);
|
|
380
|
+
const ethereumProvider = this.provider;
|
|
381
|
+
const solanaWallet = this.solanaWallet;
|
|
382
|
+
if (!ethereumProvider && !solanaWallet) {
|
|
383
|
+
throw index.AccountLinkingError.requestFailed("Failed to restore the primary AUTH session for account switch.");
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
kind: "primary",
|
|
387
|
+
targetAccount,
|
|
388
|
+
activeAccount: null,
|
|
389
|
+
activeChainId,
|
|
390
|
+
connectorName: this.name,
|
|
391
|
+
connectorNamespace: this.connectorNamespace,
|
|
392
|
+
ethereumProvider,
|
|
393
|
+
solanaWallet
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
kind: "external",
|
|
398
|
+
targetAccount,
|
|
399
|
+
activeAccount: targetAccount,
|
|
400
|
+
activeChainId: this.getChainIdForLinkedAccount(targetAccount, context.currentChainId)
|
|
401
|
+
};
|
|
402
|
+
} catch (error) {
|
|
403
|
+
await this.trackSwitchAccountFailed(account, error);
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async trackSwitchAccountCompleted(account) {
|
|
408
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_COMPLETED, _objectSpread(_objectSpread({}, this.getSwitchAccountTrackData(account)), {}, {
|
|
409
|
+
connector: account.connector
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
async trackSwitchAccountFailed(account, error) {
|
|
413
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_FAILED, _objectSpread(_objectSpread({}, this.getSwitchAccountTrackData(account)), utils.getErrorAnalyticsProperties(error)));
|
|
414
|
+
}
|
|
415
|
+
async linkAccount(params) {
|
|
416
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
417
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before linking an account.");
|
|
418
|
+
}
|
|
419
|
+
const {
|
|
420
|
+
connectorName,
|
|
421
|
+
chainId,
|
|
422
|
+
walletConnector
|
|
423
|
+
} = params;
|
|
424
|
+
try {
|
|
425
|
+
if (!walletConnector.connected) {
|
|
426
|
+
const connection = await walletConnector.connect({
|
|
427
|
+
chainId,
|
|
428
|
+
isAccountLinking: true
|
|
429
|
+
});
|
|
430
|
+
if (!connection) {
|
|
431
|
+
throw index.AccountLinkingError.walletProofFailed(`Failed to connect to "${params.connectorName}" for account linking.`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} catch (error) {
|
|
435
|
+
if (error instanceof index.AccountLinkingError) {
|
|
436
|
+
throw error;
|
|
437
|
+
}
|
|
438
|
+
throw index.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
|
|
439
|
+
}
|
|
440
|
+
const trackData = {
|
|
441
|
+
connector: this.name,
|
|
442
|
+
linking_connector: connectorName,
|
|
443
|
+
chain_id: params.chainId
|
|
444
|
+
};
|
|
445
|
+
try {
|
|
446
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_STARTED, trackData);
|
|
447
|
+
const {
|
|
448
|
+
accessToken,
|
|
449
|
+
idToken
|
|
450
|
+
} = await this.getPrimaryAuthSession(params.authSessionTokens);
|
|
451
|
+
const walletProof = await this.createWalletLinkingProof(params.walletConnector);
|
|
452
|
+
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
453
|
+
const result = await rest.makeAccountLinkingRequest(authServerUrl, accessToken, {
|
|
454
|
+
idToken,
|
|
455
|
+
network: walletProof.network,
|
|
456
|
+
connector: params.connectorName,
|
|
457
|
+
message: walletProof.challenge,
|
|
458
|
+
signature: {
|
|
459
|
+
s: walletProof.signature,
|
|
460
|
+
t: walletProof.signatureType
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
|
|
464
|
+
linked_address: walletProof.address
|
|
465
|
+
}));
|
|
466
|
+
return result;
|
|
467
|
+
} catch (error) {
|
|
468
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
469
|
+
// disconnect the wallet connector to avoid any leftover state
|
|
470
|
+
try {
|
|
471
|
+
await walletConnector.disconnect({
|
|
472
|
+
cleanup: true
|
|
473
|
+
});
|
|
474
|
+
} catch (disconnectError) {
|
|
475
|
+
loglevel.log.debug("Failed to disconnect wallet connector after linking failure", disconnectError);
|
|
476
|
+
}
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
async unlinkAccount(params) {
|
|
481
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
482
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before unlinking an account.");
|
|
483
|
+
}
|
|
484
|
+
const {
|
|
485
|
+
address,
|
|
486
|
+
authSessionTokens
|
|
487
|
+
} = params;
|
|
488
|
+
const trackData = {
|
|
489
|
+
connector: this.name,
|
|
490
|
+
address
|
|
491
|
+
};
|
|
492
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_STARTED, trackData);
|
|
493
|
+
try {
|
|
494
|
+
const {
|
|
495
|
+
accessToken,
|
|
496
|
+
idToken,
|
|
497
|
+
linkedAccounts
|
|
498
|
+
} = await this.getPrimaryAuthSession(authSessionTokens, {
|
|
499
|
+
includeLinkedAccounts: true
|
|
500
|
+
});
|
|
501
|
+
const network = this.getNetworkForUnlinkAddress(linkedAccounts, address);
|
|
502
|
+
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
503
|
+
const result = await rest.makeAccountUnlinkingRequest(authServerUrl, accessToken, {
|
|
504
|
+
idToken,
|
|
505
|
+
address,
|
|
506
|
+
network
|
|
507
|
+
});
|
|
508
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
|
|
509
|
+
linked_address: address
|
|
510
|
+
}));
|
|
511
|
+
return result;
|
|
512
|
+
} catch (error) {
|
|
513
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
getChainIdForLinkedAccount(account, preferredChainId) {
|
|
518
|
+
const accountChainNamespace = account.chainNamespace ? utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace) : null;
|
|
519
|
+
if (preferredChainId) {
|
|
520
|
+
const preferredChain = this.coreOptions.chains.find(chain => chain.chainId === preferredChainId);
|
|
521
|
+
if (preferredChain && (!accountChainNamespace || preferredChain.chainNamespace === accountChainNamespace)) {
|
|
522
|
+
return preferredChainId;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (accountChainNamespace) {
|
|
526
|
+
const namespaceChain = this.coreOptions.chains.find(chain => chain.chainNamespace === accountChainNamespace);
|
|
527
|
+
if (namespaceChain) {
|
|
528
|
+
return namespaceChain.chainId;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
throw index.WalletInitializationError.invalidParams(`No compatible chainId found for connector "${account.connector}".`);
|
|
532
|
+
}
|
|
533
|
+
async assertSwitchAccountConnectorMatchesTarget(connector, account) {
|
|
534
|
+
if (!account.chainNamespace) {
|
|
535
|
+
throw index.AccountLinkingError.requestFailed(`Could not determine the chain namespace for linked account "${account.eoaAddress}".`);
|
|
536
|
+
}
|
|
537
|
+
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace);
|
|
538
|
+
let connectedAddress = null;
|
|
539
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
540
|
+
var _accounts$;
|
|
541
|
+
const accounts = connector.provider ? await connector.provider.request({
|
|
542
|
+
method: "eth_accounts"
|
|
543
|
+
}) : [];
|
|
544
|
+
connectedAddress = (_accounts$ = accounts === null || accounts === void 0 ? void 0 : accounts[0]) !== null && _accounts$ !== void 0 ? _accounts$ : null;
|
|
545
|
+
} else if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
546
|
+
var _connector$solanaWall, _connector$solanaWall2;
|
|
547
|
+
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
|
+
} else {
|
|
549
|
+
throw index.AccountLinkingError.requestFailed(`Unsupported chain namespace "${account.chainNamespace}" for linked account "${account.eoaAddress}".`);
|
|
550
|
+
}
|
|
551
|
+
if (!connectedAddress) {
|
|
552
|
+
throw index.AccountLinkingError.requestFailed(`Connector "${account.connector}" is not connected to linked account "${account.eoaAddress}". Connect the intended wallet account and try again.`);
|
|
553
|
+
}
|
|
554
|
+
const isExpectedAddress = chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 ? connectedAddress.toLowerCase() === account.eoaAddress.toLowerCase() : connectedAddress === account.eoaAddress;
|
|
555
|
+
if (!isExpectedAddress) {
|
|
556
|
+
throw index.AccountLinkingError.requestFailed(`Connector "${account.connector}" is connected to "${connectedAddress}" instead of linked account "${account.eoaAddress}". Connect the intended wallet account and try again.`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
toSwitchAccountConnectorError(account, error) {
|
|
560
|
+
if (error instanceof index.AccountLinkingError && error.code === 5401) {
|
|
561
|
+
return error;
|
|
562
|
+
}
|
|
563
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
564
|
+
const isUnavailableConnectorError = error instanceof index.AccountLinkingError && error.code === 5405 || /not available|not initialized|not ready/i.test(message);
|
|
565
|
+
if (isUnavailableConnectorError) {
|
|
566
|
+
return index.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
|
+
}
|
|
568
|
+
return index.AccountLinkingError.requestFailed(`Failed to connect connector "${account.connector}" for linked account "${account.eoaAddress}". ${message}`, error);
|
|
569
|
+
}
|
|
570
|
+
getSwitchAccountTrackData(account) {
|
|
571
|
+
var _account$eoaAddress;
|
|
572
|
+
return {
|
|
573
|
+
connector: this.name,
|
|
574
|
+
account_id: account.id,
|
|
575
|
+
account_type: account.accountType,
|
|
576
|
+
switched_to_address: (_account$eoaAddress = account.eoaAddress) !== null && _account$eoaAddress !== void 0 ? _account$eoaAddress : null
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
async getPrimaryAuthSession(authSessionTokens, options = {}) {
|
|
580
|
+
const {
|
|
581
|
+
accessToken: cachedAccessToken,
|
|
582
|
+
idToken: cachedIdToken
|
|
583
|
+
} = authSessionTokens;
|
|
584
|
+
const {
|
|
585
|
+
includeLinkedAccounts = false
|
|
586
|
+
} = options;
|
|
587
|
+
let accessToken = cachedAccessToken;
|
|
588
|
+
let idToken = cachedIdToken;
|
|
589
|
+
let linkedAccounts = [];
|
|
590
|
+
if (includeLinkedAccounts) {
|
|
591
|
+
const userInfoPromise = this.getUserInfo();
|
|
592
|
+
if (!accessToken || !idToken) {
|
|
593
|
+
var _userInfo$linkedAccou2;
|
|
594
|
+
const [tokenInfo, userInfo] = await Promise.all([this.getAuthTokenInfo(), userInfoPromise]);
|
|
595
|
+
accessToken = tokenInfo.accessToken;
|
|
596
|
+
idToken = tokenInfo.idToken;
|
|
597
|
+
linkedAccounts = (_userInfo$linkedAccou2 = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou2 !== void 0 ? _userInfo$linkedAccou2 : [];
|
|
598
|
+
} else {
|
|
599
|
+
var _userInfo$linkedAccou3;
|
|
600
|
+
const userInfo = await userInfoPromise;
|
|
601
|
+
linkedAccounts = (_userInfo$linkedAccou3 = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou3 !== void 0 ? _userInfo$linkedAccou3 : [];
|
|
602
|
+
}
|
|
603
|
+
} else if (!accessToken || !idToken) {
|
|
604
|
+
const tokenInfo = await this.getAuthTokenInfo();
|
|
605
|
+
accessToken = tokenInfo.accessToken;
|
|
606
|
+
idToken = tokenInfo.idToken;
|
|
607
|
+
}
|
|
608
|
+
if (!accessToken || !idToken) {
|
|
609
|
+
throw index.AccountLinkingError.primaryTokenNotAvailable("Could not obtain an identity token from the current AUTH session.");
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
accessToken,
|
|
613
|
+
idToken,
|
|
614
|
+
linkedAccounts
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
getNetworkForUnlinkAddress(accounts, address) {
|
|
618
|
+
const matchedAccount = accounts.find(account => {
|
|
619
|
+
var _account$address, _account$eoaAddress2;
|
|
620
|
+
if (!account.chainNamespace || utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
const normalizedAddress = address.toLowerCase();
|
|
624
|
+
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
|
+
});
|
|
626
|
+
if (!matchedAccount) {
|
|
627
|
+
throw index.AccountLinkingError.requestFailed(`No connected wallet matches address "${address}".`);
|
|
628
|
+
}
|
|
629
|
+
if (!matchedAccount.chainNamespace) {
|
|
630
|
+
throw index.AccountLinkingError.requestFailed(`Could not determine the chain namespace for address "${address}".`);
|
|
631
|
+
}
|
|
632
|
+
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(matchedAccount.chainNamespace);
|
|
633
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
634
|
+
return "ethereum";
|
|
635
|
+
}
|
|
636
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
637
|
+
return "solana";
|
|
638
|
+
}
|
|
639
|
+
throw index.AccountLinkingError.requestFailed(`Unsupported chain namespace "${matchedAccount.chainNamespace}" for address "${address}".`);
|
|
640
|
+
}
|
|
641
|
+
async createWalletLinkingProof(connector) {
|
|
642
|
+
// Notify listeners that the linking wallet is about to be asked for a signature so the UI
|
|
643
|
+
// (e.g. modal) can switch from a "connecting" loader to an "authorizing" prompt while the
|
|
644
|
+
// user reviews the signature request inside their wallet. Emitted on the isolated wallet
|
|
645
|
+
// connector (not the auth connector) so it doesn't mutate the global SDK status.
|
|
646
|
+
connector.emit(constants.CONNECTOR_EVENTS.AUTHORIZING, {
|
|
647
|
+
connector: connector.name
|
|
648
|
+
});
|
|
649
|
+
const {
|
|
650
|
+
challenge,
|
|
651
|
+
signature,
|
|
652
|
+
chainNamespace
|
|
653
|
+
} = await connector.generateChallengeAndSign();
|
|
654
|
+
const address = await this.getLinkingWalletAddress(connector, chainNamespace);
|
|
655
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
656
|
+
return {
|
|
657
|
+
address,
|
|
658
|
+
challenge,
|
|
659
|
+
signature,
|
|
660
|
+
signatureType: "eip191",
|
|
661
|
+
network: "ethereum"
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
665
|
+
return {
|
|
666
|
+
address,
|
|
667
|
+
challenge,
|
|
668
|
+
signature,
|
|
669
|
+
signatureType: "sip99",
|
|
670
|
+
network: "solana"
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
throw index.AccountLinkingError.unsupportedConnector(`Connector "${connector.name}" returned unsupported chain namespace "${chainNamespace}".`);
|
|
674
|
+
}
|
|
675
|
+
async getLinkingWalletAddress(connector, chainNamespace) {
|
|
676
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
677
|
+
var _connector$solanaWall3;
|
|
678
|
+
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
|
+
if (!address) {
|
|
680
|
+
throw index.AccountLinkingError.walletProofFailed("No connected Solana account found for account linking.");
|
|
681
|
+
}
|
|
682
|
+
return address;
|
|
683
|
+
}
|
|
684
|
+
if (!connector.provider) {
|
|
685
|
+
throw index.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
686
|
+
}
|
|
687
|
+
const accounts = await connector.provider.request({
|
|
688
|
+
method: "eth_accounts"
|
|
689
|
+
});
|
|
690
|
+
if (!(accounts !== null && accounts !== void 0 && accounts.length)) {
|
|
691
|
+
throw index.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
692
|
+
}
|
|
693
|
+
return accounts[0];
|
|
694
|
+
}
|
|
334
695
|
setupSolanaWallet() {
|
|
335
696
|
const solanaChains = this.coreOptions.chains.filter(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
336
697
|
if (solanaChains.length === 0 || !this.provider) return;
|
|
@@ -345,7 +706,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
345
706
|
// when useSFAKey is set to true.
|
|
346
707
|
// This is to ensure that when there is no user session active, we don't throw an exception.
|
|
347
708
|
if (this.authInstance.privKey && !this.authInstance.coreKitKey) {
|
|
348
|
-
throw index
|
|
709
|
+
throw index.WalletLoginError.sfaKeyNotFound();
|
|
349
710
|
}
|
|
350
711
|
finalPrivKey = this.authInstance.coreKitKey;
|
|
351
712
|
}
|
|
@@ -353,9 +714,9 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
353
714
|
}
|
|
354
715
|
async connectWithProvider(params) {
|
|
355
716
|
var _this$authInstance, _params$extraLoginOpt, _this$authInstance2, _this$authInstance3;
|
|
356
|
-
if (!this.authInstance) throw index
|
|
717
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
357
718
|
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
358
|
-
if (!chainConfig) throw index
|
|
719
|
+
if (!chainConfig) throw index.WalletLoginError.connectionError("Chain config is not available");
|
|
359
720
|
const {
|
|
360
721
|
chainNamespace
|
|
361
722
|
} = chainConfig;
|
|
@@ -381,7 +742,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
381
742
|
if (this.authInstance.sessionId) {
|
|
382
743
|
await this.authInstance.logout();
|
|
383
744
|
}
|
|
384
|
-
throw index
|
|
745
|
+
throw index.WalletLoginError.sfaKeyNotFound("This typically occurs when the authentication method used does not provide SFA keys (e.g., default auth connection).");
|
|
385
746
|
}
|
|
386
747
|
// setup WS embed if chainNamespace is EIP155 or SOLANA
|
|
387
748
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 || chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
@@ -405,7 +766,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
405
766
|
// No need to get auth token info for auth connector as it is already handled
|
|
406
767
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
407
768
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
408
|
-
connectorName: index.WALLET_CONNECTORS.AUTH,
|
|
769
|
+
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
409
770
|
reconnected: this.rehydrated,
|
|
410
771
|
ethereumProvider: this.provider,
|
|
411
772
|
solanaWallet: this._solanaWallet
|
|
@@ -428,7 +789,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
428
789
|
await this.privateKeyProvider.setupProvider(finalPrivKey, params.chainId);
|
|
429
790
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
430
791
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
431
|
-
connectorName: index.WALLET_CONNECTORS.AUTH,
|
|
792
|
+
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
432
793
|
ethereumProvider: this.provider,
|
|
433
794
|
solanaWallet: this._solanaWallet,
|
|
434
795
|
reconnected: this.rehydrated
|
|
@@ -443,7 +804,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
443
804
|
authConnectionId: params.authConnectionId,
|
|
444
805
|
groupedAuthConnectionId: params.groupedAuthConnectionId
|
|
445
806
|
});
|
|
446
|
-
if (!(providerConfig !== null && providerConfig !== void 0 && providerConfig.authConnection)) throw index
|
|
807
|
+
if (!(providerConfig !== null && providerConfig !== void 0 && providerConfig.authConnection)) throw index.WalletLoginError.connectionError("Invalid auth connection.");
|
|
447
808
|
const jwtParams = _objectSpread(_objectSpread(_objectSpread({}, providerConfig.jwtParameters || {}), params.extraLoginOptions || {}), {}, {
|
|
448
809
|
login_hint: params.loginHint || ((_params$extraLoginOpt3 = params.extraLoginOptions) === null || _params$extraLoginOpt3 === void 0 ? void 0 : _params$extraLoginOpt3.login_hint)
|
|
449
810
|
});
|
|
@@ -526,17 +887,17 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
526
887
|
if (!isClosedWindow) {
|
|
527
888
|
securePubSub$1.cleanup();
|
|
528
889
|
this.authInstance.postLoginCancelledMessage(nonce);
|
|
529
|
-
reject(index
|
|
890
|
+
reject(index.WalletLoginError.popupClosed());
|
|
530
891
|
}
|
|
531
892
|
});
|
|
532
893
|
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
|
|
533
894
|
this.auditOAuditProgress(loginParams, "failed").catch(error => {
|
|
534
895
|
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
535
896
|
});
|
|
536
|
-
if (error instanceof index
|
|
897
|
+
if (error instanceof index.Web3AuthError) {
|
|
537
898
|
throw error;
|
|
538
899
|
}
|
|
539
|
-
reject(index
|
|
900
|
+
reject(index.WalletLoginError.connectionError(error instanceof Error ? error.message : error || "Failed to login with social"));
|
|
540
901
|
});
|
|
541
902
|
});
|
|
542
903
|
}
|
|
@@ -549,7 +910,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
549
910
|
return this.authInstance.getAccessToken();
|
|
550
911
|
}
|
|
551
912
|
async getIdToken() {
|
|
552
|
-
if (!this.authInstance) throw index
|
|
913
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
553
914
|
return this.authInstance.authSessionManager.getIdToken();
|
|
554
915
|
}
|
|
555
916
|
getOriginData() {
|
|
@@ -582,7 +943,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
582
943
|
});
|
|
583
944
|
// throw error only when we cannot find the login config and authConnectionId is not provided in the params.
|
|
584
945
|
// otherwise, we will use the params to create a new auth connection config in the auth instance.
|
|
585
|
-
if (!(loginConfig !== null && loginConfig !== void 0 && loginConfig.authConnection) && !params.authConnectionId) throw index
|
|
946
|
+
if (!(loginConfig !== null && loginConfig !== void 0 && loginConfig.authConnection) && !params.authConnectionId) throw index.WalletLoginError.connectionError("Invalid auth connection.");
|
|
586
947
|
if (!(loginConfig !== null && loginConfig !== void 0 && loginConfig.authConnection)) {
|
|
587
948
|
this.authInstance.options.authConnectionConfig.push({
|
|
588
949
|
authConnection: params.authConnection,
|
|
@@ -602,7 +963,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
602
963
|
} = utils$1.parseToken(params.extraLoginOptions.id_token);
|
|
603
964
|
finalUserId = auth.getUserId(payload, loginParams.authConnection, finalExtraLoginOptions.userIdField, finalExtraLoginOptions.isUserIdCaseSensitive);
|
|
604
965
|
} else {
|
|
605
|
-
throw index
|
|
966
|
+
throw index.WalletLoginError.connectionError("Invalid login hint or id_token");
|
|
606
967
|
}
|
|
607
968
|
// Adds the login_hint to the extraLoginOptions.
|
|
608
969
|
loginParams.extraLoginOptions = _objectSpread(_objectSpread({}, finalExtraLoginOptions), {}, {
|
|
@@ -650,7 +1011,8 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
650
1011
|
const authConnector = params => {
|
|
651
1012
|
return ({
|
|
652
1013
|
projectConfig,
|
|
653
|
-
coreOptions
|
|
1014
|
+
coreOptions,
|
|
1015
|
+
analytics
|
|
654
1016
|
}) => {
|
|
655
1017
|
var _coreOptions$uiConfig, _coreOptions$walletSe, _coreOptions$walletSe2, _coreOptions$walletSe3;
|
|
656
1018
|
// Connector settings
|
|
@@ -692,9 +1054,24 @@ const authConnector = params => {
|
|
|
692
1054
|
mfaLevel: coreOptions.mfaLevel
|
|
693
1055
|
}),
|
|
694
1056
|
coreOptions,
|
|
1057
|
+
analytics,
|
|
695
1058
|
authConnectionConfig: projectConfig.embeddedWalletAuth
|
|
696
1059
|
});
|
|
697
1060
|
};
|
|
698
1061
|
};
|
|
1062
|
+
function isAuthConnector(connector) {
|
|
1063
|
+
if (!connector || connector.name !== index$1.WALLET_CONNECTORS.AUTH) {
|
|
1064
|
+
return false;
|
|
1065
|
+
}
|
|
1066
|
+
const maybeAuthConnector = connector;
|
|
1067
|
+
return typeof maybeAuthConnector.switchAccount === "function" && typeof maybeAuthConnector.linkAccount === "function" && typeof maybeAuthConnector.unlinkAccount === "function";
|
|
1068
|
+
}
|
|
1069
|
+
function assertAuthConnector(connector, errorMessage = "Account linking is only supported when connected with the AUTH connector.") {
|
|
1070
|
+
if (!isAuthConnector(connector)) {
|
|
1071
|
+
throw index.WalletLoginError.unsupportedOperation(errorMessage);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
699
1074
|
|
|
1075
|
+
exports.assertAuthConnector = assertAuthConnector;
|
|
700
1076
|
exports.authConnector = authConnector;
|
|
1077
|
+
exports.isAuthConnector = isAuthConnector;
|