@onekeyfe/hd-core 1.2.0-alpha.58 → 1.2.0-alpha.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/__tests__/DeviceCommands.test.ts +5 -15
  2. package/__tests__/device-pool-state.test.ts +22 -0
  3. package/__tests__/device-state-mapper.test.ts +12 -0
  4. package/__tests__/device-utils.test.ts +48 -1
  5. package/__tests__/deviceSettings.test.ts +10 -0
  6. package/__tests__/deviceUploadNft.test.ts +4 -28
  7. package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
  8. package/__tests__/protocol-v2-resources.test.ts +28 -13
  9. package/__tests__/protocol-v2-unlock-policy.test.ts +34 -0
  10. package/__tests__/protocol-v2.test.ts +159 -137
  11. package/__tests__/tron-sign-message-init.test.ts +2 -2
  12. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  13. package/dist/api/FirmwareUpdateV4.d.ts +4 -3
  14. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  15. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  16. package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
  17. package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
  18. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
  19. package/dist/api/polkadot/networks.d.ts +1 -1
  20. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  21. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  22. package/dist/api/solana/SolSignMessage.d.ts +1 -1
  23. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
  24. package/dist/api/solana/SolSignTransaction.d.ts +2 -2
  25. package/dist/api/sui/SuiGetAddress.d.ts +1 -1
  26. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
  27. package/dist/api/sui/SuiSignMessage.d.ts +1 -1
  28. package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
  29. package/dist/api/ton/TonGetAddress.d.ts +1 -1
  30. package/dist/api/ton/TonSignMessage.d.ts +1 -1
  31. package/dist/api/ton/TonSignProof.d.ts +1 -1
  32. package/dist/api/tron/TronSignMessage.d.ts +2 -2
  33. package/dist/api/tron/TronSignTransaction.d.ts +1 -1
  34. package/dist/data-manager/DataManager.d.ts +7 -5
  35. package/dist/data-manager/DataManager.d.ts.map +1 -1
  36. package/dist/device/Device.d.ts.map +1 -1
  37. package/dist/device/DeviceCommands.d.ts.map +1 -1
  38. package/dist/device/DevicePool.d.ts.map +1 -1
  39. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
  40. package/dist/index.d.ts +44 -34
  41. package/dist/index.js +231 -168
  42. package/dist/protocols/protocol-v2/resources.d.ts +2 -2
  43. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  44. package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -1
  45. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  46. package/dist/types/api/firmwareUpdate.d.ts +3 -2
  47. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  48. package/dist/types/device.d.ts +2 -2
  49. package/dist/types/device.d.ts.map +1 -1
  50. package/dist/types/settings.d.ts +22 -14
  51. package/dist/types/settings.d.ts.map +1 -1
  52. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  53. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  54. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  55. package/dist/utils/deviceSettings.d.ts.map +1 -1
  56. package/package.json +4 -4
  57. package/src/api/CheckAllFirmwareRelease.ts +7 -5
  58. package/src/api/FirmwareUpdateV4.ts +115 -102
  59. package/src/api/OpenWalletSession.ts +1 -0
  60. package/src/api/kaspa/KaspaGetAddress.ts +1 -1
  61. package/src/api/kaspa/KaspaSignTransaction.ts +1 -1
  62. package/src/api/polkadot/networks.ts +3 -3
  63. package/src/api/protocol-v2/DeviceUploadNft.ts +7 -12
  64. package/src/api/protocol-v2/helpers.ts +0 -1
  65. package/src/api/solana/SolSignMessage.ts +1 -1
  66. package/src/api/solana/SolSignOffchainMessage.ts +1 -1
  67. package/src/api/solana/SolSignTransaction.ts +2 -2
  68. package/src/api/sui/SuiGetAddress.ts +1 -1
  69. package/src/api/sui/SuiGetPublicKey.ts +1 -1
  70. package/src/api/sui/SuiSignMessage.ts +1 -1
  71. package/src/api/sui/SuiSignTransaction.ts +1 -1
  72. package/src/api/ton/TonGetAddress.ts +1 -1
  73. package/src/api/ton/TonSignMessage.ts +1 -1
  74. package/src/api/ton/TonSignProof.ts +1 -1
  75. package/src/api/tron/TronSignMessage.ts +2 -2
  76. package/src/api/tron/TronSignTransaction.ts +1 -1
  77. package/src/data-manager/DataManager.ts +28 -9
  78. package/src/device/Device.ts +15 -6
  79. package/src/device/DeviceCommands.ts +13 -10
  80. package/src/device/DevicePool.ts +17 -8
  81. package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
  82. package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
  83. package/src/protocols/protocol-v2/resources.ts +44 -13
  84. package/src/types/api/checkAllFirmwareRelease.ts +1 -1
  85. package/src/types/api/firmwareUpdate.ts +5 -5
  86. package/src/types/device.ts +12 -3
  87. package/src/types/settings.ts +30 -21
  88. package/src/utils/deviceFeaturesCompat.ts +5 -0
  89. package/src/utils/deviceFeaturesUtils.ts +6 -3
  90. package/src/utils/deviceInfoUtils.ts +2 -0
  91. package/src/utils/deviceSettings.ts +3 -0
package/dist/index.js CHANGED
@@ -1410,6 +1410,7 @@ const DeviceModelToTypes = {
1410
1410
  hdShared.EDeviceType.Mini,
1411
1411
  ],
1412
1412
  model_touch: [hdShared.EDeviceType.Touch, hdShared.EDeviceType.Pro],
1413
+ model_pro2: [hdShared.EDeviceType.Pro2, hdShared.EDeviceType.Neo],
1413
1414
  model_classic: [hdShared.EDeviceType.Classic, hdShared.EDeviceType.Classic1s, hdShared.EDeviceType.ClassicPure],
1414
1415
  model_classic1s: [hdShared.EDeviceType.Classic1s, hdShared.EDeviceType.ClassicPure],
1415
1416
  };
@@ -1420,7 +1421,8 @@ const DeviceTypeToModels = {
1420
1421
  [hdShared.EDeviceType.Mini]: ['model_mini'],
1421
1422
  [hdShared.EDeviceType.Touch]: ['model_touch'],
1422
1423
  [hdShared.EDeviceType.Pro]: ['model_touch'],
1423
- [hdShared.EDeviceType.Pro2]: [],
1424
+ [hdShared.EDeviceType.Pro2]: ['model_pro2'],
1425
+ [hdShared.EDeviceType.Neo]: ['model_pro2'],
1424
1426
  [hdShared.EDeviceType.Unknown]: [],
1425
1427
  };
1426
1428
 
@@ -1436,7 +1438,7 @@ const resolveDeviceSerialNo = (features) => {
1436
1438
  return ((_a = firstNonEmptyString(compatible.serialNo, compatible.onekey_serial_no, compatible.onekey_serial, compatible.serial_no)) !== null && _a !== void 0 ? _a : '');
1437
1439
  };
1438
1440
  const resolveDeviceType = (features) => {
1439
- var _a, _b, _c, _d;
1441
+ var _a, _b, _c, _d, _e;
1440
1442
  if (!features || typeof features !== 'object') {
1441
1443
  return hdShared.EDeviceType.Unknown;
1442
1444
  }
@@ -1457,12 +1459,17 @@ const resolveDeviceType = (features) => {
1457
1459
  return hdShared.EDeviceType.Pro;
1458
1460
  case 'PRO2':
1459
1461
  return hdShared.EDeviceType.Pro2;
1462
+ case 'NEO':
1463
+ return hdShared.EDeviceType.Neo;
1460
1464
  case 'PURE':
1461
1465
  return hdShared.EDeviceType.ClassicPure;
1462
1466
  }
1463
1467
  if (((_b = compatible.model) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase()) === hdShared.EDeviceType.Pro2) {
1464
1468
  return hdShared.EDeviceType.Pro2;
1465
1469
  }
1470
+ if (((_c = compatible.model) === null || _c === void 0 ? void 0 : _c.toString().toLowerCase()) === hdShared.EDeviceType.Neo) {
1471
+ return hdShared.EDeviceType.Neo;
1472
+ }
1466
1473
  const serialNo = resolveDeviceSerialNo(features);
1467
1474
  const prefix = serialNo.slice(0, 2).toLowerCase();
1468
1475
  if (prefix === 'bi' || prefix === 'cl')
@@ -1477,11 +1484,11 @@ const resolveDeviceType = (features) => {
1477
1484
  return hdShared.EDeviceType.Pro;
1478
1485
  if (prefix === 'p2')
1479
1486
  return hdShared.EDeviceType.Pro2;
1480
- const bootloaderMode = (_c = compatible.bootloaderMode) !== null && _c !== void 0 ? _c : compatible.bootloader_mode;
1487
+ const bootloaderMode = (_d = compatible.bootloaderMode) !== null && _d !== void 0 ? _d : compatible.bootloader_mode;
1481
1488
  if (!serialNo && bootloaderMode === true && compatible.model === '1') {
1482
1489
  return hdShared.EDeviceType.Classic;
1483
1490
  }
1484
- return (_d = compatible.deviceType) !== null && _d !== void 0 ? _d : hdShared.EDeviceType.Unknown;
1491
+ return (_e = compatible.deviceType) !== null && _e !== void 0 ? _e : hdShared.EDeviceType.Unknown;
1485
1492
  };
1486
1493
  const resolveDeviceFirmwareType = (features) => {
1487
1494
  if (!features) {
@@ -1555,6 +1562,8 @@ const getDeviceTypeByBleName = (name) => {
1555
1562
  return hdShared.EDeviceType.Touch;
1556
1563
  if (/\bPro\s*2\b/i.test(name) || /^Pro2/i.test(name))
1557
1564
  return hdShared.EDeviceType.Pro2;
1565
+ if (/\bNeo\b/i.test(name) || /^Neo/i.test(name))
1566
+ return hdShared.EDeviceType.Neo;
1558
1567
  if (/\bPro\b/i.test(name) || /^Pro/i.test(name))
1559
1568
  return hdShared.EDeviceType.Pro;
1560
1569
  return hdShared.EDeviceType.Unknown;
@@ -1586,6 +1595,7 @@ const getMethodVersionRange = (features, getVersionRange) => {
1586
1595
  return versionRange;
1587
1596
  }
1588
1597
  const modelFallbacks = [
1598
+ 'model_pro2',
1589
1599
  'model_classic1s',
1590
1600
  'model_classic',
1591
1601
  'model_mini',
@@ -39632,24 +39642,39 @@ function validateBootResources(value) {
39632
39642
  if (resource.required !== false) {
39633
39643
  throw new Error('Invalid Pro2 boot resources required flag: expected false');
39634
39644
  }
39635
- if (resource.target !== 'CRATE') {
39636
- throw new Error('Invalid Pro2 boot resources target: expected CRATE');
39645
+ if (resource.target !== 'RES') {
39646
+ throw new Error('Invalid Pro2 boot resources target: expected RES');
39637
39647
  }
39638
- if (typeof resource.url !== 'string' || !resource.url.startsWith('https://')) {
39639
- throw new Error('Invalid Pro2 boot resources url');
39648
+ if (resource.manifestUrl !== undefined &&
39649
+ (typeof resource.manifestUrl !== 'string' || !resource.manifestUrl.startsWith('https://'))) {
39650
+ throw new Error('Invalid Pro2 boot resources manifestUrl');
39640
39651
  }
39641
- if (!Number.isSafeInteger(resource.size) || Number(resource.size) <= 0) {
39642
- throw new Error('Invalid Pro2 boot resources size');
39652
+ if (!Array.isArray(resource.files) || resource.files.length === 0) {
39653
+ throw new Error('Invalid Pro2 boot resources files');
39643
39654
  }
39644
- return {
39645
- required: false,
39646
- target: 'CRATE',
39647
- url: resource.url,
39648
- size: Number(resource.size),
39649
- fileHash: normalizeHex$1(resource.fileHash, SHA256_HEX_LENGTH, 'boot fileHash'),
39650
- payloadHash: normalizeHex$1(resource.payloadHash, SHA3_512_HEX_LENGTH, 'boot payloadHash'),
39651
- headerHash: normalizeHex$1(resource.headerHash, SHA3_512_HEX_LENGTH, 'boot headerHash'),
39652
- };
39655
+ const files = resource.files.map((value, index) => {
39656
+ if (!value || typeof value !== 'object') {
39657
+ throw new Error(`Invalid Pro2 boot resource file at files[${index}]`);
39658
+ }
39659
+ const file = value;
39660
+ if (typeof file.url !== 'string' || !file.url.startsWith('https://')) {
39661
+ throw new Error(`Invalid Pro2 boot resource url at files[${index}]`);
39662
+ }
39663
+ if (typeof file.devicePath !== 'string' ||
39664
+ !file.devicePath.startsWith('vol0:/') ||
39665
+ file.devicePath.includes('..') ||
39666
+ file.devicePath.includes('\\\\')) {
39667
+ throw new Error(`Invalid Pro2 boot resource devicePath at files[${index}]`);
39668
+ }
39669
+ if (!Number.isSafeInteger(file.size) || Number(file.size) <= 0) {
39670
+ throw new Error(`Invalid Pro2 boot resource size at files[${index}]`);
39671
+ }
39672
+ return Object.assign(Object.assign({}, (typeof file.name === 'string' && file.name ? { name: file.name } : undefined)), { url: file.url, devicePath: file.devicePath, size: Number(file.size), fileHash: normalizeHex$1(file.fileHash, SHA256_HEX_LENGTH, `boot files[${index}].fileHash`) });
39673
+ });
39674
+ if (new Set(files.map(file => file.devicePath)).size !== files.length) {
39675
+ throw new Error('Invalid Pro2 boot resources files: duplicate devicePath');
39676
+ }
39677
+ return Object.assign(Object.assign({ required: false, target: 'RES' }, (resource.manifestUrl ? { manifestUrl: resource.manifestUrl } : undefined)), { files });
39653
39678
  }
39654
39679
  function parseProtocolV2Resources(value) {
39655
39680
  if (value === undefined)
@@ -39768,7 +39793,7 @@ class DataManager {
39768
39793
  return enrichedData;
39769
39794
  }
39770
39795
  static load(settings) {
39771
- var _b;
39796
+ var _b, _c;
39772
39797
  return __awaiter(this, void 0, void 0, function* () {
39773
39798
  this.settings = settings;
39774
39799
  this.protocolV2ResourcesConfigError = undefined;
@@ -39813,8 +39838,11 @@ class DataManager {
39813
39838
  }
39814
39839
  if (data) {
39815
39840
  let pro2Resources;
39841
+ let neoResources;
39842
+ this.protocolV2ResourcesConfigError = undefined;
39816
39843
  try {
39817
39844
  pro2Resources = parseProtocolV2Resources((_b = data.pro2) === null || _b === void 0 ? void 0 : _b.resources);
39845
+ neoResources = parseProtocolV2Resources((_c = data.neo) === null || _c === void 0 ? void 0 : _c.resources);
39818
39846
  }
39819
39847
  catch (error) {
39820
39848
  this.protocolV2ResourcesConfigError =
@@ -39822,7 +39850,9 @@ class DataManager {
39822
39850
  Log$j.warn('[DataConfig] Ignoring invalid Pro2 resources config:', error);
39823
39851
  }
39824
39852
  const enrichedPro2Config = this.enrichFirmwareReleaseInfo(data.pro2);
39853
+ const enrichedNeoConfig = this.enrichFirmwareReleaseInfo(data.neo);
39825
39854
  const pro2Config = __rest(enrichedPro2Config, ["resources"]);
39855
+ const neoConfig = __rest(enrichedNeoConfig, ["resources"]);
39826
39856
  Log$j.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
39827
39857
  this.deviceMap = {
39828
39858
  [hdShared.EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
@@ -39832,6 +39862,7 @@ class DataManager {
39832
39862
  [hdShared.EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
39833
39863
  [hdShared.EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
39834
39864
  [hdShared.EDeviceType.Pro2]: Object.assign(Object.assign({}, pro2Config), (pro2Resources ? { resources: pro2Resources } : undefined)),
39865
+ [hdShared.EDeviceType.Neo]: Object.assign(Object.assign({}, neoConfig), (neoResources ? { resources: neoResources } : undefined)),
39835
39866
  };
39836
39867
  this.assets = {
39837
39868
  bridge: data.bridge,
@@ -39859,7 +39890,7 @@ class DataManager {
39859
39890
  }
39860
39891
  });
39861
39892
  }
39862
- static forceReloadData() {
39893
+ static forceReloadData({ requireResources = false, } = {}) {
39863
39894
  return __awaiter(this, void 0, void 0, function* () {
39864
39895
  if (!this.settings) {
39865
39896
  throw new Error('Remote config settings are not initialized');
@@ -39868,19 +39899,19 @@ class DataManager {
39868
39899
  if (!loaded) {
39869
39900
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, 'Unable to refresh the latest remote config');
39870
39901
  }
39871
- if (this.protocolV2ResourcesConfigError) {
39872
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NetworkError, `Invalid Pro2 resources config: ${this.protocolV2ResourcesConfigError.message}`);
39902
+ if (requireResources && this.protocolV2ResourcesConfigError) {
39903
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, `Invalid Pro2 resources config: ${this.protocolV2ResourcesConfigError.message}`);
39873
39904
  }
39874
39905
  this.lastCheckTimestamp = getTimeStamp();
39875
39906
  });
39876
39907
  }
39877
- static getProtocolV2Resources() {
39908
+ static getProtocolV2Resources(deviceType = hdShared.EDeviceType.Pro2) {
39878
39909
  var _b, _c;
39879
- return (_c = (_b = this.deviceMap[hdShared.EDeviceType.Pro2]) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.stable;
39910
+ return (_c = (_b = this.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.stable;
39880
39911
  }
39881
- static getProtocolV2BootResources() {
39912
+ static getProtocolV2BootResources(deviceType = hdShared.EDeviceType.Pro2) {
39882
39913
  var _b, _c;
39883
- return (_c = (_b = this.deviceMap[hdShared.EDeviceType.Pro2]) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.boot;
39914
+ return (_c = (_b = this.deviceMap[deviceType]) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.boot;
39884
39915
  }
39885
39916
  static getProtobufMessages(schema = 'v1CurrentSchema') {
39886
39917
  return this.messages[schema];
@@ -39920,6 +39951,10 @@ DataManager.deviceMap = {
39920
39951
  firmware: [],
39921
39952
  ble: [],
39922
39953
  },
39954
+ [hdShared.EDeviceType.Neo]: {
39955
+ firmware: [],
39956
+ ble: [],
39957
+ },
39923
39958
  [hdShared.EDeviceType.ClassicPure]: {
39924
39959
  firmware: [],
39925
39960
  ble: [],
@@ -40784,7 +40819,8 @@ const supportInputPinOnSoftware = (features) => {
40784
40819
  const deviceType = getDeviceType(features);
40785
40820
  if (deviceType === hdShared.EDeviceType.Touch ||
40786
40821
  deviceType === hdShared.EDeviceType.Pro ||
40787
- deviceType === hdShared.EDeviceType.Pro2) {
40822
+ deviceType === hdShared.EDeviceType.Pro2 ||
40823
+ deviceType === hdShared.EDeviceType.Neo) {
40788
40824
  return { support: false };
40789
40825
  }
40790
40826
  const currentVersion = getDeviceFirmwareVersion(features).join('.');
@@ -40817,7 +40853,8 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
40817
40853
  const { passphraseState, newSession, unlockedAttachPin } = yield getPassphraseState(device, Object.assign({}, options));
40818
40854
  const isModeT = deviceType === hdShared.EDeviceType.Touch ||
40819
40855
  deviceType === hdShared.EDeviceType.Pro ||
40820
- deviceType === hdShared.EDeviceType.Pro2;
40856
+ deviceType === hdShared.EDeviceType.Pro2 ||
40857
+ deviceType === hdShared.EDeviceType.Neo;
40821
40858
  const needRefreshWithPassphrase = passphraseState && device.getCurrentPassphraseProtection() !== true;
40822
40859
  const needRefreshWithLocked = isModeT && locked;
40823
40860
  if (needRefreshWithLocked || needRefreshWithPassphrase) {
@@ -41250,6 +41287,7 @@ const getLanguageConfig = (deviceType) => {
41250
41287
  keys = Object.keys(LANGUAGE_LABELS);
41251
41288
  break;
41252
41289
  case hdShared.EDeviceType.Pro2:
41290
+ case hdShared.EDeviceType.Neo:
41253
41291
  return PRO2_LANGUAGE_OPTIONS.map(option => (Object.assign({}, option)));
41254
41292
  default:
41255
41293
  keys = [];
@@ -41278,6 +41316,7 @@ const getAutoLockOptions = (deviceType, protocol) => {
41278
41316
  case hdShared.EDeviceType.Touch:
41279
41317
  case hdShared.EDeviceType.Pro:
41280
41318
  case hdShared.EDeviceType.Pro2:
41319
+ case hdShared.EDeviceType.Neo:
41281
41320
  return withNever([30000, 60000, 120000, 300000, 600000, 1800000], protocol);
41282
41321
  default:
41283
41322
  return [];
@@ -41295,6 +41334,7 @@ const getAutoShutDownOptions = (deviceType, protocol) => {
41295
41334
  case hdShared.EDeviceType.Pro:
41296
41335
  return withNever([60000, 120000, 300000, 600000], protocol);
41297
41336
  case hdShared.EDeviceType.Pro2:
41337
+ case hdShared.EDeviceType.Neo:
41298
41338
  return withNever([60000, 120000, 300000, 600000, 1800000], protocol);
41299
41339
  default:
41300
41340
  return [];
@@ -41997,7 +42037,7 @@ class DevicePool extends events.exports {
41997
42037
  const device = this.devicesCache[connectId];
41998
42038
  if (device) {
41999
42039
  const exist = descriptorList.find(d => d.path === device.originalDescriptor.path);
42000
- if (exist) {
42040
+ if (exist && !(initOptions === null || initOptions === void 0 ? void 0 : initOptions.forceProtocolDetection)) {
42001
42041
  device.updateDescriptor(exist, true);
42002
42042
  yield this._refreshRuntimeState(device, initOptions);
42003
42043
  devices[connectId] = device;
@@ -42048,13 +42088,20 @@ class DevicePool extends events.exports {
42048
42088
  }
42049
42089
  static _createDevice(descriptor, initOptions) {
42050
42090
  return __awaiter(this, void 0, void 0, function* () {
42051
- let device = this.getDeviceByPath(descriptor.path);
42052
- if (!device) {
42053
- device = Device.fromDescriptor(descriptor);
42091
+ const cachedDevice = this.getDeviceByPath(descriptor.path);
42092
+ const forceProtocolDetection = (initOptions === null || initOptions === void 0 ? void 0 : initOptions.forceProtocolDetection) === true;
42093
+ const isNewDevice = !cachedDevice;
42094
+ const device = cachedDevice !== null && cachedDevice !== void 0 ? cachedDevice : Device.fromDescriptor(descriptor);
42095
+ if (isNewDevice || forceProtocolDetection) {
42054
42096
  device.deviceConnector = this.connector;
42055
- yield device.connect(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol, {
42056
- forceProtocolDetection: initOptions === null || initOptions === void 0 ? void 0 : initOptions.forceProtocolDetection,
42057
- });
42097
+ if (forceProtocolDetection && !isNewDevice) {
42098
+ yield device.acquire(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol, { forceProtocolDetection: true });
42099
+ }
42100
+ else {
42101
+ yield device.connect(initOptions === null || initOptions === void 0 ? void 0 : initOptions.connectProtocol, {
42102
+ forceProtocolDetection: initOptions === null || initOptions === void 0 ? void 0 : initOptions.forceProtocolDetection,
42103
+ });
42104
+ }
42058
42105
  try {
42059
42106
  yield device.initialize(initOptions);
42060
42107
  if ((initOptions === null || initOptions === void 0 ? void 0 : initOptions.refreshRuntimeState) && device.isProtocolV2()) {
@@ -42350,7 +42397,16 @@ const DEVICE_SESSION_CALLS = new Set([
42350
42397
  'DeviceSessionAskPin',
42351
42398
  'DeviceSessionAskPassphrase',
42352
42399
  ]);
42353
- const PROTOCOL_V2_ACTION_CANCELLED_SUBCODE = 1;
42400
+ const DEVICE_CONTROL_CALLS = new Set([
42401
+ 'DeviceReboot',
42402
+ 'DeviceSettingsGet',
42403
+ 'DeviceSettingsSet',
42404
+ 'DeviceSettingsPageShow',
42405
+ 'DeviceCertificateWrite',
42406
+ 'DeviceCertificateRead',
42407
+ 'DeviceCertificateSign',
42408
+ 'DeviceMiscUsbMscControl',
42409
+ ]);
42354
42410
  const isProtocolV2ActionCancelledMessage = (message) => /^(?:cancel(?:led|ed)(?: on device)?|confirm dismissed|user cancel(?:led|ed)(?:\s+.*)?)$/i.test(message);
42355
42411
  function shouldReduceDebugForCall(type) {
42356
42412
  return HIGH_VOLUME_DEBUG_CALLS.has(type);
@@ -42670,10 +42726,8 @@ class DeviceCommands {
42670
42726
  if (code === 'Failure_ProcessError') {
42671
42727
  const normalizedMessage = (_a = message === null || message === void 0 ? void 0 : message.trim()) !== null && _a !== void 0 ? _a : '';
42672
42728
  const isProtocolV2ActionCancelledFailure = this.device.isProtocolV2() && isProtocolV2ActionCancelledMessage(normalizedMessage);
42673
- const isProtocolV2ActionCancelledSubcode = this.device.isProtocolV2() && subcode === PROTOCOL_V2_ACTION_CANCELLED_SUBCODE;
42674
42729
  const isProtocolV2DeviceBusyFailure = this.device.isProtocolV2() &&
42675
- callType.startsWith('Device') &&
42676
- !DEVICE_SESSION_CALLS.has(callType) &&
42730
+ DEVICE_CONTROL_CALLS.has(callType) &&
42677
42731
  subcode === hdTransport.DeviceErrorCode.DeviceError_Busy;
42678
42732
  const isLegacyProtocolV2LockedFailure = this.device.isProtocolV2() && /^device (?:is )?locked$/i.test(normalizedMessage);
42679
42733
  if (DEVICE_SESSION_CALLS.has(callType) &&
@@ -42732,8 +42786,8 @@ class DeviceCommands {
42732
42786
  firmwareMessage: message,
42733
42787
  });
42734
42788
  }
42735
- else if (subcode === hdTransport.DeviceErrorCode.DeviceError_ActionCancelled ||
42736
- isProtocolV2ActionCancelledSubcode ||
42789
+ else if ((DEVICE_CONTROL_CALLS.has(callType) &&
42790
+ subcode === hdTransport.DeviceErrorCode.DeviceError_ActionCancelled) ||
42737
42791
  isProtocolV2ActionCancelledFailure) {
42738
42792
  error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.ActionCancelled, message, {
42739
42793
  failureCode: code,
@@ -42948,6 +43002,9 @@ const resolveProtocolV2DeviceIdentity = (deviceType) => {
42948
43002
  case hdTransport.DeviceType.PRO2:
42949
43003
  case 'PRO2':
42950
43004
  return { deviceType: hdShared.EDeviceType.Pro2, model: 'pro2' };
43005
+ case hdTransport.DeviceType.NEO:
43006
+ case 'NEO':
43007
+ return { deviceType: hdShared.EDeviceType.Neo, model: 'neo' };
42951
43008
  default:
42952
43009
  return { deviceType: hdShared.EDeviceType.Unknown, model: null };
42953
43010
  }
@@ -44110,6 +44167,7 @@ class Device extends events.exports {
44110
44167
  if (versionRange)
44111
44168
  return versionRange;
44112
44169
  const modelFallbacks = [
44170
+ 'model_pro2',
44113
44171
  'model_classic1s',
44114
44172
  'model_classic',
44115
44173
  'model_mini',
@@ -44128,7 +44186,8 @@ class Device extends events.exports {
44128
44186
  const deviceType = this.getCurrentDeviceType();
44129
44187
  if (deviceType === hdShared.EDeviceType.Touch ||
44130
44188
  deviceType === hdShared.EDeviceType.Pro ||
44131
- deviceType === hdShared.EDeviceType.Pro2) {
44189
+ deviceType === hdShared.EDeviceType.Pro2 ||
44190
+ deviceType === hdShared.EDeviceType.Neo) {
44132
44191
  return { support: true };
44133
44192
  }
44134
44193
  const firmwareVersion = this.getCurrentFirmwareVersionString();
@@ -44141,7 +44200,8 @@ class Device extends events.exports {
44141
44200
  const deviceType = this.getCurrentDeviceType();
44142
44201
  if (deviceType === hdShared.EDeviceType.Touch ||
44143
44202
  deviceType === hdShared.EDeviceType.Pro ||
44144
- deviceType === hdShared.EDeviceType.Pro2) {
44203
+ deviceType === hdShared.EDeviceType.Pro2 ||
44204
+ deviceType === hdShared.EDeviceType.Neo) {
44145
44205
  return { support: false };
44146
44206
  }
44147
44207
  const firmwareVersion = this.getCurrentFirmwareVersionString();
@@ -44485,8 +44545,10 @@ class Device extends events.exports {
44485
44545
  const protocolV2DeviceType = runtimeDeviceInfo
44486
44546
  ? resolveProtocolV2DeviceIdentity((_c = runtimeDeviceInfo.hw) === null || _c === void 0 ? void 0 : _c.Device_type).deviceType
44487
44547
  : this.getCurrentDeviceType();
44488
- if (runtimeMode === 'romloader' && protocolV2DeviceType !== hdShared.EDeviceType.Pro2) {
44489
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Protocol V2 romloader mode is only supported for Pro2.');
44548
+ if (runtimeMode === 'romloader' &&
44549
+ protocolV2DeviceType !== hdShared.EDeviceType.Pro2 &&
44550
+ protocolV2DeviceType !== hdShared.EDeviceType.Neo) {
44551
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Protocol V2 romloader mode is only supported for Pro2 and Neo.');
44490
44552
  }
44491
44553
  const deviceStatusSupported = supportsProtocolV2Message(protocolInfo, PROTOCOL_V2_DEVICE_STATUS_GET_MESSAGE_TYPE);
44492
44554
  if (runtimeMode === 'bootloader' || runtimeMode === 'romloader') {
@@ -44821,7 +44883,8 @@ class Device extends events.exports {
44821
44883
  if (!this.state)
44822
44884
  return undefined;
44823
44885
  return (this.isProtocolV2() &&
44824
- this.getCurrentDeviceType() === hdShared.EDeviceType.Pro2 &&
44886
+ (this.getCurrentDeviceType() === hdShared.EDeviceType.Pro2 ||
44887
+ this.getCurrentDeviceType() === hdShared.EDeviceType.Neo) &&
44825
44888
  this.state.status.mode === 'romloader');
44826
44889
  }
44827
44890
  isInitialized() {
@@ -44859,7 +44922,8 @@ class Device extends events.exports {
44859
44922
  const deviceType = this.getCurrentDeviceType();
44860
44923
  const isModeT = deviceType === hdShared.EDeviceType.Touch ||
44861
44924
  deviceType === hdShared.EDeviceType.Pro ||
44862
- deviceType === hdShared.EDeviceType.Pro2;
44925
+ deviceType === hdShared.EDeviceType.Pro2 ||
44926
+ deviceType === hdShared.EDeviceType.Neo;
44863
44927
  const unlocked = (_a = this.state) === null || _a === void 0 ? void 0 : _a.status.unlocked;
44864
44928
  const preCheckTouch = isModeT && unlocked === false;
44865
44929
  const passphraseProtection = this.getCurrentPassphraseProtection();
@@ -45888,6 +45952,7 @@ class OpenWalletSession extends BaseMethod {
45888
45952
  }
45889
45953
  init() {
45890
45954
  this.useDevicePassphraseState = false;
45955
+ this.unlockPolicy = 'unlock-before-run';
45891
45956
  this.skipForceUpdateCheck = true;
45892
45957
  this.params = normalizeParams(this.payload);
45893
45958
  this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
@@ -46494,8 +46559,8 @@ class CheckAllFirmwareRelease extends BaseMethod {
46494
46559
  ? ['identity', 'versions', 'verification']
46495
46560
  : ['identity', 'versions'],
46496
46561
  });
46497
- if (state.identity.deviceType !== 'pro2') {
46498
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, 'checkAllFirmwareRelease requires a Pro2 device for Protocol V2');
46562
+ if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
46563
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, 'checkAllFirmwareRelease requires a Pro2 or Neo device for Protocol V2');
46499
46564
  }
46500
46565
  const { features } = this.device;
46501
46566
  if (!features) {
@@ -46510,7 +46575,8 @@ class CheckAllFirmwareRelease extends BaseMethod {
46510
46575
  firmwareType,
46511
46576
  release,
46512
46577
  });
46513
- const resources = DataManager.getProtocolV2Resources();
46578
+ const resourceDeviceType = state.identity.deviceType === 'neo' ? hdShared.EDeviceType.Neo : hdShared.EDeviceType.Pro2;
46579
+ const resources = DataManager.getProtocolV2Resources(resourceDeviceType);
46514
46580
  let resourceStatus = 'unknown';
46515
46581
  if (resources === null || resources === void 0 ? void 0 : resources.length) {
46516
46582
  const loaderMode = state.status.mode === 'bootloader' || state.status.mode === 'romloader';
@@ -46551,7 +46617,7 @@ class CheckAllFirmwareRelease extends BaseMethod {
46551
46617
  }, bootloader: {
46552
46618
  status: 'valid',
46553
46619
  release: emptyRelease,
46554
- }, features, protocol: 'V2', deviceType: 'pro2' }, plan), { resourceStatus, hasUpgrade: plan.hasUpgrade || resourceStatus === 'outdated', targetsToUpdate });
46620
+ }, features, protocol: 'V2', deviceType: state.identity.deviceType }, plan), { resourceStatus, hasUpgrade: plan.hasUpgrade || resourceStatus === 'outdated', targetsToUpdate });
46555
46621
  });
46556
46622
  }
46557
46623
  }
@@ -49507,7 +49573,6 @@ function normalizeRebootType(value) {
49507
49573
  return hdTransport.DeviceRebootType.Normal;
49508
49574
  }
49509
49575
  const INSTALLABLE_FIRMWARE_TARGET_IDS = new Set([
49510
- ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
49511
49576
  ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_BOOTLOADER,
49512
49577
  ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P1,
49513
49578
  ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_APPLICATION_P2,
@@ -49543,7 +49608,6 @@ const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
49543
49608
  const PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET = 0x200;
49544
49609
  const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
49545
49610
  const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
49546
- const PROTOCOL_V2_BOOT_RESOURCES_FILE_NAME = 'boot_resources.crate.okpkg';
49547
49611
  const getProtocolV2DeviceTransferProgress = (bytesBeforeChunk, bytesAfterChunk, totalBytes) => {
49548
49612
  if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
49549
49613
  return 100;
@@ -49733,13 +49797,17 @@ const isProtocolV2FirmwareFingerprintValid = (binary, fingerprint) => {
49733
49797
  return true;
49734
49798
  return bytesToHex(sha256.sha256(toProtocolV2Bytes(binary))) === expectedFingerprint;
49735
49799
  };
49736
- const assertProtocolV2ReconnectIdentity = (expectedSerialNumber, actualSerialNumber) => {
49737
- if (!expectedSerialNumber || !actualSerialNumber) {
49800
+ const assertProtocolV2ReconnectIdentity = (expectedSerialNumber, actualSerialNumber, expectedPath, actualPath) => {
49801
+ if (expectedSerialNumber && actualSerialNumber) {
49802
+ if (actualSerialNumber !== expectedSerialNumber) {
49803
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 reconnect physical identity mismatch: expected ${expectedSerialNumber}, received ${actualSerialNumber}`);
49804
+ }
49738
49805
  return;
49739
49806
  }
49740
- if (actualSerialNumber !== expectedSerialNumber) {
49741
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 reconnect physical identity mismatch: expected ${expectedSerialNumber}, received ${actualSerialNumber}`);
49807
+ if (expectedPath && actualPath && expectedPath === actualPath) {
49808
+ return;
49742
49809
  }
49810
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, `Protocol V2 reconnect physical identity unavailable: expected path ${expectedPath !== null && expectedPath !== void 0 ? expectedPath : 'unknown'}, received ${actualPath !== null && actualPath !== void 0 ? actualPath : 'unknown'}`);
49743
49811
  };
49744
49812
  class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49745
49813
  getSupportedProtocols() {
@@ -49768,7 +49836,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49768
49836
  { name: 'chunkSize', type: 'number' },
49769
49837
  { name: 'forcedUpdateRes', type: 'boolean' },
49770
49838
  { name: 'bootloaderBinary', type: 'buffer' },
49771
- { name: 'bootResourcesBinary', type: 'buffer' },
49772
49839
  { name: 'romloaderBinary', type: 'buffer' },
49773
49840
  { name: 'applicationP1Binary', type: 'buffer' },
49774
49841
  { name: 'applicationP2Binary', type: 'buffer' },
@@ -49780,13 +49847,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49780
49847
  { name: 'firmwareType', type: 'string' },
49781
49848
  { name: 'targetsToUpdate', type: 'array', allowEmpty: true },
49782
49849
  { name: 'platform', type: 'string' },
49783
- { name: 'resourceBundleFiles', type: 'array', allowEmpty: true },
49850
+ { name: 'resourceFiles', type: 'array', allowEmpty: true },
49784
49851
  ]);
49785
49852
  this.params = {
49786
49853
  chunkSize: payload.chunkSize,
49787
49854
  forcedUpdateRes: payload.forcedUpdateRes,
49788
49855
  bootloaderBinary: payload.bootloaderBinary,
49789
- bootResourcesBinary: payload.bootResourcesBinary,
49790
49856
  romloaderBinary: payload.romloaderBinary,
49791
49857
  applicationP1Binary: payload.applicationP1Binary,
49792
49858
  applicationP2Binary: payload.applicationP2Binary,
@@ -49795,7 +49861,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49795
49861
  se02Binary: payload.se02Binary,
49796
49862
  se03Binary: payload.se03Binary,
49797
49863
  se04Binary: payload.se04Binary,
49798
- resourceBundleFiles: payload.resourceBundleFiles,
49864
+ resourceFiles: payload.resourceFiles,
49799
49865
  firmwareType: payload.firmwareType,
49800
49866
  targetsToUpdate: payload.targetsToUpdate,
49801
49867
  platform: payload.platform,
@@ -49828,23 +49894,22 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49828
49894
  const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
49829
49895
  const deviceFirmwareType = getFirmwareType(deviceFeatures);
49830
49896
  const firmwareType = (_a = this.params.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
49831
- const needsRemoteResources = !((_b = this.params.resourceBundleFiles) === null || _b === void 0 ? void 0 : _b.length) &&
49832
- !!((_c = this.params.targetsToUpdate) === null || _c === void 0 ? void 0 : _c.includes('resource'));
49897
+ const needsRemoteResources = !((_b = this.params.resourceFiles) === null || _b === void 0 ? void 0 : _b.length) && !!((_c = this.params.targetsToUpdate) === null || _c === void 0 ? void 0 : _c.includes('resource'));
49833
49898
  let fwBinaryMap = [];
49834
49899
  let bootloaderBinary = null;
49835
- let bootResourcesInstallItem;
49836
49900
  let installItems;
49837
49901
  let resourceBundles;
49838
49902
  try {
49839
49903
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
49840
- resourceBundles = this.prepareExplicitProtocolV2ResourceBundles();
49904
+ resourceBundles = this.prepareExplicitProtocolV2ResourceFiles();
49841
49905
  fwBinaryMap = this.collectExplicitTargetBinaries();
49842
49906
  bootloaderBinary = this.prepareBootloaderBinary();
49843
49907
  const needsRemoteFirmware = !this.hasExplicitProtocolV2Payload(fwBinaryMap);
49844
- const needsRemoteBootResources = !this.params.bootResourcesBinary &&
49845
- !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('boot_resources'));
49908
+ const needsRemoteBootResources = !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('boot_resources'));
49846
49909
  if (needsRemoteFirmware || needsRemoteResources || needsRemoteBootResources) {
49847
- yield DataManager.forceReloadData();
49910
+ yield DataManager.forceReloadData({
49911
+ requireResources: needsRemoteResources || needsRemoteBootResources,
49912
+ });
49848
49913
  }
49849
49914
  if (needsRemoteFirmware) {
49850
49915
  const remoteBinaries = yield this.prepareRemoteProtocolV2Binaries(firmwareType, deviceFeatures);
@@ -49852,12 +49917,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49852
49917
  fwBinaryMap = remoteBinaries.fwBinaryMap;
49853
49918
  installItems = remoteBinaries.installItems;
49854
49919
  }
49855
- bootResourcesInstallItem = yield this.prepareProtocolV2BootResources();
49856
- if (bootResourcesInstallItem) {
49857
- installItems = [
49858
- bootResourcesInstallItem,
49859
- ...(installItems !== null && installItems !== void 0 ? installItems : this.buildProtocolV2InstallItems({ bootloaderBinary, fwBinaryMap })),
49860
- ];
49920
+ const bootResourceFiles = yield this.prepareProtocolV2BootResources();
49921
+ if (bootResourceFiles === null || bootResourceFiles === void 0 ? void 0 : bootResourceFiles.length) {
49922
+ resourceBundles = [...(resourceBundles !== null && resourceBundles !== void 0 ? resourceBundles : []), ...bootResourceFiles];
49861
49923
  }
49862
49924
  if (!needsRemoteResources) {
49863
49925
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
@@ -49879,7 +49941,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49879
49941
  const enteredBootloader = yield this.enterProtocolV2BootloaderMode();
49880
49942
  if (needsRemoteResources) {
49881
49943
  try {
49882
- resourceBundles = yield this.prepareProtocolV2ResourceBundles();
49944
+ const stableResources = yield this.prepareProtocolV2ResourceBundles();
49945
+ resourceBundles = [...(resourceBundles !== null && resourceBundles !== void 0 ? resourceBundles : []), ...(stableResources !== null && stableResources !== void 0 ? stableResources : [])];
49883
49946
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FinishDownloadFirmware);
49884
49947
  }
49885
49948
  catch (err) {
@@ -49923,7 +49986,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49923
49986
  return serialNumber || undefined;
49924
49987
  }
49925
49988
  assertProtocolV2DeviceInfoIdentity(deviceInfo) {
49926
- assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedSerialNumber, this.getProtocolV2SerialNumber(deviceInfo));
49989
+ assertProtocolV2ReconnectIdentity(this.protocolV2ExpectedSerialNumber, this.getProtocolV2SerialNumber(deviceInfo), this.protocolV2ExpectedPath, this.device.originalDescriptor.path);
49927
49990
  }
49928
49991
  getProtocolV2DeviceInfoTimeout() {
49929
49992
  var _a;
@@ -49940,11 +50003,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49940
50003
  });
49941
50004
  }
49942
50005
  captureProtocolV2PhysicalIdentity() {
50006
+ var _a;
49943
50007
  return __awaiter(this, void 0, void 0, function* () {
49944
50008
  const deviceInfo = yield this.requestProtocolV2PhysicalIdentity();
49945
50009
  const serialNumber = this.getProtocolV2SerialNumber(deviceInfo);
49946
- assertProtocolV2ReconnectIdentity(serialNumber, serialNumber);
50010
+ const path = ((_a = this.device.originalDescriptor.path) === null || _a === void 0 ? void 0 : _a.trim()) || undefined;
50011
+ assertProtocolV2ReconnectIdentity(serialNumber, serialNumber, path, path);
49947
50012
  this.protocolV2ExpectedSerialNumber = serialNumber;
50013
+ this.protocolV2ExpectedPath = path;
49948
50014
  });
49949
50015
  }
49950
50016
  verifyProtocolV2ReconnectIdentity() {
@@ -49960,9 +50026,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
49960
50026
  }
49961
50027
  hasExplicitProtocolV2Payload(fwBinaryMap) {
49962
50028
  var _a;
49963
- return (!!((_a = this.params.resourceBundleFiles) === null || _a === void 0 ? void 0 : _a.length) ||
50029
+ return (!!((_a = this.params.resourceFiles) === null || _a === void 0 ? void 0 : _a.length) ||
49964
50030
  !!this.params.bootloaderBinary ||
49965
- !!this.params.bootResourcesBinary ||
49966
50031
  fwBinaryMap.length > 0);
49967
50032
  }
49968
50033
  buildProtocolV2InstallItems({ bootloaderBinary, fwBinaryMap, }) {
@@ -50077,63 +50142,65 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50077
50142
  };
50078
50143
  });
50079
50144
  }
50080
- validateProtocolV2BootResourcesBinary(binary, resource) {
50081
- if (resource && !isProtocolV2ResourceFileValid(binary, resource)) {
50082
- throw new Error('Pro2 boot resources file verification failed');
50083
- }
50084
- const header = parseProtocolV2OkppHeader(toProtocolV2Bytes(binary));
50085
- if (!header || header.type !== 'CRAT') {
50086
- throw new Error('Invalid Pro2 boot resources CRATE header');
50087
- }
50088
- if (resource) {
50089
- const expectedPayloadHash = normalizeProtocolV2Hex(resource.payloadHash);
50090
- const expectedHeaderHash = normalizeProtocolV2Hex(resource.headerHash);
50091
- if (header.payloadHash !== expectedPayloadHash) {
50092
- throw new Error('Pro2 boot resources payload hash mismatch');
50093
- }
50094
- if (header.headerHash !== expectedHeaderHash) {
50095
- throw new Error('Pro2 boot resources header hash mismatch');
50096
- }
50097
- }
50145
+ getProtocolV2DeviceType() {
50146
+ const deviceType = this.device.getCurrentDeviceType();
50147
+ if (deviceType === hdShared.EDeviceType.Pro2 || deviceType === hdShared.EDeviceType.Neo)
50148
+ return deviceType;
50149
+ throw new Error(`Unsupported Protocol V2 device type: ${deviceType}`);
50098
50150
  }
50099
50151
  prepareProtocolV2BootResources() {
50100
- var _a;
50152
+ var _a, _b, _c;
50101
50153
  return __awaiter(this, void 0, void 0, function* () {
50102
- let binary = this.params.bootResourcesBinary;
50103
- let resource;
50104
- if (!binary) {
50105
- if (!((_a = this.params.targetsToUpdate) === null || _a === void 0 ? void 0 : _a.includes('boot_resources'))) {
50106
- return undefined;
50107
- }
50108
- resource = DataManager.getProtocolV2BootResources();
50109
- if (!resource) {
50110
- throw new Error('Missing Pro2 boot resources configuration');
50111
- }
50112
- Log$5.log('[FirmwareUpdateV4] downloading Pro2 boot resources CRATE');
50113
- ({ binary } = yield getSysResourceBinary(resource.url));
50154
+ if (!((_a = this.params.targetsToUpdate) === null || _a === void 0 ? void 0 : _a.includes('boot_resources')))
50155
+ return undefined;
50156
+ const resource = DataManager.getProtocolV2BootResources(this.getProtocolV2DeviceType());
50157
+ if (!resource)
50158
+ throw new Error('Missing Protocol V2 boot resources configuration');
50159
+ const files = [];
50160
+ for (const file of resource.files) {
50161
+ Log$5.log(`[FirmwareUpdateV4] downloading boot resource ${file.devicePath}`);
50162
+ const { binary } = yield getSysResourceBinary(file.url);
50163
+ if (!isProtocolV2ResourceFileValid(binary, file)) {
50164
+ throw new Error(`Boot resource file verification failed: ${file.devicePath}`);
50165
+ }
50166
+ files.push({
50167
+ name: (_c = (_b = file.name) !== null && _b !== void 0 ? _b : file.devicePath.split('/').pop()) !== null && _c !== void 0 ? _c : file.devicePath,
50168
+ binary,
50169
+ devicePath: file.devicePath,
50170
+ });
50114
50171
  }
50115
- this.validateProtocolV2BootResourcesBinary(binary, resource);
50116
- return {
50117
- fileName: PROTOCOL_V2_BOOT_RESOURCES_FILE_NAME,
50118
- binary,
50119
- targetId: ProtocolV2FirmwareTargetType.FW_MGMT_TARGET_CRATE,
50120
- kind: 'boot_resources',
50121
- };
50172
+ return files;
50122
50173
  });
50123
50174
  }
50124
- prepareExplicitProtocolV2ResourceBundles() {
50175
+ prepareExplicitProtocolV2ResourceFiles() {
50125
50176
  var _a;
50126
- if (!((_a = this.params.resourceBundleFiles) === null || _a === void 0 ? void 0 : _a.length))
50177
+ const files = (_a = this.params.resourceFiles) !== null && _a !== void 0 ? _a : [];
50178
+ if (!(files === null || files === void 0 ? void 0 : files.length))
50127
50179
  return undefined;
50128
- return this.params.resourceBundleFiles.map((file, index) => {
50180
+ const prepared = files.map((file, index) => {
50129
50181
  var _a;
50130
- const devicePath = validateProtocolV2FilesystemPath(file.devicePath, `resourceBundleFiles[${index}].devicePath`);
50182
+ const devicePath = validateProtocolV2FilesystemPath(file.devicePath, `resourceFiles[${index}].devicePath`);
50183
+ const descriptor = file;
50184
+ if (descriptor.size !== undefined && descriptor.size !== file.binary.byteLength) {
50185
+ throw new Error(`resourceFiles[${index}] size mismatch`);
50186
+ }
50187
+ if (descriptor.fileHash &&
50188
+ !isProtocolV2ResourceFileValid(file.binary, {
50189
+ size: file.binary.byteLength,
50190
+ fileHash: descriptor.fileHash,
50191
+ })) {
50192
+ throw new Error(`resourceFiles[${index}] SHA-256 mismatch`);
50193
+ }
50131
50194
  return {
50132
50195
  name: (_a = devicePath.split('/').pop()) !== null && _a !== void 0 ? _a : devicePath,
50133
50196
  binary: file.binary,
50134
50197
  devicePath,
50135
50198
  };
50136
50199
  });
50200
+ if (new Set(prepared.map(file => file.devicePath)).size !== prepared.length) {
50201
+ throw new Error('resourceFiles contain duplicate devicePath values');
50202
+ }
50203
+ return prepared;
50137
50204
  }
50138
50205
  prepareProtocolV2ResourceBundles() {
50139
50206
  var _a;
@@ -50141,7 +50208,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50141
50208
  if (!((_a = this.params.targetsToUpdate) === null || _a === void 0 ? void 0 : _a.includes('resource'))) {
50142
50209
  return undefined;
50143
50210
  }
50144
- const resources = DataManager.getProtocolV2Resources();
50211
+ const resources = DataManager.getProtocolV2Resources(this.getProtocolV2DeviceType());
50145
50212
  if (!(resources === null || resources === void 0 ? void 0 : resources.length)) {
50146
50213
  throw new Error('Missing Pro2 stable resource configuration');
50147
50214
  }
@@ -50159,7 +50226,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50159
50226
  mode: 'bootloader-recovery',
50160
50227
  forced: this.params.forcedUpdateRes,
50161
50228
  });
50162
- Log$5.log(`[FirmwareUpdateV4] Pro2 resource plan mode=bootloader-recovery status=${plan.status} count=${plan.resources.length}`);
50229
+ Log$5.log(`[FirmwareUpdateV4] Protocol V2 resource plan mode=bootloader-recovery status=${plan.status} count=${plan.resources.length}`);
50163
50230
  const bundles = [];
50164
50231
  for (const resource of plan.resources) {
50165
50232
  bundles.push(yield this.downloadProtocolV2Resource(resource));
@@ -50191,7 +50258,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50191
50258
  const transferTotalSize = totalSize + firmwareSize;
50192
50259
  let processedSize = 0;
50193
50260
  for (const bundle of bundles) {
50194
- Log$5.log(`[FirmwareUpdateV4] syncing RESC bundle ${bundle.name} -> ${bundle.devicePath} bytes=${bundle.binary.byteLength}`);
50261
+ Log$5.log(`[FirmwareUpdateV4] syncing resource ${bundle.name} -> ${bundle.devicePath} bytes=${bundle.binary.byteLength}`);
50195
50262
  processedSize = yield this.protocolV2CommonUpdateProcess({
50196
50263
  payload: bundle.binary,
50197
50264
  filePath: bundle.devicePath,
@@ -50200,7 +50267,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50200
50267
  });
50201
50268
  }
50202
50269
  const elapsedMs = Date.now() - transferStartTime;
50203
- Log$5.log(`[FirmwareUpdateV4] RESC bundle sync finished transport=${transferTransport} bytes=${totalSize} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatProtocolV2TransferSpeed(totalSize, elapsedMs)} KB/s`);
50270
+ Log$5.log(`[FirmwareUpdateV4] resource sync finished transport=${transferTransport} bytes=${totalSize} elapsed=${(elapsedMs / 1000).toFixed(2)}s speed=${formatProtocolV2TransferSpeed(totalSize, elapsedMs)} KB/s`);
50204
50271
  return { processedSize, totalSize: transferTotalSize };
50205
50272
  });
50206
50273
  }
@@ -50214,7 +50281,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50214
50281
  }
50215
50282
  isProtocolV2RomloaderMode() {
50216
50283
  var _a;
50217
- if (!this.device.isProtocolV2() || this.device.getCurrentDeviceType() !== hdShared.EDeviceType.Pro2) {
50284
+ const deviceType = this.device.getCurrentDeviceType();
50285
+ if (!this.device.isProtocolV2() ||
50286
+ (deviceType !== hdShared.EDeviceType.Pro2 && deviceType !== hdShared.EDeviceType.Neo)) {
50218
50287
  return false;
50219
50288
  }
50220
50289
  if (typeof this.device.isRomloader === 'function') {
@@ -50321,7 +50390,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50321
50390
  totalSize = resourceTransfer.totalSize;
50322
50391
  }
50323
50392
  if (orderedInstallItems.length === 0) {
50324
- Log$5.log('[FirmwareUpdateV4] no firmware targets to install (RESC bundles only)');
50393
+ Log$5.log('[FirmwareUpdateV4] no firmware targets to install (resource files only)');
50325
50394
  if (totalSize > 0) {
50326
50395
  this.postProgressMessage(100, 'transferData');
50327
50396
  }
@@ -50630,7 +50699,11 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50630
50699
  const devicesDescriptor = (_b = deviceDiff === null || deviceDiff === void 0 ? void 0 : deviceDiff.descriptors) !== null && _b !== void 0 ? _b : [];
50631
50700
  if (DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
50632
50701
  devicesDescriptor.length === 1) {
50633
- this.device.updateDescriptor(Object.assign(Object.assign({}, devicesDescriptor[0]), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
50702
+ const descriptor = devicesDescriptor[0];
50703
+ if (!this.protocolV2ExpectedSerialNumber && descriptor.path !== this.protocolV2ExpectedPath) {
50704
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
50705
+ }
50706
+ this.device.updateDescriptor(Object.assign(Object.assign({}, descriptor), { protocolType: PROTOCOL_V2_CONNECT_PROTOCOL }), true);
50634
50707
  yield this.ensureProtocolV2DeviceAcquired();
50635
50708
  this.device.commands.disposed = false;
50636
50709
  this.device.getCommands().mainId = (_c = this.device.mainId) !== null && _c !== void 0 ? _c : '';
@@ -50640,14 +50713,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
50640
50713
  connectProtocol: PROTOCOL_V2_CONNECT_PROTOCOL,
50641
50714
  });
50642
50715
  const expectedSerialNumber = (_d = this.protocolV2ExpectedSerialNumber) === null || _d === void 0 ? void 0 : _d.trim();
50643
- const identityMatch = expectedSerialNumber
50644
- ? deviceList.find(candidate => { var _a; return ((_a = candidate.getCurrentSerialNo) === null || _a === void 0 ? void 0 : _a.call(candidate).trim()) === expectedSerialNumber; })
50645
- : undefined;
50646
- const singleCandidate = deviceList.length === 1 ? deviceList.at(0) : undefined;
50647
- const singleCandidateSerialNumber = (_e = singleCandidate === null || singleCandidate === void 0 ? void 0 : singleCandidate.getCurrentSerialNo) === null || _e === void 0 ? void 0 : _e.call(singleCandidate).trim();
50648
- const reconnectDevice = identityMatch !== null && identityMatch !== void 0 ? identityMatch : (singleCandidate && (!expectedSerialNumber || !singleCandidateSerialNumber)
50649
- ? singleCandidate
50650
- : undefined);
50716
+ const expectedPath = (_e = this.protocolV2ExpectedPath) === null || _e === void 0 ? void 0 : _e.trim();
50717
+ const reconnectDevice = deviceList.find(candidate => {
50718
+ var _a;
50719
+ const candidateSerialNumber = (_a = candidate.getCurrentSerialNo) === null || _a === void 0 ? void 0 : _a.call(candidate).trim();
50720
+ if (expectedSerialNumber && candidateSerialNumber) {
50721
+ return candidateSerialNumber === expectedSerialNumber;
50722
+ }
50723
+ return !!expectedPath && candidate.getConnectId() === expectedPath;
50724
+ });
50651
50725
  if (!reconnectDevice) {
50652
50726
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound);
50653
50727
  }
@@ -51058,18 +51132,7 @@ class DeviceUploadNft extends BaseMethod {
51058
51132
  }
51059
51133
  updateNft(basename) {
51060
51134
  return __awaiter(this, void 0, void 0, function* () {
51061
- const params = { file_name_no_ext: basename };
51062
- const options = { timeoutMs: this.params.timeoutMs };
51063
- try {
51064
- return yield this.device.commands.typedCall('NftUpdate', 'Success', params, options);
51065
- }
51066
- catch (error) {
51067
- if (!isProtocolV2ResponseTimeout(error)) {
51068
- throw error;
51069
- }
51070
- this.throwIfAborted();
51071
- return this.device.commands.typedCall('NftUpdate', 'Success', params, options);
51072
- }
51135
+ return this.device.commands.typedCall('NftUpdate', 'Success', { file_name_no_ext: basename }, { timeoutMs: this.params.timeoutMs });
51073
51136
  });
51074
51137
  }
51075
51138
  run() {
@@ -55143,7 +55206,7 @@ class SolSignTransaction extends BaseMethod {
55143
55206
  getVersionRange() {
55144
55207
  if (this.existsVersionedTx()) {
55145
55208
  return {
55146
- pro2: {
55209
+ model_pro2: {
55147
55210
  min: '0.0.0',
55148
55211
  },
55149
55212
  model_mini: {
@@ -55155,7 +55218,7 @@ class SolSignTransaction extends BaseMethod {
55155
55218
  };
55156
55219
  }
55157
55220
  return {
55158
- pro2: {
55221
+ model_pro2: {
55159
55222
  min: '0.0.0',
55160
55223
  },
55161
55224
  classic: {
@@ -55232,7 +55295,7 @@ class SolSignOffchainMessage extends BaseMethod {
55232
55295
  }
55233
55296
  getVersionRange() {
55234
55297
  return {
55235
- pro2: {
55298
+ model_pro2: {
55236
55299
  min: '0.0.0',
55237
55300
  },
55238
55301
  pro: {
@@ -55275,7 +55338,7 @@ class SolSignMessage extends BaseMethod {
55275
55338
  }
55276
55339
  getVersionRange() {
55277
55340
  return {
55278
- pro2: {
55341
+ model_pro2: {
55279
55342
  min: '0.0.0',
55280
55343
  },
55281
55344
  pro: {
@@ -55705,7 +55768,7 @@ class TronSignMessage extends BaseMethod {
55705
55768
  }
55706
55769
  getVersionRange() {
55707
55770
  return {
55708
- pro2: {
55771
+ model_pro2: {
55709
55772
  min: '0.0.0',
55710
55773
  },
55711
55774
  model_mini: {
@@ -55715,7 +55778,7 @@ class TronSignMessage extends BaseMethod {
55715
55778
  }
55716
55779
  getMessageV2VersionRange() {
55717
55780
  return {
55718
- pro2: {
55781
+ model_pro2: {
55719
55782
  min: '0.0.0',
55720
55783
  },
55721
55784
  pro: {
@@ -55870,7 +55933,7 @@ class TronSignTransaction extends BaseMethod {
55870
55933
  }
55871
55934
  getVersionRange() {
55872
55935
  return {
55873
- pro2: {
55936
+ model_pro2: {
55874
55937
  min: '0.0.0',
55875
55938
  },
55876
55939
  model_mini: {
@@ -56805,7 +56868,7 @@ class SuiGetAddress extends BaseMethod {
56805
56868
  }
56806
56869
  getVersionRange() {
56807
56870
  return {
56808
- pro2: {
56871
+ model_pro2: {
56809
56872
  min: '0.0.0',
56810
56873
  },
56811
56874
  model_mini: {
@@ -56900,7 +56963,7 @@ class SuiGetPublicKey extends BaseMethod {
56900
56963
  }
56901
56964
  getVersionRange() {
56902
56965
  return {
56903
- pro2: {
56966
+ model_pro2: {
56904
56967
  min: '0.0.0',
56905
56968
  },
56906
56969
  model_mini: {
@@ -56948,7 +57011,7 @@ class SuiSignMessage extends BaseMethod {
56948
57011
  }
56949
57012
  getVersionRange() {
56950
57013
  return {
56951
- pro2: {
57014
+ model_pro2: {
56952
57015
  min: '0.0.0',
56953
57016
  },
56954
57017
  model_mini: {
@@ -57008,7 +57071,7 @@ class SuiSignTransaction extends BaseMethod {
57008
57071
  }
57009
57072
  getVersionRange() {
57010
57073
  return {
57011
- pro2: {
57074
+ model_pro2: {
57012
57075
  min: '0.0.0',
57013
57076
  },
57014
57077
  model_mini: {
@@ -58225,7 +58288,7 @@ const baseVersionRange = {
58225
58288
  model_touch: {
58226
58289
  min: '4.3.0',
58227
58290
  },
58228
- pro2: {
58291
+ model_pro2: {
58229
58292
  min: '0.0.0',
58230
58293
  },
58231
58294
  };
@@ -58237,7 +58300,7 @@ const specialVersionRange = {
58237
58300
  model_touch: {
58238
58301
  min: '4.7.0',
58239
58302
  },
58240
- pro2: {
58303
+ model_pro2: {
58241
58304
  min: '0.0.0',
58242
58305
  },
58243
58306
  },
@@ -58248,7 +58311,7 @@ const specialVersionRange = {
58248
58311
  model_touch: {
58249
58312
  min: '4.9.0',
58250
58313
  },
58251
- pro2: {
58314
+ model_pro2: {
58252
58315
  min: '0.0.0',
58253
58316
  },
58254
58317
  },
@@ -58439,7 +58502,7 @@ class KaspaGetAddress extends BaseMethod {
58439
58502
  model_classic1s: {
58440
58503
  min: '3.12.0',
58441
58504
  },
58442
- pro2: {
58505
+ model_pro2: {
58443
58506
  min: '0.0.0',
58444
58507
  },
58445
58508
  };
@@ -58892,7 +58955,7 @@ class KaspaSignTransaction extends BaseMethod {
58892
58955
  model_classic1s: {
58893
58956
  min: '3.12.0',
58894
58957
  },
58895
- pro2: {
58958
+ model_pro2: {
58896
58959
  min: '0.0.0',
58897
58960
  },
58898
58961
  };
@@ -59896,7 +59959,7 @@ class TonGetAddress extends BaseMethod {
59896
59959
  }
59897
59960
  getVersionRange() {
59898
59961
  return {
59899
- pro2: {
59962
+ model_pro2: {
59900
59963
  min: '0.0.0',
59901
59964
  },
59902
59965
  model_touch: {
@@ -60011,7 +60074,7 @@ class TonSignMessage extends BaseMethod {
60011
60074
  }
60012
60075
  getVersionRange() {
60013
60076
  return {
60014
- pro2: {
60077
+ model_pro2: {
60015
60078
  min: '0.0.0',
60016
60079
  },
60017
60080
  model_touch: {
@@ -60135,7 +60198,7 @@ class TonSignProof extends BaseMethod {
60135
60198
  }
60136
60199
  getVersionRange() {
60137
60200
  return {
60138
- pro2: {
60201
+ model_pro2: {
60139
60202
  min: '0.0.0',
60140
60203
  },
60141
60204
  model_touch: {