@onekeyfe/hd-core 0.1.4 → 0.1.7

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 (68) hide show
  1. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  2. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  3. package/dist/api/btc/helpers/btcParamsUtils.d.ts.map +1 -1
  4. package/dist/api/btc/helpers/signtx.d.ts.map +1 -1
  5. package/dist/api/btc/helpers/signtxLegacy.d.ts.map +1 -1
  6. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  7. package/dist/api/evm/EVMSignTypedData.d.ts +1 -2
  8. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  9. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  10. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  11. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  12. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  13. package/dist/api/helpers/typeNameUtils.d.ts.map +1 -1
  14. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  15. package/dist/api/utils.d.ts.map +1 -1
  16. package/dist/constants/errors.d.ts +1 -26
  17. package/dist/constants/errors.d.ts.map +1 -1
  18. package/dist/constants/index.d.ts +1 -1
  19. package/dist/constants/index.d.ts.map +1 -1
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  22. package/dist/device/Device.d.ts +2 -2
  23. package/dist/device/Device.d.ts.map +1 -1
  24. package/dist/device/DeviceCommands.d.ts.map +1 -1
  25. package/dist/device/DeviceConnector.d.ts +2 -2
  26. package/dist/device/DeviceConnector.d.ts.map +1 -1
  27. package/dist/events/core.d.ts +1 -1
  28. package/dist/events/core.d.ts.map +1 -1
  29. package/dist/events/ui-promise.d.ts +1 -1
  30. package/dist/events/ui-promise.d.ts.map +1 -1
  31. package/dist/index.d.ts +87 -134
  32. package/dist/index.js +125 -165
  33. package/dist/types/params.d.ts +1 -1
  34. package/dist/types/params.d.ts.map +1 -1
  35. package/dist/utils/index.d.ts +0 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/versionUtils.d.ts +1 -1
  38. package/package.json +4 -3
  39. package/src/api/FirmwareUpdate.ts +10 -4
  40. package/src/api/btc/BTCSignTransaction.ts +3 -3
  41. package/src/api/btc/helpers/btcParamsUtils.ts +10 -4
  42. package/src/api/btc/helpers/signtx.ts +33 -15
  43. package/src/api/btc/helpers/signtxLegacy.ts +33 -12
  44. package/src/api/evm/EVMSignTransaction.ts +5 -2
  45. package/src/api/evm/EVMSignTypedData.ts +2 -2
  46. package/src/api/firmware/getBinary.ts +9 -4
  47. package/src/api/firmware/uploadFirmware.ts +4 -3
  48. package/src/api/helpers/bigNumberUtils.ts +4 -4
  49. package/src/api/helpers/paramsValidator.ts +3 -2
  50. package/src/api/helpers/pathUtils.ts +6 -3
  51. package/src/api/helpers/typeNameUtils.ts +7 -4
  52. package/src/api/nem/NEMSignTransaction.ts +5 -2
  53. package/src/api/utils.ts +6 -3
  54. package/src/constants/errors.ts +6 -46
  55. package/src/constants/index.ts +1 -1
  56. package/src/core/index.ts +17 -23
  57. package/src/data-manager/TransportManager.ts +5 -2
  58. package/src/device/Device.ts +11 -6
  59. package/src/device/DeviceCommands.ts +34 -12
  60. package/src/device/DeviceConnector.ts +4 -4
  61. package/src/events/call.ts +1 -1
  62. package/src/events/core.ts +11 -7
  63. package/src/events/ui-promise.ts +1 -1
  64. package/src/types/params.ts +1 -1
  65. package/src/utils/index.ts +0 -1
  66. package/dist/utils/deferred.d.ts +0 -9
  67. package/dist/utils/deferred.d.ts.map +0 -1
  68. package/src/utils/deferred.ts +0 -35
package/dist/index.js CHANGED
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var semver = require('semver');
6
- var hdTransport = require('@onekeyfe/hd-transport');
6
+ var hdShared = require('@onekeyfe/hd-shared');
7
7
  var axios = require('axios');
8
8
  var BigNumber = require('bignumber.js');
9
+ var hdTransport = require('@onekeyfe/hd-transport');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
12
 
@@ -605,48 +606,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
605
606
  }
606
607
  }
607
608
 
608
- const ERROR_CODES = {
609
- Method_InvalidParameter: '',
610
- Call_API: '',
611
- Call_NotResponse: 'No response data',
612
- Method_FirmwareUpdate_DownloadFailed: '',
613
- Transport_InvalidProtobuf: '',
614
- Device_FwException: '',
615
- Device_UnexpectedMode: '',
616
- Device_CallInProgress: '',
617
- Device_InitializeFailed: '',
618
- Device_Interrupted: 'The device is performing other operations',
619
- Not_Use_Onekey_Device: 'Please use onekey device',
620
- Runtime: '',
621
- Init_NotInitialized: 'Init_NotInitialized',
622
- Init_IframeBlocked: 'Init_IframeBlocked',
623
- Init_IframeTimeout: 'Init_IframeTimeout',
624
- Init_AlreadyInitialized: 'Init_AlreadyInitialized',
625
- Init_IframeLoadFail: 'Init_IframeLoadFail',
626
- };
627
- class OnekeyError extends Error {
628
- constructor(code, message) {
629
- super(message);
630
- this.code = code;
631
- this.message = message;
632
- }
633
- }
634
- const TypedError = (id, message) => new OnekeyError(id, message || ERROR_CODES[id]);
635
- const serializeError = (payload) => {
636
- if (payload && payload.error instanceof Error) {
637
- return { error: payload.error.message, code: payload.error.code };
638
- }
639
- return payload;
640
- };
641
-
642
- var errors = /*#__PURE__*/Object.freeze({
643
- __proto__: null,
644
- ERROR_CODES: ERROR_CODES,
645
- OnekeyError: OnekeyError,
646
- TypedError: TypedError,
647
- serializeError: serializeError
648
- });
649
-
650
609
  const colors = {
651
610
  '@onekey/connect': 'color: #f4a742; background: #000;',
652
611
  IFrame: 'color: #f4a742; background: #000;',
@@ -804,33 +763,6 @@ const versionCompare = (a, b) => {
804
763
  return 0;
805
764
  };
806
765
 
807
- function create(arg, data) {
808
- let localResolve = (_t) => { };
809
- let localReject = (_e) => { };
810
- let id;
811
- const promise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
812
- localResolve = resolve;
813
- localReject = reject;
814
- if (typeof arg === 'function') {
815
- try {
816
- yield arg();
817
- }
818
- catch (error) {
819
- reject(error);
820
- }
821
- }
822
- if (typeof arg === 'string')
823
- id = arg;
824
- }));
825
- return {
826
- id,
827
- data,
828
- resolve: localResolve,
829
- reject: localReject,
830
- promise,
831
- };
832
- }
833
-
834
766
  const getDeviceModel = (features) => {
835
767
  if (!features || typeof features !== 'object') {
836
768
  return 'model_mini';
@@ -902,8 +834,8 @@ const getDeviceBLEFirmwareVersion = (features) => {
902
834
  const HD_HARDENED = 0x80000000;
903
835
  const toHardened = (n) => (n | HD_HARDENED) >>> 0;
904
836
  const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
905
- const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
906
- const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
837
+ const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
838
+ const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
907
839
  const getHDPath = (path) => {
908
840
  const parts = path.toLowerCase().split('/');
909
841
  if (parts[0] !== 'm')
@@ -9941,7 +9873,7 @@ class TransportManager {
9941
9873
  this.currentMessages = messages;
9942
9874
  }
9943
9875
  catch (error) {
9944
- throw TypedError('Transport_InvalidProtobuf', error.message);
9876
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
9945
9877
  }
9946
9878
  });
9947
9879
  }
@@ -9983,13 +9915,16 @@ const parseMessage = (messageData) => {
9983
9915
  }
9984
9916
  return message;
9985
9917
  };
9986
- const createErrorMessage = (error) => ({
9987
- success: false,
9988
- payload: {
9989
- error: error.message,
9990
- code: error.code,
9991
- },
9992
- });
9918
+ const createErrorMessage = (error) => {
9919
+ let payload = { error: error.message, code: error.code };
9920
+ if (error instanceof hdShared.HardwareError) {
9921
+ payload = { error: error.message, code: error.errorCode };
9922
+ }
9923
+ return {
9924
+ success: false,
9925
+ payload,
9926
+ };
9927
+ };
9993
9928
 
9994
9929
  const UI_EVENT = 'UI_EVENT';
9995
9930
  const UI_REQUEST$1 = {
@@ -10025,7 +9960,7 @@ const createResponseMessage = (id, success, payload) => ({
10025
9960
  type: RESPONSE_EVENT,
10026
9961
  id,
10027
9962
  success,
10028
- payload: success ? payload : serializeError(payload),
9963
+ payload: success ? payload : hdShared.serializeError(payload),
10029
9964
  });
10030
9965
 
10031
9966
  const UI_RESPONSE = {
@@ -10065,7 +10000,7 @@ const createDeviceMessage = (type, payload) => ({
10065
10000
  const assertType = (res, resType) => {
10066
10001
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
10067
10002
  if (!splitResTypes.includes(res.type)) {
10068
- throw TypedError('Runtime', `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
10003
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
10069
10004
  }
10070
10005
  };
10071
10006
  const Log$4 = initLog('DeviceCommands');
@@ -10104,7 +10039,7 @@ class DeviceCommands {
10104
10039
  typedCall(type, resType, msg) {
10105
10040
  return __awaiter(this, void 0, void 0, function* () {
10106
10041
  if (this.disposed) {
10107
- throw TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
10042
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'typedCall: DeviceCommands already disposed');
10108
10043
  }
10109
10044
  const response = yield this._commonCall(type, msg);
10110
10045
  try {
@@ -10127,14 +10062,24 @@ class DeviceCommands {
10127
10062
  console.log('_filterCommonTypes: ', res);
10128
10063
  if (res.type === 'Failure') {
10129
10064
  const { code } = res.message;
10130
- let { message } = res.message;
10065
+ const { message } = res.message;
10066
+ let error = null;
10131
10067
  if (code === 'Failure_FirmwareError' && !message) {
10132
- message = 'Firmware installation failed';
10068
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError);
10069
+ }
10070
+ if (code === 'Failure_ActionCancelled') {
10071
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled);
10133
10072
  }
10134
- if (code === 'Failure_ActionCancelled' && !message) {
10135
- message = 'Action cancelled by user';
10073
+ if (code === 'Failure_PinInvalid') {
10074
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinInvalid, message);
10136
10075
  }
10137
- return Promise.reject(new OnekeyError(code || 'Failure_UnknownCode', message || 'Failure_UnknownMessage'));
10076
+ if (code === 'Failure_PinCancelled') {
10077
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinCancelled);
10078
+ }
10079
+ if (error) {
10080
+ return Promise.reject(error);
10081
+ }
10082
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${code || 'Failure_UnknownCode'},${message || 'Failure_UnknownMessage'}`));
10138
10083
  }
10139
10084
  if (res.type === 'Features') {
10140
10085
  return Promise.resolve(res);
@@ -10178,7 +10123,7 @@ class DeviceCommands {
10178
10123
  }
10179
10124
  else {
10180
10125
  console.warn('[DeviceCommands] [call] PIN callback not configured, cancelling request');
10181
- reject(TypedError('Runtime', '_promptPin: PIN callback not configured'));
10126
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPin: PIN callback not configured'));
10182
10127
  }
10183
10128
  });
10184
10129
  }
@@ -10455,7 +10400,7 @@ class Device extends events.exports {
10455
10400
  this.features = feat;
10456
10401
  this.featuresNeedsReload = false;
10457
10402
  }
10458
- updateDescriptor(descriptor) {
10403
+ updateDescriptor(descriptor, forceUpdate = false) {
10459
10404
  const env = DataManager.getSettings('env');
10460
10405
  if (env === 'react-native') {
10461
10406
  return;
@@ -10465,11 +10410,14 @@ class Device extends events.exports {
10465
10410
  if (originalSession !== upcomingSession) {
10466
10411
  this.originalDescriptor.session = upcomingSession;
10467
10412
  }
10413
+ if (forceUpdate) {
10414
+ this.originalDescriptor = descriptor;
10415
+ }
10468
10416
  }
10469
10417
  updateFromCache(device) {
10470
10418
  this.mainId = device.mainId;
10471
10419
  this.commands = device.commands;
10472
- this.updateDescriptor(device.originalDescriptor);
10420
+ this.updateDescriptor(device.originalDescriptor, true);
10473
10421
  if (device.features) {
10474
10422
  this._updateFeatures(device.features);
10475
10423
  }
@@ -10481,7 +10429,7 @@ class Device extends events.exports {
10481
10429
  Log$3.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
10482
10430
  }
10483
10431
  options = parseRunOptions(options);
10484
- this.runPromise = create(this._runInner.bind(this, fn, options));
10432
+ this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
10485
10433
  return this.runPromise.promise;
10486
10434
  });
10487
10435
  }
@@ -10496,7 +10444,7 @@ class Device extends events.exports {
10496
10444
  }
10497
10445
  catch (error) {
10498
10446
  this.runPromise = null;
10499
- return Promise.reject(TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}, code: ${error.code}`));
10447
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
10500
10448
  }
10501
10449
  }
10502
10450
  if (options.keepSession) {
@@ -10522,7 +10470,7 @@ class Device extends events.exports {
10522
10470
  this.commands.dispose();
10523
10471
  }
10524
10472
  if (this.runPromise) {
10525
- this.runPromise.reject(TypedError('Device_Interrupted'));
10473
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
10526
10474
  }
10527
10475
  }
10528
10476
  getMode() {
@@ -10753,7 +10701,7 @@ const formatAnyHex = value => {
10753
10701
  return value;
10754
10702
  };
10755
10703
 
10756
- const invalidParameter = (message) => TypedError('Method_InvalidParameter', message);
10704
+ const invalidParameter = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
10757
10705
  const validateParams = (values, fields) => {
10758
10706
  fields.forEach(field => {
10759
10707
  const existsProp = Object.prototype.hasOwnProperty.call(values, field.name);
@@ -11068,13 +11016,13 @@ const getCoinInfo = (path, coin) => {
11068
11016
  }
11069
11017
  if (!coinInfo) {
11070
11018
  if (coin) {
11071
- throw TypedError('Method_InvalidParameter', `Invalid coin name: ${coin}`);
11019
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
11072
11020
  }
11073
11021
  else if (path) {
11074
- throw TypedError('Method_InvalidParameter', `Invalid path: ${path[0]}`);
11022
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
11075
11023
  }
11076
11024
  else {
11077
- throw TypedError('Method_InvalidParameter');
11025
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
11078
11026
  }
11079
11027
  }
11080
11028
  return coinInfo;
@@ -11228,49 +11176,49 @@ class BTCSignMessage extends BaseMethod {
11228
11176
  const requestPrevTxInfo$1 = ({ typedCall, txRequest: { request_type, details }, refTxs }) => {
11229
11177
  const { tx_hash } = details;
11230
11178
  if (!tx_hash) {
11231
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
11179
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
11232
11180
  }
11233
11181
  const tx = refTxs[tx_hash.toLowerCase()];
11234
11182
  if (!tx) {
11235
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
11183
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
11236
11184
  }
11237
11185
  if (request_type === 'TXINPUT') {
11238
11186
  if (!tx.bin_outputs)
11239
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
11187
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
11240
11188
  return typedCall('TxAckPrevInput', 'TxRequest', {
11241
11189
  tx: { input: tx.inputs[details.request_index] },
11242
11190
  });
11243
11191
  }
11244
11192
  if (request_type === 'TXOUTPUT') {
11245
11193
  if (!tx.bin_outputs)
11246
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
11194
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
11247
11195
  return typedCall('TxAckPrevOutput', 'TxRequest', {
11248
11196
  tx: { output: tx.bin_outputs[details.request_index] },
11249
11197
  });
11250
11198
  }
11251
11199
  if (request_type === 'TXORIGINPUT') {
11252
11200
  if (!tx.outputs)
11253
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
11201
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
11254
11202
  return typedCall('TxAckInput', 'TxRequest', {
11255
11203
  tx: { input: tx.inputs[details.request_index] },
11256
11204
  });
11257
11205
  }
11258
11206
  if (request_type === 'TXORIGOUTPUT') {
11259
11207
  if (!tx.outputs)
11260
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
11208
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
11261
11209
  return typedCall('TxAckOutput', 'TxRequest', {
11262
11210
  tx: { output: tx.outputs[details.request_index] },
11263
11211
  });
11264
11212
  }
11265
11213
  if (request_type === 'TXEXTRADATA') {
11266
11214
  if (typeof details.extra_data_len !== 'number') {
11267
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
11215
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
11268
11216
  }
11269
11217
  if (typeof details.extra_data_offset !== 'number') {
11270
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
11218
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
11271
11219
  }
11272
11220
  if (typeof tx.extra_data !== 'string') {
11273
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
11221
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
11274
11222
  }
11275
11223
  const data = tx.extra_data;
11276
11224
  const dataLen = details.extra_data_len;
@@ -11293,7 +11241,7 @@ const requestPrevTxInfo$1 = ({ typedCall, txRequest: { request_type, details },
11293
11241
  };
11294
11242
  return typedCall('TxAckPrevMeta', 'TxRequest', { tx: meta });
11295
11243
  }
11296
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
11244
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
11297
11245
  };
11298
11246
  const requestSignedTxInfo$1 = ({ typedCall, txRequest: { request_type, details }, inputs, outputs, }) => {
11299
11247
  if (request_type === 'TXINPUT') {
@@ -11305,12 +11253,12 @@ const requestSignedTxInfo$1 = ({ typedCall, txRequest: { request_type, details }
11305
11253
  });
11306
11254
  }
11307
11255
  if (request_type === 'TXMETA') {
11308
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
11256
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
11309
11257
  }
11310
11258
  if (request_type === 'TXEXTRADATA') {
11311
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
11259
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
11312
11260
  }
11313
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
11261
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
11314
11262
  };
11315
11263
  const requestTxAck$1 = (props) => {
11316
11264
  const { tx_hash } = props.txRequest.details;
@@ -11328,7 +11276,7 @@ const saveTxSignatures$1 = (serializedTx, signatures, txRequest) => {
11328
11276
  }
11329
11277
  if (typeof signature_index === 'number') {
11330
11278
  if (!signature) {
11331
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
11279
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
11332
11280
  }
11333
11281
  signatures[signature_index] = signature;
11334
11282
  }
@@ -11373,14 +11321,14 @@ var signtx = (typedCall, inputs, outputs, refTxsArray, options, coinName) => __a
11373
11321
  const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) => {
11374
11322
  const { tx_hash } = details;
11375
11323
  if (!tx_hash) {
11376
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
11324
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
11377
11325
  }
11378
11326
  const tx = refTxs[tx_hash.toLowerCase()];
11379
11327
  if (!tx) {
11380
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
11328
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
11381
11329
  }
11382
11330
  if (!tx.bin_outputs) {
11383
- throw TypedError('Runtime', `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
11331
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
11384
11332
  }
11385
11333
  if (request_type === 'TXINPUT') {
11386
11334
  return { inputs: [tx.inputs[details.request_index]] };
@@ -11390,13 +11338,13 @@ const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) =>
11390
11338
  }
11391
11339
  if (request_type === 'TXEXTRADATA') {
11392
11340
  if (typeof details.extra_data_len !== 'number') {
11393
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
11341
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
11394
11342
  }
11395
11343
  if (typeof details.extra_data_offset !== 'number') {
11396
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
11344
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
11397
11345
  }
11398
11346
  if (typeof tx.extra_data !== 'string') {
11399
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
11347
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
11400
11348
  }
11401
11349
  const data = tx.extra_data;
11402
11350
  const dataLen = details.extra_data_len;
@@ -11421,7 +11369,7 @@ const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) =>
11421
11369
  }
11422
11370
  return meta;
11423
11371
  }
11424
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
11372
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
11425
11373
  };
11426
11374
  const requestSignedTxInfo = ({ txRequest: { request_type, details }, inputs, outputs, }) => {
11427
11375
  if (request_type === 'TXINPUT') {
@@ -11431,12 +11379,12 @@ const requestSignedTxInfo = ({ txRequest: { request_type, details }, inputs, out
11431
11379
  return { outputs: [outputs[details.request_index]] };
11432
11380
  }
11433
11381
  if (request_type === 'TXMETA') {
11434
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
11382
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
11435
11383
  }
11436
11384
  if (request_type === 'TXEXTRADATA') {
11437
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
11385
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
11438
11386
  }
11439
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
11387
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
11440
11388
  };
11441
11389
  const requestTxAck = (props) => {
11442
11390
  const { tx_hash } = props.txRequest.details;
@@ -11454,7 +11402,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
11454
11402
  }
11455
11403
  if (typeof signature_index === 'number') {
11456
11404
  if (!signature) {
11457
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
11405
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
11458
11406
  }
11459
11407
  signatures[signature_index] = signature;
11460
11408
  }
@@ -11548,12 +11496,12 @@ class BTCSignTransaction extends BaseMethod {
11548
11496
  ]);
11549
11497
  if (Object.prototype.hasOwnProperty.call(output, 'address_n') &&
11550
11498
  Object.prototype.hasOwnProperty.call(output, 'address')) {
11551
- throw TypedError('Method_InvalidParameter', 'Cannot use address and address_n in one output');
11499
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
11552
11500
  }
11553
11501
  if (output.address_n) {
11554
11502
  const scriptType = getOutputScriptType(output.address_n);
11555
11503
  if (output.script_type !== scriptType)
11556
- throw TypedError('Method_InvalidParameter', `Output change script_type should be set to ${scriptType}`);
11504
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
11557
11505
  }
11558
11506
  });
11559
11507
  const { inputs, outputs, refTxs, account, coin } = this.payload;
@@ -12003,7 +11951,7 @@ class EVMSignTransaction extends BaseMethod {
12003
11951
  const r = request.signature_r;
12004
11952
  const s = request.signature_s;
12005
11953
  if (v == null || r == null || s == null) {
12006
- throw TypedError('Runtime', 'processTxRequest: Unexpected request');
11954
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
12007
11955
  }
12008
11956
  if (chain_id && v <= 1) {
12009
11957
  v += 2 * chain_id + 35;
@@ -12143,7 +12091,7 @@ class EVMSignTypedData extends BaseMethod {
12143
12091
  this.params.messageHash = formatAnyHex(messageHash);
12144
12092
  }
12145
12093
  else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
12146
- throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
12094
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'message_hash should only be empty when data.primaryType=EIP712Domain');
12147
12095
  }
12148
12096
  }
12149
12097
  }
@@ -12168,7 +12116,7 @@ class EVMSignTypedData extends BaseMethod {
12168
12116
  run() {
12169
12117
  return __awaiter(this, void 0, void 0, function* () {
12170
12118
  if (!this.device.features) {
12171
- throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
12119
+ throw hdShared.ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
12172
12120
  }
12173
12121
  const { addressN } = this.params;
12174
12122
  const deviceType = getDeviceType(this.device.features);
@@ -12195,7 +12143,7 @@ class EVMSignTypedData extends BaseMethod {
12195
12143
  }
12196
12144
  return Promise.resolve(response.message);
12197
12145
  }
12198
- return Promise.resolve(TypedError('Runtime', 'Not implemented'));
12146
+ return Promise.resolve(hdShared.ERRORS.TypedError('Runtime', 'Not implemented'));
12199
12147
  });
12200
12148
  }
12201
12149
  }
@@ -12576,7 +12524,7 @@ class NEMSignTransaction extends BaseMethod {
12576
12524
  message.supply_change = this.supplyChangeMessage(transaction);
12577
12525
  break;
12578
12526
  default:
12579
- throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
12527
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
12580
12528
  }
12581
12529
  return message;
12582
12530
  };
@@ -12909,14 +12857,20 @@ class StellarSignTransaction extends BaseMethod {
12909
12857
  const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void 0, void 0, function* () {
12910
12858
  const releaseInfo = getInfo({ features, updateType });
12911
12859
  if (!releaseInfo) {
12912
- throw TypedError('Runtime', 'no firmware found for this device');
12860
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
12913
12861
  }
12914
12862
  if (version &&
12915
12863
  !semver__default["default"].eq(releaseInfo.version, version)) {
12916
- throw TypedError('Runtime', 'firmware version mismatch');
12864
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
12917
12865
  }
12918
12866
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
12919
- const fw = yield httpRequest(url, 'binary');
12867
+ let fw;
12868
+ try {
12869
+ fw = yield httpRequest(url, 'binary');
12870
+ }
12871
+ catch (_a) {
12872
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
12873
+ }
12920
12874
  return Object.assign(Object.assign({}, releaseInfo), { binary: fw });
12921
12875
  });
12922
12876
  const getInfo = ({ features, updateType }) => {
@@ -12949,6 +12903,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
12949
12903
  const { message } = yield typedCall('FirmwareUpload', 'Success', {
12950
12904
  payload,
12951
12905
  });
12906
+ postProgressMessage(device, 100, postMessage);
12952
12907
  return message;
12953
12908
  }
12954
12909
  if (((_b = device.features) === null || _b === void 0 ? void 0 : _b.major_version) === 2) {
@@ -12969,7 +12924,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
12969
12924
  postProgressMessage(device, 100, postMessage);
12970
12925
  return response.message;
12971
12926
  }
12972
- throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
12927
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
12973
12928
  });
12974
12929
 
12975
12930
  class FirmwareUpdate extends BaseMethod {
@@ -12982,7 +12937,7 @@ class FirmwareUpdate extends BaseMethod {
12982
12937
  { name: 'binary', type: 'buffer' },
12983
12938
  ]);
12984
12939
  if (!payload.updateType) {
12985
- throw TypedError('Method_InvalidParameter', 'updateType is required');
12940
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
12986
12941
  }
12987
12942
  this.params = { updateType: payload.updateType };
12988
12943
  if ('version' in payload) {
@@ -13002,7 +12957,7 @@ class FirmwareUpdate extends BaseMethod {
13002
12957
  }
13003
12958
  else {
13004
12959
  if (!device.features) {
13005
- throw TypedError('Runtime', 'no features found for this device');
12960
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
13006
12961
  }
13007
12962
  const firmware = yield getBinary({
13008
12963
  features: device.features,
@@ -13013,7 +12968,7 @@ class FirmwareUpdate extends BaseMethod {
13013
12968
  }
13014
12969
  }
13015
12970
  catch (err) {
13016
- throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
12971
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
13017
12972
  }
13018
12973
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
13019
12974
  });
@@ -13066,15 +13021,24 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
13066
13021
  function findMethod(message) {
13067
13022
  const { method } = message.payload;
13068
13023
  if (typeof method !== 'string') {
13069
- throw TypedError('Method_InvalidParameter', 'Method is not set');
13024
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
13070
13025
  }
13071
13026
  const MethodConstructor = ApiMethods[method];
13072
13027
  if (MethodConstructor) {
13073
13028
  return new MethodConstructor(message);
13074
13029
  }
13075
- throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
13030
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
13076
13031
  }
13077
13032
 
13033
+ const safeThrowError = (error) => {
13034
+ if (error instanceof hdShared.HardwareError) {
13035
+ throw error;
13036
+ }
13037
+ else {
13038
+ throw hdShared.ERRORS.TypedError(error);
13039
+ }
13040
+ };
13041
+
13078
13042
  const resolveAfter = (msec, value) => new Promise(resolve => {
13079
13043
  setTimeout(resolve, msec, value);
13080
13044
  });
@@ -13140,7 +13104,7 @@ class DeviceConnector {
13140
13104
  return diff;
13141
13105
  }
13142
13106
  catch (error) {
13143
- throw new Error(error);
13107
+ safeThrowError(error);
13144
13108
  }
13145
13109
  });
13146
13110
  }
@@ -13196,7 +13160,7 @@ class DeviceConnector {
13196
13160
  return res;
13197
13161
  }
13198
13162
  catch (error) {
13199
- throw new Error(error);
13163
+ safeThrowError(error);
13200
13164
  }
13201
13165
  });
13202
13166
  }
@@ -13207,7 +13171,7 @@ class DeviceConnector {
13207
13171
  return res;
13208
13172
  }
13209
13173
  catch (error) {
13210
- throw new Error(error);
13174
+ safeThrowError(error);
13211
13175
  }
13212
13176
  });
13213
13177
  }
@@ -13226,9 +13190,9 @@ let _uiPromises = [];
13226
13190
  let _callPromise;
13227
13191
  const deviceCacheMap = new Map();
13228
13192
  const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13229
- var _a, _b;
13193
+ var _a;
13230
13194
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
13231
- return Promise.reject(TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing'));
13195
+ return Promise.reject(hdShared.ERRORS.TypedError('on call: message.id or message.payload is missing'));
13232
13196
  }
13233
13197
  let method;
13234
13198
  let messageResponse;
@@ -13247,10 +13211,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13247
13211
  return createResponseMessage(method.responseID, true, response);
13248
13212
  }
13249
13213
  catch (error) {
13250
- return createResponseMessage(method.responseID, false, {
13251
- code: error.code,
13252
- error: (_a = error.message) !== null && _a !== void 0 ? _a : error,
13253
- });
13214
+ return createResponseMessage(method.responseID, false, { error });
13254
13215
  }
13255
13216
  }
13256
13217
  try {
@@ -13273,7 +13234,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13273
13234
  return Promise.reject(error);
13274
13235
  }
13275
13236
  Log.debug('Call API - setDevice: ', device);
13276
- (_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
13237
+ (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
13277
13238
  device.on(DEVICE.PIN, onDevicePinHandler);
13278
13239
  device.on(DEVICE.BUTTON, (d, code) => {
13279
13240
  onDeviceButtonHandler(d, code);
@@ -13288,17 +13249,17 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13288
13249
  if (versionRange && device.features) {
13289
13250
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
13290
13251
  if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
13291
- return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
13252
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too low, please update to ${versionRange.min}`));
13292
13253
  }
13293
13254
  if (versionRange.max &&
13294
13255
  semver__default["default"].valid(versionRange.max) &&
13295
13256
  semver__default["default"].gt(currentVersion, versionRange.max)) {
13296
- return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
13257
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
13297
13258
  }
13298
13259
  }
13299
13260
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
13300
13261
  if (unexpectedMode) {
13301
- return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
13262
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
13302
13263
  }
13303
13264
  if (_deviceList) {
13304
13265
  yield TransportManager.reconfigure(device.getFirmwareVersion());
@@ -13311,24 +13272,24 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
13311
13272
  }
13312
13273
  catch (error) {
13313
13274
  Log.debug('Call API - Inner Method Run Error: ', error);
13314
- messageResponse = createResponseMessage(method.responseID, false, error.message);
13275
+ messageResponse = createResponseMessage(method.responseID, false, { error });
13315
13276
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
13316
13277
  }
13317
13278
  });
13318
13279
  Log.debug('Call API - Device Run: ', device);
13319
13280
  const deviceRun = () => device.run(inner);
13320
- _callPromise = create(deviceRun);
13281
+ _callPromise = hdShared.createDeferred(deviceRun);
13321
13282
  try {
13322
13283
  return yield _callPromise.promise;
13323
13284
  }
13324
13285
  catch (e) {
13325
13286
  console.log('Device Run Error: ', e);
13326
- return createResponseMessage(method.responseID, false, e.message);
13287
+ return createResponseMessage(method.responseID, false, { error: e });
13327
13288
  }
13328
13289
  }
13329
13290
  catch (error) {
13330
- messageResponse = createResponseMessage(method.responseID, false, error);
13331
- _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
13291
+ messageResponse = createResponseMessage(method.responseID, false, { error });
13292
+ _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
13332
13293
  Log.debug('Call API - Run Error: ', error);
13333
13294
  }
13334
13295
  finally {
@@ -13359,7 +13320,7 @@ function initDeviceList(method) {
13359
13320
  }
13360
13321
  function initDevice(method) {
13361
13322
  if (!_deviceList) {
13362
- throw TypedError('Call_API', 'DeviceList is not initialized');
13323
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
13363
13324
  }
13364
13325
  let device;
13365
13326
  const allDevices = _deviceList.allDevices();
@@ -13370,17 +13331,17 @@ function initDevice(method) {
13370
13331
  [device] = allDevices;
13371
13332
  }
13372
13333
  else if (allDevices.length > 1) {
13373
- throw TypedError('Call_API', '请选择连接设备');
13334
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
13374
13335
  }
13375
13336
  if (!device) {
13376
- throw TypedError('Call_API', 'Device Not Found');
13337
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
13377
13338
  }
13378
13339
  device.deviceConnector = _connector;
13379
13340
  return device;
13380
13341
  }
13381
13342
  function initDeviceForBle(method) {
13382
13343
  if (!method.connectId && !_deviceList) {
13383
- throw TypedError('Call_API', 'DeviceList is not initialized');
13344
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
13384
13345
  }
13385
13346
  if (!method.connectId) {
13386
13347
  return initDevice(method);
@@ -13444,7 +13405,7 @@ const postMessage = (message) => {
13444
13405
  _core.emit(CORE_EVENT, message);
13445
13406
  };
13446
13407
  const createUiPromise = (promiseEvent, device) => {
13447
- const uiPromise = create(promiseEvent, device);
13408
+ const uiPromise = hdShared.createDeferred(promiseEvent, device);
13448
13409
  _uiPromises.push(uiPromise);
13449
13410
  return uiPromise;
13450
13411
  };
@@ -13501,7 +13462,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
13501
13462
  yield DataManager.load(settings);
13502
13463
  initTransport(Transport);
13503
13464
  }
13504
- catch (_c) {
13465
+ catch (_b) {
13505
13466
  Log.error('DataManager.load error');
13506
13467
  }
13507
13468
  enableLog(DataManager.getSettings('debug'));
@@ -13533,14 +13494,12 @@ exports.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
13533
13494
  exports.DEVICE = DEVICE;
13534
13495
  exports.DEVICE_EVENT = DEVICE_EVENT;
13535
13496
  exports.DataManager = DataManager;
13536
- exports.ERRORS = errors;
13537
13497
  exports.IFRAME = IFRAME;
13538
13498
  exports.RESPONSE_EVENT = RESPONSE_EVENT;
13539
13499
  exports.UI_EVENT = UI_EVENT;
13540
13500
  exports.UI_REQUEST = UI_REQUEST$1;
13541
13501
  exports.UI_RESPONSE = UI_RESPONSE;
13542
13502
  exports.corsValidator = corsValidator;
13543
- exports.create = create;
13544
13503
  exports.createDeviceMessage = createDeviceMessage;
13545
13504
  exports.createErrorMessage = createErrorMessage;
13546
13505
  exports.createIFrameMessage = createIFrameMessage;
@@ -13566,5 +13525,6 @@ exports.isValidVersionString = isValidVersionString;
13566
13525
  exports.normalizeVersionArray = normalizeVersionArray;
13567
13526
  exports.parseConnectSettings = parseConnectSettings;
13568
13527
  exports.parseMessage = parseMessage;
13528
+ exports.safeThrowError = safeThrowError;
13569
13529
  exports.versionCompare = versionCompare;
13570
13530
  exports.versionSplit = versionSplit;