@web3auth/no-modal 7.2.1 → 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,57 +1,13 @@
1
1
  import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
2
- import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
3
- import { ADAPTER_STATUS_TYPE, CustomChainConfig, IAdapter, IProvider, IWeb3Auth, UserAuthInfo, UserInfo, WALLET_ADAPTER_TYPE } from "@web3auth/base";
2
+ import { ADAPTER_STATUS_TYPE, CustomChainConfig, IAdapter, IProvider, IWeb3Auth, UserAuthInfo, UserInfo, WALLET_ADAPTER_TYPE, Web3AuthNoModalOptions } from "@web3auth/base";
4
3
  import { IPlugin } from "@web3auth/base-plugin";
5
4
  import { CommonJRPCProvider } from "@web3auth/base-provider";
6
- export interface Web3AuthNoModalOptions {
7
- /**
8
- * Client id for web3auth.
9
- * You can obtain your client id from the web3auth developer dashboard.
10
- * You can set any random string for this on localhost.
11
- */
12
- clientId: string;
13
- /**
14
- * custom chain configuration for chainNamespace
15
- *
16
- * @defaultValue mainnet config of provided chainNamespace
17
- */
18
- chainConfig: Partial<CustomChainConfig> & Pick<CustomChainConfig, "chainNamespace">;
19
- /**
20
- * setting to true will enable logs
21
- *
22
- * @defaultValue false
23
- */
24
- enableLogging?: boolean;
25
- /**
26
- * setting to "local" will persist social login session accross browser tabs.
27
- *
28
- * @defaultValue "local"
29
- */
30
- storageKey?: "session" | "local";
31
- /**
32
- * sessionTime (in seconds) for idToken issued by Web3Auth for server side verification.
33
- * @defaultValue 86400
34
- *
35
- * Note: max value can be 7 days (86400 * 7) and min can be 1 day (86400)
36
- */
37
- sessionTime?: number;
38
- /**
39
- * Web3Auth Network to use for the session & the issued idToken
40
- * @defaultValue mainnet
41
- */
42
- web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE;
43
- /**
44
- * Uses core-kit key with web3auth provider
45
- * @defaultValue false
46
- */
47
- useCoreKitKey?: boolean;
48
- }
49
5
  export declare class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
50
6
  readonly coreOptions: Web3AuthNoModalOptions;
51
7
  connectedAdapterName: WALLET_ADAPTER_TYPE | null;
52
8
  status: ADAPTER_STATUS_TYPE;
53
9
  cachedAdapter: string | null;
54
- protected walletAdapters: Record<string, IAdapter<unknown>>;
10
+ walletAdapters: Record<string, IAdapter<unknown>>;
55
11
  protected commonJRPCProvider: CommonJRPCProvider | null;
56
12
  private plugins;
57
13
  private storage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@web3auth/no-modal",
3
- "version": "7.2.1",
3
+ "version": "8.0.0-alpha.0",
4
4
  "description": "Multi chain wallet aggregator for web3Auth",
5
5
  "keywords": [
6
6
  "web3Auth/no-modal",
@@ -32,15 +32,29 @@
32
32
  "src"
33
33
  ],
34
34
  "peerDependencies": {
35
- "@babel/runtime": "^7.x"
35
+ "@babel/runtime": "^7.x",
36
+ "@web3auth/openlogin-adapter": "^7.x",
37
+ "@web3auth/wallet-connect-v2-adapter": "^7.x"
36
38
  },
37
39
  "dependencies": {
38
- "@toruslabs/openlogin": "^6.1.0",
39
- "@toruslabs/openlogin-jrpc": "^6.1.0",
40
- "@toruslabs/openlogin-utils": "^6.1.0",
41
- "@web3auth/base": "^7.2.1",
42
- "@web3auth/base-plugin": "^7.2.1",
43
- "@web3auth/base-provider": "^7.2.1"
40
+ "@toruslabs/openlogin": "^6.2.5",
41
+ "@toruslabs/openlogin-jrpc": "^6.2.8",
42
+ "@toruslabs/openlogin-utils": "^6.2.5",
43
+ "@web3auth/base": "^8.0.0-alpha.0",
44
+ "@web3auth/base-plugin": "^8.0.0-alpha.0",
45
+ "@web3auth/base-provider": "^8.0.0-alpha.0"
46
+ },
47
+ "devDependencies": {
48
+ "@web3auth/openlogin-adapter": "^8.0.0-alpha.0",
49
+ "@web3auth/wallet-connect-v2-adapter": "^8.0.0-alpha.0"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "@web3auth/openlogin-adapter": {
53
+ "optional": true
54
+ },
55
+ "@web3auth/wallet-connect-v2-adapter": {
56
+ "optional": true
57
+ }
44
58
  },
45
59
  "lint-staged": {
46
60
  "!(*d).ts": [
@@ -62,5 +76,5 @@
62
76
  "node": ">=18.x",
63
77
  "npm": ">=9.x"
64
78
  },
65
- "gitHead": "fd62ba4aeb83a4bf4c9b0fcd3f942db742d5751f"
79
+ "gitHead": "ef1bb1e8518e7c242f5371ea872341eaad755361"
66
80
  }
package/src/noModal.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
2
- import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
3
2
  import {
4
3
  ADAPTER_EVENTS,
5
4
  ADAPTER_NAMESPACES,
@@ -18,59 +17,16 @@ import {
18
17
  UserAuthInfo,
19
18
  UserInfo,
20
19
  WALLET_ADAPTER_TYPE,
20
+ WALLET_ADAPTERS,
21
21
  WalletInitializationError,
22
22
  WalletLoginError,
23
23
  Web3AuthError,
24
+ Web3AuthNoModalOptions,
24
25
  } from "@web3auth/base";
25
26
  import { IPlugin, PLUGIN_NAMESPACES } from "@web3auth/base-plugin";
26
27
  import { CommonJRPCProvider } from "@web3auth/base-provider";
27
-
28
- export interface Web3AuthNoModalOptions {
29
- /**
30
- * Client id for web3auth.
31
- * You can obtain your client id from the web3auth developer dashboard.
32
- * You can set any random string for this on localhost.
33
- */
34
- clientId: string;
35
- /**
36
- * custom chain configuration for chainNamespace
37
- *
38
- * @defaultValue mainnet config of provided chainNamespace
39
- */
40
- chainConfig: Partial<CustomChainConfig> & Pick<CustomChainConfig, "chainNamespace">;
41
-
42
- /**
43
- * setting to true will enable logs
44
- *
45
- * @defaultValue false
46
- */
47
- enableLogging?: boolean;
48
- /**
49
- * setting to "local" will persist social login session accross browser tabs.
50
- *
51
- * @defaultValue "local"
52
- */
53
- storageKey?: "session" | "local";
54
-
55
- /**
56
- * sessionTime (in seconds) for idToken issued by Web3Auth for server side verification.
57
- * @defaultValue 86400
58
- *
59
- * Note: max value can be 7 days (86400 * 7) and min can be 1 day (86400)
60
- */
61
- sessionTime?: number;
62
- /**
63
- * Web3Auth Network to use for the session & the issued idToken
64
- * @defaultValue mainnet
65
- */
66
- web3AuthNetwork?: OPENLOGIN_NETWORK_TYPE;
67
-
68
- /**
69
- * Uses core-kit key with web3auth provider
70
- * @defaultValue false
71
- */
72
- useCoreKitKey?: boolean;
73
- }
28
+ import type { OpenloginAdapter } from "@web3auth/openlogin-adapter";
29
+ import type { WalletConnectV2Adapter } from "@web3auth/wallet-connect-v2-adapter";
74
30
 
75
31
  const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
76
32
  export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
@@ -82,7 +38,7 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
82
38
 
83
39
  public cachedAdapter: string | null = null;
84
40
 
85
- protected walletAdapters: Record<string, IAdapter<unknown>> = {};
41
+ public walletAdapters: Record<string, IAdapter<unknown>> = {};
86
42
 
87
43
  protected commonJRPCProvider: CommonJRPCProvider | null = null;
88
44
 
@@ -127,9 +83,11 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
127
83
 
128
84
  public async init(): Promise<void> {
129
85
  this.commonJRPCProvider = await CommonJRPCProvider.getProviderInstance({ chainConfig: this.coreOptions.chainConfig as CustomChainConfig });
86
+ // TODO: get stuff from dashboard here
87
+ // disable sms login
130
88
  const initPromises = Object.keys(this.walletAdapters).map((adapterName) => {
131
89
  this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
132
- // if adapter doesn't have any chain config yet thn set it based on provided namespace and chainId.
90
+ // if adapter doesn't have any chain config yet then set it based on provided namespace and chainId.
133
91
  // if no chainNamespace or chainId is being provided, it will connect with mainnet.
134
92
  if (!this.walletAdapters[adapterName].chainConfigProxy) {
135
93
  const providedChainConfig = this.coreOptions.chainConfig;
@@ -149,6 +107,31 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
149
107
  useCoreKitKey: this.coreOptions.useCoreKitKey,
150
108
  });
151
109
  }
110
+ if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
111
+ const openloginAdapter = this.walletAdapters[adapterName] as OpenloginAdapter;
112
+ if (this.coreOptions.privateKeyProvider) {
113
+ if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
114
+ throw WalletInitializationError.incompatibleChainNameSpace(
115
+ "private key provider is not compatible with provided chainNamespace for openlogin adapter"
116
+ );
117
+ }
118
+ openloginAdapter.setAdapterSettings({ privateKeyProvider: this.coreOptions.privateKeyProvider });
119
+ }
120
+ openloginAdapter.setAdapterSettings({ whiteLabel: this.coreOptions.uiConfig });
121
+ if (!openloginAdapter.privateKeyProvider) {
122
+ throw WalletInitializationError.invalidParams("privateKeyProvider is required for openlogin adapter");
123
+ }
124
+ } else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
125
+ const walletConnectAdapter = this.walletAdapters[adapterName] as WalletConnectV2Adapter;
126
+ walletConnectAdapter.setAdapterSettings({
127
+ adapterSettings: {
128
+ walletConnectInitOptions: {
129
+ // Using a default wallet connect project id for web3auth modal integration
130
+ projectId: "d3c63f19f9582f8ba48e982057eb096b", // TODO: get from dashboard
131
+ },
132
+ },
133
+ });
134
+ }
152
135
 
153
136
  return this.walletAdapters[adapterName].init({ autoConnect: this.cachedAdapter === adapterName }).catch((e) => log.error(e));
154
137
  });