@onekeyfe/hd-web-sdk 0.1.5 → 0.1.6

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 = {
@@ -14226,7 +14161,7 @@ const createResponseMessage = (id, success, payload) => ({
14226
14161
  type: RESPONSE_EVENT,
14227
14162
  id,
14228
14163
  success,
14229
- payload: success ? payload : serializeError(payload)
14164
+ payload: success ? payload : hdShared.serializeError(payload)
14230
14165
  });
14231
14166
 
14232
14167
  const UI_RESPONSE = {
@@ -14269,7 +14204,7 @@ const assertType = (res, resType) => {
14269
14204
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
14270
14205
 
14271
14206
  if (!splitResTypes.includes(res.type)) {
14272
- throw TypedError('Runtime', `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14207
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
14273
14208
  }
14274
14209
  };
14275
14210
 
@@ -14316,7 +14251,7 @@ class DeviceCommands {
14316
14251
  typedCall(type, resType, msg) {
14317
14252
  return __awaiter(this, void 0, void 0, function* () {
14318
14253
  if (this.disposed) {
14319
- throw TypedError('Runtime', 'typedCall: DeviceCommands already disposed');
14254
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'typedCall: DeviceCommands already disposed');
14320
14255
  }
14321
14256
 
14322
14257
  const response = yield this._commonCall(type, msg);
@@ -14346,19 +14281,32 @@ class DeviceCommands {
14346
14281
  const {
14347
14282
  code
14348
14283
  } = res.message;
14349
- let {
14284
+ const {
14350
14285
  message
14351
14286
  } = res.message;
14287
+ let error = null;
14352
14288
 
14353
14289
  if (code === 'Failure_FirmwareError' && !message) {
14354
- message = 'Firmware installation failed';
14290
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError);
14355
14291
  }
14356
14292
 
14357
- if (code === 'Failure_ActionCancelled' && !message) {
14358
- message = 'Action cancelled by user';
14293
+ if (code === 'Failure_ActionCancelled') {
14294
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled);
14359
14295
  }
14360
14296
 
14361
- return Promise.reject(new OnekeyError(code || 'Failure_UnknownCode', message || 'Failure_UnknownMessage'));
14297
+ if (code === 'Failure_PinInvalid') {
14298
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinInvalid, message);
14299
+ }
14300
+
14301
+ if (code === 'Failure_PinCancelled') {
14302
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinCancelled);
14303
+ }
14304
+
14305
+ if (error) {
14306
+ return Promise.reject(error);
14307
+ }
14308
+
14309
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${code || 'Failure_UnknownCode'},${message || 'Failure_UnknownMessage'}`));
14362
14310
  }
14363
14311
 
14364
14312
  if (res.type === 'Features') {
@@ -14410,7 +14358,7 @@ class DeviceCommands {
14410
14358
  });
14411
14359
  } else {
14412
14360
  console.warn('[DeviceCommands] [call] PIN callback not configured, cancelling request');
14413
- reject(TypedError('Runtime', '_promptPin: PIN callback not configured'));
14361
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPin: PIN callback not configured'));
14414
14362
  }
14415
14363
  });
14416
14364
  }
@@ -14763,7 +14711,7 @@ class Device extends events.exports {
14763
14711
  }
14764
14712
 
14765
14713
  options = parseRunOptions(options);
14766
- this.runPromise = create(this._runInner.bind(this, fn, options));
14714
+ this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
14767
14715
  return this.runPromise.promise;
14768
14716
  });
14769
14717
  }
@@ -14779,7 +14727,7 @@ class Device extends events.exports {
14779
14727
  }
14780
14728
  } catch (error) {
14781
14729
  this.runPromise = null;
14782
- return Promise.reject(TypedError('Device_InitializeFailed', `Initialize failed: ${error.message}, code: ${error.code}`));
14730
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
14783
14731
  }
14784
14732
  }
14785
14733
 
@@ -14811,7 +14759,7 @@ class Device extends events.exports {
14811
14759
  }
14812
14760
 
14813
14761
  if (this.runPromise) {
14814
- this.runPromise.reject(TypedError('Device_Interrupted'));
14762
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
14815
14763
  }
14816
14764
  }
14817
14765
 
@@ -15108,7 +15056,7 @@ const formatAnyHex = value => {
15108
15056
  return value;
15109
15057
  };
15110
15058
 
15111
- const invalidParameter = message => TypedError('Method_InvalidParameter', message);
15059
+ const invalidParameter = message => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
15112
15060
 
15113
15061
  const validateParams = (values, fields) => {
15114
15062
  fields.forEach(field => {
@@ -15421,11 +15369,11 @@ const getCoinInfo = (path, coin) => {
15421
15369
 
15422
15370
  if (!coinInfo) {
15423
15371
  if (coin) {
15424
- throw TypedError('Method_InvalidParameter', `Invalid coin name: ${coin}`);
15372
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
15425
15373
  } else if (path) {
15426
- throw TypedError('Method_InvalidParameter', `Invalid path: ${path[0]}`);
15374
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
15427
15375
  } else {
15428
- throw TypedError('Method_InvalidParameter');
15376
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
15429
15377
  }
15430
15378
  }
15431
15379
 
@@ -15668,17 +15616,17 @@ const requestPrevTxInfo$1 = ({
15668
15616
  } = details;
15669
15617
 
15670
15618
  if (!tx_hash) {
15671
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15619
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15672
15620
  }
15673
15621
 
15674
15622
  const tx = refTxs[tx_hash.toLowerCase()];
15675
15623
 
15676
15624
  if (!tx) {
15677
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15625
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15678
15626
  }
15679
15627
 
15680
15628
  if (request_type === 'TXINPUT') {
15681
- if (!tx.bin_outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
15629
+ if (!tx.bin_outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
15682
15630
  return typedCall('TxAckPrevInput', 'TxRequest', {
15683
15631
  tx: {
15684
15632
  input: tx.inputs[details.request_index]
@@ -15687,7 +15635,7 @@ const requestPrevTxInfo$1 = ({
15687
15635
  }
15688
15636
 
15689
15637
  if (request_type === 'TXOUTPUT') {
15690
- if (!tx.bin_outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
15638
+ if (!tx.bin_outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
15691
15639
  return typedCall('TxAckPrevOutput', 'TxRequest', {
15692
15640
  tx: {
15693
15641
  output: tx.bin_outputs[details.request_index]
@@ -15696,7 +15644,7 @@ const requestPrevTxInfo$1 = ({
15696
15644
  }
15697
15645
 
15698
15646
  if (request_type === 'TXORIGINPUT') {
15699
- if (!tx.outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
15647
+ if (!tx.outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
15700
15648
  return typedCall('TxAckInput', 'TxRequest', {
15701
15649
  tx: {
15702
15650
  input: tx.inputs[details.request_index]
@@ -15705,7 +15653,7 @@ const requestPrevTxInfo$1 = ({
15705
15653
  }
15706
15654
 
15707
15655
  if (request_type === 'TXORIGOUTPUT') {
15708
- if (!tx.outputs) throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
15656
+ if (!tx.outputs) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
15709
15657
  return typedCall('TxAckOutput', 'TxRequest', {
15710
15658
  tx: {
15711
15659
  output: tx.outputs[details.request_index]
@@ -15715,15 +15663,15 @@ const requestPrevTxInfo$1 = ({
15715
15663
 
15716
15664
  if (request_type === 'TXEXTRADATA') {
15717
15665
  if (typeof details.extra_data_len !== 'number') {
15718
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15666
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15719
15667
  }
15720
15668
 
15721
15669
  if (typeof details.extra_data_offset !== 'number') {
15722
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15670
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15723
15671
  }
15724
15672
 
15725
15673
  if (typeof tx.extra_data !== 'string') {
15726
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15674
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15727
15675
  }
15728
15676
 
15729
15677
  const data = tx.extra_data;
@@ -15755,7 +15703,7 @@ const requestPrevTxInfo$1 = ({
15755
15703
  });
15756
15704
  }
15757
15705
 
15758
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15706
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15759
15707
  };
15760
15708
 
15761
15709
  const requestSignedTxInfo$1 = ({
@@ -15784,14 +15732,14 @@ const requestSignedTxInfo$1 = ({
15784
15732
  }
15785
15733
 
15786
15734
  if (request_type === 'TXMETA') {
15787
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15735
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15788
15736
  }
15789
15737
 
15790
15738
  if (request_type === 'TXEXTRADATA') {
15791
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15739
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15792
15740
  }
15793
15741
 
15794
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15742
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15795
15743
  };
15796
15744
 
15797
15745
  const requestTxAck$1 = props => {
@@ -15820,7 +15768,7 @@ const saveTxSignatures$1 = (serializedTx, signatures, txRequest) => {
15820
15768
 
15821
15769
  if (typeof signature_index === 'number') {
15822
15770
  if (!signature) {
15823
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15771
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15824
15772
  }
15825
15773
 
15826
15774
  signatures[signature_index] = signature;
@@ -15895,17 +15843,17 @@ const requestPrevTxInfo = ({
15895
15843
  } = details;
15896
15844
 
15897
15845
  if (!tx_hash) {
15898
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15846
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15899
15847
  }
15900
15848
 
15901
15849
  const tx = refTxs[tx_hash.toLowerCase()];
15902
15850
 
15903
15851
  if (!tx) {
15904
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15852
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15905
15853
  }
15906
15854
 
15907
15855
  if (!tx.bin_outputs) {
15908
- throw TypedError('Runtime', `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
15856
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
15909
15857
  }
15910
15858
 
15911
15859
  if (request_type === 'TXINPUT') {
@@ -15922,15 +15870,15 @@ const requestPrevTxInfo = ({
15922
15870
 
15923
15871
  if (request_type === 'TXEXTRADATA') {
15924
15872
  if (typeof details.extra_data_len !== 'number') {
15925
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15873
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15926
15874
  }
15927
15875
 
15928
15876
  if (typeof details.extra_data_offset !== 'number') {
15929
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15877
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15930
15878
  }
15931
15879
 
15932
15880
  if (typeof tx.extra_data !== 'string') {
15933
- throw TypedError('Runtime', `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15881
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
15934
15882
  }
15935
15883
 
15936
15884
  const data = tx.extra_data;
@@ -15964,7 +15912,7 @@ const requestPrevTxInfo = ({
15964
15912
  return meta;
15965
15913
  }
15966
15914
 
15967
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15915
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15968
15916
  };
15969
15917
 
15970
15918
  const requestSignedTxInfo = ({
@@ -15988,14 +15936,14 @@ const requestSignedTxInfo = ({
15988
15936
  }
15989
15937
 
15990
15938
  if (request_type === 'TXMETA') {
15991
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15939
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
15992
15940
  }
15993
15941
 
15994
15942
  if (request_type === 'TXEXTRADATA') {
15995
- throw TypedError('Runtime', 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15943
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
15996
15944
  }
15997
15945
 
15998
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15946
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15999
15947
  };
16000
15948
 
16001
15949
  const requestTxAck = props => {
@@ -16024,7 +15972,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
16024
15972
 
16025
15973
  if (typeof signature_index === 'number') {
16026
15974
  if (!signature) {
16027
- throw TypedError('Runtime', 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
15975
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
16028
15976
  }
16029
15977
 
16030
15978
  signatures[signature_index] = signature;
@@ -16212,12 +16160,12 @@ class BTCSignTransaction extends BaseMethod {
16212
16160
  }]);
16213
16161
 
16214
16162
  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');
16163
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
16216
16164
  }
16217
16165
 
16218
16166
  if (output.address_n) {
16219
16167
  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}`);
16168
+ if (output.script_type !== scriptType) throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
16221
16169
  }
16222
16170
  });
16223
16171
  const {
@@ -16846,7 +16794,7 @@ class EVMSignTransaction extends BaseMethod {
16846
16794
  const s = request.signature_s;
16847
16795
 
16848
16796
  if (v == null || r == null || s == null) {
16849
- throw TypedError('Runtime', 'processTxRequest: Unexpected request');
16797
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
16850
16798
  }
16851
16799
 
16852
16800
  if (chain_id && v <= 1) {
@@ -17080,7 +17028,7 @@ class EVMSignTypedData extends BaseMethod {
17080
17028
  if (messageHash) {
17081
17029
  this.params.messageHash = formatAnyHex(messageHash);
17082
17030
  } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
17083
- throw TypedError('Method_InvalidParameter', 'message_hash should only be empty when data.primaryType=EIP712Domain');
17031
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'message_hash should only be empty when data.primaryType=EIP712Domain');
17084
17032
  }
17085
17033
  }
17086
17034
  }
@@ -17111,7 +17059,7 @@ class EVMSignTypedData extends BaseMethod {
17111
17059
  run() {
17112
17060
  return __awaiter(this, void 0, void 0, function* () {
17113
17061
  if (!this.device.features) {
17114
- throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17062
+ throw hdShared.ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17115
17063
  }
17116
17064
 
17117
17065
  const {
@@ -17152,7 +17100,7 @@ class EVMSignTypedData extends BaseMethod {
17152
17100
  return Promise.resolve(response.message);
17153
17101
  }
17154
17102
 
17155
- return Promise.resolve(TypedError('Runtime', 'Not implemented'));
17103
+ return Promise.resolve(hdShared.ERRORS.TypedError('Runtime', 'Not implemented'));
17156
17104
  });
17157
17105
  }
17158
17106
 
@@ -17662,7 +17610,7 @@ class NEMSignTransaction extends BaseMethod {
17662
17610
  break;
17663
17611
 
17664
17612
  default:
17665
- throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
17613
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
17666
17614
  }
17667
17615
 
17668
17616
  return message;
@@ -18140,15 +18088,22 @@ const getBinary = ({
18140
18088
  });
18141
18089
 
18142
18090
  if (!releaseInfo) {
18143
- throw TypedError('Runtime', 'no firmware found for this device');
18091
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
18144
18092
  }
18145
18093
 
18146
18094
  if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
18147
- throw TypedError('Runtime', 'firmware version mismatch');
18095
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
18148
18096
  }
18149
18097
 
18150
18098
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
18151
- const fw = yield httpRequest(url, 'binary');
18099
+ let fw;
18100
+
18101
+ try {
18102
+ fw = yield httpRequest(url, 'binary');
18103
+ } catch (_a) {
18104
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
18105
+ }
18106
+
18152
18107
  return Object.assign(Object.assign({}, releaseInfo), {
18153
18108
  binary: fw
18154
18109
  });
@@ -18200,6 +18155,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18200
18155
  } = yield typedCall('FirmwareUpload', 'Success', {
18201
18156
  payload
18202
18157
  });
18158
+ postProgressMessage(device, 100, postMessage);
18203
18159
  return message;
18204
18160
  }
18205
18161
 
@@ -18228,7 +18184,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18228
18184
  return response.message;
18229
18185
  }
18230
18186
 
18231
- throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
18187
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
18232
18188
  });
18233
18189
 
18234
18190
  class FirmwareUpdate extends BaseMethod {
@@ -18247,7 +18203,7 @@ class FirmwareUpdate extends BaseMethod {
18247
18203
  }]);
18248
18204
 
18249
18205
  if (!payload.updateType) {
18250
- throw TypedError('Method_InvalidParameter', 'updateType is required');
18206
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
18251
18207
  }
18252
18208
 
18253
18209
  this.params = {
@@ -18280,7 +18236,7 @@ class FirmwareUpdate extends BaseMethod {
18280
18236
  binary = this.params.binary;
18281
18237
  } else {
18282
18238
  if (!device.features) {
18283
- throw TypedError('Runtime', 'no features found for this device');
18239
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
18284
18240
  }
18285
18241
 
18286
18242
  const firmware = yield getBinary({
@@ -18291,7 +18247,7 @@ class FirmwareUpdate extends BaseMethod {
18291
18247
  binary = firmware.binary;
18292
18248
  }
18293
18249
  } catch (err) {
18294
- throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
18250
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
18295
18251
  }
18296
18252
 
18297
18253
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
@@ -18351,7 +18307,7 @@ function findMethod(message) {
18351
18307
  } = message.payload;
18352
18308
 
18353
18309
  if (typeof method !== 'string') {
18354
- throw TypedError('Method_InvalidParameter', 'Method is not set');
18310
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
18355
18311
  }
18356
18312
 
18357
18313
  const MethodConstructor = ApiMethods[method];
@@ -18360,9 +18316,17 @@ function findMethod(message) {
18360
18316
  return new MethodConstructor(message);
18361
18317
  }
18362
18318
 
18363
- throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
18319
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
18364
18320
  }
18365
18321
 
18322
+ const safeThrowError = error => {
18323
+ if (error instanceof hdShared.HardwareError) {
18324
+ throw error;
18325
+ } else {
18326
+ throw hdShared.ERRORS.TypedError(error);
18327
+ }
18328
+ };
18329
+
18366
18330
  const resolveAfter = (msec, value) => new Promise(resolve => {
18367
18331
  setTimeout(resolve, msec, value);
18368
18332
  });
@@ -18437,7 +18401,7 @@ class DeviceConnector {
18437
18401
  Log$1.debug('diff result: ', diff);
18438
18402
  return diff;
18439
18403
  } catch (error) {
18440
- throw new Error(error);
18404
+ safeThrowError(error);
18441
18405
  }
18442
18406
  });
18443
18407
  }
@@ -18499,7 +18463,7 @@ class DeviceConnector {
18499
18463
 
18500
18464
  return res;
18501
18465
  } catch (error) {
18502
- throw new Error(error);
18466
+ safeThrowError(error);
18503
18467
  }
18504
18468
  });
18505
18469
  }
@@ -18510,7 +18474,7 @@ class DeviceConnector {
18510
18474
  const res = yield this.transport.release(session, onclose);
18511
18475
  return res;
18512
18476
  } catch (error) {
18513
- throw new Error(error);
18477
+ safeThrowError(error);
18514
18478
  }
18515
18479
  });
18516
18480
  }
@@ -18538,10 +18502,10 @@ let _callPromise;
18538
18502
  const deviceCacheMap = new Map();
18539
18503
 
18540
18504
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18541
- var _a, _b;
18505
+ var _a;
18542
18506
 
18543
18507
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
18544
- return Promise.reject(TypedError('Method_InvalidParameter', 'onCall: message.id or message.payload is missing'));
18508
+ return Promise.reject(hdShared.ERRORS.TypedError('on call: message.id or message.payload is missing'));
18545
18509
  }
18546
18510
 
18547
18511
  let method;
@@ -18562,8 +18526,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18562
18526
  return createResponseMessage(method.responseID, true, response);
18563
18527
  } catch (error) {
18564
18528
  return createResponseMessage(method.responseID, false, {
18565
- code: error.code,
18566
- error: (_a = error.message) !== null && _a !== void 0 ? _a : error
18529
+ error
18567
18530
  });
18568
18531
  }
18569
18532
  }
@@ -18588,7 +18551,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18588
18551
  }
18589
18552
 
18590
18553
  Log.debug('Call API - setDevice: ', device);
18591
- (_b = method.setDevice) === null || _b === void 0 ? void 0 : _b.call(method, device);
18554
+ (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
18592
18555
  device.on(DEVICE.PIN, onDevicePinHandler);
18593
18556
  device.on(DEVICE.BUTTON, (d, code) => {
18594
18557
  onDeviceButtonHandler(d, code);
@@ -18606,18 +18569,18 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18606
18569
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
18607
18570
 
18608
18571
  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}`));
18572
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too low, please update to ${versionRange.min}`));
18610
18573
  }
18611
18574
 
18612
18575
  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}`));
18576
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceFwException, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`));
18614
18577
  }
18615
18578
  }
18616
18579
 
18617
18580
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
18618
18581
 
18619
18582
  if (unexpectedMode) {
18620
- return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
18583
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
18621
18584
  }
18622
18585
 
18623
18586
  if (_deviceList) {
@@ -18631,7 +18594,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18631
18594
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18632
18595
  } catch (error) {
18633
18596
  Log.debug('Call API - Inner Method Run Error: ', error);
18634
- messageResponse = createResponseMessage(method.responseID, false, error.message);
18597
+ messageResponse = createResponseMessage(method.responseID, false, {
18598
+ error
18599
+ });
18635
18600
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18636
18601
  }
18637
18602
  });
@@ -18640,17 +18605,21 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18640
18605
 
18641
18606
  const deviceRun = () => device.run(inner);
18642
18607
 
18643
- _callPromise = create(deviceRun);
18608
+ _callPromise = hdShared.createDeferred(deviceRun);
18644
18609
 
18645
18610
  try {
18646
18611
  return yield _callPromise.promise;
18647
18612
  } catch (e) {
18648
18613
  console.log('Device Run Error: ', e);
18649
- return createResponseMessage(method.responseID, false, e.message);
18614
+ return createResponseMessage(method.responseID, false, {
18615
+ error: e
18616
+ });
18650
18617
  }
18651
18618
  } catch (error) {
18652
- messageResponse = createResponseMessage(method.responseID, false, error);
18653
- _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(TypedError('Call_API', error));
18619
+ messageResponse = createResponseMessage(method.responseID, false, {
18620
+ error
18621
+ });
18622
+ _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
18654
18623
  Log.debug('Call API - Run Error: ', error);
18655
18624
  } finally {
18656
18625
  const response = messageResponse;
@@ -18687,7 +18656,7 @@ function initDeviceList(method) {
18687
18656
 
18688
18657
  function initDevice(method) {
18689
18658
  if (!_deviceList) {
18690
- throw TypedError('Call_API', 'DeviceList is not initialized');
18659
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18691
18660
  }
18692
18661
 
18693
18662
  let device;
@@ -18699,11 +18668,11 @@ function initDevice(method) {
18699
18668
  } else if (allDevices.length === 1) {
18700
18669
  [device] = allDevices;
18701
18670
  } else if (allDevices.length > 1) {
18702
- throw TypedError('Call_API', '请选择连接设备');
18671
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
18703
18672
  }
18704
18673
 
18705
18674
  if (!device) {
18706
- throw TypedError('Call_API', 'Device Not Found');
18675
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
18707
18676
  }
18708
18677
 
18709
18678
  device.deviceConnector = _connector;
@@ -18712,7 +18681,7 @@ function initDevice(method) {
18712
18681
 
18713
18682
  function initDeviceForBle(method) {
18714
18683
  if (!method.connectId && !_deviceList) {
18715
- throw TypedError('Call_API', 'DeviceList is not initialized');
18684
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18716
18685
  }
18717
18686
 
18718
18687
  if (!method.connectId) {
@@ -18799,7 +18768,7 @@ const postMessage = message => {
18799
18768
  };
18800
18769
 
18801
18770
  const createUiPromise = (promiseEvent, device) => {
18802
- const uiPromise = create(promiseEvent, device);
18771
+ const uiPromise = hdShared.createDeferred(promiseEvent, device);
18803
18772
 
18804
18773
  _uiPromises.push(uiPromise);
18805
18774
 
@@ -18875,7 +18844,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
18875
18844
  try {
18876
18845
  yield DataManager.load(settings);
18877
18846
  initTransport(Transport);
18878
- } catch (_c) {
18847
+ } catch (_b) {
18879
18848
  Log.error('DataManager.load error');
18880
18849
  }
18881
18850
 
@@ -18916,14 +18885,12 @@ __webpack_unused_export__ = DEFAULT_PRIORITY;
18916
18885
  __webpack_unused_export__ = DEVICE;
18917
18886
  __webpack_unused_export__ = DEVICE_EVENT;
18918
18887
  __webpack_unused_export__ = DataManager;
18919
- exports.Sg = errors;
18920
18888
  exports.Bg = IFRAME;
18921
18889
  __webpack_unused_export__ = RESPONSE_EVENT;
18922
18890
  exports.rF = UI_EVENT;
18923
18891
  __webpack_unused_export__ = UI_REQUEST$1;
18924
18892
  __webpack_unused_export__ = UI_RESPONSE;
18925
18893
  __webpack_unused_export__ = corsValidator;
18926
- exports.Ue = create;
18927
18894
  __webpack_unused_export__ = createDeviceMessage;
18928
18895
  exports.xG = createErrorMessage;
18929
18896
  __webpack_unused_export__ = createIFrameMessage;
@@ -18949,6 +18916,7 @@ __webpack_unused_export__ = isValidVersionString;
18949
18916
  __webpack_unused_export__ = normalizeVersionArray;
18950
18917
  exports._4 = parseConnectSettings;
18951
18918
  exports.kW = parseMessage;
18919
+ __webpack_unused_export__ = safeThrowError;
18952
18920
  __webpack_unused_export__ = versionCompare;
18953
18921
  __webpack_unused_export__ = versionSplit;
18954
18922
 
@@ -19973,6 +19941,249 @@ exports["default"] = index;
19973
19941
 
19974
19942
  /***/ }),
19975
19943
 
19944
+ /***/ 8402:
19945
+ /***/ ((__unused_webpack_module, exports) => {
19946
+
19947
+ "use strict";
19948
+
19949
+
19950
+ Object.defineProperty(exports, "__esModule", ({
19951
+ value: true
19952
+ }));
19953
+ /******************************************************************************
19954
+ Copyright (c) Microsoft Corporation.
19955
+
19956
+ Permission to use, copy, modify, and/or distribute this software for any
19957
+ purpose with or without fee is hereby granted.
19958
+
19959
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19960
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19961
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19962
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19963
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19964
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19965
+ PERFORMANCE OF THIS SOFTWARE.
19966
+ ***************************************************************************** */
19967
+
19968
+ function __awaiter(thisArg, _arguments, P, generator) {
19969
+ function adopt(value) {
19970
+ return value instanceof P ? value : new P(function (resolve) {
19971
+ resolve(value);
19972
+ });
19973
+ }
19974
+
19975
+ return new (P || (P = Promise))(function (resolve, reject) {
19976
+ function fulfilled(value) {
19977
+ try {
19978
+ step(generator.next(value));
19979
+ } catch (e) {
19980
+ reject(e);
19981
+ }
19982
+ }
19983
+
19984
+ function rejected(value) {
19985
+ try {
19986
+ step(generator["throw"](value));
19987
+ } catch (e) {
19988
+ reject(e);
19989
+ }
19990
+ }
19991
+
19992
+ function step(result) {
19993
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
19994
+ }
19995
+
19996
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19997
+ });
19998
+ }
19999
+
20000
+ function createDeferred(arg, data) {
20001
+ let localResolve = _t => {};
20002
+
20003
+ let localReject = _e => {};
20004
+
20005
+ let id;
20006
+ const promise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
20007
+ localResolve = resolve;
20008
+ localReject = reject;
20009
+
20010
+ if (typeof arg === 'function') {
20011
+ try {
20012
+ yield arg();
20013
+ } catch (error) {
20014
+ reject(error);
20015
+ }
20016
+ }
20017
+
20018
+ if (typeof arg === 'string') id = arg;
20019
+ }));
20020
+ return {
20021
+ id,
20022
+ data,
20023
+ resolve: localResolve,
20024
+ reject: localReject,
20025
+ promise
20026
+ };
20027
+ }
20028
+
20029
+ function fillStringWithArguments(value, object) {
20030
+ return value.replace(/\{([^}]+)\}/g, (_, arg) => object[arg] || '?');
20031
+ }
20032
+
20033
+ class HardwareError extends Error {
20034
+ constructor(hardwareError) {
20035
+ var _a;
20036
+
20037
+ super();
20038
+ this.errorCode = HardwareErrorCode.UnknownError;
20039
+ this.message = '';
20040
+ const errorMessageMapping = HardwareErrorCodeMessage;
20041
+ this.message = errorMessageMapping[HardwareErrorCode.UnknownError];
20042
+
20043
+ if (typeof hardwareError === 'string') {
20044
+ this.errorCode = HardwareErrorCode.UnknownError;
20045
+ this.message = hardwareError;
20046
+ } else {
20047
+ const message = (_a = hardwareError.message || errorMessageMapping[hardwareError.errorCode]) !== null && _a !== void 0 ? _a : '';
20048
+
20049
+ if (message) {
20050
+ this.message = fillStringWithArguments(message, hardwareError);
20051
+ }
20052
+
20053
+ this.errorCode = hardwareError.errorCode;
20054
+ }
20055
+
20056
+ this.name = 'HardwareError';
20057
+ }
20058
+
20059
+ }
20060
+
20061
+ const HardwareErrorCode = {
20062
+ UnknownError: 0,
20063
+ DeviceFwException: 101,
20064
+ DeviceUnexpectedMode: 102,
20065
+ DeviceListNotInitialized: 103,
20066
+ SelectDevice: 104,
20067
+ DeviceNotFound: 105,
20068
+ DeviceInitializeFailed: 106,
20069
+ DeviceInterruptedFromOutside: 107,
20070
+ NotInitialized: 200,
20071
+ IFrameNotInitialized: 300,
20072
+ IFrameAleradyInitialized: 301,
20073
+ IFrameLoadFail: 302,
20074
+ IframeTimeout: 303,
20075
+ IframeBlocked: 304,
20076
+ CallMethodError: 400,
20077
+ CallMethodNotResponse: 404,
20078
+ CallMethodInvalidParameter: 405,
20079
+ FirmwareUpdateDownloadFailed: 406,
20080
+ NetworkError: 500,
20081
+ TransportNotConfigured: 600,
20082
+ TransportCallInProgress: 601,
20083
+ TransportNotFound: 602,
20084
+ TransportInvalidProtobuf: 603,
20085
+ BleScanError: 700,
20086
+ BlePermissionError: 701,
20087
+ BleLocationError: 702,
20088
+ BleRequiredUUID: 703,
20089
+ BleConnectedError: 704,
20090
+ BleDeviceNotBonded: 705,
20091
+ BleServiceNotFound: 706,
20092
+ BleCharacteristicNotFound: 707,
20093
+ BleMonitorError: 708,
20094
+ RuntimeError: 800,
20095
+ PinInvalid: 801,
20096
+ PinCancelled: 802,
20097
+ ActionCancelled: 803,
20098
+ FirmwareError: 804
20099
+ };
20100
+ const HardwareErrorCodeMessage = {
20101
+ [HardwareErrorCode.UnknownError]: 'Unknown error occurred. Check message property.',
20102
+ [HardwareErrorCode.DeviceFwException]: 'Firmware version mismatch',
20103
+ [HardwareErrorCode.DeviceUnexpectedMode]: 'Device unexpected mode',
20104
+ [HardwareErrorCode.DeviceListNotInitialized]: 'Device list is not initialized',
20105
+ [HardwareErrorCode.SelectDevice]: 'Please select the connected device',
20106
+ [HardwareErrorCode.DeviceNotFound]: 'Device not found',
20107
+ [HardwareErrorCode.DeviceInitializeFailed]: 'Device initialization failed',
20108
+ [HardwareErrorCode.DeviceInterruptedFromOutside]: 'Device interrupted',
20109
+ [HardwareErrorCode.NotInitialized]: 'Not initialized',
20110
+ [HardwareErrorCode.IFrameNotInitialized]: 'IFrame not initialized',
20111
+ [HardwareErrorCode.IFrameAleradyInitialized]: 'IFrame alerady initialized',
20112
+ [HardwareErrorCode.IFrameLoadFail]: 'IFrame load fail',
20113
+ [HardwareErrorCode.IframeTimeout]: 'init iframe time out',
20114
+ [HardwareErrorCode.IframeBlocked]: 'IFrame blocked',
20115
+ [HardwareErrorCode.CallMethodError]: 'Runtime errors during method execution',
20116
+ [HardwareErrorCode.CallMethodNotResponse]: 'Method does not responding',
20117
+ [HardwareErrorCode.CallMethodInvalidParameter]: 'Call method invalid parameter',
20118
+ [HardwareErrorCode.FirmwareUpdateDownloadFailed]: 'Firmware update download failed',
20119
+ [HardwareErrorCode.NetworkError]: 'Network request error',
20120
+ [HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
20121
+ [HardwareErrorCode.TransportCallInProgress]: 'Transport call in progress',
20122
+ [HardwareErrorCode.TransportNotFound]: 'Transport not found',
20123
+ [HardwareErrorCode.TransportInvalidProtobuf]: 'Transport invalid protobuf',
20124
+ [HardwareErrorCode.BleScanError]: 'BLE scan error',
20125
+ [HardwareErrorCode.BlePermissionError]: 'Bluetooth required to be turned on',
20126
+ [HardwareErrorCode.BleLocationError]: 'Device is not authorized to use BluetoothLE',
20127
+ [HardwareErrorCode.BleRequiredUUID]: 'uuid is required',
20128
+ [HardwareErrorCode.BleConnectedError]: 'connected error is always runtime error',
20129
+ [HardwareErrorCode.BleDeviceNotBonded]: 'device is not bonded',
20130
+ [HardwareErrorCode.BleServiceNotFound]: 'BLEServiceNotFound: service not found',
20131
+ [HardwareErrorCode.BleCharacteristicNotFound]: 'BLEServiceNotFound: service not found',
20132
+ [HardwareErrorCode.BleMonitorError]: 'Monitor Error: characteristic not found',
20133
+ [HardwareErrorCode.RuntimeError]: 'Runtime error',
20134
+ [HardwareErrorCode.PinInvalid]: 'Pin invalid',
20135
+ [HardwareErrorCode.PinCancelled]: 'Pin cancelled',
20136
+ [HardwareErrorCode.ActionCancelled]: 'Action cancelled by user',
20137
+ [HardwareErrorCode.FirmwareError]: 'Firmware installation failed'
20138
+ };
20139
+
20140
+ const TypedError = (hardwareError, message) => {
20141
+ if (typeof hardwareError === 'string') {
20142
+ return new HardwareError(hardwareError);
20143
+ }
20144
+
20145
+ return new HardwareError({
20146
+ errorCode: hardwareError,
20147
+ message: message !== null && message !== void 0 ? message : ''
20148
+ });
20149
+ };
20150
+
20151
+ const serializeError = payload => {
20152
+ if (payload && payload.error instanceof HardwareError) {
20153
+ return {
20154
+ error: payload.error.message,
20155
+ code: payload.error.errorCode
20156
+ };
20157
+ }
20158
+
20159
+ if (payload && payload.error instanceof Error) {
20160
+ return {
20161
+ error: payload.error.message,
20162
+ code: payload.error.code
20163
+ };
20164
+ }
20165
+
20166
+ return payload;
20167
+ };
20168
+
20169
+ var HardwareError$1 = /*#__PURE__*/Object.freeze({
20170
+ __proto__: null,
20171
+ HardwareError: HardwareError,
20172
+ HardwareErrorCode: HardwareErrorCode,
20173
+ HardwareErrorCodeMessage: HardwareErrorCodeMessage,
20174
+ TypedError: TypedError,
20175
+ serializeError: serializeError
20176
+ });
20177
+ exports.ERRORS = HardwareError$1;
20178
+ exports.HardwareError = HardwareError;
20179
+ exports.HardwareErrorCode = HardwareErrorCode;
20180
+ exports.HardwareErrorCodeMessage = HardwareErrorCodeMessage;
20181
+ exports.TypedError = TypedError;
20182
+ exports.createDeferred = createDeferred;
20183
+ exports.serializeError = serializeError;
20184
+
20185
+ /***/ }),
20186
+
19976
20187
  /***/ 5766:
19977
20188
  /***/ ((__unused_webpack_module, exports) => {
19978
20189
 
@@ -42190,6 +42401,8 @@ var events = __webpack_require__(2699);
42190
42401
  var events_default = /*#__PURE__*/__webpack_require__.n(events);
42191
42402
  // EXTERNAL MODULE: ../core/dist/index.js
42192
42403
  var dist = __webpack_require__(5890);
42404
+ // EXTERNAL MODULE: ../shared/dist/index.js
42405
+ var shared_dist = __webpack_require__(8402);
42193
42406
  ;// CONCATENATED MODULE: ./src/utils/urlUtils.ts
42194
42407
  const getOrigin = url => {
42195
42408
  if (typeof url !== 'string') return 'unknown';
@@ -42205,12 +42418,12 @@ const getOrigin = url => {
42205
42418
 
42206
42419
  let instance;
42207
42420
  let origin;
42208
- let initPromise = (0,dist/* create */.Ue)();
42421
+ let initPromise = (0,shared_dist.createDeferred)();
42209
42422
  let timeout = 0;
42210
42423
  /* eslint-disable import/no-mutable-exports */
42211
42424
 
42212
42425
  const init = async settings => {
42213
- initPromise = (0,dist/* create */.Ue)();
42426
+ initPromise = (0,shared_dist.createDeferred)();
42214
42427
  const existedFrame = document.getElementById('onekey-connect');
42215
42428
 
42216
42429
  if (existedFrame) {
@@ -42233,14 +42446,14 @@ const init = async settings => {
42233
42446
  instance.setAttribute('src', src);
42234
42447
  origin = getOrigin(instance.src);
42235
42448
  timeout = window.setTimeout(() => {
42236
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeTimeout'));
42449
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeTimeout));
42237
42450
  }, 10000);
42238
42451
 
42239
42452
  const onLoad = () => {
42240
42453
  var _instance$contentWind;
42241
42454
 
42242
42455
  if (!instance) {
42243
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeBlocked'));
42456
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeBlocked));
42244
42457
  return;
42245
42458
  }
42246
42459
 
@@ -44479,6 +44692,7 @@ const sendMessage = async (messages, isHost = true) => {
44479
44692
 
44480
44693
 
44481
44694
 
44695
+
44482
44696
  const eventEmitter = new (events_default())();
44483
44697
  const src_Log = (0,dist/* initLog */.KR)('@onekey/connect');
44484
44698
 
@@ -44514,7 +44728,7 @@ const src_dispose = () => {
44514
44728
 
44515
44729
  const uiResponse = response => {
44516
44730
  if (!instance) {
44517
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_NotInitialized');
44731
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameNotInitialized);
44518
44732
  }
44519
44733
 
44520
44734
  const {
@@ -44566,7 +44780,7 @@ const createJSBridge = messageEvent => {
44566
44780
 
44567
44781
  const src_init = async settings => {
44568
44782
  if (instance) {
44569
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_AlreadyInitialized');
44783
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameAleradyInitialized);
44570
44784
  }
44571
44785
 
44572
44786
  _settings = (0,dist/* parseConnectSettings */._4)({ ..._settings,
@@ -44600,7 +44814,7 @@ const call = async params => {
44600
44814
  }
44601
44815
 
44602
44816
  if (timeout) {
44603
- return (0,dist/* createErrorMessage */.xG)(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeLoadFail'));
44817
+ return (0,dist/* createErrorMessage */.xG)(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameLoadFail));
44604
44818
  }
44605
44819
 
44606
44820
  try {
@@ -44614,7 +44828,7 @@ const call = async params => {
44614
44828
  return response;
44615
44829
  }
44616
44830
 
44617
- return (0,dist/* createErrorMessage */.xG)(dist/* ERRORS.TypedError */.Sg.TypedError('Call_NotResponse'));
44831
+ return (0,dist/* createErrorMessage */.xG)(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.CallMethodNotResponse));
44618
44832
  } catch (error) {
44619
44833
  src_Log.error('__call error: ', error);
44620
44834
  return (0,dist/* createErrorMessage */.xG)(error);