@onekeyfe/hd-core 1.2.0-alpha.79 → 1.2.0-alpha.80

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 (53) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +51 -5
  2. package/__tests__/check-firmware-release-protocol-v2.test.ts +164 -0
  3. package/__tests__/protocol-v2-resources.test.ts +24 -8
  4. package/__tests__/protocol-v2.test.ts +195 -49
  5. package/dist/api/CheckAllFirmwareRelease.d.ts +2 -3
  6. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  7. package/dist/api/CheckBLEFirmwareRelease.d.ts +2 -1
  8. package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
  9. package/dist/api/CheckBootloaderRelease.d.ts +3 -2
  10. package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
  11. package/dist/api/CheckFirmwareRelease.d.ts +2 -1
  12. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  13. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  14. package/dist/api/firmware/protocolV2Release.d.ts +33 -0
  15. package/dist/api/firmware/protocolV2Release.d.ts.map +1 -0
  16. package/dist/index.d.ts +35 -49
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +340 -183
  19. package/dist/protocols/protocol-v2/resources.d.ts +0 -4
  20. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  21. package/dist/types/api/checkAllFirmwareRelease.d.ts +20 -9
  22. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  23. package/dist/types/api/checkBLEFirmwareRelease.d.ts +2 -13
  24. package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
  25. package/dist/types/api/checkBootloaderRelease.d.ts +2 -6
  26. package/dist/types/api/checkBootloaderRelease.d.ts.map +1 -1
  27. package/dist/types/api/checkFirmwareRelease.d.ts +2 -13
  28. package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
  29. package/dist/types/api/checkFirmwareTypeAvailable.d.ts +2 -2
  30. package/dist/types/api/checkFirmwareTypeAvailable.d.ts.map +1 -1
  31. package/dist/types/api/export.d.ts +1 -1
  32. package/dist/types/api/export.d.ts.map +1 -1
  33. package/dist/types/api/firmwareUpdate.d.ts +1 -1
  34. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  35. package/dist/types/settings.d.ts +3 -1
  36. package/dist/types/settings.d.ts.map +1 -1
  37. package/package.json +4 -4
  38. package/src/api/CheckAllFirmwareRelease.ts +49 -49
  39. package/src/api/CheckBLEFirmwareRelease.ts +41 -3
  40. package/src/api/CheckBootloaderRelease.ts +40 -1
  41. package/src/api/CheckFirmwareRelease.ts +37 -3
  42. package/src/api/FirmwareUpdateV4.ts +35 -15
  43. package/src/api/firmware/protocolV2Release.ts +166 -0
  44. package/src/index.ts +0 -1
  45. package/src/protocols/protocol-v2/resources.ts +19 -25
  46. package/src/types/api/checkAllFirmwareRelease.ts +27 -13
  47. package/src/types/api/checkBLEFirmwareRelease.ts +4 -13
  48. package/src/types/api/checkBootloaderRelease.ts +2 -6
  49. package/src/types/api/checkFirmwareRelease.ts +2 -13
  50. package/src/types/api/checkFirmwareTypeAvailable.ts +2 -2
  51. package/src/types/api/export.ts +6 -1
  52. package/src/types/api/firmwareUpdate.ts +2 -3
  53. package/src/types/settings.ts +3 -1
package/dist/index.js CHANGED
@@ -1287,12 +1287,22 @@ function parseProtocolV2Resources(value) {
1287
1287
  if (!source || typeof source !== 'object') {
1288
1288
  throw new Error('Invalid Pro2 resources config: source is required');
1289
1289
  }
1290
- const { manifestUrl } = source;
1291
- if (typeof manifestUrl !== 'string' || !manifestUrl.startsWith('https://')) {
1292
- throw new Error('Invalid Pro2 resources config: source.manifestUrl must use HTTPS');
1290
+ const { archiveUrl, archiveSha256, archiveSize } = source;
1291
+ if (typeof archiveUrl !== 'string' || !archiveUrl.startsWith('https://')) {
1292
+ throw new Error('Invalid Pro2 resources config: source.archiveUrl must use HTTPS');
1293
+ }
1294
+ if (typeof archiveSha256 !== 'string' || !/^[0-9a-fA-F]{64}$/.test(archiveSha256)) {
1295
+ throw new Error('Invalid Pro2 resources config: source.archiveSha256 must be a SHA-256 digest');
1296
+ }
1297
+ if (!Number.isSafeInteger(archiveSize) || archiveSize <= 0) {
1298
+ throw new Error('Invalid Pro2 resources config: source.archiveSize must be a positive integer');
1293
1299
  }
1294
1300
  return {
1295
- source: { manifestUrl },
1301
+ source: {
1302
+ archiveUrl,
1303
+ archiveSha256: archiveSha256.toLowerCase(),
1304
+ archiveSize: archiveSize,
1305
+ },
1296
1306
  };
1297
1307
  }
1298
1308
  const PROTOCOL_V2_RESOURCE_MANIFEST_DEVICE_ROOTS = [
@@ -1418,20 +1428,7 @@ function parseProtocolV2ResourceManifest(value) {
1418
1428
  };
1419
1429
  }
1420
1430
  function selectProtocolV2ResourceManifestFiles({ manifest, targetsToUpdate, }) {
1421
- const targets = new Set(targetsToUpdate);
1422
- return manifest.files.filter(file => {
1423
- if (file.device_path.startsWith('vol0:/bundles/')) {
1424
- return targets.has('resource');
1425
- }
1426
- return targets.has('boot_resources');
1427
- });
1428
- }
1429
- function resolveProtocolV2ResourceManifestFileUrl({ manifestUrl, archivePath, }) {
1430
- const url = new URL(assertManifestRelativePath(archivePath, 'archive_path'), manifestUrl);
1431
- if (url.protocol !== 'https:') {
1432
- throw new Error('Invalid Pro2 resource manifest file URL');
1433
- }
1434
- return url.toString();
1431
+ return targetsToUpdate.includes('resource') ? [...manifest.files] : [];
1435
1432
  }
1436
1433
  function prepareProtocolV2ResourceFiles({ manifest: value, files, targetsToUpdate, }) {
1437
1434
  const manifest = parseProtocolV2ResourceManifest(value);
@@ -47303,76 +47300,93 @@ class ClearSessionCache extends BaseMethod {
47303
47300
  }
47304
47301
  }
47305
47302
 
47306
- class CheckFirmwareRelease extends BaseMethod {
47307
- init() {
47308
- this.allowDeviceMode = [
47309
- ...this.allowDeviceMode,
47310
- UI_REQUEST.NOT_INITIALIZE,
47311
- UI_REQUEST.BOOTLOADER,
47312
- ];
47313
- this.useDevicePassphraseState = false;
47314
- this.skipForceUpdateCheck = true;
47315
- }
47316
- run() {
47317
- var _a;
47318
- const payload = this.payload;
47319
- if (this.device.features) {
47320
- const deviceFirmwareType = this.device.getCurrentFirmwareType();
47321
- const firmwareType = (_a = payload.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
47322
- const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
47323
- return Promise.resolve(releaseInfo);
47303
+ const PROTOCOL_V2_MAIN_FIRMWARE_TARGETS = [
47304
+ 'APPLICATION_P1',
47305
+ 'APPLICATION_P2',
47306
+ 'SE01',
47307
+ 'SE02',
47308
+ 'SE03',
47309
+ 'SE04',
47310
+ ];
47311
+ const PROTOCOL_V2_BLE_TARGETS = [
47312
+ 'COPROCESSOR',
47313
+ ];
47314
+ const PROTOCOL_V2_BOOTLOADER_TARGETS = [
47315
+ 'BOOTLOADER',
47316
+ ];
47317
+ function loadProtocolV2FirmwareReleaseContext({ device, firmwareType: firmwareTypeParam, checkFirmwareHash = false, methodName, }) {
47318
+ var _a;
47319
+ return __awaiter(this, void 0, void 0, function* () {
47320
+ const state = yield device.getDeviceState({
47321
+ refreshSections: checkFirmwareHash
47322
+ ? ['identity', 'versions', 'verification']
47323
+ : ['identity', 'versions'],
47324
+ });
47325
+ if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
47326
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, `${methodName} requires a Pro2 or Neo device for Protocol V2`);
47324
47327
  }
47325
- return Promise.resolve(null);
47326
- }
47328
+ const { features } = device;
47329
+ if (!features) {
47330
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `${methodName} requires initialized device features`);
47331
+ }
47332
+ const firmwareType = (_a = firmwareTypeParam !== null && firmwareTypeParam !== void 0 ? firmwareTypeParam : state.identity.firmwareType) !== null && _a !== void 0 ? _a : hdShared.EFirmwareType.Universal;
47333
+ return {
47334
+ state: state,
47335
+ features,
47336
+ firmwareType,
47337
+ release: DataManager.getFirmwareLatestRelease(features, firmwareType),
47338
+ };
47339
+ });
47327
47340
  }
47328
-
47329
- class CheckBLEFirmwareRelease extends BaseMethod {
47330
- init() {
47331
- this.allowDeviceMode = [
47332
- ...this.allowDeviceMode,
47333
- UI_REQUEST.NOT_INITIALIZE,
47334
- UI_REQUEST.BOOTLOADER,
47335
- ];
47336
- this.useDevicePassphraseState = false;
47337
- this.skipForceUpdateCheck = true;
47341
+ function summarizeProtocolV2FirmwareRelease(plan, componentTargets) {
47342
+ var _a;
47343
+ const targetSet = new Set(componentTargets);
47344
+ const components = plan.components.filter(component => targetSet.has(component.componentTarget));
47345
+ const targetsToUpdate = Array.from(new Set(components.flatMap(component => component.status === 'outdated' && component.updateTarget ? [component.updateTarget] : [])));
47346
+ const hasUpgrade = targetsToUpdate.length > 0;
47347
+ const required = !!((_a = plan.release) === null || _a === void 0 ? void 0 : _a.required) && hasUpgrade;
47348
+ let status = 'valid';
47349
+ if (!plan.release || components.length === 0) {
47350
+ status = 'unavailable';
47338
47351
  }
47339
- run() {
47340
- if (this.device.features) {
47341
- const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
47342
- return Promise.resolve(releaseInfo);
47343
- }
47344
- return Promise.resolve(null);
47352
+ else if (required) {
47353
+ status = 'required';
47354
+ }
47355
+ else if (hasUpgrade) {
47356
+ status = 'outdated';
47357
+ }
47358
+ else if (components.some(component => component.status === 'unknown')) {
47359
+ status = 'unknown';
47345
47360
  }
47361
+ else if (components.every(component => component.status === 'unsupported')) {
47362
+ status = 'unavailable';
47363
+ }
47364
+ return Object.assign(Object.assign({}, plan), { status,
47365
+ hasUpgrade,
47366
+ required,
47367
+ components,
47368
+ targetsToUpdate });
47346
47369
  }
47347
-
47348
- class CheckBridgeStatus extends BaseMethod {
47349
- init() {
47350
- this.useDevice = false;
47351
- this.useDevicePassphraseState = false;
47352
- this.skipForceUpdateCheck = true;
47370
+ function toProtocolV2FirmwareReleaseInfo({ plan, state, release, }) {
47371
+ return {
47372
+ shouldUpdate: plan.hasUpgrade,
47373
+ status: plan.status === 'unavailable' ? 'unknown' : plan.status,
47374
+ changelog: plan.release ? [plan.release.changelog] : [],
47375
+ release,
47376
+ bootloaderMode: state.status.mode === 'bootloader' || state.status.mode === 'romloader',
47377
+ };
47378
+ }
47379
+ function getProtocolV2ComponentReleaseInfo(plan, componentTarget) {
47380
+ var _a;
47381
+ const componentRelease = plan.components.find(component => component.componentTarget === componentTarget);
47382
+ if (!componentRelease || !plan.release) {
47383
+ return undefined;
47353
47384
  }
47354
- run() {
47355
- return __awaiter(this, void 0, void 0, function* () {
47356
- return new Promise((resolve, reject) => {
47357
- axios__default["default"]
47358
- .request({
47359
- url: 'http://localhost:21320',
47360
- method: 'POST',
47361
- withCredentials: false,
47362
- timeout: 3000,
47363
- })
47364
- .then(() => resolve(true))
47365
- .catch(e => {
47366
- if (e.code === 'ECONNABORTED') {
47367
- reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError));
47368
- }
47369
- else {
47370
- resolve(false);
47371
- }
47372
- });
47373
- });
47374
- });
47385
+ const component = (_a = plan.release.components) === null || _a === void 0 ? void 0 : _a[componentRelease.configKey];
47386
+ if (!component) {
47387
+ return undefined;
47375
47388
  }
47389
+ return Object.assign(Object.assign({}, component), { protocol: 'V2', configKey: componentRelease.configKey, componentTarget, required: plan.release.required, changelog: plan.release.changelog });
47376
47390
  }
47377
47391
 
47378
47392
  const REQUIRED_BRIDGE_VERSION = '2.2.0';
@@ -47429,56 +47443,6 @@ function getBridgeReleaseInfo({ deviceType, currentFirmwareVersion, willUpdateFi
47429
47443
  });
47430
47444
  }
47431
47445
 
47432
- class CheckBridgeRelease extends BaseMethod {
47433
- init() {
47434
- this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
47435
- this.useDevicePassphraseState = false;
47436
- this.skipForceUpdateCheck = true;
47437
- }
47438
- run() {
47439
- return __awaiter(this, void 0, void 0, function* () {
47440
- if (!this.device.features) {
47441
- return null;
47442
- }
47443
- const { willUpdateFirmwareVersion } = this.payload;
47444
- const { features } = this.device;
47445
- const deviceType = getDeviceType(features);
47446
- const currentFirmwareVersion = getDeviceFirmwareVersion(features).join('.');
47447
- return getBridgeReleaseInfo({
47448
- deviceType,
47449
- currentFirmwareVersion,
47450
- willUpdateFirmwareVersion,
47451
- });
47452
- });
47453
- }
47454
- }
47455
-
47456
- class CheckBootloaderRelease extends BaseMethod {
47457
- init() {
47458
- this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
47459
- this.useDevicePassphraseState = false;
47460
- this.skipForceUpdateCheck = true;
47461
- }
47462
- run() {
47463
- var _a;
47464
- return __awaiter(this, void 0, void 0, function* () {
47465
- if (!this.device.features) {
47466
- return null;
47467
- }
47468
- const { features } = this.device;
47469
- const payload = this.payload;
47470
- const deviceFirmwareType = this.device.getCurrentFirmwareType();
47471
- const firmwareType = (_a = payload.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
47472
- const releaseInfo = getBootloaderReleaseInfo({
47473
- features,
47474
- willUpdateFirmwareVersion: payload.willUpdateFirmwareVersion,
47475
- firmwareType,
47476
- });
47477
- return Promise.resolve(releaseInfo);
47478
- });
47479
- }
47480
- }
47481
-
47482
47446
  const UPDATE_TARGET_BY_COMPONENT_TARGET = {
47483
47447
  BOOTLOADER: 'boot',
47484
47448
  APPLICATION_P1: 'app_v1',
@@ -47724,24 +47688,15 @@ class CheckAllFirmwareRelease extends BaseMethod {
47724
47688
  });
47725
47689
  }
47726
47690
  runProtocolV2() {
47727
- var _a;
47728
47691
  return __awaiter(this, void 0, void 0, function* () {
47729
47692
  const { checkFirmwareHash = false, firmwareType: firmwareTypeParam } = this
47730
47693
  .payload;
47731
- const state = yield this.device.getDeviceState({
47732
- refreshSections: checkFirmwareHash
47733
- ? ['identity', 'versions', 'verification']
47734
- : ['identity', 'versions'],
47694
+ const { state, features, firmwareType, release } = yield loadProtocolV2FirmwareReleaseContext({
47695
+ device: this.device,
47696
+ firmwareType: firmwareTypeParam,
47697
+ checkFirmwareHash,
47698
+ methodName: 'checkAllFirmwareRelease',
47735
47699
  });
47736
- if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
47737
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, 'checkAllFirmwareRelease requires a Pro2 or Neo device for Protocol V2');
47738
- }
47739
- const { features } = this.device;
47740
- if (!features) {
47741
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'checkAllFirmwareRelease requires initialized device features');
47742
- }
47743
- const firmwareType = (_a = firmwareTypeParam !== null && firmwareTypeParam !== void 0 ? firmwareTypeParam : state.identity.firmwareType) !== null && _a !== void 0 ? _a : hdShared.EFirmwareType.Universal;
47744
- const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
47745
47700
  const plan = buildProtocolV2FirmwareRelease({
47746
47701
  currentVersions: state.versions,
47747
47702
  currentVerification: checkFirmwareHash ? state.verification : undefined,
@@ -47753,21 +47708,211 @@ class CheckAllFirmwareRelease extends BaseMethod {
47753
47708
  const resourceDeviceType = state.identity.deviceType === 'neo' ? hdShared.EDeviceType.Neo : hdShared.EDeviceType.Pro2;
47754
47709
  const resourceSource = DataManager.getProtocolV2ResourceSource(resourceDeviceType);
47755
47710
  const resourceStatus = 'unknown';
47756
- const targetsToUpdate = [...plan.targetsToUpdate];
47757
- const firmwareStatus = plan.status === 'unavailable' ? 'unknown' : plan.status;
47758
- const emptyRelease = 'none';
47759
- return Object.assign(Object.assign({ firmware: {
47760
- status: firmwareStatus,
47761
- changelog: release ? [release.changelog] : [],
47762
- release: release !== null && release !== void 0 ? release : emptyRelease,
47763
- bootloaderMode: state.status.mode === 'bootloader' || state.status.mode === 'romloader',
47764
- }, ble: {
47765
- status: 'valid',
47766
- release: emptyRelease,
47767
- }, bootloader: {
47768
- status: 'valid',
47769
- release: emptyRelease,
47770
- }, features, protocol: 'V2', deviceType: state.identity.deviceType }, plan), { resourceStatus, resourceManifestUrl: resourceSource === null || resourceSource === void 0 ? void 0 : resourceSource.manifestUrl, hasUpgrade: plan.hasUpgrade, targetsToUpdate });
47711
+ const resourcePreparationRequired = !!resourceSource;
47712
+ const targetsToUpdate = Array.from(new Set([
47713
+ ...plan.targetsToUpdate,
47714
+ ...(resourcePreparationRequired ? ['resource'] : []),
47715
+ ]));
47716
+ const firmwarePlan = summarizeProtocolV2FirmwareRelease(plan, PROTOCOL_V2_MAIN_FIRMWARE_TARGETS);
47717
+ const blePlan = summarizeProtocolV2FirmwareRelease(plan, PROTOCOL_V2_BLE_TARGETS);
47718
+ const bootloaderPlan = summarizeProtocolV2FirmwareRelease(plan, PROTOCOL_V2_BOOTLOADER_TARGETS);
47719
+ const status = resourcePreparationRequired && (plan.status === 'valid' || plan.status === 'unavailable')
47720
+ ? 'unknown'
47721
+ : plan.status;
47722
+ return Object.assign(Object.assign({ firmware: toProtocolV2FirmwareReleaseInfo({ plan: firmwarePlan, state, release }), ble: toProtocolV2FirmwareReleaseInfo({
47723
+ plan: blePlan,
47724
+ state,
47725
+ release: getProtocolV2ComponentReleaseInfo(plan, 'COPROCESSOR'),
47726
+ }), bootloader: toProtocolV2FirmwareReleaseInfo({
47727
+ plan: bootloaderPlan,
47728
+ state,
47729
+ release: getProtocolV2ComponentReleaseInfo(plan, 'BOOTLOADER'),
47730
+ }), features, protocol: 'V2', deviceType: state.identity.deviceType }, plan), { status,
47731
+ resourceStatus, resourceArchive: resourceSource, resourcePreparationRequired, hasUpgrade: plan.hasUpgrade || resourcePreparationRequired, targetsToUpdate });
47732
+ });
47733
+ }
47734
+ }
47735
+
47736
+ class CheckFirmwareRelease extends BaseMethod {
47737
+ getSupportedProtocols() {
47738
+ return ['V1', 'V2'];
47739
+ }
47740
+ init() {
47741
+ this.allowDeviceMode = [
47742
+ ...this.allowDeviceMode,
47743
+ UI_REQUEST.NOT_INITIALIZE,
47744
+ UI_REQUEST.BOOTLOADER,
47745
+ ];
47746
+ this.useDevicePassphraseState = false;
47747
+ this.skipForceUpdateCheck = true;
47748
+ }
47749
+ run() {
47750
+ var _a;
47751
+ return __awaiter(this, void 0, void 0, function* () {
47752
+ const payload = this.payload;
47753
+ if (this.device.isProtocolV2()) {
47754
+ const { state, firmwareType, release } = yield loadProtocolV2FirmwareReleaseContext({
47755
+ device: this.device,
47756
+ firmwareType: payload.firmwareType,
47757
+ methodName: 'checkFirmwareRelease',
47758
+ });
47759
+ const plan = summarizeProtocolV2FirmwareRelease(buildProtocolV2FirmwareRelease({
47760
+ currentVersions: state.versions,
47761
+ firmwareType,
47762
+ release,
47763
+ deviceType: state.identity.deviceType,
47764
+ }), PROTOCOL_V2_MAIN_FIRMWARE_TARGETS);
47765
+ return toProtocolV2FirmwareReleaseInfo({ plan, state, release });
47766
+ }
47767
+ if (this.device.features) {
47768
+ const deviceFirmwareType = this.device.getCurrentFirmwareType();
47769
+ const firmwareType = (_a = payload.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
47770
+ const releaseInfo = getFirmwareReleaseInfo(this.device.features, firmwareType);
47771
+ return releaseInfo;
47772
+ }
47773
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'checkFirmwareRelease requires initialized device features');
47774
+ });
47775
+ }
47776
+ }
47777
+
47778
+ class CheckBLEFirmwareRelease extends BaseMethod {
47779
+ getSupportedProtocols() {
47780
+ return ['V1', 'V2'];
47781
+ }
47782
+ init() {
47783
+ this.allowDeviceMode = [
47784
+ ...this.allowDeviceMode,
47785
+ UI_REQUEST.NOT_INITIALIZE,
47786
+ UI_REQUEST.BOOTLOADER,
47787
+ ];
47788
+ this.useDevicePassphraseState = false;
47789
+ this.skipForceUpdateCheck = true;
47790
+ }
47791
+ run() {
47792
+ return __awaiter(this, void 0, void 0, function* () {
47793
+ if (this.device.isProtocolV2()) {
47794
+ const { state, firmwareType, release } = yield loadProtocolV2FirmwareReleaseContext({
47795
+ device: this.device,
47796
+ methodName: 'checkBLEFirmwareRelease',
47797
+ });
47798
+ const plan = summarizeProtocolV2FirmwareRelease(buildProtocolV2FirmwareRelease({
47799
+ currentVersions: state.versions,
47800
+ firmwareType,
47801
+ release,
47802
+ deviceType: state.identity.deviceType,
47803
+ }), PROTOCOL_V2_BLE_TARGETS);
47804
+ return toProtocolV2FirmwareReleaseInfo({
47805
+ plan,
47806
+ state,
47807
+ release: getProtocolV2ComponentReleaseInfo(plan, 'COPROCESSOR'),
47808
+ });
47809
+ }
47810
+ if (this.device.features) {
47811
+ const releaseInfo = getBleFirmwareReleaseInfo(this.device.features);
47812
+ return releaseInfo;
47813
+ }
47814
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'checkBLEFirmwareRelease requires initialized device features');
47815
+ });
47816
+ }
47817
+ }
47818
+
47819
+ class CheckBridgeStatus extends BaseMethod {
47820
+ init() {
47821
+ this.useDevice = false;
47822
+ this.useDevicePassphraseState = false;
47823
+ this.skipForceUpdateCheck = true;
47824
+ }
47825
+ run() {
47826
+ return __awaiter(this, void 0, void 0, function* () {
47827
+ return new Promise((resolve, reject) => {
47828
+ axios__default["default"]
47829
+ .request({
47830
+ url: 'http://localhost:21320',
47831
+ method: 'POST',
47832
+ withCredentials: false,
47833
+ timeout: 3000,
47834
+ })
47835
+ .then(() => resolve(true))
47836
+ .catch(e => {
47837
+ if (e.code === 'ECONNABORTED') {
47838
+ reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.BridgeTimeoutError));
47839
+ }
47840
+ else {
47841
+ resolve(false);
47842
+ }
47843
+ });
47844
+ });
47845
+ });
47846
+ }
47847
+ }
47848
+
47849
+ class CheckBridgeRelease extends BaseMethod {
47850
+ init() {
47851
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
47852
+ this.useDevicePassphraseState = false;
47853
+ this.skipForceUpdateCheck = true;
47854
+ }
47855
+ run() {
47856
+ return __awaiter(this, void 0, void 0, function* () {
47857
+ if (!this.device.features) {
47858
+ return null;
47859
+ }
47860
+ const { willUpdateFirmwareVersion } = this.payload;
47861
+ const { features } = this.device;
47862
+ const deviceType = getDeviceType(features);
47863
+ const currentFirmwareVersion = getDeviceFirmwareVersion(features).join('.');
47864
+ return getBridgeReleaseInfo({
47865
+ deviceType,
47866
+ currentFirmwareVersion,
47867
+ willUpdateFirmwareVersion,
47868
+ });
47869
+ });
47870
+ }
47871
+ }
47872
+
47873
+ class CheckBootloaderRelease extends BaseMethod {
47874
+ getSupportedProtocols() {
47875
+ return ['V1', 'V2'];
47876
+ }
47877
+ init() {
47878
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
47879
+ this.useDevicePassphraseState = false;
47880
+ this.skipForceUpdateCheck = true;
47881
+ }
47882
+ run() {
47883
+ var _a;
47884
+ return __awaiter(this, void 0, void 0, function* () {
47885
+ if (!this.device.features) {
47886
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'checkBootloaderRelease requires initialized device features');
47887
+ }
47888
+ const { features } = this.device;
47889
+ const payload = this.payload;
47890
+ if (this.device.isProtocolV2()) {
47891
+ const { state, firmwareType, release } = yield loadProtocolV2FirmwareReleaseContext({
47892
+ device: this.device,
47893
+ firmwareType: payload.firmwareType,
47894
+ methodName: 'checkBootloaderRelease',
47895
+ });
47896
+ const plan = summarizeProtocolV2FirmwareRelease(buildProtocolV2FirmwareRelease({
47897
+ currentVersions: state.versions,
47898
+ firmwareType,
47899
+ release,
47900
+ deviceType: state.identity.deviceType,
47901
+ }), PROTOCOL_V2_BOOTLOADER_TARGETS);
47902
+ return toProtocolV2FirmwareReleaseInfo({
47903
+ plan,
47904
+ state,
47905
+ release: getProtocolV2ComponentReleaseInfo(plan, 'BOOTLOADER'),
47906
+ });
47907
+ }
47908
+ const deviceFirmwareType = this.device.getCurrentFirmwareType();
47909
+ const firmwareType = (_a = payload.firmwareType) !== null && _a !== void 0 ? _a : deviceFirmwareType;
47910
+ const releaseInfo = getBootloaderReleaseInfo({
47911
+ features,
47912
+ willUpdateFirmwareVersion: payload.willUpdateFirmwareVersion,
47913
+ firmwareType,
47914
+ });
47915
+ return Promise.resolve(releaseInfo);
47771
47916
  });
47772
47917
  }
47773
47918
  }
@@ -51391,7 +51536,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51391
51536
  });
51392
51537
  }
51393
51538
  runProtocolV2() {
51394
- var _a, _b, _c, _d, _e, _f;
51539
+ var _a, _b, _c, _d, _e;
51395
51540
  return __awaiter(this, void 0, void 0, function* () {
51396
51541
  yield this.captureProtocolV2PhysicalIdentity();
51397
51542
  const deviceFeatures = yield this.getProtocolV2DeviceFeatures();
@@ -51408,9 +51553,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51408
51553
  return this.runProtocolV2PreparedArtifacts(deviceFeatures, firmwareType);
51409
51554
  }
51410
51555
  const hasExplicitResourceFiles = !!((_c = this.params.resourceFiles) === null || _c === void 0 ? void 0 : _c.length);
51411
- const wantsStableResources = !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('resource'));
51412
- const wantsBootResources = !!((_e = this.params.targetsToUpdate) === null || _e === void 0 ? void 0 : _e.includes('boot_resources'));
51413
- const needsPreparedResources = !hasExplicitResourceFiles && (wantsStableResources || wantsBootResources);
51556
+ const wantsResources = !!((_d = this.params.targetsToUpdate) === null || _d === void 0 ? void 0 : _d.includes('resource'));
51557
+ const needsPreparedResources = !hasExplicitResourceFiles && wantsResources;
51414
51558
  let fwBinaryMap = [];
51415
51559
  let bootloaderBinary = null;
51416
51560
  let installItems;
@@ -51448,7 +51592,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51448
51592
  if (typeof err === 'object' &&
51449
51593
  err !== null &&
51450
51594
  'params' in err &&
51451
- ((_f = err.params) === null || _f === void 0 ? void 0 : _f.firmwareUpdateCode) === 'FirmwareArtifactsNotPrepared') {
51595
+ ((_e = err.params) === null || _e === void 0 ? void 0 : _e.firmwareUpdateCode) === 'FirmwareArtifactsNotPrepared') {
51452
51596
  throw err;
51453
51597
  }
51454
51598
  if (err instanceof hdShared.HardwareError && err.errorCode === hdShared.HardwareErrorCode.NetworkError) {
@@ -51572,7 +51716,19 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51572
51716
  try {
51573
51717
  this.postTipMessage(exports.FirmwareUpdateTipMessage.StartDownloadFirmware);
51574
51718
  const installSources = yield this.prepareProtocolV2InstallSources(firmwareType, features);
51575
- const resourceSources = yield this.prepareProtocolV2ResourceSources(firmwareType, features);
51719
+ const explicitResourceBundles = this.prepareExplicitProtocolV2ResourceFiles();
51720
+ const resourceSources = (explicitResourceBundles === null || explicitResourceBundles === void 0 ? void 0 : explicitResourceBundles.length)
51721
+ ? yield Promise.all(explicitResourceBundles.map((bundle) => __awaiter(this, void 0, void 0, function* () {
51722
+ return ({
51723
+ name: bundle.name,
51724
+ source: yield this.openProtocolV2MemorySource(bundle.binary),
51725
+ devicePath: bundle.devicePath,
51726
+ version: bundle.version,
51727
+ payloadHash: bundle.payloadHash,
51728
+ headerHash: bundle.headerHash,
51729
+ });
51730
+ })))
51731
+ : yield this.prepareProtocolV2ResourceSources(firmwareType, features);
51576
51732
  if (installSources.length === 0 && resourceSources.length === 0) {
51577
51733
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareUpdateDownloadFailed, 'No firmware to update');
51578
51734
  }
@@ -51888,11 +52044,14 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51888
52044
  })) {
51889
52045
  throw new Error(`resourceFiles[${index}] SHA-256 mismatch`);
51890
52046
  }
51891
- return {
51892
- name: (_a = devicePath.split('/').pop()) !== null && _a !== void 0 ? _a : devicePath,
51893
- binary: file.binary,
51894
- devicePath,
51895
- };
52047
+ const header = parseProtocolV2OkppHeader(toProtocolV2Bytes(file.binary));
52048
+ return Object.assign({ name: (_a = devicePath.split('/').pop()) !== null && _a !== void 0 ? _a : devicePath, binary: file.binary, devicePath }, (header
52049
+ ? {
52050
+ version: header.version,
52051
+ payloadHash: header.payloadHash,
52052
+ headerHash: header.headerHash,
52053
+ }
52054
+ : {}));
51896
52055
  });
51897
52056
  if (new Set(prepared.map(file => file.devicePath)).size !== prepared.length) {
51898
52057
  throw new Error('resourceFiles contain duplicate devicePath values');
@@ -51955,7 +52114,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51955
52114
  return __awaiter(this, void 0, void 0, function* () {
51956
52115
  if ((_a = this.params) === null || _a === void 0 ? void 0 : _a.forcedUpdateRes)
51957
52116
  return false;
51958
- if (!bundle.version && !bundle.payloadHash)
52117
+ if (!bundle.payloadHash || !bundle.headerHash)
51959
52118
  return false;
51960
52119
  try {
51961
52120
  const header = yield this.readProtocolV2DeviceFileHeader(bundle.devicePath);
@@ -51966,16 +52125,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
51966
52125
  if (cmp === undefined || cmp !== 0)
51967
52126
  return false;
51968
52127
  }
51969
- if (bundle.payloadHash) {
51970
- const expected = normalizeProtocolV2Hex(bundle.payloadHash);
51971
- if (expected && header.payloadHash !== expected)
51972
- return false;
51973
- }
51974
- if (bundle.headerHash) {
51975
- const expected = normalizeProtocolV2Hex(bundle.headerHash);
51976
- if (expected && header.headerHash !== expected)
51977
- return false;
51978
- }
52128
+ const expectedPayloadHash = normalizeProtocolV2Hex(bundle.payloadHash);
52129
+ const expectedHeaderHash = normalizeProtocolV2Hex(bundle.headerHash);
52130
+ if (!expectedPayloadHash || header.payloadHash !== expectedPayloadHash)
52131
+ return false;
52132
+ if (!expectedHeaderHash || header.headerHash !== expectedHeaderHash)
52133
+ return false;
51979
52134
  return true;
51980
52135
  }
51981
52136
  catch (error) {
@@ -52179,6 +52334,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
52179
52334
  name: bundle.name,
52180
52335
  source: yield this.openProtocolV2MemorySource(bundle.binary),
52181
52336
  devicePath: bundle.devicePath,
52337
+ version: bundle.version,
52338
+ payloadHash: bundle.payloadHash,
52339
+ headerHash: bundle.headerHash,
52182
52340
  });
52183
52341
  })));
52184
52342
  return yield this.executeProtocolV2Phases({
@@ -64936,7 +65094,6 @@ exports.preloadSessionCache = preloadSessionCache;
64936
65094
  exports.prepareProtocolV2ResourceFiles = prepareProtocolV2ResourceFiles;
64937
65095
  exports.projectDeviceStateFeatures = projectFeatures;
64938
65096
  exports.registerFirmwareUpdateHostBinding = registerFirmwareUpdateHostBinding;
64939
- exports.resolveProtocolV2ResourceManifestFileUrl = resolveProtocolV2ResourceManifestFileUrl;
64940
65097
  exports.safeThrowError = safeThrowError;
64941
65098
  exports.selectProtocolV2ResourceManifestFiles = selectProtocolV2ResourceManifestFiles;
64942
65099
  exports.setLoggerPostMessage = setLoggerPostMessage;
@@ -9,10 +9,6 @@ export declare function selectProtocolV2ResourceManifestFiles({ manifest, target
9
9
  manifest: IProtocolV2ResourceManifest;
10
10
  targetsToUpdate: readonly FirmwareUpdateV4Target[];
11
11
  }): IProtocolV2ResourceManifestFile[];
12
- export declare function resolveProtocolV2ResourceManifestFileUrl({ manifestUrl, archivePath, }: {
13
- manifestUrl: string;
14
- archivePath: string;
15
- }): string;
16
12
  export declare function prepareProtocolV2ResourceFiles({ manifest: value, files, targetsToUpdate, }: {
17
13
  manifest: unknown;
18
14
  files: Array<{
@@ -1 +1 @@
1
- {"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"AAEA,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,s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