@web3auth/no-modal 11.0.0-beta.0 → 11.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs/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 +501 -70
- 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 +834 -117
- 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 +43 -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 +7 -1
- package/dist/lib.cjs/react/wagmi/provider.js +37 -5
- 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 +33 -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 +50 -23
- package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +13 -4
- package/dist/lib.cjs/vue/wagmi/provider.js +35 -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 +462 -31
- 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 +851 -126
- 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 +45 -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 +9 -2
- package/dist/lib.esm/react/wagmi/provider.js +39 -7
- 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 +51 -24
- package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +12 -3
- package/dist/lib.esm/vue/wagmi/provider.js +36 -8
- package/package.json +44 -20
|
@@ -8,27 +8,38 @@ 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 viem = require('viem');
|
|
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');
|
|
27
|
+
var rest = require('../../account-linking/rest.js');
|
|
26
28
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
27
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
|
+
}
|
|
28
39
|
class AuthConnector extends baseConnector.BaseConnector {
|
|
29
40
|
constructor(params) {
|
|
30
41
|
super(params);
|
|
31
|
-
_defineProperty(this, "name", index.WALLET_CONNECTORS.AUTH);
|
|
42
|
+
_defineProperty(this, "name", index$1.WALLET_CONNECTORS.AUTH);
|
|
32
43
|
_defineProperty(this, "connectorNamespace", IChainInterface.CONNECTOR_NAMESPACES.MULTICHAIN);
|
|
33
44
|
_defineProperty(this, "type", constants.CONNECTOR_CATEGORY.IN_APP);
|
|
34
45
|
_defineProperty(this, "authInstance", null);
|
|
@@ -42,7 +53,22 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
42
53
|
_defineProperty(this, "wsEmbedInstance", null);
|
|
43
54
|
_defineProperty(this, "authConnectionConfig", []);
|
|
44
55
|
_defineProperty(this, "wsEmbedInstancePromise", null);
|
|
56
|
+
_defineProperty(this, "wsEmbedProviderListenerTarget", null);
|
|
45
57
|
_defineProperty(this, "_solanaWallet", null);
|
|
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
|
+
});
|
|
46
72
|
this.authOptions = params.connectorSettings;
|
|
47
73
|
this.loginSettings = params.loginSettings || {
|
|
48
74
|
authConnection: ""
|
|
@@ -51,13 +77,12 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
51
77
|
loginMode: wsEmbed.WS_EMBED_LOGIN_MODE.PLUGIN
|
|
52
78
|
};
|
|
53
79
|
this.authConnectionConfig = params.authConnectionConfig || [];
|
|
80
|
+
this.analytics = params.analytics || new analytics.Analytics();
|
|
54
81
|
}
|
|
55
82
|
get provider() {
|
|
56
83
|
if (this.status !== constants.CONNECTOR_STATUS.NOT_READY) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return this.wsEmbedInstance.provider;
|
|
60
|
-
} else if (this.privateKeyProvider) return this.privateKeyProvider;
|
|
84
|
+
const wsEmbedProvider = this.getWsEmbedProvider();
|
|
85
|
+
return wsEmbedProvider || this.privateKeyProvider;
|
|
61
86
|
}
|
|
62
87
|
return null;
|
|
63
88
|
}
|
|
@@ -81,9 +106,9 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
81
106
|
super.checkInitializationRequirements({
|
|
82
107
|
chainConfig
|
|
83
108
|
});
|
|
84
|
-
if (!this.coreOptions.clientId) throw index
|
|
85
|
-
if (!this.authOptions) throw index
|
|
86
|
-
if (this.authConnectionConfig.length === 0) throw index
|
|
109
|
+
if (!this.coreOptions.clientId) throw index.WalletInitializationError.invalidParams("clientId is required before auth's initialization");
|
|
110
|
+
if (!this.authOptions) throw index.WalletInitializationError.invalidParams("authOptions is required before auth's initialization");
|
|
111
|
+
if (this.authConnectionConfig.length === 0) throw index.WalletInitializationError.invalidParams("authConnectionConfig is required before auth's initialization");
|
|
87
112
|
const isRedirectResult = this.authOptions.uxMode === auth.UX_MODE.REDIRECT;
|
|
88
113
|
this.authOptions = _objectSpread(_objectSpread({}, this.authOptions), {}, {
|
|
89
114
|
replaceUrlOnRedirect: isRedirectResult,
|
|
@@ -124,13 +149,14 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
124
149
|
buildEnv: this.authOptions.buildEnv,
|
|
125
150
|
whiteLabel: _objectSpread(_objectSpread({}, this.authOptions.whiteLabel), this.wsSettings.whiteLabel)
|
|
126
151
|
})).then(() => {
|
|
152
|
+
this.bindWsEmbedProviderEvents();
|
|
127
153
|
this.wsEmbedInstancePromise = null;
|
|
128
154
|
return;
|
|
129
155
|
});
|
|
130
156
|
break;
|
|
131
157
|
}
|
|
132
158
|
case baseControllers.CHAIN_NAMESPACES.XRPL:
|
|
133
|
-
throw index
|
|
159
|
+
throw index.WalletLoginError.connectionError("Private key provider is required for XRPL");
|
|
134
160
|
default:
|
|
135
161
|
{
|
|
136
162
|
const {
|
|
@@ -149,7 +175,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
149
175
|
loglevel.log.debug("initializing auth connector");
|
|
150
176
|
await authInstancePromise;
|
|
151
177
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
152
|
-
this.emit(constants.CONNECTOR_EVENTS.READY, index.WALLET_CONNECTORS.AUTH);
|
|
178
|
+
this.emit(constants.CONNECTOR_EVENTS.READY, index$1.WALLET_CONNECTORS.AUTH);
|
|
153
179
|
try {
|
|
154
180
|
const {
|
|
155
181
|
sessionId
|
|
@@ -165,17 +191,18 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
165
191
|
// if here, this means that the connector is cached but the sessionId is not available.
|
|
166
192
|
// this can happen if the sessionId has expired.
|
|
167
193
|
// we are throwing an error to reset the cached state.
|
|
168
|
-
throw index
|
|
194
|
+
throw index.WalletLoginError.connectionError("Failed to rehydrate");
|
|
169
195
|
}
|
|
170
196
|
} catch (error) {
|
|
171
197
|
this.emit(constants.CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
172
198
|
}
|
|
173
199
|
}
|
|
174
200
|
async connect(params) {
|
|
201
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
175
202
|
super.checkConnectionRequirements();
|
|
176
203
|
this.status = constants.CONNECTOR_STATUS.CONNECTING;
|
|
177
204
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTING, _objectSpread(_objectSpread({}, params), {}, {
|
|
178
|
-
connector: index.WALLET_CONNECTORS.AUTH
|
|
205
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
179
206
|
}));
|
|
180
207
|
try {
|
|
181
208
|
await this.connectWithProvider(params);
|
|
@@ -191,50 +218,52 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
191
218
|
this.status = constants.CONNECTOR_STATUS.READY;
|
|
192
219
|
this.emit(constants.CONNECTOR_EVENTS.ERRORED, error);
|
|
193
220
|
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
|
|
221
|
+
throw index.WalletLoginError.popupClosed();
|
|
222
|
+
} else if (error instanceof index.Web3AuthError) {
|
|
196
223
|
throw error;
|
|
197
224
|
}
|
|
198
|
-
throw index
|
|
225
|
+
throw index.WalletLoginError.connectionError("Failed to login with auth", error);
|
|
199
226
|
}
|
|
200
227
|
}
|
|
201
228
|
async enableMFA(params = {
|
|
202
229
|
authConnection: ""
|
|
203
230
|
}) {
|
|
204
|
-
|
|
205
|
-
if (!this.
|
|
231
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
232
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
233
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
206
234
|
try {
|
|
207
235
|
const result = await this.authInstance.enableMFA(params);
|
|
208
236
|
// In redirect mode, the result is not available immediately, so we emit the event when the result is available.
|
|
209
237
|
if (result) this.emit(constants.CONNECTOR_EVENTS.MFA_ENABLED, result);
|
|
210
238
|
} catch (error) {
|
|
211
239
|
loglevel.log.error("Failed to enable MFA with auth provider", error);
|
|
212
|
-
if (error instanceof index
|
|
240
|
+
if (error instanceof index.Web3AuthError) {
|
|
213
241
|
throw error;
|
|
214
242
|
}
|
|
215
|
-
throw index
|
|
243
|
+
throw index.WalletLoginError.connectionError("Failed to enable MFA with auth", error);
|
|
216
244
|
}
|
|
217
245
|
}
|
|
218
246
|
async manageMFA(params = {
|
|
219
247
|
authConnection: ""
|
|
220
248
|
}) {
|
|
221
|
-
|
|
222
|
-
if (!this.
|
|
249
|
+
assertAuthConnectionSupported(params === null || params === void 0 ? void 0 : params.authConnection);
|
|
250
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
251
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
223
252
|
try {
|
|
224
253
|
await this.authInstance.manageMFA(params);
|
|
225
254
|
} catch (error) {
|
|
226
255
|
loglevel.log.error("Failed to manage MFA with auth provider", error);
|
|
227
|
-
if (error instanceof index
|
|
256
|
+
if (error instanceof index.Web3AuthError) {
|
|
228
257
|
throw error;
|
|
229
258
|
}
|
|
230
|
-
throw index
|
|
259
|
+
throw index.WalletLoginError.connectionError("Failed to manage MFA with auth", error);
|
|
231
260
|
}
|
|
232
261
|
}
|
|
233
262
|
async disconnect(options = {
|
|
234
263
|
cleanup: false
|
|
235
264
|
}) {
|
|
236
|
-
if (!this.connected) throw index
|
|
237
|
-
if (!this.authInstance) throw index
|
|
265
|
+
if (!this.connected) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
266
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
238
267
|
this.status = constants.CONNECTOR_STATUS.DISCONNECTING;
|
|
239
268
|
await this.authInstance.logout();
|
|
240
269
|
if (this.wsEmbedInstance) await this.wsEmbedInstance.logout();
|
|
@@ -249,19 +278,22 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
249
278
|
}
|
|
250
279
|
this.rehydrated = false;
|
|
251
280
|
this._solanaWallet = null;
|
|
252
|
-
this.
|
|
281
|
+
this.unbindWsEmbedProviderEvents();
|
|
282
|
+
this.emit(constants.CONNECTOR_EVENTS.DISCONNECTED, {
|
|
283
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
284
|
+
});
|
|
253
285
|
}
|
|
254
286
|
async getAuthTokenInfo() {
|
|
255
|
-
if (!this.canAuthorize) throw index
|
|
287
|
+
if (!this.canAuthorize) throw index.WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
256
288
|
this.status = constants.CONNECTOR_STATUS.AUTHORIZING;
|
|
257
289
|
this.emit(constants.CONNECTOR_EVENTS.AUTHORIZING, {
|
|
258
|
-
connector: index.WALLET_CONNECTORS.AUTH
|
|
290
|
+
connector: index$1.WALLET_CONNECTORS.AUTH
|
|
259
291
|
});
|
|
260
292
|
const userInfo = await this.getUserInfo();
|
|
261
293
|
this.status = constants.CONNECTOR_STATUS.AUTHORIZED;
|
|
262
294
|
const [accessToken, refreshToken] = await Promise.all([this.authInstance.authSessionManager.getAccessToken(), this.authInstance.authSessionManager.getRefreshToken()]);
|
|
263
295
|
this.emit(constants.CONNECTOR_EVENTS.AUTHORIZED, {
|
|
264
|
-
connector: index.WALLET_CONNECTORS.AUTH,
|
|
296
|
+
connector: index$1.WALLET_CONNECTORS.AUTH,
|
|
265
297
|
authTokenInfo: {
|
|
266
298
|
idToken: userInfo.idToken,
|
|
267
299
|
accessToken,
|
|
@@ -275,10 +307,26 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
275
307
|
};
|
|
276
308
|
}
|
|
277
309
|
async getUserInfo() {
|
|
278
|
-
if (!this.canAuthorize) throw index
|
|
279
|
-
if (!this.authInstance) throw index
|
|
280
|
-
const userInfo = this.authInstance.getUserInfo();
|
|
281
|
-
return userInfo
|
|
310
|
+
if (!this.canAuthorize) throw index.WalletLoginError.notConnectedError("Not connected with wallet");
|
|
311
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
312
|
+
const [userInfo, linkedAccounts] = await Promise.all([this.authInstance.getUserInfo(), this.getLinkedAccounts()]);
|
|
313
|
+
return _objectSpread(_objectSpread({}, userInfo), {}, {
|
|
314
|
+
linkedAccounts
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async getLinkedAccounts() {
|
|
318
|
+
const accessToken = await this.authInstance.authSessionManager.getAccessToken();
|
|
319
|
+
if (!accessToken) throw index.WalletLoginError.connectionError("Could not obtain an access token from the current AUTH session.");
|
|
320
|
+
const citadelUserInfo = await httpHelpers.get(`${utils.citadelServerUrl(this.coreOptions.authBuildEnv)}/v1/user`, {
|
|
321
|
+
headers: {
|
|
322
|
+
Authorization: `Bearer ${accessToken}`
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
const linkedAccounts = (citadelUserInfo === null || citadelUserInfo === void 0 ? void 0 : citadelUserInfo.accounts) || [];
|
|
326
|
+
return linkedAccounts.map(account => _objectSpread(_objectSpread({}, account), {}, {
|
|
327
|
+
// by default, the primary account is the active account
|
|
328
|
+
active: account.isPrimary
|
|
329
|
+
}));
|
|
282
330
|
}
|
|
283
331
|
async switchChain(params, init = false) {
|
|
284
332
|
super.checkSwitchChainRequirements(params, init);
|
|
@@ -290,15 +338,17 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
290
338
|
} = this.provider;
|
|
291
339
|
if (currentChainId === newChainId) return;
|
|
292
340
|
const newChainConfig = this.coreOptions.chains.find(c => c.chainId === newChainId);
|
|
293
|
-
if (!newChainConfig) throw index
|
|
341
|
+
if (!newChainConfig) throw index.WalletInitializationError.invalidParams("Chain config is not available");
|
|
294
342
|
if (newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA || newChainConfig.chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
295
|
-
var _this$
|
|
296
|
-
if (!((_this$
|
|
297
|
-
const
|
|
343
|
+
var _this$wsEmbedInstance;
|
|
344
|
+
if (!((_this$wsEmbedInstance = this.wsEmbedInstance) !== null && _this$wsEmbedInstance !== void 0 && _this$wsEmbedInstance.provider)) throw index.WalletInitializationError.notReady("Wallet embed is not ready");
|
|
345
|
+
const chainIdNum = parseInt(newChainConfig.chainId, 16);
|
|
346
|
+
// WsEmbed expects the chainId in hex format
|
|
347
|
+
const chainIdHex = viem.numberToHex(chainIdNum);
|
|
298
348
|
await this.wsEmbedInstance.provider.request({
|
|
299
349
|
method: "wallet_switchChain",
|
|
300
350
|
params: {
|
|
301
|
-
chainId:
|
|
351
|
+
chainId: chainIdHex
|
|
302
352
|
}
|
|
303
353
|
});
|
|
304
354
|
} else {
|
|
@@ -307,11 +357,13 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
307
357
|
}
|
|
308
358
|
}
|
|
309
359
|
async cleanup() {
|
|
310
|
-
if (!this.authInstance) throw index
|
|
360
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
311
361
|
await this.authInstance.cleanup();
|
|
312
362
|
if (this.wsEmbedInstance) {
|
|
313
363
|
this.wsEmbedInstance.clearInit();
|
|
314
364
|
}
|
|
365
|
+
this._solanaWallet = null;
|
|
366
|
+
this.unbindWsEmbedProviderEvents();
|
|
315
367
|
}
|
|
316
368
|
getOAuthProviderConfig(params) {
|
|
317
369
|
const {
|
|
@@ -331,9 +383,377 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
331
383
|
});
|
|
332
384
|
return providerConfig;
|
|
333
385
|
}
|
|
386
|
+
async generateChallengeAndSign() {
|
|
387
|
+
// we do not support this for auth connector, as of now. since auth login returns a valid idToken
|
|
388
|
+
throw new Error("Not implemented");
|
|
389
|
+
}
|
|
390
|
+
async switchAccount(account, context) {
|
|
391
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
392
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before switching accounts.");
|
|
393
|
+
}
|
|
394
|
+
try {
|
|
395
|
+
var _userInfo$linkedAccou;
|
|
396
|
+
const userInfo = await this.getUserInfo();
|
|
397
|
+
const linkedAccounts = (_userInfo$linkedAccou = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou !== void 0 ? _userInfo$linkedAccou : [];
|
|
398
|
+
const targetAccount = linkedAccounts.find(candidate => candidate.id === account.id);
|
|
399
|
+
if (!targetAccount) {
|
|
400
|
+
throw index.AccountLinkingError.requestFailed(`No connected wallet matches account id "${account.id}". Refresh user info and try again.`);
|
|
401
|
+
}
|
|
402
|
+
const currentActiveAccount = context.activeAccount;
|
|
403
|
+
const isTargetAlreadyActive = currentActiveAccount ? currentActiveAccount.id === targetAccount.id : targetAccount.isPrimary;
|
|
404
|
+
if (isTargetAlreadyActive) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_STARTED, this.getSwitchAccountTrackData(targetAccount));
|
|
408
|
+
if (targetAccount.connector === index$1.WALLET_CONNECTORS.AUTH && targetAccount.isPrimary) {
|
|
409
|
+
var _this$provider$chainI, _this$provider;
|
|
410
|
+
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);
|
|
411
|
+
const ethereumProvider = this.provider;
|
|
412
|
+
const solanaWallet = this.solanaWallet;
|
|
413
|
+
if (!ethereumProvider && !solanaWallet) {
|
|
414
|
+
throw index.AccountLinkingError.requestFailed("Failed to restore the primary AUTH session for account switch.");
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
kind: "primary",
|
|
418
|
+
targetAccount,
|
|
419
|
+
activeAccount: null,
|
|
420
|
+
activeChainId,
|
|
421
|
+
connectorName: this.name,
|
|
422
|
+
connectorNamespace: this.connectorNamespace,
|
|
423
|
+
ethereumProvider,
|
|
424
|
+
solanaWallet
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
kind: "external",
|
|
429
|
+
targetAccount,
|
|
430
|
+
activeAccount: targetAccount,
|
|
431
|
+
activeChainId: this.getChainIdForLinkedAccount(targetAccount, context.currentChainId)
|
|
432
|
+
};
|
|
433
|
+
} catch (error) {
|
|
434
|
+
await this.trackSwitchAccountFailed(account, error);
|
|
435
|
+
throw error;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
async trackSwitchAccountCompleted(account) {
|
|
439
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_COMPLETED, _objectSpread(_objectSpread({}, this.getSwitchAccountTrackData(account)), {}, {
|
|
440
|
+
connector: account.connector
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
async trackSwitchAccountFailed(account, error) {
|
|
444
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_SWITCH_FAILED, _objectSpread(_objectSpread({}, this.getSwitchAccountTrackData(account)), utils.getErrorAnalyticsProperties(error)));
|
|
445
|
+
}
|
|
446
|
+
async linkAccount(params) {
|
|
447
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
448
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before linking an account.");
|
|
449
|
+
}
|
|
450
|
+
const {
|
|
451
|
+
connectorName,
|
|
452
|
+
chainId,
|
|
453
|
+
connectorToLink
|
|
454
|
+
} = params;
|
|
455
|
+
try {
|
|
456
|
+
if (!connectorToLink.connected) {
|
|
457
|
+
const connection = await connectorToLink.connect({
|
|
458
|
+
chainId,
|
|
459
|
+
isAccountLinking: true
|
|
460
|
+
});
|
|
461
|
+
if (!connection) {
|
|
462
|
+
throw index.AccountLinkingError.walletProofFailed(`Failed to connect to "${params.connectorName}" for account linking.`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
} catch (error) {
|
|
466
|
+
if (error instanceof index.AccountLinkingError) {
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
throw index.AccountLinkingError.walletProofFailed(error instanceof Error ? error.message : String(error), error);
|
|
470
|
+
}
|
|
471
|
+
const trackData = {
|
|
472
|
+
connector: this.name,
|
|
473
|
+
linking_connector: connectorName,
|
|
474
|
+
chain_id: params.chainId
|
|
475
|
+
};
|
|
476
|
+
try {
|
|
477
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_STARTED, trackData);
|
|
478
|
+
const {
|
|
479
|
+
accessToken,
|
|
480
|
+
idToken
|
|
481
|
+
} = await this.getPrimaryAuthSession(params.authSessionTokens);
|
|
482
|
+
const walletProof = await this.createWalletLinkingProof(params.connectorToLink);
|
|
483
|
+
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
484
|
+
const result = await rest.makeAccountLinkingRequest(authServerUrl, accessToken, {
|
|
485
|
+
idToken,
|
|
486
|
+
network: walletProof.network,
|
|
487
|
+
connector: params.connectorName,
|
|
488
|
+
message: walletProof.challenge,
|
|
489
|
+
signature: {
|
|
490
|
+
s: walletProof.signature,
|
|
491
|
+
t: walletProof.signatureType
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
|
|
495
|
+
linked_address: walletProof.address
|
|
496
|
+
}));
|
|
497
|
+
return result;
|
|
498
|
+
} catch (error) {
|
|
499
|
+
this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_LINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
500
|
+
// disconnect the wallet connector to avoid any leftover state
|
|
501
|
+
try {
|
|
502
|
+
if (connectorToLink.connected) {
|
|
503
|
+
await connectorToLink.disconnect({
|
|
504
|
+
cleanup: true
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
} catch (disconnectError) {
|
|
508
|
+
loglevel.log.debug("Failed to disconnect wallet connector after linking failure", disconnectError);
|
|
509
|
+
}
|
|
510
|
+
throw error;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async unlinkAccount(params) {
|
|
514
|
+
if (!connectorStatus.CONNECTED_STATUSES.includes(this.status)) {
|
|
515
|
+
throw index.WalletLoginError.notConnectedError("No wallet is connected. Connect with AUTH before unlinking an account.");
|
|
516
|
+
}
|
|
517
|
+
const {
|
|
518
|
+
address,
|
|
519
|
+
authSessionTokens
|
|
520
|
+
} = params;
|
|
521
|
+
const trackData = {
|
|
522
|
+
connector: this.name,
|
|
523
|
+
address
|
|
524
|
+
};
|
|
525
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_STARTED, trackData);
|
|
526
|
+
try {
|
|
527
|
+
const {
|
|
528
|
+
accessToken,
|
|
529
|
+
idToken,
|
|
530
|
+
linkedAccounts
|
|
531
|
+
} = await this.getPrimaryAuthSession(authSessionTokens, {
|
|
532
|
+
includeLinkedAccounts: true
|
|
533
|
+
});
|
|
534
|
+
const network = this.getNetworkForUnlinkAddress(linkedAccounts, address);
|
|
535
|
+
const authServerUrl = utils.citadelServerUrl(this.coreOptions.authBuildEnv);
|
|
536
|
+
const result = await rest.makeAccountUnlinkingRequest(authServerUrl, accessToken, {
|
|
537
|
+
idToken,
|
|
538
|
+
address,
|
|
539
|
+
network
|
|
540
|
+
});
|
|
541
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_COMPLETED, _objectSpread(_objectSpread({}, trackData), {}, {
|
|
542
|
+
linked_address: address
|
|
543
|
+
}));
|
|
544
|
+
return result;
|
|
545
|
+
} catch (error) {
|
|
546
|
+
await this.analytics.track(analytics.ANALYTICS_EVENTS.ACCOUNT_UNLINKING_FAILED, _objectSpread(_objectSpread({}, trackData), utils.getErrorAnalyticsProperties(error)));
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
getChainIdForLinkedAccount(account, preferredChainId) {
|
|
551
|
+
const accountChainNamespace = account.chainNamespace ? utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace) : null;
|
|
552
|
+
if (preferredChainId) {
|
|
553
|
+
const preferredChain = this.coreOptions.chains.find(chain => chain.chainId === preferredChainId);
|
|
554
|
+
if (preferredChain && (!accountChainNamespace || preferredChain.chainNamespace === accountChainNamespace)) {
|
|
555
|
+
return preferredChainId;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (accountChainNamespace) {
|
|
559
|
+
const namespaceChain = this.coreOptions.chains.find(chain => chain.chainNamespace === accountChainNamespace);
|
|
560
|
+
if (namespaceChain) {
|
|
561
|
+
return namespaceChain.chainId;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
throw index.WalletInitializationError.invalidParams(`No compatible chainId found for connector "${account.connector}".`);
|
|
565
|
+
}
|
|
566
|
+
async assertSwitchAccountConnectorMatchesTarget(connector, account) {
|
|
567
|
+
if (!account.chainNamespace) {
|
|
568
|
+
throw index.AccountLinkingError.requestFailed(`Could not determine the chain namespace for linked account "${account.eoaAddress}".`);
|
|
569
|
+
}
|
|
570
|
+
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace);
|
|
571
|
+
let connectedAddress = null;
|
|
572
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
573
|
+
var _accounts$;
|
|
574
|
+
const accounts = connector.provider ? await connector.provider.request({
|
|
575
|
+
method: "eth_accounts"
|
|
576
|
+
}) : [];
|
|
577
|
+
connectedAddress = (_accounts$ = accounts === null || accounts === void 0 ? void 0 : accounts[0]) !== null && _accounts$ !== void 0 ? _accounts$ : null;
|
|
578
|
+
} else if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
579
|
+
var _connector$solanaWall, _connector$solanaWall2;
|
|
580
|
+
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
|
+
} else {
|
|
582
|
+
throw index.AccountLinkingError.requestFailed(`Unsupported chain namespace "${account.chainNamespace}" for linked account "${account.eoaAddress}".`);
|
|
583
|
+
}
|
|
584
|
+
if (!connectedAddress) {
|
|
585
|
+
throw index.AccountLinkingError.requestFailed(`Connector "${account.connector}" is not connected to linked account "${account.eoaAddress}". Connect the intended wallet account and try again.`);
|
|
586
|
+
}
|
|
587
|
+
const isExpectedAddress = chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 ? connectedAddress.toLowerCase() === account.eoaAddress.toLowerCase() : connectedAddress === account.eoaAddress;
|
|
588
|
+
if (!isExpectedAddress) {
|
|
589
|
+
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.`);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
toSwitchAccountConnectorError(account, error) {
|
|
593
|
+
if (error instanceof index.AccountLinkingError && error.code === 5401) {
|
|
594
|
+
return error;
|
|
595
|
+
}
|
|
596
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
597
|
+
const isUnavailableConnectorError = error instanceof index.AccountLinkingError && error.code === 5405 || /not available|not initialized|not ready/i.test(message);
|
|
598
|
+
if (isUnavailableConnectorError) {
|
|
599
|
+
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);
|
|
600
|
+
}
|
|
601
|
+
return index.AccountLinkingError.requestFailed(`Failed to connect connector "${account.connector}" for linked account "${account.eoaAddress}". ${message}`, error);
|
|
602
|
+
}
|
|
603
|
+
getSwitchAccountTrackData(account) {
|
|
604
|
+
var _account$eoaAddress;
|
|
605
|
+
return {
|
|
606
|
+
connector: this.name,
|
|
607
|
+
account_id: account.id,
|
|
608
|
+
account_type: account.accountType,
|
|
609
|
+
switched_to_address: (_account$eoaAddress = account.eoaAddress) !== null && _account$eoaAddress !== void 0 ? _account$eoaAddress : null
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
async getPrimaryAuthSession(authSessionTokens, options = {}) {
|
|
613
|
+
const {
|
|
614
|
+
accessToken: cachedAccessToken,
|
|
615
|
+
idToken: cachedIdToken
|
|
616
|
+
} = authSessionTokens;
|
|
617
|
+
const {
|
|
618
|
+
includeLinkedAccounts = false
|
|
619
|
+
} = options;
|
|
620
|
+
let accessToken = cachedAccessToken;
|
|
621
|
+
let idToken = cachedIdToken;
|
|
622
|
+
let linkedAccounts = [];
|
|
623
|
+
if (includeLinkedAccounts) {
|
|
624
|
+
const userInfoPromise = this.getUserInfo();
|
|
625
|
+
if (!accessToken || !idToken) {
|
|
626
|
+
var _userInfo$linkedAccou2;
|
|
627
|
+
const [tokenInfo, userInfo] = await Promise.all([this.getAuthTokenInfo(), userInfoPromise]);
|
|
628
|
+
accessToken = tokenInfo.accessToken;
|
|
629
|
+
idToken = tokenInfo.idToken;
|
|
630
|
+
linkedAccounts = (_userInfo$linkedAccou2 = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou2 !== void 0 ? _userInfo$linkedAccou2 : [];
|
|
631
|
+
} else {
|
|
632
|
+
var _userInfo$linkedAccou3;
|
|
633
|
+
const userInfo = await userInfoPromise;
|
|
634
|
+
linkedAccounts = (_userInfo$linkedAccou3 = userInfo.linkedAccounts) !== null && _userInfo$linkedAccou3 !== void 0 ? _userInfo$linkedAccou3 : [];
|
|
635
|
+
}
|
|
636
|
+
} else if (!accessToken || !idToken) {
|
|
637
|
+
const tokenInfo = await this.getAuthTokenInfo();
|
|
638
|
+
accessToken = tokenInfo.accessToken;
|
|
639
|
+
idToken = tokenInfo.idToken;
|
|
640
|
+
}
|
|
641
|
+
if (!accessToken || !idToken) {
|
|
642
|
+
throw index.AccountLinkingError.primaryTokenNotAvailable("Could not obtain an identity token from the current AUTH session.");
|
|
643
|
+
}
|
|
644
|
+
return {
|
|
645
|
+
accessToken,
|
|
646
|
+
idToken,
|
|
647
|
+
linkedAccounts
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
getNetworkForUnlinkAddress(accounts, address) {
|
|
651
|
+
const matchedAccount = accounts.find(account => {
|
|
652
|
+
var _account$address, _account$eoaAddress2;
|
|
653
|
+
if (!account.chainNamespace || utils.parseChainNamespaceFromCitadelResponse(account.chainNamespace) !== baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
const normalizedAddress = address.toLowerCase();
|
|
657
|
+
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
|
+
});
|
|
659
|
+
if (!matchedAccount) {
|
|
660
|
+
throw index.AccountLinkingError.requestFailed(`No connected wallet matches address "${address}".`);
|
|
661
|
+
}
|
|
662
|
+
if (!matchedAccount.chainNamespace) {
|
|
663
|
+
throw index.AccountLinkingError.requestFailed(`Could not determine the chain namespace for address "${address}".`);
|
|
664
|
+
}
|
|
665
|
+
const chainNamespace = utils.parseChainNamespaceFromCitadelResponse(matchedAccount.chainNamespace);
|
|
666
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
667
|
+
return "ethereum";
|
|
668
|
+
}
|
|
669
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
670
|
+
return "solana";
|
|
671
|
+
}
|
|
672
|
+
throw index.AccountLinkingError.requestFailed(`Unsupported chain namespace "${matchedAccount.chainNamespace}" for address "${address}".`);
|
|
673
|
+
}
|
|
674
|
+
async createWalletLinkingProof(connector) {
|
|
675
|
+
// Notify listeners that the linking wallet is about to be asked for a signature so the UI
|
|
676
|
+
// (e.g. modal) can switch from a "connecting" loader to an "authorizing" prompt while the
|
|
677
|
+
// user reviews the signature request inside their wallet. Emitted on the isolated wallet
|
|
678
|
+
// connector (not the auth connector) so it doesn't mutate the global SDK status.
|
|
679
|
+
connector.emit(constants.CONNECTOR_EVENTS.AUTHORIZING, {
|
|
680
|
+
connector: connector.name
|
|
681
|
+
});
|
|
682
|
+
const {
|
|
683
|
+
challenge,
|
|
684
|
+
signature,
|
|
685
|
+
chainNamespace
|
|
686
|
+
} = await connector.generateChallengeAndSign();
|
|
687
|
+
const address = await this.getLinkingWalletAddress(connector, chainNamespace);
|
|
688
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155) {
|
|
689
|
+
return {
|
|
690
|
+
address,
|
|
691
|
+
challenge,
|
|
692
|
+
signature,
|
|
693
|
+
signatureType: "eip191",
|
|
694
|
+
network: "ethereum"
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
698
|
+
return {
|
|
699
|
+
address,
|
|
700
|
+
challenge,
|
|
701
|
+
signature,
|
|
702
|
+
signatureType: "sip99",
|
|
703
|
+
network: "solana"
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
throw index.AccountLinkingError.unsupportedConnector(`Connector "${connector.name}" returned unsupported chain namespace "${chainNamespace}".`);
|
|
707
|
+
}
|
|
708
|
+
async getLinkingWalletAddress(connector, chainNamespace) {
|
|
709
|
+
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
710
|
+
var _connector$solanaWall3;
|
|
711
|
+
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
|
+
if (!address) {
|
|
713
|
+
throw index.AccountLinkingError.walletProofFailed("No connected Solana account found for account linking.");
|
|
714
|
+
}
|
|
715
|
+
return address;
|
|
716
|
+
}
|
|
717
|
+
if (!connector.provider) {
|
|
718
|
+
throw index.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
719
|
+
}
|
|
720
|
+
const accounts = await connector.provider.request({
|
|
721
|
+
method: "eth_accounts"
|
|
722
|
+
});
|
|
723
|
+
if (!(accounts !== null && accounts !== void 0 && accounts.length)) {
|
|
724
|
+
throw index.AccountLinkingError.walletProofFailed("No connected EVM account found for account linking.");
|
|
725
|
+
}
|
|
726
|
+
return accounts[0];
|
|
727
|
+
}
|
|
728
|
+
getWsEmbedProvider() {
|
|
729
|
+
var _this$wsEmbedInstance2, _this$wsEmbedInstance3;
|
|
730
|
+
return (_this$wsEmbedInstance2 = (_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 ? void 0 : _this$wsEmbedInstance3.provider) !== null && _this$wsEmbedInstance2 !== void 0 ? _this$wsEmbedInstance2 : null;
|
|
731
|
+
}
|
|
732
|
+
bindWsEmbedProviderEvents() {
|
|
733
|
+
const rawProvider = this.getWsEmbedProvider();
|
|
734
|
+
if (this.wsEmbedProviderListenerTarget === rawProvider) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
this.unbindWsEmbedProviderEvents();
|
|
738
|
+
if (!rawProvider) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
rawProvider.on("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
742
|
+
this.wsEmbedProviderListenerTarget = rawProvider;
|
|
743
|
+
}
|
|
744
|
+
unbindWsEmbedProviderEvents() {
|
|
745
|
+
if (!this.wsEmbedProviderListenerTarget) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
this.wsEmbedProviderListenerTarget.removeListener("accountsChanged", this.handleWsEmbedAccountsChanged);
|
|
749
|
+
this.wsEmbedProviderListenerTarget = null;
|
|
750
|
+
}
|
|
334
751
|
setupSolanaWallet() {
|
|
335
752
|
const solanaChains = this.coreOptions.chains.filter(c => c.chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA);
|
|
336
753
|
if (solanaChains.length === 0 || !this.provider) return;
|
|
754
|
+
if (this._solanaWallet instanceof authSolanaWallet.AuthSolanaWallet) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
337
757
|
this._solanaWallet = new authSolanaWallet.AuthSolanaWallet(this.provider, solanaChains);
|
|
338
758
|
}
|
|
339
759
|
_getFinalPrivKey() {
|
|
@@ -345,7 +765,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
345
765
|
// when useSFAKey is set to true.
|
|
346
766
|
// This is to ensure that when there is no user session active, we don't throw an exception.
|
|
347
767
|
if (this.authInstance.privKey && !this.authInstance.coreKitKey) {
|
|
348
|
-
throw index
|
|
768
|
+
throw index.WalletLoginError.sfaKeyNotFound();
|
|
349
769
|
}
|
|
350
770
|
finalPrivKey = this.authInstance.coreKitKey;
|
|
351
771
|
}
|
|
@@ -353,9 +773,9 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
353
773
|
}
|
|
354
774
|
async connectWithProvider(params) {
|
|
355
775
|
var _this$authInstance, _params$extraLoginOpt, _this$authInstance2, _this$authInstance3;
|
|
356
|
-
if (!this.authInstance) throw index
|
|
776
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
357
777
|
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
|
|
358
|
-
if (!chainConfig) throw index
|
|
778
|
+
if (!chainConfig) throw index.WalletLoginError.connectionError("Chain config is not available");
|
|
359
779
|
const {
|
|
360
780
|
chainNamespace
|
|
361
781
|
} = chainConfig;
|
|
@@ -381,7 +801,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
381
801
|
if (this.authInstance.sessionId) {
|
|
382
802
|
await this.authInstance.logout();
|
|
383
803
|
}
|
|
384
|
-
throw index
|
|
804
|
+
throw index.WalletLoginError.sfaKeyNotFound("This typically occurs when the authentication method used does not provide SFA keys (e.g., default auth connection).");
|
|
385
805
|
}
|
|
386
806
|
// setup WS embed if chainNamespace is EIP155 or SOLANA
|
|
387
807
|
if (chainNamespace === baseControllers.CHAIN_NAMESPACES.EIP155 || chainNamespace === baseControllers.CHAIN_NAMESPACES.SOLANA) {
|
|
@@ -393,19 +813,19 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
393
813
|
} = this.authInstance || {};
|
|
394
814
|
if (sessionId) {
|
|
395
815
|
this.wsEmbedInstance.setAccessTokenProvider(this.accessTokenProvider.bind(this));
|
|
816
|
+
this.bindWsEmbedProviderEvents();
|
|
396
817
|
const isLoggedIn = await this.wsEmbedInstance.connectWithSession({
|
|
397
818
|
sessionId,
|
|
398
819
|
sessionNamespace,
|
|
399
820
|
idToken: await this.getIdToken()
|
|
400
821
|
});
|
|
401
822
|
if (isLoggedIn) {
|
|
402
|
-
var _this$wsEmbedInstance3;
|
|
403
823
|
this.setupSolanaWallet();
|
|
404
824
|
// if getAuthTokenInfo is true, then get auth token info
|
|
405
825
|
// No need to get auth token info for auth connector as it is already handled
|
|
406
826
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
407
827
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
408
|
-
connectorName: index.WALLET_CONNECTORS.AUTH,
|
|
828
|
+
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
409
829
|
reconnected: this.rehydrated,
|
|
410
830
|
ethereumProvider: this.provider,
|
|
411
831
|
solanaWallet: this._solanaWallet
|
|
@@ -413,12 +833,6 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
413
833
|
if (params.getAuthTokenInfo) {
|
|
414
834
|
await this.getAuthTokenInfo();
|
|
415
835
|
}
|
|
416
|
-
// handle disconnect from ws embed
|
|
417
|
-
(_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 || _this$wsEmbedInstance3.provider.on("accountsChanged", (accounts = []) => {
|
|
418
|
-
if (accounts.length === 0 && connectorStatus.CONNECTED_STATUSES.includes(this.status)) this.disconnect({
|
|
419
|
-
cleanup: false
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
836
|
}
|
|
423
837
|
}
|
|
424
838
|
} else {
|
|
@@ -428,7 +842,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
428
842
|
await this.privateKeyProvider.setupProvider(finalPrivKey, params.chainId);
|
|
429
843
|
this.status = constants.CONNECTOR_STATUS.CONNECTED;
|
|
430
844
|
this.emit(constants.CONNECTOR_EVENTS.CONNECTED, {
|
|
431
|
-
connectorName: index.WALLET_CONNECTORS.AUTH,
|
|
845
|
+
connectorName: index$1.WALLET_CONNECTORS.AUTH,
|
|
432
846
|
ethereumProvider: this.provider,
|
|
433
847
|
solanaWallet: this._solanaWallet,
|
|
434
848
|
reconnected: this.rehydrated
|
|
@@ -443,7 +857,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
443
857
|
authConnectionId: params.authConnectionId,
|
|
444
858
|
groupedAuthConnectionId: params.groupedAuthConnectionId
|
|
445
859
|
});
|
|
446
|
-
if (!(providerConfig !== null && providerConfig !== void 0 && providerConfig.authConnection)) throw index
|
|
860
|
+
if (!(providerConfig !== null && providerConfig !== void 0 && providerConfig.authConnection)) throw index.WalletLoginError.connectionError("Invalid auth connection.");
|
|
447
861
|
const jwtParams = _objectSpread(_objectSpread(_objectSpread({}, providerConfig.jwtParameters || {}), params.extraLoginOptions || {}), {}, {
|
|
448
862
|
login_hint: params.loginHint || ((_params$extraLoginOpt3 = params.extraLoginOptions) === null || _params$extraLoginOpt3 === void 0 ? void 0 : _params$extraLoginOpt3.login_hint)
|
|
449
863
|
});
|
|
@@ -518,25 +932,21 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
518
932
|
}).catch(error => {
|
|
519
933
|
// swallow the error, dont need to throw.
|
|
520
934
|
loglevel.log.error("Error during login with social", error);
|
|
521
|
-
this.
|
|
522
|
-
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
523
|
-
});
|
|
935
|
+
this.reportFailedOauthAudit(loginParams);
|
|
524
936
|
});
|
|
525
937
|
verifierWindow.once("close", () => {
|
|
526
938
|
if (!isClosedWindow) {
|
|
527
939
|
securePubSub$1.cleanup();
|
|
528
940
|
this.authInstance.postLoginCancelledMessage(nonce);
|
|
529
|
-
reject(index
|
|
941
|
+
reject(index.WalletLoginError.popupClosed());
|
|
530
942
|
}
|
|
531
943
|
});
|
|
532
944
|
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
|
|
533
|
-
this.
|
|
534
|
-
|
|
535
|
-
});
|
|
536
|
-
if (error instanceof index$1.Web3AuthError) {
|
|
945
|
+
this.reportFailedOauthAudit(loginParams);
|
|
946
|
+
if (error instanceof index.Web3AuthError) {
|
|
537
947
|
throw error;
|
|
538
948
|
}
|
|
539
|
-
reject(index
|
|
949
|
+
reject(index.WalletLoginError.connectionError(error instanceof Error ? error.message : error || "Failed to login with social"));
|
|
540
950
|
});
|
|
541
951
|
});
|
|
542
952
|
}
|
|
@@ -549,7 +959,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
549
959
|
return this.authInstance.getAccessToken();
|
|
550
960
|
}
|
|
551
961
|
async getIdToken() {
|
|
552
|
-
if (!this.authInstance) throw index
|
|
962
|
+
if (!this.authInstance) throw index.WalletInitializationError.notReady("authInstance is not ready");
|
|
553
963
|
return this.authInstance.authSessionManager.getIdToken();
|
|
554
964
|
}
|
|
555
965
|
getOriginData() {
|
|
@@ -582,7 +992,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
582
992
|
});
|
|
583
993
|
// throw error only when we cannot find the login config and authConnectionId is not provided in the params.
|
|
584
994
|
// 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
|
|
995
|
+
if (!(loginConfig !== null && loginConfig !== void 0 && loginConfig.authConnection) && !params.authConnectionId) throw index.WalletLoginError.connectionError("Invalid auth connection.");
|
|
586
996
|
if (!(loginConfig !== null && loginConfig !== void 0 && loginConfig.authConnection)) {
|
|
587
997
|
this.authInstance.options.authConnectionConfig.push({
|
|
588
998
|
authConnection: params.authConnection,
|
|
@@ -602,7 +1012,7 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
602
1012
|
} = utils$1.parseToken(params.extraLoginOptions.id_token);
|
|
603
1013
|
finalUserId = auth.getUserId(payload, loginParams.authConnection, finalExtraLoginOptions.userIdField, finalExtraLoginOptions.isUserIdCaseSensitive);
|
|
604
1014
|
} else {
|
|
605
|
-
throw index
|
|
1015
|
+
throw index.WalletLoginError.connectionError("Invalid login hint or id_token");
|
|
606
1016
|
}
|
|
607
1017
|
// Adds the login_hint to the extraLoginOptions.
|
|
608
1018
|
loginParams.extraLoginOptions = _objectSpread(_objectSpread({}, finalExtraLoginOptions), {}, {
|
|
@@ -646,11 +1056,17 @@ class AuthConnector extends baseConnector.BaseConnector {
|
|
|
646
1056
|
}
|
|
647
1057
|
await httpHelpers.put(auditServerUrl, auditPayload);
|
|
648
1058
|
}
|
|
1059
|
+
reportFailedOauthAudit(loginParams) {
|
|
1060
|
+
void this.auditOAuditProgress(loginParams, "failed").catch(error => {
|
|
1061
|
+
loglevel.log.error("Error reporting `oauthFailed` audit progress", error);
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
649
1064
|
}
|
|
650
1065
|
const authConnector = params => {
|
|
651
1066
|
return ({
|
|
652
1067
|
projectConfig,
|
|
653
|
-
coreOptions
|
|
1068
|
+
coreOptions,
|
|
1069
|
+
analytics
|
|
654
1070
|
}) => {
|
|
655
1071
|
var _coreOptions$uiConfig, _coreOptions$walletSe, _coreOptions$walletSe2, _coreOptions$walletSe3;
|
|
656
1072
|
// Connector settings
|
|
@@ -692,9 +1108,24 @@ const authConnector = params => {
|
|
|
692
1108
|
mfaLevel: coreOptions.mfaLevel
|
|
693
1109
|
}),
|
|
694
1110
|
coreOptions,
|
|
1111
|
+
analytics,
|
|
695
1112
|
authConnectionConfig: projectConfig.embeddedWalletAuth
|
|
696
1113
|
});
|
|
697
1114
|
};
|
|
698
1115
|
};
|
|
1116
|
+
function isAuthConnector(connector) {
|
|
1117
|
+
if (!connector || connector.name !== index$1.WALLET_CONNECTORS.AUTH) {
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
const maybeAuthConnector = connector;
|
|
1121
|
+
return typeof maybeAuthConnector.switchAccount === "function" && typeof maybeAuthConnector.linkAccount === "function" && typeof maybeAuthConnector.unlinkAccount === "function";
|
|
1122
|
+
}
|
|
1123
|
+
function assertAuthConnector(connector, errorMessage = "Account linking is only supported when connected with the AUTH connector.") {
|
|
1124
|
+
if (!isAuthConnector(connector)) {
|
|
1125
|
+
throw index.WalletLoginError.unsupportedOperation(errorMessage);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
699
1128
|
|
|
1129
|
+
exports.assertAuthConnector = assertAuthConnector;
|
|
700
1130
|
exports.authConnector = authConnector;
|
|
1131
|
+
exports.isAuthConnector = isAuthConnector;
|