@onekeyfe/hd-core 1.2.0-alpha.95 → 1.2.0-alpha.97

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 (89) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +84 -404
  2. package/__tests__/firmware-update/device-update-bootloader.test.ts +2 -6
  3. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -9
  4. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +112 -0
  5. package/__tests__/firmware-update/firmware-update-plan.test.ts +70 -131
  6. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +1 -53
  7. package/__tests__/protocol-v2-resources.test.ts +232 -148
  8. package/__tests__/protocol-v2.test.ts +517 -1106
  9. package/dist/api/CheckAllFirmwareRelease.d.ts +3 -2
  10. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  11. package/dist/api/CheckBLEFirmwareRelease.d.ts +2 -3
  12. package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
  13. package/dist/api/CheckBootloaderRelease.d.ts +1 -2
  14. package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
  15. package/dist/api/CheckFirmwareRelease.d.ts +2 -3
  16. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  17. package/dist/api/FirmwareUpdateV2.d.ts +0 -1
  18. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  19. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  20. package/dist/api/FirmwareUpdateV4.d.ts +8 -6
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  22. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  23. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  24. package/dist/api/firmware/FirmwareHostBinding.d.ts +1 -1
  25. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -1
  26. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  27. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +1 -48
  28. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
  29. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
  30. package/dist/api/firmware/getBinary.d.ts +1 -0
  31. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  32. package/dist/data-manager/DataManager.d.ts +3 -4
  33. package/dist/data-manager/DataManager.d.ts.map +1 -1
  34. package/dist/index.d.ts +111 -103
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +849 -1301
  37. package/dist/protocols/protocol-v2/resources.d.ts +28 -10
  38. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  39. package/dist/types/api/checkAllFirmwareRelease.d.ts +8 -20
  40. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  41. package/dist/types/api/checkBLEFirmwareRelease.d.ts +13 -2
  42. package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
  43. package/dist/types/api/checkBootloaderRelease.d.ts +6 -2
  44. package/dist/types/api/checkBootloaderRelease.d.ts.map +1 -1
  45. package/dist/types/api/checkFirmwareRelease.d.ts +13 -2
  46. package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
  47. package/dist/types/api/checkFirmwareTypeAvailable.d.ts +2 -2
  48. package/dist/types/api/checkFirmwareTypeAvailable.d.ts.map +1 -1
  49. package/dist/types/api/export.d.ts +1 -1
  50. package/dist/types/api/export.d.ts.map +1 -1
  51. package/dist/types/api/firmwareUpdate.d.ts +11 -3
  52. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  53. package/dist/types/settings.d.ts +36 -35
  54. package/dist/types/settings.d.ts.map +1 -1
  55. package/package.json +4 -4
  56. package/src/api/CheckAllFirmwareRelease.ts +80 -108
  57. package/src/api/CheckBLEFirmwareRelease.ts +5 -37
  58. package/src/api/CheckBootloaderRelease.ts +3 -35
  59. package/src/api/CheckFirmwareRelease.ts +7 -35
  60. package/src/api/FirmwareUpdateV2.ts +3 -15
  61. package/src/api/FirmwareUpdateV3.ts +6 -13
  62. package/src/api/FirmwareUpdateV4.ts +407 -824
  63. package/src/api/UploadPortfolio.ts +0 -18
  64. package/src/api/device/DeviceUpdateBootloader.ts +5 -26
  65. package/src/api/firmware/FirmwareHostBinding.ts +3 -16
  66. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +2 -0
  67. package/src/api/firmware/FirmwareUpdatePlan.ts +88 -226
  68. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +3 -10
  69. package/src/data-manager/DataManager.ts +19 -35
  70. package/src/index.ts +0 -10
  71. package/src/protocols/protocol-v2/resources.ts +341 -157
  72. package/src/types/api/checkAllFirmwareRelease.ts +12 -27
  73. package/src/types/api/checkBLEFirmwareRelease.ts +13 -4
  74. package/src/types/api/checkBootloaderRelease.ts +6 -2
  75. package/src/types/api/checkFirmwareRelease.ts +13 -2
  76. package/src/types/api/checkFirmwareTypeAvailable.ts +2 -2
  77. package/src/types/api/export.ts +1 -6
  78. package/src/types/api/firmwareUpdate.ts +16 -10
  79. package/src/types/settings.ts +61 -35
  80. package/src/utils/deviceFeaturesUtils.ts +2 -2
  81. package/__tests__/check-firmware-release-protocol-v2.test.ts +0 -199
  82. package/__tests__/firmware-memory-host.test.ts +0 -112
  83. package/__tests__/firmware-update/firmware-prepared-host-digest.test.ts +0 -448
  84. package/dist/api/firmware/FirmwareMemoryHost.d.ts +0 -22
  85. package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +0 -1
  86. package/dist/api/firmware/protocolV2Release.d.ts +0 -33
  87. package/dist/api/firmware/protocolV2Release.d.ts.map +0 -1
  88. package/src/api/firmware/FirmwareMemoryHost.ts +0 -142
  89. package/src/api/firmware/protocolV2Release.ts +0 -168
@@ -1,6 +1,17 @@
1
+ import type { IFirmwareReleaseInfo } from '../settings';
1
2
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
2
3
  import type { Response } from '../params';
3
- import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
4
+ import type { IDeviceFirmwareStatus } from '../device';
5
+
6
+ type FirmwareRelease = {
7
+ status: IDeviceFirmwareStatus;
8
+ changelog: {
9
+ 'en-US': string;
10
+ 'zh-CN': string;
11
+ }[];
12
+ release: IFirmwareReleaseInfo;
13
+ bootloaderMode: boolean;
14
+ };
4
15
 
5
16
  export type CheckFirmwareReleaseParams = {
6
17
  firmwareType?: EFirmwareType;
@@ -9,4 +20,4 @@ export type CheckFirmwareReleaseParams = {
9
20
  export declare function checkFirmwareRelease(
10
21
  connectId?: string,
11
22
  params?: CheckFirmwareReleaseParams
12
- ): Response<FirmwareReleaseCheckResult | null>;
23
+ ): Response<FirmwareRelease>;
@@ -1,6 +1,6 @@
1
1
  import type { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
2
2
  import type { Response } from '../params';
3
- import type { FirmwareReleaseCheckResult } from './checkAllFirmwareRelease';
3
+ import type { FirmwareRelease } from './checkAllFirmwareRelease';
4
4
 
5
5
  export type CheckFirmwareTypeAvailableParams = {
6
6
  deviceType: EDeviceType;
@@ -9,4 +9,4 @@ export type CheckFirmwareTypeAvailableParams = {
9
9
 
10
10
  export declare function checkFirmwareTypeAvailable(
11
11
  params: CheckFirmwareTypeAvailableParams
12
- ): Response<FirmwareReleaseCheckResult | undefined>;
12
+ ): Response<FirmwareRelease | undefined>;
@@ -50,12 +50,7 @@ export type {
50
50
  FirmwareUpdatePreparedPlan,
51
51
  } from './firmwareUpdatePreparedPlan';
52
52
  export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
53
- export type {
54
- AllFirmwareRelease,
55
- BridgeReleaseCheckResult,
56
- FirmwareReleaseCheckResult,
57
- ProtocolV2ComponentReleaseInfo,
58
- } from './checkAllFirmwareRelease';
53
+ export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
59
54
  export type {
60
55
  ProtocolV2FirmwareComponentRelease,
61
56
  ProtocolV2FirmwareComponentReleaseStatus,
@@ -26,8 +26,6 @@ export interface FirmwareArtifactReader {
26
26
 
27
27
  export interface FirmwareUpdateHostBinding {
28
28
  artifactReader: FirmwareArtifactReader;
29
- /** 将读取器 generation 绑定到包含 ZIP 条目的完整 PreparedPlan。 */
30
- preparedPlanDigest: string;
31
29
  }
32
30
 
33
31
  export interface FirmwareUpdateBinaryParams {
@@ -120,7 +118,6 @@ export interface FirmwareUpdateV3Params {
120
118
  */
121
119
  export type FirmwareUpdateV4Target =
122
120
  | 'boot'
123
- /** @deprecated Use resource with resourceArchiveBinary. */
124
121
  | 'boot_resources'
125
122
  | 'app_v1'
126
123
  | 'app_v2'
@@ -133,7 +130,6 @@ export type FirmwareUpdateV4Target =
133
130
 
134
131
  export interface FirmwareUpdateV4Params {
135
132
  preparedPlan?: FirmwareUpdatePreparedPlan;
136
- /** Required whenever preparedPlan is present; Core resolves the reader from this digest-bound host. */
137
133
  hostBindingGeneration?: number;
138
134
  platform: IPlatform;
139
135
  expectedDeviceId?: string;
@@ -157,16 +153,26 @@ export interface FirmwareUpdateV4Params {
157
153
  se02Binary?: ArrayBuffer;
158
154
  se03Binary?: ArrayBuffer;
159
155
  se04Binary?: ArrayBuffer;
160
- /** Complete Protocol V2 resource ZIP for local development; Core converts it to a local PreparedPlan. */
161
- resourceArchiveBinary?: ArrayBuffer;
162
156
  forcedUpdateRes?: boolean;
157
+ /**
158
+ * Arbitrary Protocol V2 resource files written directly with FilesystemFileWrite.
159
+ * Use this for manifest-driven boot resources and other non-RESC files.
160
+ * When provided, these files are authoritative for resource and boot_resources targets.
161
+ */
162
+ resourceFiles?: Array<{
163
+ binary: ArrayBuffer;
164
+ devicePath: string;
165
+ size?: number;
166
+ fileHash?: string;
167
+ }>;
163
168
  artifactReader?: FirmwareArtifactReader;
164
169
  componentArtifacts?: Partial<
165
- Record<
166
- Exclude<FirmwareUpdateV4Target, 'resource' | 'boot_resources'>,
167
- FirmwareArtifactReference
168
- >
170
+ Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
169
171
  >;
172
+ resourceBundleArtifacts?: Array<{
173
+ name: string;
174
+ artifact: FirmwareArtifactReference;
175
+ }>;
170
176
  }
171
177
 
172
178
  export declare function registerFirmwareUpdateHostBinding(
@@ -64,44 +64,66 @@ export type IProtocolV2FirmwareComponent = {
64
64
  version?: IVersionArray;
65
65
  };
66
66
 
67
- export type IProtocolV2ResourceSource = {
68
- archiveUrl: string;
69
- archiveSha256: string;
70
- archiveSize: number;
71
- };
67
+ export type IProtocolV2ResourceType =
68
+ | 'images'
69
+ | 'animation'
70
+ | 'wallpaper'
71
+ | 'translations'
72
+ | 'roobert'
73
+ | 'noto'
74
+ | 'firmware_logo';
72
75
 
73
- export type IProtocolV2Resources = {
74
- source: IProtocolV2ResourceSource;
76
+ /** Pro2 RES package descriptor. Hashes identify content without a human-managed version. */
77
+ export type IProtocolV2Resource = {
78
+ type: IProtocolV2ResourceType;
79
+ url: string;
80
+ /** Complete okpkg file size in bytes. */
81
+ size: number;
82
+ /** SHA-256 of the complete okpkg file. */
83
+ fileHash: string;
84
+ /** SHA3-512 header_hash from the signed okpkg header. */
85
+ headerHash: string;
75
86
  };
76
87
 
77
- export type IProtocolV2ResourceManifestFile = {
78
- archive_path: string;
79
- original_name: string;
80
- device_path: string;
88
+ /** A file from the Protocol V2 resource manifest, written directly with FileWrite. */
89
+ export type IProtocolV2ResourceFile = {
90
+ name?: string;
91
+ url: string;
92
+ devicePath: string;
81
93
  size: number;
82
- sha256: string;
83
- signed: true;
84
- sig_algo: 'ed25519' | 'mldsa65';
85
- payload_version: string | null;
94
+ /** SHA-256 of the complete file. */
95
+ fileHash: string;
96
+ };
97
+
98
+ /** Optional Protocol V2 boot resources restored as individual files. */
99
+ export type IProtocolV2BootResources = {
100
+ required: false;
101
+ target: 'RES';
102
+ manifestUrl?: string;
103
+ files: IProtocolV2ResourceFile[];
104
+ };
105
+
106
+ export type IProtocolV2Resources = {
107
+ stable: IProtocolV2Resource[];
108
+ boot?: IProtocolV2BootResources;
86
109
  };
87
110
 
88
- export type IProtocolV2ResourceManifest = {
89
- schema: 1;
90
- artifact_name: string;
91
- release_name: string;
92
- variant: 'resource';
93
- commit: string;
94
- short_sha: string;
95
- timestamp_utc: string;
96
- core_version: string;
97
- key_set: string;
98
- device_root: 'vol0:';
99
- restore_mode: 'bootloader_update';
100
- trees: Array<{
101
- path: string;
102
- device: string;
103
- }>;
104
- files: IProtocolV2ResourceManifestFile[];
111
+ /** Pro2 RESC bundle okpkg descriptor for incremental FileWrite synchronization. */
112
+ export type IProtocolV2ResourceBundle = {
113
+ /** Bundle name, such as images, animation, translations, or fonts_roobert. */
114
+ name: string;
115
+ /** Download URL. */
116
+ url: string;
117
+ fingerprint?: string;
118
+ expectedSize?: number;
119
+ /** Device target path, such as vol0:/bundles/images/images.okpkg. */
120
+ devicePath: string;
121
+ /** okpkg payload_version used to skip matching content after FileRead. */
122
+ version?: IVersionArray;
123
+ /** okpkg payload_hash used for SHA3-512 comparison after FileRead. */
124
+ payloadHash?: string;
125
+ /** okpkg header_hash used for SHA3-512 comparison after FileRead. */
126
+ headerHash?: string;
105
127
  };
106
128
 
107
129
  /** STM32 firmware config */
@@ -131,6 +153,8 @@ export type IFirmwareReleaseInfo = {
131
153
  upgradeType?: 'payload-package-set' | string;
132
154
  components?: Record<string, IProtocolV2FirmwareComponent>;
133
155
  installOrder?: string[];
156
+ /** Pro2 RESC bundles for incremental direct FileWrite synchronization. */
157
+ resourceBundles?: IProtocolV2ResourceBundle[];
134
158
  bootloaderChangelog?: {
135
159
  [k in ILocale]: string;
136
160
  };
@@ -159,20 +183,22 @@ export type IBLEFirmwareReleaseInfo = {
159
183
  };
160
184
 
161
185
  type IKnownDevice = Exclude<IDeviceType, 'unknown'>;
186
+ type ILegacyKnownDevice = Exclude<IKnownDevice, 'neo'>;
187
+
162
188
  type IDeviceReleaseInfo = {
163
- firmware?: IFirmwareReleaseInfo[];
189
+ firmware: IFirmwareReleaseInfo[];
164
190
  /** Protocol V2 payload package set */
165
191
  'firmware-v1'?: IFirmwareReleaseInfo[];
166
192
  'firmware-v2'?: IFirmwareReleaseInfo[];
167
193
  'firmware-v8'?: IFirmwareReleaseInfo[];
168
194
  'firmware-btc-v8'?: IFirmwareReleaseInfo[];
169
- ble?: IBLEFirmwareReleaseInfo[];
195
+ ble: IBLEFirmwareReleaseInfo[];
170
196
  /** Independent Protocol V2 resource release configuration. */
171
197
  resources?: IProtocolV2Resources;
172
198
  };
173
199
 
174
200
  export type DeviceTypeMap = {
175
- [k in Exclude<IKnownDevice, 'neo'>]: IDeviceReleaseInfo;
201
+ [k in ILegacyKnownDevice]: IDeviceReleaseInfo;
176
202
  } & {
177
203
  /** Optional until every remote-config producer publishes a Neo entry. */
178
204
  neo?: IDeviceReleaseInfo;
@@ -328,7 +328,7 @@ export const getFirmwareUpdateField = ({
328
328
  if (deviceType === EDeviceType.Pro) {
329
329
  return latestFirmwareField;
330
330
  }
331
- if (deviceType === EDeviceType.Pro2 || deviceType === EDeviceType.Neo) {
331
+ if (deviceType === EDeviceType.Pro2) {
332
332
  return 'firmware-v1';
333
333
  }
334
334
  return 'firmware';
@@ -374,7 +374,7 @@ export const getFirmwareUpdateFieldArray = (
374
374
  return ['firmware-v8'];
375
375
  }
376
376
 
377
- if (deviceType === 'pro2' || deviceType === 'neo') {
377
+ if (deviceType === 'pro2') {
378
378
  return ['firmware-v1'];
379
379
  }
380
380
 
@@ -1,199 +0,0 @@
1
- import { EFirmwareType } from '@onekeyfe/hd-shared';
2
-
3
- import CheckAllFirmwareRelease from '../src/api/CheckAllFirmwareRelease';
4
- import CheckBLEFirmwareRelease from '../src/api/CheckBLEFirmwareRelease';
5
- import CheckBootloaderRelease from '../src/api/CheckBootloaderRelease';
6
- import CheckFirmwareRelease from '../src/api/CheckFirmwareRelease';
7
- import { DataManager } from '../src/data-manager';
8
-
9
- import type { IFirmwareReleaseInfo } from '../src/types';
10
-
11
- jest.mock('../src/data/config', () => ({
12
- DEFAULT_DOMAIN: 'https://example.com/',
13
- getSDKVersion: () => '0.0.0-test',
14
- }));
15
-
16
- const release: IFirmwareReleaseInfo = {
17
- required: false,
18
- version: [2, 0, 0],
19
- url: 'https://example.com/application-p1.okpkg',
20
- fingerprint: 'release-fingerprint',
21
- changelog: {
22
- 'zh-CN': '更新',
23
- 'en-US': 'Update',
24
- },
25
- bootloaderChangelog: {
26
- 'zh-CN': '旧版 Bootloader 更新',
27
- 'en-US': 'Legacy bootloader update',
28
- },
29
- installOrder: ['bootloader', 'applicationP1', 'coprocessor'],
30
- components: {
31
- bootloader: {
32
- target: 'BOOTLOADER',
33
- url: 'https://example.com/bootloader.okpkg',
34
- version: [2, 0, 0],
35
- },
36
- applicationP1: {
37
- target: 'APPLICATION_P1',
38
- url: 'https://example.com/application-p1.okpkg',
39
- version: [2, 0, 0],
40
- },
41
- coprocessor: {
42
- target: 'COPROCESSOR',
43
- url: 'https://example.com/coprocessor.okpkg',
44
- version: [2, 0, 0],
45
- },
46
- },
47
- };
48
-
49
- const createDevice = (deviceType: 'pro2' | 'neo') => ({
50
- isProtocolV2: () => true,
51
- features: {
52
- deviceType,
53
- firmwareVersion: '1.0.0',
54
- },
55
- getDeviceState: jest.fn().mockResolvedValue({
56
- identity: {
57
- deviceType,
58
- firmwareType: EFirmwareType.Universal,
59
- },
60
- status: { mode: 'normal' },
61
- versions: {
62
- firmware: '1.0.0',
63
- applicationP1: '1.0.0',
64
- bootloader: '1.0.0',
65
- board: '1.0.0',
66
- ble: '1.0.0',
67
- },
68
- }),
69
- });
70
-
71
- describe.each(['pro2', 'neo'] as const)('Protocol V2 release checks for %s', deviceType => {
72
- afterEach(() => {
73
- jest.restoreAllMocks();
74
- });
75
-
76
- test('supports firmware, BLE, bootloader, and aggregate release checks', async () => {
77
- jest.spyOn(DataManager, 'getFirmwareLatestRelease').mockReturnValue(release);
78
- jest.spyOn(DataManager, 'getProtocolV2ResourceSource').mockReturnValue({
79
- archiveUrl: `https://example.com/${deviceType}/pro2-resource.zip`,
80
- archiveSha256: 'a'.repeat(64),
81
- archiveSize: 16_815_479,
82
- });
83
-
84
- const firmwareMethod = new CheckFirmwareRelease({
85
- id: 1,
86
- payload: { method: 'checkFirmwareRelease' },
87
- });
88
- firmwareMethod.init();
89
- firmwareMethod.device = createDevice(deviceType) as unknown as CheckFirmwareRelease['device'];
90
-
91
- const bleMethod = new CheckBLEFirmwareRelease({
92
- id: 2,
93
- payload: { method: 'checkBLEFirmwareRelease' },
94
- });
95
- bleMethod.init();
96
- bleMethod.device = createDevice(deviceType) as unknown as CheckBLEFirmwareRelease['device'];
97
-
98
- const bootloaderMethod = new CheckBootloaderRelease({
99
- id: 3,
100
- payload: { method: 'checkBootloaderRelease' },
101
- });
102
- bootloaderMethod.init();
103
- bootloaderMethod.device = createDevice(
104
- deviceType
105
- ) as unknown as CheckBootloaderRelease['device'];
106
-
107
- const allMethod = new CheckAllFirmwareRelease({
108
- id: 4,
109
- payload: { method: 'checkAllFirmwareRelease' },
110
- });
111
- allMethod.init();
112
- allMethod.device = createDevice(deviceType) as unknown as CheckAllFirmwareRelease['device'];
113
-
114
- await expect(firmwareMethod.run()).resolves.toMatchObject({
115
- status: 'outdated',
116
- shouldUpdate: true,
117
- release,
118
- });
119
- await expect(bleMethod.run()).resolves.toMatchObject({
120
- status: 'outdated',
121
- shouldUpdate: true,
122
- release: {
123
- protocol: 'V2',
124
- configKey: 'coprocessor',
125
- componentTarget: 'COPROCESSOR',
126
- target: 'COPROCESSOR',
127
- url: 'https://example.com/coprocessor.okpkg',
128
- version: [2, 0, 0],
129
- },
130
- });
131
- await expect(bootloaderMethod.run()).resolves.toMatchObject({
132
- status: 'outdated',
133
- shouldUpdate: true,
134
- changelog: [release.changelog],
135
- release: {
136
- protocol: 'V2',
137
- configKey: 'bootloader',
138
- componentTarget: 'BOOTLOADER',
139
- target: 'BOOTLOADER',
140
- url: 'https://example.com/bootloader.okpkg',
141
- version: [2, 0, 0],
142
- changelog: release.changelog,
143
- },
144
- });
145
- await expect(allMethod.run()).resolves.toMatchObject({
146
- protocol: 'V2',
147
- deviceType,
148
- status: 'outdated',
149
- hasUpgrade: true,
150
- targetsToUpdate: ['boot', 'app_v1', 'coprocessor'],
151
- firmware: { status: 'outdated', shouldUpdate: true },
152
- ble: {
153
- status: 'outdated',
154
- shouldUpdate: true,
155
- release: { componentTarget: 'COPROCESSOR' },
156
- },
157
- bootloader: {
158
- status: 'outdated',
159
- shouldUpdate: true,
160
- release: { componentTarget: 'BOOTLOADER' },
161
- },
162
- });
163
-
164
- expect(firmwareMethod.getSupportedProtocols()).toEqual(['V1', 'V2']);
165
- expect(bleMethod.getSupportedProtocols()).toEqual(['V1', 'V2']);
166
- expect(bootloaderMethod.getSupportedProtocols()).toEqual(['V1', 'V2']);
167
- expect(allMethod.getSupportedProtocols()).toEqual(['V1', 'V2']);
168
- });
169
- });
170
-
171
- test('returns null from optional release probes when device features are unavailable', async () => {
172
- const deviceWithoutFeatures = {
173
- isProtocolV2: jest.fn(() => true),
174
- features: undefined,
175
- getDeviceState: jest.fn(),
176
- };
177
- const firmwareMethod = new CheckFirmwareRelease({
178
- id: 1,
179
- payload: { method: 'checkFirmwareRelease' },
180
- });
181
- const bleMethod = new CheckBLEFirmwareRelease({
182
- id: 2,
183
- payload: { method: 'checkBLEFirmwareRelease' },
184
- });
185
- const bootloaderMethod = new CheckBootloaderRelease({
186
- id: 3,
187
- payload: { method: 'checkBootloaderRelease' },
188
- });
189
-
190
- firmwareMethod.device = deviceWithoutFeatures as unknown as CheckFirmwareRelease['device'];
191
- bleMethod.device = deviceWithoutFeatures as unknown as CheckBLEFirmwareRelease['device'];
192
- bootloaderMethod.device = deviceWithoutFeatures as unknown as CheckBootloaderRelease['device'];
193
-
194
- await expect(firmwareMethod.run()).resolves.toBeNull();
195
- await expect(bleMethod.run()).resolves.toBeNull();
196
- await expect(bootloaderMethod.run()).resolves.toBeNull();
197
- expect(deviceWithoutFeatures.isProtocolV2).not.toHaveBeenCalled();
198
- expect(deviceWithoutFeatures.getDeviceState).not.toHaveBeenCalled();
199
- });
@@ -1,112 +0,0 @@
1
- import { prepareFirmwareUpdateV4MemoryHost } from '../src/api/firmware/FirmwareMemoryHost';
2
-
3
- import type { CoreApi } from '../src/types/api';
4
- import type { FirmwareUpdatePlan } from '../src/types/api/firmwareUpdatePlan';
5
-
6
- describe('prepareFirmwareUpdateV4MemoryHost', () => {
7
- test('registers artifact-backed component and resource readers', async () => {
8
- const componentBinary = new Uint8Array([1, 2, 3, 4]).buffer;
9
- const archiveBinary = new Uint8Array([5, 6]).buffer;
10
- const manifestBinary = new TextEncoder().encode('{"schema":1}').buffer;
11
- let artifactReader: Parameters<
12
- CoreApi['registerFirmwareUpdateHostBinding']
13
- >[0]['artifactReader'];
14
- const unregisterFirmwareUpdateHostBinding = jest.fn();
15
- const sdk = {
16
- prepareFirmwareUpdatePlan: jest.fn(({ plan, artifacts }) => ({
17
- schemaVersion: 2,
18
- preparedPlanDigest: 'b'.repeat(64),
19
- planDigest: plan.planDigest,
20
- networkPolicy: 'forbid',
21
- executor: plan.executor,
22
- deviceIdentity: plan.deviceIdentity,
23
- deviceModel: plan.deviceModel,
24
- firmwareType: plan.firmwareType,
25
- platform: plan.platform,
26
- leaseRef: 'test-lease',
27
- targetsToUpdate: plan.targetsToUpdate,
28
- artifacts: plan.artifacts.map(planArtifact => {
29
- const input = artifacts.find(item => item.artifactId === planArtifact.artifactId);
30
- return {
31
- ...planArtifact,
32
- artifact: input?.artifact,
33
- materializedEntries: input?.materializedEntries,
34
- };
35
- }),
36
- })),
37
- registerFirmwareUpdateHostBinding: jest.fn(binding => {
38
- artifactReader = binding.artifactReader;
39
- return 7;
40
- }),
41
- unregisterFirmwareUpdateHostBinding,
42
- } as unknown as Pick<
43
- CoreApi,
44
- | 'prepareFirmwareUpdatePlan'
45
- | 'registerFirmwareUpdateHostBinding'
46
- | 'unregisterFirmwareUpdateHostBinding'
47
- >;
48
- const plan = {
49
- schemaVersion: 2,
50
- planDigest: 'a'.repeat(64),
51
- executor: 'v4',
52
- deviceIdentity: 'device-id',
53
- deviceModel: 'pro2',
54
- firmwareType: 0,
55
- platform: 'web',
56
- targetsToUpdate: ['boot', 'resource'],
57
- artifacts: [
58
- {
59
- artifactId: 'component:boot',
60
- role: 'component',
61
- target: 'boot',
62
- url: 'https://example.com/boot.okpkg',
63
- container: 'raw',
64
- },
65
- {
66
- artifactId: 'resource:archive',
67
- role: 'resourceBundle',
68
- target: 'resource',
69
- url: 'https://example.com/resource.zip',
70
- container: 'zip',
71
- logicalName: 'resource-archive',
72
- },
73
- ],
74
- } as FirmwareUpdatePlan;
75
-
76
- const host = prepareFirmwareUpdateV4MemoryHost({
77
- sdk,
78
- plan,
79
- artifacts: [
80
- { artifactId: 'component:boot', binary: componentBinary },
81
- {
82
- artifactId: 'resource:archive',
83
- binary: archiveBinary,
84
- materializedEntries: [{ entryName: 'manifest.json', binary: manifestBinary }],
85
- },
86
- ],
87
- });
88
-
89
- expect(host.hostBindingGeneration).toBe(7);
90
- expect(sdk.registerFirmwareUpdateHostBinding).toHaveBeenCalledWith(
91
- expect.objectContaining({ preparedPlanDigest: host.preparedPlan.preparedPlanDigest })
92
- );
93
- const componentArtifact = host.preparedPlan.artifacts.find(
94
- artifact => artifact.target === 'boot'
95
- )?.artifact;
96
- expect(componentArtifact?.size).toBe(componentBinary.byteLength);
97
- new Uint8Array(componentBinary).fill(9);
98
- const opened = await artifactReader!.open({
99
- artifactRef: componentArtifact!.artifactRef,
100
- });
101
- const chunk = await artifactReader!.read({
102
- readerId: opened.readerId,
103
- offset: 1,
104
- length: 2,
105
- });
106
- expect(Array.from(new Uint8Array(chunk.data))).toEqual([2, 3]);
107
- await artifactReader!.close({ readerId: opened.readerId });
108
-
109
- host.release();
110
- expect(unregisterFirmwareUpdateHostBinding).toHaveBeenCalledWith(7);
111
- });
112
- });