@onekeyfe/hd-web-sdk 0.1.16 → 0.1.19

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.
@@ -4096,8 +4096,9 @@ const inject = ({
4096
4096
  checkBridgeStatus: () => call({
4097
4097
  method: 'checkBridgeStatus'
4098
4098
  }),
4099
- cipherKeyValue: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4099
+ cipherKeyValue: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4100
4100
  connectId,
4101
+ deviceId,
4101
4102
  method: 'cipherKeyValue'
4102
4103
  })),
4103
4104
  deviceBackup: connectId => call({
@@ -4140,96 +4141,119 @@ const inject = ({
4140
4141
  connectId,
4141
4142
  method: 'deviceWipe'
4142
4143
  }),
4143
- evmGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4144
+ evmGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4144
4145
  connectId,
4146
+ deviceId,
4145
4147
  method: 'evmGetAddress'
4146
4148
  })),
4147
- evmGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4149
+ evmGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4148
4150
  connectId,
4151
+ deviceId,
4149
4152
  method: 'evmGetPublicKey'
4150
4153
  })),
4151
- evmSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4154
+ evmSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4152
4155
  connectId,
4156
+ deviceId,
4153
4157
  method: 'evmSignMessage'
4154
4158
  })),
4155
- evmSignMessageEIP712: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4159
+ evmSignMessageEIP712: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4156
4160
  connectId,
4161
+ deviceId,
4157
4162
  method: 'evmSignMessageEIP712'
4158
4163
  })),
4159
- evmSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4164
+ evmSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4160
4165
  connectId,
4166
+ deviceId,
4161
4167
  method: 'evmSignTransaction'
4162
4168
  })),
4163
- evmSignTypedData: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4169
+ evmSignTypedData: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4164
4170
  connectId,
4171
+ deviceId,
4165
4172
  method: 'evmSignTypedData'
4166
4173
  })),
4167
- evmVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4174
+ evmVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4168
4175
  connectId,
4176
+ deviceId,
4169
4177
  method: 'evmVerifyMessage'
4170
4178
  })),
4171
- btcGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4179
+ btcGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4172
4180
  connectId,
4181
+ deviceId,
4173
4182
  method: 'btcGetAddress'
4174
4183
  })),
4175
- btcGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4184
+ btcGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4176
4185
  connectId,
4186
+ deviceId,
4177
4187
  method: 'btcGetPublicKey'
4178
4188
  })),
4179
- btcSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4189
+ btcSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4180
4190
  connectId,
4191
+ deviceId,
4181
4192
  method: 'btcSignMessage'
4182
4193
  })),
4183
- btcSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4194
+ btcSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4184
4195
  connectId,
4196
+ deviceId,
4185
4197
  method: 'btcSignTransaction'
4186
4198
  })),
4187
- btcVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4199
+ btcVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4188
4200
  connectId,
4201
+ deviceId,
4189
4202
  method: 'btcVerifyMessage'
4190
4203
  })),
4191
- starcoinGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4204
+ starcoinGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4192
4205
  connectId,
4206
+ deviceId,
4193
4207
  method: 'starcoinGetAddress'
4194
4208
  })),
4195
- starcoinGetPublicKey: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4209
+ starcoinGetPublicKey: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4196
4210
  connectId,
4211
+ deviceId,
4197
4212
  method: 'starcoinGetPublicKey'
4198
4213
  })),
4199
- starcoinSignMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4214
+ starcoinSignMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4200
4215
  connectId,
4216
+ deviceId,
4201
4217
  method: 'starcoinSignMessage'
4202
4218
  })),
4203
- starcoinSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4219
+ starcoinSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4204
4220
  connectId,
4221
+ deviceId,
4205
4222
  method: 'starcoinSignTransaction'
4206
4223
  })),
4207
- starcoinVerifyMessage: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4224
+ starcoinVerifyMessage: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4208
4225
  connectId,
4226
+ deviceId,
4209
4227
  method: 'starcoinVerifyMessage'
4210
4228
  })),
4211
- nemGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4229
+ nemGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4212
4230
  connectId,
4231
+ deviceId,
4213
4232
  method: 'nemGetAddress'
4214
4233
  })),
4215
- nemSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4234
+ nemSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4216
4235
  connectId,
4236
+ deviceId,
4217
4237
  method: 'nemSignTransaction'
4218
4238
  })),
4219
- solGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4239
+ solGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4220
4240
  connectId,
4241
+ deviceId,
4221
4242
  method: 'solGetAddress'
4222
4243
  })),
4223
- solSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4244
+ solSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4224
4245
  connectId,
4246
+ deviceId,
4225
4247
  method: 'solSignTransaction'
4226
4248
  })),
4227
- stellarGetAddress: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4249
+ stellarGetAddress: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4228
4250
  connectId,
4251
+ deviceId,
4229
4252
  method: 'stellarGetAddress'
4230
4253
  })),
4231
- stellarSignTransaction: (connectId, params) => call(Object.assign(Object.assign({}, params), {
4254
+ stellarSignTransaction: (connectId, deviceId, params) => call(Object.assign(Object.assign({}, params), {
4232
4255
  connectId,
4256
+ deviceId,
4233
4257
  method: 'stellarSignTransaction'
4234
4258
  })),
4235
4259
  firmwareUpdate: (connectId, params) => call(Object.assign(Object.assign({}, params), {
@@ -13805,45 +13829,45 @@ class Log$6 {
13805
13829
 
13806
13830
  log(...args) {
13807
13831
  this.addMessage('log', this.prefix, ...args);
13832
+ sendLogMessage(this.prefix, ...args);
13808
13833
 
13809
13834
  if (!this.enabled) {
13810
13835
  return;
13811
13836
  }
13812
13837
 
13813
- sendLogMessage(this.prefix, ...args);
13814
13838
  console.log(this.prefix, ...args);
13815
13839
  }
13816
13840
 
13817
13841
  error(...args) {
13818
13842
  this.addMessage('error', this.prefix, ...args);
13843
+ sendLogMessage(this.prefix, ...args);
13819
13844
 
13820
13845
  if (!this.enabled) {
13821
13846
  return;
13822
13847
  }
13823
13848
 
13824
- sendLogMessage(this.prefix, ...args);
13825
13849
  console.error(this.prefix, ...args);
13826
13850
  }
13827
13851
 
13828
13852
  warn(...args) {
13829
13853
  this.addMessage('warn', this.prefix, ...args);
13854
+ sendLogMessage(this.prefix, ...args);
13830
13855
 
13831
13856
  if (!this.enabled) {
13832
13857
  return;
13833
13858
  }
13834
13859
 
13835
- sendLogMessage(this.prefix, ...args);
13836
13860
  console.warn(this.prefix, ...args);
13837
13861
  }
13838
13862
 
13839
13863
  debug(...args) {
13840
13864
  this.addMessage('debug', this.prefix, ...args);
13865
+ sendLogMessage(this.prefix, ...args);
13841
13866
 
13842
13867
  if (!this.enabled) {
13843
13868
  return;
13844
13869
  }
13845
13870
 
13846
- sendLogMessage(this.prefix, ...args);
13847
13871
  console.log(this.prefix, ...args);
13848
13872
  }
13849
13873
 
@@ -14326,7 +14350,8 @@ const DEVICE = {
14326
14350
  PIN: 'pin',
14327
14351
  PASSPHRASE: 'passphrase',
14328
14352
  PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
14329
- WORD: 'word'
14353
+ WORD: 'word',
14354
+ FEATURES: 'features'
14330
14355
  };
14331
14356
 
14332
14357
  const createDeviceMessage = (type, payload) => ({
@@ -14335,6 +14360,18 @@ const createDeviceMessage = (type, payload) => ({
14335
14360
  payload
14336
14361
  });
14337
14362
 
14363
+ const FIRMWARE_EVENT = 'FIRMWARE_EVENT';
14364
+ const FIRMWARE = {
14365
+ RELEASE_INFO: 'firmware-release-info',
14366
+ BLE_RELEASE_INFO: 'ble-firmware-release-info'
14367
+ };
14368
+
14369
+ const createFirmwareMessage = (type, payload) => ({
14370
+ event: FIRMWARE_EVENT,
14371
+ type,
14372
+ payload
14373
+ });
14374
+
14338
14375
  const assertType = (res, resType) => {
14339
14376
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14340
14377
 
@@ -14353,17 +14390,19 @@ class DeviceCommands {
14353
14390
  this.disposed = false;
14354
14391
  }
14355
14392
 
14356
- dispose() {
14393
+ dispose(cancelRequest) {
14357
14394
  var _a, _b;
14358
14395
 
14359
- this.disposed = true;
14396
+ return __awaiter(this, void 0, void 0, function* () {
14397
+ this.disposed = true;
14360
14398
 
14361
- if (this._cancelableRequest) {
14362
- this._cancelableRequest();
14363
- }
14399
+ if (cancelRequest && this._cancelableRequest) {
14400
+ this._cancelableRequest();
14401
+ }
14364
14402
 
14365
- this._cancelableRequest = undefined;
14366
- (_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
14403
+ this._cancelableRequest = undefined;
14404
+ yield (_b = (_a = this.transport).cancel) === null || _b === void 0 ? void 0 : _b.call(_a);
14405
+ });
14367
14406
  }
14368
14407
 
14369
14408
  call(type, msg = {}) {
@@ -14491,7 +14530,12 @@ class DeviceCommands {
14491
14530
  }, () => this._commonCall('Cancel', {}));
14492
14531
  }
14493
14532
 
14494
- if (res.type === 'PassphraseRequest') ;
14533
+ if (res.type === 'PassphraseRequest') {
14534
+ return this._commonCall('PassphraseAck', {
14535
+ passphrase: ''
14536
+ });
14537
+ }
14538
+
14495
14539
  if (res.type === 'Deprecated_PassphraseStateRequest') ;
14496
14540
  if (res.type === 'WordRequest') ;
14497
14541
  return Promise.resolve(res);
@@ -14729,7 +14773,7 @@ class Device extends events.exports {
14729
14773
  });
14730
14774
 
14731
14775
  if (this.commands) {
14732
- this.commands.dispose();
14776
+ yield this.commands.dispose(false);
14733
14777
  }
14734
14778
 
14735
14779
  this.commands = new DeviceCommands(this, (_d = this.mainId) !== null && _d !== void 0 ? _d : '');
@@ -14753,7 +14797,7 @@ class Device extends events.exports {
14753
14797
 
14754
14798
  if (this.isUsedHere() && !this.keepSession && this.mainId || this.mainId && env === 'react-native') {
14755
14799
  if (this.commands) {
14756
- this.commands.dispose();
14800
+ this.commands.dispose(false);
14757
14801
 
14758
14802
  if (this.commands.callPromise) {
14759
14803
  try {
@@ -14825,6 +14869,7 @@ class Device extends events.exports {
14825
14869
  feat.unlocked = feat.unlocked || true;
14826
14870
  this.features = feat;
14827
14871
  this.featuresNeedsReload = false;
14872
+ this.emit(DEVICE.FEATURES, this, feat);
14828
14873
  }
14829
14874
 
14830
14875
  updateDescriptor(descriptor, forceUpdate = false) {
@@ -14859,7 +14904,7 @@ class Device extends events.exports {
14859
14904
  run(fn, options) {
14860
14905
  return __awaiter(this, void 0, void 0, function* () {
14861
14906
  if (this.runPromise) {
14862
- this.interruption();
14907
+ yield this.interruptionFromOutside();
14863
14908
  Log$3.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
14864
14909
  }
14865
14910
 
@@ -14906,14 +14951,28 @@ class Device extends events.exports {
14906
14951
  });
14907
14952
  }
14908
14953
 
14909
- interruption() {
14910
- if (this.commands) {
14911
- this.commands.dispose();
14912
- }
14954
+ interruptionFromOutside() {
14955
+ return __awaiter(this, void 0, void 0, function* () {
14956
+ if (this.commands) {
14957
+ yield this.commands.dispose(false);
14958
+ }
14913
14959
 
14914
- if (this.runPromise) {
14915
- this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
14916
- }
14960
+ if (this.runPromise) {
14961
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
14962
+ }
14963
+ });
14964
+ }
14965
+
14966
+ interruptionFromUser() {
14967
+ return __awaiter(this, void 0, void 0, function* () {
14968
+ if (this.commands) {
14969
+ yield this.commands.dispose(true);
14970
+ }
14971
+
14972
+ if (this.runPromise) {
14973
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser));
14974
+ }
14975
+ });
14917
14976
  }
14918
14977
 
14919
14978
  getMode() {
@@ -14991,9 +15050,17 @@ class Device extends events.exports {
14991
15050
  return null;
14992
15051
  }
14993
15052
 
15053
+ checkDeviceId(deviceId) {
15054
+ if (this.features) {
15055
+ return this.features.device_id === deviceId;
15056
+ }
15057
+
15058
+ return false;
15059
+ }
15060
+
14994
15061
  }
14995
15062
 
14996
- const cacheDeviceMap = new Map();
15063
+ const cacheDeviceMap = {};
14997
15064
  const Log$2 = getLogger(exports.d0.DeviceList);
14998
15065
 
14999
15066
  class DeviceList extends events.exports {
@@ -15002,7 +15069,7 @@ class DeviceList extends events.exports {
15002
15069
  this.devices = {};
15003
15070
  }
15004
15071
 
15005
- getDeviceLists() {
15072
+ getDeviceLists(connectId) {
15006
15073
  var e_1, _a;
15007
15074
 
15008
15075
  var _b, _c;
@@ -15014,6 +15081,21 @@ class DeviceList extends events.exports {
15014
15081
  const deviceList = [];
15015
15082
  Log$2.debug('get device list');
15016
15083
 
15084
+ if (connectId) {
15085
+ const device = cacheDeviceMap[connectId];
15086
+
15087
+ if (device) {
15088
+ const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
15089
+
15090
+ if (exist) {
15091
+ device.updateDescriptor(exist, true);
15092
+ Log$2.debug('find existed Device: ', connectId);
15093
+ this.devices[connectId] = device;
15094
+ return [device];
15095
+ }
15096
+ }
15097
+ }
15098
+
15017
15099
  try {
15018
15100
  for (var descriptorList_1 = __asyncValues(descriptorList), descriptorList_1_1; descriptorList_1_1 = yield descriptorList_1.next(), !descriptorList_1_1.done;) {
15019
15101
  const descriptor = descriptorList_1_1.value;
@@ -15027,15 +15109,14 @@ class DeviceList extends events.exports {
15027
15109
  if (device.features) {
15028
15110
  const uuid = getDeviceUUID(device.features);
15029
15111
 
15030
- if (cacheDeviceMap.has(uuid)) {
15031
- const cache = cacheDeviceMap.get(uuid);
15112
+ if (cacheDeviceMap[uuid]) {
15113
+ const cache = cacheDeviceMap[uuid];
15032
15114
  cache === null || cache === void 0 ? void 0 : cache.updateFromCache(device);
15033
15115
  device = cache;
15034
- Log$2.debug('use cache device: ', uuid);
15035
15116
  }
15036
15117
 
15037
15118
  this.devices[uuid] = device;
15038
- cacheDeviceMap.set(uuid, device);
15119
+ cacheDeviceMap[uuid] = device;
15039
15120
  }
15040
15121
  }
15041
15122
  } catch (e_1_1) {
@@ -15064,8 +15145,32 @@ class DeviceList extends events.exports {
15064
15145
 
15065
15146
  }
15066
15147
 
15148
+ const getFirmwareReleaseInfo = features => {
15149
+ const firmwareStatus = DataManager.getFirmwareStatus(features);
15150
+ const changelog = DataManager.getFirmwareChangelog(features);
15151
+ const release = DataManager.getFirmwareLeatestRelease(features);
15152
+ return {
15153
+ status: firmwareStatus,
15154
+ changelog,
15155
+ release
15156
+ };
15157
+ };
15158
+
15159
+ const getBleFirmwareReleaseInfo = features => {
15160
+ const firmwareStatus = DataManager.getBLEFirmwareStatus(features);
15161
+ const changelog = DataManager.getBleFirmwareChangelog(features);
15162
+ const release = DataManager.getBleFirmwareLeatestRelease(features);
15163
+ return {
15164
+ status: firmwareStatus,
15165
+ changelog,
15166
+ release
15167
+ };
15168
+ };
15169
+
15067
15170
  class BaseMethod {
15068
15171
  constructor(message) {
15172
+ this.shouldEnsureConnected = true;
15173
+ this.checkDeviceId = false;
15069
15174
  const {
15070
15175
  payload
15071
15176
  } = message;
@@ -15073,6 +15178,7 @@ class BaseMethod {
15073
15178
  this.payload = payload;
15074
15179
  this.responseID = message.id || 0;
15075
15180
  this.connectId = payload.connectId || '';
15181
+ this.deviceId = payload.deviceId || '';
15076
15182
  this.useDevice = true;
15077
15183
  this.allowDeviceMode = [UI_REQUEST.INITIALIZE];
15078
15184
  this.requireDeviceMode = [];
@@ -15087,6 +15193,21 @@ class BaseMethod {
15087
15193
  this.connectId = device.originalDescriptor.path;
15088
15194
  }
15089
15195
 
15196
+ checkFirmwareRelease() {
15197
+ if (!this.device || !this.device.features) return;
15198
+ const releaseInfo = getFirmwareReleaseInfo(this.device.features);
15199
+
15200
+ if (['outdated', 'required'].includes(releaseInfo.status)) {
15201
+ this.postMessage(createFirmwareMessage(FIRMWARE.RELEASE_INFO, releaseInfo));
15202
+ }
15203
+
15204
+ const bleReleaseInfo = getBleFirmwareReleaseInfo(this.device.features);
15205
+
15206
+ if (['outdated', 'required'].includes(bleReleaseInfo.status)) {
15207
+ this.postMessage(createFirmwareMessage(FIRMWARE.BLE_RELEASE_INFO, bleReleaseInfo));
15208
+ }
15209
+ }
15210
+
15090
15211
  dispose() {}
15091
15212
 
15092
15213
  }
@@ -16416,14 +16537,8 @@ class CheckFirmwareRelease extends BaseMethod {
16416
16537
 
16417
16538
  run() {
16418
16539
  if (this.device.features) {
16419
- const firmwareStatus = DataManager.getFirmwareStatus(this.device.features);
16420
- const changelog = DataManager.getFirmwareChangelog(this.device.features);
16421
- const release = DataManager.getFirmwareLeatestRelease(this.device.features);
16422
- return Promise.resolve({
16423
- status: firmwareStatus,
16424
- changelog,
16425
- release
16426
- });
16540
+ const releaseInfo = getFirmwareReleaseInfo(this.device.features);
16541
+ return Promise.resolve(releaseInfo);
16427
16542
  }
16428
16543
 
16429
16544
  return Promise.resolve(null);
@@ -16434,18 +16549,13 @@ class CheckFirmwareRelease extends BaseMethod {
16434
16549
  class CheckBLEFirmwareRelease extends BaseMethod {
16435
16550
  init() {
16436
16551
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
16552
+ this.checkDeviceId = true;
16437
16553
  }
16438
16554
 
16439
16555
  run() {
16440
16556
  if (this.device.features) {
16441
- const firmwareStatus = DataManager.getBLEFirmwareStatus(this.device.features);
16442
- const changelog = DataManager.getBleFirmwareChangelog(this.device.features);
16443
- const release = DataManager.getBleFirmwareLeatestRelease(this.device.features);
16444
- return Promise.resolve({
16445
- status: firmwareStatus,
16446
- changelog,
16447
- release
16448
- });
16557
+ const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
16558
+ return Promise.resolve(releaseInfo);
16449
16559
  }
16450
16560
 
16451
16561
  return Promise.resolve(null);
@@ -18806,6 +18916,10 @@ function findMethod(message) {
18806
18916
  const safeThrowError = error => {
18807
18917
  if (error instanceof hdShared.HardwareError) {
18808
18918
  throw error;
18919
+ } else if (error.code === 'ERR_NETWORK') {
18920
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
18921
+ } else if (error.code === 'ECONNABORTED') {
18922
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
18809
18923
  } else {
18810
18924
  throw hdShared.ERRORS.TypedError(error);
18811
18925
  }
@@ -18983,7 +19097,10 @@ let _uiPromises = [];
18983
19097
 
18984
19098
  let _callPromise;
18985
19099
 
19100
+ const callApiQueue = [];
18986
19101
  const deviceCacheMap = new Map();
19102
+ let pollingId = 1;
19103
+ const pollingState = {};
18987
19104
 
18988
19105
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18989
19106
  var _a;
@@ -19015,23 +19132,25 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19015
19132
  }
19016
19133
  }
19017
19134
 
19018
- try {
19019
- yield initDeviceList(method);
19020
- } catch (error) {
19021
- return Promise.reject(error);
19135
+ callApiQueue.push(method);
19136
+
19137
+ if (callApiQueue.length > 1) {
19138
+ Log.debug('should cancel the previous method execution: ', callApiQueue);
19022
19139
  }
19023
19140
 
19024
- const env = DataManager.getSettings('env');
19141
+ if (pollingState[pollingId]) {
19142
+ pollingState[pollingId] = false;
19143
+ }
19144
+
19145
+ pollingId += 1;
19025
19146
  let device;
19026
19147
 
19027
19148
  try {
19028
- if (env === 'react-native') {
19029
- device = initDeviceForBle(method);
19030
- } else {
19031
- device = initDevice(method);
19032
- }
19033
- } catch (error) {
19034
- return Promise.reject(error);
19149
+ device = yield ensureConnected(method, pollingId);
19150
+ } catch (e) {
19151
+ return createResponseMessage(method.responseID, false, {
19152
+ error: e
19153
+ });
19035
19154
  }
19036
19155
 
19037
19156
  Log.debug('Call API - setDevice: ', device.mainId);
@@ -19040,6 +19159,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19040
19159
  device.on(DEVICE.BUTTON, (d, code) => {
19041
19160
  onDeviceButtonHandler(d, code);
19042
19161
  });
19162
+ device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
19043
19163
 
19044
19164
  try {
19045
19165
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -19071,6 +19191,16 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19071
19191
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
19072
19192
  }
19073
19193
 
19194
+ if (method.deviceId && method.checkDeviceId) {
19195
+ const isSameDeviceID = device.checkDeviceId(method.deviceId);
19196
+
19197
+ if (!isSameDeviceID) {
19198
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError));
19199
+ }
19200
+ }
19201
+
19202
+ method.checkFirmwareRelease();
19203
+
19074
19204
  if (_deviceList) {
19075
19205
  yield TransportManager.reconfigure(device.getFirmwareVersion());
19076
19206
  }
@@ -19118,6 +19248,13 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19118
19248
  }
19119
19249
  }
19120
19250
 
19251
+ const index = messageResponse && messageResponse.id ? callApiQueue.findIndex(m => m.responseID === messageResponse.id) : -1;
19252
+
19253
+ if (index > -1) {
19254
+ callApiQueue.splice(index, 1);
19255
+ Log.debug('Remove the finished method from the queue: ', callApiQueue);
19256
+ }
19257
+
19121
19258
  closePopup();
19122
19259
  cleanup();
19123
19260
  }
@@ -19138,7 +19275,7 @@ function initDeviceList(method) {
19138
19275
  _deviceList.connector = _connector;
19139
19276
  }
19140
19277
 
19141
- yield _deviceList.getDeviceLists();
19278
+ yield _deviceList.getDeviceLists(method.connectId);
19142
19279
  });
19143
19280
  }
19144
19281
 
@@ -19191,23 +19328,118 @@ function initDeviceForBle(method) {
19191
19328
  return device;
19192
19329
  }
19193
19330
 
19331
+ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0, function* () {
19332
+ let tryCount = 0;
19333
+ const MAX_RETRY_COUNT = method.payload && method.payload.retryCount || 5;
19334
+ const POLL_INTERVAL_TIME = method.payload && method.payload.pollIntervalTime || 1000;
19335
+ const TIME_OUT = method.payload && method.payload.timeout || 10000;
19336
+ let timer = null;
19337
+ Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
19338
+
19339
+ const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
19340
+ return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
19341
+ if (!pollingState[pollingId]) {
19342
+ Log.debug('EnsureConnected function stop, polling id: ', pollingId);
19343
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
19344
+ return;
19345
+ }
19346
+
19347
+ if (timer) {
19348
+ clearTimeout(timer);
19349
+ }
19350
+
19351
+ timer = setTimeout(() => {
19352
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingTimeout));
19353
+ }, TIME_OUT);
19354
+ tryCount += 1;
19355
+ Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
19356
+
19357
+ try {
19358
+ yield initDeviceList(method);
19359
+ } catch (error) {
19360
+ Log.debug('device list error: ', error);
19361
+
19362
+ if (error.errorCode === hdShared.HardwareErrorCode.BridgeNotInstalled) {
19363
+ reject(error);
19364
+ return;
19365
+ }
19366
+
19367
+ if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
19368
+ yield TransportManager.configure();
19369
+ }
19370
+ }
19371
+
19372
+ const env = DataManager.getSettings('env');
19373
+ let device;
19374
+
19375
+ try {
19376
+ if (env === 'react-native') {
19377
+ device = initDeviceForBle(method);
19378
+ } else {
19379
+ device = initDevice(method);
19380
+ }
19381
+
19382
+ if (device) {
19383
+ if (timer) {
19384
+ clearTimeout(timer);
19385
+ }
19386
+
19387
+ if (env === 'react-native') {
19388
+ yield device.acquire();
19389
+ yield device.initialize();
19390
+ }
19391
+
19392
+ resolve(device);
19393
+ return;
19394
+ }
19395
+ } catch (error) {
19396
+ Log.debug('device error: ', error);
19397
+
19398
+ if (error.errorCode === hdShared.HardwareErrorCode.BlePermissionError) {
19399
+ reject(error);
19400
+ return;
19401
+ }
19402
+ }
19403
+
19404
+ if (tryCount > 5) {
19405
+ if (timer) {
19406
+ clearTimeout(timer);
19407
+ }
19408
+
19409
+ Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
19410
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
19411
+ return;
19412
+ }
19413
+
19414
+ return setTimeout(() => resolve(poll(time * 1.5)), time);
19415
+ }));
19416
+ });
19417
+
19418
+ pollingState[pollingId] = true;
19419
+ return poll();
19420
+ });
19421
+
19194
19422
  const cancel = connectId => {
19195
19423
  const env = DataManager.getSettings('env');
19196
19424
 
19197
- if (connectId) {
19198
- let device;
19425
+ try {
19426
+ if (connectId) {
19427
+ let device;
19199
19428
 
19200
- if (env === 'react-native') {
19201
- device = initDeviceForBle({
19202
- connectId
19203
- });
19204
- } else {
19205
- device = initDevice({
19206
- connectId
19207
- });
19208
- }
19429
+ if (env === 'react-native') {
19430
+ device = initDeviceForBle({
19431
+ connectId
19432
+ });
19433
+ } else {
19434
+ device = initDevice({
19435
+ connectId
19436
+ });
19437
+ }
19209
19438
 
19210
- device === null || device === void 0 ? void 0 : device.interruption();
19439
+ device === null || device === void 0 ? void 0 : device.interruptionFromUser();
19440
+ }
19441
+ } catch (e) {
19442
+ Log.error('Cancel API Error: ', e);
19211
19443
  }
19212
19444
 
19213
19445
  cleanup();
@@ -19251,6 +19483,10 @@ const onDeviceButtonHandler = (...[device, request]) => {
19251
19483
  }
19252
19484
  };
19253
19485
 
19486
+ const onDeviceFeaturesHandler = (...[_, features]) => {
19487
+ postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
19488
+ };
19489
+
19254
19490
  const postMessage = message => {
19255
19491
  _core.emit(CORE_EVENT, message);
19256
19492
  };
@@ -19375,9 +19611,11 @@ __webpack_unused_export__ = ({
19375
19611
  __webpack_unused_export__ = CORE_EVENT;
19376
19612
  __webpack_unused_export__ = Core;
19377
19613
  __webpack_unused_export__ = DEFAULT_PRIORITY;
19378
- __webpack_unused_export__ = DEVICE;
19379
- __webpack_unused_export__ = DEVICE_EVENT;
19614
+ exports.Td = DEVICE;
19615
+ exports.Fd = DEVICE_EVENT;
19380
19616
  __webpack_unused_export__ = DataManager;
19617
+ __webpack_unused_export__ = FIRMWARE;
19618
+ exports.SI = FIRMWARE_EVENT;
19381
19619
  exports.Bg = IFRAME;
19382
19620
  __webpack_unused_export__ = LOG;
19383
19621
  exports.og = LOG_EVENT;
@@ -19388,6 +19626,7 @@ __webpack_unused_export__ = UI_RESPONSE;
19388
19626
  __webpack_unused_export__ = corsValidator;
19389
19627
  __webpack_unused_export__ = createDeviceMessage;
19390
19628
  exports.xG = createErrorMessage;
19629
+ __webpack_unused_export__ = createFirmwareMessage;
19391
19630
  __webpack_unused_export__ = createIFrameMessage;
19392
19631
  __webpack_unused_export__ = createLogMessage;
19393
19632
  __webpack_unused_export__ = createResponseMessage;
@@ -20568,6 +20807,8 @@ const HardwareErrorCode = {
20568
20807
  DeviceInitializeFailed: 106,
20569
20808
  DeviceInterruptedFromOutside: 107,
20570
20809
  DeviceUnexpectedBootloaderMode: 108,
20810
+ DeviceInterruptedFromUser: 109,
20811
+ DeviceCheckDeviceIdError: 110,
20571
20812
  NotInitialized: 200,
20572
20813
  IFrameNotInitialized: 300,
20573
20814
  IFrameAleradyInitialized: 301,
@@ -20600,7 +20841,10 @@ const HardwareErrorCode = {
20600
20841
  FirmwareError: 804,
20601
20842
  ResponseUnexpectTypeError: 805,
20602
20843
  BridgeNetworkError: 806,
20603
- BridgeTimeoutError: 807
20844
+ BridgeTimeoutError: 807,
20845
+ BridgeNotInstalled: 808,
20846
+ PollingTimeout: 809,
20847
+ PollingStop: 810
20604
20848
  };
20605
20849
  const HardwareErrorCodeMessage = {
20606
20850
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -20611,7 +20855,9 @@ const HardwareErrorCodeMessage = {
20611
20855
  [HardwareErrorCode.DeviceNotFound]: 'Device not found',
20612
20856
  [HardwareErrorCode.DeviceInitializeFailed]: 'Device initialization failed',
20613
20857
  [HardwareErrorCode.DeviceInterruptedFromOutside]: 'Device interrupted',
20858
+ [HardwareErrorCode.DeviceInterruptedFromUser]: 'Device interrupted',
20614
20859
  [HardwareErrorCode.DeviceUnexpectedBootloaderMode]: 'Device should be in bootloader mode',
20860
+ [HardwareErrorCode.DeviceCheckDeviceIdError]: 'Device Id in the features is not same.',
20615
20861
  [HardwareErrorCode.NotInitialized]: 'Not initialized',
20616
20862
  [HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
20617
20863
  [HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
@@ -20644,7 +20890,10 @@ const HardwareErrorCodeMessage = {
20644
20890
  [HardwareErrorCode.FirmwareError]: 'Firmware installation failed',
20645
20891
  [HardwareErrorCode.ResponseUnexpectTypeError]: 'Response type is not expected',
20646
20892
  [HardwareErrorCode.BridgeNetworkError]: 'Bridge network error',
20647
- [HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout'
20893
+ [HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout',
20894
+ [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
20895
+ [HardwareErrorCode.PollingTimeout]: 'Polling timeout',
20896
+ [HardwareErrorCode.PollingStop]: 'Polling stop'
20648
20897
  };
20649
20898
 
20650
20899
  const TypedError = (hardwareError, message) => {
@@ -45776,9 +46025,17 @@ const handleMessage = async message => {
45776
46025
  break;
45777
46026
 
45778
46027
  case dist/* LOG_EVENT */.og:
46028
+ case dist/* FIRMWARE_EVENT */.SI:
45779
46029
  eventEmitter.emit(message.event, message);
45780
46030
  break;
45781
46031
 
46032
+ case dist/* DEVICE_EVENT */.Fd:
46033
+ if (message.type === dist/* DEVICE.FEATURES */.Td.FEATURES) {
46034
+ eventEmitter.emit(message.type, message.payload);
46035
+ }
46036
+
46037
+ break;
46038
+
45782
46039
  default:
45783
46040
  src_Log.log('No need to be captured message', message.event);
45784
46041
  }
@@ -45867,7 +46124,7 @@ const src_init = async settings => {
45867
46124
 
45868
46125
  try {
45869
46126
  await init({ ..._settings,
45870
- version: "0.1.16"
46127
+ version: "0.1.19"
45871
46128
  });
45872
46129
  return true;
45873
46130
  } catch (e) {