@onekeyfe/hd-core 1.2.0-alpha.145 → 1.2.0-alpha.147
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.
- package/__tests__/device-lifecycle-events.test.ts +1 -23
- package/__tests__/device-utils.test.ts +0 -8
- package/__tests__/deviceUploadNft.test.ts +0 -3
- package/__tests__/protocol-v2-resources.test.ts +89 -35
- package/__tests__/protocol-v2-unlock-policy.test.ts +0 -35
- package/__tests__/protocol-v2.test.ts +188 -49
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +298 -133
- package/dist/protocols/protocol-v2/resources.d.ts +7 -11
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +238 -61
- package/src/api/PromptWebDeviceAccess.ts +2 -2
- package/src/api/protocol-v2/DeviceUploadNft.ts +1 -5
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -5
- package/src/core/index.ts +99 -11
- package/src/index.ts +4 -0
- package/src/protocols/protocol-v2/resources.ts +102 -92
- package/src/types/settings.ts +15 -0
- package/src/utils/deviceInfoUtils.ts +2 -7
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IProtocolV2ResourceManifest, IProtocolV2ResourceManifestFile, IProtocolV2Resources } from '../../types';
|
|
2
|
+
import type { FirmwareUpdateV4Target } from '../../types/api/firmwareUpdate';
|
|
2
3
|
export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH = "vol0:/loaders/bootloader/boot_resource.okpkg";
|
|
3
4
|
export declare const PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_STAGING_PATH: string;
|
|
4
5
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
headerHash: string;
|
|
13
|
-
};
|
|
14
|
-
export declare function parseProtocolV2ResourcePackageHeader(bytes: Uint8Array, packageSize: number): ProtocolV2ResourcePackageHeader;
|
|
15
|
-
export declare function parseProtocolV2ResourcePackage(binary: ArrayBuffer | Uint8Array): ProtocolV2ResourcePackageHeader;
|
|
7
|
+
export declare function parseProtocolV2ResourceManifest(value: unknown): IProtocolV2ResourceManifest;
|
|
8
|
+
export declare function selectProtocolV2ResourceManifestFiles({ manifest, targetsToUpdate, }: {
|
|
9
|
+
manifest: IProtocolV2ResourceManifest;
|
|
10
|
+
targetsToUpdate: readonly FirmwareUpdateV4Target[];
|
|
11
|
+
}): IProtocolV2ResourceManifestFile[];
|
|
16
12
|
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/resources.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/types/settings.d.ts
CHANGED
|
@@ -43,6 +43,19 @@ 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
|
+
};
|
|
46
59
|
export type IFirmwareReleaseInfo = {
|
|
47
60
|
required: boolean;
|
|
48
61
|
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,GAC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AAC;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;QACZ,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE;aACR,CAAC,IAAI,OAAO,GAAG,MAAM;SACvB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;CAC7B,GAAG,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"deviceInfoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceInfoUtils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAKlE,eAAO,MAAM,aAAa,cAAe,mBAAmB,KAAG,WAClC,CAAC;AAM9B,eAAO,MAAM,sBAAsB,UAAW,MAAM,KAAG,WActD,CAAC;AAMF,eAAO,MAAM,gBAAgB,cAAe,mBAAmB,KAAG,MAAM,GAAG,IAC3C,CAAC;AAKjC,eAAO,MAAM,iBAAiB,cAAe,mBAAmB,KAAG,MAClC,CAAC;AAKlC,eAAO,MAAM,aAAa,cANmB,mBAAmB,KAAG,MAMrB,CAAC;AAK/C,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.
|
|
3
|
+
"version": "1.2.0-alpha.147",
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.147",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.147",
|
|
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": "
|
|
49
|
+
"gitHead": "a34e98865e6be227cf3e00d486146e6592761db0"
|
|
50
50
|
}
|
|
@@ -32,11 +32,8 @@ import {
|
|
|
32
32
|
} from '../protocols/protocol-v2';
|
|
33
33
|
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
parseProtocolV2ResourcePackage,
|
|
38
|
-
parseProtocolV2ResourcePackageHeader,
|
|
39
|
-
type ProtocolV2ResourcePackageHeader,
|
|
35
|
+
parseProtocolV2ResourceManifest,
|
|
36
|
+
selectProtocolV2ResourceManifestFiles,
|
|
40
37
|
} from '../protocols/protocol-v2/resources';
|
|
41
38
|
import {
|
|
42
39
|
getProtocolV2UnknownErrorText,
|
|
@@ -73,6 +70,7 @@ import type {
|
|
|
73
70
|
Features,
|
|
74
71
|
IFirmwareReleaseInfo,
|
|
75
72
|
IProtocolV2FirmwareComponent,
|
|
73
|
+
IProtocolV2ResourceManifestFile,
|
|
76
74
|
IVersionArray,
|
|
77
75
|
KnownDevice,
|
|
78
76
|
} from '../types';
|
|
@@ -111,9 +109,21 @@ const PROTOCOL_V2_TRANSFER_PROGRESS_HEARTBEAT_MS = 1000;
|
|
|
111
109
|
const PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE = 'FirmwareInstallStatusConflict';
|
|
112
110
|
const PROTOCOL_V2_INSTALL_FAILED_CODE = 'FirmwareInstallFailed';
|
|
113
111
|
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;
|
|
114
117
|
const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
|
|
115
118
|
const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
|
|
116
119
|
|
|
120
|
+
const getProtocolV2LocalResourceArchivePath = (entryName: string) => {
|
|
121
|
+
const match = entryName.match(
|
|
122
|
+
/(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu
|
|
123
|
+
);
|
|
124
|
+
return match?.[1];
|
|
125
|
+
};
|
|
126
|
+
|
|
117
127
|
const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set<FirmwareUpdateV4Target>(['se03', 'se04']);
|
|
118
128
|
|
|
119
129
|
const getProtocolV2ZipEntrySizes = (entry: JSZip.JSZipObject) => {
|
|
@@ -231,11 +241,6 @@ type ProtocolV2ResourceBundleSource = {
|
|
|
231
241
|
type ProtocolV2LocalResourceArchive = {
|
|
232
242
|
binary: ArrayBuffer;
|
|
233
243
|
materializedEntries: FirmwareMemoryArtifactEntry[];
|
|
234
|
-
resources: Array<{
|
|
235
|
-
entryName: string;
|
|
236
|
-
binary: ArrayBuffer;
|
|
237
|
-
header: ProtocolV2ResourcePackageHeader;
|
|
238
|
-
}>;
|
|
239
244
|
};
|
|
240
245
|
|
|
241
246
|
type JSZipSizedEntry = JSZip.JSZipObject & {
|
|
@@ -250,6 +255,13 @@ type ProtocolV2TransferBatch = {
|
|
|
250
255
|
resourceSources: ProtocolV2ResourceBundleSource[];
|
|
251
256
|
};
|
|
252
257
|
|
|
258
|
+
type ProtocolV2OkppHeader = {
|
|
259
|
+
type: string;
|
|
260
|
+
version: IVersionArray;
|
|
261
|
+
payloadHash: string;
|
|
262
|
+
headerHash: string;
|
|
263
|
+
};
|
|
264
|
+
|
|
253
265
|
const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS: Readonly<
|
|
254
266
|
Record<string, ProtocolV2RemoteComponentTarget>
|
|
255
267
|
> = {
|
|
@@ -301,9 +313,18 @@ const PROTOCOL_V2_FIRMWARE_STAGING_PATHS = new Set(
|
|
|
301
313
|
)
|
|
302
314
|
);
|
|
303
315
|
|
|
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
|
+
|
|
304
319
|
const isProtocolV2BootResourcePackagePath = (devicePath: string) =>
|
|
305
320
|
typeof devicePath === 'string' &&
|
|
306
|
-
devicePath.toLowerCase() ===
|
|
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;
|
|
307
328
|
|
|
308
329
|
const PROTOCOL_V2_UPDATE_TARGET_BY_TARGET_ID = new Map<
|
|
309
330
|
number,
|
|
@@ -470,6 +491,42 @@ const toProtocolV2FiniteNumber = (value: unknown) => {
|
|
|
470
491
|
return undefined;
|
|
471
492
|
};
|
|
472
493
|
|
|
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
|
+
|
|
473
530
|
export const isProtocolV2FirmwareFingerprintValid = (
|
|
474
531
|
binary: ArrayBuffer | Uint8Array,
|
|
475
532
|
fingerprint: string | undefined
|
|
@@ -1205,69 +1262,130 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1205
1262
|
);
|
|
1206
1263
|
}
|
|
1207
1264
|
const zipEntries = Object.values(zip.files);
|
|
1208
|
-
const resourceEntries = zipEntries.filter(
|
|
1209
|
-
entry => !entry.dir && entry.name.toLowerCase().endsWith('.okpkg')
|
|
1210
|
-
);
|
|
1211
1265
|
if (
|
|
1212
|
-
|
|
1213
|
-
resourceEntries.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT
|
|
1266
|
+
zipEntries.some(entry => entry.unsafeOriginalName && entry.unsafeOriginalName !== entry.name)
|
|
1214
1267
|
) {
|
|
1215
1268
|
throw ERRORS.TypedError(
|
|
1216
1269
|
HardwareErrorCode.RuntimeError,
|
|
1217
|
-
'Protocol V2 resource ZIP
|
|
1270
|
+
'Protocol V2 local resource ZIP contains an unsafe entry path',
|
|
1218
1271
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1219
1272
|
);
|
|
1220
1273
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
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',
|
|
1279
|
+
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
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) {
|
|
1229
1287
|
if (
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
totalSize > PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES
|
|
1288
|
+
getProtocolV2ZipEntrySizes(manifestEntry).uncompressedSize >
|
|
1289
|
+
PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
|
|
1233
1290
|
) {
|
|
1234
1291
|
throw ERRORS.TypedError(
|
|
1235
1292
|
HardwareErrorCode.RuntimeError,
|
|
1236
|
-
|
|
1293
|
+
'Protocol V2 local resource manifest size is invalid',
|
|
1237
1294
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1238
1295
|
);
|
|
1239
1296
|
}
|
|
1240
|
-
|
|
1241
|
-
if (
|
|
1297
|
+
manifestBinary = await manifestEntry.async('arraybuffer');
|
|
1298
|
+
if (
|
|
1299
|
+
manifestBinary.byteLength <= 0 ||
|
|
1300
|
+
manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES
|
|
1301
|
+
) {
|
|
1242
1302
|
throw ERRORS.TypedError(
|
|
1243
1303
|
HardwareErrorCode.RuntimeError,
|
|
1244
|
-
|
|
1245
|
-
{ firmwareUpdateCode: '
|
|
1304
|
+
'Protocol V2 local resource manifest size is invalid',
|
|
1305
|
+
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1246
1306
|
);
|
|
1247
1307
|
}
|
|
1248
|
-
let
|
|
1308
|
+
let manifestValue: unknown;
|
|
1249
1309
|
try {
|
|
1250
|
-
|
|
1310
|
+
manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
|
|
1251
1311
|
} catch (error) {
|
|
1252
1312
|
throw ERRORS.TypedError(
|
|
1253
1313
|
HardwareErrorCode.RuntimeError,
|
|
1254
|
-
`Protocol V2 resource
|
|
1314
|
+
`Protocol V2 local resource manifest is invalid: ${String(error)}`,
|
|
1255
1315
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1256
1316
|
);
|
|
1257
1317
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
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) {
|
|
1260
1356
|
throw ERRORS.TypedError(
|
|
1261
1357
|
HardwareErrorCode.RuntimeError,
|
|
1262
|
-
`Protocol V2 resource ZIP
|
|
1358
|
+
`Protocol V2 local resource ZIP is missing ${file.archive_path}`,
|
|
1263
1359
|
{ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' }
|
|
1264
1360
|
);
|
|
1265
1361
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
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 });
|
|
1269
1385
|
}
|
|
1270
|
-
|
|
1386
|
+
manifestBinary ??= new TextEncoder().encode(JSON.stringify({ files: normalizedFiles })).buffer;
|
|
1387
|
+
materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
|
|
1388
|
+
return { binary, materializedEntries };
|
|
1271
1389
|
}
|
|
1272
1390
|
|
|
1273
1391
|
private async prepareProtocolV2ResourceSources(): Promise<ProtocolV2ResourceBundleSource[]> {
|
|
@@ -1332,19 +1450,82 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1332
1450
|
);
|
|
1333
1451
|
}
|
|
1334
1452
|
|
|
1335
|
-
// The verified
|
|
1336
|
-
//
|
|
1453
|
+
// The verified archive bytes are authoritative. Host materialization is an
|
|
1454
|
+
// implementation detail and may preserve wrapper paths or extra metadata files.
|
|
1337
1455
|
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;
|
|
1338
1492
|
const sources: ProtocolV2ResourceBundleSource[] = [];
|
|
1339
|
-
for (const
|
|
1340
|
-
const
|
|
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;
|
|
1341
1518
|
sources.push({
|
|
1342
|
-
name:
|
|
1519
|
+
name: file.original_name || `resource-${index}`,
|
|
1343
1520
|
source,
|
|
1344
|
-
devicePath:
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1521
|
+
devicePath: file.device_path,
|
|
1522
|
+
...(header
|
|
1523
|
+
? {
|
|
1524
|
+
version: header.version,
|
|
1525
|
+
payloadHash: header.payloadHash,
|
|
1526
|
+
headerHash: header.headerHash,
|
|
1527
|
+
}
|
|
1528
|
+
: {}),
|
|
1348
1529
|
});
|
|
1349
1530
|
}
|
|
1350
1531
|
return sources;
|
|
@@ -1842,7 +2023,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1842
2023
|
!pathInfoRes.message?.exist ||
|
|
1843
2024
|
pathInfoRes.message?.directory ||
|
|
1844
2025
|
fileSize === undefined ||
|
|
1845
|
-
fileSize <
|
|
2026
|
+
fileSize < PROTOCOL_V2_OKPP_HEADER_SIZE ||
|
|
1846
2027
|
(expectedSize !== undefined && fileSize !== expectedSize)
|
|
1847
2028
|
) {
|
|
1848
2029
|
return null;
|
|
@@ -1851,8 +2032,8 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1851
2032
|
const chunkSize = this.getProtocolV2FirmwareChunkSize('read');
|
|
1852
2033
|
const chunks: Uint8Array[] = [];
|
|
1853
2034
|
let offset = 0;
|
|
1854
|
-
while (offset <
|
|
1855
|
-
const readLen = Math.min(chunkSize,
|
|
2035
|
+
while (offset < PROTOCOL_V2_OKPP_HEADER_SIZE) {
|
|
2036
|
+
const readLen = Math.min(chunkSize, PROTOCOL_V2_OKPP_HEADER_SIZE - offset);
|
|
1856
2037
|
const res = await typedCall('FilesystemFileRead', 'FilesystemFile', {
|
|
1857
2038
|
file: {
|
|
1858
2039
|
path: filePath,
|
|
@@ -1874,11 +2055,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
1874
2055
|
headerBytes.set(chunk, cursor);
|
|
1875
2056
|
cursor += chunk.byteLength;
|
|
1876
2057
|
});
|
|
1877
|
-
|
|
1878
|
-
return parseProtocolV2ResourcePackageHeader(headerBytes, fileSize);
|
|
1879
|
-
} catch {
|
|
1880
|
-
return null;
|
|
1881
|
-
}
|
|
2058
|
+
return parseProtocolV2OkppHeader(headerBytes);
|
|
1882
2059
|
}
|
|
1883
2060
|
|
|
1884
2061
|
/** Compare the downloaded and installed okpkg headers before transferring a resource. */
|
|
@@ -2171,7 +2348,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
2171
2348
|
for (const resource of resourcesToSync) {
|
|
2172
2349
|
// The bootloader keeps its live resource package mounted. FatFs rejects
|
|
2173
2350
|
// replacing an open file, so early boot promotes this staging file before mounting it.
|
|
2174
|
-
const writePath = resource.devicePath;
|
|
2351
|
+
const writePath = resolveProtocolV2ResourceWritePath(resource.devicePath);
|
|
2175
2352
|
processedSize = await this.protocolV2SourceUpdateProcess({
|
|
2176
2353
|
source: resource.source,
|
|
2177
2354
|
filePath: writePath,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode
|
|
1
|
+
import { ERRORS, HardwareErrorCode } 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 =
|
|
55
|
+
const path = usbDevice.serialNumber;
|
|
56
56
|
if (!path) {
|
|
57
57
|
throw ERRORS.TypedError(HardwareErrorCode.WebDevicePromptAccessError);
|
|
58
58
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode, createDeviceNotSupportMethodError } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import { UI_REQUEST, createUiMessage } from '../../events/ui-request';
|
|
5
4
|
import { supportsProtocolV2Message } from '../../protocols/protocol-v2/features';
|
|
@@ -130,10 +129,7 @@ export default class DeviceUploadNft extends BaseMethod<DeviceUploadNftParams> {
|
|
|
130
129
|
paceMs,
|
|
131
130
|
timeoutMs,
|
|
132
131
|
};
|
|
133
|
-
this.unlockPolicy = '
|
|
134
|
-
// File writes and NftUpdate require an unlocked device. Either PIN may
|
|
135
|
-
// authorize this device-management action.
|
|
136
|
-
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
132
|
+
this.unlockPolicy = 'none';
|
|
137
133
|
this.skipForceUpdateCheck = true;
|
|
138
134
|
this.useDevicePassphraseState = false;
|
|
139
135
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
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';
|
|
5
4
|
|
|
6
5
|
import { BaseMethod } from '../BaseMethod';
|
|
7
6
|
import { decodeJpegBase64ToRgba } from '../helpers/base64Data';
|
|
@@ -79,10 +78,7 @@ export default class DeviceUploadWallpaper extends BaseMethod<DeviceUploadWallpa
|
|
|
79
78
|
});
|
|
80
79
|
this.path = `${WALLPAPER_DIRECTORY}/${normalizeFileName(fileName, this.encoded.data)}`;
|
|
81
80
|
this.params = { jpegBase64, fileName, chunkSize };
|
|
82
|
-
this.unlockPolicy = '
|
|
83
|
-
// File writes and wallpaper apply require an unlocked device. Either PIN
|
|
84
|
-
// may authorize this device-management action.
|
|
85
|
-
this.protocolV2PreUnlockPinType = DeviceSessionPinType.Any;
|
|
81
|
+
this.unlockPolicy = 'none';
|
|
86
82
|
this.skipForceUpdateCheck = true;
|
|
87
83
|
this.useDevicePassphraseState = false;
|
|
88
84
|
}
|