@web3auth/modal 7.3.0 → 8.0.0-alpha.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.
@@ -1,5 +1,5 @@
1
- import { IProvider, WALLET_ADAPTER_TYPE } from "@web3auth/base";
2
- import { Web3AuthNoModal, Web3AuthNoModalOptions } from "@web3auth/no-modal";
1
+ import { IProvider, WALLET_ADAPTER_TYPE, Web3AuthNoModalOptions } from "@web3auth/base";
2
+ import { Web3AuthNoModal } from "@web3auth/no-modal";
3
3
  import { LoginModal, UIConfig } from "@web3auth/ui";
4
4
  import { IWeb3AuthModal, ModalConfig } from "./interface";
5
5
  export interface Web3AuthOptions extends Web3AuthNoModalOptions {
package/package.json CHANGED
@@ -4,27 +4,19 @@
4
4
  "url": "https://github.com/Web3Auth/Web3Auth/issues"
5
5
  },
6
6
  "dependencies": {
7
- "@web3auth/base": "^7.2.1",
8
- "@web3auth/base-provider": "^7.2.1",
9
- "@web3auth/ethereum-provider": "^7.2.1",
10
- "@web3auth/metamask-adapter": "^7.2.1",
11
- "@web3auth/no-modal": "^7.2.1",
12
- "@web3auth/openlogin-adapter": "^7.2.1",
13
- "@web3auth/phantom-adapter": "^7.2.1",
14
- "@web3auth/solana-provider": "^7.2.1",
15
- "@web3auth/torus-evm-adapter": "^7.2.1",
16
- "@web3auth/torus-solana-adapter": "^7.2.1",
17
- "@web3auth/ui": "^7.2.1",
18
- "@web3auth/wallet-connect-v2-adapter": "^7.2.1"
7
+ "@web3auth/base": "^8.0.0-alpha.0",
8
+ "@web3auth/base-provider": "^8.0.0-alpha.0",
9
+ "@web3auth/no-modal": "^8.0.0-alpha.0",
10
+ "@web3auth/ui": "^8.0.0-alpha.0"
19
11
  },
20
12
  "devDependencies": {
21
13
  "@svgr/webpack": "^8.1.0",
22
14
  "@toruslabs/isomorphic-style-loader": "^5.3.3",
23
- "@toruslabs/openlogin-utils": "^6.1.0",
24
- "css-loader": "^6.8.1",
15
+ "@toruslabs/openlogin-utils": "^6.2.5",
16
+ "css-loader": "^6.9.1",
25
17
  "postcss-prefix-selector": "^1.16.0",
26
- "style-loader": "^3.3.3",
27
- "tailwindcss": "^3.4.0",
18
+ "style-loader": "^3.3.4",
19
+ "tailwindcss": "^3.4.1",
28
20
  "url-loader": "^4.1.1"
29
21
  },
30
22
  "engines": {
@@ -49,8 +41,7 @@
49
41
  "module": "dist/modal.esm.js",
50
42
  "name": "@web3auth/modal",
51
43
  "peerDependencies": {
52
- "@babel/runtime": "7.x",
53
- "@solana/web3.js": "^1.x"
44
+ "@babel/runtime": "7.x"
54
45
  },
55
46
  "publishConfig": {
56
47
  "access": "public"
@@ -70,6 +61,6 @@
70
61
  },
71
62
  "types": "dist/types/index.d.ts",
72
63
  "unpkg": "dist/modal.umd.min.js",
73
- "version": "7.3.0",
74
- "gitHead": "13816a41cfc89de9c9628fe174cf49c221c1cfda"
64
+ "version": "8.0.0-alpha.0",
65
+ "gitHead": "ef1bb1e8518e7c242f5371ea872341eaad755361"
75
66
  }
@@ -11,11 +11,14 @@ import {
11
11
  LoginMethodConfig,
12
12
  WALLET_ADAPTER_TYPE,
13
13
  WALLET_ADAPTERS,
14
+ WalletInitializationError,
15
+ Web3AuthNoModalOptions,
14
16
  } from "@web3auth/base";
15
17
  import { CommonJRPCProvider } from "@web3auth/base-provider";
16
- import { Web3AuthNoModal, Web3AuthNoModalOptions } from "@web3auth/no-modal";
18
+ import { Web3AuthNoModal } from "@web3auth/no-modal";
17
19
  import type { OpenloginAdapter } from "@web3auth/openlogin-adapter";
18
20
  import { getAdapterSocialLogins, getUserLanguage, LOGIN_MODAL_EVENTS, LoginModal, OPENLOGIN_PROVIDERS, UIConfig } from "@web3auth/ui";
21
+ import type { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
19
22
 
20
23
  import {
21
24
  defaultEvmDappModalConfig,
@@ -24,7 +27,6 @@ import {
24
27
  defaultSolanaDappModalConfig,
25
28
  defaultSolanaWalletModalConfig,
26
29
  } from "./config";
27
- import { getDefaultAdapterModule, getPrivateKeyProvider } from "./default";
28
30
  import { AdaptersModalConfig, IWeb3AuthModal, ModalConfig } from "./interface";
29
31
 
30
32
  export interface Web3AuthOptions extends Web3AuthNoModalOptions {
@@ -91,7 +93,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
91
93
  super.checkInitRequirements();
92
94
  await this.loginModal.initModal();
93
95
  const providedChainConfig = this.options.chainConfig;
94
-
96
+ // TODO: get stuff from dashboard here
95
97
  // merge default adapters with the custom configured adapters.
96
98
  const allAdapters = [...new Set([...Object.keys(this.modalConfig.adapters || {}), ...Object.keys(this.walletAdapters)])];
97
99
 
@@ -117,18 +119,8 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
117
119
  // if adapter is not custom configured then check if it is available in default adapters.
118
120
  // and if adapter is not hidden by user
119
121
  if (!adapter && this.modalConfig.adapters?.[adapterName].showOnModal) {
120
- // if adapter is not configured and some default configuration is available, use it.
121
- const ad = await getDefaultAdapterModule({
122
- name: adapterName,
123
- customChainConfig: this.options.chainConfig,
124
- clientId: this.options.clientId,
125
- sessionTime: this.options.sessionTime,
126
- web3AuthNetwork: this.options.web3AuthNetwork,
127
- uiConfig: this.options.uiConfig,
128
- });
129
-
130
- this.walletAdapters[adapterName] = ad;
131
- return adapterName;
122
+ // Adapters to be shown on modal should be pre-configured.
123
+ throw WalletInitializationError.invalidParams(`Adapter ${adapterName} is not configured`);
132
124
  } else if (adapter?.type === ADAPTER_CATEGORY.IN_APP || adapter?.type === ADAPTER_CATEGORY.EXTERNAL || adapterName === this.cachedAdapter) {
133
125
  if (!this.modalConfig.adapters?.[adapterName].showOnModal) return;
134
126
  // add client id to adapter, same web3auth client id can be used in adapter.
@@ -137,6 +129,7 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
137
129
  clientId: this.options.clientId,
138
130
  sessionTime: this.options.sessionTime,
139
131
  web3AuthNetwork: this.options.web3AuthNetwork,
132
+ useCoreKitKey: this.coreOptions.useCoreKitKey,
140
133
  });
141
134
 
142
135
  // if adapter doesn't have any chainConfig then we will set the chainConfig based of passed chainNamespace
@@ -151,10 +144,28 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
151
144
 
152
145
  if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
153
146
  const openloginAdapter = this.walletAdapters[adapterName] as OpenloginAdapter;
147
+ if (this.coreOptions.privateKeyProvider) {
148
+ if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
149
+ throw WalletInitializationError.incompatibleChainNameSpace(
150
+ "private key provider is not compatible with provided chainNamespace for openlogin adapter"
151
+ );
152
+ }
153
+ openloginAdapter.setAdapterSettings({ privateKeyProvider: this.coreOptions.privateKeyProvider });
154
+ }
155
+ openloginAdapter.setAdapterSettings({ whiteLabel: this.options.uiConfig });
154
156
  if (!openloginAdapter.privateKeyProvider) {
155
- const currentPrivateKeyProvider = await getPrivateKeyProvider(openloginAdapter.chainConfigProxy as CustomChainConfig);
156
- openloginAdapter.setAdapterSettings({ privateKeyProvider: currentPrivateKeyProvider, whiteLabel: this.options.uiConfig });
157
+ throw WalletInitializationError.invalidParams("privateKeyProvider is required for openlogin adapter");
157
158
  }
159
+ } else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
160
+ const walletConnectAdapter = this.walletAdapters[adapterName] as WalletConnectV2Adapter;
161
+ walletConnectAdapter.setAdapterSettings({
162
+ adapterSettings: {
163
+ walletConnectInitOptions: {
164
+ // Using a default wallet connect project id for web3auth modal integration
165
+ projectId: "d3c63f19f9582f8ba48e982057eb096b", // TODO: get from dashboard
166
+ },
167
+ },
168
+ });
158
169
  }
159
170
 
160
171
  return adapterName;
@@ -1,12 +0,0 @@
1
- import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
2
- import { CustomChainConfig, IAdapter, IBaseProvider, WALLET_ADAPTER_TYPE } from "@web3auth/base";
3
- import { UIConfig } from "@web3auth/ui";
4
- export declare function getPrivateKeyProvider(chainConfig: CustomChainConfig): Promise<IBaseProvider<string>>;
5
- export declare const getDefaultAdapterModule: (params: {
6
- name: WALLET_ADAPTER_TYPE;
7
- clientId: string;
8
- customChainConfig: Partial<CustomChainConfig> & Pick<CustomChainConfig, "chainNamespace">;
9
- sessionTime?: number;
10
- web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE;
11
- uiConfig?: Omit<UIConfig, "adapterListener">;
12
- }) => Promise<IAdapter<unknown>>;
package/src/default.ts DELETED
@@ -1,86 +0,0 @@
1
- import type { OPENLOGIN_NETWORK_TYPE, OpenLoginOptions } from "@toruslabs/openlogin-utils";
2
- import { CHAIN_NAMESPACES, CustomChainConfig, getChainConfig, IAdapter, IBaseProvider, WALLET_ADAPTER_TYPE, WALLET_ADAPTERS } from "@web3auth/base";
3
- import { CommonPrivateKeyProvider } from "@web3auth/base-provider";
4
- import { UIConfig } from "@web3auth/ui";
5
-
6
- export async function getPrivateKeyProvider(chainConfig: CustomChainConfig): Promise<IBaseProvider<string>> {
7
- if (chainConfig.chainNamespace === CHAIN_NAMESPACES.SOLANA) {
8
- const { SolanaPrivateKeyProvider } = await import("@web3auth/solana-provider");
9
- return new SolanaPrivateKeyProvider({ config: { chainConfig } });
10
- } else if (chainConfig.chainNamespace === CHAIN_NAMESPACES.EIP155) {
11
- const { EthereumPrivateKeyProvider } = await import("@web3auth/ethereum-provider");
12
- return new EthereumPrivateKeyProvider({ config: { chainConfig } });
13
- } else if (chainConfig.chainNamespace === CHAIN_NAMESPACES.OTHER) {
14
- // Modal doesn't support ripple provider
15
- // Can always override this with a custom provider
16
- return new CommonPrivateKeyProvider({ config: { chainConfig } });
17
- }
18
- throw new Error(`Invalid chainNamespace: ${chainConfig.chainNamespace} found while connecting to wallet`);
19
- }
20
-
21
- // warning: this function is not compatible with "OTHER" chain namespace.
22
- export const getDefaultAdapterModule = async (params: {
23
- name: WALLET_ADAPTER_TYPE;
24
- clientId: string;
25
- customChainConfig: Partial<CustomChainConfig> & Pick<CustomChainConfig, "chainNamespace">;
26
- sessionTime?: number;
27
- web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE;
28
- uiConfig?: Omit<UIConfig, "adapterListener">;
29
- }): Promise<IAdapter<unknown>> => {
30
- const { name, customChainConfig, clientId, sessionTime, web3AuthNetwork, uiConfig } = params;
31
- if (!Object.values(CHAIN_NAMESPACES).includes(customChainConfig.chainNamespace))
32
- throw new Error(`Invalid chainNamespace: ${customChainConfig.chainNamespace}`);
33
- const finalChainConfig = {
34
- ...(getChainConfig(customChainConfig.chainNamespace, customChainConfig?.chainId) as CustomChainConfig),
35
- ...(customChainConfig || {}),
36
- };
37
- if (name === WALLET_ADAPTERS.TORUS_EVM) {
38
- const { TorusWalletAdapter } = await import("@web3auth/torus-evm-adapter");
39
- const adapter = new TorusWalletAdapter({ chainConfig: finalChainConfig, clientId, sessionTime, web3AuthNetwork });
40
- return adapter;
41
- } else if (name === WALLET_ADAPTERS.TORUS_SOLANA) {
42
- const { SolanaWalletAdapter } = await import("@web3auth/torus-solana-adapter");
43
- const adapter = new SolanaWalletAdapter({ chainConfig: finalChainConfig, clientId, sessionTime, web3AuthNetwork });
44
- return adapter;
45
- } else if (name === WALLET_ADAPTERS.METAMASK) {
46
- const { MetamaskAdapter } = await import("@web3auth/metamask-adapter");
47
- const adapter = new MetamaskAdapter({ chainConfig: finalChainConfig, clientId, sessionTime, web3AuthNetwork });
48
- return adapter;
49
- } else if (name === WALLET_ADAPTERS.PHANTOM) {
50
- const { PhantomAdapter } = await import("@web3auth/phantom-adapter");
51
- const adapter = new PhantomAdapter({ chainConfig: finalChainConfig, clientId, sessionTime, web3AuthNetwork });
52
- return adapter;
53
- } else if (name === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
54
- const { WalletConnectV2Adapter } = await import("@web3auth/wallet-connect-v2-adapter");
55
- const adapter = new WalletConnectV2Adapter({
56
- chainConfig: finalChainConfig,
57
- clientId,
58
- sessionTime,
59
- web3AuthNetwork,
60
- adapterSettings: {
61
- walletConnectInitOptions: {
62
- // Using a default wallet connect project id for web3auth modal integration
63
- projectId: "d3c63f19f9582f8ba48e982057eb096b",
64
- },
65
- },
66
- });
67
- return adapter;
68
- } else if (name === WALLET_ADAPTERS.OPENLOGIN) {
69
- const { OpenloginAdapter, getOpenloginDefaultOptions } = await import("@web3auth/openlogin-adapter");
70
-
71
- const privateKeyProvider: IBaseProvider<string> = await getPrivateKeyProvider(finalChainConfig);
72
-
73
- const defaultOptions = getOpenloginDefaultOptions();
74
- const adapter = new OpenloginAdapter({
75
- ...defaultOptions,
76
- clientId,
77
- chainConfig: { ...finalChainConfig },
78
- adapterSettings: { ...(defaultOptions.adapterSettings as OpenLoginOptions), clientId, network: web3AuthNetwork, whiteLabel: uiConfig },
79
- sessionTime,
80
- web3AuthNetwork,
81
- privateKeyProvider,
82
- });
83
- return adapter;
84
- }
85
- throw new Error("Invalid wallet adapter name");
86
- };