@onekeyfe/hd-core 1.2.0-alpha.147 → 1.2.0-alpha.148

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 (39) hide show
  1. package/__tests__/device-lifecycle-events.test.ts +128 -2
  2. package/__tests__/device-utils.test.ts +8 -0
  3. package/__tests__/deviceUploadNft.test.ts +3 -0
  4. package/__tests__/protocol-v2-resources.test.ts +35 -89
  5. package/__tests__/protocol-v2-unlock-policy.test.ts +72 -0
  6. package/__tests__/protocol-v2.test.ts +51 -188
  7. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  8. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  9. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  10. package/dist/api/protocol-v2/DeviceReboot.d.ts +1 -1
  11. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
  12. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  13. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  14. package/dist/core/index.d.ts +2 -0
  15. package/dist/core/index.d.ts.map +1 -1
  16. package/dist/device/Device.d.ts +4 -0
  17. package/dist/device/Device.d.ts.map +1 -1
  18. package/dist/index.d.ts +14 -20
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +202 -314
  21. package/dist/protocols/protocol-v2/resources.d.ts +11 -7
  22. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  23. package/dist/types/settings.d.ts +0 -13
  24. package/dist/types/settings.d.ts.map +1 -1
  25. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  26. package/package.json +4 -4
  27. package/src/api/FirmwareUpdateV4.ts +61 -238
  28. package/src/api/PromptWebDeviceAccess.ts +2 -2
  29. package/src/api/device/DeviceRebootToBoardloader.ts +3 -1
  30. package/src/api/device/DeviceRebootToBootloader.ts +3 -1
  31. package/src/api/protocol-v2/DeviceReboot.ts +5 -0
  32. package/src/api/protocol-v2/DeviceUploadNft.ts +5 -1
  33. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +5 -1
  34. package/src/core/index.ts +28 -106
  35. package/src/device/Device.ts +59 -8
  36. package/src/index.ts +0 -4
  37. package/src/protocols/protocol-v2/resources.ts +92 -102
  38. package/src/types/settings.ts +0 -15
  39. package/src/utils/deviceInfoUtils.ts +7 -2
@@ -1,12 +1,16 @@
1
- import type { IProtocolV2ResourceManifest, IProtocolV2ResourceManifestFile, IProtocolV2Resources } from '../../types';
2
- import type { FirmwareUpdateV4Target } from '../../types/api/firmwareUpdate';
1
+ import type { IProtocolV2Resources, IVersionArray } from '../../types';
3
2
  export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH = "vol0:/loaders/bootloader/boot_resource.okpkg";
4
3
  export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH: string;
5
4
  export declare const PROTOCOL_V2_ROM_PARAMS_PACKAGE_PATH = "vol0:/loaders/rom/params.okpkg";
5
+ export declare const PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE = 24464;
6
6
  export declare function parseProtocolV2Resources(value: unknown): IProtocolV2Resources | undefined;
7
- export declare function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2ResourceManifest;
8
- export declare function selectProtocolV2ResourceManifestFiles({ manifest, targetsToUpdate, }: {
9
- manifest: IProtocolV2ResourceManifest;
10
- targetsToUpdate: readonly FirmwareUpdateV4Target[];
11
- }): IProtocolV2ResourceManifestFile[];
7
+ export type ProtocolV2ResourcePackageHeader = {
8
+ version: IVersionArray;
9
+ payloadLength: number;
10
+ devicePath: string;
11
+ payloadHash: string;
12
+ headerHash: string;
13
+ };
14
+ export declare function parseProtocolV2ResourcePackageHeader(bytes: Uint8Array, packageSize: number): ProtocolV2ResourcePackageHeader;
15
+ export declare function parseProtocolV2ResourcePackage(binary: ArrayBuffer | Uint8Array): ProtocolV2ResourcePackageHeader;
12
16
  //# sourceMappingURL=resources.d.ts.map
@@ -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;AAiFD,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,2BAA2B,CAqB3F;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":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvE,eAAO,MAAM,sCAAsC,iDACH,CAAC;AACjD,eAAO,MAAM,8CAA8C,QAAsD,CAAC;AAClH,eAAO,MAAM,mCAAmC,mCAAmC,CAAC;AACpF,eAAO,MAAM,wCAAwC,QAAS,CAAC;AAW/D,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,GAAG,SAAS,CA8BzF;AAoDD,MAAM,MAAM,+BAA+B,GAAG;IAC5C,OAAO,EAAE,aAAa,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,UAAU,EACjB,WAAW,EAAE,MAAM,GAClB,+BAA+B,CAyCjC;AAED,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,WAAW,GAAG,UAAU,GAC/B,+BAA+B,CAGjC"}
@@ -43,19 +43,6 @@ export type IProtocolV2ResourceSource = {
43
43
  export type IProtocolV2Resources = {
44
44
  source: IProtocolV2ResourceSource;
45
45
  };
46
- export type IProtocolV2ResourceManifestFile = {
47
- archive_path: string;
48
- original_name?: string;
49
- device_path: string;
50
- size: number;
51
- sha256: string;
52
- signed?: boolean;
53
- sig_algo?: string;
54
- payload_version?: string | null;
55
- };
56
- export type IProtocolV2ResourceManifest = {
57
- files: IProtocolV2ResourceManifestFile[];
58
- };
59
46
  export type IFirmwareReleaseInfo = {
60
47
  required: boolean;
61
48
  url: string;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/types/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,KAAK,GACL,cAAc,GACd,UAAU,GACV,cAAc,GACd,QAAQ,GACR,gBAAgB,GAChB,iBAAiB,GACjB,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AACf,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MA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eAAO,MAAM,cAAc,cAAe,mBAAmB,kBAkB5D,CAAC;AAMF,eAAO,MAAM,qBAAqB,aACtB,mBAAmB,GAAG,SAAS,iCACV,WAAW,GAAG,YAAY,KAAK,aAAa,GAAG,SAAS,KACtF,aAAa,GAAG,SAyBlB,CAAC;AAEF,eAAO,MAAM,eAAe,cAAe,mBAAmB,gDACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.147",
3
+ "version": "1.2.0-alpha.148",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.2.0-alpha.147",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.147",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.148",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.148",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "buffer": "^6.0.3",
@@ -46,5 +46,5 @@
46
46
  "@types/w3c-web-usb": "^1.0.10",
47
47
  "@types/web-bluetooth": "^0.0.21"
48
48
  },
49
- "gitHead": "a34e98865e6be227cf3e00d486146e6592761db0"
49
+ "gitHead": "0538b18c48292741d9b7c29a87851227bc3e229b"
50
50
  }
@@ -32,8 +32,11 @@ import {
32
32
  } from '../protocols/protocol-v2';
33
33
  import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
34
34
  import {
35
- parseProtocolV2ResourceManifest,
36
- selectProtocolV2ResourceManifestFiles,
35
+ PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH,
36
+ PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE,
37
+ parseProtocolV2ResourcePackage,
38
+ parseProtocolV2ResourcePackageHeader,
39
+ type ProtocolV2ResourcePackageHeader,
37
40
  } from '../protocols/protocol-v2/resources';
38
41
  import {
39
42
  getProtocolV2UnknownErrorText,
@@ -70,7 +73,6 @@ import type {
70
73
  Features,
71
74
  IFirmwareReleaseInfo,
72
75
  IProtocolV2FirmwareComponent,
73
- IProtocolV2ResourceManifestFile,
74
76
  IVersionArray,
75
77
  KnownDevice,
76
78
  } from '../types';
@@ -109,21 +111,9 @@ const PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS = 1000;
109
111
  const PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE = 'FirmwareInstallStatusConflict';
110
112
  const PROTOCOL_V2_INSTALL_FAILED_CODE = 'FirmwareInstallFailed';
111
113
  const PROTOCOL_V2_INSTALL_TIMEOUT_CODE = 'FirmwareInstallTimeout';
112
- const PROTOCOL_V2_OKPP_HEADER_SIZE = 0x52a0;
113
- const PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET = 0x200;
114
- const PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET = 0x240;
115
- const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
116
- const PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES = 1024 * 1024;
117
114
  const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
118
115
  const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
119
116
 
120
- const getProtocolV2LocalResourceArchivePath = (entryName: string) => {
121
- const match = entryName.match(
122
- /(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu
123
- );
124
- return match?.[1];
125
- };
126
-
127
117
  const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set<FirmwareUpdateV4Target>(['se03', 'se04']);
128
118
 
129
119
  const getProtocolV2ZipEntrySizes = (entry: JSZip.JSZipObject) => {
@@ -241,6 +231,11 @@ type ProtocolV2ResourceBundleSource = {
241
231
  type ProtocolV2LocalResourceArchive = {
242
232
  binary: ArrayBuffer;
243
233
  materializedEntries: FirmwareMemoryArtifactEntry[];
234
+ resources: Array<{
235
+ entryName: string;
236
+ binary: ArrayBuffer;
237
+ header: ProtocolV2ResourcePackageHeader;
238
+ }>;
244
239
  };
245
240
 
246
241
  type JSZipSizedEntry = JSZip.JSZipObject & {
@@ -255,13 +250,6 @@ type ProtocolV2TransferBatch = {
255
250
  resourceSources: ProtocolV2ResourceBundleSource[];
256
251
  };
257
252
 
258
- type ProtocolV2OkppHeader = {
259
- type: string;
260
- version: IVersionArray;
261
- payloadHash: string;
262
- headerHash: string;
263
- };
264
-
265
253
  const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS: Readonly<
266
254
  Record<string, ProtocolV2RemoteComponentTarget>
267
255
  > = {
@@ -313,18 +301,9 @@ const PROTOCOL_V2_FIRMWARE_STAGING_PATHS = new Set(
313
301
  )
314
302
  );
315
303
 
316
- const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH = 'vol0:/loaders/bootloader/boot_resource.okpkg';
317
- const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH = `${PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH}.staging`;
318
-
319
304
  const isProtocolV2BootResourcePackagePath = (devicePath: string) =>
320
305
  typeof devicePath === 'string' &&
321
- devicePath.replace(/^vol0:(?!\/)/i, 'vol0:/').toLowerCase() ===
322
- PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH;
323
-
324
- const resolveProtocolV2ResourceWritePath = (devicePath: string) =>
325
- isProtocolV2BootResourcePackagePath(devicePath)
326
- ? PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH
327
- : devicePath;
306
+ devicePath.toLowerCase() === PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH;
328
307
 
329
308
  const PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID = new Map<
330
309
  number,
@@ -491,42 +470,6 @@ const toProtocolV2FiniteNumber = (value: unknown) => {
491
470
  return undefined;
492
471
  };
493
472
 
494
- const readProtocolV2Ascii = (bytes: Uint8Array, offset: number, length: number) =>
495
- Array.from(bytes.slice(offset, offset + length))
496
- .map(byte => String.fromCharCode(byte))
497
- .join('');
498
-
499
- const parseProtocolV2OkppHeader = (bytes: Uint8Array): ProtocolV2OkppHeader | null => {
500
- if (bytes.byteLength < PROTOCOL_V2_OKPP_HEADER_SIZE) return null;
501
- if (readProtocolV2Ascii(bytes, 0, 4) !== 'OKPP') return null;
502
-
503
- const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
504
- const headerLen = view.getUint32(0x0c, true);
505
- if (headerLen !== PROTOCOL_V2_OKPP_HEADER_SIZE) return null;
506
-
507
- const packedVersion = view.getUint32(0x10, true);
508
- return {
509
- type: readProtocolV2Ascii(bytes, 0x08, 4),
510
- version: [
511
- Math.floor(packedVersion / 0x10000) % 0x100,
512
- Math.floor(packedVersion / 0x100) % 0x100,
513
- packedVersion % 0x100,
514
- ],
515
- payloadHash: bytesToHex(
516
- bytes.slice(
517
- PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET,
518
- PROTOCOL_V2_OKPP_PAYLOAD_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE
519
- )
520
- ),
521
- headerHash: bytesToHex(
522
- bytes.slice(
523
- PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET,
524
- PROTOCOL_V2_OKPP_HEADER_HASH_OFFSET + PROTOCOL_V2_OKPP_HASH_SIZE
525
- )
526
- ),
527
- };
528
- };
529
-
530
473
  export const isProtocolV2FirmwareFingerprintValid = (
531
474
  binary: ArrayBuffer | Uint8Array,
532
475
  fingerprint: string | undefined
@@ -1262,130 +1205,69 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
1262
1205
  );
1263
1206
  }
1264
1207
  const zipEntries = Object.values(zip.files);
1208
+ const resourceEntries = zipEntries.filter(
1209
+ entry => !entry.dir && entry.name.toLowerCase().endsWith('.okpkg')
1210
+ );
1265
1211
  if (
1266
- zipEntries.some(entry => entry.unsafeOriginalName && entry.unsafeOriginalName !== entry.name)
1212
+ resourceEntries.length === 0 ||
1213
+ resourceEntries.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT
1267
1214
  ) {
1268
1215
  throw ERRORS.TypedError(
1269
1216
  HardwareErrorCode.RuntimeError,
1270
- 'Protocol V2 local resource ZIP contains an unsafe entry path',
1271
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1272
- );
1273
- }
1274
- const entries = zipEntries.filter(entry => !entry.dir);
1275
- if (entries.length === 0) {
1276
- throw ERRORS.TypedError(
1277
- HardwareErrorCode.RuntimeError,
1278
- 'Protocol V2 local resource ZIP entry set is invalid',
1217
+ 'Protocol V2 resource ZIP has no valid resource package set',
1279
1218
  { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1280
1219
  );
1281
1220
  }
1282
- const manifestEntry = entries.find(entry => entry.name.split('/').pop() === 'manifest.json');
1283
- let manifestBinary: ArrayBuffer | undefined;
1284
- let manifestDirectory = '';
1285
- let selectedFiles: IProtocolV2ResourceManifestFile[];
1286
- if (manifestEntry) {
1221
+
1222
+ let totalSize = 0;
1223
+ const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
1224
+ const resources: ProtocolV2LocalResourceArchive['resources'] = [];
1225
+ const devicePaths = new Set<string>();
1226
+ for (const entry of resourceEntries) {
1227
+ const { compressedSize, uncompressedSize } = getProtocolV2ZipEntrySizes(entry);
1228
+ totalSize += uncompressedSize;
1287
1229
  if (
1288
- getProtocolV2ZipEntrySizes(manifestEntry).uncompressedSize >
1289
- PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
1230
+ compressedSize > binary.byteLength ||
1231
+ uncompressedSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES ||
1232
+ totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES
1290
1233
  ) {
1291
1234
  throw ERRORS.TypedError(
1292
1235
  HardwareErrorCode.RuntimeError,
1293
- 'Protocol V2 local resource manifest size is invalid',
1236
+ `Protocol V2 resource package size is invalid: ${entry.name}`,
1294
1237
  { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1295
1238
  );
1296
1239
  }
1297
- manifestBinary = await manifestEntry.async('arraybuffer');
1298
- if (
1299
- manifestBinary.byteLength <= 0 ||
1300
- manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
1301
- ) {
1240
+ const fileBinary = await entry.async('arraybuffer');
1241
+ if (fileBinary.byteLength !== uncompressedSize) {
1302
1242
  throw ERRORS.TypedError(
1303
1243
  HardwareErrorCode.RuntimeError,
1304
- 'Protocol V2 local resource manifest size is invalid',
1305
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1244
+ `Protocol V2 resource package is incomplete: ${entry.name}`,
1245
+ { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
1306
1246
  );
1307
1247
  }
1308
- let manifestValue: unknown;
1248
+ let header: ProtocolV2ResourcePackageHeader;
1309
1249
  try {
1310
- manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
1250
+ header = parseProtocolV2ResourcePackage(fileBinary);
1311
1251
  } catch (error) {
1312
1252
  throw ERRORS.TypedError(
1313
1253
  HardwareErrorCode.RuntimeError,
1314
- `Protocol V2 local resource manifest is invalid: ${String(error)}`,
1254
+ `Protocol V2 resource package is invalid: ${entry.name}: ${String(error)}`,
1315
1255
  { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1316
1256
  );
1317
1257
  }
1318
- selectedFiles = selectProtocolV2ResourceManifestFiles({
1319
- manifest: parseProtocolV2ResourceManifest(manifestValue),
1320
- targetsToUpdate: this.params.targetsToUpdate ?? [],
1321
- });
1322
- manifestDirectory = manifestEntry.name.slice(0, -'manifest.json'.length);
1323
- } else {
1324
- selectedFiles = entries.flatMap(entry => {
1325
- const archivePath = getProtocolV2LocalResourceArchivePath(entry.name);
1326
- if (!archivePath) return [];
1327
- return [
1328
- {
1329
- archive_path: archivePath,
1330
- original_name: archivePath.split('/').pop() ?? archivePath,
1331
- device_path: `vol0:/${archivePath}`,
1332
- size: getProtocolV2ZipEntrySizes(entry).uncompressedSize,
1333
- sha256: '',
1334
- },
1335
- ];
1336
- });
1337
- }
1338
- if (selectedFiles.length === 0 || selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
1339
- throw ERRORS.TypedError(
1340
- HardwareErrorCode.RuntimeError,
1341
- 'Protocol V2 local resource ZIP has no resource packages',
1342
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1343
- );
1344
- }
1345
-
1346
- let totalSize = 0;
1347
- const materializedEntries: FirmwareMemoryArtifactEntry[] = [];
1348
- const normalizedFiles: IProtocolV2ResourceManifestFile[] = [];
1349
- for (const file of selectedFiles) {
1350
- const entry = manifestEntry
1351
- ? zip.file(`${manifestDirectory}${file.archive_path}`)
1352
- : entries.find(
1353
- candidate => getProtocolV2LocalResourceArchivePath(candidate.name) === file.archive_path
1354
- );
1355
- if (!entry) {
1258
+ const canonicalDevicePath = header.devicePath.toLowerCase();
1259
+ if (devicePaths.has(canonicalDevicePath)) {
1356
1260
  throw ERRORS.TypedError(
1357
1261
  HardwareErrorCode.RuntimeError,
1358
- `Protocol V2 local resource ZIP is missing ${file.archive_path}`,
1262
+ `Protocol V2 resource ZIP contains duplicate device path: ${header.devicePath}`,
1359
1263
  { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1360
1264
  );
1361
1265
  }
1362
- const { uncompressedSize } = getProtocolV2ZipEntrySizes(entry);
1363
- totalSize += uncompressedSize;
1364
- if (uncompressedSize !== file.size || totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES) {
1365
- throw ERRORS.TypedError(
1366
- HardwareErrorCode.RuntimeError,
1367
- `Protocol V2 local resource file declared size is invalid: ${file.archive_path}`,
1368
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1369
- );
1370
- }
1371
- const fileBinary = await entry.async('arraybuffer');
1372
- const digest = bytesToHex(sha256(new Uint8Array(fileBinary)));
1373
- if (
1374
- fileBinary.byteLength !== file.size ||
1375
- (file.sha256 && digest !== file.sha256.toLowerCase())
1376
- ) {
1377
- throw ERRORS.TypedError(
1378
- HardwareErrorCode.RuntimeError,
1379
- `Protocol V2 local resource file does not match manifest: ${file.archive_path}`,
1380
- { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
1381
- );
1382
- }
1383
- normalizedFiles.push({ ...file, sha256: digest });
1384
- materializedEntries.push({ entryName: file.archive_path, binary: fileBinary });
1266
+ devicePaths.add(canonicalDevicePath);
1267
+ materializedEntries.push({ entryName: entry.name, binary: fileBinary });
1268
+ resources.push({ entryName: entry.name, binary: fileBinary, header });
1385
1269
  }
1386
- manifestBinary ??= new TextEncoder().encode(JSON.stringify({ files: normalizedFiles })).buffer;
1387
- materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
1388
- return { binary, materializedEntries };
1270
+ return { binary, materializedEntries, resources };
1389
1271
  }
1390
1272
 
1391
1273
  private async prepareProtocolV2ResourceSources(): Promise<ProtocolV2ResourceBundleSource[]> {
@@ -1450,82 +1332,19 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
1450
1332
  );
1451
1333
  }
1452
1334
 
1453
- // The verified archive bytes are authoritative. Host materialization is an
1454
- // implementation detail and may preserve wrapper paths or extra metadata files.
1335
+ // The verified ZIP bytes are authoritative. Non-okpkg entries are release
1336
+ // metadata only; each RESOURCE package carries its own device path.
1455
1337
  const verifiedArchive = await this.prepareProtocolV2LocalResourceArchive(archiveBinary);
1456
- const verifiedEntriesByName = new Map(
1457
- verifiedArchive.materializedEntries.map(entry => [entry.entryName, entry.binary] as const)
1458
- );
1459
- const manifestBinary = verifiedEntriesByName.get('manifest.json');
1460
- if (!manifestBinary) {
1461
- throw ERRORS.TypedError(
1462
- HardwareErrorCode.RuntimeError,
1463
- 'Protocol V2 prepared resource archive has no valid manifest.json',
1464
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1465
- );
1466
- }
1467
-
1468
- let manifestValue: unknown;
1469
- try {
1470
- manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
1471
- } catch (error) {
1472
- throw ERRORS.TypedError(
1473
- HardwareErrorCode.RuntimeError,
1474
- `Protocol V2 prepared resource manifest is invalid: ${String(error)}`,
1475
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1476
- );
1477
- }
1478
- const manifest = parseProtocolV2ResourceManifest(manifestValue);
1479
- const selectedFiles = selectProtocolV2ResourceManifestFiles({
1480
- manifest,
1481
- targetsToUpdate: this.params.targetsToUpdate ?? [],
1482
- });
1483
- if (selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
1484
- throw ERRORS.TypedError(
1485
- HardwareErrorCode.RuntimeError,
1486
- 'Protocol V2 prepared resource archive contains too many files',
1487
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1488
- );
1489
- }
1490
-
1491
- let totalSize = 0;
1492
1338
  const sources: ProtocolV2ResourceBundleSource[] = [];
1493
- for (const [index, file] of selectedFiles.entries()) {
1494
- const binary = verifiedEntriesByName.get(file.archive_path);
1495
- if (!binary || binary.byteLength !== file.size) {
1496
- throw ERRORS.TypedError(
1497
- HardwareErrorCode.RuntimeError,
1498
- `Protocol V2 prepared resource file does not match manifest: ${file.archive_path}`,
1499
- { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' }
1500
- );
1501
- }
1502
- totalSize += binary.byteLength;
1503
- if (totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES) {
1504
- throw ERRORS.TypedError(
1505
- HardwareErrorCode.RuntimeError,
1506
- 'Protocol V2 prepared resource archive exceeds the total size limit',
1507
- { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
1508
- );
1509
- }
1510
- // 使用从获批 ZIP 中提取的规范字节,避免宿主在校验后替换 entry reader 内容。
1511
- const source = await this.openProtocolV2MemorySource(binary);
1512
- const header =
1513
- source.size >= PROTOCOL_V2_OKPP_HEADER_SIZE
1514
- ? parseProtocolV2OkppHeader(
1515
- new Uint8Array(await source.readAt(0, PROTOCOL_V2_OKPP_HEADER_SIZE))
1516
- )
1517
- : null;
1339
+ for (const resource of verifiedArchive.resources) {
1340
+ const source = await this.openProtocolV2MemorySource(resource.binary);
1518
1341
  sources.push({
1519
- name: file.original_name || `resource-${index}`,
1342
+ name: resource.entryName.split('/').pop() ?? resource.entryName,
1520
1343
  source,
1521
- devicePath: file.device_path,
1522
- ...(header
1523
- ? {
1524
- version: header.version,
1525
- payloadHash: header.payloadHash,
1526
- headerHash: header.headerHash,
1527
- }
1528
- : {}),
1344
+ devicePath: resource.header.devicePath,
1345
+ version: resource.header.version,
1346
+ payloadHash: resource.header.payloadHash,
1347
+ headerHash: resource.header.headerHash,
1529
1348
  });
1530
1349
  }
1531
1350
  return sources;
@@ -2023,7 +1842,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2023
1842
  !pathInfoRes.message?.exist ||
2024
1843
  pathInfoRes.message?.directory ||
2025
1844
  fileSize === undefined ||
2026
- fileSize < PROTOCOL_V2_OKPP_HEADER_SIZE ||
1845
+ fileSize < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE ||
2027
1846
  (expectedSize !== undefined && fileSize !== expectedSize)
2028
1847
  ) {
2029
1848
  return null;
@@ -2032,8 +1851,8 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2032
1851
  const chunkSize = this.getProtocolV2FirmwareChunkSize('read');
2033
1852
  const chunks: Uint8Array[] = [];
2034
1853
  let offset = 0;
2035
- while (offset < PROTOCOL_V2_OKPP_HEADER_SIZE) {
2036
- const readLen = Math.min(chunkSize, PROTOCOL_V2_OKPP_HEADER_SIZE - offset);
1854
+ while (offset < PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE) {
1855
+ const readLen = Math.min(chunkSize, PROTOCOL_V2_RESOURCE_PACKAGE_HEADER_SIZE - offset);
2037
1856
  const res = await typedCall('FilesystemFileRead', 'FilesystemFile', {
2038
1857
  file: {
2039
1858
  path: filePath,
@@ -2055,7 +1874,11 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2055
1874
  headerBytes.set(chunk, cursor);
2056
1875
  cursor += chunk.byteLength;
2057
1876
  });
2058
- return parseProtocolV2OkppHeader(headerBytes);
1877
+ try {
1878
+ return parseProtocolV2ResourcePackageHeader(headerBytes, fileSize);
1879
+ } catch {
1880
+ return null;
1881
+ }
2059
1882
  }
2060
1883
 
2061
1884
  /** Compare the downloaded and installed okpkg headers before transferring a resource. */
@@ -2348,7 +2171,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2348
2171
  for (const resource of resourcesToSync) {
2349
2172
  // The bootloader keeps its live resource package mounted. FatFs rejects
2350
2173
  // replacing an open file, so early boot promotes this staging file before mounting it.
2351
- const writePath = resolveProtocolV2ResourceWritePath(resource.devicePath);
2174
+ const writePath = resource.devicePath;
2352
2175
  processedSize = await this.protocolV2SourceUpdateProcess({
2353
2176
  source: resource.source,
2354
2177
  filePath: writePath,
@@ -1,4 +1,4 @@
1
- import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
1
+ import { ERRORS, HardwareErrorCode, resolveOneKeyUsbDevicePath } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import { BaseMethod } from './BaseMethod';
4
4
  import TransportManager from '../data-manager/TransportManager';
@@ -52,7 +52,7 @@ export default class PromptWebDeviceAccess extends BaseMethod {
52
52
 
53
53
  if (isWebUsbEnv) {
54
54
  const usbDevice = device as USBDevice;
55
- const path = usbDevice.serialNumber;
55
+ const path = resolveOneKeyUsbDevicePath(usbDevice);
56
56
  if (!path) {
57
57
  throw ERRORS.TypedError(HardwareErrorCode.WebDevicePromptAccessError);
58
58
  }
@@ -1,4 +1,4 @@
1
- import { DeviceRebootType } from '@onekeyfe/hd-transport';
1
+ import { DeviceRebootType, DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
2
 
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
 
@@ -13,6 +13,8 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
13
13
  init() {
14
14
  this.useDevicePassphraseState = false;
15
15
  this.skipForceUpdateCheck = true;
16
+ this.unlockPolicy = 'unlock-before-run';
17
+ this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
16
18
  }
17
19
 
18
20
  getVersionRange() {
@@ -1,4 +1,4 @@
1
- import { DeviceRebootType } from '@onekeyfe/hd-transport';
1
+ import { DeviceRebootType, DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
2
 
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
 
@@ -13,6 +13,8 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
13
13
  init() {
14
14
  this.useDevicePassphraseState = false;
15
15
  this.skipForceUpdateCheck = true;
16
+ this.unlockPolicy = 'unlock-before-run';
17
+ this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
16
18
  }
17
19
 
18
20
  getVersionRange() {
@@ -1,3 +1,5 @@
1
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
+
1
3
  import { BaseMethod } from '../BaseMethod';
2
4
  import { normalizeRebootType } from './helpers';
3
5
 
@@ -11,6 +13,9 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
11
13
  init() {
12
14
  this.skipForceUpdateCheck = true;
13
15
  this.useDevicePassphraseState = false;
16
+ this.unlockPolicy = 'unlock-before-run';
17
+ // Device-management action: main PIN or Attach PIN may authorize reboot.
18
+ this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
14
19
  this.params = {
15
20
  rebootType: this.payload.rebootType,
16
21
  reboot_type: this.payload.reboot_type,
@@ -1,4 +1,5 @@
1
1
  import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
2
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
3
 
3
4
  import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
4
5
  import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
@@ -129,7 +130,10 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
129
130
  paceMs,
130
131
  timeoutMs,
131
132
  };
132
- this.unlockPolicy = 'none';
133
+ this.unlockPolicy = 'unlock-before-run';
134
+ // File writes and NftUpdate require an unlocked device. Either PIN may
135
+ // authorize this device-management action.
136
+ this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
133
137
  this.skipForceUpdateCheck = true;
134
138
  this.useDevicePassphraseState = false;
135
139
  }
@@ -1,6 +1,7 @@
1
1
  import { blake2s } from '@noble/hashes/blake2s';
2
2
  import { bytesToHex } from '@noble/hashes/utils';
3
3
  import { createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
4
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
4
5
 
5
6
  import { BaseMethod } from '../BaseMethod';
6
7
  import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
@@ -78,7 +79,10 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
78
79
  });
79
80
  this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
80
81
  this.params = { jpegBase64, fileName, chunkSize };
81
- this.unlockPolicy = 'none';
82
+ this.unlockPolicy = 'unlock-before-run';
83
+ // File writes and wallpaper apply require an unlocked device. Either PIN
84
+ // may authorize this device-management action.
85
+ this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
82
86
  this.skipForceUpdateCheck = true;
83
87
  this.useDevicePassphraseState = false;
84
88
  }