@onekeyfe/hd-core 1.2.0-alpha.108 → 1.2.0-alpha.109

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 (31) hide show
  1. package/__tests__/DeviceCommands.test.ts +2 -2
  2. package/__tests__/device-lifecycle-events.test.ts +1 -1
  3. package/__tests__/device-state-mapper.test.ts +4 -4
  4. package/__tests__/device-utils.test.ts +1 -1
  5. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +36 -89
  6. package/__tests__/get-device-state.test.ts +8 -8
  7. package/__tests__/protocol-v2-resources.test.ts +8 -0
  8. package/__tests__/protocol-v2.test.ts +192 -236
  9. package/dist/api/FirmwareUpdateV4.d.ts +0 -3
  10. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  11. package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
  12. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  13. package/dist/index.d.ts +5 -20
  14. package/dist/index.js +128 -206
  15. package/dist/protocols/protocol-v2/features.d.ts +4 -4
  16. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  17. package/dist/types/settings.d.ts +4 -19
  18. package/dist/types/settings.d.ts.map +1 -1
  19. package/dist/utils/patch.d.ts +1 -1
  20. package/dist/utils/patch.d.ts.map +1 -1
  21. package/package.json +4 -4
  22. package/src/api/FirmwareUpdateV4.ts +84 -174
  23. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
  24. package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
  25. package/src/api/ton/TonSignMessage.ts +1 -1
  26. package/src/data/messages/messages-protocol-v2.json +31 -14
  27. package/src/device/DeviceStateMapper.ts +15 -15
  28. package/src/deviceProfile/buildDeviceFeatures.ts +3 -3
  29. package/src/protocols/protocol-v2/features.ts +6 -6
  30. package/src/protocols/protocol-v2/resources.ts +9 -46
  31. package/src/types/settings.ts +4 -19
package/dist/index.js CHANGED
@@ -27499,9 +27499,10 @@ var nested = {
27499
27499
  MessageType_FilesystemDirMake: 60809,
27500
27500
  MessageType_FilesystemDirRemove: 60810,
27501
27501
  MessageType_FilesystemFormat: 60811,
27502
- MessageType_DeviceFirmwareUpdateRequest: 61000,
27503
- MessageType_DeviceFirmwareUpdateStatusGet: 61001,
27504
- MessageType_DeviceFirmwareUpdateStatus: 61002,
27502
+ MessageType_DeviceFirmwareUpdateStage: 61000,
27503
+ MessageType_DeviceFirmwareUpdateRequest: 61001,
27504
+ MessageType_DeviceFirmwareUpdateStatusGet: 61002,
27505
+ MessageType_DeviceFirmwareUpdateStatus: 61003,
27505
27506
  MessageType_DeviceSessionGet: 61200,
27506
27507
  MessageType_DeviceSession: 61201,
27507
27508
  MessageType_DeviceSessionAskPin: 61202,
@@ -38003,7 +38004,7 @@ var nested = {
38003
38004
  type: "bytes",
38004
38005
  id: 1
38005
38006
  },
38006
- signing_message: {
38007
+ signning_message: {
38007
38008
  type: "bytes",
38008
38009
  id: 2
38009
38010
  },
@@ -38897,14 +38898,14 @@ var nested = {
38897
38898
  type: "string",
38898
38899
  id: 2
38899
38900
  },
38900
- burn_in_completed: {
38901
- type: "bool",
38902
- id: 3
38903
- },
38904
38901
  factory_test_completed: {
38905
38902
  type: "bool",
38906
38903
  id: 4
38907
38904
  },
38905
+ factory_burn_in_completed: {
38906
+ type: "bool",
38907
+ id: 3
38908
+ },
38908
38909
  manufacture_time: {
38909
38910
  type: "DeviceFactoryInfoManufactureTime",
38910
38911
  id: 5
@@ -38991,7 +38992,7 @@ var nested = {
38991
38992
  }
38992
38993
  }
38993
38994
  },
38994
- DeviceFirmwareUpdateRequest: {
38995
+ DeviceFirmwareUpdateStage: {
38995
38996
  fields: {
38996
38997
  targets: {
38997
38998
  rule: "repeated",
@@ -39000,6 +39001,10 @@ var nested = {
39000
39001
  }
39001
39002
  }
39002
39003
  },
39004
+ DeviceFirmwareUpdateRequest: {
39005
+ fields: {
39006
+ }
39007
+ },
39003
39008
  DeviceFirmwareUpdateRecord: {
39004
39009
  fields: {
39005
39010
  target_id: {
@@ -39181,7 +39186,7 @@ var nested = {
39181
39186
  type: "bool",
39182
39187
  id: 100
39183
39188
  },
39184
- fw: {
39189
+ main_mcu: {
39185
39190
  type: "bool",
39186
39191
  id: 200
39187
39192
  },
@@ -39250,7 +39255,7 @@ var nested = {
39250
39255
  type: "DeviceHardwareInfo",
39251
39256
  id: 100
39252
39257
  },
39253
- fw: {
39258
+ main_mcu: {
39254
39259
  type: "DeviceMainMcuInfo",
39255
39260
  id: 200
39256
39261
  },
@@ -39792,9 +39797,12 @@ var nested = {
39792
39797
  id: 1
39793
39798
  },
39794
39799
  text: {
39795
- rule: "required",
39796
39800
  type: "string",
39797
39801
  id: 2
39802
+ },
39803
+ text_id: {
39804
+ type: "uint32",
39805
+ id: 3
39798
39806
  }
39799
39807
  }
39800
39808
  },
@@ -39825,7 +39833,6 @@ var nested = {
39825
39833
  ViewSignPage: {
39826
39834
  fields: {
39827
39835
  title: {
39828
- rule: "required",
39829
39836
  type: "string",
39830
39837
  id: 1
39831
39838
  },
@@ -39859,13 +39866,16 @@ var nested = {
39859
39866
  options: {
39860
39867
  "default": "LayoutDefault"
39861
39868
  }
39869
+ },
39870
+ title_id: {
39871
+ type: "uint32",
39872
+ id: 8
39862
39873
  }
39863
39874
  }
39864
39875
  },
39865
39876
  ViewVerifyPage: {
39866
39877
  fields: {
39867
39878
  title: {
39868
- rule: "required",
39869
39879
  type: "string",
39870
39880
  id: 1
39871
39881
  },
@@ -39890,6 +39900,14 @@ var nested = {
39890
39900
  value_key: {
39891
39901
  type: "uint32",
39892
39902
  id: 6
39903
+ },
39904
+ title_id: {
39905
+ type: "uint32",
39906
+ id: 7
39907
+ },
39908
+ chain_id: {
39909
+ type: "uint32",
39910
+ id: 8
39893
39911
  }
39894
39912
  }
39895
39913
  },
@@ -40736,7 +40754,9 @@ function parseProtocolV2ResourceManifestFile(value, index) {
40736
40754
  }
40737
40755
  const file = value;
40738
40756
  const archivePath = assertManifestRelativePath(file.archive_path, `files[${index}].archive_path`);
40739
- const originalName = assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
40757
+ const originalName = file.original_name === undefined
40758
+ ? (_a = archivePath.split('/').pop()) !== null && _a !== void 0 ? _a : archivePath
40759
+ : assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
40740
40760
  if (originalName.includes('/')) {
40741
40761
  throw new Error(`Invalid Pro2 resource manifest files[${index}].original_name`);
40742
40762
  }
@@ -40748,41 +40768,18 @@ function parseProtocolV2ResourceManifestFile(value, index) {
40748
40768
  throw new Error(`Invalid Pro2 resource manifest files[${index}].size`);
40749
40769
  }
40750
40770
  const digest = normalizeHex$1(file.sha256, SHA256_HEX_LENGTH, `files[${index}].sha256`);
40751
- if (file.signed !== true) {
40752
- throw new Error(`Invalid Pro2 resource manifest files[${index}].signed`);
40753
- }
40754
- if (file.sig_algo !== 'ed25519' && file.sig_algo !== 'mldsa65') {
40755
- throw new Error(`Invalid Pro2 resource manifest files[${index}].sig_algo`);
40756
- }
40757
- if (file.payload_version !== null && typeof file.payload_version !== 'string') {
40758
- throw new Error(`Invalid Pro2 resource manifest files[${index}].payload_version`);
40759
- }
40760
40771
  if (!archivePath.endsWith('.okpkg') || !originalName.endsWith('.okpkg')) {
40761
40772
  throw new Error(`Invalid Pro2 resource manifest files[${index}] package extension`);
40762
40773
  }
40763
- return {
40764
- archive_path: archivePath,
40765
- original_name: originalName,
40766
- device_path: devicePath,
40767
- size: Number(file.size),
40768
- sha256: digest,
40769
- signed: true,
40770
- sig_algo: file.sig_algo,
40771
- payload_version: (_a = file.payload_version) !== null && _a !== void 0 ? _a : null,
40772
- };
40774
+ return Object.assign(Object.assign(Object.assign({ archive_path: archivePath, original_name: originalName, device_path: devicePath, size: Number(file.size), sha256: digest }, (file.signed === undefined ? {} : { signed: file.signed })), (file.sig_algo === undefined ? {} : { sig_algo: file.sig_algo })), (file.payload_version === undefined ? {} : { payload_version: file.payload_version }));
40773
40775
  }
40774
40776
  function parseProtocolV2ResourceManifest(value) {
40775
40777
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
40776
40778
  throw new Error('Invalid Pro2 resource manifest');
40777
40779
  }
40778
40780
  const manifest = value;
40779
- if (manifest.schema !== 1 ||
40780
- manifest.variant !== 'resource' ||
40781
- manifest.device_root !== 'vol0:' ||
40782
- manifest.restore_mode !== 'bootloader_update' ||
40783
- !Array.isArray(manifest.trees) ||
40784
- !Array.isArray(manifest.files)) {
40785
- throw new Error('Invalid Pro2 resource manifest contract');
40781
+ if (!Array.isArray(manifest.files)) {
40782
+ throw new Error('Invalid Pro2 resource manifest files');
40786
40783
  }
40787
40784
  const files = manifest.files.map(parseProtocolV2ResourceManifestFile);
40788
40785
  const devicePaths = new Set(files.map(file => file.device_path));
@@ -40795,27 +40792,6 @@ function parseProtocolV2ResourceManifest(value) {
40795
40792
  throw new Error('Invalid Pro2 resource manifest file set');
40796
40793
  }
40797
40794
  return {
40798
- schema: 1,
40799
- artifact_name: assertManifestString(manifest.artifact_name, 'artifact_name'),
40800
- release_name: assertManifestString(manifest.release_name, 'release_name'),
40801
- variant: 'resource',
40802
- commit: assertManifestString(manifest.commit, 'commit'),
40803
- short_sha: assertManifestString(manifest.short_sha, 'short_sha'),
40804
- timestamp_utc: assertManifestString(manifest.timestamp_utc, 'timestamp_utc'),
40805
- core_version: assertManifestString(manifest.core_version, 'core_version'),
40806
- key_set: assertManifestString(manifest.key_set, 'key_set'),
40807
- device_root: 'vol0:',
40808
- restore_mode: 'bootloader_update',
40809
- trees: manifest.trees.map((tree, index) => {
40810
- if (!tree || typeof tree !== 'object') {
40811
- throw new Error(`Invalid Pro2 resource manifest trees[${index}]`);
40812
- }
40813
- const item = tree;
40814
- return {
40815
- path: assertManifestRelativePath(item.path, `trees[${index}].path`),
40816
- device: assertManifestString(item.device, `trees[${index}].device`),
40817
- };
40818
- }),
40819
40795
  files,
40820
40796
  };
40821
40797
  }
@@ -44250,10 +44226,10 @@ const getProtocolV2RuntimeMode = (protocolInfo, deviceInfo) => {
44250
44226
  return 'normal';
44251
44227
  if (binary)
44252
44228
  return binary;
44253
- if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _b === void 0 ? void 0 : _b.application)) {
44254
- if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _c === void 0 ? void 0 : _c.romloader)
44229
+ if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _b === void 0 ? void 0 : _b.application)) {
44230
+ if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _c === void 0 ? void 0 : _c.romloader)
44255
44231
  return 'romloader';
44256
- if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.fw) === null || _d === void 0 ? void 0 : _d.bootloader)
44232
+ if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _d === void 0 ? void 0 : _d.bootloader)
44257
44233
  return 'bootloader';
44258
44234
  }
44259
44235
  return undefined;
@@ -44263,7 +44239,7 @@ const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.su
44263
44239
  const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
44264
44240
  targets: {
44265
44241
  hw: true,
44266
- fw: true,
44242
+ main_mcu: true,
44267
44243
  coprocessor: true,
44268
44244
  },
44269
44245
  types: {
@@ -44274,7 +44250,7 @@ const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
44274
44250
  const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
44275
44251
  targets: {
44276
44252
  hw: true,
44277
- fw: true,
44253
+ main_mcu: true,
44278
44254
  coprocessor: true,
44279
44255
  se1: true,
44280
44256
  se2: true,
@@ -44289,7 +44265,7 @@ const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
44289
44265
  const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
44290
44266
  targets: {
44291
44267
  hw: true,
44292
- fw: true,
44268
+ main_mcu: true,
44293
44269
  coprocessor: true,
44294
44270
  se1: true,
44295
44271
  se2: true,
@@ -44556,11 +44532,11 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
44556
44532
  }
44557
44533
  : { mode },
44558
44534
  versions: definedEntries({
44559
- firmware: imageVersion((_d = info.fw) === null || _d === void 0 ? void 0 : _d.application),
44560
- applicationP1: imageVersion((_e = info.fw) === null || _e === void 0 ? void 0 : _e.application),
44561
- applicationP2: imageVersion((_f = info.fw) === null || _f === void 0 ? void 0 : _f.application_data),
44562
- bootloader: imageVersion((_g = info.fw) === null || _g === void 0 ? void 0 : _g.bootloader),
44563
- board: imageVersion((_h = info.fw) === null || _h === void 0 ? void 0 : _h.romloader),
44535
+ firmware: imageVersion((_d = info.main_mcu) === null || _d === void 0 ? void 0 : _d.application),
44536
+ applicationP1: imageVersion((_e = info.main_mcu) === null || _e === void 0 ? void 0 : _e.application),
44537
+ applicationP2: imageVersion((_f = info.main_mcu) === null || _f === void 0 ? void 0 : _f.application_data),
44538
+ bootloader: imageVersion((_g = info.main_mcu) === null || _g === void 0 ? void 0 : _g.bootloader),
44539
+ board: imageVersion((_h = info.main_mcu) === null || _h === void 0 ? void 0 : _h.romloader),
44564
44540
  ble: imageVersion((_j = info.coprocessor) === null || _j === void 0 ? void 0 : _j.application),
44565
44541
  se01: imageVersion((_k = info.se1) === null || _k === void 0 ? void 0 : _k.application),
44566
44542
  se02: imageVersion((_l = info.se2) === null || _l === void 0 ? void 0 : _l.application),
@@ -44572,16 +44548,16 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
44572
44548
  se04Boot: imageVersion((_s = info.se4) === null || _s === void 0 ? void 0 : _s.bootloader),
44573
44549
  }),
44574
44550
  verification: definedEntries({
44575
- firmwareBuildId: imageBuildId((_t = info.fw) === null || _t === void 0 ? void 0 : _t.application),
44576
- firmwareHash: imageHash((_u = info.fw) === null || _u === void 0 ? void 0 : _u.application),
44577
- applicationP1BuildId: imageBuildId((_v = info.fw) === null || _v === void 0 ? void 0 : _v.application),
44578
- applicationP1Hash: imageHash((_w = info.fw) === null || _w === void 0 ? void 0 : _w.application),
44579
- applicationP2BuildId: imageBuildId((_x = info.fw) === null || _x === void 0 ? void 0 : _x.application_data),
44580
- applicationP2Hash: imageHash((_y = info.fw) === null || _y === void 0 ? void 0 : _y.application_data),
44581
- bootloaderBuildId: imageBuildId((_z = info.fw) === null || _z === void 0 ? void 0 : _z.bootloader),
44582
- bootloaderHash: imageHash((_0 = info.fw) === null || _0 === void 0 ? void 0 : _0.bootloader),
44583
- boardBuildId: imageBuildId((_1 = info.fw) === null || _1 === void 0 ? void 0 : _1.romloader),
44584
- boardHash: imageHash((_2 = info.fw) === null || _2 === void 0 ? void 0 : _2.romloader),
44551
+ firmwareBuildId: imageBuildId((_t = info.main_mcu) === null || _t === void 0 ? void 0 : _t.application),
44552
+ firmwareHash: imageHash((_u = info.main_mcu) === null || _u === void 0 ? void 0 : _u.application),
44553
+ applicationP1BuildId: imageBuildId((_v = info.main_mcu) === null || _v === void 0 ? void 0 : _v.application),
44554
+ applicationP1Hash: imageHash((_w = info.main_mcu) === null || _w === void 0 ? void 0 : _w.application),
44555
+ applicationP2BuildId: imageBuildId((_x = info.main_mcu) === null || _x === void 0 ? void 0 : _x.application_data),
44556
+ applicationP2Hash: imageHash((_y = info.main_mcu) === null || _y === void 0 ? void 0 : _y.application_data),
44557
+ bootloaderBuildId: imageBuildId((_z = info.main_mcu) === null || _z === void 0 ? void 0 : _z.bootloader),
44558
+ bootloaderHash: imageHash((_0 = info.main_mcu) === null || _0 === void 0 ? void 0 : _0.bootloader),
44559
+ boardBuildId: imageBuildId((_1 = info.main_mcu) === null || _1 === void 0 ? void 0 : _1.romloader),
44560
+ boardHash: imageHash((_2 = info.main_mcu) === null || _2 === void 0 ? void 0 : _2.romloader),
44585
44561
  bleBuildId: imageBuildId((_3 = info.coprocessor) === null || _3 === void 0 ? void 0 : _3.application),
44586
44562
  bleHash: imageHash((_4 = info.coprocessor) === null || _4 === void 0 ? void 0 : _4.application),
44587
44563
  se01BuildId: imageBuildId((_5 = info.se1) === null || _5 === void 0 ? void 0 : _5.application),
@@ -51670,7 +51646,6 @@ const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
51670
51646
  const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
51671
51647
  const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
51672
51648
  const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
51673
- const PROTOCOL_V2_START_UPDATE_TIMEOUT = 3 * 60 * 1000;
51674
51649
  const PROTOCOL_V2_INSTALL_TIMEOUT = 8 * 60 * 1000;
51675
51650
  const PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT = 30 * 1000;
51676
51651
  const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
@@ -51693,6 +51668,10 @@ const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
51693
51668
  const PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES = 1024 * 1024;
51694
51669
  const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
51695
51670
  const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
51671
+ const getProtocolV2LocalResourceArchivePath = (entryName) => {
51672
+ const match = entryName.match(/(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu);
51673
+ return match === null || match === void 0 ? void 0 : match[1];
51674
+ };
51696
51675
  const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set(['se03', 'se04']);
51697
51676
  const getProtocolV2ZipEntrySizes = (entry) => {
51698
51677
  var _a;
@@ -51831,36 +51810,12 @@ const isProtocolV2ReconnectProbeError = (error) => {
51831
51810
  return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
51832
51811
  message.includes('did not respond to expected protocol'));
51833
51812
  };
51834
- const PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES = new Set([
51835
- hdShared.HardwareErrorCode.BleConnectedError,
51836
- hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
51837
- hdShared.HardwareErrorCode.BleForceCleanRunPromise,
51838
- hdShared.HardwareErrorCode.BleDeviceDisconnected,
51839
- ]);
51840
- const isProtocolV2BleInstallInterruptionError = (error) => {
51841
- if (error instanceof hdShared.HardwareError &&
51842
- PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES.has(error.errorCode)) {
51843
- return true;
51844
- }
51845
- const message = getProtocolV2UnknownErrorText(error).toLowerCase();
51846
- const compactMessage = message.replace(/\s+/gu, '');
51847
- return (/react native ble transport (?:released|disconnected)/u.test(message) ||
51848
- (compactMessage.includes('rxerrorerror6') &&
51849
- (compactMessage.includes('multiplatformbleadapter') ||
51850
- compactMessage.includes('multipalformebleadapter'))));
51851
- };
51852
51813
  const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
51853
51814
  const message = getProtocolV2UnknownErrorText(error).toLowerCase();
51854
51815
  return (message.includes('handler not registered') ||
51855
51816
  message.includes('message handler not found') ||
51856
51817
  message.includes('unsupported message'));
51857
51818
  };
51858
- const isProtocolV2FirmwareUpdateEndpointUnavailable = (error) => {
51859
- const message = getProtocolV2UnknownErrorText(error).toLowerCase();
51860
- return (message.includes('handler not registered') ||
51861
- message.includes('message handler not found') ||
51862
- message.includes('unsupported message'));
51863
- };
51864
51819
  const isProtocolV2TerminalInstallStatusError = (error) => {
51865
51820
  var _a;
51866
51821
  return error instanceof hdShared.HardwareError &&
@@ -51993,11 +51948,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51993
51948
  this.protocolV2HasExplicitTargetSelection = false;
51994
51949
  this.protocolV2PreparedSources = [];
51995
51950
  this.protocolV2ExecutionInLoader = false;
51996
- this.protocolV2LegacyDirectUpdate = false;
51997
51951
  this.protocolV2BootResourceStagingSafe = false;
51998
51952
  this.protocolV2CompletedTargetVersions = new Map();
51999
51953
  this.protocolV2FinalStatusVerified = false;
52000
- this.protocolV2InstallAckReceived = false;
52001
51954
  this.protocolV2InstallBaselineVersions = new Map();
52002
51955
  }
52003
51956
  getSupportedProtocols() {
@@ -52493,60 +52446,63 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
52493
52446
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unsafe entry path', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52494
52447
  }
52495
52448
  const entries = zipEntries.filter(entry => !entry.dir);
52496
- if (entries.length === 0 || entries.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT + 1) {
52449
+ if (entries.length === 0) {
52497
52450
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP entry set is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52498
52451
  }
52499
- let declaredUncompressedSize = 0;
52500
- let declaredCompressedSize = 0;
52501
- for (const entry of entries) {
52502
- const sizes = getProtocolV2ZipEntrySizes(entry);
52503
- declaredCompressedSize += sizes.compressedSize;
52504
- declaredUncompressedSize += sizes.uncompressedSize;
52505
- const entryLimit = entry.name === 'manifest.json'
52506
- ? PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
52507
- : PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES;
52508
- if (sizes.uncompressedSize > entryLimit ||
52509
- declaredCompressedSize > binary.byteLength ||
52510
- declaredUncompressedSize >
52511
- PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES + PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
52512
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP declared size exceeds the allowed limit', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52452
+ const manifestEntry = entries.find(entry => entry.name.split('/').pop() === 'manifest.json');
52453
+ let manifestBinary;
52454
+ let manifestDirectory = '';
52455
+ let selectedFiles;
52456
+ if (manifestEntry) {
52457
+ if (getProtocolV2ZipEntrySizes(manifestEntry).uncompressedSize >
52458
+ PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
52459
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52513
52460
  }
52461
+ manifestBinary = yield manifestEntry.async('arraybuffer');
52462
+ if (manifestBinary.byteLength <= 0 ||
52463
+ manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
52464
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52465
+ }
52466
+ let manifestValue;
52467
+ try {
52468
+ manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
52469
+ }
52470
+ catch (error) {
52471
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource manifest is invalid: ${String(error)}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52472
+ }
52473
+ selectedFiles = selectProtocolV2ResourceManifestFiles({
52474
+ manifest: parseProtocolV2ResourceManifest(manifestValue),
52475
+ targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
52476
+ });
52477
+ manifestDirectory = manifestEntry.name.slice(0, -'manifest.json'.length);
52514
52478
  }
52515
- const manifestEntry = zip.file('manifest.json');
52516
- if (!manifestEntry) {
52517
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP has no manifest.json', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52518
- }
52519
- const manifestBinary = yield manifestEntry.async('arraybuffer');
52520
- if (manifestBinary.byteLength <= 0 ||
52521
- manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
52522
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52523
- }
52524
- let manifestValue;
52525
- try {
52526
- manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
52527
- }
52528
- catch (error) {
52529
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource manifest is invalid: ${String(error)}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52479
+ else {
52480
+ selectedFiles = entries.flatMap(entry => {
52481
+ var _a;
52482
+ const archivePath = getProtocolV2LocalResourceArchivePath(entry.name);
52483
+ if (!archivePath)
52484
+ return [];
52485
+ return [
52486
+ {
52487
+ archive_path: archivePath,
52488
+ original_name: (_a = archivePath.split('/').pop()) !== null && _a !== void 0 ? _a : archivePath,
52489
+ device_path: `vol0:/${archivePath}`,
52490
+ size: getProtocolV2ZipEntrySizes(entry).uncompressedSize,
52491
+ sha256: '',
52492
+ },
52493
+ ];
52494
+ });
52530
52495
  }
52531
- const manifest = parseProtocolV2ResourceManifest(manifestValue);
52532
- const selectedFiles = selectProtocolV2ResourceManifestFiles({
52533
- manifest,
52534
- targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
52535
- });
52536
- const expectedEntryNames = new Set([
52537
- 'manifest.json',
52538
- ...selectedFiles.map(file => file.archive_path),
52539
- ]);
52540
- if (entries.length !== expectedEntryNames.size ||
52541
- entries.some(entry => !expectedEntryNames.has(entry.name))) {
52542
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unexpected entry', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52496
+ if (selectedFiles.length === 0 || selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
52497
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP has no resource packages', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52543
52498
  }
52544
52499
  let totalSize = 0;
52545
- const materializedEntries = [
52546
- { entryName: 'manifest.json', binary: manifestBinary },
52547
- ];
52500
+ const materializedEntries = [];
52501
+ const normalizedFiles = [];
52548
52502
  for (const file of selectedFiles) {
52549
- const entry = zip.file(file.archive_path);
52503
+ const entry = manifestEntry
52504
+ ? zip.file(`${manifestDirectory}${file.archive_path}`)
52505
+ : entries.find(candidate => getProtocolV2LocalResourceArchivePath(candidate.name) === file.archive_path);
52550
52506
  if (!entry) {
52551
52507
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource ZIP is missing ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
52552
52508
  }
@@ -52557,11 +52513,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
52557
52513
  }
52558
52514
  const fileBinary = yield entry.async('arraybuffer');
52559
52515
  const digest = bytesToHex(sha256.sha256(new Uint8Array(fileBinary)));
52560
- if (fileBinary.byteLength !== file.size || digest !== file.sha256.toLowerCase()) {
52516
+ if (fileBinary.byteLength !== file.size ||
52517
+ (file.sha256 && digest !== file.sha256.toLowerCase())) {
52561
52518
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource file does not match manifest: ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
52562
52519
  }
52520
+ normalizedFiles.push(Object.assign(Object.assign({}, file), { sha256: digest }));
52563
52521
  materializedEntries.push({ entryName: file.archive_path, binary: fileBinary });
52564
52522
  }
52523
+ manifestBinary !== null && manifestBinary !== void 0 ? manifestBinary : (manifestBinary = new TextEncoder().encode(JSON.stringify({ files: normalizedFiles })).buffer);
52524
+ materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
52565
52525
  return { binary, materializedEntries };
52566
52526
  });
52567
52527
  }
@@ -53148,11 +53108,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53148
53108
  }
53149
53109
  return ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader';
53150
53110
  }
53151
- isLegacyProtocolV2Runtime() {
53152
- var _a, _b;
53153
- const protocolInfo = (_b = (_a = this.device.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2ProtocolInfo;
53154
- return protocolInfo ? isLegacyProtocolV2ProtocolInfo(protocolInfo) : false;
53155
- }
53156
53111
  rebootProtocolV2ToBootloader() {
53157
53112
  return __awaiter(this, void 0, void 0, function* () {
53158
53113
  try {
@@ -53175,16 +53130,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53175
53130
  }
53176
53131
  enterProtocolV2BootloaderMode() {
53177
53132
  return __awaiter(this, void 0, void 0, function* () {
53178
- this.protocolV2LegacyDirectUpdate = false;
53179
53133
  if (this.isProtocolV2RomloaderMode()) {
53180
53134
  Log$6.debug('Protocol V2 device is in romloader mode; start firmware update directly');
53181
- this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
53182
53135
  this.protocolV2ExecutionInLoader = true;
53183
53136
  return false;
53184
53137
  }
53185
53138
  if (this.isProtocolV2BootloaderMode()) {
53186
53139
  Log$6.debug('Protocol V2 device is already in bootloader mode, skip reboot');
53187
- this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
53188
53140
  this.protocolV2ExecutionInLoader = true;
53189
53141
  this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
53190
53142
  return false;
@@ -53544,7 +53496,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53544
53496
  let missingTargetStatusSince;
53545
53497
  let missingTargetStatusKey;
53546
53498
  let normalModeWithoutInstallEvidenceSince;
53547
- let installEvidenceObserved = this.protocolV2InstallAckReceived;
53499
+ let installEvidenceObserved = false;
53548
53500
  const resetMissingTargetStatusGrace = () => {
53549
53501
  missingTargetStatusSince = undefined;
53550
53502
  missingTargetStatusKey = undefined;
@@ -53559,13 +53511,18 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53559
53511
  }
53560
53512
  const currentDeviceInfo = deviceInfo;
53561
53513
  try {
53562
- const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
53514
+ const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', ['DeviceFirmwareUpdateStatus', 'Success'], {
53563
53515
  fields: {
53564
53516
  status: true,
53565
53517
  payload_version: true,
53566
53518
  path: true,
53567
53519
  },
53568
53520
  }, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
53521
+ if (statusResponse.type === 'Success') {
53522
+ this.protocolV2FinalStatusVerified = true;
53523
+ this.postProgressMessage(100, 'installingFirmware');
53524
+ return;
53525
+ }
53569
53526
  const statusTargets = ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : []);
53570
53527
  if (statusTargets.some(target => {
53571
53528
  const targetId = normalizeProtocolV2TargetId(target.target_id);
@@ -53870,46 +53827,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53870
53827
  }
53871
53828
  protocolV2StartFirmwareUpdate({ targets, }) {
53872
53829
  return __awaiter(this, void 0, void 0, function* () {
53873
- this.protocolV2InstallAckReceived = false;
53874
53830
  this.protocolV2LastRuntimeProbeFeatures = undefined;
53875
- const startUpdate = () => this.device
53876
- .getCommands()
53877
- .typedCall('DeviceFirmwareUpdateRequest', 'Success', { targets }, { timeoutMs: PROTOCOL_V2_START_UPDATE_TIMEOUT });
53878
- let response;
53879
- try {
53880
- response = yield startUpdate();
53881
- this.protocolV2InstallAckReceived = true;
53882
- }
53883
- catch (error) {
53884
- if (this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(error)) {
53885
- this.throwIfAborted();
53886
- Log$6.log('[FirmwareUpdateV4] install request interrupted by device reboot; continue status polling: ', error);
53887
- }
53888
- else if (this.protocolV2LegacyDirectUpdate &&
53889
- isProtocolV2FirmwareUpdateEndpointUnavailable(error)) {
53890
- this.protocolV2LegacyDirectUpdate = false;
53891
- Log$6.debug('[FirmwareUpdateV4] legacy App does not expose DeviceFirmwareUpdateRequest; rebooting to bootloader');
53892
- yield this.rebootProtocolV2ToBootloader();
53893
- try {
53894
- response = yield startUpdate();
53895
- this.protocolV2InstallAckReceived = true;
53896
- }
53897
- catch (retryError) {
53898
- if (!(this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(retryError))) {
53899
- throw retryError;
53900
- }
53901
- this.throwIfAborted();
53902
- Log$6.log('[FirmwareUpdateV4] install request interrupted after legacy reboot; continue status polling: ', retryError);
53903
- }
53904
- }
53905
- else {
53906
- throw error;
53907
- }
53908
- }
53909
- this.protocolV2LegacyDirectUpdate = false;
53831
+ const commands = this.device.getCommands();
53832
+ yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
53833
+ yield commands.call('DeviceFirmwareUpdateRequest', {}, { returnAfterWrite: true });
53910
53834
  this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdating);
53911
53835
  this.postProgressMessage(0, 'installingFirmware');
53912
- return response;
53913
53836
  });
53914
53837
  }
53915
53838
  protocolV2Reboot(rebootType) {
@@ -63481,11 +63404,10 @@ class TonSignMessage extends BaseMethod {
63481
63404
  super(...arguments);
63482
63405
  this.initState = null;
63483
63406
  this.processTxRequest = (request, data) => __awaiter(this, void 0, void 0, function* () {
63484
- var _a;
63485
63407
  if (!request.init_data_length) {
63486
63408
  const deviceType = this.device.getCurrentDeviceType();
63487
63409
  const hasClassic = DeviceModelToTypes.model_classic1s.includes(deviceType);
63488
- const signingMessage = (_a = request.signing_message) !== null && _a !== void 0 ? _a : request.signning_message;
63410
+ const signingMessage = request.signning_message;
63489
63411
  const shouldSkipValidation = signingMessage == null;
63490
63412
  return Promise.resolve(Object.assign(Object.assign({}, request), { signing_message: signingMessage, skip_validate: hasClassic || shouldSkipValidation }));
63491
63413
  }
@@ -29,7 +29,7 @@ export declare const supportsProtocolV2Message: (protocolInfo: ProtocolInfo, mes
29
29
  export declare const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST: {
30
30
  targets: {
31
31
  hw: boolean;
32
- fw: boolean;
32
+ main_mcu: boolean;
33
33
  coprocessor: boolean;
34
34
  };
35
35
  types: {
@@ -40,7 +40,7 @@ export declare const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST: {
40
40
  export declare const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST: {
41
41
  targets: {
42
42
  hw: boolean;
43
- fw: boolean;
43
+ main_mcu: boolean;
44
44
  coprocessor: boolean;
45
45
  se1: boolean;
46
46
  se2: boolean;
@@ -55,7 +55,7 @@ export declare const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST: {
55
55
  export declare const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST: {
56
56
  targets: {
57
57
  hw: boolean;
58
- fw: boolean;
58
+ main_mcu: boolean;
59
59
  coprocessor: boolean;
60
60
  se1: boolean;
61
61
  se2: boolean;
@@ -72,7 +72,7 @@ export declare const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST: {
72
72
  export declare const PROTOCOL_V2_DEVICE_INFO_REQUEST: {
73
73
  targets: {
74
74
  hw: boolean;
75
- fw: boolean;
75
+ main_mcu: boolean;
76
76
  coprocessor: boolean;
77
77
  se1: boolean;
78
78
  se2: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAE7E,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AAkBpF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;AA0FD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,2BAA2B,CAmD3F;AAED,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,eAAe,GAChB,EAAE;IACD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACpD,GAAG,+BAA+B,EAAE,CAEpC"}
1
+ {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EACrB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAE7E,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AAkBpF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;AAiFD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,2BAA2B,CAuB3F;AAED,wBAAgB,qCAAqC,CAAC,EACpD,QAAQ,EACR,eAAe,GAChB,EAAE;IACD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACpD,GAAG,+BAA+B,EAAE,CAEpC"}