@onekeyfe/hd-web-sdk 0.1.18 → 0.1.21

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.
@@ -14350,7 +14350,8 @@ const DEVICE = {
14350
14350
  PIN: 'pin',
14351
14351
  PASSPHRASE: 'passphrase',
14352
14352
  PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
14353
- WORD: 'word'
14353
+ WORD: 'word',
14354
+ FEATURES: 'features'
14354
14355
  };
14355
14356
 
14356
14357
  const createDeviceMessage = (type, payload) => ({
@@ -14868,6 +14869,7 @@ class Device extends events.exports {
14868
14869
  feat.unlocked = feat.unlocked || true;
14869
14870
  this.features = feat;
14870
14871
  this.featuresNeedsReload = false;
14872
+ this.emit(DEVICE.FEATURES, this, feat);
14871
14873
  }
14872
14874
 
14873
14875
  updateDescriptor(descriptor, forceUpdate = false) {
@@ -14923,6 +14925,11 @@ class Device extends events.exports {
14923
14925
  }
14924
14926
  } catch (error) {
14925
14927
  this.runPromise = null;
14928
+
14929
+ if (error instanceof hdShared.HardwareError) {
14930
+ return Promise.reject(error);
14931
+ }
14932
+
14926
14933
  return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
14927
14934
  }
14928
14935
  }
@@ -15194,16 +15201,13 @@ class BaseMethod {
15194
15201
  checkFirmwareRelease() {
15195
15202
  if (!this.device || !this.device.features) return;
15196
15203
  const releaseInfo = getFirmwareReleaseInfo(this.device.features);
15197
-
15198
- if (['outdated', 'required'].includes(releaseInfo.status)) {
15199
- this.postMessage(createFirmwareMessage(FIRMWARE.RELEASE_INFO, releaseInfo));
15200
- }
15201
-
15204
+ this.postMessage(createFirmwareMessage(FIRMWARE.RELEASE_INFO, Object.assign(Object.assign({}, releaseInfo), {
15205
+ features: this.device.features
15206
+ })));
15202
15207
  const bleReleaseInfo = getBleFirmwareReleaseInfo(this.device.features);
15203
-
15204
- if (['outdated', 'required'].includes(bleReleaseInfo.status)) {
15205
- this.postMessage(createFirmwareMessage(FIRMWARE.BLE_RELEASE_INFO, bleReleaseInfo));
15206
- }
15208
+ this.postMessage(createFirmwareMessage(FIRMWARE.BLE_RELEASE_INFO, Object.assign(Object.assign({}, bleReleaseInfo), {
15209
+ features: this.device.features
15210
+ })));
15207
15211
  }
15208
15212
 
15209
15213
  dispose() {}
@@ -15402,6 +15406,7 @@ class CipherKeyValue extends BaseMethod {
15402
15406
  init() {
15403
15407
  var _a;
15404
15408
 
15409
+ this.checkDeviceId = true;
15405
15410
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15406
15411
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
15407
15412
  const payload = this.hasBundle ? this.payload : {
@@ -15679,6 +15684,7 @@ class BTCGetAddress extends BaseMethod {
15679
15684
  }
15680
15685
 
15681
15686
  init() {
15687
+ this.checkDeviceId = true;
15682
15688
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15683
15689
  this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
15684
15690
  const payload = this.hasBundle ? this.payload : {
@@ -15762,6 +15768,7 @@ class BTCGetPublicKey extends BaseMethod {
15762
15768
  }
15763
15769
 
15764
15770
  init() {
15771
+ this.checkDeviceId = true;
15765
15772
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15766
15773
  this.hasBundle = Object.prototype.hasOwnProperty.call(this.payload, 'bundle');
15767
15774
  const payload = this.hasBundle ? this.payload : {
@@ -15836,6 +15843,7 @@ class BTCGetPublicKey extends BaseMethod {
15836
15843
 
15837
15844
  class BTCSignMessage extends BaseMethod {
15838
15845
  init() {
15846
+ this.checkDeviceId = true;
15839
15847
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15840
15848
  validateParams(this.payload, [{
15841
15849
  name: 'path',
@@ -16312,6 +16320,7 @@ var signtxLegacy = (typedCall, inputs, outputs, refTxsArray, options, coinName)
16312
16320
 
16313
16321
  class BTCSignTransaction extends BaseMethod {
16314
16322
  init() {
16323
+ this.checkDeviceId = true;
16315
16324
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16316
16325
  validateParams(this.payload, [{
16317
16326
  name: 'coin',
@@ -16486,6 +16495,7 @@ class BTCSignTransaction extends BaseMethod {
16486
16495
 
16487
16496
  class BTCVerifyMessage extends BaseMethod {
16488
16497
  init() {
16498
+ this.checkDeviceId = true;
16489
16499
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16490
16500
  validateParams(this.payload, [{
16491
16501
  name: 'address',
@@ -16914,6 +16924,7 @@ class EvmGetAddress extends BaseMethod {
16914
16924
  init() {
16915
16925
  var _a;
16916
16926
 
16927
+ this.checkDeviceId = true;
16917
16928
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16918
16929
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16919
16930
  const payload = this.hasBundle ? this.payload : {
@@ -16974,6 +16985,7 @@ class EVMGetPublicKey extends BaseMethod {
16974
16985
  init() {
16975
16986
  var _a;
16976
16987
 
16988
+ this.checkDeviceId = true;
16977
16989
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16978
16990
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
16979
16991
  const payload = this.hasBundle ? this.payload : {
@@ -17023,6 +17035,7 @@ class EVMGetPublicKey extends BaseMethod {
17023
17035
 
17024
17036
  class EVMSignMessage$2 extends BaseMethod {
17025
17037
  init() {
17038
+ this.checkDeviceId = true;
17026
17039
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17027
17040
  validateParams(this.payload, [{
17028
17041
  name: 'path',
@@ -17054,6 +17067,7 @@ class EVMSignMessage$2 extends BaseMethod {
17054
17067
 
17055
17068
  class EVMSignMessageEIP712 extends BaseMethod {
17056
17069
  init() {
17070
+ this.checkDeviceId = true;
17057
17071
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17058
17072
  validateParams(this.payload, [{
17059
17073
  name: 'path',
@@ -17217,6 +17231,7 @@ class EVMSignTransaction extends BaseMethod {
17217
17231
  }
17218
17232
 
17219
17233
  init() {
17234
+ this.checkDeviceId = true;
17220
17235
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17221
17236
  validateParams(this.payload, [{
17222
17237
  name: 'path',
@@ -17458,6 +17473,7 @@ const getFieldType = (typeName, types) => {
17458
17473
 
17459
17474
  class EVMSignTypedData extends BaseMethod {
17460
17475
  init() {
17476
+ this.checkDeviceId = true;
17461
17477
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17462
17478
  validateParams(this.payload, [{
17463
17479
  name: 'path',
@@ -17681,6 +17697,7 @@ class EVMSignTypedData extends BaseMethod {
17681
17697
 
17682
17698
  class EVMSignMessage$1 extends BaseMethod {
17683
17699
  init() {
17700
+ this.checkDeviceId = true;
17684
17701
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17685
17702
  validateParams(this.payload, [{
17686
17703
  name: 'address',
@@ -17725,6 +17742,7 @@ class StarcoinGetAddress extends BaseMethod {
17725
17742
  init() {
17726
17743
  var _a;
17727
17744
 
17745
+ this.checkDeviceId = true;
17728
17746
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17729
17747
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17730
17748
  const payload = this.hasBundle ? this.payload : {
@@ -17781,6 +17799,7 @@ class StarcoinGetPublicKey extends BaseMethod {
17781
17799
  init() {
17782
17800
  var _a;
17783
17801
 
17802
+ this.checkDeviceId = true;
17784
17803
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17785
17804
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17786
17805
  const payload = this.hasBundle ? this.payload : {
@@ -17830,6 +17849,7 @@ class StarcoinGetPublicKey extends BaseMethod {
17830
17849
 
17831
17850
  class StarcoinSignMessage extends BaseMethod {
17832
17851
  init() {
17852
+ this.checkDeviceId = true;
17833
17853
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17834
17854
  validateParams(this.payload, [{
17835
17855
  name: 'path',
@@ -17861,6 +17881,7 @@ class StarcoinSignMessage extends BaseMethod {
17861
17881
 
17862
17882
  class StarcoinSignTransaction extends BaseMethod {
17863
17883
  init() {
17884
+ this.checkDeviceId = true;
17864
17885
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17865
17886
  validateParams(this.payload, [{
17866
17887
  name: 'path',
@@ -17892,6 +17913,7 @@ class StarcoinSignTransaction extends BaseMethod {
17892
17913
 
17893
17914
  class EVMSignMessage extends BaseMethod {
17894
17915
  init() {
17916
+ this.checkDeviceId = true;
17895
17917
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17896
17918
  validateParams(this.payload, [{
17897
17919
  name: 'publicKey',
@@ -17938,6 +17960,7 @@ class NEMGetAddress extends BaseMethod {
17938
17960
  init() {
17939
17961
  var _a;
17940
17962
 
17963
+ this.checkDeviceId = true;
17941
17964
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
17942
17965
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
17943
17966
  const payload = this.hasBundle ? this.payload : {
@@ -18191,6 +18214,7 @@ class NEMSignTransaction extends BaseMethod {
18191
18214
  }
18192
18215
 
18193
18216
  init() {
18217
+ this.checkDeviceId = true;
18194
18218
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
18195
18219
  validateParams(this.payload, [{
18196
18220
  name: 'path',
@@ -18226,6 +18250,7 @@ class SolGetAddress extends BaseMethod {
18226
18250
  init() {
18227
18251
  var _a;
18228
18252
 
18253
+ this.checkDeviceId = true;
18229
18254
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
18230
18255
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
18231
18256
  const payload = this.hasBundle ? this.payload : {
@@ -18286,6 +18311,7 @@ class SolSignTransaction extends BaseMethod {
18286
18311
  init() {
18287
18312
  var _a;
18288
18313
 
18314
+ this.checkDeviceId = true;
18289
18315
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
18290
18316
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
18291
18317
  const payload = this.hasBundle ? this.payload : {
@@ -18355,6 +18381,7 @@ class StellarGetAddress extends BaseMethod {
18355
18381
  init() {
18356
18382
  var _a;
18357
18383
 
18384
+ this.checkDeviceId = true;
18358
18385
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
18359
18386
  this.hasBundle = !!((_a = this.payload) === null || _a === void 0 ? void 0 : _a.bundle);
18360
18387
  const payload = this.hasBundle ? this.payload : {
@@ -18591,6 +18618,7 @@ class StellarSignTransaction extends BaseMethod {
18591
18618
  }
18592
18619
 
18593
18620
  init() {
18621
+ this.checkDeviceId = true;
18594
18622
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
18595
18623
  validateParams(this.payload, [{
18596
18624
  name: 'path',
@@ -19154,9 +19182,8 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19154
19182
  Log.debug('Call API - setDevice: ', device.mainId);
19155
19183
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
19156
19184
  device.on(DEVICE.PIN, onDevicePinHandler);
19157
- device.on(DEVICE.BUTTON, (d, code) => {
19158
- onDeviceButtonHandler(d, code);
19159
- });
19185
+ device.on(DEVICE.BUTTON, onDeviceButtonHandler);
19186
+ device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
19160
19187
 
19161
19188
  try {
19162
19189
  const inner = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -19254,6 +19281,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
19254
19281
 
19255
19282
  closePopup();
19256
19283
  cleanup();
19284
+ removeDeviceListener(device);
19257
19285
  }
19258
19286
  });
19259
19287
 
@@ -19337,7 +19365,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19337
19365
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
19338
19366
  if (!pollingState[pollingId]) {
19339
19367
  Log.debug('EnsureConnected function stop, polling id: ', pollingId);
19340
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Polling stop'));
19368
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
19341
19369
  return;
19342
19370
  }
19343
19371
 
@@ -19346,7 +19374,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19346
19374
  }
19347
19375
 
19348
19376
  timer = setTimeout(() => {
19349
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Polling timeout'));
19377
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingTimeout));
19350
19378
  }, TIME_OUT);
19351
19379
  tryCount += 1;
19352
19380
  Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
@@ -19356,7 +19384,8 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19356
19384
  } catch (error) {
19357
19385
  Log.debug('device list error: ', error);
19358
19386
 
19359
- if (error.errorCode === hdShared.HardwareErrorCode.BridgeNotInstalled) {
19387
+ if ([hdShared.HardwareErrorCode.BridgeNotInstalled, hdShared.HardwareErrorCode.BridgeTimeoutError].includes(error.errorCode)) {
19388
+ _deviceList = undefined;
19360
19389
  reject(error);
19361
19390
  return;
19362
19391
  }
@@ -19392,7 +19421,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
19392
19421
  } catch (error) {
19393
19422
  Log.debug('device error: ', error);
19394
19423
 
19395
- if (error.errorCode === hdShared.HardwareErrorCode.BlePermissionError) {
19424
+ if ([hdShared.HardwareErrorCode.BlePermissionError, hdShared.HardwareErrorCode.BleLocationError, hdShared.HardwareErrorCode.BleDeviceNotBonded, hdShared.HardwareErrorCode.BleCharacteristicNotifyError].includes(error.errorCode)) {
19396
19425
  reject(error);
19397
19426
  return;
19398
19427
  }
@@ -19448,6 +19477,12 @@ const cleanup = () => {
19448
19477
  Log.debug('Cleanup...');
19449
19478
  };
19450
19479
 
19480
+ const removeDeviceListener = device => {
19481
+ device.removeListener(DEVICE.PIN, onDevicePinHandler);
19482
+ device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
19483
+ device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
19484
+ };
19485
+
19451
19486
  const closePopup = () => {
19452
19487
  postMessage(createUiMessage(UI_REQUEST$1.CLOSE_UI_WINDOW));
19453
19488
  };
@@ -19480,6 +19515,10 @@ const onDeviceButtonHandler = (...[device, request]) => {
19480
19515
  }
19481
19516
  };
19482
19517
 
19518
+ const onDeviceFeaturesHandler = (...[_, features]) => {
19519
+ postMessage(createDeviceMessage(DEVICE.FEATURES, Object.assign({}, features)));
19520
+ };
19521
+
19483
19522
  const postMessage = message => {
19484
19523
  _core.emit(CORE_EVENT, message);
19485
19524
  };
@@ -19604,8 +19643,8 @@ __webpack_unused_export__ = ({
19604
19643
  __webpack_unused_export__ = CORE_EVENT;
19605
19644
  __webpack_unused_export__ = Core;
19606
19645
  __webpack_unused_export__ = DEFAULT_PRIORITY;
19607
- __webpack_unused_export__ = DEVICE;
19608
- __webpack_unused_export__ = DEVICE_EVENT;
19646
+ exports.Td = DEVICE;
19647
+ exports.Fd = DEVICE_EVENT;
19609
19648
  __webpack_unused_export__ = DataManager;
19610
19649
  __webpack_unused_export__ = FIRMWARE;
19611
19650
  exports.SI = FIRMWARE_EVENT;
@@ -20835,7 +20874,9 @@ const HardwareErrorCode = {
20835
20874
  ResponseUnexpectTypeError: 805,
20836
20875
  BridgeNetworkError: 806,
20837
20876
  BridgeTimeoutError: 807,
20838
- BridgeNotInstalled: 808
20877
+ BridgeNotInstalled: 808,
20878
+ PollingTimeout: 809,
20879
+ PollingStop: 810
20839
20880
  };
20840
20881
  const HardwareErrorCodeMessage = {
20841
20882
  [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
@@ -20882,7 +20923,9 @@ const HardwareErrorCodeMessage = {
20882
20923
  [HardwareErrorCode.ResponseUnexpectTypeError]: 'Response type is not expected',
20883
20924
  [HardwareErrorCode.BridgeNetworkError]: 'Bridge network error',
20884
20925
  [HardwareErrorCode.BridgeTimeoutError]: 'Bridge network timeout',
20885
- [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed'
20926
+ [HardwareErrorCode.BridgeNotInstalled]: 'Bridge not installed',
20927
+ [HardwareErrorCode.PollingTimeout]: 'Polling timeout',
20928
+ [HardwareErrorCode.PollingStop]: 'Polling stop'
20886
20929
  };
20887
20930
 
20888
20931
  const TypedError = (hardwareError, message) => {
@@ -46018,6 +46061,13 @@ const handleMessage = async message => {
46018
46061
  eventEmitter.emit(message.event, message);
46019
46062
  break;
46020
46063
 
46064
+ case dist/* DEVICE_EVENT */.Fd:
46065
+ if (message.type === dist/* DEVICE.FEATURES */.Td.FEATURES) {
46066
+ eventEmitter.emit(message.type, message.payload);
46067
+ }
46068
+
46069
+ break;
46070
+
46021
46071
  default:
46022
46072
  src_Log.log('No need to be captured message', message.event);
46023
46073
  }
@@ -46106,7 +46156,7 @@ const src_init = async settings => {
46106
46156
 
46107
46157
  try {
46108
46158
  await init({ ..._settings,
46109
- version: "0.1.18"
46159
+ version: "0.1.21"
46110
46160
  });
46111
46161
  return true;
46112
46162
  } catch (e) {