@trezor/connect 9.3.1-beta.2 → 9.4.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/lib/core/index.js CHANGED
@@ -20,47 +20,26 @@ const debug_1 = require("../utils/debug");
20
20
  const BlockchainLink_1 = require("../backend/BlockchainLink");
21
21
  const interactionTimeout_1 = require("../utils/interactionTimeout");
22
22
  const onCallFirmwareUpdate_1 = require("./onCallFirmwareUpdate");
23
- let _core;
24
- let _deviceList;
25
- const _callMethods = [];
26
- let _interactionTimeout;
27
- let _deviceListInitReject;
28
- let _overridePromise;
29
- const methodSynchronize = (0, utils_2.getSynchronize)();
30
- let waitForFirstMethod = (0, utils_1.createDeferred)();
31
23
  const _log = (0, debug_1.initLog)('Core');
32
- const postMessage = (message) => {
33
- if (message.event === events_2.RESPONSE_EVENT) {
34
- const index = _callMethods.findIndex(call => call && call.responseID === message.id);
35
- if (index >= 0) {
36
- _callMethods.splice(index, 1);
37
- if (_callMethods.length === 0) {
38
- waitForFirstMethod = (0, utils_1.createDeferred)();
39
- }
40
- }
41
- }
42
- _core.emit(events_2.CORE_EVENT, message);
43
- };
44
- const popupPromise = (0, popupPromiseManager_1.createPopupPromiseManager)();
45
- const waitForPopup = () => {
46
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_UI_WINDOW));
24
+ const waitForPopup = ({ popupPromise, sendCoreMessage }) => {
25
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_UI_WINDOW));
47
26
  return popupPromise.wait();
48
27
  };
49
- const interactionTimeout = () => _interactionTimeout.start(() => {
50
- onPopupClosed('Interaction timeout');
28
+ const startInteractionTimeout = (context) => context.interactionTimeout.start(() => {
29
+ onPopupClosed(context, 'Interaction timeout');
51
30
  });
52
- const uiPromises = (0, uiPromiseManager_1.createUiPromiseManager)(interactionTimeout);
53
- const initDevice = async (devicePath) => {
54
- await _deviceList.pendingConnection();
55
- _deviceList.assertConnected();
56
- const isWebUsb = _deviceList.transportType() === 'WebUsbTransport';
31
+ const initDevice = async (context, devicePath) => {
32
+ const { uiPromises, deviceList, sendCoreMessage } = context;
33
+ await deviceList.pendingConnection();
34
+ (0, DeviceList_1.assertDeviceListConnected)(deviceList);
35
+ const isWebUsb = deviceList.transportType() === 'WebUsbTransport';
57
36
  let device;
58
37
  let showDeviceSelection = isWebUsb;
59
38
  const isUsingPopup = DataManager_1.DataManager.getSettings('popup');
60
39
  const origin = DataManager_1.DataManager.getSettings('origin');
61
40
  const useCoreInPopup = DataManager_1.DataManager.getSettings('useCoreInPopup');
62
41
  const { preferredDevice } = connect_common_1.storage.load().origin[origin] || {};
63
- const preferredDeviceInList = preferredDevice && _deviceList.getDevice(preferredDevice.path);
42
+ const preferredDeviceInList = preferredDevice && deviceList.getDevice(preferredDevice.path);
64
43
  if (preferredDevice && !preferredDeviceInList) {
65
44
  connect_common_1.storage.save(store => {
66
45
  store.origin[origin] = { ...store.origin[origin], preferredDevice: undefined };
@@ -68,14 +47,14 @@ const initDevice = async (devicePath) => {
68
47
  });
69
48
  }
70
49
  if (devicePath) {
71
- device = _deviceList.getDevice(devicePath);
50
+ device = deviceList.getDevice(devicePath);
72
51
  showDeviceSelection =
73
52
  !device || !!(device === null || device === void 0 ? void 0 : device.unreadableError) || (device.isUnacquired() && !!isUsingPopup);
74
53
  }
75
54
  else {
76
- const devices = _deviceList.asArray();
55
+ const devices = deviceList.asArray();
77
56
  if (devices.length === 1 && (!isWebUsb || !isUsingPopup)) {
78
- device = _deviceList.getDevice(devices[0].path);
57
+ device = deviceList.getDevice(devices[0].path);
79
58
  showDeviceSelection =
80
59
  !!(device === null || device === void 0 ? void 0 : device.unreadableError) || device.isUnacquired() || !!useCoreInPopup;
81
60
  }
@@ -85,20 +64,20 @@ const initDevice = async (devicePath) => {
85
64
  }
86
65
  if (showDeviceSelection) {
87
66
  uiPromises.create(events_2.UI.RECEIVE_DEVICE);
88
- await waitForPopup();
89
- _deviceList.assertConnected();
90
- const devices = _deviceList.asArray();
67
+ await waitForPopup(context);
68
+ (0, DeviceList_1.assertDeviceListConnected)(deviceList);
69
+ const devices = deviceList.asArray();
91
70
  if (devices.length === 1 &&
92
71
  devices[0].type !== 'unreadable' &&
93
72
  devices[0].features &&
94
73
  !isWebUsb &&
95
74
  !useCoreInPopup) {
96
- device = _deviceList.getDevice(devices[0].path);
75
+ device = deviceList.getDevice(devices[0].path);
97
76
  }
98
77
  else {
99
- postMessage((0, events_2.createUiMessage)(events_2.UI.SELECT_DEVICE, {
78
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.SELECT_DEVICE, {
100
79
  webusb: isWebUsb,
101
- devices: _deviceList.asArray(),
80
+ devices: deviceList.asArray(),
102
81
  }));
103
82
  if (uiPromises.exists(events_2.UI.RECEIVE_DEVICE)) {
104
83
  const { payload } = await uiPromises.get(events_2.UI.RECEIVE_DEVICE);
@@ -112,7 +91,7 @@ const initDevice = async (devicePath) => {
112
91
  return store;
113
92
  });
114
93
  }
115
- device = _deviceList.getDevice(payload.device.path);
94
+ device = deviceList.getDevice(payload.device.path);
116
95
  }
117
96
  }
118
97
  }
@@ -125,14 +104,14 @@ const initDevice = async (devicePath) => {
125
104
  return device;
126
105
  };
127
106
  const MAX_PIN_TRIES = 3;
128
- const getInvalidDeviceState = async (device, preauthorized) => {
107
+ const getInvalidDeviceState = async ({ sendCoreMessage }, device, preauthorized) => {
129
108
  for (let i = 0; i < MAX_PIN_TRIES - 1; ++i) {
130
109
  try {
131
110
  return await device.validateState(preauthorized);
132
111
  }
133
112
  catch (error) {
134
113
  if (error.message.includes('PIN invalid')) {
135
- postMessage((0, events_2.createUiMessage)(events_2.UI.INVALID_PIN, { device: device.toMessageObject() }));
114
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.INVALID_PIN, { device: device.toMessageObject() }));
136
115
  }
137
116
  else {
138
117
  throw error;
@@ -141,25 +120,26 @@ const getInvalidDeviceState = async (device, preauthorized) => {
141
120
  }
142
121
  return device.validateState(preauthorized);
143
122
  };
144
- const inner = async (method, device) => {
123
+ const inner = async (context, method, device) => {
145
124
  var _a;
125
+ const { uiPromises, sendCoreMessage } = context;
146
126
  const trustedHost = DataManager_1.DataManager.getSettings('trustedHost');
147
127
  const isUsingPopup = (_a = DataManager_1.DataManager.getSettings('popup')) !== null && _a !== void 0 ? _a : false;
148
128
  const firmwareException = method.checkFirmwareRange();
149
129
  if (firmwareException) {
150
130
  if (isUsingPopup) {
151
131
  if (firmwareException === events_2.UI.FIRMWARE_NOT_COMPATIBLE) {
152
- await waitForPopup();
132
+ await waitForPopup(context);
153
133
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_CONFIRMATION, device);
154
- postMessage((0, events_2.createUiMessage)(events_2.UI.FIRMWARE_NOT_COMPATIBLE, device.toMessageObject()));
134
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.FIRMWARE_NOT_COMPATIBLE, device.toMessageObject()));
155
135
  const uiResp = await uiPromise.promise;
156
136
  if (!uiResp.payload) {
157
137
  throw constants_1.ERRORS.TypedError('Method_PermissionsNotGranted');
158
138
  }
159
139
  }
160
140
  else {
161
- await waitForPopup();
162
- postMessage((0, events_2.createUiMessage)(firmwareException, device.toMessageObject()));
141
+ await waitForPopup(context);
142
+ sendCoreMessage((0, events_2.createUiMessage)(firmwareException, device.toMessageObject()));
163
143
  await uiPromises.create(events_2.DEVICE.DISCONNECT, device).promise;
164
144
  return Promise.reject(constants_1.ERRORS.TypedError('Method_Cancel'));
165
145
  }
@@ -172,8 +152,8 @@ const inner = async (method, device) => {
172
152
  if (unexpectedMode) {
173
153
  device.keepSession = false;
174
154
  if (isUsingPopup) {
175
- await waitForPopup();
176
- postMessage((0, events_2.createUiMessage)(unexpectedMode, device.toMessageObject()));
155
+ await waitForPopup(context);
156
+ sendCoreMessage((0, events_2.createUiMessage)(unexpectedMode, device.toMessageObject()));
177
157
  await uiPromises.create(events_2.DEVICE.DISCONNECT, device).promise;
178
158
  return Promise.reject(constants_1.ERRORS.TypedError('Device_ModeException', unexpectedMode));
179
159
  }
@@ -181,9 +161,9 @@ const inner = async (method, device) => {
181
161
  }
182
162
  method.checkPermissions();
183
163
  if (!trustedHost && method.requiredPermissions.length > 0) {
184
- await waitForPopup();
164
+ await waitForPopup(context);
185
165
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_PERMISSION, device);
186
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PERMISSION, {
166
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PERMISSION, {
187
167
  permissions: method.requiredPermissions,
188
168
  device: device.toMessageObject(),
189
169
  }));
@@ -199,9 +179,9 @@ const inner = async (method, device) => {
199
179
  if (deviceNeedsBackup) {
200
180
  if (method.noBackupConfirmationMode === 'always' ||
201
181
  (method.noBackupConfirmationMode === 'popup-only' && isUsingPopup)) {
202
- await waitForPopup();
182
+ await waitForPopup(context);
203
183
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_CONFIRMATION, device);
204
- postMessage((0, analyticsInfo_1.enhanceMessageWithAnalytics)((0, events_2.createUiMessage)(events_2.UI.REQUEST_CONFIRMATION, {
184
+ sendCoreMessage((0, analyticsInfo_1.enhanceMessageWithAnalytics)((0, events_2.createUiMessage)(events_2.UI.REQUEST_CONFIRMATION, {
205
185
  view: 'no-backup',
206
186
  }), { device: device.toMessageObject() }));
207
187
  const permitted = await uiPromise.promise.then(({ payload }) => payload);
@@ -209,19 +189,19 @@ const inner = async (method, device) => {
209
189
  return Promise.reject(constants_1.ERRORS.TypedError('Method_PermissionsNotGranted'));
210
190
  }
211
191
  }
212
- await waitForPopup();
213
- postMessage((0, events_2.createUiMessage)(events_2.UI.DEVICE_NEEDS_BACKUP, device.toMessageObject()));
192
+ await waitForPopup(context);
193
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.DEVICE_NEEDS_BACKUP, device.toMessageObject()));
214
194
  }
215
195
  if (device.firmwareStatus === 'outdated') {
216
- await waitForPopup();
217
- postMessage((0, events_2.createUiMessage)(events_2.UI.FIRMWARE_OUTDATED, device.toMessageObject()));
196
+ await waitForPopup(context);
197
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.FIRMWARE_OUTDATED, device.toMessageObject()));
218
198
  }
219
199
  if (!trustedHost) {
220
200
  const requestConfirmation = method.confirmation;
221
201
  if (requestConfirmation) {
222
- await waitForPopup();
202
+ await waitForPopup(context);
223
203
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_CONFIRMATION, device);
224
- postMessage((0, analyticsInfo_1.enhanceMessageWithAnalytics)((0, events_2.createUiMessage)(events_2.UI.REQUEST_CONFIRMATION, requestConfirmation), { device: device.toMessageObject() }));
204
+ sendCoreMessage((0, analyticsInfo_1.enhanceMessageWithAnalytics)((0, events_2.createUiMessage)(events_2.UI.REQUEST_CONFIRMATION, requestConfirmation), { device: device.toMessageObject() }));
225
205
  const confirmed = await uiPromise.promise.then(({ payload }) => payload);
226
206
  if (!confirmed) {
227
207
  return Promise.reject(constants_1.ERRORS.TypedError('Method_Cancel'));
@@ -231,18 +211,18 @@ const inner = async (method, device) => {
231
211
  const isDeviceUnlocked = device.features.unlocked;
232
212
  if (method.useDeviceState) {
233
213
  try {
234
- let invalidDeviceState = await getInvalidDeviceState(device, method.preauthorized);
214
+ let invalidDeviceState = await getInvalidDeviceState(context, device, method.preauthorized);
235
215
  if (isUsingPopup) {
236
216
  while (invalidDeviceState) {
237
217
  const uiPromise = uiPromises.create(events_2.UI.INVALID_PASSPHRASE_ACTION, device);
238
- postMessage((0, events_2.createUiMessage)(events_2.UI.INVALID_PASSPHRASE, {
218
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.INVALID_PASSPHRASE, {
239
219
  device: device.toMessageObject(),
240
220
  }));
241
221
  const uiResp = await uiPromise.promise;
242
222
  if (uiResp.payload) {
243
223
  device.setInternalState(undefined);
244
224
  await device.initialize(method.useCardanoDerivation);
245
- invalidDeviceState = await getInvalidDeviceState(device, method.preauthorized);
225
+ invalidDeviceState = await getInvalidDeviceState(context, device, method.preauthorized);
246
226
  }
247
227
  else {
248
228
  device.setExternalState(invalidDeviceState);
@@ -260,13 +240,13 @@ const inner = async (method, device) => {
260
240
  }
261
241
  }
262
242
  if (!isDeviceUnlocked && device.features.unlocked) {
263
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CHANGED, device.toMessageObject()));
243
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CHANGED, device.toMessageObject()));
264
244
  }
265
245
  if (method.useUi) {
266
- await waitForPopup();
246
+ await waitForPopup(context);
267
247
  }
268
248
  else {
269
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
249
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
270
250
  }
271
251
  try {
272
252
  const response = await method.run();
@@ -276,11 +256,12 @@ const inner = async (method, device) => {
276
256
  return Promise.reject(error);
277
257
  }
278
258
  };
279
- const onCall = async (message) => {
259
+ const onCall = async (context, message) => {
280
260
  var _a;
281
261
  if (!message.id || !message.payload || message.type !== events_2.IFRAME.CALL) {
282
262
  throw constants_1.ERRORS.TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing');
283
263
  }
264
+ const { uiPromises, deviceList, callMethods, methodSynchronize, resolveWaitForFirstMethod, getOverridePromise, setOverridePromise, sendCoreMessage, } = context;
284
265
  const responseID = message.id;
285
266
  const origin = DataManager_1.DataManager.getSettings('origin');
286
267
  const env = DataManager_1.DataManager.getSettings('env');
@@ -297,27 +278,27 @@ const onCall = async (message) => {
297
278
  _log.debug('loading method...');
298
279
  const method = await (0, method_1.getMethod)(message);
299
280
  _log.debug('method selected', method.name);
300
- method.postMessage = postMessage;
281
+ method.postMessage = sendCoreMessage;
301
282
  method.createUiPromise = uiPromises.create;
302
283
  method.init();
303
284
  await ((_a = method.initAsync) === null || _a === void 0 ? void 0 : _a.call(method));
304
285
  return method;
305
286
  });
306
- waitForFirstMethod.resolve();
307
- _callMethods.push(method);
287
+ resolveWaitForFirstMethod();
288
+ callMethods.push(method);
308
289
  }
309
290
  catch (error) {
310
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
311
- postMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
291
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
292
+ sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
312
293
  return Promise.resolve();
313
294
  }
314
295
  if (!method.useDevice) {
315
296
  try {
316
297
  if (method.useUi) {
317
- await waitForPopup();
298
+ await waitForPopup(context);
318
299
  }
319
300
  else {
320
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
301
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
321
302
  }
322
303
  const response = await method.run();
323
304
  messageResponse = (0, events_2.createResponseMessage)(method.responseID, true, response);
@@ -325,47 +306,47 @@ const onCall = async (message) => {
325
306
  catch (error) {
326
307
  messageResponse = (0, events_2.createResponseMessage)(method.responseID, false, { error });
327
308
  }
328
- postMessage(messageResponse);
309
+ sendCoreMessage(messageResponse);
329
310
  return Promise.resolve();
330
311
  }
331
- if (!_deviceList.isConnected() && !_deviceList.pendingConnection()) {
312
+ if (!deviceList.isConnected() && !deviceList.pendingConnection()) {
332
313
  const { transports, pendingTransportEvent } = DataManager_1.DataManager.getSettings();
333
- _deviceList.setTransports(transports);
334
- await _deviceList.init({ pendingTransportEvent });
314
+ deviceList.setTransports(transports);
315
+ await deviceList.init({ pendingTransportEvent });
335
316
  }
336
317
  if (method.isManagementRestricted()) {
337
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
338
- postMessage((0, events_2.createResponseMessage)(responseID, false, {
318
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
319
+ sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, {
339
320
  error: constants_1.ERRORS.TypedError('Method_NotAllowed'),
340
321
  }));
341
322
  return Promise.resolve();
342
323
  }
343
324
  let device;
344
325
  try {
345
- device = await initDevice(method.devicePath);
326
+ device = await initDevice(context, method.devicePath);
346
327
  }
347
328
  catch (error) {
348
329
  if (error.code === 'Transport_Missing') {
349
- await waitForPopup();
350
- postMessage((0, events_2.createUiMessage)(events_2.UI.TRANSPORT));
330
+ await waitForPopup(context);
331
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.TRANSPORT));
351
332
  }
352
333
  else {
353
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
334
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
354
335
  }
355
- postMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
336
+ sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, { error }));
356
337
  throw error;
357
338
  }
358
339
  method.setDevice(device);
359
- const previousCall = _callMethods.filter(call => call && call !== method && call.devicePath === method.devicePath);
340
+ const previousCall = callMethods.filter(call => call && call !== method && call.devicePath === method.devicePath);
360
341
  if (previousCall.length > 0 && method.overridePreviousCall) {
361
342
  previousCall.forEach(call => {
362
343
  call.overridden = true;
363
344
  });
364
345
  const overrideError = constants_1.ERRORS.TypedError('Method_Override');
365
- _overridePromise = device.override(overrideError);
366
- await _overridePromise;
346
+ setOverridePromise(device.override(overrideError));
347
+ await getOverridePromise();
367
348
  if (method.overridden) {
368
- postMessage((0, events_2.createResponseMessage)(method.responseID, false, { error: overrideError }));
349
+ sendCoreMessage((0, events_2.createResponseMessage)(method.responseID, false, { error: overrideError }));
369
350
  throw overrideError;
370
351
  }
371
352
  }
@@ -374,7 +355,7 @@ const onCall = async (message) => {
374
355
  await device.waitForFirstRun();
375
356
  }
376
357
  else {
377
- postMessage((0, events_2.createResponseMessage)(responseID, false, {
358
+ sendCoreMessage((0, events_2.createResponseMessage)(responseID, false, {
378
359
  error: constants_1.ERRORS.TypedError('Device_CallInProgress'),
379
360
  }));
380
361
  throw constants_1.ERRORS.TypedError('Device_CallInProgress');
@@ -384,14 +365,12 @@ const onCall = async (message) => {
384
365
  if (method.hasExpectedDeviceState) {
385
366
  device.setExternalState(method.deviceState);
386
367
  }
387
- device.on(events_2.DEVICE.BUTTON, (d, code) => {
388
- onDeviceButtonHandler(d, code, method);
389
- });
390
- device.on(events_2.DEVICE.PIN, onDevicePinHandler);
391
- device.on(events_2.DEVICE.WORD, onDeviceWordHandler);
392
- device.on(events_2.DEVICE.PASSPHRASE, method.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
368
+ device.on(events_2.DEVICE.BUTTON, onDeviceButtonHandler(context, method));
369
+ device.on(events_2.DEVICE.PIN, onDevicePinHandler(context));
370
+ device.on(events_2.DEVICE.WORD, onDeviceWordHandler(context));
371
+ device.on(events_2.DEVICE.PASSPHRASE, (method.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler)(context));
393
372
  device.on(events_2.DEVICE.PASSPHRASE_ON_DEVICE, () => {
394
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE_ON_DEVICE, { device: device.toMessageObject() }));
373
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE_ON_DEVICE, { device: device.toMessageObject() }));
395
374
  });
396
375
  device.on(events_2.DEVICE.SAVE_STATE, (state) => {
397
376
  if (useCoreInPopup && env === 'webextension') {
@@ -418,10 +397,10 @@ const onCall = async (message) => {
418
397
  }
419
398
  }
420
399
  try {
421
- if (_overridePromise) {
422
- await _overridePromise;
400
+ if (getOverridePromise()) {
401
+ await getOverridePromise();
423
402
  }
424
- const innerAction = () => inner(method, device).then(response => {
403
+ const innerAction = () => inner(context, method, device).then(response => {
425
404
  messageResponse = response;
426
405
  });
427
406
  await device.run(innerAction, {
@@ -432,19 +411,19 @@ const onCall = async (message) => {
432
411
  }
433
412
  catch (error) {
434
413
  if (error.code === 'Device_Disconnected') {
435
- _deviceList.addAuthPenalty(device);
414
+ deviceList.addAuthPenalty(device);
436
415
  }
437
416
  if (method) {
438
- if (_deviceList.isConnected() &&
417
+ if (deviceList.isConnected() &&
439
418
  error.message === transport_1.TRANSPORT_ERROR.SESSION_WRONG_PREVIOUS) {
440
- await _deviceList.enumerate();
419
+ await deviceList.enumerate();
441
420
  }
442
421
  messageResponse = (0, events_2.createResponseMessage)(method.responseID, false, { error });
443
422
  }
444
423
  }
445
424
  finally {
446
- if (_overridePromise) {
447
- await _overridePromise;
425
+ if (getOverridePromise()) {
426
+ await getOverridePromise();
448
427
  }
449
428
  const response = messageResponse;
450
429
  if (response) {
@@ -458,71 +437,75 @@ const onCall = async (message) => {
458
437
  }
459
438
  await device.cleanup();
460
439
  if (useCoreInPopup) {
461
- postMessage(response);
440
+ sendCoreMessage(response);
462
441
  }
463
- closePopup();
464
- cleanup();
442
+ closePopup(context);
443
+ cleanup(context);
465
444
  if (method) {
466
445
  method.dispose();
467
446
  }
468
447
  if (response.success) {
469
- _deviceList.removeAuthPenalty(device);
448
+ deviceList.removeAuthPenalty(device);
470
449
  }
471
450
  if (!useCoreInPopup) {
472
- postMessage(response);
451
+ sendCoreMessage(response);
473
452
  }
474
453
  }
475
454
  }
476
455
  };
477
- const cleanup = () => {
456
+ const cleanup = ({ uiPromises, popupPromise, interactionTimeout }) => {
478
457
  popupPromise.clear();
479
458
  uiPromises.clear();
480
- _interactionTimeout.stop();
459
+ interactionTimeout.stop();
481
460
  _log.debug('Cleanup...');
482
461
  };
483
- const closePopup = () => {
462
+ const closePopup = ({ popupPromise, sendCoreMessage }) => {
484
463
  if (popupPromise.isWaiting()) {
485
- postMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
464
+ sendCoreMessage((0, events_2.createPopupMessage)(events_2.POPUP.CANCEL_POPUP_REQUEST));
486
465
  }
487
- postMessage((0, events_2.createUiMessage)(events_2.UI.CLOSE_UI_WINDOW));
466
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.CLOSE_UI_WINDOW));
488
467
  };
489
- const onDeviceButtonHandler = async (...[device, request, method]) => {
468
+ const onDeviceButtonHandler = (context, method) => async (...[device, request]) => {
469
+ const { sendCoreMessage } = context;
490
470
  const addressRequest = request.code === 'ButtonRequest_Address';
491
471
  if (!addressRequest || (addressRequest && method.useUi)) {
492
- await waitForPopup();
472
+ await waitForPopup(context);
493
473
  }
494
474
  const data = typeof method.getButtonRequestData === 'function' && request.code
495
475
  ? method.getButtonRequestData(request.code)
496
476
  : undefined;
497
- interactionTimeout();
498
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
499
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_BUTTON, {
477
+ startInteractionTimeout(context);
478
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
479
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_BUTTON, {
500
480
  ...request,
501
481
  device: device.toMessageObject(),
502
482
  data,
503
483
  }));
504
484
  if (addressRequest && !method.useUi) {
505
- postMessage((0, events_2.createUiMessage)(events_2.UI.ADDRESS_VALIDATION, data));
485
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.ADDRESS_VALIDATION, data));
506
486
  }
507
487
  };
508
- const onDevicePinHandler = async (...[device, type, callback]) => {
509
- await waitForPopup();
488
+ const onDevicePinHandler = (context) => async (...[device, type, callback]) => {
489
+ const { uiPromises, sendCoreMessage } = context;
490
+ await waitForPopup(context);
510
491
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_PIN, device);
511
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PIN, { device: device.toMessageObject(), type }));
492
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PIN, { device: device.toMessageObject(), type }));
512
493
  const uiResp = await uiPromise.promise;
513
494
  callback(null, uiResp.payload);
514
495
  };
515
- const onDeviceWordHandler = async (...[device, type, callback]) => {
516
- await waitForPopup();
496
+ const onDeviceWordHandler = (context) => async (...[device, type, callback]) => {
497
+ const { uiPromises, sendCoreMessage } = context;
498
+ await waitForPopup(context);
517
499
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_WORD, device);
518
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_WORD, { device: device.toMessageObject(), type }));
500
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_WORD, { device: device.toMessageObject(), type }));
519
501
  const uiResp = await uiPromise.promise;
520
502
  callback(null, uiResp.payload);
521
503
  };
522
- const onDevicePassphraseHandler = async (...[device, callback]) => {
523
- await waitForPopup();
504
+ const onDevicePassphraseHandler = (context) => async (...[device, callback]) => {
505
+ const { uiPromises, sendCoreMessage } = context;
506
+ await waitForPopup(context);
524
507
  const uiPromise = uiPromises.create(events_2.UI.RECEIVE_PASSPHRASE, device);
525
- postMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE, { device: device.toMessageObject() }));
508
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.REQUEST_PASSPHRASE, { device: device.toMessageObject() }));
526
509
  const uiResp = await uiPromise.promise;
527
510
  const { value, passphraseOnDevice, save } = uiResp.payload;
528
511
  callback({
@@ -531,27 +514,28 @@ const onDevicePassphraseHandler = async (...[device, callback]) => {
531
514
  cache: save,
532
515
  });
533
516
  };
534
- const onEmptyPassphraseHandler = (...[_, callback]) => {
517
+ const onEmptyPassphraseHandler = () => (...[_, callback]) => {
535
518
  callback({ passphrase: '' });
536
519
  };
537
- const onPopupClosed = (customErrorMessage) => {
520
+ const onPopupClosed = (context, customErrorMessage) => {
521
+ const { uiPromises, popupPromise, deviceList, callMethods, resetWaitForFirstMethod, setOverridePromise, sendCoreMessage, } = context;
538
522
  const error = customErrorMessage
539
523
  ? constants_1.ERRORS.TypedError('Method_Cancel', customErrorMessage)
540
524
  : constants_1.ERRORS.TypedError('Method_Interrupted');
541
- if (_deviceList.isConnected() && _deviceList.asArray().length > 0) {
542
- _deviceList.allDevices().forEach(d => {
525
+ if (deviceList.isConnected() && deviceList.asArray().length > 0) {
526
+ deviceList.allDevices().forEach(d => {
543
527
  d.keepSession = false;
544
528
  if (d.isUsedHere()) {
545
- _overridePromise = d.interruptionFromUser(error);
529
+ setOverridePromise(d.interruptionFromUser(error));
546
530
  }
547
531
  else {
548
532
  const success = uiPromises.resolve({ type: events_2.DEVICE.DISCONNECT, payload: undefined });
549
533
  if (!success) {
550
- _callMethods.forEach(m => {
551
- postMessage((0, events_2.createResponseMessage)(m.responseID, false, { error }));
534
+ callMethods.forEach(m => {
535
+ sendCoreMessage((0, events_2.createResponseMessage)(m.responseID, false, { error }));
552
536
  });
553
- _callMethods.splice(0, _callMethods.length);
554
- waitForFirstMethod = (0, utils_1.createDeferred)();
537
+ callMethods.splice(0, callMethods.length);
538
+ resetWaitForFirstMethod();
555
539
  }
556
540
  }
557
541
  });
@@ -560,13 +544,14 @@ const onPopupClosed = (customErrorMessage) => {
560
544
  uiPromises.rejectAll(error);
561
545
  popupPromise.reject(error);
562
546
  }
563
- cleanup();
547
+ cleanup(context);
564
548
  };
565
- const handleDeviceSelectionChanges = (interruptDevice) => {
549
+ const handleDeviceSelectionChanges = (context, interruptDevice) => {
550
+ const { uiPromises, deviceList, sendCoreMessage } = context;
566
551
  const promiseExists = uiPromises.exists(events_2.UI.RECEIVE_DEVICE);
567
- if (promiseExists && _deviceList.isConnected()) {
568
- const list = _deviceList.asArray();
569
- const isWebUsb = _deviceList.transportType() === 'WebUsbTransport';
552
+ if (promiseExists && deviceList.isConnected()) {
553
+ const list = deviceList.asArray();
554
+ const isWebUsb = deviceList.transportType() === 'WebUsbTransport';
570
555
  if (list.length === 1 && !isWebUsb) {
571
556
  uiPromises.resolve({
572
557
  type: events_2.UI.RECEIVE_DEVICE,
@@ -574,7 +559,7 @@ const handleDeviceSelectionChanges = (interruptDevice) => {
574
559
  });
575
560
  }
576
561
  else {
577
- postMessage((0, events_2.createUiMessage)(events_2.UI.SELECT_DEVICE, {
562
+ sendCoreMessage((0, events_2.createUiMessage)(events_2.UI.SELECT_DEVICE, {
578
563
  webusb: isWebUsb,
579
564
  devices: list,
580
565
  }));
@@ -584,60 +569,107 @@ const handleDeviceSelectionChanges = (interruptDevice) => {
584
569
  const { path } = interruptDevice;
585
570
  const shouldClosePopup = uiPromises.disconnected(path);
586
571
  if (shouldClosePopup) {
587
- closePopup();
588
- cleanup();
572
+ closePopup(context);
573
+ cleanup(context);
589
574
  }
590
575
  }
591
576
  };
592
- const createDeviceList = (params) => {
593
- const deviceList = new DeviceList_1.DeviceList(params);
577
+ const initDeviceList = (context) => {
578
+ const { deviceList, sendCoreMessage } = context;
594
579
  deviceList.on(events_2.DEVICE.CONNECT, device => {
595
- handleDeviceSelectionChanges();
596
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CONNECT, device));
580
+ handleDeviceSelectionChanges(context);
581
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CONNECT, device));
597
582
  });
598
583
  deviceList.on(events_2.DEVICE.CONNECT_UNACQUIRED, device => {
599
- handleDeviceSelectionChanges();
600
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CONNECT_UNACQUIRED, device));
584
+ handleDeviceSelectionChanges(context);
585
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CONNECT_UNACQUIRED, device));
601
586
  });
602
587
  deviceList.on(events_2.DEVICE.DISCONNECT, device => {
603
- handleDeviceSelectionChanges(device);
604
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.DISCONNECT, device));
588
+ handleDeviceSelectionChanges(context);
589
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.DISCONNECT, device));
605
590
  });
606
591
  deviceList.on(events_2.DEVICE.CHANGED, device => {
607
- postMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CHANGED, device));
592
+ sendCoreMessage((0, events_2.createDeviceMessage)(events_2.DEVICE.CHANGED, device));
608
593
  });
609
- deviceList.on(transport_1.TRANSPORT.START, transportType => postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.START, transportType)));
594
+ deviceList.on(transport_1.TRANSPORT.START, transportType => sendCoreMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.START, transportType)));
610
595
  deviceList.on(transport_1.TRANSPORT.ERROR, error => {
611
596
  _log.warn('TRANSPORT.ERROR', error);
612
- postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
597
+ sendCoreMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
613
598
  });
614
- return deviceList;
615
599
  };
616
600
  class Core extends events_1.default {
617
601
  constructor() {
618
602
  super(...arguments);
619
603
  this.abortController = new AbortController();
604
+ this.callMethods = [];
605
+ this.popupPromise = (0, popupPromiseManager_1.createPopupPromiseManager)();
606
+ this.methodSynchronize = (0, utils_2.getSynchronize)();
607
+ this.uiPromises = (0, uiPromiseManager_1.createUiPromiseManager)(() => startInteractionTimeout(this.getCoreContext()));
608
+ this.waitForFirstMethod = (0, utils_1.createDeferred)();
609
+ }
610
+ get interactionTimeout() {
611
+ var _a;
612
+ return (_a = this._interactionTimeout) !== null && _a !== void 0 ? _a : (0, utils_1.throwError)('Core not initialized: interactionTimeout');
613
+ }
614
+ get deviceList() {
615
+ var _a;
616
+ return (_a = this._deviceList) !== null && _a !== void 0 ? _a : (0, utils_1.throwError)('Core not initialized: deviceList');
617
+ }
618
+ sendCoreMessage(message) {
619
+ if (message.event === events_2.RESPONSE_EVENT) {
620
+ const index = this.callMethods.findIndex(call => call && call.responseID === message.id);
621
+ if (index >= 0) {
622
+ this.callMethods.splice(index, 1);
623
+ if (this.callMethods.length === 0) {
624
+ this.waitForFirstMethod = (0, utils_1.createDeferred)();
625
+ }
626
+ }
627
+ }
628
+ this.emit(events_2.CORE_EVENT, message);
629
+ }
630
+ getCoreContext() {
631
+ return {
632
+ uiPromises: this.uiPromises,
633
+ popupPromise: this.popupPromise,
634
+ interactionTimeout: this.interactionTimeout,
635
+ deviceList: this.deviceList,
636
+ callMethods: this.callMethods,
637
+ methodSynchronize: this.methodSynchronize,
638
+ sendCoreMessage: this.sendCoreMessage.bind(this),
639
+ resetWaitForFirstMethod: () => {
640
+ this.waitForFirstMethod = (0, utils_1.createDeferred)();
641
+ },
642
+ resolveWaitForFirstMethod: () => {
643
+ this.waitForFirstMethod.resolve();
644
+ },
645
+ getOverridePromise: () => {
646
+ return this.overridePromise;
647
+ },
648
+ setOverridePromise: (promise) => {
649
+ this.overridePromise = promise;
650
+ },
651
+ };
620
652
  }
621
653
  handleMessage(message) {
622
654
  _log.debug('handleMessage', message);
623
655
  switch (message.type) {
624
656
  case events_2.POPUP.HANDSHAKE:
625
- popupPromise.resolve();
657
+ this.popupPromise.resolve();
626
658
  break;
627
659
  case events_2.POPUP.CLOSED:
628
- popupPromise.clear();
629
- onPopupClosed(message.payload ? message.payload.error : null);
660
+ this.popupPromise.clear();
661
+ onPopupClosed(this.getCoreContext(), message.payload ? message.payload.error : null);
630
662
  break;
631
663
  case transport_1.TRANSPORT.DISABLE_WEBUSB:
632
- disableWebUSBTransport();
664
+ disableWebUSBTransport(this.getCoreContext());
633
665
  break;
634
666
  case transport_1.TRANSPORT.REQUEST_DEVICE:
635
- if (_deviceList.isConnected()) {
636
- _deviceList.enumerate();
667
+ if (this.deviceList.isConnected()) {
668
+ this.deviceList.enumerate();
637
669
  }
638
670
  break;
639
671
  case transport_1.TRANSPORT.GET_INFO:
640
- postMessage((0, events_2.createResponseMessage)(message.id, true, this.getTransportInfo()));
672
+ this.sendCoreMessage((0, events_2.createResponseMessage)(message.id, true, this.getTransportInfo()));
641
673
  break;
642
674
  case events_2.UI.RECEIVE_DEVICE:
643
675
  case events_2.UI.RECEIVE_CONFIRMATION:
@@ -649,31 +681,31 @@ class Core extends events_1.default {
649
681
  case events_2.UI.RECEIVE_FEE:
650
682
  case events_2.UI.RECEIVE_WORD:
651
683
  case events_2.UI.LOGIN_CHALLENGE_RESPONSE:
652
- uiPromises.resolve(message);
684
+ this.uiPromises.resolve(message);
653
685
  break;
654
686
  case events_2.IFRAME.CALL:
655
687
  if (message.payload.method === 'firmwareUpdate') {
656
- _deviceList.assertConnected();
688
+ (0, DeviceList_1.assertDeviceListConnected)(this.deviceList);
657
689
  (0, onCallFirmwareUpdate_1.onCallFirmwareUpdate)({
658
690
  params: message.payload,
659
691
  context: {
660
- deviceList: _deviceList,
661
- postMessage,
662
- initDevice,
692
+ deviceList: this.deviceList,
693
+ postMessage: this.sendCoreMessage.bind(this),
694
+ initDevice: path => initDevice(this.getCoreContext(), path),
663
695
  log: _log,
664
696
  abortSignal: this.abortController.signal,
665
697
  },
666
698
  })
667
699
  .then(payload => {
668
- postMessage((0, events_2.createResponseMessage)(message.id, true, payload));
700
+ this.sendCoreMessage((0, events_2.createResponseMessage)(message.id, true, payload));
669
701
  })
670
702
  .catch(error => {
671
- postMessage((0, events_2.createResponseMessage)(message.id, false, { error }));
703
+ this.sendCoreMessage((0, events_2.createResponseMessage)(message.id, false, { error }));
672
704
  _log.error('onCallFirmwareUpdate', error);
673
705
  });
674
706
  }
675
707
  else {
676
- onCall(message).catch(error => {
708
+ onCall(this.getCoreContext(), message).catch(error => {
677
709
  _log.error('onCall', error);
678
710
  });
679
711
  }
@@ -681,63 +713,74 @@ class Core extends events_1.default {
681
713
  }
682
714
  dispose() {
683
715
  (0, BlockchainLink_1.dispose)();
684
- _deviceListInitReject === null || _deviceListInitReject === void 0 ? void 0 : _deviceListInitReject(new Error('Disposed during initialization'));
685
716
  this.removeAllListeners();
686
717
  this.abortController.abort();
687
- _deviceList.dispose();
718
+ this.deviceList.dispose();
688
719
  }
689
720
  async getCurrentMethod() {
690
- await waitForFirstMethod.promise;
691
- return await methodSynchronize(() => _callMethods[0]);
721
+ await this.waitForFirstMethod.promise;
722
+ return await this.methodSynchronize(() => this.callMethods[0]);
692
723
  }
693
724
  getTransportInfo() {
694
- if (_deviceList.isConnected()) {
695
- return _deviceList.getTransportInfo();
725
+ if (this.deviceList.isConnected()) {
726
+ return this.deviceList.getTransportInfo();
696
727
  }
697
728
  }
698
729
  enumerate() {
699
- if (_deviceList.isConnected()) {
700
- _deviceList.enumerate();
730
+ if (this.deviceList.isConnected()) {
731
+ this.deviceList.enumerate();
701
732
  }
702
733
  }
703
734
  async init(settings, onCoreEvent, logWriterFactory) {
704
735
  if (logWriterFactory) {
705
736
  (0, debug_1.setLogWriter)(logWriterFactory);
706
737
  }
738
+ const throttlePromise = (0, utils_1.createDeferred)();
739
+ throttlePromise.promise.catch(() => { });
740
+ const onCoreEventThrottled = (message) => throttlePromise.promise.then(() => onCoreEvent(message));
707
741
  try {
708
742
  await DataManager_1.DataManager.load(settings);
709
743
  const { debug, priority } = DataManager_1.DataManager.getSettings();
710
744
  const messages = DataManager_1.DataManager.getProtobufMessages();
711
745
  (0, debug_1.enableLog)(debug);
712
- _core = this;
713
- _deviceList = createDeviceList({ debug, messages, priority });
714
- _interactionTimeout = new interactionTimeout_1.InteractionTimeout(settings.popup ? settings.interactionTimeout : 0);
715
- this.on(events_2.CORE_EVENT, onCoreEvent);
746
+ this._interactionTimeout = new interactionTimeout_1.InteractionTimeout(settings.popup ? settings.interactionTimeout : 0);
747
+ this._deviceList = new DeviceList_1.DeviceList({
748
+ debug,
749
+ messages,
750
+ priority,
751
+ });
752
+ initDeviceList(this.getCoreContext());
753
+ this.on(events_2.CORE_EVENT, onCoreEventThrottled);
716
754
  }
717
755
  catch (error) {
718
756
  _log.error('init', error);
757
+ throttlePromise.reject(error);
719
758
  throw error;
720
759
  }
721
760
  const { transports, pendingTransportEvent, transportReconnect, coreMode } = DataManager_1.DataManager.getSettings();
722
761
  try {
723
- _deviceList.setTransports(transports);
762
+ this.deviceList.setTransports(transports);
724
763
  }
725
764
  catch (error) {
726
765
  _log.error('setTransports', error);
727
- postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
766
+ this.sendCoreMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
767
+ throttlePromise.reject(error);
728
768
  throw error;
729
769
  }
730
- _deviceList.init({ pendingTransportEvent, transportReconnect });
770
+ this.deviceList.init({ pendingTransportEvent, transportReconnect });
731
771
  if (!transportReconnect || coreMode === 'auto') {
732
- await _deviceList.pendingConnection();
772
+ await this.deviceList.pendingConnection();
733
773
  }
774
+ this.on(events_2.CORE_EVENT, onCoreEvent);
775
+ this.off(events_2.CORE_EVENT, onCoreEventThrottled);
776
+ setTimeout(throttlePromise.resolve, 0);
734
777
  }
735
778
  }
736
779
  exports.Core = Core;
737
- const disableWebUSBTransport = async () => {
738
- if (!_deviceList.isConnected())
780
+ const disableWebUSBTransport = async ({ deviceList, sendCoreMessage }) => {
781
+ if (!deviceList.isConnected())
739
782
  return;
740
- if (_deviceList.transportType() !== 'WebUsbTransport')
783
+ if (deviceList.transportType() !== 'WebUsbTransport')
741
784
  return;
742
785
  const { transports, pendingTransportEvent, transportReconnect } = DataManager_1.DataManager.getSettings();
743
786
  if (transports) {
@@ -750,26 +793,17 @@ const disableWebUSBTransport = async () => {
750
793
  }
751
794
  }
752
795
  try {
753
- _deviceList.cleanup();
754
- _deviceList.setTransports(transports);
755
- await _deviceList.init({ pendingTransportEvent, transportReconnect });
796
+ deviceList.cleanup();
797
+ deviceList.setTransports(transports);
798
+ await deviceList.init({ pendingTransportEvent, transportReconnect });
756
799
  }
757
800
  catch (error) {
758
- postMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
801
+ sendCoreMessage((0, events_2.createTransportMessage)(transport_1.TRANSPORT.ERROR, { error }));
759
802
  }
760
803
  };
761
- const initCore = async (settings, onCoreEvent, logWriterFactory) => {
804
+ const initCore = async (...params) => {
762
805
  const core = new Core();
763
- let promise;
764
- const eventThrottle = (...args) => promise
765
- .then(() => {
766
- setTimeout(() => onCoreEvent(...args), 0);
767
- })
768
- .catch(() => { });
769
- promise = core.init(settings, eventThrottle, logWriterFactory);
770
- await promise;
771
- core.on(events_2.CORE_EVENT, onCoreEvent);
772
- core.off(events_2.CORE_EVENT, eventThrottle);
806
+ await core.init(...params);
773
807
  return core;
774
808
  };
775
809
  const disposeCore = (core) => {