@web3auth/no-modal 10.0.0-beta.9 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib.cjs/base/analytics.js +121 -0
- package/dist/lib.cjs/base/connector/constants.js +2 -1
- package/dist/lib.cjs/base/constants.js +13 -0
- package/dist/lib.cjs/base/cookie.js +38 -0
- package/dist/lib.cjs/base/deserialize.js +13 -0
- package/dist/lib.cjs/base/errors/index.js +2 -2
- package/dist/lib.cjs/base/utils.js +112 -9
- package/dist/lib.cjs/base/wallet/index.js +3 -3
- package/dist/lib.cjs/connectors/auth-connector/authConnector.js +40 -63
- package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +5 -2
- package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +5 -2
- package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +11 -4
- package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +10 -4
- package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +10 -5
- package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +10 -5
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +2 -1
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/config.js +11 -9
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/index.js +0 -1
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +9 -4
- package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +6 -5
- package/dist/lib.cjs/index.js +18 -1
- package/dist/lib.cjs/noModal.js +367 -101
- package/dist/lib.cjs/plugins/nft-checkout-plugin/plugin.js +3 -1
- package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +3 -1
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +10 -5
- package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +3 -2
- package/dist/lib.cjs/providers/base-provider/baseProvider.js +2 -1
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +2 -1
- package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +2 -1
- package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +2 -1
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +4 -2
- package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +4 -2
- package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +3 -1
- package/dist/lib.cjs/react/context/WalletServicesInnerContext.js +4 -2
- package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +21 -16
- package/dist/lib.cjs/react/hooks/useCheckout.js +4 -2
- package/dist/lib.cjs/react/hooks/useIdentityToken.js +3 -3
- package/dist/lib.cjs/react/hooks/useSwap.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/react/hooks/useWalletUI.js +4 -2
- package/dist/lib.cjs/react/hooks/useWeb3AuthInner.js +4 -2
- package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +3 -2
- package/dist/lib.cjs/react/wagmi/constants.js +16 -0
- package/dist/lib.cjs/react/wagmi/provider.js +14 -9
- package/dist/lib.cjs/types/base/analytics.d.ts +42 -0
- package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +2 -2
- package/dist/lib.cjs/types/base/connector/constants.d.ts +1 -0
- package/dist/lib.cjs/types/base/connector/interfaces.d.ts +3 -2
- package/dist/lib.cjs/types/base/constants.d.ts +6 -0
- package/dist/lib.cjs/types/base/cookie.d.ts +10 -0
- package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +31 -11
- package/dist/lib.cjs/types/base/deserialize.d.ts +3 -0
- package/dist/lib.cjs/types/base/errors/index.d.ts +1 -1
- package/dist/lib.cjs/types/base/index.d.ts +2 -0
- package/dist/lib.cjs/types/base/interfaces.d.ts +9 -1
- package/dist/lib.cjs/types/base/utils.d.ts +50 -3
- package/dist/lib.cjs/types/base/wallet/index.d.ts +4 -2
- package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +1 -1
- package/dist/lib.cjs/types/connectors/auth-connector/interface.d.ts +1 -1
- package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +2 -2
- package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +2 -2
- package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/config.d.ts +0 -1
- package/dist/lib.cjs/types/noModal.d.ts +18 -9
- package/dist/lib.cjs/types/providers/account-abstraction-provider/providers/AccountAbstractionProvider.d.ts +4 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/converter.d.ts +0 -1
- package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.d.ts +0 -1
- package/dist/lib.cjs/types/react/hooks/useIdentityToken.d.ts +2 -2
- package/dist/lib.cjs/types/react/interfaces.d.ts +2 -1
- package/dist/lib.cjs/types/react/wagmi/constants.d.ts +43 -0
- package/dist/lib.cjs/types/vue/composables/useIdentityToken.d.ts +1 -1
- package/dist/lib.cjs/types/vue/wagmi/constants.d.ts +43 -0
- package/dist/lib.cjs/types/vue/wagmi/provider.d.ts +1 -0
- package/dist/lib.cjs/vue/WalletServicesInnerProvider.js +4 -2
- package/dist/lib.cjs/vue/Web3AuthProvider.js +7 -1
- package/dist/lib.cjs/vue/composables/useCheckout.js +4 -2
- package/dist/lib.cjs/vue/composables/useEnableMFA.js +4 -2
- package/dist/lib.cjs/vue/composables/useIdentityToken.js +7 -5
- package/dist/lib.cjs/vue/composables/useManageMFA.js +5 -3
- package/dist/lib.cjs/vue/composables/useSwap.js +4 -2
- package/dist/lib.cjs/vue/composables/useSwitchChain.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletConnectScanner.js +4 -2
- package/dist/lib.cjs/vue/composables/useWalletUI.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthDisconnect.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthInner.js +4 -2
- package/dist/lib.cjs/vue/composables/useWeb3AuthUser.js +4 -2
- package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +21 -15
- package/dist/lib.cjs/vue/wagmi/constants.js +16 -0
- package/dist/lib.cjs/vue/wagmi/provider.js +33 -15
- package/dist/lib.esm/base/analytics.js +117 -0
- package/dist/lib.esm/base/connector/constants.js +2 -1
- package/dist/lib.esm/base/constants.js +11 -1
- package/dist/lib.esm/base/cookie.js +34 -0
- package/dist/lib.esm/base/deserialize.js +11 -0
- package/dist/lib.esm/base/errors/index.js +2 -2
- package/dist/lib.esm/base/utils.js +104 -7
- package/dist/lib.esm/base/wallet/index.js +3 -3
- package/dist/lib.esm/connectors/auth-connector/authConnector.js +41 -65
- package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +1 -1
- package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +1 -1
- package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +9 -3
- package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +7 -3
- package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +7 -4
- package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +8 -4
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/config.js +8 -7
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/index.js +1 -1
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +8 -4
- package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +1 -1
- package/dist/lib.esm/index.js +5 -3
- package/dist/lib.esm/noModal.js +378 -107
- package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +8 -4
- package/dist/lib.esm/react/context/Web3AuthInnerContext.js +22 -17
- package/dist/lib.esm/react/hooks/useIdentityToken.js +3 -3
- package/dist/lib.esm/react/wagmi/constants.js +14 -0
- package/dist/lib.esm/react/wagmi/provider.js +13 -8
- package/dist/lib.esm/vue/Web3AuthProvider.js +7 -1
- package/dist/lib.esm/vue/composables/useIdentityToken.js +3 -3
- package/dist/lib.esm/vue/composables/useManageMFA.js +1 -1
- package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +18 -14
- package/dist/lib.esm/vue/wagmi/constants.js +14 -0
- package/dist/lib.esm/vue/wagmi/provider.js +33 -13
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +4 -6
- package/package.json +21 -19
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { WEB3AUTH_STATE_STORAGE_KEY } from './constants.js';
|
|
2
|
+
import { deserialize } from './deserialize.js';
|
|
3
|
+
|
|
4
|
+
const cookieStorage = options => ({
|
|
5
|
+
getItem(key) {
|
|
6
|
+
if (typeof window === "undefined") return null;
|
|
7
|
+
const value = parseCookie(document.cookie, key);
|
|
8
|
+
return value !== null && value !== void 0 ? value : null;
|
|
9
|
+
},
|
|
10
|
+
setItem(key, value) {
|
|
11
|
+
if (typeof window === "undefined") return;
|
|
12
|
+
let cookieString = `${key}=${value};path=/;samesite=Lax`;
|
|
13
|
+
if (options !== null && options !== void 0 && options.expiry && typeof options.expiry === "number") cookieString += `; expires=${new Date(Date.now() + options.expiry).toUTCString()}`;
|
|
14
|
+
if (process.env.NODE_ENV === "production") cookieString += "; secure";
|
|
15
|
+
document.cookie = cookieString;
|
|
16
|
+
},
|
|
17
|
+
removeItem(key) {
|
|
18
|
+
if (typeof window === "undefined") return;
|
|
19
|
+
document.cookie = `${key}=;max-age=-1;path=/`;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function cookieToWeb3AuthState(cookie) {
|
|
23
|
+
if (!cookie) return undefined;
|
|
24
|
+
const parsed = parseCookie(cookie, WEB3AUTH_STATE_STORAGE_KEY);
|
|
25
|
+
if (!parsed) return undefined;
|
|
26
|
+
return deserialize(parsed);
|
|
27
|
+
}
|
|
28
|
+
function parseCookie(cookie, key) {
|
|
29
|
+
const keyValue = cookie.split("; ").find(x => x.startsWith(`${key}=`));
|
|
30
|
+
if (!keyValue) return undefined;
|
|
31
|
+
return keyValue.substring(key.length + 1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { cookieStorage, cookieToWeb3AuthState, parseCookie };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function deserialize(value, reviver) {
|
|
2
|
+
return JSON.parse(value, (key, value_) => {
|
|
3
|
+
var _value, _value2, _reviver;
|
|
4
|
+
let value = value_;
|
|
5
|
+
if (((_value = value) === null || _value === void 0 ? void 0 : _value.__type) === "bigint") value = BigInt(value.value);
|
|
6
|
+
if (((_value2 = value) === null || _value2 === void 0 ? void 0 : _value2.__type) === "Map") value = new Map(value.value);
|
|
7
|
+
return (_reviver = void 0 ) !== null && _reviver !== void 0 ? _reviver : value;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { deserialize };
|
|
@@ -135,7 +135,7 @@ class WalletLoginError extends Web3AuthError {
|
|
|
135
135
|
static unsupportedOperation(extraMessage = "", cause) {
|
|
136
136
|
return WalletLoginError.fromCode(5117, extraMessage, cause);
|
|
137
137
|
}
|
|
138
|
-
static
|
|
138
|
+
static sfaKeyNotFound(extraMessage = "", cause) {
|
|
139
139
|
return WalletLoginError.fromCode(5118, extraMessage, cause);
|
|
140
140
|
}
|
|
141
141
|
static userNotLoggedIn(extraMessage = "", cause) {
|
|
@@ -151,7 +151,7 @@ _defineProperty(WalletLoginError, "messages", {
|
|
|
151
151
|
5115: "User has already enabled mfa, please use the @web3auth/web3auth-web sdk for login with mfa",
|
|
152
152
|
5116: "Chain config has not been added. Please add the chain config before calling switchChain",
|
|
153
153
|
5117: "Unsupported operation",
|
|
154
|
-
5118: "
|
|
154
|
+
5118: "useSFAKey flag is enabled but SFA key is not available",
|
|
155
155
|
5119: "User not logged in."
|
|
156
156
|
});
|
|
157
157
|
class WalletOperationsError extends Web3AuthError {
|
|
@@ -2,15 +2,14 @@ import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
|
2
2
|
export { cloneDeep } from '@toruslabs/base-controllers';
|
|
3
3
|
import { SIGNER_MAP } from '@toruslabs/constants';
|
|
4
4
|
import { get } from '@toruslabs/http-helpers';
|
|
5
|
-
import {
|
|
5
|
+
import { SOLANA_CAIP_CHAIN_MAP } from './constants.js';
|
|
6
|
+
import { Web3AuthError } from './errors/index.js';
|
|
7
|
+
import { WEB3AUTH_NETWORK } from '@web3auth/auth';
|
|
6
8
|
|
|
7
9
|
const isHexStrict = hex => {
|
|
8
10
|
return (typeof hex === "string" || typeof hex === "number") && /^(-)?0x[0-9a-f]*$/i.test(hex);
|
|
9
11
|
};
|
|
10
|
-
const signerHost = (web3AuthNetwork = WEB3AUTH_NETWORK.SAPPHIRE_MAINNET
|
|
11
|
-
if (authBuildEnv === BUILD_ENV.TESTING || authBuildEnv === BUILD_ENV.DEVELOPMENT) {
|
|
12
|
-
return "https://test-signer.web3auth.io";
|
|
13
|
-
}
|
|
12
|
+
const signerHost = (web3AuthNetwork = WEB3AUTH_NETWORK.SAPPHIRE_MAINNET) => {
|
|
14
13
|
return SIGNER_MAP[web3AuthNetwork];
|
|
15
14
|
};
|
|
16
15
|
const fetchProjectConfig = async ({
|
|
@@ -19,7 +18,7 @@ const fetchProjectConfig = async ({
|
|
|
19
18
|
aaProvider,
|
|
20
19
|
authBuildEnv
|
|
21
20
|
}) => {
|
|
22
|
-
const url = new URL(`${signerHost(web3AuthNetwork
|
|
21
|
+
const url = new URL(`${signerHost(web3AuthNetwork)}/api/v2/configuration`);
|
|
23
22
|
url.searchParams.append("project_id", clientId);
|
|
24
23
|
url.searchParams.append("network", web3AuthNetwork);
|
|
25
24
|
if (authBuildEnv) url.searchParams.append("build_env", authBuildEnv);
|
|
@@ -81,6 +80,104 @@ function withAbort(fn, signal, onAbort) {
|
|
|
81
80
|
});
|
|
82
81
|
});
|
|
83
82
|
}
|
|
83
|
+
const isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
|
|
84
84
|
const fromViemChain = fromWagmiChain;
|
|
85
|
+
const getWhitelabelAnalyticsProperties = uiConfig => {
|
|
86
|
+
var _uiConfig$theme, _uiConfig$theme2;
|
|
87
|
+
return {
|
|
88
|
+
whitelabel_app_name: uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.appName,
|
|
89
|
+
whitelabel_app_url: uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.appUrl,
|
|
90
|
+
whitelabel_logo_light_enabled: Boolean(uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.logoLight),
|
|
91
|
+
whitelabel_logo_dark_enabled: Boolean(uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.logoDark),
|
|
92
|
+
whitelabel_default_language: uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.defaultLanguage,
|
|
93
|
+
whitelabel_theme_mode: uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.mode,
|
|
94
|
+
whitelabel_use_logo_loader: uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.useLogoLoader,
|
|
95
|
+
whitelabel_theme_primary: uiConfig === null || uiConfig === void 0 || (_uiConfig$theme = uiConfig.theme) === null || _uiConfig$theme === void 0 ? void 0 : _uiConfig$theme.primary,
|
|
96
|
+
whitelabel_theme_on_primary: uiConfig === null || uiConfig === void 0 || (_uiConfig$theme2 = uiConfig.theme) === null || _uiConfig$theme2 === void 0 ? void 0 : _uiConfig$theme2.onPrimary,
|
|
97
|
+
whitelabel_tnc_link_enabled: Boolean(uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.tncLink),
|
|
98
|
+
whitelabel_privacy_policy_enabled: Boolean(uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.privacyPolicy)
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const getAaAnalyticsProperties = accountAbstractionConfig => {
|
|
102
|
+
var _accountAbstractionCo, _accountAbstractionCo2, _accountAbstractionCo3, _accountAbstractionCo4, _accountAbstractionCo5;
|
|
103
|
+
const bundlerHostnames = Array.from(new Set(accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo = accountAbstractionConfig.chains) === null || _accountAbstractionCo === void 0 ? void 0 : _accountAbstractionCo.map(chain => {
|
|
104
|
+
var _chain$bundlerConfig;
|
|
105
|
+
return getHostname((_chain$bundlerConfig = chain.bundlerConfig) === null || _chain$bundlerConfig === void 0 ? void 0 : _chain$bundlerConfig.url);
|
|
106
|
+
}).filter(Boolean)));
|
|
107
|
+
const paymasterHostnames = Array.from(new Set(accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo2 = accountAbstractionConfig.chains) === null || _accountAbstractionCo2 === void 0 ? void 0 : _accountAbstractionCo2.map(chain => {
|
|
108
|
+
var _chain$paymasterConfi;
|
|
109
|
+
return getHostname((_chain$paymasterConfi = chain.paymasterConfig) === null || _chain$paymasterConfi === void 0 ? void 0 : _chain$paymasterConfi.url);
|
|
110
|
+
}).filter(Boolean)));
|
|
111
|
+
return {
|
|
112
|
+
aa_smart_account_type: accountAbstractionConfig === null || accountAbstractionConfig === void 0 ? void 0 : accountAbstractionConfig.smartAccountType,
|
|
113
|
+
aa_chain_ids: accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo3 = accountAbstractionConfig.chains) === null || _accountAbstractionCo3 === void 0 ? void 0 : _accountAbstractionCo3.map(chain => getCaipChainId({
|
|
114
|
+
chainId: chain.chainId,
|
|
115
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155
|
|
116
|
+
})),
|
|
117
|
+
aa_bundler_urls: bundlerHostnames,
|
|
118
|
+
aa_paymaster_urls: paymasterHostnames,
|
|
119
|
+
aa_paymaster_enabled: paymasterHostnames.length > 0,
|
|
120
|
+
aa_paymaster_context_enabled: accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo4 = accountAbstractionConfig.chains) === null || _accountAbstractionCo4 === void 0 ? void 0 : _accountAbstractionCo4.some(chain => {
|
|
121
|
+
var _chain$bundlerConfig2;
|
|
122
|
+
return (_chain$bundlerConfig2 = chain.bundlerConfig) === null || _chain$bundlerConfig2 === void 0 ? void 0 : _chain$bundlerConfig2.paymasterContext;
|
|
123
|
+
}),
|
|
124
|
+
aa_erc20_paymaster_enabled: accountAbstractionConfig === null || accountAbstractionConfig === void 0 || (_accountAbstractionCo5 = accountAbstractionConfig.chains) === null || _accountAbstractionCo5 === void 0 ? void 0 : _accountAbstractionCo5.some(chain => {
|
|
125
|
+
var _chain$bundlerConfig3;
|
|
126
|
+
return (_chain$bundlerConfig3 = chain.bundlerConfig) === null || _chain$bundlerConfig3 === void 0 || (_chain$bundlerConfig3 = _chain$bundlerConfig3.paymasterContext) === null || _chain$bundlerConfig3 === void 0 ? void 0 : _chain$bundlerConfig3.token;
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const getWalletServicesAnalyticsProperties = walletServicesConfig => {
|
|
131
|
+
var _walletServicesConfig, _walletServicesConfig2, _walletServicesConfig3, _walletServicesConfig4, _walletServicesConfig5, _walletServicesConfig6, _walletServicesConfig7, _walletServicesConfig8, _walletServicesConfig9, _walletServicesConfig0, _walletServicesConfig1;
|
|
132
|
+
return {
|
|
133
|
+
ws_confirmation_strategy: walletServicesConfig === null || walletServicesConfig === void 0 ? void 0 : walletServicesConfig.confirmationStrategy,
|
|
134
|
+
ws_enable_key_export: walletServicesConfig === null || walletServicesConfig === void 0 ? void 0 : walletServicesConfig.enableKeyExport,
|
|
135
|
+
ws_show_widget_button: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig = walletServicesConfig.whiteLabel) === null || _walletServicesConfig === void 0 ? void 0 : _walletServicesConfig.showWidgetButton,
|
|
136
|
+
ws_button_position: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig2 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig2 === void 0 ? void 0 : _walletServicesConfig2.buttonPosition,
|
|
137
|
+
ws_hide_nft_display: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig3 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig3 === void 0 ? void 0 : _walletServicesConfig3.hideNftDisplay,
|
|
138
|
+
ws_hide_token_display: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig4 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig4 === void 0 ? void 0 : _walletServicesConfig4.hideTokenDisplay,
|
|
139
|
+
ws_hide_transfers: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig5 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig5 === void 0 ? void 0 : _walletServicesConfig5.hideTransfers,
|
|
140
|
+
ws_hide_topup: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig6 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig6 === void 0 ? void 0 : _walletServicesConfig6.hideTopup,
|
|
141
|
+
ws_hide_receive: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig7 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig7 === void 0 ? void 0 : _walletServicesConfig7.hideReceive,
|
|
142
|
+
ws_hide_swap: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig8 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig8 === void 0 ? void 0 : _walletServicesConfig8.hideSwap,
|
|
143
|
+
ws_hide_show_all_tokens: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig9 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig9 === void 0 ? void 0 : _walletServicesConfig9.hideShowAllTokens,
|
|
144
|
+
ws_hide_wallet_connect: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig0 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig0 === void 0 ? void 0 : _walletServicesConfig0.hideWalletConnect,
|
|
145
|
+
ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
const sdkVersion = "10.0.0";
|
|
149
|
+
const getErrorAnalyticsProperties = error => {
|
|
150
|
+
try {
|
|
151
|
+
const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
|
|
152
|
+
const message = error instanceof Error ? error.message : (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
|
|
153
|
+
return {
|
|
154
|
+
error_message: message,
|
|
155
|
+
error_code: code
|
|
156
|
+
};
|
|
157
|
+
} catch {
|
|
158
|
+
return {
|
|
159
|
+
error_message: "Unknown error",
|
|
160
|
+
error_code: undefined
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const getHostname = url => {
|
|
165
|
+
try {
|
|
166
|
+
return new URL(url).hostname;
|
|
167
|
+
} catch {
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const getCaipChainId = chain => {
|
|
172
|
+
if (chain.chainNamespace === CHAIN_NAMESPACES.EIP155) {
|
|
173
|
+
return `${chain.chainNamespace}:${parseInt(chain.chainId, 16)}`;
|
|
174
|
+
}
|
|
175
|
+
if (chain.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
|
|
176
|
+
return `${chain.chainNamespace}:${SOLANA_CAIP_CHAIN_MAP[chain.chainId]}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// for other chain namespaces, we just return the chainId as is
|
|
180
|
+
return `${chain.chainNamespace}:${chain.chainId}`;
|
|
181
|
+
};
|
|
85
182
|
|
|
86
|
-
export { fetchProjectConfig, fetchWalletRegistry, fromViemChain, fromWagmiChain, isHexStrict, normalizeWalletName, signerHost, withAbort };
|
|
183
|
+
export { fetchProjectConfig, fetchWalletRegistry, fromViemChain, fromWagmiChain, getAaAnalyticsProperties, getCaipChainId, getErrorAnalyticsProperties, getHostname, getWalletServicesAnalyticsProperties, getWhitelabelAnalyticsProperties, isBrowser, isHexStrict, normalizeWalletName, sdkVersion, signerHost, withAbort };
|
|
@@ -2,12 +2,12 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
|
2
2
|
|
|
3
3
|
const MULTI_CHAIN_CONNECTORS = {
|
|
4
4
|
AUTH: "auth",
|
|
5
|
-
WALLET_CONNECT_V2: "wallet-connect-v2"
|
|
5
|
+
WALLET_CONNECT_V2: "wallet-connect-v2",
|
|
6
|
+
METAMASK: "metamask"
|
|
6
7
|
};
|
|
7
8
|
const SOLANA_CONNECTORS = _objectSpread({}, MULTI_CHAIN_CONNECTORS);
|
|
8
9
|
const EVM_CONNECTORS = _objectSpread({
|
|
9
|
-
COINBASE: "coinbase"
|
|
10
|
-
METAMASK: "metamask"
|
|
10
|
+
COINBASE: "coinbase"
|
|
11
11
|
}, MULTI_CHAIN_CONNECTORS);
|
|
12
12
|
const WALLET_CONNECTORS = _objectSpread(_objectSpread({}, EVM_CONNECTORS), SOLANA_CONNECTORS);
|
|
13
13
|
const CONNECTOR_NAMES = {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { cloneDeep, BUTTON_POSITION, CONFIRMATION_STRATEGY, CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
4
3
|
import { SecurePubSub } from '@toruslabs/secure-pub-sub';
|
|
5
|
-
import { BUILD_ENV, UX_MODE, Auth, SDK_MODE, SUPPORTED_KEY_CURVES, randomId, createHandler, PopupHandler, getUserId } from '@web3auth/auth';
|
|
4
|
+
import { BUILD_ENV, UX_MODE, Auth, SDK_MODE, SUPPORTED_KEY_CURVES, randomId, version, createHandler, PopupHandler, getUserId } from '@web3auth/auth';
|
|
6
5
|
import deepmerge from 'deepmerge';
|
|
7
6
|
import { parseToken } from '../utils.js';
|
|
8
|
-
import '@toruslabs/constants';
|
|
9
|
-
import '@toruslabs/http-helpers';
|
|
10
7
|
import { BaseConnector } from '../../base/connector/baseConnector.js';
|
|
11
8
|
import { WALLET_CONNECTORS } from '../../base/wallet/index.js';
|
|
12
9
|
import { CONNECTOR_NAMESPACES } from '../../base/chain/IChainInterface.js';
|
|
13
10
|
import { CONNECTOR_CATEGORY, CONNECTOR_STATUS, CONNECTOR_EVENTS } from '../../base/connector/constants.js';
|
|
14
11
|
import { WalletInitializationError, WalletLoginError, Web3AuthError } from '../../base/errors/index.js';
|
|
15
12
|
import { log } from '../../base/loglevel.js';
|
|
13
|
+
import { CHAIN_NAMESPACES, cloneDeep } from '@toruslabs/base-controllers';
|
|
14
|
+
import '@toruslabs/constants';
|
|
15
|
+
import '@toruslabs/http-helpers';
|
|
16
16
|
|
|
17
17
|
class AuthConnector extends BaseConnector {
|
|
18
18
|
constructor(params) {
|
|
@@ -70,13 +70,14 @@ class AuthConnector extends BaseConnector {
|
|
|
70
70
|
const isRedirectResult = this.authOptions.uxMode === UX_MODE.REDIRECT;
|
|
71
71
|
this.authOptions = _objectSpread(_objectSpread({}, this.authOptions), {}, {
|
|
72
72
|
replaceUrlOnRedirect: isRedirectResult,
|
|
73
|
-
useCoreKitKey: this.coreOptions.
|
|
73
|
+
useCoreKitKey: this.coreOptions.useSFAKey
|
|
74
74
|
});
|
|
75
75
|
this.authInstance = new Auth(_objectSpread(_objectSpread({}, this.authOptions), {}, {
|
|
76
76
|
clientId: this.coreOptions.clientId,
|
|
77
77
|
network: this.coreOptions.web3AuthNetwork,
|
|
78
78
|
sdkMode: SDK_MODE.IFRAME,
|
|
79
|
-
authConnectionConfig: this.authConnectionConfig.filter(x => !x.isDefault)
|
|
79
|
+
authConnectionConfig: this.authConnectionConfig.filter(x => !x.isDefault),
|
|
80
|
+
mfaSettings: this.coreOptions.mfaSettings
|
|
80
81
|
}));
|
|
81
82
|
log.debug("initializing auth connector init", this.authOptions);
|
|
82
83
|
|
|
@@ -129,11 +130,11 @@ class AuthConnector extends BaseConnector {
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
// wait for auth instance to be ready.
|
|
133
|
+
log.debug("initializing auth connector");
|
|
132
134
|
await authInstancePromise;
|
|
133
135
|
this.status = CONNECTOR_STATUS.READY;
|
|
134
136
|
this.emit(CONNECTOR_EVENTS.READY, WALLET_CONNECTORS.AUTH);
|
|
135
137
|
try {
|
|
136
|
-
log.debug("initializing auth connector");
|
|
137
138
|
const {
|
|
138
139
|
sessionId
|
|
139
140
|
} = this.authInstance || {};
|
|
@@ -143,10 +144,14 @@ class AuthConnector extends BaseConnector {
|
|
|
143
144
|
await this.connect({
|
|
144
145
|
chainId: options.chainId
|
|
145
146
|
});
|
|
147
|
+
} else if (!sessionId && options.autoConnect) {
|
|
148
|
+
// if here, this means that the connector is cached but the sessionId is not available.
|
|
149
|
+
// this can happen if the sessionId has expired.
|
|
150
|
+
// we are throwing an error to reset the cached state.
|
|
151
|
+
throw WalletLoginError.connectionError("Failed to rehydrate");
|
|
146
152
|
}
|
|
147
153
|
} catch (error) {
|
|
148
|
-
|
|
149
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
154
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
150
155
|
}
|
|
151
156
|
}
|
|
152
157
|
async connect(params) {
|
|
@@ -224,7 +229,7 @@ class AuthConnector extends BaseConnector {
|
|
|
224
229
|
this.rehydrated = false;
|
|
225
230
|
this.emit(CONNECTOR_EVENTS.DISCONNECTED);
|
|
226
231
|
}
|
|
227
|
-
async
|
|
232
|
+
async getIdentityToken() {
|
|
228
233
|
if (this.status !== CONNECTOR_STATUS.CONNECTED) throw WalletLoginError.notConnectedError("Not connected with wallet, Please login/connect first");
|
|
229
234
|
const userInfo = await this.getUserInfo();
|
|
230
235
|
return {
|
|
@@ -288,13 +293,13 @@ class AuthConnector extends BaseConnector {
|
|
|
288
293
|
_getFinalPrivKey() {
|
|
289
294
|
if (!this.authInstance) return "";
|
|
290
295
|
let finalPrivKey = this.authInstance.privKey;
|
|
291
|
-
// coreKitKey is available only for custom
|
|
292
|
-
if (this.coreOptions.
|
|
296
|
+
// coreKitKey is available only for custom connections by default
|
|
297
|
+
if (this.coreOptions.useSFAKey) {
|
|
293
298
|
// this is to check if the user has already logged in but coreKitKey is not available.
|
|
294
|
-
// when
|
|
299
|
+
// when useSFAKey is set to true.
|
|
295
300
|
// This is to ensure that when there is no user session active, we don't throw an exception.
|
|
296
301
|
if (this.authInstance.privKey && !this.authInstance.coreKitKey) {
|
|
297
|
-
throw WalletLoginError.
|
|
302
|
+
throw WalletLoginError.sfaKeyNotFound();
|
|
298
303
|
}
|
|
299
304
|
finalPrivKey = this.authInstance.coreKitKey;
|
|
300
305
|
}
|
|
@@ -311,8 +316,8 @@ class AuthConnector extends BaseConnector {
|
|
|
311
316
|
|
|
312
317
|
// if not logged in then login
|
|
313
318
|
const keyAvailable = chainNamespace === CHAIN_NAMESPACES.EIP155 || chainNamespace === CHAIN_NAMESPACES.SOLANA ? (_this$authInstance = this.authInstance) === null || _this$authInstance === void 0 ? void 0 : _this$authInstance.sessionId : this._getFinalPrivKey();
|
|
314
|
-
if (params.
|
|
315
|
-
id_token: params.
|
|
319
|
+
if (params.idToken) params.extraLoginOptions = _objectSpread(_objectSpread({}, params.extraLoginOptions), {}, {
|
|
320
|
+
id_token: params.idToken
|
|
316
321
|
});
|
|
317
322
|
if (!keyAvailable || (_params$extraLoginOpt = params.extraLoginOptions) !== null && _params$extraLoginOpt !== void 0 && _params$extraLoginOpt.id_token) {
|
|
318
323
|
var _params$extraLoginOpt2;
|
|
@@ -378,14 +383,14 @@ class AuthConnector extends BaseConnector {
|
|
|
378
383
|
});
|
|
379
384
|
if (!(providerConfig !== null && providerConfig !== void 0 && providerConfig.authConnection)) throw WalletLoginError.connectionError("Invalid auth connection.");
|
|
380
385
|
const jwtParams = _objectSpread(_objectSpread(_objectSpread({}, providerConfig.jwtParameters || {}), params.extraLoginOptions || {}), {}, {
|
|
381
|
-
login_hint: params.
|
|
386
|
+
login_hint: params.loginHint || ((_params$extraLoginOpt3 = params.extraLoginOptions) === null || _params$extraLoginOpt3 === void 0 ? void 0 : _params$extraLoginOpt3.login_hint)
|
|
382
387
|
});
|
|
383
388
|
const nonce = randomId();
|
|
384
389
|
|
|
385
390
|
// post a message to the auth provider to indicate that login has been initiated.
|
|
386
391
|
const loginParams = cloneDeep(params);
|
|
387
392
|
loginParams.extraLoginOptions = _objectSpread(_objectSpread({}, loginParams.extraLoginOptions || {}), {}, {
|
|
388
|
-
login_hint: params.
|
|
393
|
+
login_hint: params.loginHint || ((_params$extraLoginOpt4 = params.extraLoginOptions) === null || _params$extraLoginOpt4 === void 0 ? void 0 : _params$extraLoginOpt4.login_hint)
|
|
389
394
|
});
|
|
390
395
|
delete loginParams.chainId;
|
|
391
396
|
const popupParams = {
|
|
@@ -393,7 +398,7 @@ class AuthConnector extends BaseConnector {
|
|
|
393
398
|
authConnectionId: providerConfig.authConnectionId,
|
|
394
399
|
clientId: providerConfig.clientId || jwtParams.client_id,
|
|
395
400
|
groupedAuthConnectionId: providerConfig.groupedAuthConnectionId,
|
|
396
|
-
redirect_uri: `${this.authInstance.
|
|
401
|
+
redirect_uri: `${this.authInstance.options.sdkUrl}/auth`,
|
|
397
402
|
jwtParams,
|
|
398
403
|
customState: {
|
|
399
404
|
nonce,
|
|
@@ -402,7 +407,8 @@ class AuthConnector extends BaseConnector {
|
|
|
402
407
|
dapp_redirect_url: this.authInstance.options.redirectUrl,
|
|
403
408
|
uxMode: this.authInstance.options.uxMode,
|
|
404
409
|
whiteLabel: JSON.stringify(this.authInstance.options.whiteLabel),
|
|
405
|
-
loginParams: JSON.stringify(loginParams)
|
|
410
|
+
loginParams: JSON.stringify(loginParams),
|
|
411
|
+
version: version.split(".")[0]
|
|
406
412
|
},
|
|
407
413
|
web3AuthClientId: this.coreOptions.clientId,
|
|
408
414
|
web3AuthNetwork: this.coreOptions.web3AuthNetwork
|
|
@@ -448,7 +454,12 @@ class AuthConnector extends BaseConnector {
|
|
|
448
454
|
reject(WalletLoginError.popupClosed());
|
|
449
455
|
}
|
|
450
456
|
});
|
|
451
|
-
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(
|
|
457
|
+
this.authInstance.postLoginInitiatedMessage(loginParams, nonce).then(resolve).catch(error => {
|
|
458
|
+
if (error instanceof Web3AuthError) {
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
reject(WalletLoginError.connectionError(error instanceof Error ? error.message : error || "Failed to login with social"));
|
|
462
|
+
});
|
|
452
463
|
});
|
|
453
464
|
}
|
|
454
465
|
connectWithJwtLogin(params) {
|
|
@@ -472,9 +483,9 @@ class AuthConnector extends BaseConnector {
|
|
|
472
483
|
const loginParams = cloneDeep(params);
|
|
473
484
|
const finalExtraLoginOptions = _objectSpread(_objectSpread({}, (loginConfig === null || loginConfig === void 0 ? void 0 : loginConfig.jwtParameters) || {}), params.extraLoginOptions || {});
|
|
474
485
|
let finalUserId;
|
|
475
|
-
if (params.
|
|
486
|
+
if (params.loginHint || (_params$extraLoginOpt5 = params.extraLoginOptions) !== null && _params$extraLoginOpt5 !== void 0 && _params$extraLoginOpt5.login_hint) {
|
|
476
487
|
var _params$extraLoginOpt6;
|
|
477
|
-
finalUserId = params.
|
|
488
|
+
finalUserId = params.loginHint || ((_params$extraLoginOpt6 = params.extraLoginOptions) === null || _params$extraLoginOpt6 === void 0 ? void 0 : _params$extraLoginOpt6.login_hint);
|
|
478
489
|
} else if ((_params$extraLoginOpt7 = params.extraLoginOptions) !== null && _params$extraLoginOpt7 !== void 0 && _params$extraLoginOpt7.id_token) {
|
|
479
490
|
if (typeof finalExtraLoginOptions.isUserIdCaseSensitive === "undefined") {
|
|
480
491
|
throw WalletInitializationError.invalidParams(`isUserIdCaseSensitive is required for this connection: ${finalExtraLoginOptions.authConnection}`);
|
|
@@ -523,14 +534,12 @@ const authConnector = params => {
|
|
|
523
534
|
const connectorSettings = {};
|
|
524
535
|
const {
|
|
525
536
|
whitelist,
|
|
526
|
-
whitelabel,
|
|
527
537
|
sessionTime
|
|
528
538
|
} = projectConfig;
|
|
529
539
|
if (whitelist) connectorSettings.originData = whitelist.signed_urls;
|
|
530
540
|
if (sessionTime) connectorSettings.sessionTime = sessionTime;
|
|
531
541
|
if ((_coreOptions$uiConfig = coreOptions.uiConfig) !== null && _coreOptions$uiConfig !== void 0 && _coreOptions$uiConfig.uxMode) connectorSettings.uxMode = coreOptions.uiConfig.uxMode;
|
|
532
|
-
const uiConfig =
|
|
533
|
-
if (!uiConfig.mode) uiConfig.mode = "light";
|
|
542
|
+
const uiConfig = coreOptions.uiConfig || {};
|
|
534
543
|
connectorSettings.whiteLabel = uiConfig;
|
|
535
544
|
const finalConnectorSettings = deepmerge.all([{
|
|
536
545
|
uxMode: UX_MODE.POPUP,
|
|
@@ -540,56 +549,23 @@ const authConnector = params => {
|
|
|
540
549
|
connectorSettings, (params === null || params === void 0 ? void 0 : params.connectorSettings) || {}]);
|
|
541
550
|
|
|
542
551
|
// WS settings
|
|
543
|
-
const {
|
|
544
|
-
enableKeyExport,
|
|
545
|
-
walletUi
|
|
546
|
-
} = projectConfig;
|
|
547
|
-
const isKeyExportEnabled = typeof enableKeyExport === "boolean" ? enableKeyExport : true;
|
|
548
|
-
const {
|
|
549
|
-
enablePortfolioWidget = false,
|
|
550
|
-
enableTokenDisplay = true,
|
|
551
|
-
enableNftDisplay = true,
|
|
552
|
-
enableWalletConnect = true,
|
|
553
|
-
enableBuyButton = true,
|
|
554
|
-
enableSendButton = true,
|
|
555
|
-
enableSwapButton = true,
|
|
556
|
-
enableReceiveButton = true,
|
|
557
|
-
enableShowAllTokensButton = true,
|
|
558
|
-
enableConfirmationModal = false,
|
|
559
|
-
portfolioWidgetPosition = BUTTON_POSITION.BOTTOM_LEFT,
|
|
560
|
-
defaultPortfolio = "token"
|
|
561
|
-
} = walletUi || {};
|
|
562
|
-
const projectConfigWhiteLabel = {
|
|
563
|
-
showWidgetButton: enablePortfolioWidget,
|
|
564
|
-
hideNftDisplay: !enableNftDisplay,
|
|
565
|
-
hideTokenDisplay: !enableTokenDisplay,
|
|
566
|
-
hideTransfers: !enableSendButton,
|
|
567
|
-
hideTopup: !enableBuyButton,
|
|
568
|
-
hideReceive: !enableReceiveButton,
|
|
569
|
-
hideSwap: !enableSwapButton,
|
|
570
|
-
hideShowAllTokens: !enableShowAllTokensButton,
|
|
571
|
-
hideWalletConnect: !enableWalletConnect,
|
|
572
|
-
buttonPosition: portfolioWidgetPosition,
|
|
573
|
-
defaultPortfolio
|
|
574
|
-
};
|
|
575
|
-
const whiteLabel = deepmerge.all([projectConfigWhiteLabel, uiConfig, ((_coreOptions$walletSe = coreOptions.walletServicesConfig) === null || _coreOptions$walletSe === void 0 ? void 0 : _coreOptions$walletSe.whiteLabel) || {}]);
|
|
576
|
-
const confirmationStrategy = (_coreOptions$walletSe2 = (_coreOptions$walletSe3 = coreOptions.walletServicesConfig) === null || _coreOptions$walletSe3 === void 0 ? void 0 : _coreOptions$walletSe3.confirmationStrategy) !== null && _coreOptions$walletSe2 !== void 0 ? _coreOptions$walletSe2 : enableConfirmationModal ? CONFIRMATION_STRATEGY.MODAL : CONFIRMATION_STRATEGY.AUTO_APPROVE;
|
|
552
|
+
const whiteLabel = deepmerge.all([uiConfig, ((_coreOptions$walletSe = coreOptions.walletServicesConfig) === null || _coreOptions$walletSe === void 0 ? void 0 : _coreOptions$walletSe.whiteLabel) || {}]);
|
|
577
553
|
const finalWsSettings = _objectSpread(_objectSpread({}, coreOptions.walletServicesConfig), {}, {
|
|
578
|
-
confirmationStrategy,
|
|
579
554
|
whiteLabel,
|
|
580
555
|
accountAbstractionConfig: coreOptions.accountAbstractionConfig,
|
|
581
|
-
enableLogging: coreOptions.enableLogging
|
|
582
|
-
enableKeyExport: enableKeyExport
|
|
556
|
+
enableLogging: coreOptions.enableLogging
|
|
583
557
|
});
|
|
584
558
|
|
|
585
559
|
// Core options
|
|
560
|
+
const isKeyExportEnabled = (_coreOptions$walletSe2 = (_coreOptions$walletSe3 = coreOptions.walletServicesConfig) === null || _coreOptions$walletSe3 === void 0 ? void 0 : _coreOptions$walletSe3.enableKeyExport) !== null && _coreOptions$walletSe2 !== void 0 ? _coreOptions$walletSe2 : true;
|
|
586
561
|
if (coreOptions.privateKeyProvider) coreOptions.privateKeyProvider.setKeyExportFlag(isKeyExportEnabled);
|
|
587
562
|
return new AuthConnector({
|
|
588
563
|
connectorSettings: finalConnectorSettings,
|
|
589
564
|
walletServicesSettings: finalWsSettings,
|
|
590
|
-
loginSettings: params === null || params === void 0 ? void 0 : params.loginSettings,
|
|
565
|
+
loginSettings: _objectSpread(_objectSpread({}, (params === null || params === void 0 ? void 0 : params.loginSettings) || {}), {}, {
|
|
566
|
+
mfaLevel: coreOptions.mfaLevel
|
|
567
|
+
}),
|
|
591
568
|
coreOptions,
|
|
592
|
-
// TODO: check, test this and may need to send modal config here later on.!!
|
|
593
569
|
authConnectionConfig: projectConfig.embeddedWalletAuth
|
|
594
570
|
});
|
|
595
571
|
};
|
|
@@ -7,7 +7,7 @@ import { WalletLoginError, WalletInitializationError } from '../../base/errors/i
|
|
|
7
7
|
|
|
8
8
|
class BaseEvmConnector extends BaseConnector {
|
|
9
9
|
async init(_) {}
|
|
10
|
-
async
|
|
10
|
+
async getIdentityToken() {
|
|
11
11
|
if (!this.provider || this.status !== CONNECTOR_STATUS.CONNECTED) throw WalletLoginError.notConnectedError();
|
|
12
12
|
if (!this.coreOptions) throw WalletInitializationError.invalidParams("Please initialize Web3Auth with valid options");
|
|
13
13
|
const accounts = await this.provider.request({
|
|
@@ -7,7 +7,7 @@ import { getSavedToken, checkIfTokenIsExpired, saveToken, clearToken } from '../
|
|
|
7
7
|
|
|
8
8
|
class BaseSolanaConnector extends BaseConnector {
|
|
9
9
|
async init(_) {}
|
|
10
|
-
async
|
|
10
|
+
async getIdentityToken() {
|
|
11
11
|
if (!this.provider || this.status !== CONNECTOR_STATUS.CONNECTED) throw WalletLoginError.notConnectedError();
|
|
12
12
|
if (!this.coreOptions) throw WalletInitializationError.invalidParams("Please initialize Web3Auth with a valid options");
|
|
13
13
|
const accounts = await this.provider.request({
|
|
@@ -53,12 +53,17 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
53
53
|
try {
|
|
54
54
|
if (options.autoConnect) {
|
|
55
55
|
this.rehydrated = true;
|
|
56
|
-
await this.connect({
|
|
56
|
+
const provider = await this.connect({
|
|
57
57
|
chainId: options.chainId
|
|
58
58
|
});
|
|
59
|
+
// the connect function could fail silently as well.
|
|
60
|
+
if (!provider) {
|
|
61
|
+
this.rehydrated = false;
|
|
62
|
+
throw WalletLoginError.connectionError("Failed to rehydrate.");
|
|
63
|
+
}
|
|
59
64
|
}
|
|
60
65
|
} catch (error) {
|
|
61
|
-
this.emit(CONNECTOR_EVENTS.
|
|
66
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
async connect({
|
|
@@ -97,8 +102,9 @@ class CoinbaseConnector extends BaseEvmConnector {
|
|
|
97
102
|
} catch (error) {
|
|
98
103
|
// ready again to be connected
|
|
99
104
|
this.status = CONNECTOR_STATUS.READY;
|
|
105
|
+
// only throw error if the connector is not rehydrated.
|
|
106
|
+
if (!this.rehydrated) this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
100
107
|
this.rehydrated = false;
|
|
101
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
102
108
|
if (error instanceof Web3AuthError) throw error;
|
|
103
109
|
throw WalletLoginError.connectionError("Failed to login with coinbase wallet", error);
|
|
104
110
|
}
|
|
@@ -42,12 +42,16 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
42
42
|
log.debug(`initializing ${this.name} injected connector`);
|
|
43
43
|
if (options.autoConnect) {
|
|
44
44
|
this.rehydrated = true;
|
|
45
|
-
await this.connect({
|
|
45
|
+
const provider = await this.connect({
|
|
46
46
|
chainId: options.chainId
|
|
47
47
|
});
|
|
48
|
+
if (!provider) {
|
|
49
|
+
this.rehydrated = false;
|
|
50
|
+
throw WalletLoginError.connectionError("Failed to rehydrate.");
|
|
51
|
+
}
|
|
48
52
|
}
|
|
49
53
|
} catch (error) {
|
|
50
|
-
this.emit(CONNECTOR_EVENTS.
|
|
54
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
async connect({
|
|
@@ -92,8 +96,8 @@ class InjectedEvmConnector extends BaseEvmConnector {
|
|
|
92
96
|
} catch (error) {
|
|
93
97
|
// ready again to be connected
|
|
94
98
|
this.status = CONNECTOR_STATUS.READY;
|
|
99
|
+
if (!this.rehydrated) this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
95
100
|
this.rehydrated = false;
|
|
96
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
97
101
|
if (error instanceof Web3AuthError) throw error;
|
|
98
102
|
throw WalletLoginError.connectionError(`Failed to login with ${this.name} injected wallet`);
|
|
99
103
|
}
|
|
@@ -56,13 +56,16 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
56
56
|
log.debug("initializing solana injected connector");
|
|
57
57
|
if (options.autoConnect) {
|
|
58
58
|
this.rehydrated = true;
|
|
59
|
-
await this.connect({
|
|
59
|
+
const provider = await this.connect({
|
|
60
60
|
chainId: options.chainId
|
|
61
61
|
});
|
|
62
|
+
if (!provider) {
|
|
63
|
+
this.rehydrated = false;
|
|
64
|
+
throw WalletLoginError.connectionError("Failed to rehydrate.");
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
} catch (error) {
|
|
64
|
-
|
|
65
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
68
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
71
|
async connect({
|
|
@@ -92,8 +95,8 @@ class WalletStandardConnector extends BaseSolanaConnector {
|
|
|
92
95
|
} catch (error) {
|
|
93
96
|
// ready again to be connected
|
|
94
97
|
this.status = CONNECTOR_STATUS.READY;
|
|
98
|
+
if (!this.rehydrated) this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
95
99
|
this.rehydrated = false;
|
|
96
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
97
100
|
throw error;
|
|
98
101
|
}
|
|
99
102
|
}
|
|
@@ -69,12 +69,16 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
69
69
|
try {
|
|
70
70
|
if (options.autoConnect) {
|
|
71
71
|
this.rehydrated = true;
|
|
72
|
-
await this.connect({
|
|
72
|
+
const provider = await this.connect({
|
|
73
73
|
chainId: options.chainId
|
|
74
74
|
});
|
|
75
|
+
if (!provider) {
|
|
76
|
+
this.rehydrated = false;
|
|
77
|
+
throw WalletLoginError.connectionError("Failed to rehydrate.");
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
} catch (error) {
|
|
77
|
-
this.emit(CONNECTOR_EVENTS.
|
|
81
|
+
this.emit(CONNECTOR_EVENTS.REHYDRATION_ERROR, error);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
84
|
async connect({
|
|
@@ -130,8 +134,8 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
130
134
|
} catch (error) {
|
|
131
135
|
// ready again to be connected
|
|
132
136
|
this.status = CONNECTOR_STATUS.READY;
|
|
137
|
+
if (!this.rehydrated) this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
133
138
|
this.rehydrated = false;
|
|
134
|
-
this.emit(CONNECTOR_EVENTS.ERRORED, error);
|
|
135
139
|
if (error instanceof Web3AuthError) throw error;
|
|
136
140
|
throw WalletLoginError.connectionError("Failed to login with MetaMask wallet", error);
|
|
137
141
|
}
|
|
@@ -169,7 +173,7 @@ class MetaMaskConnector extends BaseEvmConnector {
|
|
|
169
173
|
} catch (error) {
|
|
170
174
|
// If the error code is 4902, the network needs to be added
|
|
171
175
|
if ((error === null || error === void 0 ? void 0 : error.code) === 4902) {
|
|
172
|
-
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && x.chainNamespace
|
|
176
|
+
const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && [CHAIN_NAMESPACES.EIP155, CHAIN_NAMESPACES.SOLANA].includes(x.chainNamespace));
|
|
173
177
|
await this.addChain(chainConfig);
|
|
174
178
|
await requestSwitchChain();
|
|
175
179
|
} else {
|