@web3auth/no-modal 10.9.0 → 10.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs/base/connector/baseConnector.js +9 -5
- package/dist/lib.cjs/base/connector/connectorStatus.js +9 -0
- package/dist/lib.cjs/base/connector/constants.js +8 -1
- package/dist/lib.cjs/base/utils.js +2 -1
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +22 -10
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +20 -1
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +20 -1
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +6 -5
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +6 -5
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +7 -6
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +3 -2
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +1 -0
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/config.js +1 -0
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +26 -7
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +1 -0
- package/dist/lib.cjs/index.js +4 -0
- package/dist/lib.cjs/noModal.js +80 -19
- package/dist/lib.cjs/plugins/nft-checkout-plugin/plugin.js +3 -2
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +3 -5
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +1 -0
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +1 -0
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +1 -0
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +1 -0
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +1 -0
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +1 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +1 -0
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +1 -0
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +1 -0
- package/dist/lib.cjs/react/context/WalletServicesInnerContext.js +1 -0
- package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +20 -3
- package/dist/lib.cjs/react/hooks/useCheckout.js +1 -0
- package/dist/lib.cjs/react/hooks/useFunding.js +1 -0
- package/dist/lib.cjs/react/hooks/useIdentityToken.js +8 -3
- package/dist/lib.cjs/react/hooks/useReceive.js +1 -0
- package/dist/lib.cjs/react/hooks/useSwap.js +1 -0
- package/dist/lib.cjs/react/hooks/useWalletConnectScanner.js +1 -0
- package/dist/lib.cjs/react/hooks/useWalletUI.js +1 -0
- package/dist/lib.cjs/react/hooks/useWeb3Auth.js +2 -0
- package/dist/lib.cjs/react/hooks/useWeb3AuthInner.js +1 -0
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +1 -0
- package/dist/lib.cjs/react/wagmi/provider.js +1 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +2 -1
- package/dist/lib.cjs/types/base/connector/connectorStatus.d.ts +3 -0
- package/dist/lib.cjs/types/base/connector/constants.d.ts +8 -0
- package/dist/lib.cjs/types/base/connector/index.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +16 -4
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +7 -1
- package/dist/lib.cjs/types/base/hooks/index.d.ts +1 -0
- package/dist/lib.cjs/types/noModal.d.ts +1 -0
- package/dist/lib.cjs/types/vue/interfaces.d.ts +1 -0
- package/dist/lib.cjs/types/vue/solana/composables/useSignMessage.d.ts +1 -1
- package/dist/lib.cjs/vue/WalletServicesInnerProvider.js +2 -1
- package/dist/lib.cjs/vue/Web3AuthProvider.js +17 -2
- package/dist/lib.cjs/vue/composables/useCheckout.js +3 -1
- package/dist/lib.cjs/vue/composables/useEnableMFA.js +3 -1
- package/dist/lib.cjs/vue/composables/useFunding.js +3 -1
- package/dist/lib.cjs/vue/composables/useIdentityToken.js +12 -4
- package/dist/lib.cjs/vue/composables/useManageMFA.js +3 -1
- package/dist/lib.cjs/vue/composables/useReceive.js +3 -1
- package/dist/lib.cjs/vue/composables/useSwap.js +3 -1
- package/dist/lib.cjs/vue/composables/useSwitchChain.js +3 -1
- package/dist/lib.cjs/vue/composables/useWalletConnectScanner.js +3 -1
- package/dist/lib.cjs/vue/composables/useWalletUI.js +3 -1
- package/dist/lib.cjs/vue/composables/useWeb3Auth.js +2 -0
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +3 -1
- package/dist/lib.cjs/vue/composables/useWeb3AuthDisconnect.js +3 -1
- package/dist/lib.cjs/vue/composables/useWeb3AuthInner.js +1 -0
- package/dist/lib.cjs/vue/composables/useWeb3AuthUser.js +3 -1
- package/dist/lib.cjs/vue/solana/composables/useSignAndSendTransaction.js +15 -0
- package/dist/lib.cjs/vue/solana/composables/useSignMessage.js +15 -0
- package/dist/lib.cjs/vue/solana/composables/useSignTransaction.js +15 -0
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +1 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +1 -0
- package/dist/lib.esm/base/connector/baseConnector.js +9 -5
- package/dist/lib.esm/base/connector/connectorStatus.js +6 -0
- package/dist/lib.esm/base/connector/constants.js +8 -2
- package/dist/lib.esm/base/utils.js +1 -1
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +22 -10
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +20 -2
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +20 -2
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +5 -5
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +5 -5
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +6 -6
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +2 -2
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +25 -7
- package/dist/lib.esm/index.js +2 -1
- package/dist/lib.esm/noModal.js +81 -20
- package/dist/lib.esm/plugins/nft-checkout-plugin/plugin.js +2 -2
- package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +2 -5
- package/dist/lib.esm/react/context/Web3AuthInnerContext.js +20 -3
- package/dist/lib.esm/react/hooks/useIdentityToken.js +8 -3
- package/dist/lib.esm/react/hooks/useWeb3Auth.js +2 -0
- package/dist/lib.esm/vue/WalletServicesInnerProvider.js +1 -1
- package/dist/lib.esm/vue/Web3AuthProvider.js +16 -1
- package/dist/lib.esm/vue/composables/useCheckout.js +2 -0
- package/dist/lib.esm/vue/composables/useEnableMFA.js +2 -0
- package/dist/lib.esm/vue/composables/useFunding.js +2 -0
- package/dist/lib.esm/vue/composables/useIdentityToken.js +11 -3
- package/dist/lib.esm/vue/composables/useManageMFA.js +2 -0
- package/dist/lib.esm/vue/composables/useReceive.js +2 -0
- package/dist/lib.esm/vue/composables/useSwap.js +2 -0
- package/dist/lib.esm/vue/composables/useSwitchChain.js +2 -0
- package/dist/lib.esm/vue/composables/useWalletConnectScanner.js +2 -0
- package/dist/lib.esm/vue/composables/useWalletUI.js +2 -0
- package/dist/lib.esm/vue/composables/useWeb3Auth.js +2 -0
- package/dist/lib.esm/vue/composables/useWeb3AuthConnect.js +2 -0
- package/dist/lib.esm/vue/composables/useWeb3AuthDisconnect.js +2 -0
- package/dist/lib.esm/vue/composables/useWeb3AuthUser.js +2 -0
- package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +2 -0
- package/dist/lib.esm/vue/solana/composables/useSignMessage.js +3 -1
- package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +2 -0
- package/dist/noModal.umd.min.js +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var vue = require('vue');
|
|
4
|
+
require('@babel/runtime/helpers/objectSpread2');
|
|
5
|
+
require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('@segment/analytics-next');
|
|
7
|
+
var loglevel = require('../../../base/loglevel.js');
|
|
8
|
+
require('@toruslabs/base-controllers');
|
|
9
|
+
require('@web3auth/auth');
|
|
4
10
|
var index = require('../../../base/errors/index.js');
|
|
11
|
+
require('../../../base/wallet/index.js');
|
|
12
|
+
require('../../../base/connector/connectorStatus.js');
|
|
13
|
+
require('../../../base/connector/constants.js');
|
|
14
|
+
require('jwt-decode');
|
|
15
|
+
require('../../../base/plugin/errors.js');
|
|
16
|
+
require('../../../base/plugin/IPlugin.js');
|
|
17
|
+
require('@toruslabs/constants');
|
|
18
|
+
require('@toruslabs/http-helpers');
|
|
5
19
|
var useSolanaWallet = require('./useSolanaWallet.js');
|
|
6
20
|
|
|
7
21
|
const useSignTransaction = () => {
|
|
@@ -20,6 +34,7 @@ const useSignTransaction = () => {
|
|
|
20
34
|
data.value = signedTransaction;
|
|
21
35
|
return signedTransaction;
|
|
22
36
|
} catch (err) {
|
|
37
|
+
loglevel.log.error("Error signing transaction", err);
|
|
23
38
|
error.value = err;
|
|
24
39
|
} finally {
|
|
25
40
|
loading.value = false;
|
|
@@ -12,6 +12,7 @@ require('../../../base/loglevel.js');
|
|
|
12
12
|
require('@web3auth/auth');
|
|
13
13
|
require('../../../base/errors/index.js');
|
|
14
14
|
require('../../../base/wallet/index.js');
|
|
15
|
+
require('../../../base/connector/connectorStatus.js');
|
|
15
16
|
require('../../../base/connector/constants.js');
|
|
16
17
|
require('jwt-decode');
|
|
17
18
|
require('../../../base/plugin/errors.js');
|
|
@@ -13,6 +13,7 @@ var loglevel = require('../../base/loglevel.js');
|
|
|
13
13
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
14
14
|
var index = require('../../base/errors/index.js');
|
|
15
15
|
require('../../base/wallet/index.js');
|
|
16
|
+
require('../../base/connector/connectorStatus.js');
|
|
16
17
|
require('../../base/connector/constants.js');
|
|
17
18
|
require('jwt-decode');
|
|
18
19
|
require('../../base/plugin/errors.js');
|
|
@@ -3,6 +3,7 @@ import { SafeEventEmitter } from '@web3auth/auth';
|
|
|
3
3
|
import { CONNECTOR_NAMESPACES } from '../chain/IChainInterface.js';
|
|
4
4
|
import { WalletInitializationError, WalletLoginError } from '../errors/index.js';
|
|
5
5
|
import { WALLET_CONNECTORS } from '../wallet/index.js';
|
|
6
|
+
import { CONNECTED_STATUSES, CAN_AUTHORIZE_STATUSES } from './connectorStatus.js';
|
|
6
7
|
import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from './constants.js';
|
|
7
8
|
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
8
9
|
|
|
@@ -20,15 +21,18 @@ class BaseConnector extends SafeEventEmitter {
|
|
|
20
21
|
_defineProperty(this, "status", void 0);
|
|
21
22
|
this.coreOptions = options.coreOptions;
|
|
22
23
|
}
|
|
23
|
-
get
|
|
24
|
-
return this.status
|
|
24
|
+
get connected() {
|
|
25
|
+
return CONNECTED_STATUSES.includes(this.status);
|
|
26
|
+
}
|
|
27
|
+
get canAuthorize() {
|
|
28
|
+
return CAN_AUTHORIZE_STATUSES.includes(this.status);
|
|
25
29
|
}
|
|
26
30
|
checkConnectionRequirements() {
|
|
27
31
|
// we reconnect without killing existing Wallet Connect or Metamask Connect session on calling connect again.
|
|
28
32
|
if (this.name === WALLET_CONNECTORS.WALLET_CONNECT_V2 && this.status === CONNECTOR_STATUS.CONNECTING) return;
|
|
29
33
|
if (this.name === WALLET_CONNECTORS.METAMASK && !this.isInjected && this.status === CONNECTOR_STATUS.CONNECTING) return;
|
|
30
34
|
if (this.status === CONNECTOR_STATUS.CONNECTING) throw WalletInitializationError.notReady("Already connecting");
|
|
31
|
-
if (this.
|
|
35
|
+
if (this.connected) throw WalletLoginError.connectionError("Already connected");
|
|
32
36
|
if (this.status !== CONNECTOR_STATUS.READY) throw WalletLoginError.connectionError("Wallet connector is not ready yet, Please wait for init function to resolve before calling connect/connectTo function");
|
|
33
37
|
}
|
|
34
38
|
checkInitializationRequirements({
|
|
@@ -44,11 +48,11 @@ class BaseConnector extends SafeEventEmitter {
|
|
|
44
48
|
}
|
|
45
49
|
if (this.connectorNamespace !== CONNECTOR_NAMESPACES.MULTICHAIN && this.connectorNamespace !== chainConfig.chainNamespace) throw WalletInitializationError.invalidParams("Connector doesn't support this chain namespace");
|
|
46
50
|
if (this.status === CONNECTOR_STATUS.NOT_READY) return;
|
|
47
|
-
if (this.
|
|
51
|
+
if (this.connected) throw WalletInitializationError.notReady("Already connected");
|
|
48
52
|
if (this.status === CONNECTOR_STATUS.READY) throw WalletInitializationError.notReady("Connector is already initialized");
|
|
49
53
|
}
|
|
50
54
|
checkDisconnectionRequirements() {
|
|
51
|
-
if (this.
|
|
55
|
+
if (!this.connected) throw WalletLoginError.disconnectionError("Not connected with wallet");
|
|
52
56
|
}
|
|
53
57
|
checkSwitchChainRequirements(params, init = false) {
|
|
54
58
|
if (!init && !this.provider) throw WalletLoginError.notConnectedError("Not connected with wallet.");
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CONNECTOR_STATUS } from './constants.js';
|
|
2
|
+
|
|
3
|
+
const CONNECTED_STATUSES = [CONNECTOR_STATUS.CONNECTED, CONNECTOR_STATUS.AUTHORIZED];
|
|
4
|
+
const CAN_AUTHORIZE_STATUSES = [CONNECTOR_STATUS.AUTHORIZING, CONNECTOR_STATUS.AUTHORIZED, CONNECTOR_STATUS.CONNECTED];
|
|
5
|
+
|
|
6
|
+
export { CAN_AUTHORIZE_STATUSES, CONNECTED_STATUSES };
|
|
@@ -7,7 +7,9 @@ const CONNECTOR_STATUS = {
|
|
|
7
7
|
CONNECTED: "connected",
|
|
8
8
|
DISCONNECTING: "disconnecting",
|
|
9
9
|
DISCONNECTED: "disconnected",
|
|
10
|
-
ERRORED: "errored"
|
|
10
|
+
ERRORED: "errored",
|
|
11
|
+
AUTHORIZED: "authorized",
|
|
12
|
+
AUTHORIZING: "authorizing"
|
|
11
13
|
};
|
|
12
14
|
const CONNECTOR_EVENTS = _objectSpread(_objectSpread({}, CONNECTOR_STATUS), {}, {
|
|
13
15
|
CONNECTOR_DATA_UPDATED: "connector_data_updated",
|
|
@@ -20,5 +22,9 @@ const CONNECTOR_CATEGORY = {
|
|
|
20
22
|
EXTERNAL: "external",
|
|
21
23
|
IN_APP: "in_app"
|
|
22
24
|
};
|
|
25
|
+
const CONNECTOR_INITIAL_AUTHENTICATION_MODE = {
|
|
26
|
+
CONNECT_ONLY: "connect-only",
|
|
27
|
+
CONNECT_AND_SIGN: "connect-and-sign"
|
|
28
|
+
};
|
|
23
29
|
|
|
24
|
-
export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_STATUS };
|
|
30
|
+
export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS };
|
|
@@ -146,7 +146,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
|
146
146
|
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig10 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig10 === void 0 ? void 0 : _walletServicesConfig10.defaultPortfolio
|
|
147
147
|
};
|
|
148
148
|
};
|
|
149
|
-
const sdkVersion = "10.
|
|
149
|
+
const sdkVersion = "10.10.0";
|
|
150
150
|
const getErrorAnalyticsProperties = error => {
|
|
151
151
|
try {
|
|
152
152
|
const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
@@ -10,6 +10,7 @@ import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
|
|
|
10
10
|
import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
11
11
|
import { WalletInitializationError, WalletLoginError, Web3AuthError } from '../../base/errors/index.js';
|
|
12
12
|
import { log } from '../../base/loglevel.js';
|
|
13
|
+
import { CONNECTED_STATUSES } from '../../base/connector/connectorStatus.js';
|
|
13
14
|
import { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
|
|
14
15
|
import '@toruslabs/constants';
|
|
15
16
|
import '@toruslabs/http-helpers';
|
|
@@ -143,7 +144,7 @@ class AuthConnector extends BaseConnector {
|
|
|
143
144
|
this.rehydrated = true;
|
|
144
145
|
await this.connect({
|
|
145
146
|
chainId: options.chainId,
|
|
146
|
-
getIdentityToken:
|
|
147
|
+
getIdentityToken: options.getIdentityToken
|
|
147
148
|
});
|
|
148
149
|
} else if (!sessionId && options.autoConnect) {
|
|
149
150
|
// if here, this means that the connector is cached but the sessionId is not available.
|
|
@@ -181,7 +182,7 @@ class AuthConnector extends BaseConnector {
|
|
|
181
182
|
async enableMFA(params = {
|
|
182
183
|
authConnection: ""
|
|
183
184
|
}) {
|
|
184
|
-
if (this.
|
|
185
|
+
if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet");
|
|
185
186
|
if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
|
|
186
187
|
try {
|
|
187
188
|
const result = await this.authInstance.enableMFA(params);
|
|
@@ -198,7 +199,7 @@ class AuthConnector extends BaseConnector {
|
|
|
198
199
|
async manageMFA(params = {
|
|
199
200
|
authConnection: ""
|
|
200
201
|
}) {
|
|
201
|
-
if (this.
|
|
202
|
+
if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet");
|
|
202
203
|
if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
|
|
203
204
|
try {
|
|
204
205
|
await this.authInstance.manageMFA(params);
|
|
@@ -213,7 +214,7 @@ class AuthConnector extends BaseConnector {
|
|
|
213
214
|
async disconnect(options = {
|
|
214
215
|
cleanup: false
|
|
215
216
|
}) {
|
|
216
|
-
if (this.
|
|
217
|
+
if (!this.connected) throw WalletLoginError.notConnectedError("Not connected with wallet");
|
|
217
218
|
if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
|
|
218
219
|
this.status = CONNECTOR_STATUS.DISCONNECTING;
|
|
219
220
|
await this.authInstance.logout();
|
|
@@ -231,14 +232,25 @@ class AuthConnector extends BaseConnector {
|
|
|
231
232
|
this.emit(CONNECTOR_EVENTS.DISCONNECTED);
|
|
232
233
|
}
|
|
233
234
|
async getIdentityToken() {
|
|
234
|
-
if (this.
|
|
235
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
236
|
+
this.status = CONNECTOR_STATUS.AUTHORIZING;
|
|
237
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZING, {
|
|
238
|
+
connector: WALLET_CONNECTORS.AUTH
|
|
239
|
+
});
|
|
235
240
|
const userInfo = await this.getUserInfo();
|
|
241
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
242
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
243
|
+
connector: WALLET_CONNECTORS.AUTH,
|
|
244
|
+
identityTokenInfo: {
|
|
245
|
+
idToken: userInfo.idToken
|
|
246
|
+
}
|
|
247
|
+
});
|
|
236
248
|
return {
|
|
237
249
|
idToken: userInfo.idToken
|
|
238
250
|
};
|
|
239
251
|
}
|
|
240
252
|
async getUserInfo() {
|
|
241
|
-
if (this.
|
|
253
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet");
|
|
242
254
|
if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
|
|
243
255
|
const userInfo = this.authInstance.getUserInfo();
|
|
244
256
|
return userInfo;
|
|
@@ -368,9 +380,6 @@ class AuthConnector extends BaseConnector {
|
|
|
368
380
|
// if getIdentityToken is true, then get the identity token
|
|
369
381
|
// No need to get the identity token for auth connector as it is already handled
|
|
370
382
|
let identityTokenInfo;
|
|
371
|
-
if (params.getIdentityToken) {
|
|
372
|
-
identityTokenInfo = await this.getIdentityToken();
|
|
373
|
-
}
|
|
374
383
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
375
384
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
376
385
|
connector: WALLET_CONNECTORS.AUTH,
|
|
@@ -378,9 +387,12 @@ class AuthConnector extends BaseConnector {
|
|
|
378
387
|
provider: this.provider,
|
|
379
388
|
identityTokenInfo
|
|
380
389
|
});
|
|
390
|
+
if (params.getIdentityToken) {
|
|
391
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
392
|
+
}
|
|
381
393
|
// handle disconnect from ws embed
|
|
382
394
|
(_this$wsEmbedInstance3 = this.wsEmbedInstance) === null || _this$wsEmbedInstance3 === void 0 || _this$wsEmbedInstance3.provider.on("accountsChanged", (accounts = []) => {
|
|
383
|
-
if (accounts.length === 0 && this.status
|
|
395
|
+
if (accounts.length === 0 && CONNECTED_STATUSES.includes(this.status)) this.disconnect({
|
|
384
396
|
cleanup: false
|
|
385
397
|
});
|
|
386
398
|
});
|
|
@@ -2,14 +2,18 @@ import { signChallenge, verifySignedChallenge } from '@toruslabs/base-controller
|
|
|
2
2
|
import { EVM_METHOD_TYPES } from '@web3auth/ws-embed';
|
|
3
3
|
import { getSavedToken, checkIfTokenIsExpired, saveToken, clearToken } from '../../base/connector/utils.js';
|
|
4
4
|
import { BaseConnector } from '../../base/connector/baseConnector.js';
|
|
5
|
-
import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
6
5
|
import { WalletLoginError, WalletInitializationError } from '../../base/errors/index.js';
|
|
6
|
+
import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
7
7
|
|
|
8
8
|
class BaseEvmConnector extends BaseConnector {
|
|
9
9
|
async init(_) {}
|
|
10
10
|
async getIdentityToken() {
|
|
11
|
-
if (!this.provider || this.
|
|
11
|
+
if (!this.provider || !this.canAuthorize) throw WalletLoginError.notConnectedError();
|
|
12
12
|
if (!this.coreOptions) throw WalletInitializationError.invalidParams("Please initialize Web3Auth with valid options");
|
|
13
|
+
this.status = CONNECTOR_STATUS.AUTHORIZING;
|
|
14
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZING, {
|
|
15
|
+
connector: this.name
|
|
16
|
+
});
|
|
13
17
|
const accounts = await this.provider.request({
|
|
14
18
|
method: EVM_METHOD_TYPES.GET_ACCOUNTS
|
|
15
19
|
});
|
|
@@ -18,6 +22,13 @@ class BaseEvmConnector extends BaseConnector {
|
|
|
18
22
|
if (existingToken) {
|
|
19
23
|
const isExpired = checkIfTokenIsExpired(existingToken);
|
|
20
24
|
if (!isExpired) {
|
|
25
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
26
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
27
|
+
connector: this.name,
|
|
28
|
+
identityTokenInfo: {
|
|
29
|
+
idToken: existingToken
|
|
30
|
+
}
|
|
31
|
+
});
|
|
21
32
|
return {
|
|
22
33
|
idToken: existingToken
|
|
23
34
|
};
|
|
@@ -48,6 +59,13 @@ class BaseEvmConnector extends BaseConnector {
|
|
|
48
59
|
});
|
|
49
60
|
const idToken = await verifySignedChallenge(chainNamespace, signedMessage, challenge, this.name, this.coreOptions.sessionTime, this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
50
61
|
saveToken(accounts[0], this.name, idToken);
|
|
62
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
63
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
64
|
+
connector: this.name,
|
|
65
|
+
identityTokenInfo: {
|
|
66
|
+
idToken
|
|
67
|
+
}
|
|
68
|
+
});
|
|
51
69
|
return {
|
|
52
70
|
idToken
|
|
53
71
|
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { signChallenge, verifySignedChallenge } from '@toruslabs/base-controllers';
|
|
2
2
|
import { SOLANA_METHOD_TYPES } from '@web3auth/ws-embed';
|
|
3
3
|
import { BaseConnector } from '../../base/connector/baseConnector.js';
|
|
4
|
-
import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
5
4
|
import { WalletLoginError, WalletInitializationError } from '../../base/errors/index.js';
|
|
5
|
+
import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
6
6
|
import { getSavedToken, checkIfTokenIsExpired, saveToken, clearToken } from '../../base/connector/utils.js';
|
|
7
7
|
|
|
8
8
|
class BaseSolanaConnector extends BaseConnector {
|
|
9
9
|
async init(_) {}
|
|
10
10
|
async getIdentityToken() {
|
|
11
|
-
if (!this.provider || this.
|
|
11
|
+
if (!this.provider || !this.canAuthorize) throw WalletLoginError.notConnectedError();
|
|
12
12
|
if (!this.coreOptions) throw WalletInitializationError.invalidParams("Please initialize Web3Auth with a valid options");
|
|
13
|
+
this.status = CONNECTOR_STATUS.AUTHORIZING;
|
|
14
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZING, {
|
|
15
|
+
connector: this.name
|
|
16
|
+
});
|
|
13
17
|
const accounts = await this.provider.request({
|
|
14
18
|
method: SOLANA_METHOD_TYPES.GET_ACCOUNTS
|
|
15
19
|
});
|
|
@@ -18,6 +22,13 @@ class BaseSolanaConnector extends BaseConnector {
|
|
|
18
22
|
if (existingToken) {
|
|
19
23
|
const isExpired = checkIfTokenIsExpired(existingToken);
|
|
20
24
|
if (!isExpired) {
|
|
25
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
26
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
27
|
+
connector: this.name,
|
|
28
|
+
identityTokenInfo: {
|
|
29
|
+
idToken: existingToken
|
|
30
|
+
}
|
|
31
|
+
});
|
|
21
32
|
return {
|
|
22
33
|
idToken: existingToken
|
|
23
34
|
};
|
|
@@ -50,6 +61,13 @@ class BaseSolanaConnector extends BaseConnector {
|
|
|
50
61
|
});
|
|
51
62
|
const idToken = await verifySignedChallenge(chainNamespace, signedMessage, challenge, this.name, this.coreOptions.sessionTime, this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
52
63
|
saveToken(accounts[0], this.name, idToken);
|
|
64
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
65
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
66
|
+
connector: this.name,
|
|
67
|
+
identityTokenInfo: {
|
|
68
|
+
idToken
|
|
69
|
+
}
|
|
70
|
+
});
|
|
53
71
|
return {
|
|
54
72
|
idToken
|
|
55
73
|
};
|
|
@@ -55,7 +55,7 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
55
55
|
this.rehydrated = true;
|
|
56
56
|
const provider = await this.connect({
|
|
57
57
|
chainId: options.chainId,
|
|
58
|
-
getIdentityToken:
|
|
58
|
+
getIdentityToken: options.getIdentityToken
|
|
59
59
|
});
|
|
60
60
|
// the connect function could fail silently as well.
|
|
61
61
|
if (!provider) {
|
|
@@ -96,15 +96,15 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
96
96
|
this.disconnect();
|
|
97
97
|
});
|
|
98
98
|
let identityTokenInfo;
|
|
99
|
-
if (getIdentityToken) {
|
|
100
|
-
identityTokenInfo = await this.getIdentityToken();
|
|
101
|
-
}
|
|
102
99
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
103
100
|
connector: WALLET_CONNECTORS.COINBASE,
|
|
104
101
|
reconnected: this.rehydrated,
|
|
105
102
|
provider: this.provider,
|
|
106
103
|
identityTokenInfo
|
|
107
104
|
});
|
|
105
|
+
if (getIdentityToken) {
|
|
106
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
107
|
+
}
|
|
108
108
|
return this.provider;
|
|
109
109
|
} catch (error) {
|
|
110
110
|
// ready again to be connected
|
|
@@ -132,7 +132,7 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
132
132
|
await super.disconnect();
|
|
133
133
|
}
|
|
134
134
|
async getUserInfo() {
|
|
135
|
-
if (this.
|
|
135
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
136
136
|
return {};
|
|
137
137
|
}
|
|
138
138
|
async switchChain(params, init = false) {
|
|
@@ -44,7 +44,7 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
44
44
|
this.rehydrated = true;
|
|
45
45
|
const provider = await this.connect({
|
|
46
46
|
chainId: options.chainId,
|
|
47
|
-
getIdentityToken:
|
|
47
|
+
getIdentityToken: options.getIdentityToken
|
|
48
48
|
});
|
|
49
49
|
if (!provider) {
|
|
50
50
|
this.rehydrated = false;
|
|
@@ -90,15 +90,15 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
90
90
|
};
|
|
91
91
|
this.injectedProvider.on("accountsChanged", accountDisconnectHandler);
|
|
92
92
|
let identityTokenInfo;
|
|
93
|
-
if (getIdentityToken) {
|
|
94
|
-
identityTokenInfo = await this.getIdentityToken();
|
|
95
|
-
}
|
|
96
93
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
97
94
|
connector: this.name,
|
|
98
95
|
reconnected: this.rehydrated,
|
|
99
96
|
provider: this.injectedProvider,
|
|
100
97
|
identityTokenInfo
|
|
101
98
|
});
|
|
99
|
+
if (getIdentityToken) {
|
|
100
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
101
|
+
}
|
|
102
102
|
return this.injectedProvider;
|
|
103
103
|
} catch (error) {
|
|
104
104
|
// ready again to be connected
|
|
@@ -135,7 +135,7 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
135
135
|
await super.disconnect();
|
|
136
136
|
}
|
|
137
137
|
async getUserInfo() {
|
|
138
|
-
if (this.
|
|
138
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
139
139
|
return {};
|
|
140
140
|
}
|
|
141
141
|
async addChain(chainConfig, _init = false) {
|
|
@@ -35,7 +35,7 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
get isWalletConnected() {
|
|
38
|
-
return !!(this.
|
|
38
|
+
return !!(this.connected && this.wallet.accounts.length > 0);
|
|
39
39
|
}
|
|
40
40
|
async init(options) {
|
|
41
41
|
await super.init(options);
|
|
@@ -58,7 +58,7 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
58
58
|
this.rehydrated = true;
|
|
59
59
|
const provider = await this.connect({
|
|
60
60
|
chainId: options.chainId,
|
|
61
|
-
getIdentityToken:
|
|
61
|
+
getIdentityToken: options.getIdentityToken
|
|
62
62
|
});
|
|
63
63
|
if (!provider) {
|
|
64
64
|
this.rehydrated = false;
|
|
@@ -89,15 +89,15 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
89
89
|
if (this.wallet.accounts.length === 0) throw WalletLoginError.connectionError();
|
|
90
90
|
this.status = CONNECTOR_STATUS.CONNECTED;
|
|
91
91
|
let identityTokenInfo;
|
|
92
|
-
if (getIdentityToken) {
|
|
93
|
-
identityTokenInfo = await this.getIdentityToken();
|
|
94
|
-
}
|
|
95
92
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
96
93
|
connector: this.name,
|
|
97
94
|
reconnected: this.rehydrated,
|
|
98
95
|
provider: this.provider,
|
|
99
96
|
identityTokenInfo
|
|
100
97
|
});
|
|
98
|
+
if (getIdentityToken) {
|
|
99
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
100
|
+
}
|
|
101
101
|
return this.provider;
|
|
102
102
|
} catch (error) {
|
|
103
103
|
// ready again to be connected
|
|
@@ -126,7 +126,7 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
async getUserInfo() {
|
|
129
|
-
if (!this.
|
|
129
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
130
130
|
return {};
|
|
131
131
|
}
|
|
132
132
|
async switchChain(params, init = false) {
|
|
@@ -74,7 +74,7 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
74
74
|
this.rehydrated = true;
|
|
75
75
|
const provider = await this.connect({
|
|
76
76
|
chainId: options.chainId,
|
|
77
|
-
getIdentityToken:
|
|
77
|
+
getIdentityToken: options.getIdentityToken
|
|
78
78
|
});
|
|
79
79
|
if (!provider) {
|
|
80
80
|
this.rehydrated = false;
|
|
@@ -199,7 +199,7 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
199
199
|
await super.disconnect();
|
|
200
200
|
}
|
|
201
201
|
async getUserInfo() {
|
|
202
|
-
if (this.
|
|
202
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
203
203
|
return {};
|
|
204
204
|
}
|
|
205
205
|
async switchChain(params, init = false) {
|
|
@@ -100,7 +100,7 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
100
100
|
try {
|
|
101
101
|
await this.onConnectHandler({
|
|
102
102
|
chain: chainConfig,
|
|
103
|
-
getIdentityToken:
|
|
103
|
+
getIdentityToken: options.getIdentityToken
|
|
104
104
|
});
|
|
105
105
|
} catch (error) {
|
|
106
106
|
log.error("wallet auto connect", error);
|
|
@@ -167,7 +167,7 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
167
167
|
if (this.connected) {
|
|
168
168
|
await this.onConnectHandler({
|
|
169
169
|
chain: chainConfig,
|
|
170
|
-
getIdentityToken
|
|
170
|
+
getIdentityToken
|
|
171
171
|
});
|
|
172
172
|
return this.provider;
|
|
173
173
|
}
|
|
@@ -211,7 +211,7 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
async getUserInfo() {
|
|
214
|
-
if (!this.
|
|
214
|
+
if (!this.canAuthorize) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
215
215
|
return {};
|
|
216
216
|
}
|
|
217
217
|
async disconnect(options = {
|
|
@@ -240,7 +240,11 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
240
240
|
this.emit(CONNECTOR_EVENTS.DISCONNECTED);
|
|
241
241
|
}
|
|
242
242
|
async getIdentityToken() {
|
|
243
|
-
if (!this.provider || this.
|
|
243
|
+
if (!this.provider || !this.canAuthorize) throw WalletLoginError.notConnectedError();
|
|
244
|
+
this.status = CONNECTOR_STATUS.AUTHORIZING;
|
|
245
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZING, {
|
|
246
|
+
connector: WALLET_CONNECTORS.WALLET_CONNECT_V2
|
|
247
|
+
});
|
|
244
248
|
const {
|
|
245
249
|
chainId
|
|
246
250
|
} = this.provider;
|
|
@@ -257,6 +261,13 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
257
261
|
if (existingToken) {
|
|
258
262
|
const isExpired = checkIfTokenIsExpired(existingToken);
|
|
259
263
|
if (!isExpired) {
|
|
264
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
265
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
266
|
+
connector: WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
267
|
+
identityTokenInfo: {
|
|
268
|
+
idToken: existingToken
|
|
269
|
+
}
|
|
270
|
+
});
|
|
260
271
|
return {
|
|
261
272
|
idToken: existingToken
|
|
262
273
|
};
|
|
@@ -275,6 +286,13 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
275
286
|
const signedMessage = await this._getSignedMessage(challenge, accounts, chainNamespace);
|
|
276
287
|
const idToken = await verifySignedChallenge(chainNamespace, signedMessage, challenge, this.name, this.coreOptions.sessionTime, this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
277
288
|
saveToken(accounts[0], this.name, idToken);
|
|
289
|
+
this.status = CONNECTOR_STATUS.AUTHORIZED;
|
|
290
|
+
this.emit(CONNECTOR_EVENTS.AUTHORIZED, {
|
|
291
|
+
connector: WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
292
|
+
identityTokenInfo: {
|
|
293
|
+
idToken
|
|
294
|
+
}
|
|
295
|
+
});
|
|
278
296
|
return {
|
|
279
297
|
idToken
|
|
280
298
|
};
|
|
@@ -414,15 +432,15 @@ class WalletConnectV2Connector extends BaseConnector {
|
|
|
414
432
|
// track connection events
|
|
415
433
|
if (trackCompletionEvents) trackCompletionEvents();
|
|
416
434
|
let identityTokenInfo;
|
|
417
|
-
if (getIdentityToken) {
|
|
418
|
-
identityTokenInfo = await this.getIdentityToken();
|
|
419
|
-
}
|
|
420
435
|
this.emit(CONNECTOR_EVENTS.CONNECTED, {
|
|
421
436
|
connector: WALLET_CONNECTORS.WALLET_CONNECT_V2,
|
|
422
437
|
reconnected: this.rehydrated,
|
|
423
438
|
provider: this.provider,
|
|
424
439
|
identityTokenInfo
|
|
425
440
|
});
|
|
441
|
+
if (getIdentityToken) {
|
|
442
|
+
identityTokenInfo = await this.getIdentityToken();
|
|
443
|
+
}
|
|
426
444
|
}
|
|
427
445
|
subscribeEvents() {
|
|
428
446
|
if (!this.connector) throw WalletInitializationError.notReady("Wallet connector is not ready yet");
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -5,7 +5,8 @@ export { CONNECTOR_NAMESPACES } from './base/chain/IChainInterface.js';
|
|
|
5
5
|
export { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
|
|
6
6
|
export { Web3AuthContextKey } from './base/composables/index.js';
|
|
7
7
|
export { BaseConnector } from './base/connector/baseConnector.js';
|
|
8
|
-
export {
|
|
8
|
+
export { CAN_AUTHORIZE_STATUSES, CONNECTED_STATUSES } from './base/connector/connectorStatus.js';
|
|
9
|
+
export { CONNECTOR_CATEGORY, CONNECTOR_EVENTS, CONNECTOR_INITIAL_AUTHENTICATION_MODE, CONNECTOR_STATUS } from './base/connector/constants.js';
|
|
9
10
|
export { AUTH_CONNECTION, MFA_FACTOR, MFA_LEVELS, UX_MODE, WEB3AUTH_NETWORK, getED25519Key } from '@web3auth/auth';
|
|
10
11
|
export { checkIfTokenIsExpired, clearToken, getSavedToken, saveToken, storageAvailable } from './base/connector/utils.js';
|
|
11
12
|
export { LOGIN_MODE, MODAL_SIGN_IN_METHODS, SMART_ACCOUNT_WALLET_SCOPE, SOLANA_CAIP_CHAIN_MAP, WALLET_REGISTRY_URL, WEB3AUTH_STATE_STORAGE_KEY, WIDGET_TYPE } from './base/constants.js';
|