@web3auth/no-modal 8.12.4 → 9.0.0-alpha.1
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/README.md +1 -1
- 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 +32 -30
- package/dist/noModal.esm.js +27 -22
- 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 +13 -15
|
@@ -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 { LOGIN_PROVIDER } from '@web3auth/auth-adapter';
|
|
5
|
+
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';
|
|
6
|
+
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
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.AUTH) {
|
|
82
|
+
const authAdapter = 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
|
+
authAdapter.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
|
+
authAdapter.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 (authAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
117
|
+
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for auth adapter");
|
|
118
|
+
}
|
|
119
|
+
authAdapter.setAdapterSettings({
|
|
120
|
+
privateKeyProvider: this.coreOptions.privateKeyProvider
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
authAdapter.setAdapterSettings({
|
|
124
|
+
whiteLabel: this.coreOptions.uiConfig
|
|
125
|
+
});
|
|
126
|
+
if (!authAdapter.privateKeyProvider) {
|
|
127
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required for auth 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.AUTH) 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
|
+
authInstance
|
|
319
|
+
} = this.walletAdapters[this.connectedAdapterName];
|
|
320
|
+
const {
|
|
321
|
+
options,
|
|
322
|
+
sessionId,
|
|
323
|
+
sessionNamespace
|
|
324
|
+
} = authInstance || {};
|
|
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
|
+
;// CONCATENATED MODULE: external "@web3auth/auth-adapter"
|
|
66
|
+
const auth_adapter_namespaceObject = require("@web3auth/auth-adapter");
|
|
65
67
|
;// CONCATENATED MODULE: external "@web3auth/base"
|
|
66
68
|
const base_namespaceObject = require("@web3auth/base");
|
|
67
69
|
;// CONCATENATED MODULE: external "@web3auth/base-provider"
|
|
68
70
|
const base_provider_namespaceObject = require("@web3auth/base-provider");
|
|
69
|
-
;// CONCATENATED MODULE: external "
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const external_lodash_clonedeep_namespaceObject = require("lodash.clonedeep");
|
|
73
|
-
var external_lodash_clonedeep_default = /*#__PURE__*/__webpack_require__.n(external_lodash_clonedeep_namespaceObject);
|
|
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();
|
|
@@ -155,21 +151,22 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
155
151
|
useCoreKitKey: this.coreOptions.useCoreKitKey
|
|
156
152
|
});
|
|
157
153
|
}
|
|
158
|
-
if (adapterName === base_namespaceObject.WALLET_ADAPTERS.
|
|
159
|
-
const
|
|
154
|
+
if (adapterName === base_namespaceObject.WALLET_ADAPTERS.AUTH) {
|
|
155
|
+
const authAdapter = this.walletAdapters[adapterName];
|
|
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
|
+
authAdapter.setAdapterSettings({
|
|
171
168
|
loginConfig: {
|
|
172
|
-
[
|
|
169
|
+
[auth_adapter_namespaceObject.LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
173
170
|
showOnModal: smsOtpEnabled,
|
|
174
171
|
showOnDesktop: smsOtpEnabled,
|
|
175
172
|
showOnMobile: smsOtpEnabled,
|
|
@@ -179,23 +176,28 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
179
176
|
});
|
|
180
177
|
}
|
|
181
178
|
if (whitelist) {
|
|
182
|
-
|
|
179
|
+
authAdapter.setAdapterSettings({
|
|
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
|
-
if (
|
|
188
|
-
throw base_namespaceObject.WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for
|
|
189
|
+
if (authAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
190
|
+
throw base_namespaceObject.WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for auth adapter");
|
|
189
191
|
}
|
|
190
|
-
|
|
192
|
+
authAdapter.setAdapterSettings({
|
|
191
193
|
privateKeyProvider: this.coreOptions.privateKeyProvider
|
|
192
194
|
});
|
|
193
195
|
}
|
|
194
|
-
|
|
196
|
+
authAdapter.setAdapterSettings({
|
|
195
197
|
whiteLabel: this.coreOptions.uiConfig
|
|
196
198
|
});
|
|
197
|
-
if (!
|
|
198
|
-
throw base_namespaceObject.WalletInitializationError.invalidParams("privateKeyProvider is required for
|
|
199
|
+
if (!authAdapter.privateKeyProvider) {
|
|
200
|
+
throw base_namespaceObject.WalletInitializationError.invalidParams("privateKeyProvider is required for auth adapter");
|
|
199
201
|
}
|
|
200
202
|
} else if (adapterName === base_namespaceObject.WALLET_ADAPTERS.WALLET_CONNECT_V2) {
|
|
201
203
|
const walletConnectAdapter = this.walletAdapters[adapterName];
|
|
@@ -287,7 +289,7 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
287
289
|
}
|
|
288
290
|
async enableMFA(loginParams) {
|
|
289
291
|
if (this.status !== base_namespaceObject.ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw base_namespaceObject.WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
290
|
-
if (this.connectedAdapterName !== base_namespaceObject.WALLET_ADAPTERS.
|
|
292
|
+
if (this.connectedAdapterName !== base_namespaceObject.WALLET_ADAPTERS.AUTH) throw base_namespaceObject.WalletLoginError.unsupportedOperation(`EnableMFA is not supported for this adapter.`);
|
|
291
293
|
return this.walletAdapters[this.connectedAdapterName].enableMFA(loginParams);
|
|
292
294
|
}
|
|
293
295
|
async authenticateUser() {
|
|
@@ -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;
|
|
@@ -386,13 +388,13 @@ class Web3AuthNoModal extends openlogin_jrpc_namespaceObject.SafeEventEmitter {
|
|
|
386
388
|
}
|
|
387
389
|
if (plugin.status === base_namespaceObject.PLUGIN_STATUS.CONNECTED) return;
|
|
388
390
|
const {
|
|
389
|
-
|
|
391
|
+
authInstance
|
|
390
392
|
} = this.walletAdapters[this.connectedAdapterName];
|
|
391
393
|
const {
|
|
392
394
|
options,
|
|
393
395
|
sessionId,
|
|
394
396
|
sessionNamespace
|
|
395
|
-
} =
|
|
397
|
+
} = authInstance || {};
|
|
396
398
|
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
397
399
|
await plugin.connect({
|
|
398
400
|
sessionId,
|
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 {
|
|
3
|
+
import { SafeEventEmitter } from '@web3auth/auth';
|
|
4
|
+
import { LOGIN_PROVIDER } from '@web3auth/auth-adapter';
|
|
5
|
+
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
6
|
import { CommonJRPCProvider } from '@web3auth/base-provider';
|
|
6
|
-
import
|
|
7
|
-
import clonedeep from 'lodash.clonedeep';
|
|
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 {
|
|
@@ -79,19 +78,20 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
79
78
|
useCoreKitKey: this.coreOptions.useCoreKitKey
|
|
80
79
|
});
|
|
81
80
|
}
|
|
82
|
-
if (adapterName === WALLET_ADAPTERS.
|
|
83
|
-
const
|
|
81
|
+
if (adapterName === WALLET_ADAPTERS.AUTH) {
|
|
82
|
+
const authAdapter = this.walletAdapters[adapterName];
|
|
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
|
+
authAdapter.setAdapterSettings({
|
|
95
95
|
loginConfig: {
|
|
96
96
|
[LOGIN_PROVIDER.SMS_PASSWORDLESS]: {
|
|
97
97
|
showOnModal: smsOtpEnabled,
|
|
@@ -103,23 +103,28 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
if (whitelist) {
|
|
106
|
-
|
|
106
|
+
authAdapter.setAdapterSettings({
|
|
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
|
-
if (
|
|
112
|
-
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for
|
|
116
|
+
if (authAdapter.currentChainNamespace !== this.coreOptions.privateKeyProvider.currentChainConfig.chainNamespace) {
|
|
117
|
+
throw WalletInitializationError.incompatibleChainNameSpace("private key provider is not compatible with provided chainNamespace for auth adapter");
|
|
113
118
|
}
|
|
114
|
-
|
|
119
|
+
authAdapter.setAdapterSettings({
|
|
115
120
|
privateKeyProvider: this.coreOptions.privateKeyProvider
|
|
116
121
|
});
|
|
117
122
|
}
|
|
118
|
-
|
|
123
|
+
authAdapter.setAdapterSettings({
|
|
119
124
|
whiteLabel: this.coreOptions.uiConfig
|
|
120
125
|
});
|
|
121
|
-
if (!
|
|
122
|
-
throw WalletInitializationError.invalidParams("privateKeyProvider is required for
|
|
126
|
+
if (!authAdapter.privateKeyProvider) {
|
|
127
|
+
throw WalletInitializationError.invalidParams("privateKeyProvider is required for auth adapter");
|
|
123
128
|
}
|
|
124
129
|
} else if (adapterName === WALLET_ADAPTERS.WALLET_CONNECT_V2) {
|
|
125
130
|
const walletConnectAdapter = this.walletAdapters[adapterName];
|
|
@@ -211,7 +216,7 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
211
216
|
}
|
|
212
217
|
async enableMFA(loginParams) {
|
|
213
218
|
if (this.status !== ADAPTER_STATUS.CONNECTED || !this.connectedAdapterName) throw WalletLoginError.notConnectedError(`No wallet is connected`);
|
|
214
|
-
if (this.connectedAdapterName !== WALLET_ADAPTERS.
|
|
219
|
+
if (this.connectedAdapterName !== WALLET_ADAPTERS.AUTH) throw WalletLoginError.unsupportedOperation(`EnableMFA is not supported for this adapter.`);
|
|
215
220
|
return this.walletAdapters[this.connectedAdapterName].enableMFA(loginParams);
|
|
216
221
|
}
|
|
217
222
|
async authenticateUser() {
|
|
@@ -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;
|
|
@@ -310,13 +315,13 @@ class Web3AuthNoModal extends SafeEventEmitter {
|
|
|
310
315
|
}
|
|
311
316
|
if (plugin.status === PLUGIN_STATUS.CONNECTED) return;
|
|
312
317
|
const {
|
|
313
|
-
|
|
318
|
+
authInstance
|
|
314
319
|
} = this.walletAdapters[this.connectedAdapterName];
|
|
315
320
|
const {
|
|
316
321
|
options,
|
|
317
322
|
sessionId,
|
|
318
323
|
sessionNamespace
|
|
319
|
-
} =
|
|
324
|
+
} = authInstance || {};
|
|
320
325
|
await plugin.initWithWeb3Auth(this, options.whiteLabel);
|
|
321
326
|
await plugin.connect({
|
|
322
327
|
sessionId,
|