@web3auth/no-modal 5.2.0 → 6.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/noModal.cjs.js +32 -11
- package/dist/noModal.cjs.js.map +1 -1
- package/dist/noModal.esm.js +29 -10
- package/dist/noModal.esm.js.map +1 -1
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +15 -0
- package/dist/noModal.umd.min.js.map +1 -1
- package/dist/types/noModal.d.ts +4 -1
- package/package.json +12 -6
- package/src/noModal.ts +32 -11
package/dist/types/noModal.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin";
|
|
2
1
|
import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
|
|
2
|
+
import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
|
|
3
3
|
import { ADAPTER_STATUS_TYPE, CustomChainConfig, IAdapter, IWeb3Auth, SafeEventEmitterProvider, UserAuthInfo, UserInfo, WALLET_ADAPTER_TYPE } from "@web3auth/base";
|
|
4
4
|
import { IPlugin } from "@web3auth/base-plugin";
|
|
5
|
+
import { CommonJRPCProvider } from "@web3auth/base-provider";
|
|
5
6
|
export interface Web3AuthNoModalOptions {
|
|
6
7
|
/**
|
|
7
8
|
* Client id for web3auth.
|
|
@@ -51,9 +52,11 @@ export declare class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Au
|
|
|
51
52
|
status: ADAPTER_STATUS_TYPE;
|
|
52
53
|
cachedAdapter: string | null;
|
|
53
54
|
protected walletAdapters: Record<string, IAdapter<unknown>>;
|
|
55
|
+
protected commonJRPCProvider: CommonJRPCProvider | null;
|
|
54
56
|
private plugins;
|
|
55
57
|
private storage;
|
|
56
58
|
constructor(options: Web3AuthNoModalOptions);
|
|
59
|
+
get connected(): boolean;
|
|
57
60
|
get provider(): SafeEventEmitterProvider | null;
|
|
58
61
|
set provider(_: SafeEventEmitterProvider | null);
|
|
59
62
|
init(): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@web3auth/no-modal",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Multi chain wallet aggregator for web3Auth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web3Auth/no-modal",
|
|
@@ -35,10 +35,12 @@
|
|
|
35
35
|
"@babel/runtime": "^7.x"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@toruslabs/openlogin": "^
|
|
39
|
-
"@toruslabs/openlogin-jrpc": "^
|
|
40
|
-
"@
|
|
41
|
-
"@web3auth/base
|
|
38
|
+
"@toruslabs/openlogin": "^4.5.4",
|
|
39
|
+
"@toruslabs/openlogin-jrpc": "^4.5.1",
|
|
40
|
+
"@toruslabs/openlogin-utils": "^4.5.1",
|
|
41
|
+
"@web3auth/base": "^6.0.0",
|
|
42
|
+
"@web3auth/base-plugin": "^6.0.0",
|
|
43
|
+
"@web3auth/base-provider": "^6.0.0"
|
|
42
44
|
},
|
|
43
45
|
"lint-staged": {
|
|
44
46
|
"!(*d).ts": [
|
|
@@ -56,5 +58,9 @@
|
|
|
56
58
|
"bugs": {
|
|
57
59
|
"url": "https://github.com/Web3Auth/Web3Auth/issues"
|
|
58
60
|
},
|
|
59
|
-
"
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=16.18.1",
|
|
63
|
+
"npm": ">=8.x"
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "e6f82b462c440e19d6faeffff3229bc9d1805598"
|
|
60
66
|
}
|
package/src/noModal.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin";
|
|
2
1
|
import { SafeEventEmitter } from "@toruslabs/openlogin-jrpc";
|
|
2
|
+
import type { OPENLOGIN_NETWORK_TYPE } from "@toruslabs/openlogin-utils";
|
|
3
3
|
import {
|
|
4
4
|
ADAPTER_EVENTS,
|
|
5
5
|
ADAPTER_NAMESPACES,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
Web3AuthError,
|
|
24
24
|
} from "@web3auth/base";
|
|
25
25
|
import { IPlugin, PLUGIN_NAMESPACES } from "@web3auth/base-plugin";
|
|
26
|
+
import { CommonJRPCProvider } from "@web3auth/base-provider";
|
|
26
27
|
|
|
27
28
|
export interface Web3AuthNoModalOptions {
|
|
28
29
|
/**
|
|
@@ -83,6 +84,8 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
83
84
|
|
|
84
85
|
protected walletAdapters: Record<string, IAdapter<unknown>> = {};
|
|
85
86
|
|
|
87
|
+
protected commonJRPCProvider: CommonJRPCProvider | null = null;
|
|
88
|
+
|
|
86
89
|
private plugins: Record<string, IPlugin> = {};
|
|
87
90
|
|
|
88
91
|
private storage: "sessionStorage" | "localStorage" = "localStorage";
|
|
@@ -91,7 +94,7 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
91
94
|
super();
|
|
92
95
|
if (!options.clientId) throw WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
93
96
|
if (options.enableLogging) log.enableAll();
|
|
94
|
-
else log.
|
|
97
|
+
else log.setLevel("error");
|
|
95
98
|
if (!options.chainConfig?.chainNamespace || !Object.values(CHAIN_NAMESPACES).includes(options.chainConfig?.chainNamespace))
|
|
96
99
|
throw WalletInitializationError.invalidParams("Please provide a valid chainNamespace in chainConfig");
|
|
97
100
|
if (options.storageKey === "session") this.storage = "sessionStorage";
|
|
@@ -107,10 +110,13 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
107
110
|
this.subscribeToAdapterEvents = this.subscribeToAdapterEvents.bind(this);
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
get connected(): boolean {
|
|
114
|
+
return Boolean(this.connectedAdapterName);
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
get provider(): SafeEventEmitterProvider | null {
|
|
111
|
-
if (this.status
|
|
112
|
-
|
|
113
|
-
return adapter.provider;
|
|
118
|
+
if (this.status !== ADAPTER_STATUS.NOT_READY && this.commonJRPCProvider) {
|
|
119
|
+
return this.commonJRPCProvider.provider;
|
|
114
120
|
}
|
|
115
121
|
return null;
|
|
116
122
|
}
|
|
@@ -120,6 +126,7 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
public async init(): Promise<void> {
|
|
129
|
+
this.commonJRPCProvider = await CommonJRPCProvider.getProviderInstance({ chainConfig: this.coreOptions.chainConfig as CustomChainConfig });
|
|
123
130
|
const initPromises = Object.keys(this.walletAdapters).map((adapterName) => {
|
|
124
131
|
this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
|
|
125
132
|
// if adapter doesn't have any chain config yet thn set it based on provided namespace and chainId.
|
|
@@ -193,13 +200,23 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
193
200
|
}
|
|
194
201
|
|
|
195
202
|
public async addChain(chainConfig: CustomChainConfig): Promise<void> {
|
|
196
|
-
if (this.status
|
|
197
|
-
|
|
203
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName)
|
|
204
|
+
return this.walletAdapters[this.connectedAdapterName].addChain(chainConfig);
|
|
205
|
+
|
|
206
|
+
if (this.commonJRPCProvider) {
|
|
207
|
+
return this.commonJRPCProvider.addChain(chainConfig);
|
|
208
|
+
}
|
|
209
|
+
throw WalletInitializationError.notReady(`No wallet is ready`);
|
|
198
210
|
}
|
|
199
211
|
|
|
200
212
|
public async switchChain(params: { chainId: string }): Promise<void> {
|
|
201
|
-
if (this.status
|
|
202
|
-
|
|
213
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName)
|
|
214
|
+
return this.walletAdapters[this.connectedAdapterName].switchChain(params);
|
|
215
|
+
|
|
216
|
+
if (this.commonJRPCProvider) {
|
|
217
|
+
return this.commonJRPCProvider.switchChain(params);
|
|
218
|
+
}
|
|
219
|
+
throw WalletInitializationError.notReady(`No wallet is connected`);
|
|
203
220
|
}
|
|
204
221
|
|
|
205
222
|
/**
|
|
@@ -207,10 +224,11 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
207
224
|
* @param walletName - Key of the walletAdapter to use.
|
|
208
225
|
*/
|
|
209
226
|
async connectTo<T>(walletName: WALLET_ADAPTER_TYPE, loginParams?: T): Promise<SafeEventEmitterProvider | null> {
|
|
210
|
-
if (!this.walletAdapters[walletName])
|
|
227
|
+
if (!this.walletAdapters[walletName] || !this.commonJRPCProvider)
|
|
211
228
|
throw WalletInitializationError.notFound(`Please add wallet adapter for ${walletName} wallet, before connecting`);
|
|
212
229
|
const provider = await this.walletAdapters[walletName].connect(loginParams);
|
|
213
|
-
|
|
230
|
+
this.commonJRPCProvider.updateProviderEngineProxy(provider as SafeEventEmitterProvider);
|
|
231
|
+
return this.provider;
|
|
214
232
|
}
|
|
215
233
|
|
|
216
234
|
async logout(options: { cleanup: boolean } = { cleanup: false }): Promise<void> {
|
|
@@ -242,6 +260,9 @@ export class Web3AuthNoModal extends SafeEventEmitter implements IWeb3Auth {
|
|
|
242
260
|
|
|
243
261
|
protected subscribeToAdapterEvents(walletAdapter: IAdapter<unknown>): void {
|
|
244
262
|
walletAdapter.on(ADAPTER_EVENTS.CONNECTED, async (data: CONNECTED_EVENT_DATA) => {
|
|
263
|
+
if (!this.commonJRPCProvider) throw WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
264
|
+
const { provider } = this.walletAdapters[data.adapter];
|
|
265
|
+
this.commonJRPCProvider.updateProviderEngineProxy(provider as SafeEventEmitterProvider);
|
|
245
266
|
this.status = ADAPTER_STATUS.CONNECTED;
|
|
246
267
|
this.connectedAdapterName = data.adapter;
|
|
247
268
|
this.cacheWallet(data.adapter);
|