@onekeyfe/hd-web-sdk 0.1.3 → 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
  }
@@ -14726,7 +14674,7 @@ class Device extends events.exports {
14726
14674
  this.featuresNeedsReload = false;
14727
14675
  }
14728
14676
 
14729
- updateDescriptor(descriptor) {
14677
+ updateDescriptor(descriptor, forceUpdate = false) {
14730
14678
  const env = DataManager.getSettings('env');
14731
14679
 
14732
14680
  if (env === 'react-native') {
@@ -14739,12 +14687,16 @@ class Device extends events.exports {
14739
14687
  if (originalSession !== upcomingSession) {
14740
14688
  this.originalDescriptor.session = upcomingSession;
14741
14689
  }
14690
+
14691
+ if (forceUpdate) {
14692
+ this.originalDescriptor = descriptor;
14693
+ }
14742
14694
  }
14743
14695
 
14744
14696
  updateFromCache(device) {
14745
14697
  this.mainId = device.mainId;
14746
14698
  this.commands = device.commands;
14747
- this.updateDescriptor(device.originalDescriptor);
14699
+ this.updateDescriptor(device.originalDescriptor, true);
14748
14700
 
14749
14701
  if (device.features) {
14750
14702
  this._updateFeatures(device.features);
@@ -14759,7 +14711,7 @@ class Device extends events.exports {
14759
14711
  }
14760
14712
 
14761
14713
  options = parseRunOptions(options);
14762
- this.runPromise = create(this._runInner.bind(this, fn, options));
14714
+ this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
14763
14715
  return this.runPromise.promise;
14764
14716
  });
14765
14717
  }
@@ -14775,7 +14727,7 @@ class Device extends events.exports {
14775
14727
  }
14776
14728
  } catch (error) {
14777
14729
  this.runPromise = null;
14778
- 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}`));
14779
14731
  }
14780
14732
  }
14781
14733
 
@@ -14807,7 +14759,7 @@ class Device extends events.exports {
14807
14759
  }
14808
14760
 
14809
14761
  if (this.runPromise) {
14810
- this.runPromise.reject(TypedError('Device_Interrupted'));
14762
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
14811
14763
  }
14812
14764
  }
14813
14765
 
@@ -15104,7 +15056,7 @@ const formatAnyHex = value => {
15104
15056
  return value;
15105
15057
  };
15106
15058
 
15107
- const invalidParameter = message => TypedError('Method_InvalidParameter', message);
15059
+ const invalidParameter = message => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
15108
15060
 
15109
15061
  const validateParams = (values, fields) => {
15110
15062
  fields.forEach(field => {
@@ -15417,11 +15369,11 @@ const getCoinInfo = (path, coin) => {
15417
15369
 
15418
15370
  if (!coinInfo) {
15419
15371
  if (coin) {
15420
- throw TypedError('Method_InvalidParameter', `Invalid coin name: ${coin}`);
15372
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
15421
15373
  } else if (path) {
15422
- throw TypedError('Method_InvalidParameter', `Invalid path: ${path[0]}`);
15374
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
15423
15375
  } else {
15424
- throw TypedError('Method_InvalidParameter');
15376
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
15425
15377
  }
15426
15378
  }
15427
15379
 
@@ -15664,17 +15616,17 @@ const requestPrevTxInfo$1 = ({
15664
15616
  } = details;
15665
15617
 
15666
15618
  if (!tx_hash) {
15667
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15619
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15668
15620
  }
15669
15621
 
15670
15622
  const tx = refTxs[tx_hash.toLowerCase()];
15671
15623
 
15672
15624
  if (!tx) {
15673
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15625
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15674
15626
  }
15675
15627
 
15676
15628
  if (request_type === 'TXINPUT') {
15677
- 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}`);
15678
15630
  return typedCall('TxAckPrevInput', 'TxRequest', {
15679
15631
  tx: {
15680
15632
  input: tx.inputs[details.request_index]
@@ -15683,7 +15635,7 @@ const requestPrevTxInfo$1 = ({
15683
15635
  }
15684
15636
 
15685
15637
  if (request_type === 'TXOUTPUT') {
15686
- 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}`);
15687
15639
  return typedCall('TxAckPrevOutput', 'TxRequest', {
15688
15640
  tx: {
15689
15641
  output: tx.bin_outputs[details.request_index]
@@ -15692,7 +15644,7 @@ const requestPrevTxInfo$1 = ({
15692
15644
  }
15693
15645
 
15694
15646
  if (request_type === 'TXORIGINPUT') {
15695
- 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}`);
15696
15648
  return typedCall('TxAckInput', 'TxRequest', {
15697
15649
  tx: {
15698
15650
  input: tx.inputs[details.request_index]
@@ -15701,7 +15653,7 @@ const requestPrevTxInfo$1 = ({
15701
15653
  }
15702
15654
 
15703
15655
  if (request_type === 'TXORIGOUTPUT') {
15704
- 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}`);
15705
15657
  return typedCall('TxAckOutput', 'TxRequest', {
15706
15658
  tx: {
15707
15659
  output: tx.outputs[details.request_index]
@@ -15711,15 +15663,15 @@ const requestPrevTxInfo$1 = ({
15711
15663
 
15712
15664
  if (request_type === 'TXEXTRADATA') {
15713
15665
  if (typeof details.extra_data_len !== 'number') {
15714
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15666
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15715
15667
  }
15716
15668
 
15717
15669
  if (typeof details.extra_data_offset !== 'number') {
15718
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15670
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15719
15671
  }
15720
15672
 
15721
15673
  if (typeof tx.extra_data !== 'string') {
15722
- 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}`);
15723
15675
  }
15724
15676
 
15725
15677
  const data = tx.extra_data;
@@ -15751,7 +15703,7 @@ const requestPrevTxInfo$1 = ({
15751
15703
  });
15752
15704
  }
15753
15705
 
15754
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15706
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15755
15707
  };
15756
15708
 
15757
15709
  const requestSignedTxInfo$1 = ({
@@ -15780,14 +15732,14 @@ const requestSignedTxInfo$1 = ({
15780
15732
  }
15781
15733
 
15782
15734
  if (request_type === 'TXMETA') {
15783
- 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');
15784
15736
  }
15785
15737
 
15786
15738
  if (request_type === 'TXEXTRADATA') {
15787
- 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');
15788
15740
  }
15789
15741
 
15790
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15742
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15791
15743
  };
15792
15744
 
15793
15745
  const requestTxAck$1 = props => {
@@ -15816,7 +15768,7 @@ const saveTxSignatures$1 = (serializedTx, signatures, txRequest) => {
15816
15768
 
15817
15769
  if (typeof signature_index === 'number') {
15818
15770
  if (!signature) {
15819
- 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.');
15820
15772
  }
15821
15773
 
15822
15774
  signatures[signature_index] = signature;
@@ -15891,17 +15843,17 @@ const requestPrevTxInfo = ({
15891
15843
  } = details;
15892
15844
 
15893
15845
  if (!tx_hash) {
15894
- throw TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
15846
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
15895
15847
  }
15896
15848
 
15897
15849
  const tx = refTxs[tx_hash.toLowerCase()];
15898
15850
 
15899
15851
  if (!tx) {
15900
- throw TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15852
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
15901
15853
  }
15902
15854
 
15903
15855
  if (!tx.bin_outputs) {
15904
- 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}`);
15905
15857
  }
15906
15858
 
15907
15859
  if (request_type === 'TXINPUT') {
@@ -15918,15 +15870,15 @@ const requestPrevTxInfo = ({
15918
15870
 
15919
15871
  if (request_type === 'TXEXTRADATA') {
15920
15872
  if (typeof details.extra_data_len !== 'number') {
15921
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
15873
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
15922
15874
  }
15923
15875
 
15924
15876
  if (typeof details.extra_data_offset !== 'number') {
15925
- throw TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
15877
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
15926
15878
  }
15927
15879
 
15928
15880
  if (typeof tx.extra_data !== 'string') {
15929
- 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}`);
15930
15882
  }
15931
15883
 
15932
15884
  const data = tx.extra_data;
@@ -15960,7 +15912,7 @@ const requestPrevTxInfo = ({
15960
15912
  return meta;
15961
15913
  }
15962
15914
 
15963
- throw TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
15915
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
15964
15916
  };
15965
15917
 
15966
15918
  const requestSignedTxInfo = ({
@@ -15984,14 +15936,14 @@ const requestSignedTxInfo = ({
15984
15936
  }
15985
15937
 
15986
15938
  if (request_type === 'TXMETA') {
15987
- 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');
15988
15940
  }
15989
15941
 
15990
15942
  if (request_type === 'TXEXTRADATA') {
15991
- 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');
15992
15944
  }
15993
15945
 
15994
- throw TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
15946
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
15995
15947
  };
15996
15948
 
15997
15949
  const requestTxAck = props => {
@@ -16020,7 +15972,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
16020
15972
 
16021
15973
  if (typeof signature_index === 'number') {
16022
15974
  if (!signature) {
16023
- 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.');
16024
15976
  }
16025
15977
 
16026
15978
  signatures[signature_index] = signature;
@@ -16208,12 +16160,12 @@ class BTCSignTransaction extends BaseMethod {
16208
16160
  }]);
16209
16161
 
16210
16162
  if (Object.prototype.hasOwnProperty.call(output, 'address_n') && Object.prototype.hasOwnProperty.call(output, 'address')) {
16211
- 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');
16212
16164
  }
16213
16165
 
16214
16166
  if (output.address_n) {
16215
16167
  const scriptType = getOutputScriptType(output.address_n);
16216
- 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}`);
16217
16169
  }
16218
16170
  });
16219
16171
  const {
@@ -16842,7 +16794,7 @@ class EVMSignTransaction extends BaseMethod {
16842
16794
  const s = request.signature_s;
16843
16795
 
16844
16796
  if (v == null || r == null || s == null) {
16845
- throw TypedError('Runtime', 'processTxRequest: Unexpected request');
16797
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
16846
16798
  }
16847
16799
 
16848
16800
  if (chain_id && v <= 1) {
@@ -17076,7 +17028,7 @@ class EVMSignTypedData extends BaseMethod {
17076
17028
  if (messageHash) {
17077
17029
  this.params.messageHash = formatAnyHex(messageHash);
17078
17030
  } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
17079
- 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');
17080
17032
  }
17081
17033
  }
17082
17034
  }
@@ -17107,7 +17059,7 @@ class EVMSignTypedData extends BaseMethod {
17107
17059
  run() {
17108
17060
  return __awaiter(this, void 0, void 0, function* () {
17109
17061
  if (!this.device.features) {
17110
- throw TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17062
+ throw hdShared.ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
17111
17063
  }
17112
17064
 
17113
17065
  const {
@@ -17148,7 +17100,7 @@ class EVMSignTypedData extends BaseMethod {
17148
17100
  return Promise.resolve(response.message);
17149
17101
  }
17150
17102
 
17151
- return Promise.resolve(TypedError('Runtime', 'Not implemented'));
17103
+ return Promise.resolve(hdShared.ERRORS.TypedError('Runtime', 'Not implemented'));
17152
17104
  });
17153
17105
  }
17154
17106
 
@@ -17658,7 +17610,7 @@ class NEMSignTransaction extends BaseMethod {
17658
17610
  break;
17659
17611
 
17660
17612
  default:
17661
- throw TypedError('Method_InvalidParameter', 'Unknown transaction type');
17613
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
17662
17614
  }
17663
17615
 
17664
17616
  return message;
@@ -18136,15 +18088,22 @@ const getBinary = ({
18136
18088
  });
18137
18089
 
18138
18090
  if (!releaseInfo) {
18139
- throw TypedError('Runtime', 'no firmware found for this device');
18091
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
18140
18092
  }
18141
18093
 
18142
18094
  if (version && !semver__default["default"].eq(releaseInfo.version, version)) {
18143
- throw TypedError('Runtime', 'firmware version mismatch');
18095
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
18144
18096
  }
18145
18097
 
18146
18098
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
18147
- 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
+
18148
18107
  return Object.assign(Object.assign({}, releaseInfo), {
18149
18108
  binary: fw
18150
18109
  });
@@ -18196,6 +18155,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18196
18155
  } = yield typedCall('FirmwareUpload', 'Success', {
18197
18156
  payload
18198
18157
  });
18158
+ postProgressMessage(device, 100, postMessage);
18199
18159
  return message;
18200
18160
  }
18201
18161
 
@@ -18224,7 +18184,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, {
18224
18184
  return response.message;
18225
18185
  }
18226
18186
 
18227
- throw TypedError('Runtime', 'uploadFirmware: unknown major_version');
18187
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
18228
18188
  });
18229
18189
 
18230
18190
  class FirmwareUpdate extends BaseMethod {
@@ -18243,7 +18203,7 @@ class FirmwareUpdate extends BaseMethod {
18243
18203
  }]);
18244
18204
 
18245
18205
  if (!payload.updateType) {
18246
- throw TypedError('Method_InvalidParameter', 'updateType is required');
18206
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
18247
18207
  }
18248
18208
 
18249
18209
  this.params = {
@@ -18276,7 +18236,7 @@ class FirmwareUpdate extends BaseMethod {
18276
18236
  binary = this.params.binary;
18277
18237
  } else {
18278
18238
  if (!device.features) {
18279
- throw TypedError('Runtime', 'no features found for this device');
18239
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
18280
18240
  }
18281
18241
 
18282
18242
  const firmware = yield getBinary({
@@ -18287,7 +18247,7 @@ class FirmwareUpdate extends BaseMethod {
18287
18247
  binary = firmware.binary;
18288
18248
  }
18289
18249
  } catch (err) {
18290
- throw TypedError('Method_FirmwareUpdate_DownloadFailed', err);
18250
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
18291
18251
  }
18292
18252
 
18293
18253
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, {
@@ -18347,7 +18307,7 @@ function findMethod(message) {
18347
18307
  } = message.payload;
18348
18308
 
18349
18309
  if (typeof method !== 'string') {
18350
- throw TypedError('Method_InvalidParameter', 'Method is not set');
18310
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
18351
18311
  }
18352
18312
 
18353
18313
  const MethodConstructor = ApiMethods[method];
@@ -18356,9 +18316,17 @@ function findMethod(message) {
18356
18316
  return new MethodConstructor(message);
18357
18317
  }
18358
18318
 
18359
- throw TypedError('Method_InvalidParameter', `Method ${method} is not set`);
18319
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
18360
18320
  }
18361
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
+
18362
18330
  const resolveAfter = (msec, value) => new Promise(resolve => {
18363
18331
  setTimeout(resolve, msec, value);
18364
18332
  });
@@ -18433,7 +18401,7 @@ class DeviceConnector {
18433
18401
  Log$1.debug('diff result: ', diff);
18434
18402
  return diff;
18435
18403
  } catch (error) {
18436
- throw new Error(error);
18404
+ safeThrowError(error);
18437
18405
  }
18438
18406
  });
18439
18407
  }
@@ -18495,7 +18463,7 @@ class DeviceConnector {
18495
18463
 
18496
18464
  return res;
18497
18465
  } catch (error) {
18498
- throw new Error(error);
18466
+ safeThrowError(error);
18499
18467
  }
18500
18468
  });
18501
18469
  }
@@ -18506,7 +18474,7 @@ class DeviceConnector {
18506
18474
  const res = yield this.transport.release(session, onclose);
18507
18475
  return res;
18508
18476
  } catch (error) {
18509
- throw new Error(error);
18477
+ safeThrowError(error);
18510
18478
  }
18511
18479
  });
18512
18480
  }
@@ -18534,10 +18502,10 @@ let _callPromise;
18534
18502
  const deviceCacheMap = new Map();
18535
18503
 
18536
18504
  const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18537
- var _a, _b;
18505
+ var _a;
18538
18506
 
18539
18507
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
18540
- 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'));
18541
18509
  }
18542
18510
 
18543
18511
  let method;
@@ -18558,8 +18526,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18558
18526
  return createResponseMessage(method.responseID, true, response);
18559
18527
  } catch (error) {
18560
18528
  return createResponseMessage(method.responseID, false, {
18561
- code: error.code,
18562
- error: (_a = error.message) !== null && _a !== void 0 ? _a : error
18529
+ error
18563
18530
  });
18564
18531
  }
18565
18532
  }
@@ -18584,7 +18551,7 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18584
18551
  }
18585
18552
 
18586
18553
  Log.debug('Call API - setDevice: ', device);
18587
- (_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);
18588
18555
  device.on(DEVICE.PIN, onDevicePinHandler);
18589
18556
  device.on(DEVICE.BUTTON, (d, code) => {
18590
18557
  onDeviceButtonHandler(d, code);
@@ -18602,18 +18569,18 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18602
18569
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
18603
18570
 
18604
18571
  if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
18605
- 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}`));
18606
18573
  }
18607
18574
 
18608
18575
  if (versionRange.max && semver__default["default"].valid(versionRange.max) && semver__default["default"].gt(currentVersion, versionRange.max)) {
18609
- 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}`));
18610
18577
  }
18611
18578
  }
18612
18579
 
18613
18580
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
18614
18581
 
18615
18582
  if (unexpectedMode) {
18616
- return Promise.reject(TypedError('Device_UnexpectedMode', unexpectedMode));
18583
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
18617
18584
  }
18618
18585
 
18619
18586
  if (_deviceList) {
@@ -18627,7 +18594,9 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18627
18594
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18628
18595
  } catch (error) {
18629
18596
  Log.debug('Call API - Inner Method Run Error: ', error);
18630
- messageResponse = createResponseMessage(method.responseID, false, error.message);
18597
+ messageResponse = createResponseMessage(method.responseID, false, {
18598
+ error
18599
+ });
18631
18600
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
18632
18601
  }
18633
18602
  });
@@ -18636,17 +18605,21 @@ const callAPI = message => __awaiter(void 0, void 0, void 0, function* () {
18636
18605
 
18637
18606
  const deviceRun = () => device.run(inner);
18638
18607
 
18639
- _callPromise = create(deviceRun);
18608
+ _callPromise = hdShared.createDeferred(deviceRun);
18640
18609
 
18641
18610
  try {
18642
18611
  return yield _callPromise.promise;
18643
18612
  } catch (e) {
18644
18613
  console.log('Device Run Error: ', e);
18645
- return createResponseMessage(method.responseID, false, e.message);
18614
+ return createResponseMessage(method.responseID, false, {
18615
+ error: e
18616
+ });
18646
18617
  }
18647
18618
  } catch (error) {
18648
- messageResponse = createResponseMessage(method.responseID, false, error);
18649
- _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));
18650
18623
  Log.debug('Call API - Run Error: ', error);
18651
18624
  } finally {
18652
18625
  const response = messageResponse;
@@ -18683,7 +18656,7 @@ function initDeviceList(method) {
18683
18656
 
18684
18657
  function initDevice(method) {
18685
18658
  if (!_deviceList) {
18686
- throw TypedError('Call_API', 'DeviceList is not initialized');
18659
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18687
18660
  }
18688
18661
 
18689
18662
  let device;
@@ -18695,11 +18668,11 @@ function initDevice(method) {
18695
18668
  } else if (allDevices.length === 1) {
18696
18669
  [device] = allDevices;
18697
18670
  } else if (allDevices.length > 1) {
18698
- throw TypedError('Call_API', '请选择连接设备');
18671
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
18699
18672
  }
18700
18673
 
18701
18674
  if (!device) {
18702
- throw TypedError('Call_API', 'Device Not Found');
18675
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
18703
18676
  }
18704
18677
 
18705
18678
  device.deviceConnector = _connector;
@@ -18708,7 +18681,7 @@ function initDevice(method) {
18708
18681
 
18709
18682
  function initDeviceForBle(method) {
18710
18683
  if (!method.connectId && !_deviceList) {
18711
- throw TypedError('Call_API', 'DeviceList is not initialized');
18684
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
18712
18685
  }
18713
18686
 
18714
18687
  if (!method.connectId) {
@@ -18795,7 +18768,7 @@ const postMessage = message => {
18795
18768
  };
18796
18769
 
18797
18770
  const createUiPromise = (promiseEvent, device) => {
18798
- const uiPromise = create(promiseEvent, device);
18771
+ const uiPromise = hdShared.createDeferred(promiseEvent, device);
18799
18772
 
18800
18773
  _uiPromises.push(uiPromise);
18801
18774
 
@@ -18871,7 +18844,7 @@ const init = (settings, Transport) => __awaiter(void 0, void 0, void 0, function
18871
18844
  try {
18872
18845
  yield DataManager.load(settings);
18873
18846
  initTransport(Transport);
18874
- } catch (_c) {
18847
+ } catch (_b) {
18875
18848
  Log.error('DataManager.load error');
18876
18849
  }
18877
18850
 
@@ -18912,14 +18885,12 @@ __webpack_unused_export__ = DEFAULT_PRIORITY;
18912
18885
  __webpack_unused_export__ = DEVICE;
18913
18886
  __webpack_unused_export__ = DEVICE_EVENT;
18914
18887
  __webpack_unused_export__ = DataManager;
18915
- exports.Sg = errors;
18916
18888
  exports.Bg = IFRAME;
18917
18889
  __webpack_unused_export__ = RESPONSE_EVENT;
18918
18890
  exports.rF = UI_EVENT;
18919
18891
  __webpack_unused_export__ = UI_REQUEST$1;
18920
18892
  __webpack_unused_export__ = UI_RESPONSE;
18921
18893
  __webpack_unused_export__ = corsValidator;
18922
- exports.Ue = create;
18923
18894
  __webpack_unused_export__ = createDeviceMessage;
18924
18895
  exports.xG = createErrorMessage;
18925
18896
  __webpack_unused_export__ = createIFrameMessage;
@@ -18945,6 +18916,7 @@ __webpack_unused_export__ = isValidVersionString;
18945
18916
  __webpack_unused_export__ = normalizeVersionArray;
18946
18917
  exports._4 = parseConnectSettings;
18947
18918
  exports.kW = parseMessage;
18919
+ __webpack_unused_export__ = safeThrowError;
18948
18920
  __webpack_unused_export__ = versionCompare;
18949
18921
  __webpack_unused_export__ = versionSplit;
18950
18922
 
@@ -19969,6 +19941,249 @@ exports["default"] = index;
19969
19941
 
19970
19942
  /***/ }),
19971
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
+
19972
20187
  /***/ 5766:
19973
20188
  /***/ ((__unused_webpack_module, exports) => {
19974
20189
 
@@ -42186,6 +42401,8 @@ var events = __webpack_require__(2699);
42186
42401
  var events_default = /*#__PURE__*/__webpack_require__.n(events);
42187
42402
  // EXTERNAL MODULE: ../core/dist/index.js
42188
42403
  var dist = __webpack_require__(5890);
42404
+ // EXTERNAL MODULE: ../shared/dist/index.js
42405
+ var shared_dist = __webpack_require__(8402);
42189
42406
  ;// CONCATENATED MODULE: ./src/utils/urlUtils.ts
42190
42407
  const getOrigin = url => {
42191
42408
  if (typeof url !== 'string') return 'unknown';
@@ -42201,12 +42418,12 @@ const getOrigin = url => {
42201
42418
 
42202
42419
  let instance;
42203
42420
  let origin;
42204
- let initPromise = (0,dist/* create */.Ue)();
42421
+ let initPromise = (0,shared_dist.createDeferred)();
42205
42422
  let timeout = 0;
42206
42423
  /* eslint-disable import/no-mutable-exports */
42207
42424
 
42208
42425
  const init = async settings => {
42209
- initPromise = (0,dist/* create */.Ue)();
42426
+ initPromise = (0,shared_dist.createDeferred)();
42210
42427
  const existedFrame = document.getElementById('onekey-connect');
42211
42428
 
42212
42429
  if (existedFrame) {
@@ -42229,14 +42446,14 @@ const init = async settings => {
42229
42446
  instance.setAttribute('src', src);
42230
42447
  origin = getOrigin(instance.src);
42231
42448
  timeout = window.setTimeout(() => {
42232
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeTimeout'));
42449
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeTimeout));
42233
42450
  }, 10000);
42234
42451
 
42235
42452
  const onLoad = () => {
42236
42453
  var _instance$contentWind;
42237
42454
 
42238
42455
  if (!instance) {
42239
- initPromise.reject(dist/* ERRORS.TypedError */.Sg.TypedError('Init_IframeBlocked'));
42456
+ initPromise.reject(shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IframeBlocked));
42240
42457
  return;
42241
42458
  }
42242
42459
 
@@ -44475,6 +44692,7 @@ const sendMessage = async (messages, isHost = true) => {
44475
44692
 
44476
44693
 
44477
44694
 
44695
+
44478
44696
  const eventEmitter = new (events_default())();
44479
44697
  const src_Log = (0,dist/* initLog */.KR)('@onekey/connect');
44480
44698
 
@@ -44510,7 +44728,7 @@ const src_dispose = () => {
44510
44728
 
44511
44729
  const uiResponse = response => {
44512
44730
  if (!instance) {
44513
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_NotInitialized');
44731
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameNotInitialized);
44514
44732
  }
44515
44733
 
44516
44734
  const {
@@ -44562,7 +44780,7 @@ const createJSBridge = messageEvent => {
44562
44780
 
44563
44781
  const src_init = async settings => {
44564
44782
  if (instance) {
44565
- throw dist/* ERRORS.TypedError */.Sg.TypedError('Init_AlreadyInitialized');
44783
+ throw shared_dist.ERRORS.TypedError(shared_dist.HardwareErrorCode.IFrameAleradyInitialized);
44566
44784
  }
44567
44785
 
44568
44786
  _settings = (0,dist/* parseConnectSettings */._4)({ ..._settings,
@@ -44596,7 +44814,7 @@ const call = async params => {
44596
44814
  }
44597
44815
 
44598
44816
  if (timeout) {
44599
- 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));
44600
44818
  }
44601
44819
 
44602
44820
  try {
@@ -44610,7 +44828,7 @@ const call = async params => {
44610
44828
  return response;
44611
44829
  }
44612
44830
 
44613
- 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));
44614
44832
  } catch (error) {
44615
44833
  src_Log.error('__call error: ', error);
44616
44834
  return (0,dist/* createErrorMessage */.xG)(error);