@onekeyfe/hd-core 1.2.0-alpha.84 → 1.2.0-alpha.85

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 (46) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +24 -18
  2. package/__tests__/firmware-memory-host.test.ts +105 -0
  3. package/__tests__/firmware-update/firmware-update-plan.test.ts +15 -70
  4. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +53 -1
  5. package/__tests__/protocol-v2-resources.test.ts +0 -38
  6. package/__tests__/protocol-v2.test.ts +207 -318
  7. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  8. package/dist/api/FirmwareUpdateV4.d.ts +1 -2
  9. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  10. package/dist/api/firmware/FirmwareMemoryHost.d.ts +27 -0
  11. package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +1 -0
  12. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +3 -4
  13. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
  14. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
  15. package/dist/api/firmware/getBinary.d.ts +0 -1
  16. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  17. package/dist/index.d.ts +24 -64
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +406 -367
  20. package/dist/inject.d.ts.map +1 -1
  21. package/dist/protocols/protocol-v2/resources.d.ts +0 -17
  22. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  23. package/dist/types/api/export.d.ts +0 -1
  24. package/dist/types/api/export.d.ts.map +1 -1
  25. package/dist/types/api/firmwareUpdate.d.ts +0 -10
  26. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  27. package/dist/types/api/index.d.ts +0 -2
  28. package/dist/types/api/index.d.ts.map +1 -1
  29. package/dist/types/settings.d.ts +0 -11
  30. package/dist/types/settings.d.ts.map +1 -1
  31. package/package.json +4 -4
  32. package/src/api/CheckAllFirmwareRelease.ts +2 -6
  33. package/src/api/FirmwareUpdateV4.ts +154 -165
  34. package/src/api/firmware/FirmwareMemoryHost.ts +171 -0
  35. package/src/api/firmware/FirmwareUpdatePlan.ts +28 -48
  36. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +8 -1
  37. package/src/index.ts +6 -1
  38. package/src/inject.ts +0 -2
  39. package/src/protocols/protocol-v2/resources.ts +0 -47
  40. package/src/types/api/export.ts +0 -4
  41. package/src/types/api/firmwareUpdate.ts +0 -15
  42. package/src/types/api/index.ts +0 -2
  43. package/src/types/settings.ts +0 -20
  44. package/dist/types/api/protocolV2ResourceManifest.d.ts +0 -17
  45. package/dist/types/api/protocolV2ResourceManifest.d.ts.map +0 -1
  46. package/src/types/api/protocolV2ResourceManifest.ts +0 -19
@@ -17,7 +17,7 @@ import type {
17
17
  FirmwareUpdatePlanForceTarget,
18
18
  FirmwareUpdatePlanTarget,
19
19
  } from '../../types/api/firmwareUpdatePlan';
20
- import type { Features } from '../../types';
20
+ import type { Features, IProtocolV2ResourceSource } from '../../types';
21
21
 
22
22
  type FirmwareUpdatePlatform = 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
23
23
 
@@ -31,7 +31,6 @@ type ReleaseRecord = {
31
31
  version?: unknown;
32
32
  components?: unknown;
33
33
  installOrder?: unknown;
34
- resourceBundles?: unknown;
35
34
  fingerprint?: unknown;
36
35
  fingerprintWeb?: unknown;
37
36
  expectedSize?: unknown;
@@ -444,11 +443,9 @@ const buildProtocolV2Artifacts = (
444
443
  release: ReleaseRecord,
445
444
  {
446
445
  includeComponents = true,
447
- includeResources = true,
448
446
  componentTargets: selectedComponentTargets,
449
447
  }: {
450
448
  includeComponents?: boolean;
451
- includeResources?: boolean;
452
449
  componentTargets?: ReadonlySet<FirmwareUpdatePlanTarget>;
453
450
  } = {}
454
451
  ): {
@@ -523,43 +520,6 @@ const buildProtocolV2Artifacts = (
523
520
  targets.push(target);
524
521
  }
525
522
 
526
- const bundles =
527
- includeResources && Array.isArray(release.resourceBundles) ? release.resourceBundles : [];
528
- const resourceBundleNames = new Set<string>();
529
- for (const value of bundles) {
530
- const bundle = asRecord(value);
531
- const name = asString(bundle?.name);
532
- if (!bundle || !name) {
533
- throw ERRORS.TypedError(
534
- HardwareErrorCode.RuntimeError,
535
- 'Protocol V2 resource bundle is invalid',
536
- { firmwareUpdateCode: 'FirmwarePlanInvalid' }
537
- );
538
- }
539
- if (resourceBundleNames.has(name)) {
540
- throw ERRORS.TypedError(
541
- HardwareErrorCode.RuntimeError,
542
- `Protocol V2 resource bundle duplicates name ${name}`,
543
- { firmwareUpdateCode: 'FirmwarePlanInvalid' }
544
- );
545
- }
546
- resourceBundleNames.add(name);
547
- artifacts.push({
548
- artifactId: `resourceBundle:${name}`,
549
- role: 'resourceBundle',
550
- target: 'resource',
551
- url: assertArtifactUrl(bundle.url, `Protocol V2 resource bundle ${name}`),
552
- container: 'raw',
553
- logicalName: name,
554
- ...asIntegrity({
555
- size: bundle.expectedSize,
556
- sha256: bundle.fingerprint,
557
- }),
558
- });
559
- }
560
- if (bundles.length > 0) {
561
- targets.push('resource');
562
- }
563
523
  return { artifacts, targets: [...new Set(targets)] };
564
524
  };
565
525
 
@@ -679,7 +639,7 @@ export const buildProtocolV2FirmwareUpdatePlan = ({
679
639
  release,
680
640
  targetsToUpdate,
681
641
  forceUpdateTargets,
682
- resourceArchiveAvailable,
642
+ resourceArchive,
683
643
  }: {
684
644
  features: Features;
685
645
  firmwareType: EFirmwareType;
@@ -687,7 +647,7 @@ export const buildProtocolV2FirmwareUpdatePlan = ({
687
647
  release: ReleaseRecord | undefined;
688
648
  targetsToUpdate: readonly FirmwareUpdateV4Target[];
689
649
  forceUpdateTargets?: FirmwareUpdatePlanForceTarget[];
690
- resourceArchiveAvailable: boolean;
650
+ resourceArchive: IProtocolV2ResourceSource | undefined;
691
651
  }): FirmwareUpdatePlan => {
692
652
  const validatedForceTargets = validateFirmwareUpdatePlanForceTargets(forceUpdateTargets);
693
653
  if (validatedForceTargets.some(target => target === 'ble' || target === 'bootloader')) {
@@ -705,9 +665,32 @@ export const buildProtocolV2FirmwareUpdatePlan = ({
705
665
  }
706
666
  const protocolV2 = buildProtocolV2Artifacts(release ?? {}, {
707
667
  includeComponents: requestedComponentTargets.size > 0,
708
- includeResources: false,
709
668
  componentTargets: requestedComponentTargets,
710
669
  });
670
+ const resourceRequested = targetsToUpdate.includes('resource');
671
+ if (resourceRequested) {
672
+ const archive = resourceArchive;
673
+ if (!archive) {
674
+ return planError('Protocol V2 resource target has no resource archive');
675
+ }
676
+ const integrity = asIntegrity({
677
+ size: archive.archiveSize,
678
+ sha256: archive.archiveSha256,
679
+ });
680
+ if (integrity.expectedSize === undefined || integrity.expectedSha256 === undefined) {
681
+ planError('Protocol V2 resource archive integrity metadata is invalid');
682
+ }
683
+ protocolV2.artifacts.push({
684
+ artifactId: 'resource:archive',
685
+ role: 'resourceBundle',
686
+ target: 'resource',
687
+ url: assertArtifactUrl(archive.archiveUrl, 'Protocol V2 resource archive'),
688
+ container: 'zip',
689
+ logicalName: 'protocol-v2-resource-archive',
690
+ ...integrity,
691
+ });
692
+ protocolV2.targets.push('resource');
693
+ }
711
694
  const representedTargets = new Set(protocolV2.targets);
712
695
  const missingTarget = Array.from(requestedComponentTargets).find(
713
696
  target => !representedTargets.has(target)
@@ -718,12 +701,10 @@ export const buildProtocolV2FirmwareUpdatePlan = ({
718
701
  if (validatedForceTargets.includes('firmware') && protocolV2.targets.length === 0) {
719
702
  planError('Forced firmware update target firmware is not represented by the plan');
720
703
  }
721
- if (validatedForceTargets.includes('resource') && !resourceArchiveAvailable) {
704
+ if (validatedForceTargets.includes('resource') && !resourceArchive) {
722
705
  planError('Forced firmware update target resource has no Protocol V2 resource archive');
723
706
  }
724
707
 
725
- // Protocol V2 resource archives are materialized by the host into explicit
726
- // resourceFiles. The prepared artifact plan therefore binds firmware components only.
727
708
  return finalizeFirmwareUpdatePlan({
728
709
  features,
729
710
  firmwareType,
@@ -781,7 +762,6 @@ export const buildFirmwareUpdatePlan = ({
781
762
  if (executor === 'v4' && (shouldUpdateFirmware || shouldUpdateResource)) {
782
763
  const protocolV2 = buildProtocolV2Artifacts(firmwareRelease ?? {}, {
783
764
  includeComponents: shouldUpdateFirmware,
784
- includeResources: shouldUpdateResource,
785
765
  });
786
766
  artifacts = protocolV2.artifacts;
787
767
  targetsToUpdate = protocolV2.targets;
@@ -278,7 +278,14 @@ export const validateFirmwareUpdatePreparedPlan = (value: unknown): FirmwareUpda
278
278
  artifactIds.add(artifact.artifactId);
279
279
  artifactTargets.add(artifact.target);
280
280
  assertFirmwareArtifactReference(artifact.artifact);
281
- artifact.materializedEntries?.forEach(assertPreparedEntry);
281
+ const materializedEntryNames =
282
+ artifact.materializedEntries?.map(entry => {
283
+ assertPreparedEntry(entry);
284
+ return getFirmwareUpdateResourceName(entry.entryName).toLowerCase();
285
+ }) ?? [];
286
+ if (new Set(materializedEntryNames).size !== materializedEntryNames.length) {
287
+ return preparedPlanError('Firmware prepared plan contains duplicate entry names');
288
+ }
282
289
  }
283
290
  if (
284
291
  preparedPlan.targetsToUpdate.some(target => !FIRMWARE_UPDATE_PLAN_TARGETS.has(target)) ||
package/src/index.ts CHANGED
@@ -23,9 +23,14 @@ export { projectFeatures as projectDeviceStateFeatures } from './device/DeviceSt
23
23
  export { getMethodSupportedProtocols } from './api/utils';
24
24
  export {
25
25
  parseProtocolV2ResourceManifest,
26
- prepareProtocolV2ResourceFiles,
27
26
  selectProtocolV2ResourceManifestFiles,
28
27
  } from './protocols/protocol-v2/resources';
28
+ export { prepareFirmwareUpdateV4MemoryHost } from './api/firmware/FirmwareMemoryHost';
29
+ export type {
30
+ FirmwareMemoryArtifact,
31
+ FirmwareMemoryArtifactEntry,
32
+ FirmwareUpdateV4MemoryHost,
33
+ } from './api/firmware/FirmwareMemoryHost';
29
34
  export {
30
35
  getFirmwareUpdateHostBindingGeneration,
31
36
  registerFirmwareUpdateHostBinding,
package/src/inject.ts CHANGED
@@ -3,7 +3,6 @@ import {
3
3
  prepareFirmwareUpdatePlan,
4
4
  validateFirmwareUpdatePreparedPlan,
5
5
  } from './api/firmware/FirmwareUpdatePreparedPlan';
6
- import { prepareProtocolV2ResourceFiles } from './protocols/protocol-v2/resources';
7
6
  import {
8
7
  getFirmwareUpdateHostBindingGeneration,
9
8
  registerFirmwareUpdateHostBinding,
@@ -169,7 +168,6 @@ export const createCoreApi = (
169
168
  getFirmwareUpdateHostBindingGeneration,
170
169
  prepareFirmwareUpdatePlan,
171
170
  validateFirmwareUpdatePreparedPlan,
172
- prepareProtocolV2ResourceFiles,
173
171
  getLogs: () => call({ method: 'getLogs' }),
174
172
  clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
175
173
  /**
@@ -1,5 +1,3 @@
1
- import { sha256 } from '@noble/hashes/sha256';
2
-
3
1
  import type {
4
2
  IProtocolV2ResourceManifest,
5
3
  IProtocolV2ResourceManifestFile,
@@ -210,48 +208,3 @@ export function selectProtocolV2ResourceManifestFiles({
210
208
  }): IProtocolV2ResourceManifestFile[] {
211
209
  return targetsToUpdate.includes('resource') ? [...manifest.files] : [];
212
210
  }
213
-
214
- export function prepareProtocolV2ResourceFiles({
215
- manifest: value,
216
- files,
217
- targetsToUpdate,
218
- }: {
219
- manifest: unknown;
220
- files: Array<{ archivePath: string; binary: ArrayBuffer }>;
221
- targetsToUpdate: readonly FirmwareUpdateV4Target[];
222
- }): Array<{ binary: ArrayBuffer; devicePath: string; size: number; fileHash: string }> {
223
- const manifest = parseProtocolV2ResourceManifest(value);
224
- const selected = selectProtocolV2ResourceManifestFiles({ manifest, targetsToUpdate });
225
- const binaries = new Map(files.map(file => [file.archivePath, file.binary] as const));
226
- return selected.map(file => {
227
- const binary = binaries.get(file.archive_path);
228
- if (
229
- !binary ||
230
- !isProtocolV2ResourceFileValid(binary, {
231
- size: file.size,
232
- fileHash: file.sha256,
233
- })
234
- ) {
235
- throw new Error(`Pro2 resource manifest file verification failed: ${file.archive_path}`);
236
- }
237
- return {
238
- binary,
239
- devicePath: file.device_path,
240
- size: file.size,
241
- fileHash: file.sha256,
242
- };
243
- });
244
- }
245
-
246
- function bytesToHex(bytes: Uint8Array): string {
247
- return Array.from(bytes, byte => byte.toString(16).padStart(2, '0')).join('');
248
- }
249
-
250
- /** Verify the complete downloaded file before any device mutation. */
251
- export function isProtocolV2ResourceFileValid(
252
- binary: ArrayBuffer,
253
- resource: { size: number; fileHash: string }
254
- ): boolean {
255
- if (binary.byteLength !== resource.size) return false;
256
- return bytesToHex(sha256(new Uint8Array(binary))) === resource.fileHash.toLowerCase();
257
- }
@@ -49,10 +49,6 @@ export type {
49
49
  FirmwareUpdatePreparedEntry,
50
50
  FirmwareUpdatePreparedPlan,
51
51
  } from './firmwareUpdatePreparedPlan';
52
- export type {
53
- ProtocolV2PreparedResourceFile,
54
- ProtocolV2ResourceManifestBinary,
55
- } from './protocolV2ResourceManifest';
56
52
  export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
57
53
  export type {
58
54
  AllFirmwareRelease,
@@ -153,25 +153,10 @@ export interface FirmwareUpdateV4Params {
153
153
  se03Binary?: ArrayBuffer;
154
154
  se04Binary?: ArrayBuffer;
155
155
  forcedUpdateRes?: boolean;
156
- /**
157
- * Arbitrary Protocol V2 resource files written directly with FilesystemFileWrite.
158
- * Use this for every file selected from the manifest-driven resource archive.
159
- * When provided, these files are authoritative for the resource target.
160
- */
161
- resourceFiles?: Array<{
162
- binary: ArrayBuffer;
163
- devicePath: string;
164
- size?: number;
165
- fileHash?: string;
166
- }>;
167
156
  artifactReader?: FirmwareArtifactReader;
168
157
  componentArtifacts?: Partial<
169
158
  Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
170
159
  >;
171
- resourceBundleArtifacts?: Array<{
172
- name: string;
173
- artifact: FirmwareArtifactReference;
174
- }>;
175
160
  }
176
161
 
177
162
  export declare function registerFirmwareUpdateHostBinding(
@@ -41,7 +41,6 @@ import type {
41
41
  prepareFirmwareUpdatePlan,
42
42
  validateFirmwareUpdatePreparedPlan,
43
43
  } from './firmwareUpdatePreparedPlan';
44
- import type { prepareProtocolV2ResourceFiles } from './protocolV2ResourceManifest';
45
44
  import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
46
45
  import type { deviceReset } from './deviceReset';
47
46
  import type { deviceRecovery } from './deviceRecovery';
@@ -254,7 +253,6 @@ export type CoreApi = {
254
253
  getFirmwareUpdateCapabilities: typeof getFirmwareUpdateCapabilities;
255
254
  prepareFirmwareUpdatePlan: typeof prepareFirmwareUpdatePlan;
256
255
  validateFirmwareUpdatePreparedPlan: typeof validateFirmwareUpdatePreparedPlan;
257
- prepareProtocolV2ResourceFiles: typeof prepareProtocolV2ResourceFiles;
258
256
  cipherKeyValue: typeof cipherKeyValue;
259
257
 
260
258
  /**
@@ -104,24 +104,6 @@ export type IProtocolV2ResourceManifest = {
104
104
  files: IProtocolV2ResourceManifestFile[];
105
105
  };
106
106
 
107
- /** Pro2 RESC bundle okpkg descriptor for incremental FileWrite synchronization. */
108
- export type IProtocolV2ResourceBundle = {
109
- /** Bundle name, such as images, animation, translations, or fonts_roobert. */
110
- name: string;
111
- /** Download URL. */
112
- url: string;
113
- fingerprint?: string;
114
- expectedSize?: number;
115
- /** Device target path, such as vol0:/bundles/images/images.okpkg. */
116
- devicePath: string;
117
- /** okpkg payload_version used to skip matching content after FileRead. */
118
- version?: IVersionArray;
119
- /** okpkg payload_hash used for SHA3-512 comparison after FileRead. */
120
- payloadHash?: string;
121
- /** okpkg header_hash used for SHA3-512 comparison after FileRead. */
122
- headerHash?: string;
123
- };
124
-
125
107
  /** STM32 firmware config */
126
108
  export type IFirmwareReleaseInfo = {
127
109
  required: boolean;
@@ -149,8 +131,6 @@ export type IFirmwareReleaseInfo = {
149
131
  upgradeType?: 'payload-package-set' | string;
150
132
  components?: Record<string, IProtocolV2FirmwareComponent>;
151
133
  installOrder?: string[];
152
- /** Pro2 RESC bundles for incremental direct FileWrite synchronization. */
153
- resourceBundles?: IProtocolV2ResourceBundle[];
154
134
  bootloaderChangelog?: {
155
135
  [k in ILocale]: string;
156
136
  };
@@ -1,17 +0,0 @@
1
- import type { FirmwareUpdateV4Target } from './firmwareUpdate';
2
- export type ProtocolV2ResourceManifestBinary = {
3
- archivePath: string;
4
- binary: ArrayBuffer;
5
- };
6
- export type ProtocolV2PreparedResourceFile = {
7
- binary: ArrayBuffer;
8
- devicePath: string;
9
- size: number;
10
- fileHash: string;
11
- };
12
- export declare function prepareProtocolV2ResourceFiles(input: {
13
- manifest: unknown;
14
- files: ProtocolV2ResourceManifestBinary[];
15
- targetsToUpdate: readonly FirmwareUpdateV4Target[];
16
- }): ProtocolV2PreparedResourceFile[];
17
- //# sourceMappingURL=protocolV2ResourceManifest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"protocolV2ResourceManifest.d.ts","sourceRoot":"","sources":["../../../src/types/api/protocolV2ResourceManifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,MAAM,gCAAgC,GAAG;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,8BAA8B,CAAC,KAAK,EAAE;IAC5D,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,gCAAgC,EAAE,CAAC;IAC1C,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACpD,GAAG,8BAA8B,EAAE,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { FirmwareUpdateV4Target } from './firmwareUpdate';
2
-
3
- export type ProtocolV2ResourceManifestBinary = {
4
- archivePath: string;
5
- binary: ArrayBuffer;
6
- };
7
-
8
- export type ProtocolV2PreparedResourceFile = {
9
- binary: ArrayBuffer;
10
- devicePath: string;
11
- size: number;
12
- fileHash: string;
13
- };
14
-
15
- export declare function prepareProtocolV2ResourceFiles(input: {
16
- manifest: unknown;
17
- files: ProtocolV2ResourceManifestBinary[];
18
- targetsToUpdate: readonly FirmwareUpdateV4Target[];
19
- }): ProtocolV2PreparedResourceFile[];