@onekeyfe/hd-web-sdk 0.1.5 → 0.1.8

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.
@@ -4025,12 +4025,14 @@ __webpack_unused_export__ = ({
4025
4025
 
4026
4026
  var semver = __webpack_require__(7699);
4027
4027
 
4028
- var hdTransport = __webpack_require__(7495);
4028
+ var hdShared = __webpack_require__(8402);
4029
4029
 
4030
4030
  var axios = __webpack_require__(9644);
4031
4031
 
4032
4032
  var BigNumber = __webpack_require__(6391);
4033
4033
 
4034
+ var hdTransport = __webpack_require__(7495);
4035
+
4034
4036
  function _interopDefaultLegacy(e) {
4035
4037
  return e && typeof e === 'object' && 'default' in e ? e : {
4036
4038
  'default': e
@@ -4772,55 +4774,6 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
4772
4774
  }
4773
4775
  }
4774
4776
 
4775
- const ERROR_CODES = {
4776
- Method_InvalidParameter: '',
4777
- Call_API: '',
4778
- Call_NotResponse: 'No response data',
4779
- Method_FirmwareUpdate_DownloadFailed: '',
4780
- Transport_InvalidProtobuf: '',
4781
- Device_FwException: '',
4782
- Device_UnexpectedMode: '',
4783
- Device_CallInProgress: '',
4784
- Device_InitializeFailed: '',
4785
- Device_Interrupted: 'The device is performing other operations',
4786
- Not_Use_Onekey_Device: 'Please use onekey device',
4787
- Runtime: '',
4788
- Init_NotInitialized: 'Init_NotInitialized',
4789
- Init_IframeBlocked: 'Init_IframeBlocked',
4790
- Init_IframeTimeout: 'Init_IframeTimeout',
4791
- Init_AlreadyInitialized: 'Init_AlreadyInitialized',
4792
- Init_IframeLoadFail: 'Init_IframeLoadFail'
4793
- };
4794
-
4795
- class OnekeyError extends Error {
4796
- constructor(code, message) {
4797
- super(message);
4798
- this.code = code;
4799
- this.message = message;
4800
- }
4801
-
4802
- }
4803
-
4804
- const TypedError = (id, message) => new OnekeyError(id, message || ERROR_CODES[id]);
4805
-
4806
- const serializeError = payload => {
4807
- if (payload && payload.error instanceof Error) {
4808
- return {
4809
- error: payload.error.message,
4810
- code: payload.error.code
4811
- };
4812
- }
4813
-
4814
- return payload;
4815
- };
4816
-
4817
- var errors = /*#__PURE__*/Object.freeze({
4818
- __proto__: null,
4819
- ERROR_CODES: ERROR_CODES,
4820
- OnekeyError: OnekeyError,
4821
- TypedError: TypedError,
4822
- serializeError: serializeError
4823
- });
4824
4777
  const colors = {
4825
4778
  '@onekey/connect': 'color: #f4a742; background: #000;',
4826
4779
  IFrame: 'color: #f4a742; background: #000;',
@@ -5015,35 +4968,6 @@ const versionCompare = (a, b) => {
5015
4968
  return 0;
5016
4969
  };
5017
4970
 
5018
- function create(arg, data) {
5019
- let localResolve = _t => {};
5020
-
5021
- let localReject = _e => {};
5022
-
5023
- let id;
5024
- const promise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
5025
- localResolve = resolve;
5026
- localReject = reject;
5027
-
5028
- if (typeof arg === 'function') {
5029
- try {
5030
- yield arg();
5031
- } catch (error) {
5032
- reject(error);
5033
- }
5034
- }
5035
-
5036
- if (typeof arg === 'string') id = arg;
5037
- }));
5038
- return {
5039
- id,
5040
- data,
5041
- resolve: localResolve,
5042
- reject: localReject,
5043
- promise
5044
- };
5045
- }
5046
-
5047
4971
  const getDeviceModel = features => {
5048
4972
  if (!features || typeof features !== 'object') {
5049
4973
  return 'model_mini';
@@ -5129,8 +5053,8 @@ const toHardened = n => (n | HD_HARDENED) >>> 0;
5129
5053
 
5130
5054
  const fromHardened = n => (n & ~HD_HARDENED) >>> 0;
5131
5055
 
5132
- const PATH_NOT_VALID = TypedError('Method_InvalidParameter', 'Not a valid path');
5133
- const PATH_NEGATIVE_VALUES = TypedError('Method_InvalidParameter', 'Path cannot contain negative values');
5056
+ const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
5057
+ const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
5134
5058
 
5135
5059
  const getHDPath = path => {
5136
5060
  const parts = path.toLowerCase().split('/');
@@ -14124,7 +14048,7 @@ class TransportManager {
14124
14048
  yield this.transport.configure(JSON.stringify(messages));
14125
14049
  this.currentMessages = messages;
14126
14050
  } catch (error) {
14127
- throw TypedError('Transport_InvalidProtobuf', error.message);
14051
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
14128
14052
  }
14129
14053
  });
14130
14054
  }
@@ -14181,13 +14105,24 @@ const parseMessage = messageData => {
14181
14105
  return message;
14182
14106
  };
14183
14107
 
14184
- const createErrorMessage = error => ({
14185
- success: false,
14186
- payload: {
14108
+ const createErrorMessage = error => {
14109
+ let payload = {
14187
14110
  error: error.message,
14188
14111
  code: error.code
14112
+ };
14113
+
14114
+ if (error instanceof hdShared.HardwareError) {
14115
+ payload = {
14116
+ error: error.message,
14117
+ code: error.errorCode
14118
+ };
14189
14119
  }
14190
- });
14120
+
14121
+ return {
14122
+ success: false,
14123
+ payload
14124
+ };
14125
+ };
14191
14126
 
14192
14127
  const UI_EVENT = 'UI_EVENT';
14193
14128
  const UI_REQUEST$1 = {
@@ -14197,7 +14132,8 @@ const UI_REQUEST$1 = {
14197
14132
  CLOSE_UI_WINDOW: 'ui-close_window',
14198
14133
  BLUETOOTH_PERMISSION: 'ui-bluetooth_permission',
14199
14134
  LOCATION_PERMISSION: 'ui-location_permission',
14200
- FIRMWARE_PROGRESS: 'ui-firmware-progress'
14135
+ FIRMWARE_PROGRESS: 'ui-firmware-progress',
14136
+ NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode'
14201
14137
  };
14202
14138
 
14203
14139
  const createUiMessage = (type, payload) => ({
@@ -14226,7 +14162,7 @@ const createResponseMessage = (id, success, payload) => ({
14226
14162
  type: RESPONSE_EVENT,
14227
14163
  id,
14228
14164
  success,
14229
- payload: success ? payload : serializeError(payload)
14165
+ payload: success ? payload : hdShared.serializeError(payload)
14230
14166
  });
14231
14167
 
14232
14168
  const UI_RESPONSE = {
@@ -14269,7 +14205,7 @@ const assertType = (res, resType) => {
14269
14205
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14270
14206
 
14271
14207
  if (!splitResTypes.includes(res.type)) {
14272
- throw TypedError('Runtime', `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14208
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14273
14209
  }
14274
14210
  };
14275
14211
 
@@ -14316,7 +14252,7 @@ class DeviceCommands {
14316
14252
  typedCall(type, resType, msg) {
14317
14253
  return __awaiter(this, void 0, void 0, function* () {
14318
14254
  if (this.disposed) {
14319
- throw TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
14255
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'typedCall: DeviceCommands already disposed');
14320
14256
  }
14321
14257
 
14322
14258
  const response = yield this._commonCall(type, msg);
@@ -14346,19 +14282,32 @@ class DeviceCommands {
14346
14282
  const {
14347
14283
  code
14348
14284
  } = res.message;
14349
- let {
14285
+ const {
14350
14286
  message
14351
14287
  } = res.message;
14288
+ let error = null;
14352
14289
 
14353
14290
  if (code === 'Failure_FirmwareError' && !message) {
14354
- message = 'Firmware installation failed';
14291
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError);
14355
14292
  }
14356
14293
 
14357
- if (code === 'Failure_ActionCancelled' && !message) {
14358
- message = 'Action cancelled by user';
14294
+ if (code === 'Failure_ActionCancelled') {
14295
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled);
14359
14296
  }
14360
14297
 
14361
- return Promise.reject(new OnekeyError(code || 'Failure_UnknownCode', message || 'Failure_UnknownMessage'));
14298
+ if (code === 'Failure_PinInvalid') {
14299
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinInvalid, message);
14300
+ }
14301
+
14302
+ if (code === 'Failure_PinCancelled') {
14303
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinCancelled);
14304
+ }
14305
+
14306
+ if (error) {
14307
+ return Promise.reject(error);
14308
+ }
14309
+
14310
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${code || 'Failure_UnknownCode'},${message || 'Failure_UnknownMessage'}`));
14362
14311
  }
14363
14312
 
14364
14313
  if (res.type === 'Features') {
@@ -14410,7 +14359,7 @@ class DeviceCommands {
14410
14359
  });
14411
14360
  } else {
14412
14361
  console.warn('[DeviceCommands] [call] PIN callback not configured, cancelling request');
14413
- reject(TypedError('Runtime', '_promptPin: PIN callback not configured'));
14362
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPin: PIN callback not configured'));
14414
14363
  }
14415
14364
  });
14416
14365
  }
@@ -14763,7 +14712,7 @@ class Device extends events.exports {
14763
14712
  }
14764
14713
 
14765
14714
  options = parseRunOptions(options);
14766
- this.runPromise = create(this._runInner.bind(this, fn, options));
14715
+ this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
14767
14716
  return this.runPromise.promise;
14768
14717
  });
14769
14718
  }
@@ -14779,7 +14728,7 @@ class Device extends events.exports {
14779
14728
  }
14780
14729
  } catch (error) {
14781
14730
  this.runPromise = null;
14782
- return Promise.reject(TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}, code: ${error.code}`));
14731
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
14783
14732
  }
14784
14733
  }
14785
14734
 
@@ -14811,7 +14760,7 @@ class Device extends events.exports {
14811
14760
  }
14812
14761
 
14813
14762
  if (this.runPromise) {
14814
- this.runPromise.reject(TypedError('Device_Interrupted'));
14763
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
14815
14764
  }
14816
14765
  }
14817
14766
 
@@ -15108,7 +15057,7 @@ const formatAnyHex = value => {
15108
15057
  return value;
15109
15058
  };
15110
15059
 
15111
- const invalidParameter = message => TypedError('Method_InvalidParameter', message);
15060
+ const invalidParameter = message => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
15112
15061
 
15113
15062
  const validateParams = (values, fields) => {
15114
15063
  fields.forEach(field => {
@@ -15421,11 +15370,11 @@ const getCoinInfo = (path, coin) => {
15421
15370
 
15422
15371
  if (!coinInfo) {
15423
15372
  if (coin) {
15424
- throw TypedError('Method_InvalidParameter', `Invalid coin name: ${coin}`);
15373
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
15425
15374
  } else if (path) {
15426
- throw TypedError('Method_InvalidParameter', `Invalid path: ${path[0]}`);
15375
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
15427
15376
  } else {
15428
- throw TypedError('Method_InvalidParameter');
15377
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
15429
15378
  }
15430
15379
  }
15431
15380
 
@@ -15668,17 +15617,17 @@ const requestPrevTxInfo$1 = ({
15668
15617
  } = details;
15669
15618
 
15670
15619
  if (!tx_hash) {
15671
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15620
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15672
15621
  }
15673
15622
 
15674
15623
  const tx = refTxs[tx_hash.toLowerCase()];
15675
15624
 
15676
15625
  if (!tx) {
15677
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15626
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15678
15627
  }
15679
15628
 
15680
15629
  if (request_type === 'TXINPUT') {
15681
- if (!tx.bin_outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
15630
+ if (!tx.bin_outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
15682
15631
  return typedCall('TxAckPrevInput', 'TxRequest', {
15683
15632
  tx: {
15684
15633
  input: tx.inputs[details.request_index]
@@ -15687,7 +15636,7 @@ const requestPrevTxInfo$1 = ({
15687
15636
  }
15688
15637
 
15689
15638
  if (request_type === 'TXOUTPUT') {
15690
- if (!tx.bin_outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
15639
+ if (!tx.bin_outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
15691
15640
  return typedCall('TxAckPrevOutput', 'TxRequest', {
15692
15641
  tx: {
15693
15642
  output: tx.bin_outputs[details.request_index]
@@ -15696,7 +15645,7 @@ const requestPrevTxInfo$1 = ({
15696
15645
  }
15697
15646
 
15698
15647
  if (request_type === 'TXORIGINPUT') {
15699
- if (!tx.outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
15648
+ if (!tx.outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
15700
15649
  return typedCall('TxAckInput', 'TxRequest', {
15701
15650
  tx: {
15702
15651
  input: tx.inputs[details.request_index]
@@ -15705,7 +15654,7 @@ const requestPrevTxInfo$1 = ({
15705
15654
  }
15706
15655
 
15707
15656
  if (request_type === 'TXORIGOUTPUT') {
15708
- if (!tx.outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
15657
+ if (!tx.outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
15709
15658
  return typedCall('TxAckOutput', 'TxRequest', {
15710
15659
  tx: {
15711
15660
  output: tx.outputs[details.request_index]
@@ -15715,15 +15664,15 @@ const requestPrevTxInfo$1 = ({
15715
15664
 
15716
15665
  if (request_type === 'TXEXTRADATA') {
15717
15666
  if (typeof details.extra_data_len !== 'number') {
15718
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15667
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15719
15668
  }
15720
15669
 
15721
15670
  if (typeof details.extra_data_offset !== 'number') {
15722
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15671
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15723
15672
  }
15724
15673
 
15725
15674
  if (typeof tx.extra_data !== 'string') {
15726
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15675
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15727
15676
  }
15728
15677
 
15729
15678
  const data = tx.extra_data;
@@ -15755,7 +15704,7 @@ const requestPrevTxInfo$1 = ({
15755
15704
  });
15756
15705
  }
15757
15706
 
15758
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15707
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15759
15708
  };
15760
15709
 
15761
15710
  const requestSignedTxInfo$1 = ({
@@ -15784,14 +15733,14 @@ const requestSignedTxInfo$1 = ({
15784
15733
  }
15785
15734
 
15786
15735
  if (request_type === 'TXMETA') {
15787
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15736
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15788
15737
  }
15789
15738
 
15790
15739
  if (request_type === 'TXEXTRADATA') {
15791
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15740
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15792
15741
  }
15793
15742
 
15794
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15743
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15795
15744
  };
15796
15745
 
15797
15746
  const requestTxAck$1 = props => {
@@ -15820,7 +15769,7 @@ const saveTxSignatures$1 = (serializedTx, signatures, txRequest) => {
15820
15769
 
15821
15770
  if (typeof signature_index === 'number') {
15822
15771
  if (!signature) {
15823
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15772
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15824
15773
  }
15825
15774
 
15826
15775
  signatures[signature_index] = signature;
@@ -15895,17 +15844,17 @@ const requestPrevTxInfo = ({
15895
15844
  } = details;
15896
15845
 
15897
15846
  if (!tx_hash) {
15898
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15847
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15899
15848
  }
15900
15849
 
15901
15850
  const tx = refTxs[tx_hash.toLowerCase()];
15902
15851
 
15903
15852
  if (!tx) {
15904
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15853
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15905
15854
  }
15906
15855
 
15907
15856
  if (!tx.bin_outputs) {
15908
- throw TypedError('Runtime', `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
15857
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
15909
15858
  }
15910
15859
 
15911
15860
  if (request_type === 'TXINPUT') {
@@ -15922,15 +15871,15 @@ const requestPrevTxInfo = ({
15922
15871
 
15923
15872
  if (request_type === 'TXEXTRADATA') {
15924
15873
  if (typeof details.extra_data_len !== 'number') {
15925
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15874
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15926
15875
  }
15927
15876
 
15928
15877
  if (typeof details.extra_data_offset !== 'number') {
15929
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15878
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15930
15879
  }
15931
15880
 
15932
15881
  if (typeof tx.extra_data !== 'string') {
15933
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15882
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15934
15883
  }
15935
15884
 
15936
15885
  const data = tx.extra_data;
@@ -15964,7 +15913,7 @@ const requestPrevTxInfo = ({
15964
15913
  return meta;
15965
15914
  }
15966
15915
 
15967
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15916
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15968
15917
  };
15969
15918
 
15970
15919
  const requestSignedTxInfo = ({
@@ -15988,14 +15937,14 @@ const requestSignedTxInfo = ({
15988
15937
  }
15989
15938
 
15990
15939
  if (request_type === 'TXMETA') {
15991
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15940
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15992
15941
  }
15993
15942
 
15994
15943
  if (request_type === 'TXEXTRADATA') {
15995
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15944
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15996
15945
  }
15997
15946
 
15998
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15947
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15999
15948
  };
16000
15949
 
16001
15950
  const requestTxAck = props => {
@@ -16024,7 +15973,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
16024
15973
 
16025
15974
  if (typeof signature_index === 'number') {
16026
15975
  if (!signature) {
16027
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15976
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
16028
15977
  }
16029
15978
 
16030
15979
  signatures[signature_index] = signature;
@@ -16212,12 +16161,12 @@ class BTCSignTransaction extends BaseMethod {
16212
16161
  }]);
16213
16162
 
16214
16163
  if (Object.prototype.hasOwnProperty.call(output, 'address_n') && Object.prototype.hasOwnProperty.call(output, 'address')) {
16215
- throw TypedError('Method_InvalidParameter', 'Cannot use address and address_n in one output');
16164
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
16216
16165
  }
16217
16166
 
16218
16167
  if (output.address_n) {
16219
16168
  const scriptType = getOutputScriptType(output.address_n);
16220
- if (output.script_type !== scriptType) throw TypedError('Method_InvalidParameter', `Output change script_type should be set to ${scriptType}`);
16169
+ if (output.script_type !== scriptType) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
16221
16170
  }
16222
16171
  });
16223
16172
  const {
@@ -16846,7 +16795,7 @@ class EVMSignTransaction extends BaseMethod {
16846
16795
  const s = request.signature_s;
16847
16796
 
16848
16797
  if (v == null || r == null || s == null) {
16849
- throw TypedError('Runtime', 'processTxRequest: Unexpected request');
16798
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
16850
16799
  }
16851
16800
 
16852
16801
  if (chain_id && v <= 1) {
@@ -17080,7 +17029,7 @@ class EVMSignTypedData extends BaseMethod {
17080
17029
  if (messageHash) {
17081
17030
  this.params.messageHash = formatAnyHex(messageHash);
17082
17031
  } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
17083
- throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
17032
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'message_hash should only be empty when data.primaryType=EIP712Domain');
17084
17033
  }
17085
17034
  }
17086
17035
  }
@@ -17111,7 +17060,7 @@ class EVMSignTypedData extends BaseMethod {
17111
17060
  run() {
17112
17061
  return __awaiter(this, void 0, void 0, function* () {
17113
17062
  if (!this.device.features) {
17114
- throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17063
+ throw hdShared.ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17115
17064
  }
17116
17065
 
17117
17066
  const {
@@ -17152,7 +17101,7 @@ class EVMSignTypedData extends BaseMethod {
17152
17101
  return Promise.resolve(response.message);
17153
17102
  }
17154
17103
 
17155
- return Promise.resolve(TypedError('Runtime', 'Not implemented'));
17104
+ return Promise.resolve(hdShared.ERRORS.TypedError('Runtime', 'Not implemented'));
17156
17105
  });
17157
17106
  }
17158
17107
 
@@ -17662,7 +17611,7 @@ class NEMSignTransaction extends BaseMethod {
17662
17611
  break;
17663
17612
 
17664
17613
  default:
17665
- throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
17614
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
17666
17615
  }
17667
17616
 
17668
17617
  return message;
@@ -18140,15 +18089,22 @@ const getBinary = ({
18140
18089
  });
18141
18090
 
18142
18091
  if (!releaseInfo) {
18143
- throw TypedError('Runtime', 'no firmware found for this device');
18092
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
18144
18093
  }
18145
18094
 
18146
18095
  if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
18147
- throw TypedError('Runtime', 'firmware version mismatch');
18096
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
18148
18097
  }
18149
18098
 
18150
18099
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
18151
- const fw = yield httpRequest(url, 'binary');
18100
+ let fw;
18101
+
18102
+ try {
18103
+ fw = yield httpRequest(url, 'binary');
18104
+ } catch (_a) {
18105
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
18106
+ }
18107
+
18152
18108
  return Object.assign(Object.assign({}, releaseInfo), {
18153
18109
  binary: fw
18154
18110
  });
@@ -18200,6 +18156,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18200
18156
  } = yield typedCall('FirmwareUpload', 'Success', {
18201
18157
  payload
18202
18158
  });
18159
+ postProgressMessage(device, 100, postMessage);
18203
18160
  return message;
18204
18161
  }
18205
18162
 
@@ -18228,7 +18185,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18228
18185
  return response.message;
18229
18186
  }
18230
18187
 
18231
- throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
18188
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
18232
18189
  });
18233
18190
 
18234
18191
  class FirmwareUpdate extends BaseMethod {
@@ -18247,7 +18204,7 @@ class FirmwareUpdate extends BaseMethod {
18247
18204
  }]);
18248
18205
 
18249
18206
  if (!payload.updateType) {
18250
- throw TypedError('Method_InvalidParameter', 'updateType is required');
18207
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
18251
18208
  }
18252
18209
 
18253
18210
  this.params = {
@@ -18280,7 +18237,7 @@ class FirmwareUpdate extends BaseMethod {
18280
18237
  binary = this.params.binary;
18281
18238
  } else {
18282
18239
  if (!device.features) {
18283
- throw TypedError('Runtime', 'no features found for this device');
18240
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
18284
18241
  }
18285
18242
 
18286
18243
  const firmware = yield getBinary({
@@ -18291,7 +18248,7 @@ class FirmwareUpdate extends BaseMethod {
18291
18248
  binary = firmware.binary;
18292
18249
  }
18293
18250
  } catch (err) {
18294
- throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
18251
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
18295
18252
  }
18296
18253
 
18297
18254
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
@@ -18351,7 +18308,7 @@ function findMethod(message) {
18351
18308
  } = message.payload;
18352
18309
 
18353
18310
  if (typeof method !== 'string') {
18354
- throw TypedError('Method_InvalidParameter', 'Method is not set');
18311
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
18355
18312
  }
18356
18313
 
18357
18314
  const MethodConstructor = ApiMethods[method];
@@ -18360,9 +18317,17 @@ function findMethod(message) {
18360
18317
  return new MethodConstructor(message);
18361
18318
  }
18362
18319
 
18363
- throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
18320
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
18364
18321
  }
18365
18322
 
18323
+ const safeThrowError = error => {
18324
+ if (error instanceof hdShared.HardwareError) {
18325
+ throw error;
18326
+ } else {
18327
+ throw hdShared.ERRORS.TypedError(error);
18328
+ }
18329
+ };
18330
+
18366
18331
  const resolveAfter = (msec, value) => new Promise(resolve => {
18367
18332
  setTimeout(resolve, msec, value);
18368
18333
  });
@@ -18437,7 +18402,7 @@ class DeviceConnector {
18437
18402
  Log$1.debug('diff result: ', diff);
18438
18403
  return diff;
18439
18404
  } catch (error) {
18440
- throw new Error(error);
18405
+ safeThrowError(error);
18441
18406
  }
18442
18407
  });
18443
18408
  }
@@ -18499,7 +18464,7 @@ class DeviceConnector {
18499
18464
 
18500
18465
  return res;
18501
18466
  } catch (error) {
18502
- throw new Error(error);
18467
+ safeThrowError(error);
18503
18468
  }
18504
18469
  });
18505
18470
  }
@@ -18510,7 +18475,7 @@ class DeviceConnector {
18510
18475
  const res = yield this.transport.release(session, onclose);
18511
18476
  return res;
18512
18477
  } catch (error) {
18513
- throw new Error(error);
18478
+ safeThrowError(error);
18514
18479
  }
18515
18480
  });
18516
18481
  }
@@ -18538,10 +18503,10 @@ let _callPromise;
18538
18503
  const deviceCacheMap = new Map();
18539
18504
 
18540
18505
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18541
- var _a, _b;
18506
+ var _a;
18542
18507
 
18543
18508
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
18544
- return Promise.reject(TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing'));
18509
+ return Promise.reject(hdShared.ERRORS.TypedError('on call: message.id or message.payload is missing'));
18545
18510
  }
18546
18511
 
18547
18512
  let method;
@@ -18562,8 +18527,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18562
18527
  return createResponseMessage(method.responseID, true, response);
18563
18528
  } catch (error) {
18564
18529
  return createResponseMessage(method.responseID, false, {
18565
- code: error.code,
18566
- error: (_a = error.message) !== null && _a !== void 0 ? _a : error
18530
+ error
18567
18531
  });
18568
18532
  }
18569
18533
  }
@@ -18588,7 +18552,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18588
18552
  }
18589
18553
 
18590
18554
  Log.debug('Call API - setDevice: ', device);
18591
- (_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
18555
+ (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
18592
18556
  device.on(DEVICE.PIN, onDevicePinHandler);
18593
18557
  device.on(DEVICE.BUTTON, (d, code) => {
18594
18558
  onDeviceButtonHandler(d, code);
@@ -18606,18 +18570,22 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18606
18570
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
18607
18571
 
18608
18572
  if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
18609
- return Promise.reject(TypedError('Device_FwException', `Device firmware version is too low, please update to ${versionRange.min}`));
18573
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too low, please update to ${versionRange.min}`));
18610
18574
  }
18611
18575
 
18612
18576
  if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gt(currentVersion, versionRange.max)) {
18613
- return Promise.reject(TypedError('Device_FwException', `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
18577
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
18614
18578
  }
18615
18579
  }
18616
18580
 
18617
18581
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
18618
18582
 
18619
18583
  if (unexpectedMode) {
18620
- return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
18584
+ if (unexpectedMode === UI_REQUEST$1.NOT_IN_BOOTLOADER) {
18585
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedBootloaderMode));
18586
+ }
18587
+
18588
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
18621
18589
  }
18622
18590
 
18623
18591
  if (_deviceList) {
@@ -18631,7 +18599,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18631
18599
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18632
18600
  } catch (error) {
18633
18601
  Log.debug('Call API - Inner Method Run Error: ', error);
18634
- messageResponse = createResponseMessage(method.responseID, false, error.message);
18602
+ messageResponse = createResponseMessage(method.responseID, false, {
18603
+ error
18604
+ });
18635
18605
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18636
18606
  }
18637
18607
  });
@@ -18640,17 +18610,21 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18640
18610
 
18641
18611
  const deviceRun = () => device.run(inner);
18642
18612
 
18643
- _callPromise = create(deviceRun);
18613
+ _callPromise = hdShared.createDeferred(deviceRun);
18644
18614
 
18645
18615
  try {
18646
18616
  return yield _callPromise.promise;
18647
18617
  } catch (e) {
18648
18618
  console.log('Device Run Error: ', e);
18649
- return createResponseMessage(method.responseID, false, e.message);
18619
+ return createResponseMessage(method.responseID, false, {
18620
+ error: e
18621
+ });
18650
18622
  }
18651
18623
  } catch (error) {
18652
- messageResponse = createResponseMessage(method.responseID, false, error);
18653
- _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
18624
+ messageResponse = createResponseMessage(method.responseID, false, {
18625
+ error
18626
+ });
18627
+ _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
18654
18628
  Log.debug('Call API - Run Error: ', error);
18655
18629
  } finally {
18656
18630
  const response = messageResponse;
@@ -18687,7 +18661,7 @@ function initDeviceList(method) {
18687
18661
 
18688
18662
  function initDevice(method) {
18689
18663
  if (!_deviceList) {
18690
- throw TypedError('Call_API', 'DeviceList is not initialized');
18664
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18691
18665
  }
18692
18666
 
18693
18667
  let device;
@@ -18699,11 +18673,11 @@ function initDevice(method) {
18699
18673
  } else if (allDevices.length === 1) {
18700
18674
  [device] = allDevices;
18701
18675
  } else if (allDevices.length > 1) {
18702
- throw TypedError('Call_API', '请选择连接设备');
18676
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
18703
18677
  }
18704
18678
 
18705
18679
  if (!device) {
18706
- throw TypedError('Call_API', 'Device Not Found');
18680
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
18707
18681
  }
18708
18682
 
18709
18683
  device.deviceConnector = _connector;
@@ -18712,7 +18686,7 @@ function initDevice(method) {
18712
18686
 
18713
18687
  function initDeviceForBle(method) {
18714
18688
  if (!method.connectId && !_deviceList) {
18715
- throw TypedError('Call_API', 'DeviceList is not initialized');
18689
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18716
18690
  }
18717
18691
 
18718
18692
  if (!method.connectId) {
@@ -18799,7 +18773,7 @@ const postMessage = message => {
18799
18773
  };
18800
18774
 
18801
18775
  const createUiPromise = (promiseEvent, device) => {
18802
- const uiPromise = create(promiseEvent, device);
18776
+ const uiPromise = hdShared.createDeferred(promiseEvent, device);
18803
18777
 
18804
18778
  _uiPromises.push(uiPromise);
18805
18779
 
@@ -18875,7 +18849,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
18875
18849
  try {
18876
18850
  yield DataManager.load(settings);
18877
18851
  initTransport(Transport);
18878
- } catch (_c) {
18852
+ } catch (_b) {
18879
18853
  Log.error('DataManager.load error');
18880
18854
  }
18881
18855
 
@@ -18916,14 +18890,12 @@ __webpack_unused_export__ = DEFAULT_PRIORITY;
18916
18890
  __webpack_unused_export__ = DEVICE;
18917
18891
  __webpack_unused_export__ = DEVICE_EVENT;
18918
18892
  __webpack_unused_export__ = DataManager;
18919
- exports.Sg = errors;
18920
18893
  exports.Bg = IFRAME;
18921
18894
  __webpack_unused_export__ = RESPONSE_EVENT;
18922
18895
  exports.rF = UI_EVENT;
18923
18896
  __webpack_unused_export__ = UI_REQUEST$1;
18924
18897
  __webpack_unused_export__ = UI_RESPONSE;
18925
18898
  __webpack_unused_export__ = corsValidator;
18926
- exports.Ue = create;
18927
18899
  __webpack_unused_export__ = createDeviceMessage;
18928
18900
  exports.xG = createErrorMessage;
18929
18901
  __webpack_unused_export__ = createIFrameMessage;
@@ -18949,6 +18921,7 @@ __webpack_unused_export__ = isValidVersionString;
18949
18921
  __webpack_unused_export__ = normalizeVersionArray;
18950
18922
  exports._4 = parseConnectSettings;
18951
18923
  exports.kW = parseMessage;
18924
+ __webpack_unused_export__ = safeThrowError;
18952
18925
  __webpack_unused_export__ = versionCompare;
18953
18926
  __webpack_unused_export__ = versionSplit;
18954
18927
 
@@ -19973,6 +19946,253 @@ exports["default"] = index;
19973
19946
 
19974
19947
  /***/ }),
19975
19948
 
19949
+ /***/ 8402:
19950
+ /***/ ((__unused_webpack_module, exports) => {
19951
+
19952
+ "use strict";
19953
+
19954
+
19955
+ Object.defineProperty(exports, "__esModule", ({
19956
+ value: true
19957
+ }));
19958
+ /******************************************************************************
19959
+ Copyright (c) Microsoft Corporation.
19960
+
19961
+ Permission to use, copy, modify, and/or distribute this software for any
19962
+ purpose with or without fee is hereby granted.
19963
+
19964
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19965
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19966
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19967
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19968
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19969
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19970
+ PERFORMANCE OF THIS SOFTWARE.
19971
+ ***************************************************************************** */
19972
+
19973
+ function __awaiter(thisArg, _arguments, P, generator) {
19974
+ function adopt(value) {
19975
+ return value instanceof P ? value : new P(function (resolve) {
19976
+ resolve(value);
19977
+ });
19978
+ }
19979
+
19980
+ return new (P || (P = Promise))(function (resolve, reject) {
19981
+ function fulfilled(value) {
19982
+ try {
19983
+ step(generator.next(value));
19984
+ } catch (e) {
19985
+ reject(e);
19986
+ }
19987
+ }
19988
+
19989
+ function rejected(value) {
19990
+ try {
19991
+ step(generator["throw"](value));
19992
+ } catch (e) {
19993
+ reject(e);
19994
+ }
19995
+ }
19996
+
19997
+ function step(result) {
19998
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
19999
+ }
20000
+
20001
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20002
+ });
20003
+ }
20004
+
20005
+ function createDeferred(arg, data) {
20006
+ let localResolve = _t => {};
20007
+
20008
+ let localReject = _e => {};
20009
+
20010
+ let id;
20011
+ const promise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
20012
+ localResolve = resolve;
20013
+ localReject = reject;
20014
+
20015
+ if (typeof arg === 'function') {
20016
+ try {
20017
+ yield arg();
20018
+ } catch (error) {
20019
+ reject(error);
20020
+ }
20021
+ }
20022
+
20023
+ if (typeof arg === 'string') id = arg;
20024
+ }));
20025
+ return {
20026
+ id,
20027
+ data,
20028
+ resolve: localResolve,
20029
+ reject: localReject,
20030
+ promise
20031
+ };
20032
+ }
20033
+
20034
+ function fillStringWithArguments(value, object) {
20035
+ return value.replace(/\{([^}]+)\}/g, (_, arg) => object[arg] || '?');
20036
+ }
20037
+
20038
+ class HardwareError extends Error {
20039
+ constructor(hardwareError) {
20040
+ var _a;
20041
+
20042
+ super();
20043
+ this.errorCode = HardwareErrorCode.UnknownError;
20044
+ this.message = '';
20045
+ const errorMessageMapping = HardwareErrorCodeMessage;
20046
+ this.message = errorMessageMapping[HardwareErrorCode.UnknownError];
20047
+
20048
+ if (typeof hardwareError === 'string') {
20049
+ this.errorCode = HardwareErrorCode.UnknownError;
20050
+ this.message = hardwareError;
20051
+ } else {
20052
+ const message = (_a = hardwareError.message || errorMessageMapping[hardwareError.errorCode]) !== null && _a !== void 0 ? _a : '';
20053
+
20054
+ if (message) {
20055
+ this.message = fillStringWithArguments(message, hardwareError);
20056
+ }
20057
+
20058
+ this.errorCode = hardwareError.errorCode;
20059
+ }
20060
+
20061
+ this.name = 'HardwareError';
20062
+ }
20063
+
20064
+ }
20065
+
20066
+ const HardwareErrorCode = {
20067
+ UnknownError: 0,
20068
+ DeviceFwException: 101,
20069
+ DeviceUnexpectedMode: 102,
20070
+ DeviceListNotInitialized: 103,
20071
+ SelectDevice: 104,
20072
+ DeviceNotFound: 105,
20073
+ DeviceInitializeFailed: 106,
20074
+ DeviceInterruptedFromOutside: 107,
20075
+ DeviceUnexpectedBootloaderMode: 108,
20076
+ NotInitialized: 200,
20077
+ IFrameNotInitialized: 300,
20078
+ IFrameAleradyInitialized: 301,
20079
+ IFrameLoadFail: 302,
20080
+ IframeTimeout: 303,
20081
+ IframeBlocked: 304,
20082
+ CallMethodError: 400,
20083
+ CallMethodNotResponse: 404,
20084
+ CallMethodInvalidParameter: 405,
20085
+ FirmwareUpdateDownloadFailed: 406,
20086
+ NetworkError: 500,
20087
+ TransportNotConfigured: 600,
20088
+ TransportCallInProgress: 601,
20089
+ TransportNotFound: 602,
20090
+ TransportInvalidProtobuf: 603,
20091
+ BleScanError: 700,
20092
+ BlePermissionError: 701,
20093
+ BleLocationError: 702,
20094
+ BleRequiredUUID: 703,
20095
+ BleConnectedError: 704,
20096
+ BleDeviceNotBonded: 705,
20097
+ BleServiceNotFound: 706,
20098
+ BleCharacteristicNotFound: 707,
20099
+ BleMonitorError: 708,
20100
+ BleCharacteristicNotifyError: 709,
20101
+ RuntimeError: 800,
20102
+ PinInvalid: 801,
20103
+ PinCancelled: 802,
20104
+ ActionCancelled: 803,
20105
+ FirmwareError: 804
20106
+ };
20107
+ const HardwareErrorCodeMessage = {
20108
+ [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
20109
+ [HardwareErrorCode.DeviceFwException]: 'Firmware version mismatch',
20110
+ [HardwareErrorCode.DeviceUnexpectedMode]: 'Device unexpected mode',
20111
+ [HardwareErrorCode.DeviceListNotInitialized]: 'Device list is not initialized',
20112
+ [HardwareErrorCode.SelectDevice]: 'Please select the connected device',
20113
+ [HardwareErrorCode.DeviceNotFound]: 'Device not found',
20114
+ [HardwareErrorCode.DeviceInitializeFailed]: 'Device initialization failed',
20115
+ [HardwareErrorCode.DeviceInterruptedFromOutside]: 'Device interrupted',
20116
+ [HardwareErrorCode.DeviceUnexpectedBootloaderMode]: 'Device should be in bootloader mode',
20117
+ [HardwareErrorCode.NotInitialized]: 'Not initialized',
20118
+ [HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
20119
+ [HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
20120
+ [HardwareErrorCode.IFrameLoadFail]: 'IFrame load fail',
20121
+ [HardwareErrorCode.IframeTimeout]: 'init iframe time out',
20122
+ [HardwareErrorCode.IframeBlocked]: 'IFrame blocked',
20123
+ [HardwareErrorCode.CallMethodError]: 'Runtime errors during method execution',
20124
+ [HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
20125
+ [HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
20126
+ [HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
20127
+ [HardwareErrorCode.NetworkError]: 'Network request error',
20128
+ [HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
20129
+ [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
20130
+ [HardwareErrorCode.TransportNotFound]: 'Transport not found',
20131
+ [HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
20132
+ [HardwareErrorCode.BleScanError]: 'BLE scan error',
20133
+ [HardwareErrorCode.BlePermissionError]: 'Bluetooth required to be turned on',
20134
+ [HardwareErrorCode.BleLocationError]: 'Device is not authorized to use BluetoothLE',
20135
+ [HardwareErrorCode.BleRequiredUUID]: 'uuid is required',
20136
+ [HardwareErrorCode.BleConnectedError]: 'connected error is always runtime error',
20137
+ [HardwareErrorCode.BleDeviceNotBonded]: 'device is not bonded',
20138
+ [HardwareErrorCode.BleServiceNotFound]: 'BLEServiceNotFound: service not found',
20139
+ [HardwareErrorCode.BleCharacteristicNotFound]: 'BLEServiceNotFound: service not found',
20140
+ [HardwareErrorCode.BleMonitorError]: 'Monitor Error: characteristic not found',
20141
+ [HardwareErrorCode.BleCharacteristicNotifyError]: 'Characteristic Notify Error',
20142
+ [HardwareErrorCode.RuntimeError]: 'Runtime error',
20143
+ [HardwareErrorCode.PinInvalid]: 'Pin invalid',
20144
+ [HardwareErrorCode.PinCancelled]: 'Pin cancelled',
20145
+ [HardwareErrorCode.ActionCancelled]: 'Action cancelled by user',
20146
+ [HardwareErrorCode.FirmwareError]: 'Firmware installation failed'
20147
+ };
20148
+
20149
+ const TypedError = (hardwareError, message) => {
20150
+ if (typeof hardwareError === 'string') {
20151
+ return new HardwareError(hardwareError);
20152
+ }
20153
+
20154
+ return new HardwareError({
20155
+ errorCode: hardwareError,
20156
+ message: message !== null && message !== void 0 ? message : ''
20157
+ });
20158
+ };
20159
+
20160
+ const serializeError = payload => {
20161
+ if (payload && payload.error instanceof HardwareError) {
20162
+ return {
20163
+ error: payload.error.message,
20164
+ code: payload.error.errorCode
20165
+ };
20166
+ }
20167
+
20168
+ if (payload && payload.error instanceof Error) {
20169
+ return {
20170
+ error: payload.error.message,
20171
+ code: payload.error.code
20172
+ };
20173
+ }
20174
+
20175
+ return payload;
20176
+ };
20177
+
20178
+ var HardwareError$1 = /*#__PURE__*/Object.freeze({
20179
+ __proto__: null,
20180
+ HardwareError: HardwareError,
20181
+ HardwareErrorCode: HardwareErrorCode,
20182
+ HardwareErrorCodeMessage: HardwareErrorCodeMessage,
20183
+ TypedError: TypedError,
20184
+ serializeError: serializeError
20185
+ });
20186
+ exports.ERRORS = HardwareError$1;
20187
+ exports.HardwareError = HardwareError;
20188
+ exports.HardwareErrorCode = HardwareErrorCode;
20189
+ exports.HardwareErrorCodeMessage = HardwareErrorCodeMessage;
20190
+ exports.TypedError = TypedError;
20191
+ exports.createDeferred = createDeferred;
20192
+ exports.serializeError = serializeError;
20193
+
20194
+ /***/ }),
20195
+
19976
20196
  /***/ 5766:
19977
20197
  /***/ ((__unused_webpack_module, exports) => {
19978
20198
 
@@ -42190,6 +42410,8 @@ var events = __webpack_require__(2699);
42190
42410
  var events_default = /*#__PURE__*/__webpack_require__.n(events);
42191
42411
  // EXTERNAL MODULE: ../core/dist/index.js
42192
42412
  var dist = __webpack_require__(5890);
42413
+ // EXTERNAL MODULE: ../shared/dist/index.js
42414
+ var shared_dist = __webpack_require__(8402);
42193
42415
  ;// CONCATENATED MODULE: ./src/utils/urlUtils.ts
42194
42416
  const getOrigin = url => {
42195
42417
  if (typeof url !== 'string') return 'unknown';
@@ -42205,12 +42427,12 @@ const getOrigin = url => {
42205
42427
 
42206
42428
  let instance;
42207
42429
  let origin;
42208
- let initPromise = (0,dist/* create */.Ue)();
42430
+ let initPromise = (0,shared_dist.createDeferred)();
42209
42431
  let timeout = 0;
42210
42432
  /* eslint-disable import/no-mutable-exports */
42211
42433
 
42212
42434
  const init = async settings => {
42213
- initPromise = (0,dist/* create */.Ue)();
42435
+ initPromise = (0,shared_dist.createDeferred)();
42214
42436
  const existedFrame = document.getElementById('onekey-connect');
42215
42437
 
42216
42438
  if (existedFrame) {
@@ -42233,14 +42455,14 @@ const init = async settings => {
42233
42455
  instance.setAttribute('src', src);
42234
42456
  origin = getOrigin(instance.src);
42235
42457
  timeout = window.setTimeout(() => {
42236
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeTimeout'));
42458
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeTimeout));
42237
42459
  }, 10000);
42238
42460
 
42239
42461
  const onLoad = () => {
42240
42462
  var _instance$contentWind;
42241
42463
 
42242
42464
  if (!instance) {
42243
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeBlocked'));
42465
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeBlocked));
42244
42466
  return;
42245
42467
  }
42246
42468
 
@@ -44479,6 +44701,7 @@ const sendMessage = async (messages, isHost = true) => {
44479
44701
 
44480
44702
 
44481
44703
 
44704
+
44482
44705
  const eventEmitter = new (events_default())();
44483
44706
  const src_Log = (0,dist/* initLog */.KR)('@onekey/connect');
44484
44707
 
@@ -44514,7 +44737,7 @@ const src_dispose = () => {
44514
44737
 
44515
44738
  const uiResponse = response => {
44516
44739
  if (!instance) {
44517
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_NotInitialized');
44740
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameNotInitialized);
44518
44741
  }
44519
44742
 
44520
44743
  const {
@@ -44566,7 +44789,7 @@ const createJSBridge = messageEvent => {
44566
44789
 
44567
44790
  const src_init = async settings => {
44568
44791
  if (instance) {
44569
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_AlreadyInitialized');
44792
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameAleradyInitialized);
44570
44793
  }
44571
44794
 
44572
44795
  _settings = (0,dist/* parseConnectSettings */._4)({ ..._settings,
@@ -44600,7 +44823,7 @@ const call = async params => {
44600
44823
  }
44601
44824
 
44602
44825
  if (timeout) {
44603
- return (0,dist/* createErrorMessage */.xG)(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeLoadFail'));
44826
+ return (0,dist/* createErrorMessage */.xG)(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameLoadFail));
44604
44827
  }
44605
44828
 
44606
44829
  try {
@@ -44614,7 +44837,7 @@ const call = async params => {
44614
44837
  return response;
44615
44838
  }
44616
44839
 
44617
- return (0,dist/* createErrorMessage */.xG)(dist/* ERRORS.TypedError */.Sg.TypedError('Call_NotResponse'));
44840
+ return (0,dist/* createErrorMessage */.xG)(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.CallMethodNotResponse));
44618
44841
  } catch (error) {
44619
44842
  src_Log.error('__call error: ', error);
44620
44843
  return (0,dist/* createErrorMessage */.xG)(error);