@trezor/connect 9.4.0 → 9.4.1-beta.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +83 -8
  2. package/README.md +1 -1
  3. package/lib/api/binance/api/index.js +4 -6
  4. package/lib/api/bitcoin/Fees.d.ts +2 -2
  5. package/lib/api/bitcoin/outputs.d.ts +1 -1
  6. package/lib/api/bitcoin/refTx.d.ts +2 -2
  7. package/lib/api/cardano/api/index.js +6 -8
  8. package/lib/api/cardano/cardanoInputs.d.ts +10 -10
  9. package/lib/api/cardano/cardanoOutputs.d.ts +23 -23
  10. package/lib/api/cardano/cardanoTokenBundle.d.ts +6 -6
  11. package/lib/api/common/Discovery.d.ts +0 -1
  12. package/lib/api/common/paramsValidator.js +2 -2
  13. package/lib/api/composeTransaction.js +3 -0
  14. package/lib/api/eos/api/index.js +3 -5
  15. package/lib/api/eos/eosSignTx.d.ts +4 -4
  16. package/lib/api/eos/eosSignTx.js +2 -2
  17. package/lib/api/ethereum/api/ethereumSignTypedData.d.ts +68 -68
  18. package/lib/api/ethereum/api/index.js +7 -9
  19. package/lib/api/ethereum/ethereumDefinitions.d.ts +23 -23
  20. package/lib/api/ethereum/ethereumSignTypedData.js +3 -4
  21. package/lib/api/firmware/calculateFirmwareHash.d.ts +0 -1
  22. package/lib/api/firmware/parseFirmwareHeaders.d.ts +0 -1
  23. package/lib/api/firmware/uploadFirmware.d.ts +6 -1
  24. package/lib/api/firmware/verifyAuthenticityProof.d.ts +0 -1
  25. package/lib/api/getAccountInfo.d.ts +38 -38
  26. package/lib/api/getCoinInfo.d.ts +3 -3
  27. package/lib/api/getDeviceState.d.ts +2 -1
  28. package/lib/api/getDeviceState.js +6 -3
  29. package/lib/api/getFeatures.d.ts +10 -10
  30. package/lib/api/index.js +49 -51
  31. package/lib/api/nem/api/index.js +3 -5
  32. package/lib/api/pushTransaction.js +1 -1
  33. package/lib/api/ripple/api/index.js +3 -5
  34. package/lib/api/signTransaction.js +3 -0
  35. package/lib/api/solana/api/index.js +4 -6
  36. package/lib/api/stellar/api/index.js +3 -5
  37. package/lib/api/tezos/api/index.js +4 -6
  38. package/lib/api/tezos/tezosSignTx.js +2 -2
  39. package/lib/backend/Blockchain.d.ts +2 -2
  40. package/lib/backend/BlockchainLink.d.ts +2 -2
  41. package/lib/constants/nem.d.ts +3 -3
  42. package/lib/core/AbstractMethod.d.ts +8 -6
  43. package/lib/core/AbstractMethod.js +26 -3
  44. package/lib/core/index.d.ts +0 -1
  45. package/lib/core/index.js +45 -54
  46. package/lib/core/onCallFirmwareUpdate.js +7 -2
  47. package/lib/data/DataManager.d.ts +5 -31
  48. package/lib/data/coinInfo.d.ts +15 -21
  49. package/lib/data/config.d.ts +5 -31
  50. package/lib/data/config.js +8 -5
  51. package/lib/data/deviceAuthenticityConfig.js +32 -14
  52. package/lib/data/deviceAuthenticityConfigTypes.d.ts +28 -28
  53. package/lib/data/firmwareInfo.d.ts +2 -2
  54. package/lib/data/firmwareInfo.js +8 -7
  55. package/lib/data/models.js +3 -3
  56. package/lib/data/version.d.ts +1 -1
  57. package/lib/data/version.js +1 -1
  58. package/lib/device/Device.d.ts +52 -19
  59. package/lib/device/Device.js +87 -73
  60. package/lib/device/DeviceCommands.d.ts +9 -9
  61. package/lib/device/DeviceCommands.js +10 -10
  62. package/lib/device/DeviceList.js +60 -83
  63. package/lib/device/StateStorage.d.ts +15 -0
  64. package/lib/device/StateStorage.js +40 -0
  65. package/lib/device/checkFirmwareRevision.js +0 -4
  66. package/lib/events/device.d.ts +0 -1
  67. package/lib/events/device.js +0 -1
  68. package/lib/events/ui-request.d.ts +2 -1
  69. package/lib/factory.d.ts +0 -1
  70. package/lib/index.d.ts +0 -1
  71. package/lib/types/api/applySettings.d.ts +14 -14
  72. package/lib/types/api/authenticateDevice.d.ts +30 -30
  73. package/lib/types/api/authorizeCoinjoin.d.ts +10 -10
  74. package/lib/types/api/binance/index.d.ts +152 -152
  75. package/lib/types/api/bitcoin/index.d.ts +12 -12
  76. package/lib/types/api/cancelCoinjoinAuthorization.d.ts +2 -2
  77. package/lib/types/api/cardano/index.d.ts +556 -556
  78. package/lib/types/api/changeLanguage.d.ts +7 -7
  79. package/lib/types/api/cipherKeyValue.d.ts +8 -8
  80. package/lib/types/api/eos/index.d.ts +633 -633
  81. package/lib/types/api/ethereum/index.d.ts +124 -124
  82. package/lib/types/api/firmwareUpdate.d.ts +6 -6
  83. package/lib/types/api/getAccountDescriptor.d.ts +5 -5
  84. package/lib/types/api/getAddress.d.ts +33 -33
  85. package/lib/types/api/getDeviceState.d.ts +3 -1
  86. package/lib/types/api/getOwnershipId.d.ts +25 -25
  87. package/lib/types/api/getOwnershipProof.d.ts +29 -29
  88. package/lib/types/api/getPublicKey.d.ts +25 -25
  89. package/lib/types/api/nem/index.d.ts +707 -707
  90. package/lib/types/api/nemGetAddress.d.ts +7 -7
  91. package/lib/types/api/pushTransaction.d.ts +4 -4
  92. package/lib/types/api/recoveryDevice.d.ts +10 -10
  93. package/lib/types/api/requestLogin.d.ts +28 -28
  94. package/lib/types/api/ripple/index.d.ts +28 -28
  95. package/lib/types/api/solana/index.d.ts +28 -28
  96. package/lib/types/api/stellar/index.d.ts +745 -745
  97. package/lib/types/api/tezos/index.d.ts +129 -129
  98. package/lib/types/api/unlockPath.d.ts +3 -3
  99. package/lib/types/coinInfo.d.ts +246 -246
  100. package/lib/types/device.d.ts +9 -1
  101. package/lib/types/fees.d.ts +22 -22
  102. package/lib/types/firmware.d.ts +1 -1
  103. package/lib/types/params.d.ts +20 -19
  104. package/lib/utils/assetUtils.js +1 -1
  105. package/lib/utils/assets-browser.d.ts +1 -1
  106. package/lib/utils/assets.js +1 -2
  107. package/lib/utils/debug.d.ts +2 -2
  108. package/lib/utils/deviceFeaturesUtils.d.ts +1 -1
  109. package/lib/utils/hdnodeUtils.d.ts +1 -191
  110. package/lib/utils/hdnodeUtils.js +2 -2
  111. package/lib/utils/pathUtils.d.ts +1 -191
  112. package/lib/utils/promiseUtils.d.ts +1 -1
  113. package/lib/utils/uiPromiseManager.d.ts +2 -2
  114. package/package.json +15 -13
@@ -28,14 +28,12 @@ class Device extends utils_1.TypedEmitter {
28
28
  constructor(transport, descriptor) {
29
29
  super();
30
30
  this.featuresNeedsReload = false;
31
- this.acquirePromise = undefined;
32
- this.releasePromise = undefined;
31
+ this.keepTransportSession = false;
33
32
  this.loaded = false;
34
33
  this.inconsistent = false;
35
- this.keepSession = false;
36
34
  this.instance = 0;
37
- this.internalState = [];
38
- this.externalState = [];
35
+ this.state = [];
36
+ this.stateStorage = undefined;
39
37
  this.unavailableCapabilities = {};
40
38
  this.networkTypeState = [];
41
39
  this.name = 'Trezor';
@@ -43,12 +41,8 @@ class Device extends utils_1.TypedEmitter {
43
41
  this.authenticityChecks = {
44
42
  firmwareRevision: null,
45
43
  };
46
- if (transport.name === 'BridgeTransport') {
47
- this.protocol = protocol_1.bridge;
48
- }
49
- else {
50
- this.protocol = protocol_1.v1;
51
- }
44
+ this.useCardanoDerivation = false;
45
+ this.protocol = protocol_1.v1;
52
46
  this.transport = transport;
53
47
  this.originalDescriptor = descriptor;
54
48
  this.firstRunPromise = (0, utils_1.createDeferred)();
@@ -76,7 +70,7 @@ class Device extends utils_1.TypedEmitter {
76
70
  previous: this.originalDescriptor.session,
77
71
  },
78
72
  });
79
- const acquireResult = await this.acquirePromise.promise;
73
+ const acquireResult = await this.acquirePromise;
80
74
  this.acquirePromise = undefined;
81
75
  if (!acquireResult.success) {
82
76
  if (this.runPromise) {
@@ -85,34 +79,34 @@ class Device extends utils_1.TypedEmitter {
85
79
  }
86
80
  throw acquireResult.error;
87
81
  }
88
- const sessionID = acquireResult.payload;
89
- _log.debug('Expected session id:', sessionID);
90
- this.activitySessionID = sessionID;
91
- this.originalDescriptor.session = sessionID;
82
+ const transportSession = acquireResult.payload;
83
+ _log.debug('Expected workflow id:', transportSession);
84
+ this.transportSession = transportSession;
85
+ this.originalDescriptor.session = transportSession;
92
86
  if (this.commands) {
93
87
  this.commands.dispose();
94
88
  }
95
- this.commands = new DeviceCommands_1.DeviceCommands(this, this.transport, sessionID);
89
+ this.commands = new DeviceCommands_1.DeviceCommands(this, this.transport, transportSession);
96
90
  }
97
91
  async release() {
98
92
  if (this.isUsedHere() &&
99
- !this.keepSession &&
100
- this.activitySessionID &&
93
+ this.transportSession &&
94
+ !this.keepTransportSession &&
101
95
  !this.releasePromise) {
102
96
  if (this.commands) {
103
97
  this.commands.dispose();
104
98
  if (this.commands.callPromise) {
105
- await this.commands.callPromise.promise;
99
+ await this.commands.callPromise;
106
100
  }
107
101
  }
108
102
  this.releasePromise = this.transport.release({
109
- session: this.activitySessionID,
103
+ session: this.transportSession,
110
104
  path: this.originalDescriptor.path,
111
105
  });
112
- const releaseResponse = await this.releasePromise.promise;
106
+ const releaseResponse = await this.releasePromise;
113
107
  this.releasePromise = undefined;
114
108
  if (releaseResponse.success) {
115
- this.activitySessionID = null;
109
+ this.transportSession = null;
116
110
  this.originalDescriptor.session = null;
117
111
  }
118
112
  }
@@ -139,13 +133,13 @@ class Device extends utils_1.TypedEmitter {
139
133
  }
140
134
  async override(error) {
141
135
  if (this.acquirePromise) {
142
- await this.acquirePromise.promise;
136
+ await this.acquirePromise;
143
137
  }
144
138
  if (this.runPromise) {
145
139
  await this.interruptionFromUser(error);
146
140
  }
147
141
  if (this.releasePromise) {
148
- await this.releasePromise.promise;
142
+ await this.releasePromise;
149
143
  }
150
144
  }
151
145
  async interruptionFromUser(error) {
@@ -170,11 +164,14 @@ class Device extends utils_1.TypedEmitter {
170
164
  this.transport.releaseDevice(this.originalDescriptor.path);
171
165
  }
172
166
  async _runInner(fn, options) {
173
- var _a;
167
+ var _a, _b;
174
168
  if (this.releasePromise) {
175
- await this.releasePromise.promise;
169
+ await this.releasePromise;
176
170
  }
177
- if (!this.isUsedHere() || ((_a = this.commands) === null || _a === void 0 ? void 0 : _a.disposed) || !this.getExternalState()) {
171
+ if (!this.isUsedHere() ||
172
+ ((_a = this.commands) === null || _a === void 0 ? void 0 : _a.disposed) ||
173
+ !((_b = this.getState()) === null || _b === void 0 ? void 0 : _b.staticSessionId) ||
174
+ this.useCardanoDerivation != !!options.useCardanoDerivation) {
178
175
  await this.acquire();
179
176
  try {
180
177
  if (fn) {
@@ -205,7 +202,7 @@ class Device extends utils_1.TypedEmitter {
205
202
  }
206
203
  }
207
204
  if (options.keepSession) {
208
- this.keepSession = true;
205
+ this.keepTransportSession = true;
209
206
  }
210
207
  if (this.listeners(events_1.DEVICE.ACQUIRED).length > 0) {
211
208
  this.emit(events_1.DEVICE.ACQUIRED);
@@ -216,9 +213,9 @@ class Device extends utils_1.TypedEmitter {
216
213
  if (this.loaded && this.features && !options.skipFinalReload) {
217
214
  await this.getFeatures();
218
215
  }
219
- if ((!this.keepSession && typeof options.keepSession !== 'boolean') ||
216
+ if ((!this.keepTransportSession && typeof options.keepSession !== 'boolean') ||
220
217
  options.keepSession === false) {
221
- this.keepSession = false;
218
+ this.keepTransportSession = false;
222
219
  await this.release();
223
220
  }
224
221
  if (this.runPromise) {
@@ -238,9 +235,9 @@ class Device extends utils_1.TypedEmitter {
238
235
  }
239
236
  setInstance(instance = 0) {
240
237
  if (this.instance !== instance) {
241
- if (this.keepSession) {
242
- this.activitySessionID = null;
243
- this.keepSession = false;
238
+ if (this.keepTransportSession) {
239
+ this.transportSession = null;
240
+ this.keepTransportSession = false;
244
241
  }
245
242
  }
246
243
  this.instance = instance;
@@ -248,31 +245,26 @@ class Device extends utils_1.TypedEmitter {
248
245
  getInstance() {
249
246
  return this.instance;
250
247
  }
251
- setInternalState(state) {
252
- if (typeof state !== 'string') {
253
- delete this.internalState[this.instance];
254
- }
255
- else if (state !== this.internalState[this.instance]) {
256
- this.internalState[this.instance] = state;
257
- this.emit(events_1.DEVICE.SAVE_STATE, state);
258
- }
259
- }
260
- getInternalState() {
261
- return this.internalState[this.instance];
248
+ getState() {
249
+ return this.state[this.instance];
262
250
  }
263
- setExternalState(state) {
264
- if (typeof state !== 'string') {
265
- delete this.internalState[this.instance];
266
- delete this.externalState[this.instance];
251
+ setState(state) {
252
+ var _a;
253
+ if (!state) {
254
+ delete this.state[this.instance];
267
255
  }
268
256
  else {
269
- this.externalState[this.instance] = state;
257
+ const prevState = this.state[this.instance];
258
+ const newState = {
259
+ ...prevState,
260
+ ...state,
261
+ };
262
+ this.state[this.instance] = newState;
263
+ (_a = this.stateStorage) === null || _a === void 0 ? void 0 : _a.saveState(this, newState);
270
264
  }
271
265
  }
272
- getExternalState() {
273
- return this.externalState[this.instance];
274
- }
275
266
  async validateState(preauthorized = false) {
267
+ var _a;
276
268
  if (!this.features)
277
269
  return;
278
270
  if (!this.features.unlocked && preauthorized) {
@@ -280,32 +272,38 @@ class Device extends utils_1.TypedEmitter {
280
272
  return;
281
273
  }
282
274
  }
283
- const expectedState = this.getExternalState();
275
+ const expectedState = (_a = this.getState()) === null || _a === void 0 ? void 0 : _a.staticSessionId;
284
276
  const state = await this.getCommands().getDeviceState();
285
- const uniqueState = `${state}@${this.features.device_id || 'device_id'}:${this.instance}`;
277
+ const uniqueState = `${state}@${this.features.device_id}:${this.instance}`;
286
278
  if (this.features.session_id) {
287
- this.setInternalState(this.features.session_id);
279
+ this.setState({ sessionId: this.features.session_id });
288
280
  }
289
281
  if (expectedState && expectedState !== uniqueState) {
290
282
  return uniqueState;
291
283
  }
292
284
  if (!expectedState) {
293
- this.setExternalState(uniqueState);
285
+ this.setState({ staticSessionId: uniqueState });
294
286
  }
295
287
  }
296
288
  async initialize(useCardanoDerivation) {
289
+ var _a;
297
290
  let payload;
298
291
  if (this.features) {
299
- const internalState = this.getInternalState();
292
+ const sessionId = (_a = this.getState()) === null || _a === void 0 ? void 0 : _a.sessionId;
300
293
  payload = {};
301
294
  payload.derive_cardano = useCardanoDerivation;
302
- if (internalState) {
303
- payload.session_id = internalState;
295
+ this.useCardanoDerivation = useCardanoDerivation;
296
+ if (sessionId) {
297
+ payload.session_id = sessionId;
304
298
  }
305
299
  }
306
300
  const { message } = await this.getCommands().typedCall('Initialize', 'Features', payload);
307
301
  this._updateFeatures(message);
308
302
  }
303
+ initStorage(storage) {
304
+ this.stateStorage = storage;
305
+ this.setState(storage.loadState(this));
306
+ }
309
307
  async getFeatures() {
310
308
  const { message } = await this.getCommands().typedCall('GetFeatures', 'Features', {});
311
309
  this._updateFeatures(message);
@@ -328,7 +326,7 @@ class Device extends utils_1.TypedEmitter {
328
326
  }
329
327
  async checkFirmwareRevision() {
330
328
  const firmwareVersion = this.getVersion();
331
- if (firmwareVersion.length === 0 || !this.features) {
329
+ if (!firmwareVersion || !this.features) {
332
330
  return;
333
331
  }
334
332
  if (this.features.bootloader_mode === true) {
@@ -352,9 +350,13 @@ class Device extends utils_1.TypedEmitter {
352
350
  if (binary) {
353
351
  return this._uploadTranslationData(binary);
354
352
  }
353
+ const version = this.getVersion();
354
+ if (!version) {
355
+ throw constants_1.ERRORS.TypedError('Runtime', 'changeLanguage: device version unknown');
356
+ }
355
357
  const downloadedBinary = await (0, getLanguage_1.getLanguage)({
356
358
  language,
357
- version: this.getVersion(),
359
+ version,
358
360
  internal_model: this.features.internal_model,
359
361
  });
360
362
  if (!downloadedBinary) {
@@ -398,12 +400,13 @@ class Device extends utils_1.TypedEmitter {
398
400
  if (!feat.internal_model) {
399
401
  feat.internal_model = (0, deviceFeaturesUtils_1.ensureInternalModelFeature)(feat.model);
400
402
  }
401
- const version = [
403
+ const version = this.getVersion();
404
+ const newVersion = [
402
405
  feat.major_version,
403
406
  feat.minor_version,
404
407
  feat.patch_version,
405
408
  ];
406
- if (!utils_1.versionUtils.isEqual(version, this.getVersion())) {
409
+ if (!version || !utils_1.versionUtils.isEqual(version, newVersion)) {
407
410
  this.unavailableCapabilities = (0, deviceFeaturesUtils_1.getUnavailableCapabilities)(feat, (0, coinInfo_1.getAllNetworks)());
408
411
  this.firmwareStatus = (0, firmwareInfo_1.getFirmwareStatus)(feat);
409
412
  this.firmwareRelease = (0, firmwareInfo_1.getRelease)(feat);
@@ -442,7 +445,7 @@ class Device extends utils_1.TypedEmitter {
442
445
  }
443
446
  disconnect() {
444
447
  _log.debug('Disconnect cleanup');
445
- this.activitySessionID = null;
448
+ this.transportSession = null;
446
449
  this.interruptionFromUser(constants_1.ERRORS.TypedError('Device_Disconnected'));
447
450
  delete this.runPromise;
448
451
  }
@@ -460,7 +463,7 @@ class Device extends utils_1.TypedEmitter {
460
463
  }
461
464
  getVersion() {
462
465
  if (!this.features)
463
- return [];
466
+ return;
464
467
  return [
465
468
  this.features.major_version,
466
469
  this.features.minor_version,
@@ -468,16 +471,17 @@ class Device extends utils_1.TypedEmitter {
468
471
  ];
469
472
  }
470
473
  atLeast(versions) {
471
- if (!this.features)
474
+ const version = this.getVersion();
475
+ if (!this.features || !version)
472
476
  return false;
473
477
  const modelVersion = typeof versions === 'string' ? versions : versions[this.features.major_version - 1];
474
- return utils_1.versionUtils.isNewerOrEqual(this.getVersion().join('.'), modelVersion);
478
+ return utils_1.versionUtils.isNewerOrEqual(version, modelVersion);
475
479
  }
476
480
  isUsed() {
477
481
  return typeof this.originalDescriptor.session === 'string';
478
482
  }
479
483
  isUsedHere() {
480
- return this.isUsed() && this.originalDescriptor.session === this.activitySessionID;
484
+ return this.isUsed() && this.originalDescriptor.session === this.transportSession;
481
485
  }
482
486
  isUsedElsewhere() {
483
487
  return this.isUsed() && !this.isUsedHere();
@@ -514,15 +518,23 @@ class Device extends utils_1.TypedEmitter {
514
518
  }
515
519
  return null;
516
520
  }
521
+ updateDescriptor(descriptor) {
522
+ this.originalDescriptor = {
523
+ session: descriptor.session,
524
+ path: descriptor.path,
525
+ product: descriptor.product,
526
+ type: descriptor.type,
527
+ };
528
+ }
517
529
  async dispose() {
518
530
  this.removeAllListeners();
519
- if (this.isUsedHere() && this.activitySessionID) {
531
+ if (this.isUsedHere() && this.transportSession) {
520
532
  try {
521
533
  if (this.commands) {
522
534
  await this.commands.cancel();
523
535
  }
524
536
  return this.transport.release({
525
- session: this.activitySessionID,
537
+ session: this.transportSession,
526
538
  path: this.originalDescriptor.path,
527
539
  onClose: true,
528
540
  });
@@ -541,6 +553,7 @@ class Device extends utils_1.TypedEmitter {
541
553
  return 'normal';
542
554
  }
543
555
  toMessageObject() {
556
+ var _a;
544
557
  if (this.unreadableError) {
545
558
  return {
546
559
  type: 'unreadable',
@@ -565,10 +578,11 @@ class Device extends utils_1.TypedEmitter {
565
578
  status = 'used';
566
579
  return {
567
580
  type: 'acquired',
568
- id: this.features.device_id || null,
581
+ id: this.features.device_id,
569
582
  path: this.originalDescriptor.path,
570
583
  label,
571
- state: this.getExternalState(),
584
+ _state: this.getState(),
585
+ state: (_a = this.getState()) === null || _a === void 0 ? void 0 : _a.staticSessionId,
572
586
  status,
573
587
  mode: this.getMode(),
574
588
  name: this.name,
@@ -5,14 +5,14 @@ import type { CoinInfo, BitcoinNetworkInfo } from '../types';
5
5
  import type { HDNodeResponse } from '../types/api/getPublicKey';
6
6
  type MessageType = Messages.MessageType;
7
7
  type MessageKey = keyof MessageType;
8
- export type TypedResponseMessage<T extends MessageKey> = {
8
+ type TypedPayload<T extends MessageKey> = {
9
9
  type: T;
10
10
  message: MessageType[T];
11
11
  };
12
12
  type TypedCallResponseMap = {
13
- [K in keyof MessageType]: TypedResponseMessage<K>;
13
+ [K in keyof MessageType]: TypedPayload<K>;
14
14
  };
15
- type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
15
+ type DefaultPayloadMessage = TypedCallResponseMap[keyof MessageType];
16
16
  export type PassphrasePromptResponse = {
17
17
  passphrase?: string;
18
18
  passphraseOnDevice?: boolean;
@@ -21,15 +21,15 @@ export type PassphrasePromptResponse = {
21
21
  export declare class DeviceCommands {
22
22
  device: Device;
23
23
  transport: Transport;
24
- sessionId: Session;
24
+ transportSession: Session;
25
25
  disposed: boolean;
26
26
  callPromise?: ReturnType<Transport['call']>;
27
27
  _cancelableRequest?: (error?: any) => void;
28
28
  _cancelableRequestBySend?: boolean;
29
- constructor(device: Device, transport: Transport, sessionId: Session);
29
+ constructor(device: Device, transport: Transport, transportSession: Session);
30
30
  dispose(): void;
31
31
  isDisposed(): boolean;
32
- unlockPath(params?: Messages.UnlockPath): Promise<TypedResponseMessage<"UnlockedPathRequest">>;
32
+ unlockPath(params?: Messages.UnlockPath): Promise<TypedPayload<"UnlockedPathRequest">>;
33
33
  getPublicKey(params: Messages.GetPublicKey, unlockPath?: Messages.UnlockPath): Promise<{
34
34
  descriptor?: string | undefined;
35
35
  root_fingerprint?: number | undefined;
@@ -74,9 +74,9 @@ export declare class DeviceCommands {
74
74
  getDeviceState(): Promise<string>;
75
75
  private call;
76
76
  typedCall<T extends MessageKey, R extends MessageKey[]>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedCallResponseMap[R[number]]>;
77
- typedCall<T extends MessageKey, R extends MessageKey>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedResponseMessage<R>>;
78
- _commonCall(type: MessageKey, msg?: DefaultMessageResponse['message']): Promise<DefaultMessageResponse>;
79
- _filterCommonTypes(res: DefaultMessageResponse): Promise<DefaultMessageResponse>;
77
+ typedCall<T extends MessageKey, R extends MessageKey>(type: T, resType: R, msg?: MessageType[T]): Promise<TypedPayload<R>>;
78
+ _commonCall(type: MessageKey, msg?: DefaultPayloadMessage['message']): Promise<DefaultPayloadMessage>;
79
+ _filterCommonTypes(res: DefaultPayloadMessage): Promise<DefaultPayloadMessage>;
80
80
  private _getAddress;
81
81
  _promptPin(type?: Messages.PinMatrixRequestType): Promise<string>;
82
82
  _promptPassphrase(): Promise<PassphrasePromptResponse>;
@@ -37,10 +37,10 @@ const filterForLog = (type, msg) => {
37
37
  return msg;
38
38
  };
39
39
  class DeviceCommands {
40
- constructor(device, transport, sessionId) {
40
+ constructor(device, transport, transportSession) {
41
41
  this.device = device;
42
42
  this.transport = transport;
43
- this.sessionId = sessionId;
43
+ this.transportSession = transportSession;
44
44
  this.disposed = false;
45
45
  }
46
46
  dispose() {
@@ -203,12 +203,12 @@ class DeviceCommands {
203
203
  async call(type, msg = {}) {
204
204
  logger.debug('Sending', type, filterForLog(type, msg));
205
205
  this.callPromise = this.transport.call({
206
- session: this.sessionId,
206
+ session: this.transportSession,
207
207
  name: type,
208
208
  data: msg,
209
209
  protocol: this.device.protocol,
210
210
  });
211
- const res = await this.callPromise.promise;
211
+ const res = await this.callPromise;
212
212
  this.callPromise = undefined;
213
213
  if (!res.success) {
214
214
  logger.warn('Received error', res.error);
@@ -228,9 +228,9 @@ class DeviceCommands {
228
228
  }
229
229
  catch (error) {
230
230
  await this.transport.receive({
231
- session: this.sessionId,
231
+ session: this.transportSession,
232
232
  protocol: this.device.protocol,
233
- }).promise;
233
+ });
234
234
  throw error;
235
235
  }
236
236
  return response;
@@ -422,7 +422,7 @@ class DeviceCommands {
422
422
  this.dispose();
423
423
  if (!this._cancelableRequestBySend) {
424
424
  if (this.callPromise) {
425
- await this.callPromise.promise;
425
+ await this.callPromise;
426
426
  }
427
427
  return;
428
428
  }
@@ -437,12 +437,12 @@ class DeviceCommands {
437
437
  else {
438
438
  await this.transport.send({
439
439
  protocol: this.device.protocol,
440
- session: this.sessionId,
440
+ session: this.transportSession,
441
441
  name: 'Cancel',
442
442
  data: {},
443
- }).promise;
443
+ });
444
444
  if (this.callPromise) {
445
- await this.callPromise.promise;
445
+ await this.callPromise;
446
446
  }
447
447
  }
448
448
  }
@@ -97,82 +97,66 @@ class DeviceList extends utils_1.TypedEmitter {
97
97
  this.transports = transportTypes.map(this.createTransport.bind(this));
98
98
  }
99
99
  onTransportUpdate(diff, transport) {
100
- diff.disconnected.forEach(descriptor => {
101
- const path = descriptor.path.toString();
102
- const device = this.devices[path];
103
- if (device) {
104
- device.disconnect();
105
- delete this.devices[path];
106
- this.emit(events_1.DEVICE.DISCONNECT, device.toMessageObject());
107
- }
108
- });
109
- diff.connected.forEach(async (descriptor) => {
110
- const path = descriptor.path.toString();
111
- this.creatingDevicesDescriptors[path] = descriptor;
112
- const penalty = this.authPenaltyManager.get();
113
- if (penalty) {
114
- await (0, promiseUtils_1.resolveAfter)(501 + penalty, null).promise;
115
- }
116
- if (this.creatingDevicesDescriptors[path].session == null) {
117
- await this._createAndSaveDevice(descriptor, transport);
118
- }
119
- else {
120
- const device = this._createUnacquiredDevice(descriptor, transport);
121
- this.devices[path] = device;
122
- this.emit(events_1.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
123
- }
124
- });
125
- diff.acquiredElsewhere.forEach((descriptor) => {
126
- const path = descriptor.path.toString();
127
- const device = this.devices[path];
128
- if (device) {
129
- device.featuresNeedsReload = true;
130
- device.interruptionFromOutside();
131
- }
132
- });
133
- diff.released.forEach(descriptor => {
100
+ diff.forEach(async ({ descriptor, ...category }) => {
134
101
  var _a;
135
102
  const path = descriptor.path.toString();
136
103
  const device = this.devices[path];
137
- const methodStillRunning = !((_a = device === null || device === void 0 ? void 0 : device.commands) === null || _a === void 0 ? void 0 : _a.isDisposed());
138
- if (device && methodStillRunning) {
139
- device.keepSession = false;
140
- }
141
- });
142
- diff.releasedElsewhere.forEach(async (descriptor) => {
143
- const path = descriptor.path.toString();
144
- const device = this.devices[path];
145
- await (0, promiseUtils_1.resolveAfter)(1000, null).promise;
146
- if (device) {
147
- if (!device.isUsed() && device.isUnacquired() && !device.isInconsistent()) {
148
- _log.debug('Create device from unacquired', device.toMessageObject());
149
- await this._createAndSaveDevice(descriptor, transport);
150
- }
151
- }
152
- });
153
- const forEachDescriptor = (d, e) => {
154
- d.forEach(descriptor => {
155
- const path = descriptor.path.toString();
156
- const device = this.devices[path];
157
- if (device) {
158
- _log.debug('Event', e, device.toMessageObject());
159
- this.emit(e, device.toMessageObject());
160
- }
161
- });
162
- };
163
- forEachDescriptor(diff.changedSessions, events_1.DEVICE.CHANGED);
164
- forEachDescriptor(diff.acquired, events_1.DEVICE.ACQUIRED);
165
- forEachDescriptor(diff.released, events_1.DEVICE.RELEASED);
166
- diff.descriptors.forEach(d => {
167
- this.creatingDevicesDescriptors[d.path] = d;
168
- if (this.devices[d.path]) {
169
- this.devices[d.path].originalDescriptor = {
170
- session: d.session,
171
- path: d.path,
172
- product: d.product,
173
- type: d.type,
174
- };
104
+ this.creatingDevicesDescriptors[path] = descriptor;
105
+ switch (category.type) {
106
+ case 'disconnected':
107
+ if (!device)
108
+ break;
109
+ device.disconnect();
110
+ delete this.devices[path];
111
+ this.emit(events_1.DEVICE.DISCONNECT, device.toMessageObject());
112
+ break;
113
+ case 'connected':
114
+ const penalty = this.authPenaltyManager.get();
115
+ if (penalty) {
116
+ await (0, promiseUtils_1.resolveAfter)(501 + penalty, null).promise;
117
+ }
118
+ if (this.creatingDevicesDescriptors[path].session == null) {
119
+ await this._createAndSaveDevice(descriptor, transport);
120
+ }
121
+ else {
122
+ const device = this._createUnacquiredDevice(descriptor, transport);
123
+ this.devices[path] = device;
124
+ this.emit(events_1.DEVICE.CONNECT_UNACQUIRED, device.toMessageObject());
125
+ }
126
+ break;
127
+ case 'acquired':
128
+ if (!device)
129
+ break;
130
+ if (category.subtype === 'elsewhere') {
131
+ device.featuresNeedsReload = true;
132
+ device.interruptionFromOutside();
133
+ }
134
+ _log.debug('Event', events_1.DEVICE.CHANGED, device.toMessageObject());
135
+ this.emit(events_1.DEVICE.CHANGED, device.toMessageObject());
136
+ _log.debug('Event', events_1.DEVICE.ACQUIRED, device.toMessageObject());
137
+ this.emit(events_1.DEVICE.ACQUIRED, device.toMessageObject());
138
+ break;
139
+ case 'released':
140
+ if (!device)
141
+ break;
142
+ const methodStillRunning = !((_a = device.commands) === null || _a === void 0 ? void 0 : _a.isDisposed());
143
+ if (methodStillRunning) {
144
+ device.keepTransportSession = false;
145
+ }
146
+ _log.debug('Event', events_1.DEVICE.CHANGED, device.toMessageObject());
147
+ this.emit(events_1.DEVICE.CHANGED, device.toMessageObject());
148
+ _log.debug('Event', events_1.DEVICE.RELEASED, device.toMessageObject());
149
+ this.emit(events_1.DEVICE.RELEASED, device.toMessageObject());
150
+ if (category.subtype === 'elsewhere') {
151
+ await (0, promiseUtils_1.resolveAfter)(1000, null).promise;
152
+ if (!device.isUsed() && device.isUnacquired() && !device.isInconsistent()) {
153
+ _log.debug('Create device from unacquired', device.toMessageObject());
154
+ await this._createAndSaveDevice(descriptor, transport);
155
+ }
156
+ }
157
+ break;
175
158
  }
159
+ device === null || device === void 0 ? void 0 : device.updateDescriptor(descriptor);
176
160
  });
177
161
  }
178
162
  init(initParams = {}) {
@@ -204,7 +188,7 @@ class DeviceList extends utils_1.TypedEmitter {
204
188
  return promise.then(this.createInitPromise.bind(this));
205
189
  }
206
190
  async selectTransport([transport, ...rest]) {
207
- const result = await transport.init().promise;
191
+ const result = await transport.init();
208
192
  if (result.success)
209
193
  return transport;
210
194
  else if (rest.length)
@@ -221,7 +205,7 @@ class DeviceList extends utils_1.TypedEmitter {
221
205
  this.initPromise = this.createReconnectPromise(initParams);
222
206
  }
223
207
  });
224
- const enumerateResult = await transport.enumerate().promise;
208
+ const enumerateResult = await transport.enumerate();
225
209
  if (!enumerateResult.success) {
226
210
  throw new Error(enumerateResult.error);
227
211
  }
@@ -314,19 +298,13 @@ class DeviceList extends utils_1.TypedEmitter {
314
298
  transport === null || transport === void 0 ? void 0 : transport.stop();
315
299
  }
316
300
  async enumerate(transport = this.transport) {
317
- const res = await transport.enumerate().promise;
301
+ const res = await transport.enumerate();
318
302
  if (!res.success) {
319
303
  return;
320
304
  }
321
305
  res.payload.forEach(d => {
322
306
  if (this.devices[d.path]) {
323
- this.devices[d.path].originalDescriptor = {
324
- session: d.session,
325
- path: d.path,
326
- product: d.product,
327
- type: d.type,
328
- };
329
- this.devices[d.path].activitySessionID = d.session;
307
+ this.devices[d.path].updateDescriptor(d);
330
308
  }
331
309
  });
332
310
  }
@@ -371,7 +349,6 @@ class DeviceList extends utils_1.TypedEmitter {
371
349
  await this.handle(descriptor, transport);
372
350
  }
373
351
  }
374
- delete this.creatingDevicesDescriptors[path];
375
352
  }
376
353
  async _takeAndCreateDevice(descriptor, transport) {
377
354
  const device = Device_1.Device.fromDescriptor(transport, descriptor);