@web3auth/no-modal 8.12.3 → 9.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.
- package/LICENSE +2 -2
- package/dist/lib.cjs/index.js +7 -0
- package/dist/lib.cjs/noModal.js +343 -0
- package/dist/lib.esm/index.js +1 -0
- package/dist/lib.esm/noModal.js +341 -0
- package/dist/noModal.cjs.js +16 -14
- package/dist/noModal.esm.js +13 -8
- package/dist/noModal.umd.min.js +1 -1
- package/dist/noModal.umd.min.js.LICENSE.txt +0 -2
- package/dist/types/noModal.d.ts +3 -3
- package/package.json +11 -13
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
+
import { SafeEventEmitter } from '@web3auth/auth';
|
|
4
|
+
import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, cloneDeep, ADAPTER_EVENTS, ADAPTER_NAMESPACES, WalletLoginError, PLUGIN_NAMESPACES, PLUGIN_STATUS } from '@web3auth/base';
|
|
5
|
+
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
6
|
+
import { LOGIN_PROVIDER } from '@web3auth/openlogin-adapter';
|
|
7
|
+
import deepmerge from 'deepmerge';
|
|
8
|
+
|
|
9
|
+
const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
|
|
10
|
+
class Web3AuthNoModal extends SafeEventEmitter {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
var _options$chainConfig, _options$chainConfig2, _options$chainConfig3, _options$chainConfig4;
|
|
13
|
+
super();
|
|
14
|
+
_defineProperty(this, "coreOptions", void 0);
|
|
15
|
+
_defineProperty(this, "connectedAdapterName", null);
|
|
16
|
+
_defineProperty(this, "status", ADAPTER_STATUS.NOT_READY);
|
|
17
|
+
_defineProperty(this, "cachedAdapter", null);
|
|
18
|
+
_defineProperty(this, "walletAdapters", {});
|
|
19
|
+
_defineProperty(this, "commonJRPCProvider", null);
|
|
20
|
+
_defineProperty(this, "plugins", {});
|
|
21
|
+
_defineProperty(this, "storage", "localStorage");
|
|
22
|
+
if (!options.clientId) throw WalletInitializationError.invalidParams("Please provide a valid clientId in constructor");
|
|
23
|
+
if (options.enableLogging) log.enableAll();else log.setLevel("error");
|
|
24
|
+
if (!options.privateKeyProvider && !options.chainConfig) {
|
|
25
|
+
throw WalletInitializationError.invalidParams("Please provide chainConfig or privateKeyProvider");
|
|
26
|
+
}
|
|
27
|
+
options.chainConfig = options.chainConfig || options.privateKeyProvider.currentChainConfig;
|
|
28
|
+
if (!((_options$chainConfig = options.chainConfig) !== null && _options$chainConfig !== void 0 && _options$chainConfig.chainNamespace) || !Object.values(CHAIN_NAMESPACES).includes((_options$chainConfig2 = options.chainConfig) === null || _options$chainConfig2 === void 0 ? void 0 : _options$chainConfig2.chainNamespace)) throw WalletInitializationError.invalidParams("Please provide a valid chainNamespace in chainConfig");
|
|
29
|
+
if (options.storageKey === "session") this.storage = "sessionStorage";
|
|
30
|
+
this.cachedAdapter = storageAvailable(this.storage) ? window[this.storage].getItem(ADAPTER_CACHE_KEY) : null;
|
|
31
|
+
this.coreOptions = _objectSpread(_objectSpread({}, options), {}, {
|
|
32
|
+
chainConfig: _objectSpread(_objectSpread({}, getChainConfig((_options$chainConfig3 = options.chainConfig) === null || _options$chainConfig3 === void 0 ? void 0 : _options$chainConfig3.chainNamespace, (_options$chainConfig4 = options.chainConfig) === null || _options$chainConfig4 === void 0 ? void 0 : _options$chainConfig4.chainId) || {}), options.chainConfig)
|
|
33
|
+
});
|
|
34
|
+
this.subscribeToAdapterEvents = this.subscribeToAdapterEvents.bind(this);
|
|
35
|
+
}
|
|
36
|
+
get connected() {
|
|
37
|
+
return Boolean(this.connectedAdapterName);
|
|
38
|
+
}
|
|
39
|
+
get provider() {
|
|
40
|
+
if (this.status !== ADAPTER_STATUS.NOT_READY && this.commonJRPCProvider) {
|
|
41
|
+
return this.commonJRPCProvider;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
set provider(_) {
|
|
46
|
+
throw new Error("Not implemented");
|
|
47
|
+
}
|
|
48
|
+
async init() {
|
|
49
|
+
this.commonJRPCProvider = await CommonJRPCProvider.getProviderInstance({
|
|
50
|
+
chainConfig: this.coreOptions.chainConfig
|
|
51
|
+
});
|
|
52
|
+
let projectConfig;
|
|
53
|
+
try {
|
|
54
|
+
projectConfig = await fetchProjectConfig(this.coreOptions.clientId, this.coreOptions.web3AuthNetwork);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
log.error("Failed to fetch project configurations", e);
|
|
57
|
+
throw WalletInitializationError.notReady("failed to fetch project configurations", e);
|
|
58
|
+
}
|
|
59
|
+
const initPromises = Object.keys(this.walletAdapters).map(async adapterName => {
|
|
60
|
+
this.subscribeToAdapterEvents(this.walletAdapters[adapterName]);
|
|
61
|
+
// if adapter doesn't have any chain config yet then set it based on provided namespace and chainId.
|
|
62
|
+
// if no chainNamespace or chainId is being provided, it will connect with mainnet.
|
|
63
|
+
if (!this.walletAdapters[adapterName].chainConfigProxy) {
|
|
64
|
+
const providedChainConfig = this.coreOptions.chainConfig;
|
|
65
|
+
if (!providedChainConfig.chainNamespace) throw WalletInitializationError.invalidParams("Please provide chainNamespace in chainConfig");
|
|
66
|
+
this.walletAdapters[adapterName].setAdapterSettings({
|
|
67
|
+
chainConfig: providedChainConfig,
|
|
68
|
+
sessionTime: this.coreOptions.sessionTime,
|
|
69
|
+
clientId: this.coreOptions.clientId,
|
|
70
|
+
web3AuthNetwork: this.coreOptions.web3AuthNetwork,
|
|
71
|
+
useCoreKitKey: this.coreOptions.useCoreKitKey
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
this.walletAdapters[adapterName].setAdapterSettings({
|
|
75
|
+
sessionTime: this.coreOptions.sessionTime,
|
|
76
|
+
clientId: this.coreOptions.clientId,
|
|
77
|
+
web3AuthNetwork: this.coreOptions.web3AuthNetwork,
|
|
78
|
+
useCoreKitKey: this.coreOptions.useCoreKitKey
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (adapterName === WALLET_ADAPTERS.OPENLOGIN) {
|
|
82
|
+
const openloginAdapter = this.walletAdapters[adapterName];
|
|
83
|
+
const {
|
|
84
|
+
whitelabel
|
|
85
|
+
} = projectConfig;
|
|
86
|
+
this.coreOptions.uiConfig = deepmerge(cloneDeep(whitelabel), this.coreOptions.uiConfig);
|
|
87
|
+
if (!this.coreOptions.uiConfig.mode) this.coreOptions.uiConfig.mode = "light";
|
|
88
|
+
const {
|
|
89
|
+
sms_otp_enabled: smsOtpEnabled,
|
|
90
|
+
whitelist,
|
|
91
|
+
key_export_enabled: keyExportEnabled
|
|
92
|
+
} = projectConfig;
|
|
93
|
+
if (smsOtpEnabled !== undefined) {
|
|
94
|
+
openloginAdapter.setAdapterSettings({
|
|
95
|
+
loginConfig: {
|
|
96
|
+
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
97
|
+
showOnModal: smsOtpEnabled,
|
|
98
|
+
showOnDesktop: smsOtpEnabled,
|
|
99
|
+
showOnMobile: smsOtpEnabled,
|
|
100
|
+
showOnSocialBackupFactor: smsOtpEnabled
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (whitelist) {
|
|
106
|
+
openloginAdapter.setAdapterSettings({
|
|
107
|
+
originData: whitelist.signed_urls
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (typeof keyExportEnabled === "boolean") {
|
|
111
|
+
this.coreOptions.privateKeyProvider.setKeyExportFlag(keyExportEnabled);
|
|
112
|
+
// dont know if this is required or not.
|
|
113
|
+
this.commonJRPCProvider.setKeyExportFlag(keyExportEnabled);
|
|
114
|
+
}
|
|
115
|
+
if (this.coreOptions.privateKeyProvider) {
|
|
116
|
+
if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
117
|
+
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
|
|
118
|
+
}
|
|
119
|
+
openloginAdapter.setAdapterSettings({
|
|
120
|
+
privateKeyProvider: this.coreOptions.privateKeyProvider
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
openloginAdapter.setAdapterSettings({
|
|
124
|
+
whiteLabel: this.coreOptions.uiConfig
|
|
125
|
+
});
|
|
126
|
+
if (!openloginAdapter.privateKeyProvider) {
|
|
127
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required for openlogin adapter");
|
|
128
|
+
}
|
|
129
|
+
} else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
|
|
130
|
+
const walletConnectAdapter = this.walletAdapters[adapterName];
|
|
131
|
+
const {
|
|
132
|
+
wallet_connect_enabled: walletConnectEnabled,
|
|
133
|
+
wallet_connect_project_id: walletConnectProjectId
|
|
134
|
+
} = projectConfig;
|
|
135
|
+
if (walletConnectEnabled === false) {
|
|
136
|
+
throw WalletInitializationError.invalidParams("Please enable wallet connect v2 addon on dashboard");
|
|
137
|
+
}
|
|
138
|
+
if (!walletConnectProjectId) throw WalletInitializationError.invalidParams("Invalid wallet connect project id. Please configure it on the dashboard");
|
|
139
|
+
walletConnectAdapter.setAdapterSettings({
|
|
140
|
+
adapterSettings: {
|
|
141
|
+
walletConnectInitOptions: {
|
|
142
|
+
projectId: walletConnectProjectId
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return this.walletAdapters[adapterName].init({
|
|
148
|
+
autoConnect: this.cachedAdapter === adapterName
|
|
149
|
+
}).catch(e => log.error(e, adapterName));
|
|
150
|
+
});
|
|
151
|
+
await Promise.all(initPromises);
|
|
152
|
+
if (this.status === ADAPTER_STATUS.NOT_READY) {
|
|
153
|
+
this.status = ADAPTER_STATUS.READY;
|
|
154
|
+
this.emit(ADAPTER_EVENTS.READY);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
getAdapter(adapterName) {
|
|
158
|
+
return this.walletAdapters[adapterName] || null;
|
|
159
|
+
}
|
|
160
|
+
configureAdapter(adapter) {
|
|
161
|
+
this.checkInitRequirements();
|
|
162
|
+
const providedChainConfig = this.coreOptions.chainConfig;
|
|
163
|
+
if (!providedChainConfig.chainNamespace) throw WalletInitializationError.invalidParams("Please provide chainNamespace in chainConfig");
|
|
164
|
+
const adapterAlreadyExists = this.walletAdapters[adapter.name];
|
|
165
|
+
if (adapterAlreadyExists) throw WalletInitializationError.duplicateAdapterError(`Wallet adapter for ${adapter.name} already exists`);
|
|
166
|
+
if (adapter.adapterNamespace !== ADAPTER_NAMESPACES.MULTICHAIN && adapter.adapterNamespace !== providedChainConfig.chainNamespace) throw WalletInitializationError.incompatibleChainNameSpace(`This wallet adapter belongs to ${adapter.adapterNamespace} which is incompatible with currently used namespace: ${providedChainConfig.chainNamespace}`);
|
|
167
|
+
if (adapter.adapterNamespace === ADAPTER_NAMESPACES.MULTICHAIN && adapter.currentChainNamespace && providedChainConfig.chainNamespace !== adapter.currentChainNamespace) {
|
|
168
|
+
// chainConfig checks are already validated in constructor so using typecast is safe here.
|
|
169
|
+
adapter.setAdapterSettings({
|
|
170
|
+
chainConfig: providedChainConfig
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
this.walletAdapters[adapter.name] = adapter;
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
clearCache() {
|
|
177
|
+
if (!storageAvailable(this.storage)) return;
|
|
178
|
+
window[this.storage].removeItem(ADAPTER_CACHE_KEY);
|
|
179
|
+
this.cachedAdapter = null;
|
|
180
|
+
}
|
|
181
|
+
async addChain(chainConfig) {
|
|
182
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName) return this.walletAdapters[this.connectedAdapterName].addChain(chainConfig);
|
|
183
|
+
if (this.commonJRPCProvider) {
|
|
184
|
+
return this.commonJRPCProvider.addChain(chainConfig);
|
|
185
|
+
}
|
|
186
|
+
throw WalletInitializationError.notReady(`No wallet is ready`);
|
|
187
|
+
}
|
|
188
|
+
async switchChain(params) {
|
|
189
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName) return this.walletAdapters[this.connectedAdapterName].switchChain(params);
|
|
190
|
+
if (this.commonJRPCProvider) {
|
|
191
|
+
return this.commonJRPCProvider.switchChain(params);
|
|
192
|
+
}
|
|
193
|
+
throw WalletInitializationError.notReady(`No wallet is ready`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Connect to a specific wallet adapter
|
|
198
|
+
* @param walletName - Key of the walletAdapter to use.
|
|
199
|
+
*/
|
|
200
|
+
async connectTo(walletName, loginParams) {
|
|
201
|
+
if (!this.walletAdapters[walletName] || !this.commonJRPCProvider) throw WalletInitializationError.notFound(`Please add wallet adapter for ${walletName} wallet, before connecting`);
|
|
202
|
+
const provider = await this.walletAdapters[walletName].connect(loginParams);
|
|
203
|
+
this.commonJRPCProvider.updateProviderEngineProxy(provider.provider || provider);
|
|
204
|
+
return this.provider;
|
|
205
|
+
}
|
|
206
|
+
async logout(options = {
|
|
207
|
+
cleanup: false
|
|
208
|
+
}) {
|
|
209
|
+
if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
210
|
+
await this.walletAdapters[this.connectedAdapterName].disconnect(options);
|
|
211
|
+
}
|
|
212
|
+
async getUserInfo() {
|
|
213
|
+
log.debug("Getting user info", this.status, this.connectedAdapterName);
|
|
214
|
+
if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
215
|
+
return this.walletAdapters[this.connectedAdapterName].getUserInfo();
|
|
216
|
+
}
|
|
217
|
+
async enableMFA(loginParams) {
|
|
218
|
+
if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
219
|
+
if (this.connectedAdapterName !== WALLET_ADAPTERS.OPENLOGIN) throw WalletLoginError.unsupportedOperation(`EnableMFA is not supported for this adapter.`);
|
|
220
|
+
return this.walletAdapters[this.connectedAdapterName].enableMFA(loginParams);
|
|
221
|
+
}
|
|
222
|
+
async authenticateUser() {
|
|
223
|
+
if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
224
|
+
return this.walletAdapters[this.connectedAdapterName].authenticateUser();
|
|
225
|
+
}
|
|
226
|
+
addPlugin(plugin) {
|
|
227
|
+
if (this.plugins[plugin.name]) throw WalletInitializationError.duplicateAdapterError(`Plugin ${plugin.name} already exist`);
|
|
228
|
+
if (plugin.pluginNamespace !== PLUGIN_NAMESPACES.MULTICHAIN && plugin.pluginNamespace !== this.coreOptions.chainConfig.chainNamespace) throw WalletInitializationError.incompatibleChainNameSpace(`This plugin belongs to ${plugin.pluginNamespace} namespace which is incompatible with currently used namespace: ${this.coreOptions.chainConfig.chainNamespace}`);
|
|
229
|
+
this.plugins[plugin.name] = plugin;
|
|
230
|
+
if (this.status === ADAPTER_STATUS.CONNECTED && this.connectedAdapterName) {
|
|
231
|
+
// web3auth is already connected. can initialize plugins
|
|
232
|
+
this.connectToPlugins({
|
|
233
|
+
adapter: this.connectedAdapterName
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return this;
|
|
237
|
+
}
|
|
238
|
+
getPlugin(name) {
|
|
239
|
+
return this.plugins[name] || null;
|
|
240
|
+
}
|
|
241
|
+
subscribeToAdapterEvents(walletAdapter) {
|
|
242
|
+
walletAdapter.on(ADAPTER_EVENTS.CONNECTED, async data => {
|
|
243
|
+
if (!this.commonJRPCProvider) throw WalletInitializationError.notFound(`CommonJrpcProvider not found`);
|
|
244
|
+
const {
|
|
245
|
+
provider
|
|
246
|
+
} = data;
|
|
247
|
+
this.commonJRPCProvider.updateProviderEngineProxy(provider.provider || provider);
|
|
248
|
+
this.status = ADAPTER_STATUS.CONNECTED;
|
|
249
|
+
this.connectedAdapterName = data.adapter;
|
|
250
|
+
this.cacheWallet(data.adapter);
|
|
251
|
+
log.debug("connected", this.status, this.connectedAdapterName);
|
|
252
|
+
this.connectToPlugins(data);
|
|
253
|
+
this.emit(ADAPTER_EVENTS.CONNECTED, _objectSpread({}, data));
|
|
254
|
+
});
|
|
255
|
+
walletAdapter.on(ADAPTER_EVENTS.DISCONNECTED, async () => {
|
|
256
|
+
// get back to ready state for rehydrating.
|
|
257
|
+
this.status = ADAPTER_STATUS.READY;
|
|
258
|
+
if (storageAvailable(this.storage)) {
|
|
259
|
+
const cachedAdapter = window[this.storage].getItem(ADAPTER_CACHE_KEY);
|
|
260
|
+
if (this.connectedAdapterName === cachedAdapter) {
|
|
261
|
+
this.clearCache();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
log.debug("disconnected", this.status, this.connectedAdapterName);
|
|
265
|
+
await Promise.all(Object.values(this.plugins).map(plugin => {
|
|
266
|
+
return plugin.disconnect().catch(error => {
|
|
267
|
+
// swallow error if adapter doesn't supports this plugin.
|
|
268
|
+
if (error.code === 5211) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
// throw error;
|
|
272
|
+
log.error(error);
|
|
273
|
+
});
|
|
274
|
+
}));
|
|
275
|
+
this.connectedAdapterName = null;
|
|
276
|
+
this.emit(ADAPTER_EVENTS.DISCONNECTED);
|
|
277
|
+
});
|
|
278
|
+
walletAdapter.on(ADAPTER_EVENTS.CONNECTING, data => {
|
|
279
|
+
this.status = ADAPTER_STATUS.CONNECTING;
|
|
280
|
+
this.emit(ADAPTER_EVENTS.CONNECTING, data);
|
|
281
|
+
log.debug("connecting", this.status, this.connectedAdapterName);
|
|
282
|
+
});
|
|
283
|
+
walletAdapter.on(ADAPTER_EVENTS.ERRORED, data => {
|
|
284
|
+
this.status = ADAPTER_STATUS.ERRORED;
|
|
285
|
+
this.clearCache();
|
|
286
|
+
this.emit(ADAPTER_EVENTS.ERRORED, data);
|
|
287
|
+
log.debug("errored", this.status, this.connectedAdapterName);
|
|
288
|
+
});
|
|
289
|
+
walletAdapter.on(ADAPTER_EVENTS.ADAPTER_DATA_UPDATED, data => {
|
|
290
|
+
log.debug("adapter data updated", data);
|
|
291
|
+
this.emit(ADAPTER_EVENTS.ADAPTER_DATA_UPDATED, data);
|
|
292
|
+
});
|
|
293
|
+
walletAdapter.on(ADAPTER_EVENTS.CACHE_CLEAR, data => {
|
|
294
|
+
log.debug("adapter cache clear", data);
|
|
295
|
+
if (storageAvailable(this.storage)) {
|
|
296
|
+
this.clearCache();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
checkInitRequirements() {
|
|
301
|
+
if (this.status === ADAPTER_STATUS.CONNECTING) throw WalletInitializationError.notReady("Already pending connection");
|
|
302
|
+
if (this.status === ADAPTER_STATUS.CONNECTED) throw WalletInitializationError.notReady("Already connected");
|
|
303
|
+
if (this.status === ADAPTER_STATUS.READY) throw WalletInitializationError.notReady("Adapter is already initialized");
|
|
304
|
+
}
|
|
305
|
+
cacheWallet(walletName) {
|
|
306
|
+
if (!storageAvailable(this.storage)) return;
|
|
307
|
+
window[this.storage].setItem(ADAPTER_CACHE_KEY, walletName);
|
|
308
|
+
this.cachedAdapter = walletName;
|
|
309
|
+
}
|
|
310
|
+
connectToPlugins(data) {
|
|
311
|
+
Object.values(this.plugins).map(async plugin => {
|
|
312
|
+
try {
|
|
313
|
+
if (!plugin.SUPPORTED_ADAPTERS.includes(data.adapter)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (plugin.status === PLUGIN_STATUS.CONNECTED) return;
|
|
317
|
+
const {
|
|
318
|
+
openloginInstance
|
|
319
|
+
} = this.walletAdapters[this.connectedAdapterName];
|
|
320
|
+
const {
|
|
321
|
+
options,
|
|
322
|
+
sessionId,
|
|
323
|
+
sessionNamespace
|
|
324
|
+
} = openloginInstance || {};
|
|
325
|
+
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
326
|
+
await plugin.connect({
|
|
327
|
+
sessionId,
|
|
328
|
+
sessionNamespace
|
|
329
|
+
});
|
|
330
|
+
} catch (error) {
|
|
331
|
+
// swallow error if connector adapter doesn't supports this plugin.
|
|
332
|
+
if (error.code === 5211) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
log.error(error);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export { Web3AuthNoModal };
|
package/dist/noModal.cjs.js
CHANGED
|
@@ -60,20 +60,17 @@ var objectSpread2_default = /*#__PURE__*/__webpack_require__.n(objectSpread2_nam
|
|
|
60
60
|
;// CONCATENATED MODULE: external "@babel/runtime/helpers/defineProperty"
|
|
61
61
|
const defineProperty_namespaceObject = require("@babel/runtime/helpers/defineProperty");
|
|
62
62
|
var defineProperty_default = /*#__PURE__*/__webpack_require__.n(defineProperty_namespaceObject);
|
|
63
|
-
;// CONCATENATED MODULE: external "@
|
|
64
|
-
const
|
|
63
|
+
;// CONCATENATED MODULE: external "@web3auth/auth"
|
|
64
|
+
const auth_namespaceObject = require("@web3auth/auth");
|
|
65
65
|
;// CONCATENATED MODULE: external "@web3auth/base"
|
|
66
66
|
const base_namespaceObject = require("@web3auth/base");
|
|
67
67
|
;// CONCATENATED MODULE: external "@web3auth/base-provider"
|
|
68
68
|
const base_provider_namespaceObject = require("@web3auth/base-provider");
|
|
69
69
|
;// CONCATENATED MODULE: external "@web3auth/openlogin-adapter"
|
|
70
70
|
const openlogin_adapter_namespaceObject = require("@web3auth/openlogin-adapter");
|
|
71
|
-
;// CONCATENATED MODULE: external "
|
|
72
|
-
const
|
|
73
|
-
var
|
|
74
|
-
;// CONCATENATED MODULE: external "lodash.merge"
|
|
75
|
-
const external_lodash_merge_namespaceObject = require("lodash.merge");
|
|
76
|
-
var external_lodash_merge_default = /*#__PURE__*/__webpack_require__.n(external_lodash_merge_namespaceObject);
|
|
71
|
+
;// CONCATENATED MODULE: external "deepmerge"
|
|
72
|
+
const external_deepmerge_namespaceObject = require("deepmerge");
|
|
73
|
+
var external_deepmerge_default = /*#__PURE__*/__webpack_require__.n(external_deepmerge_namespaceObject);
|
|
77
74
|
;// CONCATENATED MODULE: ./src/noModal.ts
|
|
78
75
|
|
|
79
76
|
|
|
@@ -82,9 +79,8 @@ var external_lodash_merge_default = /*#__PURE__*/__webpack_require__.n(external_
|
|
|
82
79
|
|
|
83
80
|
|
|
84
81
|
|
|
85
|
-
|
|
86
82
|
const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
|
|
87
|
-
class Web3AuthNoModal extends
|
|
83
|
+
class Web3AuthNoModal extends auth_namespaceObject.SafeEventEmitter {
|
|
88
84
|
constructor(options) {
|
|
89
85
|
var _options$chainConfig, _options$chainConfig2, _options$chainConfig3, _options$chainConfig4;
|
|
90
86
|
super();
|
|
@@ -160,11 +156,12 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
160
156
|
const {
|
|
161
157
|
whitelabel
|
|
162
158
|
} = projectConfig;
|
|
163
|
-
this.coreOptions.uiConfig =
|
|
159
|
+
this.coreOptions.uiConfig = external_deepmerge_default()((0,base_namespaceObject.cloneDeep)(whitelabel), this.coreOptions.uiConfig);
|
|
164
160
|
if (!this.coreOptions.uiConfig.mode) this.coreOptions.uiConfig.mode = "light";
|
|
165
161
|
const {
|
|
166
162
|
sms_otp_enabled: smsOtpEnabled,
|
|
167
|
-
whitelist
|
|
163
|
+
whitelist,
|
|
164
|
+
key_export_enabled: keyExportEnabled
|
|
168
165
|
} = projectConfig;
|
|
169
166
|
if (smsOtpEnabled !== undefined) {
|
|
170
167
|
openloginAdapter.setAdapterSettings({
|
|
@@ -183,6 +180,11 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
183
180
|
originData: whitelist.signed_urls
|
|
184
181
|
});
|
|
185
182
|
}
|
|
183
|
+
if (typeof keyExportEnabled === "boolean") {
|
|
184
|
+
this.coreOptions.privateKeyProvider.setKeyExportFlag(keyExportEnabled);
|
|
185
|
+
// dont know if this is required or not.
|
|
186
|
+
this.commonJRPCProvider.setKeyExportFlag(keyExportEnabled);
|
|
187
|
+
}
|
|
186
188
|
if (this.coreOptions.privateKeyProvider) {
|
|
187
189
|
if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
188
190
|
throw base_namespaceObject.WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
|
|
@@ -323,7 +325,7 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
323
325
|
this.connectToPlugins(data);
|
|
324
326
|
this.emit(base_namespaceObject.ADAPTER_EVENTS.CONNECTED, objectSpread2_default()({}, data));
|
|
325
327
|
});
|
|
326
|
-
walletAdapter.on(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED, async
|
|
328
|
+
walletAdapter.on(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED, async () => {
|
|
327
329
|
// get back to ready state for rehydrating.
|
|
328
330
|
this.status = base_namespaceObject.ADAPTER_STATUS.READY;
|
|
329
331
|
if ((0,base_namespaceObject.storageAvailable)(this.storage)) {
|
|
@@ -344,7 +346,7 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
344
346
|
});
|
|
345
347
|
}));
|
|
346
348
|
this.connectedAdapterName = null;
|
|
347
|
-
this.emit(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED
|
|
349
|
+
this.emit(base_namespaceObject.ADAPTER_EVENTS.DISCONNECTED);
|
|
348
350
|
});
|
|
349
351
|
walletAdapter.on(base_namespaceObject.ADAPTER_EVENTS.CONNECTING, data => {
|
|
350
352
|
this.status = base_namespaceObject.ADAPTER_STATUS.CONNECTING;
|
package/dist/noModal.esm.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { SafeEventEmitter } from '@
|
|
4
|
-
import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, ADAPTER_EVENTS, ADAPTER_NAMESPACES, WalletLoginError, PLUGIN_NAMESPACES, PLUGIN_STATUS } from '@web3auth/base';
|
|
3
|
+
import { SafeEventEmitter } from '@web3auth/auth';
|
|
4
|
+
import { ADAPTER_STATUS, WalletInitializationError, log, CHAIN_NAMESPACES, storageAvailable, getChainConfig, fetchProjectConfig, WALLET_ADAPTERS, cloneDeep, ADAPTER_EVENTS, ADAPTER_NAMESPACES, WalletLoginError, PLUGIN_NAMESPACES, PLUGIN_STATUS } from '@web3auth/base';
|
|
5
5
|
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
6
6
|
import { LOGIN_PROVIDER } from '@web3auth/openlogin-adapter';
|
|
7
|
-
import
|
|
8
|
-
import merge from 'lodash.merge';
|
|
7
|
+
import deepmerge from 'deepmerge';
|
|
9
8
|
|
|
10
9
|
const ADAPTER_CACHE_KEY = "Web3Auth-cachedAdapter";
|
|
11
10
|
class Web3AuthNoModal extends SafeEventEmitter {
|
|
@@ -84,11 +83,12 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
84
83
|
const {
|
|
85
84
|
whitelabel
|
|
86
85
|
} = projectConfig;
|
|
87
|
-
this.coreOptions.uiConfig =
|
|
86
|
+
this.coreOptions.uiConfig = deepmerge(cloneDeep(whitelabel), this.coreOptions.uiConfig);
|
|
88
87
|
if (!this.coreOptions.uiConfig.mode) this.coreOptions.uiConfig.mode = "light";
|
|
89
88
|
const {
|
|
90
89
|
sms_otp_enabled: smsOtpEnabled,
|
|
91
|
-
whitelist
|
|
90
|
+
whitelist,
|
|
91
|
+
key_export_enabled: keyExportEnabled
|
|
92
92
|
} = projectConfig;
|
|
93
93
|
if (smsOtpEnabled !== undefined) {
|
|
94
94
|
openloginAdapter.setAdapterSettings({
|
|
@@ -107,6 +107,11 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
107
107
|
originData: whitelist.signed_urls
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
+
if (typeof keyExportEnabled === "boolean") {
|
|
111
|
+
this.coreOptions.privateKeyProvider.setKeyExportFlag(keyExportEnabled);
|
|
112
|
+
// dont know if this is required or not.
|
|
113
|
+
this.commonJRPCProvider.setKeyExportFlag(keyExportEnabled);
|
|
114
|
+
}
|
|
110
115
|
if (this.coreOptions.privateKeyProvider) {
|
|
111
116
|
if (openloginAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
112
117
|
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for openlogin adapter");
|
|
@@ -247,7 +252,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
247
252
|
this.connectToPlugins(data);
|
|
248
253
|
this.emit(ADAPTER_EVENTS.CONNECTED, _objectSpread({}, data));
|
|
249
254
|
});
|
|
250
|
-
walletAdapter.on(ADAPTER_EVENTS.DISCONNECTED, async
|
|
255
|
+
walletAdapter.on(ADAPTER_EVENTS.DISCONNECTED, async () => {
|
|
251
256
|
// get back to ready state for rehydrating.
|
|
252
257
|
this.status = ADAPTER_STATUS.READY;
|
|
253
258
|
if (storageAvailable(this.storage)) {
|
|
@@ -268,7 +273,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
268
273
|
});
|
|
269
274
|
}));
|
|
270
275
|
this.connectedAdapterName = null;
|
|
271
|
-
this.emit(ADAPTER_EVENTS.DISCONNECTED
|
|
276
|
+
this.emit(ADAPTER_EVENTS.DISCONNECTED);
|
|
272
277
|
});
|
|
273
278
|
walletAdapter.on(ADAPTER_EVENTS.CONNECTING, data => {
|
|
274
279
|
this.status = ADAPTER_STATUS.CONNECTING;
|