@onekeyfe/hd-core 0.1.44 → 0.1.45

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.
package/dist/index.js CHANGED
@@ -1,10 +1,20 @@
1
- import semver from 'semver';
2
- import { ERRORS, HardwareErrorCode, HardwareError, serializeError, createDeferred } from '@onekeyfe/hd-shared';
3
- import { FailureType, EthereumDataType, StellarMemoType } from '@onekeyfe/hd-transport';
4
- export { Messages as PROTO } from '@onekeyfe/hd-transport';
5
- import axios from 'axios';
6
- import BigNumber from 'bignumber.js';
7
- import sha256 from 'js-sha256';
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var semver = require('semver');
6
+ var hdShared = require('@onekeyfe/hd-shared');
7
+ var hdTransport = require('@onekeyfe/hd-transport');
8
+ var axios = require('axios');
9
+ var BigNumber = require('bignumber.js');
10
+ var sha256 = require('js-sha256');
11
+
12
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
+
14
+ var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
15
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
16
+ var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
17
+ var sha256__default = /*#__PURE__*/_interopDefaultLegacy(sha256);
8
18
 
9
19
  const inject = ({ call, cancel, dispose, eventEmitter, init, uiResponse, }) => {
10
20
  const api = {
@@ -618,8 +628,8 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
618
628
  const HD_HARDENED = 0x80000000;
619
629
  const toHardened = (n) => (n | HD_HARDENED) >>> 0;
620
630
  const fromHardened = (n) => (n & ~HD_HARDENED) >>> 0;
621
- const PATH_NOT_VALID = ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
622
- const PATH_NEGATIVE_VALUES = ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
631
+ const PATH_NOT_VALID = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Not a valid path');
632
+ const PATH_NEGATIVE_VALUES = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Path cannot contain negative values');
623
633
  const getHDPath = (path) => {
624
634
  const parts = path.toLowerCase().split('/');
625
635
  if (parts[0] !== 'm')
@@ -785,7 +795,7 @@ const getDeviceBLEFirmwareVersion = (features) => {
785
795
  if (!features.ble_ver) {
786
796
  return null;
787
797
  }
788
- if (!semver.valid(features.ble_ver)) {
798
+ if (!semver__default["default"].valid(features.ble_ver)) {
789
799
  return null;
790
800
  }
791
801
  return features.ble_ver.split('.');
@@ -798,7 +808,7 @@ const supportInputPinOnSoftware = (features) => {
798
808
  return { support: false };
799
809
  }
800
810
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
801
- return { support: semver.gte(currentVersion, '2.3.0'), require: '2.3.0' };
811
+ return { support: semver__default["default"].gte(currentVersion, '2.3.0'), require: '2.3.0' };
802
812
  };
803
813
  const supportNewPassphrase = (features) => {
804
814
  if (!features)
@@ -808,7 +818,7 @@ const supportNewPassphrase = (features) => {
808
818
  return { support: true };
809
819
  }
810
820
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
811
- return { support: semver.gte(currentVersion, '2.4.0'), require: '2.4.0' };
821
+ return { support: semver__default["default"].gte(currentVersion, '2.4.0'), require: '2.4.0' };
812
822
  };
813
823
  const getPassphraseState = (features, commands) => __awaiter(void 0, void 0, void 0, function* () {
814
824
  if (!features)
@@ -10030,7 +10040,7 @@ var MessagesJSON = {
10030
10040
  };
10031
10041
 
10032
10042
  const httpRequest$1 = (url, type = 'text') => __awaiter(void 0, void 0, void 0, function* () {
10033
- const response = yield axios.request({
10043
+ const response = yield axios__default["default"].request({
10034
10044
  url,
10035
10045
  withCredentials: false,
10036
10046
  responseType: type === 'binary' ? 'arraybuffer' : 'json',
@@ -10241,7 +10251,7 @@ const getCircularReplacer = () => {
10241
10251
  const sendLogMessage = (prefix, ...args) => {
10242
10252
  postMessage$1 === null || postMessage$1 === void 0 ? void 0 : postMessage$1(createLogMessage(LOG.OUTPUT, serializeLog(prefix, ...args)));
10243
10253
  };
10244
- var LoggerNames;
10254
+ exports.LoggerNames = void 0;
10245
10255
  (function (LoggerNames) {
10246
10256
  LoggerNames["Core"] = "Core";
10247
10257
  LoggerNames["Transport"] = "Transport";
@@ -10258,28 +10268,28 @@ var LoggerNames;
10258
10268
  LoggerNames["Iframe"] = "IFrame";
10259
10269
  LoggerNames["SendMessage"] = "[SendMessage]";
10260
10270
  LoggerNames["Method"] = "[Method]";
10261
- })(LoggerNames || (LoggerNames = {}));
10271
+ })(exports.LoggerNames || (exports.LoggerNames = {}));
10262
10272
  const LoggerMap = {
10263
- [LoggerNames.Core]: initLog(LoggerNames.Core),
10264
- [LoggerNames.Transport]: initLog(LoggerNames.Transport),
10265
- [LoggerNames.Device]: initLog(LoggerNames.Device),
10266
- [LoggerNames.DeviceCommands]: initLog(LoggerNames.DeviceCommands),
10267
- [LoggerNames.DeviceConnector]: initLog(LoggerNames.DeviceConnector),
10268
- [LoggerNames.DeviceList]: initLog(LoggerNames.DeviceList),
10269
- [LoggerNames.DevicePool]: initLog(LoggerNames.DevicePool),
10270
- [LoggerNames.HdBleSdk]: initLog(LoggerNames.HdBleSdk),
10271
- [LoggerNames.HdTransportHttp]: initLog(LoggerNames.HdTransportHttp),
10272
- [LoggerNames.HdBleTransport]: initLog(LoggerNames.HdBleTransport),
10273
- [LoggerNames.Connect]: initLog(LoggerNames.Connect),
10274
- [LoggerNames.Iframe]: initLog(LoggerNames.Iframe),
10275
- [LoggerNames.SendMessage]: initLog(LoggerNames.SendMessage),
10276
- [LoggerNames.Method]: initLog(LoggerNames.Method),
10277
- [LoggerNames.HdCommonConnectSdk]: initLog(LoggerNames.Method),
10273
+ [exports.LoggerNames.Core]: initLog(exports.LoggerNames.Core),
10274
+ [exports.LoggerNames.Transport]: initLog(exports.LoggerNames.Transport),
10275
+ [exports.LoggerNames.Device]: initLog(exports.LoggerNames.Device),
10276
+ [exports.LoggerNames.DeviceCommands]: initLog(exports.LoggerNames.DeviceCommands),
10277
+ [exports.LoggerNames.DeviceConnector]: initLog(exports.LoggerNames.DeviceConnector),
10278
+ [exports.LoggerNames.DeviceList]: initLog(exports.LoggerNames.DeviceList),
10279
+ [exports.LoggerNames.DevicePool]: initLog(exports.LoggerNames.DevicePool),
10280
+ [exports.LoggerNames.HdBleSdk]: initLog(exports.LoggerNames.HdBleSdk),
10281
+ [exports.LoggerNames.HdTransportHttp]: initLog(exports.LoggerNames.HdTransportHttp),
10282
+ [exports.LoggerNames.HdBleTransport]: initLog(exports.LoggerNames.HdBleTransport),
10283
+ [exports.LoggerNames.Connect]: initLog(exports.LoggerNames.Connect),
10284
+ [exports.LoggerNames.Iframe]: initLog(exports.LoggerNames.Iframe),
10285
+ [exports.LoggerNames.SendMessage]: initLog(exports.LoggerNames.SendMessage),
10286
+ [exports.LoggerNames.Method]: initLog(exports.LoggerNames.Method),
10287
+ [exports.LoggerNames.HdCommonConnectSdk]: initLog(exports.LoggerNames.Method),
10278
10288
  };
10279
10289
  const getLogger = (key) => LoggerMap[key];
10280
10290
 
10281
10291
  const getReleaseStatus = (releases, currentVersion) => {
10282
- const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
10292
+ const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
10283
10293
  if (newVersions.length === 0) {
10284
10294
  return 'valid';
10285
10295
  }
@@ -10289,7 +10299,7 @@ const getReleaseStatus = (releases, currentVersion) => {
10289
10299
  return 'outdated';
10290
10300
  };
10291
10301
  const getReleaseChangelog = (releases, currentVersion) => {
10292
- const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
10302
+ const newVersions = releases.filter(r => semver__default["default"].gt(r.version.join('.'), currentVersion));
10293
10303
  return newVersions.map(r => r.changelog);
10294
10304
  };
10295
10305
 
@@ -10299,7 +10309,7 @@ class DataManager {
10299
10309
  return __awaiter(this, void 0, void 0, function* () {
10300
10310
  this.settings = settings;
10301
10311
  try {
10302
- const { data } = yield axios.get(`https://data.onekey.so/config.json?noCache=${getTimeStamp()}`);
10312
+ const { data } = yield axios__default["default"].get(`https://data.onekey.so/config.json?noCache=${getTimeStamp()}`);
10303
10313
  this.deviceMap = {
10304
10314
  classic: data.classic,
10305
10315
  mini: data.mini,
@@ -10414,7 +10424,7 @@ DataManager.getTransportStatus = (localVersion) => {
10414
10424
  const latestTransportVersion = (_c = (_b = _a.assets) === null || _b === void 0 ? void 0 : _b.bridge) === null || _c === void 0 ? void 0 : _c.version;
10415
10425
  if (!latestTransportVersion)
10416
10426
  return 'valid';
10417
- const isLatest = semver.gte(localVersion, latestTransportVersion.join('.'));
10427
+ const isLatest = semver__default["default"].gte(localVersion, latestTransportVersion.join('.'));
10418
10428
  return isLatest ? 'valid' : 'outdated';
10419
10429
  };
10420
10430
 
@@ -10436,7 +10446,7 @@ const parseMessage = (messageData) => {
10436
10446
  };
10437
10447
  const createErrorMessage = (error) => {
10438
10448
  let payload = { error: error.message, code: error.code };
10439
- if (error instanceof HardwareError) {
10449
+ if (error instanceof hdShared.HardwareError) {
10440
10450
  payload = { error: error.message, code: error.errorCode };
10441
10451
  }
10442
10452
  return {
@@ -10481,7 +10491,7 @@ const createResponseMessage = (id, success, payload) => ({
10481
10491
  type: RESPONSE_EVENT,
10482
10492
  id,
10483
10493
  success,
10484
- payload: success ? payload : serializeError(payload),
10494
+ payload: success ? payload : hdShared.serializeError(payload),
10485
10495
  });
10486
10496
 
10487
10497
  const UI_RESPONSE = {
@@ -10531,7 +10541,7 @@ const createFirmwareMessage = (type, payload) => ({
10531
10541
  payload,
10532
10542
  });
10533
10543
 
10534
- const Log$7 = getLogger(LoggerNames.DevicePool);
10544
+ const Log$7 = getLogger(exports.LoggerNames.DevicePool);
10535
10545
  const getDiff = (current, descriptors) => {
10536
10546
  const connected = descriptors.filter(d => current.find(x => x.path === d.path) === undefined);
10537
10547
  const disconnected = current.filter(d => descriptors.find(x => x.path === d.path) === undefined);
@@ -10734,9 +10744,9 @@ DevicePool.disconnectPool = [];
10734
10744
  DevicePool.devicesCache = {};
10735
10745
  DevicePool.emitter = new events.exports();
10736
10746
 
10737
- const Log$6 = getLogger(LoggerNames.Transport);
10738
- const BleLogger = getLogger(LoggerNames.HdBleTransport);
10739
- const HttpLogger = getLogger(LoggerNames.HdTransportHttp);
10747
+ const Log$6 = getLogger(exports.LoggerNames.Transport);
10748
+ const BleLogger = getLogger(exports.LoggerNames.HdBleTransport);
10749
+ const HttpLogger = getLogger(exports.LoggerNames.HdTransportHttp);
10740
10750
  class TransportManager {
10741
10751
  static load() {
10742
10752
  Log$6.debug('transport manager load');
@@ -10767,7 +10777,7 @@ class TransportManager {
10767
10777
  catch (error) {
10768
10778
  Log$6.debug('Initializing transports error: ', error);
10769
10779
  if (error.code === 'ECONNABORTED') {
10770
- throw ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError);
10780
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
10771
10781
  }
10772
10782
  }
10773
10783
  });
@@ -10785,7 +10795,7 @@ class TransportManager {
10785
10795
  this.currentMessages = messages;
10786
10796
  }
10787
10797
  catch (error) {
10788
- throw ERRORS.TypedError(HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
10798
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportInvalidProtobuf, `Transport_InvalidProtobuf: ${error.message}`);
10789
10799
  }
10790
10800
  });
10791
10801
  }
@@ -10814,10 +10824,10 @@ TransportManager.reactNativeInit = false;
10814
10824
  const assertType = (res, resType) => {
10815
10825
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
10816
10826
  if (!splitResTypes.includes(res.type)) {
10817
- throw ERRORS.TypedError(HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
10827
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ResponseUnexpectTypeError, `assertType: Response of unexpected type: ${res.type}. Should be ${resType}`);
10818
10828
  }
10819
10829
  };
10820
- const Log$5 = getLogger(LoggerNames.DeviceCommands);
10830
+ const Log$5 = getLogger(exports.LoggerNames.DeviceCommands);
10821
10831
  class DeviceCommands {
10822
10832
  constructor(device, mainId) {
10823
10833
  this.device = device;
@@ -10859,7 +10869,7 @@ class DeviceCommands {
10859
10869
  typedCall(type, resType, msg) {
10860
10870
  return __awaiter(this, void 0, void 0, function* () {
10861
10871
  if (this.disposed) {
10862
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'typedCall: DeviceCommands already disposed');
10872
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'typedCall: DeviceCommands already disposed');
10863
10873
  }
10864
10874
  const response = yield this._commonCall(type, msg);
10865
10875
  try {
@@ -10867,10 +10877,10 @@ class DeviceCommands {
10867
10877
  }
10868
10878
  catch (error) {
10869
10879
  Log$5.debug('DeviceCommands typedcall error: ', error);
10870
- if (error instanceof HardwareError) {
10871
- if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
10880
+ if (error instanceof hdShared.HardwareError) {
10881
+ if (error.errorCode === hdShared.HardwareErrorCode.ResponseUnexpectTypeError) {
10872
10882
  if (error.message.indexOf('BridgeNetworkError') > -1) {
10873
- throw ERRORS.TypedError(HardwareErrorCode.BridgeNetworkError);
10883
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNetworkError);
10874
10884
  }
10875
10885
  }
10876
10886
  }
@@ -10893,25 +10903,25 @@ class DeviceCommands {
10893
10903
  const { code } = res.message;
10894
10904
  const { message } = res.message;
10895
10905
  let error = null;
10896
- if (code === FailureType.Failure_FirmwareError && !message) {
10897
- error = ERRORS.TypedError(HardwareErrorCode.FirmwareError);
10906
+ if (code === hdTransport.FailureType.Failure_FirmwareError && !message) {
10907
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError);
10898
10908
  }
10899
- if (code === FailureType.Failure_ActionCancelled) {
10900
- error = ERRORS.TypedError(HardwareErrorCode.ActionCancelled);
10909
+ if (code === hdTransport.FailureType.Failure_ActionCancelled) {
10910
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled);
10901
10911
  }
10902
- if (code === FailureType.Failure_PinInvalid) {
10903
- error = ERRORS.TypedError(HardwareErrorCode.PinInvalid, message);
10912
+ if (code === hdTransport.FailureType.Failure_PinInvalid) {
10913
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinInvalid, message);
10904
10914
  }
10905
- if (code === FailureType.Failure_PinCancelled) {
10906
- error = ERRORS.TypedError(HardwareErrorCode.PinCancelled);
10915
+ if (code === hdTransport.FailureType.Failure_PinCancelled) {
10916
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PinCancelled);
10907
10917
  }
10908
- if (code === FailureType.Failure_DataError && message === 'Please confirm the BlindSign enabled') {
10909
- error = ERRORS.TypedError(HardwareErrorCode.BlindSignDisabled);
10918
+ if (code === hdTransport.FailureType.Failure_DataError && message === 'Please confirm the BlindSign enabled') {
10919
+ error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BlindSignDisabled);
10910
10920
  }
10911
10921
  if (error) {
10912
10922
  return Promise.reject(error);
10913
10923
  }
10914
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, `${code || 'Failure_UnknownCode'},${message || 'Failure_UnknownMessage'}`));
10924
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${code || 'Failure_UnknownCode'},${message || 'Failure_UnknownMessage'}`));
10915
10925
  }
10916
10926
  if (res.type === 'Features') {
10917
10927
  return Promise.resolve(patchFeatures(res));
@@ -10929,7 +10939,7 @@ class DeviceCommands {
10929
10939
  const isWebusbEnv = DataManager.getSettings('env') === 'webusb';
10930
10940
  if (res.type === 'PinMatrixRequest') {
10931
10941
  if (isWebusbEnv) {
10932
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please unlock your device'));
10942
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please unlock your device'));
10933
10943
  }
10934
10944
  return this._promptPin(res.message.type).then(pin => {
10935
10945
  if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
@@ -10939,7 +10949,7 @@ class DeviceCommands {
10939
10949
  }, () => this._commonCall('Cancel', {}));
10940
10950
  }
10941
10951
  if (res.type === 'PassphraseRequest') {
10942
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceNotSupportPassphrase, 'Device not support passphrase', {
10952
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, 'Device not support passphrase', {
10943
10953
  require: '2.4.0',
10944
10954
  }));
10945
10955
  }
@@ -10963,7 +10973,7 @@ class DeviceCommands {
10963
10973
  }
10964
10974
  else {
10965
10975
  console.warn('[DeviceCommands] [call] PIN callback not configured, cancelling request');
10966
- reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, '_promptPin: PIN callback not configured'));
10976
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, '_promptPin: PIN callback not configured'));
10967
10977
  }
10968
10978
  });
10969
10979
  }
@@ -10982,7 +10992,9 @@ const UI_REQUEST = {
10982
10992
  NOT_USE_ONEKEY_DEVICE: 'ui-device_please_use_onekey_device',
10983
10993
  };
10984
10994
 
10985
- const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${process.env.VERSION}/`;
10995
+ const pkg = require('../package.json');
10996
+ const getSDKVersion = () => pkg.version;
10997
+ const DEFAULT_DOMAIN = `https://jssdk.onekey.so/${getSDKVersion()}/`;
10986
10998
 
10987
10999
  const DEFAULT_PRIORITY = 2;
10988
11000
  const initialSettings = {
@@ -10993,7 +11005,7 @@ const initialSettings = {
10993
11005
  trustedHost: false,
10994
11006
  connectSrc: DEFAULT_DOMAIN,
10995
11007
  iframeSrc: `${DEFAULT_DOMAIN}iframe.html`,
10996
- parentOrigin: window && window.location ? window.location.origin : '',
11008
+ parentOrigin: typeof window !== 'undefined' && window.location ? window.location.origin : '',
10997
11009
  supportedBrowser: typeof navigator !== 'undefined' ? !/Trident|MSIE|Edge/.test(navigator.userAgent) : true,
10998
11010
  env: 'web',
10999
11011
  lazyLoad: false,
@@ -11073,7 +11085,7 @@ const parseRunOptions = (options) => {
11073
11085
  options = {};
11074
11086
  return options;
11075
11087
  };
11076
- const Log$4 = getLogger(LoggerNames.Device);
11088
+ const Log$4 = getLogger(exports.LoggerNames.Device);
11077
11089
  const deviceSessionCache = {};
11078
11090
  class Device extends events.exports {
11079
11091
  constructor(descriptor) {
@@ -11323,7 +11335,7 @@ class Device extends events.exports {
11323
11335
  Log$4.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
11324
11336
  }
11325
11337
  options = parseRunOptions(options);
11326
- this.runPromise = createDeferred(this._runInner.bind(this, fn, options));
11338
+ this.runPromise = hdShared.createDeferred(this._runInner.bind(this, fn, options));
11327
11339
  return this.runPromise.promise;
11328
11340
  });
11329
11341
  }
@@ -11340,10 +11352,10 @@ class Device extends events.exports {
11340
11352
  }
11341
11353
  catch (error) {
11342
11354
  this.runPromise = null;
11343
- if (error instanceof HardwareError) {
11355
+ if (error instanceof hdShared.HardwareError) {
11344
11356
  return Promise.reject(error);
11345
11357
  }
11346
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
11358
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, `Initialize failed: ${error.message}, code: ${error.code}`));
11347
11359
  }
11348
11360
  }
11349
11361
  }
@@ -11380,7 +11392,7 @@ class Device extends events.exports {
11380
11392
  yield this.commands.dispose(false);
11381
11393
  }
11382
11394
  if (this.runPromise) {
11383
- this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromOutside));
11395
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromOutside));
11384
11396
  }
11385
11397
  });
11386
11398
  }
@@ -11390,7 +11402,7 @@ class Device extends events.exports {
11390
11402
  yield this.commands.dispose(true);
11391
11403
  }
11392
11404
  if (this.runPromise) {
11393
- this.runPromise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInterruptedFromUser));
11405
+ this.runPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInterruptedFromUser));
11394
11406
  }
11395
11407
  });
11396
11408
  }
@@ -11532,7 +11544,7 @@ const getBleFirmwareReleaseInfo = (features) => {
11532
11544
  };
11533
11545
  };
11534
11546
 
11535
- const Log$3 = getLogger(LoggerNames.Method);
11547
+ const Log$3 = getLogger(exports.LoggerNames.Method);
11536
11548
  class BaseMethod {
11537
11549
  constructor(message) {
11538
11550
  this.shouldEnsureConnected = true;
@@ -11637,7 +11649,7 @@ class GetPassphraseState extends BaseMethod {
11637
11649
  var _a, _b;
11638
11650
  return __awaiter(this, void 0, void 0, function* () {
11639
11651
  if (!this.device.features)
11640
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
11652
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed));
11641
11653
  let { features } = this.device;
11642
11654
  const locked = ((_b = (_a = this.device) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.unlocked) === true;
11643
11655
  const passphraseState = yield getPassphraseState(this.device.features, this.device.commands);
@@ -11718,7 +11730,7 @@ class CheckBridgeStatus extends BaseMethod {
11718
11730
  run() {
11719
11731
  return __awaiter(this, void 0, void 0, function* () {
11720
11732
  return new Promise((resolve, reject) => {
11721
- axios
11733
+ axios__default["default"]
11722
11734
  .request({
11723
11735
  url: 'http://localhost:21320',
11724
11736
  method: 'POST',
@@ -11728,7 +11740,7 @@ class CheckBridgeStatus extends BaseMethod {
11728
11740
  .then(() => resolve(true))
11729
11741
  .catch(e => {
11730
11742
  if (e.code === 'ECONNABORTED') {
11731
- reject(ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError));
11743
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError));
11732
11744
  }
11733
11745
  else {
11734
11746
  resolve(false);
@@ -11787,7 +11799,7 @@ const formatAnyHex = value => {
11787
11799
  return value;
11788
11800
  };
11789
11801
 
11790
- const invalidParameter = (message) => ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
11802
+ const invalidParameter = (message) => hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, message);
11791
11803
  const validateParams = (values, fields) => {
11792
11804
  fields.forEach(field => {
11793
11805
  const existsProp = Object.prototype.hasOwnProperty.call(values, field.name);
@@ -11810,7 +11822,7 @@ const validateParams = (values, fields) => {
11810
11822
  throw invalidParameter(`Parameter [${field.name}] is of type invalid and should be [string].`);
11811
11823
  }
11812
11824
  try {
11813
- const bn = new BigNumber(value);
11825
+ const bn = new BigNumber__default["default"](value);
11814
11826
  if (bn.toFixed(0) !== value) {
11815
11827
  throw new Error('');
11816
11828
  }
@@ -12028,7 +12040,7 @@ class DeviceSupportFeatures extends BaseMethod {
12028
12040
  }
12029
12041
  run() {
12030
12042
  if (!this.device.features)
12031
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not initialized'));
12043
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device not initialized'));
12032
12044
  const inputPinOnSoftware = supportInputPinOnSoftware(this.device.features);
12033
12045
  return Promise.resolve({
12034
12046
  inputPinOnSoftware,
@@ -12050,7 +12062,7 @@ class DeviceVerify extends BaseMethod {
12050
12062
  const deviceType = getDeviceType(this.device.features);
12051
12063
  let response;
12052
12064
  if (deviceType === 'classic') {
12053
- const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256.sha256(this.params.data) }));
12065
+ const res = yield this.device.commands.typedCall('BixinVerifyDeviceRequest', 'BixinVerifyDeviceAck', Object.assign(Object.assign({}, this.params), { data: sha256__default["default"].sha256(this.params.data) }));
12054
12066
  response = res.message;
12055
12067
  }
12056
12068
  else {
@@ -12065,7 +12077,7 @@ class DeviceVerify extends BaseMethod {
12065
12077
  }
12066
12078
  if (response)
12067
12079
  return Promise.resolve(response);
12068
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device not support verify'));
12080
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Device not support verify'));
12069
12081
  });
12070
12082
  }
12071
12083
  }
@@ -12085,11 +12097,11 @@ class DeviceWipe extends BaseMethod {
12085
12097
  const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void 0, void 0, function* () {
12086
12098
  const releaseInfo = getInfo({ features, updateType });
12087
12099
  if (!releaseInfo) {
12088
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
12100
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no firmware found for this device');
12089
12101
  }
12090
12102
  if (version &&
12091
- !semver.eq(releaseInfo.version, version)) {
12092
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
12103
+ !semver__default["default"].eq(releaseInfo.version, version)) {
12104
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'firmware version mismatch');
12093
12105
  }
12094
12106
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
12095
12107
  let fw;
@@ -12097,7 +12109,7 @@ const getBinary = ({ features, updateType, version }) => __awaiter(void 0, void
12097
12109
  fw = yield httpRequest(url, 'binary');
12098
12110
  }
12099
12111
  catch (_a) {
12100
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
12112
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
12101
12113
  }
12102
12114
  return Object.assign(Object.assign({}, releaseInfo), { binary: fw });
12103
12115
  });
@@ -12152,7 +12164,7 @@ const uploadFirmware = (updateType, typedCall, postMessage, device, { payload })
12152
12164
  postProgressMessage(device, 100, postMessage);
12153
12165
  return response.message;
12154
12166
  }
12155
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
12167
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
12156
12168
  });
12157
12169
 
12158
12170
  class FirmwareUpdate extends BaseMethod {
@@ -12166,7 +12178,7 @@ class FirmwareUpdate extends BaseMethod {
12166
12178
  { name: 'binary', type: 'buffer' },
12167
12179
  ]);
12168
12180
  if (!payload.updateType) {
12169
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
12181
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'updateType is required');
12170
12182
  }
12171
12183
  this.params = { updateType: payload.updateType };
12172
12184
  if ('version' in payload) {
@@ -12187,7 +12199,7 @@ class FirmwareUpdate extends BaseMethod {
12187
12199
  }
12188
12200
  else {
12189
12201
  if (!device.features) {
12190
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no features found for this device');
12202
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'no features found for this device');
12191
12203
  }
12192
12204
  const firmware = yield getBinary({
12193
12205
  features: device.features,
@@ -12198,14 +12210,14 @@ class FirmwareUpdate extends BaseMethod {
12198
12210
  }
12199
12211
  }
12200
12212
  catch (err) {
12201
- throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, (_a = err.message) !== null && _a !== void 0 ? _a : err);
12213
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, (_a = err.message) !== null && _a !== void 0 ? _a : err);
12202
12214
  }
12203
12215
  return uploadFirmware(params.updateType, this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, { payload: binary });
12204
12216
  });
12205
12217
  }
12206
12218
  }
12207
12219
 
12208
- const Log$2 = getLogger(LoggerNames.Method);
12220
+ const Log$2 = getLogger(exports.LoggerNames.Method);
12209
12221
  class RequestWebUsbDevice extends BaseMethod {
12210
12222
  init() {
12211
12223
  this.useDevice = false;
@@ -12217,7 +12229,7 @@ class RequestWebUsbDevice extends BaseMethod {
12217
12229
  yield TransportManager.configure();
12218
12230
  const env = DataManager.getSettings('env');
12219
12231
  if (env !== 'webusb') {
12220
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Not webusb environment'));
12232
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Not webusb environment'));
12221
12233
  }
12222
12234
  try {
12223
12235
  const deviceDiff = yield ((_a = this.connector) === null || _a === void 0 ? void 0 : _a.enumerate());
@@ -12226,11 +12238,11 @@ class RequestWebUsbDevice extends BaseMethod {
12226
12238
  if (deviceList.length > 0) {
12227
12239
  return { device: deviceList[0].toMessageObject() };
12228
12240
  }
12229
- return yield Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12241
+ return yield Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12230
12242
  }
12231
12243
  catch (error) {
12232
12244
  Log$2.debug(error);
12233
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12245
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Please select the device to connect'));
12234
12246
  }
12235
12247
  });
12236
12248
  }
@@ -12499,13 +12511,13 @@ const getCoinInfo = (path, coin) => {
12499
12511
  }
12500
12512
  if (!coinInfo) {
12501
12513
  if (coin) {
12502
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
12514
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid coin name: ${coin}`);
12503
12515
  }
12504
12516
  else if (path) {
12505
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
12517
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Invalid path: ${path[0]}`);
12506
12518
  }
12507
12519
  else {
12508
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
12520
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter);
12509
12521
  }
12510
12522
  }
12511
12523
  return coinInfo;
@@ -12662,49 +12674,49 @@ class BTCSignMessage extends BaseMethod {
12662
12674
  const requestPrevTxInfo$1 = ({ typedCall, txRequest: { request_type, details }, refTxs }) => {
12663
12675
  const { tx_hash } = details;
12664
12676
  if (!tx_hash) {
12665
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
12677
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
12666
12678
  }
12667
12679
  const tx = refTxs[tx_hash.toLowerCase()];
12668
12680
  if (!tx) {
12669
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
12681
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
12670
12682
  }
12671
12683
  if (request_type === 'TXINPUT') {
12672
12684
  if (!tx.bin_outputs)
12673
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
12685
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`);
12674
12686
  return typedCall('TxAckPrevInput', 'TxRequest', {
12675
12687
  tx: { input: tx.inputs[details.request_index] },
12676
12688
  });
12677
12689
  }
12678
12690
  if (request_type === 'TXOUTPUT') {
12679
12691
  if (!tx.bin_outputs)
12680
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
12692
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`);
12681
12693
  return typedCall('TxAckPrevOutput', 'TxRequest', {
12682
12694
  tx: { output: tx.bin_outputs[details.request_index] },
12683
12695
  });
12684
12696
  }
12685
12697
  if (request_type === 'TXORIGINPUT') {
12686
12698
  if (!tx.outputs)
12687
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
12699
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`);
12688
12700
  return typedCall('TxAckInput', 'TxRequest', {
12689
12701
  tx: { input: tx.inputs[details.request_index] },
12690
12702
  });
12691
12703
  }
12692
12704
  if (request_type === 'TXORIGOUTPUT') {
12693
12705
  if (!tx.outputs)
12694
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
12706
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`);
12695
12707
  return typedCall('TxAckOutput', 'TxRequest', {
12696
12708
  tx: { output: tx.outputs[details.request_index] },
12697
12709
  });
12698
12710
  }
12699
12711
  if (request_type === 'TXEXTRADATA') {
12700
12712
  if (typeof details.extra_data_len !== 'number') {
12701
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
12713
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
12702
12714
  }
12703
12715
  if (typeof details.extra_data_offset !== 'number') {
12704
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
12716
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
12705
12717
  }
12706
12718
  if (typeof tx.extra_data !== 'string') {
12707
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
12719
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
12708
12720
  }
12709
12721
  const data = tx.extra_data;
12710
12722
  const dataLen = details.extra_data_len;
@@ -12727,7 +12739,7 @@ const requestPrevTxInfo$1 = ({ typedCall, txRequest: { request_type, details },
12727
12739
  };
12728
12740
  return typedCall('TxAckPrevMeta', 'TxRequest', { tx: meta });
12729
12741
  }
12730
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
12742
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
12731
12743
  };
12732
12744
  const requestSignedTxInfo$1 = ({ typedCall, txRequest: { request_type, details }, inputs, outputs, }) => {
12733
12745
  if (request_type === 'TXINPUT') {
@@ -12739,12 +12751,12 @@ const requestSignedTxInfo$1 = ({ typedCall, txRequest: { request_type, details }
12739
12751
  });
12740
12752
  }
12741
12753
  if (request_type === 'TXMETA') {
12742
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
12754
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
12743
12755
  }
12744
12756
  if (request_type === 'TXEXTRADATA') {
12745
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
12757
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
12746
12758
  }
12747
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
12759
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
12748
12760
  };
12749
12761
  const requestTxAck$1 = (props) => {
12750
12762
  const { tx_hash } = props.txRequest.details;
@@ -12762,7 +12774,7 @@ const saveTxSignatures$1 = (serializedTx, signatures, txRequest) => {
12762
12774
  }
12763
12775
  if (typeof signature_index === 'number') {
12764
12776
  if (!signature) {
12765
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
12777
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
12766
12778
  }
12767
12779
  signatures[signature_index] = signature;
12768
12780
  }
@@ -12807,14 +12819,14 @@ var signtx = (typedCall, inputs, outputs, refTxsArray, options, coinName) => __a
12807
12819
  const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) => {
12808
12820
  const { tx_hash } = details;
12809
12821
  if (!tx_hash) {
12810
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
12822
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: unknown details.tx_hash');
12811
12823
  }
12812
12824
  const tx = refTxs[tx_hash.toLowerCase()];
12813
12825
  if (!tx) {
12814
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
12826
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
12815
12827
  }
12816
12828
  if (!tx.bin_outputs) {
12817
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
12829
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
12818
12830
  }
12819
12831
  if (request_type === 'TXINPUT') {
12820
12832
  return { inputs: [tx.inputs[details.request_index]] };
@@ -12824,13 +12836,13 @@ const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) =>
12824
12836
  }
12825
12837
  if (request_type === 'TXEXTRADATA') {
12826
12838
  if (typeof details.extra_data_len !== 'number') {
12827
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
12839
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_len');
12828
12840
  }
12829
12841
  if (typeof details.extra_data_offset !== 'number') {
12830
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
12842
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestPrevTxInfo: Missing extra_data_offset');
12831
12843
  }
12832
12844
  if (typeof tx.extra_data !== 'string') {
12833
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
12845
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: No extra data for transaction ${tx.hash}`);
12834
12846
  }
12835
12847
  const data = tx.extra_data;
12836
12848
  const dataLen = details.extra_data_len;
@@ -12855,7 +12867,7 @@ const requestPrevTxInfo = ({ txRequest: { request_type, details }, refTxs, }) =>
12855
12867
  }
12856
12868
  return meta;
12857
12869
  }
12858
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
12870
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestPrevTxInfo: Unknown request type: ${request_type}`);
12859
12871
  };
12860
12872
  const requestSignedTxInfo = ({ txRequest: { request_type, details }, inputs, outputs, }) => {
12861
12873
  if (request_type === 'TXINPUT') {
@@ -12865,12 +12877,12 @@ const requestSignedTxInfo = ({ txRequest: { request_type, details }, inputs, out
12865
12877
  return { outputs: [outputs[details.request_index]] };
12866
12878
  }
12867
12879
  if (request_type === 'TXMETA') {
12868
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
12880
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXMETA from signed transaction');
12869
12881
  }
12870
12882
  if (request_type === 'TXEXTRADATA') {
12871
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
12883
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction');
12872
12884
  }
12873
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
12885
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `requestSignedTxInfo: Unknown request type: ${request_type}`);
12874
12886
  };
12875
12887
  const requestTxAck = (props) => {
12876
12888
  const { tx_hash } = props.txRequest.details;
@@ -12888,7 +12900,7 @@ const saveTxSignatures = (serializedTx, signatures, txRequest) => {
12888
12900
  }
12889
12901
  if (typeof signature_index === 'number') {
12890
12902
  if (!signature) {
12891
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
12903
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.');
12892
12904
  }
12893
12905
  signatures[signature_index] = signature;
12894
12906
  }
@@ -12983,12 +12995,12 @@ class BTCSignTransaction extends BaseMethod {
12983
12995
  ]);
12984
12996
  if (Object.prototype.hasOwnProperty.call(output, 'address_n') &&
12985
12997
  Object.prototype.hasOwnProperty.call(output, 'address')) {
12986
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
12998
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Cannot use address and address_n in one output');
12987
12999
  }
12988
13000
  if (output.address_n) {
12989
13001
  const scriptType = getOutputScriptType(output.address_n);
12990
13002
  if (output.script_type !== scriptType)
12991
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
13003
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Output change script_type should be set to ${scriptType}`);
12992
13004
  }
12993
13005
  });
12994
13006
  const { inputs, outputs, refTxs, account, coin } = this.payload;
@@ -13177,7 +13189,7 @@ class ConfluxSignTransaction extends BaseMethod {
13177
13189
  const r = request.signature_r;
13178
13190
  const s = request.signature_s;
13179
13191
  if (v == null || r == null || s == null) {
13180
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodError, 'sign transaction failed');
13192
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, 'sign transaction failed');
13181
13193
  }
13182
13194
  return Promise.resolve({
13183
13195
  v: `0x${v.toString(16)}`,
@@ -13247,7 +13259,7 @@ class ConfluxSignTransaction extends BaseMethod {
13247
13259
  return __awaiter(this, void 0, void 0, function* () {
13248
13260
  const { addressN, formattedTx } = this;
13249
13261
  if (formattedTx == null) {
13250
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'ConfluxSignTransaction: format tx error');
13262
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'ConfluxSignTransaction: format tx error');
13251
13263
  }
13252
13264
  const signedTx = yield this.evmSignTx(addressN, formattedTx);
13253
13265
  return Promise.resolve(signedTx);
@@ -13405,7 +13417,7 @@ class EVMSignTransaction extends BaseMethod {
13405
13417
  const r = request.signature_r;
13406
13418
  const s = request.signature_s;
13407
13419
  if (v == null || r == null || s == null) {
13408
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
13420
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'processTxRequest: Unexpected request');
13409
13421
  }
13410
13422
  if (chain_id && v <= 1) {
13411
13423
  v += 2 * chain_id + 35;
@@ -13525,13 +13537,13 @@ class EVMSignTransaction extends BaseMethod {
13525
13537
 
13526
13538
  const twosComplement = (number, bytes) => {
13527
13539
  if (bytes < 1 || bytes > 32) {
13528
- throw ERRORS.TypedError('Runtime', 'Int byte size must be between 1 and 32 (8 and 256 bits)');
13540
+ throw hdShared.ERRORS.TypedError('Runtime', 'Int byte size must be between 1 and 32 (8 and 256 bits)');
13529
13541
  }
13530
- const minValue = new BigNumber(2).exponentiatedBy(bytes * 8 - 1).negated();
13542
+ const minValue = new BigNumber__default["default"](2).exponentiatedBy(bytes * 8 - 1).negated();
13531
13543
  const maxValue = minValue.negated().minus(1);
13532
- const bigNumber = new BigNumber(number);
13544
+ const bigNumber = new BigNumber__default["default"](number);
13533
13545
  if (bigNumber.isGreaterThan(maxValue) || bigNumber.isLessThan(minValue)) {
13534
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`);
13546
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`);
13535
13547
  }
13536
13548
  if (bigNumber.isPositive()) {
13537
13549
  return bigNumber;
@@ -13539,17 +13551,17 @@ const twosComplement = (number, bytes) => {
13539
13551
  return bigNumber.minus(minValue).minus(minValue);
13540
13552
  };
13541
13553
  const intToHex = (number, bytes, signed) => {
13542
- let bigNumber = new BigNumber(number);
13554
+ let bigNumber = new BigNumber__default["default"](number);
13543
13555
  if (signed) {
13544
13556
  bigNumber = twosComplement(bigNumber, bytes);
13545
13557
  }
13546
13558
  if (bigNumber.isNegative()) {
13547
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `Cannot convert negative number to unsigned interger: ${number.toString()}`);
13559
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Cannot convert negative number to unsigned interger: ${number.toString()}`);
13548
13560
  }
13549
13561
  const hex = bigNumber.toString(16);
13550
13562
  const hexChars = bytes * 2;
13551
13563
  if (hex.length > hexChars) {
13552
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`);
13564
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`);
13553
13565
  }
13554
13566
  return hex.padStart(bytes * 2, '0');
13555
13567
  };
@@ -13560,7 +13572,7 @@ const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
13560
13572
  const parseArrayType = (arrayTypeName) => {
13561
13573
  const arrayMatch = paramTypeArray.exec(arrayTypeName);
13562
13574
  if (arrayMatch === null) {
13563
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `typename ${arrayTypeName} could not be parsed as an EIP-712 array`);
13575
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `typename ${arrayTypeName} could not be parsed as an EIP-712 array`);
13564
13576
  }
13565
13577
  const [_, entryTypeName, arraySize] = arrayMatch;
13566
13578
  return {
@@ -13584,12 +13596,12 @@ const encodeData = (typeName, data) => {
13584
13596
  if (typeName === 'bool') {
13585
13597
  return data ? '01' : '00';
13586
13598
  }
13587
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `Unsupported data type for direct field encoding: ${typeName}`);
13599
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Unsupported data type for direct field encoding: ${typeName}`);
13588
13600
  };
13589
13601
  const paramTypesMap = {
13590
- string: EthereumDataType.STRING,
13591
- bool: EthereumDataType.BOOL,
13592
- address: EthereumDataType.ADDRESS,
13602
+ string: hdTransport.EthereumDataType.STRING,
13603
+ bool: hdTransport.EthereumDataType.BOOL,
13604
+ address: hdTransport.EthereumDataType.ADDRESS,
13593
13605
  };
13594
13606
  const getFieldType = (typeName, types) => {
13595
13607
  const arrayMatch = paramTypeArray.exec(typeName);
@@ -13597,7 +13609,7 @@ const getFieldType = (typeName, types) => {
13597
13609
  const [_, arrayItemTypeName, arraySize] = arrayMatch;
13598
13610
  const entryType = getFieldType(arrayItemTypeName, types);
13599
13611
  return {
13600
- data_type: EthereumDataType.ARRAY,
13612
+ data_type: hdTransport.EthereumDataType.ARRAY,
13601
13613
  size: parseInt(arraySize, 10) || undefined,
13602
13614
  entry_type: entryType,
13603
13615
  };
@@ -13606,7 +13618,7 @@ const getFieldType = (typeName, types) => {
13606
13618
  if (numberMatch) {
13607
13619
  const [_, type, bits] = numberMatch;
13608
13620
  return {
13609
- data_type: type === 'uint' ? EthereumDataType.UINT : EthereumDataType.INT,
13621
+ data_type: type === 'uint' ? hdTransport.EthereumDataType.UINT : hdTransport.EthereumDataType.INT,
13610
13622
  size: Math.floor(parseInt(bits, 10) / 8),
13611
13623
  };
13612
13624
  }
@@ -13614,7 +13626,7 @@ const getFieldType = (typeName, types) => {
13614
13626
  if (bytesMatch) {
13615
13627
  const [_, size] = bytesMatch;
13616
13628
  return {
13617
- data_type: EthereumDataType.BYTES,
13629
+ data_type: hdTransport.EthereumDataType.BYTES,
13618
13630
  size: parseInt(size, 10) || undefined,
13619
13631
  };
13620
13632
  }
@@ -13626,12 +13638,12 @@ const getFieldType = (typeName, types) => {
13626
13638
  }
13627
13639
  if (typeName in types) {
13628
13640
  return {
13629
- data_type: EthereumDataType.STRUCT,
13641
+ data_type: hdTransport.EthereumDataType.STRUCT,
13630
13642
  size: types[typeName].length,
13631
13643
  struct_name: typeName,
13632
13644
  };
13633
13645
  }
13634
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, `No type definition specified: ${typeName}`);
13646
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `No type definition specified: ${typeName}`);
13635
13647
  };
13636
13648
 
13637
13649
  class EVMSignTypedData extends BaseMethod {
@@ -13658,7 +13670,7 @@ class EVMSignTypedData extends BaseMethod {
13658
13670
  this.params.messageHash = formatAnyHex(messageHash);
13659
13671
  }
13660
13672
  else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
13661
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'message_hash should only be empty when data.primaryType=EIP712Domain');
13673
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'message_hash should only be empty when data.primaryType=EIP712Domain');
13662
13674
  }
13663
13675
  }
13664
13676
  }
@@ -13680,7 +13692,7 @@ class EVMSignTypedData extends BaseMethod {
13680
13692
  const { name: typeDefinitionName } = response.message;
13681
13693
  const typeDefinition = types[typeDefinitionName];
13682
13694
  if (typeDefinition === undefined) {
13683
- throw ERRORS.TypedError('Runtime', `Type ${typeDefinitionName} was not defined in types object`);
13695
+ throw hdShared.ERRORS.TypedError('Runtime', `Type ${typeDefinitionName} was not defined in types object`);
13684
13696
  }
13685
13697
  const dataStruckAck = {
13686
13698
  members: typeDefinition.map(({ name, type: typeName }) => ({
@@ -13709,7 +13721,7 @@ class EVMSignTypedData extends BaseMethod {
13709
13721
  memberTypeName = primaryType;
13710
13722
  break;
13711
13723
  default:
13712
- throw ERRORS.TypedError('Runtime', 'Root index can only be 0 or 1');
13724
+ throw hdShared.ERRORS.TypedError('Runtime', 'Root index can only be 0 or 1');
13713
13725
  }
13714
13726
  for (const index of nestedMemberPath) {
13715
13727
  if (Array.isArray(memberData)) {
@@ -13735,7 +13747,7 @@ class EVMSignTypedData extends BaseMethod {
13735
13747
  });
13736
13748
  }
13737
13749
  if (response.type !== 'EthereumTypedDataSignature') {
13738
- throw ERRORS.TypedError('Runtime', 'Unexpected response type');
13750
+ throw hdShared.ERRORS.TypedError('Runtime', 'Unexpected response type');
13739
13751
  }
13740
13752
  const { address, signature } = response.message;
13741
13753
  return {
@@ -13756,7 +13768,7 @@ class EVMSignTypedData extends BaseMethod {
13756
13768
  if (deviceType === 'classic' || deviceType === 'mini') {
13757
13769
  const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
13758
13770
  const supportSignTypedVersion = '2.2.0';
13759
- if (semver.lt(currentVersion, supportSignTypedVersion)) {
13771
+ if (semver__default["default"].lt(currentVersion, supportSignTypedVersion)) {
13760
13772
  return false;
13761
13773
  }
13762
13774
  }
@@ -13765,7 +13777,7 @@ class EVMSignTypedData extends BaseMethod {
13765
13777
  run() {
13766
13778
  return __awaiter(this, void 0, void 0, function* () {
13767
13779
  if (!this.device.features) {
13768
- throw ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
13780
+ throw hdShared.ERRORS.TypedError('Device_InitializeFailed', 'Device initialization failed. Please try again.');
13769
13781
  }
13770
13782
  const { addressN } = this.params;
13771
13783
  const deviceType = getDeviceType(this.device.features);
@@ -14180,7 +14192,7 @@ class NEMSignTransaction extends BaseMethod {
14180
14192
  message.supply_change = this.supplyChangeMessage(transaction);
14181
14193
  break;
14182
14194
  default:
14183
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
14195
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Unknown transaction type');
14184
14196
  }
14185
14197
  return message;
14186
14198
  };
@@ -14480,7 +14492,7 @@ class StellarSignTransaction extends BaseMethod {
14480
14492
  ]);
14481
14493
  const { transaction, networkPassphrase } = this.payload;
14482
14494
  if (!transaction.timebounds) {
14483
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'timebounds is required');
14495
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'timebounds is required');
14484
14496
  }
14485
14497
  const addressN = validatePath(this.payload.path, 3);
14486
14498
  this.params = {
@@ -14490,7 +14502,7 @@ class StellarSignTransaction extends BaseMethod {
14490
14502
  fee: transaction.fee,
14491
14503
  sequence_number: transaction.sequence,
14492
14504
  num_operations: transaction.operations.length,
14493
- memo_type: StellarMemoType.NONE,
14505
+ memo_type: hdTransport.StellarMemoType.NONE,
14494
14506
  timebounds_start: transaction.timebounds.minTime,
14495
14507
  timebounds_end: transaction.timebounds.maxTime,
14496
14508
  };
@@ -14884,27 +14896,27 @@ var ApiMethods = /*#__PURE__*/Object.freeze({
14884
14896
  function findMethod(message) {
14885
14897
  const { method } = message.payload;
14886
14898
  if (typeof method !== 'string') {
14887
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
14899
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
14888
14900
  }
14889
14901
  const MethodConstructor = ApiMethods[method];
14890
14902
  if (MethodConstructor) {
14891
14903
  return new MethodConstructor(message);
14892
14904
  }
14893
- throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
14905
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `Method ${method} is not set`);
14894
14906
  }
14895
14907
 
14896
14908
  const safeThrowError = (error) => {
14897
- if (error instanceof HardwareError) {
14909
+ if (error instanceof hdShared.HardwareError) {
14898
14910
  throw error;
14899
14911
  }
14900
14912
  else if (error.code === 'ERR_NETWORK') {
14901
- throw ERRORS.TypedError(HardwareErrorCode.BridgeNotInstalled);
14913
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeNotInstalled);
14902
14914
  }
14903
14915
  else if (error.code === 'ECONNABORTED') {
14904
- throw ERRORS.TypedError(HardwareErrorCode.BridgeTimeoutError);
14916
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError);
14905
14917
  }
14906
14918
  else {
14907
- throw ERRORS.TypedError(error);
14919
+ throw hdShared.ERRORS.TypedError(error);
14908
14920
  }
14909
14921
  };
14910
14922
 
@@ -14912,7 +14924,7 @@ const resolveAfter = (msec, value) => new Promise(resolve => {
14912
14924
  setTimeout(resolve, msec, value);
14913
14925
  });
14914
14926
 
14915
- const Log$1 = getLogger(LoggerNames.DeviceConnector);
14927
+ const Log$1 = getLogger(exports.LoggerNames.DeviceConnector);
14916
14928
  class DeviceConnector {
14917
14929
  constructor() {
14918
14930
  this.listenTimestamp = 0;
@@ -15009,7 +15021,7 @@ class DeviceConnector {
15009
15021
  }
15010
15022
  }
15011
15023
 
15012
- const Log = getLogger(LoggerNames.Core);
15024
+ const Log = getLogger(exports.LoggerNames.Core);
15013
15025
  const parseInitOptions = (method) => ({
15014
15026
  initSession: method === null || method === void 0 ? void 0 : method.payload.initSession,
15015
15027
  passphraseState: method === null || method === void 0 ? void 0 : method.payload.passphraseState,
@@ -15030,7 +15042,7 @@ let preConnectCache = {
15030
15042
  const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15031
15043
  var _a;
15032
15044
  if (!message.id || !message.payload || message.type !== IFRAME.CALL) {
15033
- return Promise.reject(ERRORS.TypedError('on call: message.id or message.payload is missing'));
15045
+ return Promise.reject(hdShared.ERRORS.TypedError('on call: message.id or message.payload is missing'));
15034
15046
  }
15035
15047
  let method;
15036
15048
  let messageResponse;
@@ -15091,26 +15103,26 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15091
15103
  const versionRange = versionRangeType !== null && versionRangeType !== void 0 ? versionRangeType : versionRangeModel;
15092
15104
  if (versionRange && device.features) {
15093
15105
  const currentVersion = getDeviceFirmwareVersion(device.features).join('.');
15094
- if (semver.valid(versionRange.min) && semver.lt(currentVersion, versionRange.min)) {
15095
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${versionRange.min}`, { current: currentVersion, require: versionRange.min }));
15106
+ if (semver__default["default"].valid(versionRange.min) && semver__default["default"].lt(currentVersion, versionRange.min)) {
15107
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${versionRange.min}`, { current: currentVersion, require: versionRange.min }));
15096
15108
  }
15097
15109
  if (versionRange.max &&
15098
- semver.valid(versionRange.max) &&
15099
- semver.gte(currentVersion, versionRange.max)) {
15100
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.CallMethodDeprecated, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`, { current: currentVersion, deprecated: versionRange.max }));
15110
+ semver__default["default"].valid(versionRange.max) &&
15111
+ semver__default["default"].gte(currentVersion, versionRange.max)) {
15112
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodDeprecated, `Device firmware version is too high, this method has been deprecated in ${versionRange.max}`, { current: currentVersion, deprecated: versionRange.max }));
15101
15113
  }
15102
15114
  }
15103
15115
  const unexpectedMode = device.hasUnexpectedMode(method.allowDeviceMode, method.requireDeviceMode);
15104
15116
  if (unexpectedMode) {
15105
15117
  if (unexpectedMode === UI_REQUEST$1.NOT_IN_BOOTLOADER) {
15106
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceUnexpectedBootloaderMode));
15118
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedBootloaderMode));
15107
15119
  }
15108
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
15120
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode));
15109
15121
  }
15110
15122
  if (method.deviceId && method.checkDeviceId) {
15111
15123
  const isSameDeviceID = device.checkDeviceId(method.deviceId);
15112
15124
  if (!isSameDeviceID) {
15113
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
15125
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckDeviceIdError));
15114
15126
  }
15115
15127
  }
15116
15128
  method.checkFirmwareRelease();
@@ -15122,7 +15134,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15122
15134
  if (device.hasUsePassphrase() && method.useDevicePassphraseState) {
15123
15135
  const support = supportNewPassphrase(device.features);
15124
15136
  if (!support.support) {
15125
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceNotSupportPassphrase, `Device not support passphrase, please update to ${support.require}`, {
15137
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportPassphrase, `Device not support passphrase, please update to ${support.require}`, {
15126
15138
  require: support.require,
15127
15139
  }));
15128
15140
  }
@@ -15130,16 +15142,16 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15130
15142
  checkPassphraseSafety(method, device.features);
15131
15143
  if (passphraseState) {
15132
15144
  DevicePool.clearDeviceCache(method.payload.connectId);
15133
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError));
15145
+ return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError));
15134
15146
  }
15135
15147
  }
15136
15148
  try {
15137
15149
  yield method.checkSafetyLevelOnTestNet();
15138
15150
  }
15139
15151
  catch (e) {
15140
- const error = e instanceof HardwareError
15152
+ const error = e instanceof hdShared.HardwareError
15141
15153
  ? e
15142
- : ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
15154
+ : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
15143
15155
  messageResponse = createResponseMessage(method.responseID, false, { error });
15144
15156
  _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.resolve(messageResponse);
15145
15157
  return;
@@ -15159,7 +15171,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15159
15171
  Log.debug('Call API - Device Run: ', device.mainId);
15160
15172
  const runOptions = Object.assign({ keepSession: method.payload.keepSession }, parseInitOptions(method));
15161
15173
  const deviceRun = () => device.run(inner, runOptions);
15162
- _callPromise = createDeferred(deviceRun);
15174
+ _callPromise = hdShared.createDeferred(deviceRun);
15163
15175
  try {
15164
15176
  return yield _callPromise.promise;
15165
15177
  }
@@ -15170,7 +15182,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
15170
15182
  }
15171
15183
  catch (error) {
15172
15184
  messageResponse = createResponseMessage(method.responseID, false, { error });
15173
- _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(ERRORS.TypedError(HardwareErrorCode.CallMethodError, error.message));
15185
+ _callPromise === null || _callPromise === void 0 ? void 0 : _callPromise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodError, error.message));
15174
15186
  Log.debug('Call API - Run Error: ', error);
15175
15187
  }
15176
15188
  finally {
@@ -15209,7 +15221,7 @@ function initDeviceList(method) {
15209
15221
  }
15210
15222
  function initDevice(method) {
15211
15223
  if (!_deviceList) {
15212
- throw ERRORS.TypedError(HardwareErrorCode.DeviceListNotInitialized);
15224
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
15213
15225
  }
15214
15226
  let device;
15215
15227
  const allDevices = _deviceList.allDevices();
@@ -15220,17 +15232,17 @@ function initDevice(method) {
15220
15232
  [device] = allDevices;
15221
15233
  }
15222
15234
  else if (allDevices.length > 1) {
15223
- throw ERRORS.TypedError(HardwareErrorCode.SelectDevice);
15235
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.SelectDevice);
15224
15236
  }
15225
15237
  if (!device) {
15226
- throw ERRORS.TypedError(HardwareErrorCode.DeviceNotFound);
15238
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
15227
15239
  }
15228
15240
  device.deviceConnector = _connector;
15229
15241
  return device;
15230
15242
  }
15231
15243
  function initDeviceForBle(method) {
15232
15244
  if (!method.connectId && !_deviceList) {
15233
- throw ERRORS.TypedError(HardwareErrorCode.DeviceListNotInitialized);
15245
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceListNotInitialized);
15234
15246
  }
15235
15247
  if (!method.connectId) {
15236
15248
  return initDevice(method);
@@ -15257,14 +15269,14 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
15257
15269
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
15258
15270
  if (!pollingState[pollingId]) {
15259
15271
  Log.debug('EnsureConnected function stop, polling id: ', pollingId);
15260
- reject(ERRORS.TypedError(HardwareErrorCode.PollingStop));
15272
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingStop));
15261
15273
  return;
15262
15274
  }
15263
15275
  if (timer) {
15264
15276
  clearTimeout(timer);
15265
15277
  }
15266
15278
  timer = setTimeout(() => {
15267
- reject(ERRORS.TypedError(HardwareErrorCode.PollingTimeout));
15279
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.PollingTimeout));
15268
15280
  }, TIME_OUT);
15269
15281
  tryCount += 1;
15270
15282
  Log.debug('EnsureConnected function try count: ', tryCount, ' poll interval time: ', time);
@@ -15273,12 +15285,12 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
15273
15285
  }
15274
15286
  catch (error) {
15275
15287
  Log.debug('device list error: ', error);
15276
- if ([HardwareErrorCode.BridgeNotInstalled, HardwareErrorCode.BridgeTimeoutError].includes(error.errorCode)) {
15288
+ if ([hdShared.HardwareErrorCode.BridgeNotInstalled, hdShared.HardwareErrorCode.BridgeTimeoutError].includes(error.errorCode)) {
15277
15289
  _deviceList = undefined;
15278
15290
  reject(error);
15279
15291
  return;
15280
15292
  }
15281
- if (error.errorCode === HardwareErrorCode.TransportNotConfigured) {
15293
+ if (error.errorCode === hdShared.HardwareErrorCode.TransportNotConfigured) {
15282
15294
  yield TransportManager.configure();
15283
15295
  }
15284
15296
  }
@@ -15306,12 +15318,12 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
15306
15318
  catch (error) {
15307
15319
  Log.debug('device error: ', error);
15308
15320
  if ([
15309
- HardwareErrorCode.BlePermissionError,
15310
- HardwareErrorCode.BleLocationError,
15311
- HardwareErrorCode.BleDeviceNotBonded,
15312
- HardwareErrorCode.BleCharacteristicNotifyError,
15313
- HardwareErrorCode.BleWriteCharacteristicError,
15314
- HardwareErrorCode.BleAlreadyConnected,
15321
+ hdShared.HardwareErrorCode.BlePermissionError,
15322
+ hdShared.HardwareErrorCode.BleLocationError,
15323
+ hdShared.HardwareErrorCode.BleDeviceNotBonded,
15324
+ hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
15325
+ hdShared.HardwareErrorCode.BleWriteCharacteristicError,
15326
+ hdShared.HardwareErrorCode.BleAlreadyConnected,
15315
15327
  ].includes(error.errorCode)) {
15316
15328
  reject(error);
15317
15329
  return;
@@ -15322,7 +15334,7 @@ const ensureConnected = (method, pollingId) => __awaiter(void 0, void 0, void 0,
15322
15334
  clearTimeout(timer);
15323
15335
  }
15324
15336
  Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
15325
- reject(ERRORS.TypedError(HardwareErrorCode.DeviceNotFound));
15337
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound));
15326
15338
  return;
15327
15339
  }
15328
15340
  return setTimeout(() => resolve(poll(time * 1.5)), time);
@@ -15356,11 +15368,11 @@ const checkPassphraseSafety = (method, features) => {
15356
15368
  return;
15357
15369
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
15358
15370
  DevicePool.clearDeviceCache(method.payload.connectId);
15359
- throw ERRORS.TypedError(HardwareErrorCode.DeviceOpenedPassphrase);
15371
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
15360
15372
  }
15361
15373
  if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === false && method.payload.passphraseState) {
15362
15374
  DevicePool.clearDeviceCache(method.payload.connectId);
15363
- throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
15375
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotOpenedPassphrase);
15364
15376
  }
15365
15377
  };
15366
15378
  const cleanup = () => {
@@ -15422,7 +15434,7 @@ const postMessage = (message) => {
15422
15434
  _core.emit(CORE_EVENT, message);
15423
15435
  };
15424
15436
  const createUiPromise = (promiseEvent, device) => {
15425
- const uiPromise = createDeferred(promiseEvent, device);
15437
+ const uiPromise = hdShared.createDeferred(promiseEvent, device);
15426
15438
  _uiPromises.push(uiPromise);
15427
15439
  return uiPromise;
15428
15440
  };
@@ -15510,4 +15522,57 @@ const HardwareSdk = ({ init, call, dispose, eventEmitter, uiResponse, cancel, })
15510
15522
  cancel,
15511
15523
  });
15512
15524
 
15513
- export { CORE_EVENT, Core, DEFAULT_PRIORITY, DEVICE, DEVICE_EVENT, DataManager, FIRMWARE, FIRMWARE_EVENT, IFRAME, LOG, LOG_EVENT, LoggerNames, RESPONSE_EVENT, UI_EVENT, UI_REQUEST$1 as UI_REQUEST, UI_RESPONSE, corsValidator, createDeviceMessage, createErrorMessage, createFirmwareMessage, createIFrameMessage, createLogMessage, createResponseMessage, createUiMessage, createUiResponse, HardwareSdk as default, enableLog, getDeviceLabel, getDeviceType, getDeviceTypeByBleName, getDeviceTypeByDeviceId, getDeviceUUID, getEnv, getHDPath, getLog, getLogger, getScriptType, getTimeStamp, httpRequest, init as initCore, isValidVersionArray, isValidVersionString, normalizeVersionArray, parseConnectSettings, parseMessage, patchFeatures, safeThrowError, setLoggerPostMessage, versionCompare, versionSplit };
15525
+ Object.defineProperty(exports, 'PROTO', {
15526
+ enumerable: true,
15527
+ get: function () { return hdTransport.Messages; }
15528
+ });
15529
+ exports.CORE_EVENT = CORE_EVENT;
15530
+ exports.Core = Core;
15531
+ exports.DEFAULT_PRIORITY = DEFAULT_PRIORITY;
15532
+ exports.DEVICE = DEVICE;
15533
+ exports.DEVICE_EVENT = DEVICE_EVENT;
15534
+ exports.DataManager = DataManager;
15535
+ exports.FIRMWARE = FIRMWARE;
15536
+ exports.FIRMWARE_EVENT = FIRMWARE_EVENT;
15537
+ exports.IFRAME = IFRAME;
15538
+ exports.LOG = LOG;
15539
+ exports.LOG_EVENT = LOG_EVENT;
15540
+ exports.RESPONSE_EVENT = RESPONSE_EVENT;
15541
+ exports.UI_EVENT = UI_EVENT;
15542
+ exports.UI_REQUEST = UI_REQUEST$1;
15543
+ exports.UI_RESPONSE = UI_RESPONSE;
15544
+ exports.corsValidator = corsValidator;
15545
+ exports.createDeviceMessage = createDeviceMessage;
15546
+ exports.createErrorMessage = createErrorMessage;
15547
+ exports.createFirmwareMessage = createFirmwareMessage;
15548
+ exports.createIFrameMessage = createIFrameMessage;
15549
+ exports.createLogMessage = createLogMessage;
15550
+ exports.createResponseMessage = createResponseMessage;
15551
+ exports.createUiMessage = createUiMessage;
15552
+ exports.createUiResponse = createUiResponse;
15553
+ exports["default"] = HardwareSdk;
15554
+ exports.enableLog = enableLog;
15555
+ exports.getDeviceLabel = getDeviceLabel;
15556
+ exports.getDeviceType = getDeviceType;
15557
+ exports.getDeviceTypeByBleName = getDeviceTypeByBleName;
15558
+ exports.getDeviceTypeByDeviceId = getDeviceTypeByDeviceId;
15559
+ exports.getDeviceUUID = getDeviceUUID;
15560
+ exports.getEnv = getEnv;
15561
+ exports.getHDPath = getHDPath;
15562
+ exports.getLog = getLog;
15563
+ exports.getLogger = getLogger;
15564
+ exports.getSDKVersion = getSDKVersion;
15565
+ exports.getScriptType = getScriptType;
15566
+ exports.getTimeStamp = getTimeStamp;
15567
+ exports.httpRequest = httpRequest;
15568
+ exports.initCore = init;
15569
+ exports.isValidVersionArray = isValidVersionArray;
15570
+ exports.isValidVersionString = isValidVersionString;
15571
+ exports.normalizeVersionArray = normalizeVersionArray;
15572
+ exports.parseConnectSettings = parseConnectSettings;
15573
+ exports.parseMessage = parseMessage;
15574
+ exports.patchFeatures = patchFeatures;
15575
+ exports.safeThrowError = safeThrowError;
15576
+ exports.setLoggerPostMessage = setLoggerPostMessage;
15577
+ exports.versionCompare = versionCompare;
15578
+ exports.versionSplit = versionSplit;