@onekeyfe/hd-core 1.2.0-alpha.115 → 1.2.0-alpha.117
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__/DeviceCommands.test.ts +2 -2
- package/__tests__/device-lifecycle-events.test.ts +1 -1
- package/__tests__/device-state-mapper.test.ts +4 -4
- package/__tests__/device-utils.test.ts +1 -1
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +36 -89
- package/__tests__/get-device-state.test.ts +8 -8
- package/__tests__/protocol-v2-resources.test.ts +20 -0
- package/__tests__/protocol-v2.test.ts +411 -246
- package/dist/api/FirmwareUpdateV4.d.ts +0 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +3 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/index.d.ts +5 -20
- package/dist/index.js +191 -257
- package/dist/protocols/protocol-v2/features.d.ts +4 -4
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/types/settings.d.ts +4 -19
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +170 -243
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +6 -28
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -3
- package/src/data/messages/messages-protocol-v2.json +31 -14
- package/src/device/DeviceStateMapper.ts +15 -15
- package/src/deviceProfile/buildDeviceFeatures.ts +3 -3
- package/src/protocols/protocol-v2/features.ts +6 -6
- package/src/protocols/protocol-v2/resources.ts +10 -49
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -0
- package/src/types/settings.ts +4 -19
package/dist/index.js
CHANGED
|
@@ -27499,9 +27499,10 @@ var nested = {
|
|
|
27499
27499
|
MessageType_FilesystemDirMake: 60809,
|
|
27500
27500
|
MessageType_FilesystemDirRemove: 60810,
|
|
27501
27501
|
MessageType_FilesystemFormat: 60811,
|
|
27502
|
-
|
|
27503
|
-
|
|
27504
|
-
|
|
27502
|
+
MessageType_DeviceFirmwareUpdateStage: 61000,
|
|
27503
|
+
MessageType_DeviceFirmwareUpdateRequest: 61001,
|
|
27504
|
+
MessageType_DeviceFirmwareUpdateStatusGet: 61002,
|
|
27505
|
+
MessageType_DeviceFirmwareUpdateStatus: 61003,
|
|
27505
27506
|
MessageType_DeviceSessionGet: 61200,
|
|
27506
27507
|
MessageType_DeviceSession: 61201,
|
|
27507
27508
|
MessageType_DeviceSessionAskPin: 61202,
|
|
@@ -38003,7 +38004,7 @@ var nested = {
|
|
|
38003
38004
|
type: "bytes",
|
|
38004
38005
|
id: 1
|
|
38005
38006
|
},
|
|
38006
|
-
|
|
38007
|
+
signning_message: {
|
|
38007
38008
|
type: "bytes",
|
|
38008
38009
|
id: 2
|
|
38009
38010
|
},
|
|
@@ -38897,14 +38898,14 @@ var nested = {
|
|
|
38897
38898
|
type: "string",
|
|
38898
38899
|
id: 2
|
|
38899
38900
|
},
|
|
38900
|
-
burn_in_completed: {
|
|
38901
|
-
type: "bool",
|
|
38902
|
-
id: 3
|
|
38903
|
-
},
|
|
38904
38901
|
factory_test_completed: {
|
|
38905
38902
|
type: "bool",
|
|
38906
38903
|
id: 4
|
|
38907
38904
|
},
|
|
38905
|
+
factory_burn_in_completed: {
|
|
38906
|
+
type: "bool",
|
|
38907
|
+
id: 3
|
|
38908
|
+
},
|
|
38908
38909
|
manufacture_time: {
|
|
38909
38910
|
type: "DeviceFactoryInfoManufactureTime",
|
|
38910
38911
|
id: 5
|
|
@@ -38991,7 +38992,7 @@ var nested = {
|
|
|
38991
38992
|
}
|
|
38992
38993
|
}
|
|
38993
38994
|
},
|
|
38994
|
-
|
|
38995
|
+
DeviceFirmwareUpdateStage: {
|
|
38995
38996
|
fields: {
|
|
38996
38997
|
targets: {
|
|
38997
38998
|
rule: "repeated",
|
|
@@ -39000,6 +39001,10 @@ var nested = {
|
|
|
39000
39001
|
}
|
|
39001
39002
|
}
|
|
39002
39003
|
},
|
|
39004
|
+
DeviceFirmwareUpdateRequest: {
|
|
39005
|
+
fields: {
|
|
39006
|
+
}
|
|
39007
|
+
},
|
|
39003
39008
|
DeviceFirmwareUpdateRecord: {
|
|
39004
39009
|
fields: {
|
|
39005
39010
|
target_id: {
|
|
@@ -39181,7 +39186,7 @@ var nested = {
|
|
|
39181
39186
|
type: "bool",
|
|
39182
39187
|
id: 100
|
|
39183
39188
|
},
|
|
39184
|
-
|
|
39189
|
+
main_mcu: {
|
|
39185
39190
|
type: "bool",
|
|
39186
39191
|
id: 200
|
|
39187
39192
|
},
|
|
@@ -39250,7 +39255,7 @@ var nested = {
|
|
|
39250
39255
|
type: "DeviceHardwareInfo",
|
|
39251
39256
|
id: 100
|
|
39252
39257
|
},
|
|
39253
|
-
|
|
39258
|
+
main_mcu: {
|
|
39254
39259
|
type: "DeviceMainMcuInfo",
|
|
39255
39260
|
id: 200
|
|
39256
39261
|
},
|
|
@@ -39792,9 +39797,12 @@ var nested = {
|
|
|
39792
39797
|
id: 1
|
|
39793
39798
|
},
|
|
39794
39799
|
text: {
|
|
39795
|
-
rule: "required",
|
|
39796
39800
|
type: "string",
|
|
39797
39801
|
id: 2
|
|
39802
|
+
},
|
|
39803
|
+
text_id: {
|
|
39804
|
+
type: "uint32",
|
|
39805
|
+
id: 3
|
|
39798
39806
|
}
|
|
39799
39807
|
}
|
|
39800
39808
|
},
|
|
@@ -39825,7 +39833,6 @@ var nested = {
|
|
|
39825
39833
|
ViewSignPage: {
|
|
39826
39834
|
fields: {
|
|
39827
39835
|
title: {
|
|
39828
|
-
rule: "required",
|
|
39829
39836
|
type: "string",
|
|
39830
39837
|
id: 1
|
|
39831
39838
|
},
|
|
@@ -39859,13 +39866,16 @@ var nested = {
|
|
|
39859
39866
|
options: {
|
|
39860
39867
|
"default": "LayoutDefault"
|
|
39861
39868
|
}
|
|
39869
|
+
},
|
|
39870
|
+
title_id: {
|
|
39871
|
+
type: "uint32",
|
|
39872
|
+
id: 8
|
|
39862
39873
|
}
|
|
39863
39874
|
}
|
|
39864
39875
|
},
|
|
39865
39876
|
ViewVerifyPage: {
|
|
39866
39877
|
fields: {
|
|
39867
39878
|
title: {
|
|
39868
|
-
rule: "required",
|
|
39869
39879
|
type: "string",
|
|
39870
39880
|
id: 1
|
|
39871
39881
|
},
|
|
@@ -39890,6 +39900,14 @@ var nested = {
|
|
|
39890
39900
|
value_key: {
|
|
39891
39901
|
type: "uint32",
|
|
39892
39902
|
id: 6
|
|
39903
|
+
},
|
|
39904
|
+
title_id: {
|
|
39905
|
+
type: "uint32",
|
|
39906
|
+
id: 7
|
|
39907
|
+
},
|
|
39908
|
+
chain_id: {
|
|
39909
|
+
type: "uint32",
|
|
39910
|
+
id: 8
|
|
39893
39911
|
}
|
|
39894
39912
|
}
|
|
39895
39913
|
},
|
|
@@ -40736,7 +40754,9 @@ function parseProtocolV2ResourceManifestFile(value, index) {
|
|
|
40736
40754
|
}
|
|
40737
40755
|
const file = value;
|
|
40738
40756
|
const archivePath = assertManifestRelativePath(file.archive_path, `files[${index}].archive_path`);
|
|
40739
|
-
const originalName =
|
|
40757
|
+
const originalName = file.original_name === undefined
|
|
40758
|
+
? (_a = archivePath.split('/').pop()) !== null && _a !== void 0 ? _a : archivePath
|
|
40759
|
+
: assertManifestRelativePath(file.original_name, `files[${index}].original_name`);
|
|
40740
40760
|
if (originalName.includes('/')) {
|
|
40741
40761
|
throw new Error(`Invalid Pro2 resource manifest files[${index}].original_name`);
|
|
40742
40762
|
}
|
|
@@ -40748,74 +40768,28 @@ function parseProtocolV2ResourceManifestFile(value, index) {
|
|
|
40748
40768
|
throw new Error(`Invalid Pro2 resource manifest files[${index}].size`);
|
|
40749
40769
|
}
|
|
40750
40770
|
const digest = normalizeHex$1(file.sha256, SHA256_HEX_LENGTH, `files[${index}].sha256`);
|
|
40751
|
-
if (file.signed !== true) {
|
|
40752
|
-
throw new Error(`Invalid Pro2 resource manifest files[${index}].signed`);
|
|
40753
|
-
}
|
|
40754
|
-
if (file.sig_algo !== 'ed25519' && file.sig_algo !== 'mldsa65') {
|
|
40755
|
-
throw new Error(`Invalid Pro2 resource manifest files[${index}].sig_algo`);
|
|
40756
|
-
}
|
|
40757
|
-
if (file.payload_version !== null && typeof file.payload_version !== 'string') {
|
|
40758
|
-
throw new Error(`Invalid Pro2 resource manifest files[${index}].payload_version`);
|
|
40759
|
-
}
|
|
40760
40771
|
if (!archivePath.endsWith('.okpkg') || !originalName.endsWith('.okpkg')) {
|
|
40761
40772
|
throw new Error(`Invalid Pro2 resource manifest files[${index}] package extension`);
|
|
40762
40773
|
}
|
|
40763
|
-
return {
|
|
40764
|
-
archive_path: archivePath,
|
|
40765
|
-
original_name: originalName,
|
|
40766
|
-
device_path: devicePath,
|
|
40767
|
-
size: Number(file.size),
|
|
40768
|
-
sha256: digest,
|
|
40769
|
-
signed: true,
|
|
40770
|
-
sig_algo: file.sig_algo,
|
|
40771
|
-
payload_version: (_a = file.payload_version) !== null && _a !== void 0 ? _a : null,
|
|
40772
|
-
};
|
|
40774
|
+
return Object.assign(Object.assign(Object.assign({ archive_path: archivePath, original_name: originalName, device_path: devicePath, size: Number(file.size), sha256: digest }, (file.signed === undefined ? {} : { signed: file.signed })), (file.sig_algo === undefined ? {} : { sig_algo: file.sig_algo })), (file.payload_version === undefined ? {} : { payload_version: file.payload_version }));
|
|
40773
40775
|
}
|
|
40774
40776
|
function parseProtocolV2ResourceManifest(value) {
|
|
40775
40777
|
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
40776
40778
|
throw new Error('Invalid Pro2 resource manifest');
|
|
40777
40779
|
}
|
|
40778
40780
|
const manifest = value;
|
|
40779
|
-
if (manifest.
|
|
40780
|
-
|
|
40781
|
-
manifest.device_root !== 'vol0:' ||
|
|
40782
|
-
manifest.restore_mode !== 'bootloader_update' ||
|
|
40783
|
-
!Array.isArray(manifest.trees) ||
|
|
40784
|
-
!Array.isArray(manifest.files)) {
|
|
40785
|
-
throw new Error('Invalid Pro2 resource manifest contract');
|
|
40781
|
+
if (!Array.isArray(manifest.files)) {
|
|
40782
|
+
throw new Error('Invalid Pro2 resource manifest files');
|
|
40786
40783
|
}
|
|
40787
40784
|
const files = manifest.files.map(parseProtocolV2ResourceManifestFile);
|
|
40788
40785
|
const devicePaths = new Set(files.map(file => file.device_path));
|
|
40789
40786
|
const archivePaths = new Set(files.map(file => file.archive_path));
|
|
40790
40787
|
if (files.length === 0 ||
|
|
40791
40788
|
devicePaths.size !== files.length ||
|
|
40792
|
-
archivePaths.size !== files.length
|
|
40793
|
-
!devicePaths.has(PROTOCOL_V2_BOOT_RESOURCE_PACKAGE_PATH$1) ||
|
|
40794
|
-
!files.some(file => file.device_path.startsWith('vol0:/bundles/'))) {
|
|
40789
|
+
archivePaths.size !== files.length) {
|
|
40795
40790
|
throw new Error('Invalid Pro2 resource manifest file set');
|
|
40796
40791
|
}
|
|
40797
40792
|
return {
|
|
40798
|
-
schema: 1,
|
|
40799
|
-
artifact_name: assertManifestString(manifest.artifact_name, 'artifact_name'),
|
|
40800
|
-
release_name: assertManifestString(manifest.release_name, 'release_name'),
|
|
40801
|
-
variant: 'resource',
|
|
40802
|
-
commit: assertManifestString(manifest.commit, 'commit'),
|
|
40803
|
-
short_sha: assertManifestString(manifest.short_sha, 'short_sha'),
|
|
40804
|
-
timestamp_utc: assertManifestString(manifest.timestamp_utc, 'timestamp_utc'),
|
|
40805
|
-
core_version: assertManifestString(manifest.core_version, 'core_version'),
|
|
40806
|
-
key_set: assertManifestString(manifest.key_set, 'key_set'),
|
|
40807
|
-
device_root: 'vol0:',
|
|
40808
|
-
restore_mode: 'bootloader_update',
|
|
40809
|
-
trees: manifest.trees.map((tree, index) => {
|
|
40810
|
-
if (!tree || typeof tree !== 'object') {
|
|
40811
|
-
throw new Error(`Invalid Pro2 resource manifest trees[${index}]`);
|
|
40812
|
-
}
|
|
40813
|
-
const item = tree;
|
|
40814
|
-
return {
|
|
40815
|
-
path: assertManifestRelativePath(item.path, `trees[${index}].path`),
|
|
40816
|
-
device: assertManifestString(item.device, `trees[${index}].device`),
|
|
40817
|
-
};
|
|
40818
|
-
}),
|
|
40819
40793
|
files,
|
|
40820
40794
|
};
|
|
40821
40795
|
}
|
|
@@ -44250,10 +44224,10 @@ const getProtocolV2RuntimeMode = (protocolInfo, deviceInfo) => {
|
|
|
44250
44224
|
return 'normal';
|
|
44251
44225
|
if (binary)
|
|
44252
44226
|
return binary;
|
|
44253
|
-
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
44254
|
-
if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
44227
|
+
if (isLegacyProtocolV2ProtocolInfo(protocolInfo) && !((_b = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _b === void 0 ? void 0 : _b.application)) {
|
|
44228
|
+
if ((_c = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _c === void 0 ? void 0 : _c.romloader)
|
|
44255
44229
|
return 'romloader';
|
|
44256
|
-
if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.
|
|
44230
|
+
if ((_d = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.main_mcu) === null || _d === void 0 ? void 0 : _d.bootloader)
|
|
44257
44231
|
return 'bootloader';
|
|
44258
44232
|
}
|
|
44259
44233
|
return undefined;
|
|
@@ -44263,7 +44237,7 @@ const supportsProtocolV2Message = (protocolInfo, messageType) => protocolInfo.su
|
|
|
44263
44237
|
const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
44264
44238
|
targets: {
|
|
44265
44239
|
hw: true,
|
|
44266
|
-
|
|
44240
|
+
main_mcu: true,
|
|
44267
44241
|
coprocessor: true,
|
|
44268
44242
|
},
|
|
44269
44243
|
types: {
|
|
@@ -44274,7 +44248,7 @@ const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
|
|
|
44274
44248
|
const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
44275
44249
|
targets: {
|
|
44276
44250
|
hw: true,
|
|
44277
|
-
|
|
44251
|
+
main_mcu: true,
|
|
44278
44252
|
coprocessor: true,
|
|
44279
44253
|
se1: true,
|
|
44280
44254
|
se2: true,
|
|
@@ -44289,7 +44263,7 @@ const PROTOCOL_V2_VERSIONS_DEVICE_INFO_REQUEST = {
|
|
|
44289
44263
|
const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
|
|
44290
44264
|
targets: {
|
|
44291
44265
|
hw: true,
|
|
44292
|
-
|
|
44266
|
+
main_mcu: true,
|
|
44293
44267
|
coprocessor: true,
|
|
44294
44268
|
se1: true,
|
|
44295
44269
|
se2: true,
|
|
@@ -44556,11 +44530,11 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44556
44530
|
}
|
|
44557
44531
|
: { mode },
|
|
44558
44532
|
versions: definedEntries({
|
|
44559
|
-
firmware: imageVersion((_d = info.
|
|
44560
|
-
applicationP1: imageVersion((_e = info.
|
|
44561
|
-
applicationP2: imageVersion((_f = info.
|
|
44562
|
-
bootloader: imageVersion((_g = info.
|
|
44563
|
-
board: imageVersion((_h = info.
|
|
44533
|
+
firmware: imageVersion((_d = info.main_mcu) === null || _d === void 0 ? void 0 : _d.application),
|
|
44534
|
+
applicationP1: imageVersion((_e = info.main_mcu) === null || _e === void 0 ? void 0 : _e.application),
|
|
44535
|
+
applicationP2: imageVersion((_f = info.main_mcu) === null || _f === void 0 ? void 0 : _f.application_data),
|
|
44536
|
+
bootloader: imageVersion((_g = info.main_mcu) === null || _g === void 0 ? void 0 : _g.bootloader),
|
|
44537
|
+
board: imageVersion((_h = info.main_mcu) === null || _h === void 0 ? void 0 : _h.romloader),
|
|
44564
44538
|
ble: imageVersion((_j = info.coprocessor) === null || _j === void 0 ? void 0 : _j.application),
|
|
44565
44539
|
se01: imageVersion((_k = info.se1) === null || _k === void 0 ? void 0 : _k.application),
|
|
44566
44540
|
se02: imageVersion((_l = info.se2) === null || _l === void 0 ? void 0 : _l.application),
|
|
@@ -44572,16 +44546,16 @@ const mapProtocolV2DeviceInfoToState = (info, mode = 'unknown') => {
|
|
|
44572
44546
|
se04Boot: imageVersion((_s = info.se4) === null || _s === void 0 ? void 0 : _s.bootloader),
|
|
44573
44547
|
}),
|
|
44574
44548
|
verification: definedEntries({
|
|
44575
|
-
firmwareBuildId: imageBuildId((_t = info.
|
|
44576
|
-
firmwareHash: imageHash((_u = info.
|
|
44577
|
-
applicationP1BuildId: imageBuildId((_v = info.
|
|
44578
|
-
applicationP1Hash: imageHash((_w = info.
|
|
44579
|
-
applicationP2BuildId: imageBuildId((_x = info.
|
|
44580
|
-
applicationP2Hash: imageHash((_y = info.
|
|
44581
|
-
bootloaderBuildId: imageBuildId((_z = info.
|
|
44582
|
-
bootloaderHash: imageHash((_0 = info.
|
|
44583
|
-
boardBuildId: imageBuildId((_1 = info.
|
|
44584
|
-
boardHash: imageHash((_2 = info.
|
|
44549
|
+
firmwareBuildId: imageBuildId((_t = info.main_mcu) === null || _t === void 0 ? void 0 : _t.application),
|
|
44550
|
+
firmwareHash: imageHash((_u = info.main_mcu) === null || _u === void 0 ? void 0 : _u.application),
|
|
44551
|
+
applicationP1BuildId: imageBuildId((_v = info.main_mcu) === null || _v === void 0 ? void 0 : _v.application),
|
|
44552
|
+
applicationP1Hash: imageHash((_w = info.main_mcu) === null || _w === void 0 ? void 0 : _w.application),
|
|
44553
|
+
applicationP2BuildId: imageBuildId((_x = info.main_mcu) === null || _x === void 0 ? void 0 : _x.application_data),
|
|
44554
|
+
applicationP2Hash: imageHash((_y = info.main_mcu) === null || _y === void 0 ? void 0 : _y.application_data),
|
|
44555
|
+
bootloaderBuildId: imageBuildId((_z = info.main_mcu) === null || _z === void 0 ? void 0 : _z.bootloader),
|
|
44556
|
+
bootloaderHash: imageHash((_0 = info.main_mcu) === null || _0 === void 0 ? void 0 : _0.bootloader),
|
|
44557
|
+
boardBuildId: imageBuildId((_1 = info.main_mcu) === null || _1 === void 0 ? void 0 : _1.romloader),
|
|
44558
|
+
boardHash: imageHash((_2 = info.main_mcu) === null || _2 === void 0 ? void 0 : _2.romloader),
|
|
44585
44559
|
bleBuildId: imageBuildId((_3 = info.coprocessor) === null || _3 === void 0 ? void 0 : _3.application),
|
|
44586
44560
|
bleHash: imageHash((_4 = info.coprocessor) === null || _4 === void 0 ? void 0 : _4.application),
|
|
44587
44561
|
se01BuildId: imageBuildId((_5 = info.se1) === null || _5 === void 0 ? void 0 : _5.application),
|
|
@@ -51679,8 +51653,8 @@ const PROTOCOL_V2_BOOTLOADER_RECONNECT_TIMEOUT = 90 * 1000;
|
|
|
51679
51653
|
const PROTOCOL_V2_FINAL_RECONNECT_TIMEOUT = 3 * 60 * 1000;
|
|
51680
51654
|
const PROTOCOL_V2_SHORT_RESPONSE_TIMEOUT = 5 * 1000;
|
|
51681
51655
|
const PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT = 15 * 1000;
|
|
51682
|
-
const PROTOCOL_V2_START_UPDATE_TIMEOUT = 3 * 60 * 1000;
|
|
51683
51656
|
const PROTOCOL_V2_INSTALL_TIMEOUT = 8 * 60 * 1000;
|
|
51657
|
+
const PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY = 1000;
|
|
51684
51658
|
const PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT = 30 * 1000;
|
|
51685
51659
|
const PROTOCOL_V2_TARGET_STATUS_PENDING = 0;
|
|
51686
51660
|
const PROTOCOL_V2_TARGET_STATUS_IN_PROGRESS = 1;
|
|
@@ -51702,6 +51676,10 @@ const PROTOCOL_V2_OKPP_HASH_SIZE = 64;
|
|
|
51702
51676
|
const PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES = 1024 * 1024;
|
|
51703
51677
|
const PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT = 512;
|
|
51704
51678
|
const PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES = 256 * 1024 * 1024;
|
|
51679
|
+
const getProtocolV2LocalResourceArchivePath = (entryName) => {
|
|
51680
|
+
const match = entryName.match(/(?:^|\/)((?:bundles\/|loaders\/(?:bootloader|rom)\/).+\.okpkg)$/iu);
|
|
51681
|
+
return match === null || match === void 0 ? void 0 : match[1];
|
|
51682
|
+
};
|
|
51705
51683
|
const PROTOCOL_V2_NEO_UNSUPPORTED_TARGETS = new Set(['se03', 'se04']);
|
|
51706
51684
|
const getProtocolV2ZipEntrySizes = (entry) => {
|
|
51707
51685
|
var _a;
|
|
@@ -51745,14 +51723,11 @@ function assertProtocolV2FirmwareTargetsSupported(deviceType, params, hasExplici
|
|
|
51745
51723
|
}
|
|
51746
51724
|
const getProtocolV2DeviceTransferProgress = (bytesBeforeChunk, bytesAfterChunk, totalBytes) => {
|
|
51747
51725
|
if (!Number.isFinite(totalBytes) || totalBytes <= 0) {
|
|
51748
|
-
return
|
|
51726
|
+
return 0;
|
|
51749
51727
|
}
|
|
51750
51728
|
if (bytesBeforeChunk <= 0 && bytesAfterChunk < totalBytes) {
|
|
51751
51729
|
return 0;
|
|
51752
51730
|
}
|
|
51753
|
-
if (bytesAfterChunk >= totalBytes) {
|
|
51754
|
-
return 100;
|
|
51755
|
-
}
|
|
51756
51731
|
return Math.min(Math.max(Math.ceil((bytesAfterChunk / totalBytes) * 100), 1), 99);
|
|
51757
51732
|
};
|
|
51758
51733
|
const PROTOCOL_V2_REMOTE_COMPONENT_TARGETS = {
|
|
@@ -51840,36 +51815,12 @@ const isProtocolV2ReconnectProbeError = (error) => {
|
|
|
51840
51815
|
return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
|
|
51841
51816
|
message.includes('did not respond to expected protocol'));
|
|
51842
51817
|
};
|
|
51843
|
-
const PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES = new Set([
|
|
51844
|
-
hdShared.HardwareErrorCode.BleConnectedError,
|
|
51845
|
-
hdShared.HardwareErrorCode.BleCharacteristicNotifyError,
|
|
51846
|
-
hdShared.HardwareErrorCode.BleForceCleanRunPromise,
|
|
51847
|
-
hdShared.HardwareErrorCode.BleDeviceDisconnected,
|
|
51848
|
-
]);
|
|
51849
|
-
const isProtocolV2BleInstallInterruptionError = (error) => {
|
|
51850
|
-
if (error instanceof hdShared.HardwareError &&
|
|
51851
|
-
PROTOCOL_V2_BLE_INSTALL_INTERRUPTION_ERROR_CODES.has(error.errorCode)) {
|
|
51852
|
-
return true;
|
|
51853
|
-
}
|
|
51854
|
-
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51855
|
-
const compactMessage = message.replace(/\s+/gu, '');
|
|
51856
|
-
return (/react native ble transport (?:released|disconnected)/u.test(message) ||
|
|
51857
|
-
(compactMessage.includes('rxerrorerror6') &&
|
|
51858
|
-
(compactMessage.includes('multiplatformbleadapter') ||
|
|
51859
|
-
compactMessage.includes('multipalformebleadapter'))));
|
|
51860
|
-
};
|
|
51861
51818
|
const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
|
|
51862
51819
|
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51863
51820
|
return (message.includes('handler not registered') ||
|
|
51864
51821
|
message.includes('message handler not found') ||
|
|
51865
51822
|
message.includes('unsupported message'));
|
|
51866
51823
|
};
|
|
51867
|
-
const isProtocolV2FirmwareUpdateEndpointUnavailable = (error) => {
|
|
51868
|
-
const message = getProtocolV2UnknownErrorText(error).toLowerCase();
|
|
51869
|
-
return (message.includes('handler not registered') ||
|
|
51870
|
-
message.includes('message handler not found') ||
|
|
51871
|
-
message.includes('unsupported message'));
|
|
51872
|
-
};
|
|
51873
51824
|
const isProtocolV2TerminalInstallStatusError = (error) => {
|
|
51874
51825
|
var _a;
|
|
51875
51826
|
return error instanceof hdShared.HardwareError &&
|
|
@@ -52002,11 +51953,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52002
51953
|
this.protocolV2HasExplicitTargetSelection = false;
|
|
52003
51954
|
this.protocolV2PreparedSources = [];
|
|
52004
51955
|
this.protocolV2ExecutionInLoader = false;
|
|
52005
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
52006
51956
|
this.protocolV2BootResourceStagingSafe = false;
|
|
52007
51957
|
this.protocolV2CompletedTargetVersions = new Map();
|
|
52008
51958
|
this.protocolV2FinalStatusVerified = false;
|
|
52009
|
-
this.protocolV2InstallAckReceived = false;
|
|
52010
51959
|
this.protocolV2InstallBaselineVersions = new Map();
|
|
52011
51960
|
}
|
|
52012
51961
|
getSupportedProtocols() {
|
|
@@ -52502,60 +52451,63 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52502
52451
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unsafe entry path', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52503
52452
|
}
|
|
52504
52453
|
const entries = zipEntries.filter(entry => !entry.dir);
|
|
52505
|
-
if (entries.length === 0
|
|
52454
|
+
if (entries.length === 0) {
|
|
52506
52455
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP entry set is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52507
52456
|
}
|
|
52508
|
-
|
|
52509
|
-
let
|
|
52510
|
-
|
|
52511
|
-
|
|
52512
|
-
|
|
52513
|
-
|
|
52514
|
-
|
|
52515
|
-
|
|
52516
|
-
: PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES;
|
|
52517
|
-
if (sizes.uncompressedSize > entryLimit ||
|
|
52518
|
-
declaredCompressedSize > binary.byteLength ||
|
|
52519
|
-
declaredUncompressedSize >
|
|
52520
|
-
PROTOCOL_V2_RESOURCE_TOTAL_MAX_BYTES + PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
|
|
52521
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP declared size exceeds the allowed limit', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52457
|
+
const manifestEntry = entries.find(entry => entry.name.split('/').pop() === 'manifest.json');
|
|
52458
|
+
let manifestBinary;
|
|
52459
|
+
let manifestDirectory = '';
|
|
52460
|
+
let selectedFiles;
|
|
52461
|
+
if (manifestEntry) {
|
|
52462
|
+
if (getProtocolV2ZipEntrySizes(manifestEntry).uncompressedSize >
|
|
52463
|
+
PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
|
|
52464
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52522
52465
|
}
|
|
52466
|
+
manifestBinary = yield manifestEntry.async('arraybuffer');
|
|
52467
|
+
if (manifestBinary.byteLength <= 0 ||
|
|
52468
|
+
manifestBinary.byteLength > PROTOCOL_V2_RESOURCE_MANIFEST_MAX_BYTES) {
|
|
52469
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource manifest size is invalid', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52470
|
+
}
|
|
52471
|
+
let manifestValue;
|
|
52472
|
+
try {
|
|
52473
|
+
manifestValue = JSON.parse(new TextDecoder().decode(manifestBinary));
|
|
52474
|
+
}
|
|
52475
|
+
catch (error) {
|
|
52476
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource manifest is invalid: ${String(error)}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52477
|
+
}
|
|
52478
|
+
selectedFiles = selectProtocolV2ResourceManifestFiles({
|
|
52479
|
+
manifest: parseProtocolV2ResourceManifest(manifestValue),
|
|
52480
|
+
targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
|
|
52481
|
+
});
|
|
52482
|
+
manifestDirectory = manifestEntry.name.slice(0, -'manifest.json'.length);
|
|
52523
52483
|
}
|
|
52524
|
-
|
|
52525
|
-
|
|
52526
|
-
|
|
52527
|
-
|
|
52528
|
-
|
|
52529
|
-
|
|
52530
|
-
|
|
52531
|
-
|
|
52532
|
-
|
|
52533
|
-
|
|
52534
|
-
|
|
52535
|
-
|
|
52536
|
-
|
|
52537
|
-
|
|
52538
|
-
|
|
52484
|
+
else {
|
|
52485
|
+
selectedFiles = entries.flatMap(entry => {
|
|
52486
|
+
var _a;
|
|
52487
|
+
const archivePath = getProtocolV2LocalResourceArchivePath(entry.name);
|
|
52488
|
+
if (!archivePath)
|
|
52489
|
+
return [];
|
|
52490
|
+
return [
|
|
52491
|
+
{
|
|
52492
|
+
archive_path: archivePath,
|
|
52493
|
+
original_name: (_a = archivePath.split('/').pop()) !== null && _a !== void 0 ? _a : archivePath,
|
|
52494
|
+
device_path: `vol0:/${archivePath}`,
|
|
52495
|
+
size: getProtocolV2ZipEntrySizes(entry).uncompressedSize,
|
|
52496
|
+
sha256: '',
|
|
52497
|
+
},
|
|
52498
|
+
];
|
|
52499
|
+
});
|
|
52539
52500
|
}
|
|
52540
|
-
|
|
52541
|
-
|
|
52542
|
-
manifest,
|
|
52543
|
-
targetsToUpdate: (_a = this.params.targetsToUpdate) !== null && _a !== void 0 ? _a : [],
|
|
52544
|
-
});
|
|
52545
|
-
const expectedEntryNames = new Set([
|
|
52546
|
-
'manifest.json',
|
|
52547
|
-
...selectedFiles.map(file => file.archive_path),
|
|
52548
|
-
]);
|
|
52549
|
-
if (entries.length !== expectedEntryNames.size ||
|
|
52550
|
-
entries.some(entry => !expectedEntryNames.has(entry.name))) {
|
|
52551
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP contains an unexpected entry', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52501
|
+
if (selectedFiles.length === 0 || selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
|
|
52502
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 local resource ZIP has no resource packages', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52552
52503
|
}
|
|
52553
52504
|
let totalSize = 0;
|
|
52554
|
-
const materializedEntries = [
|
|
52555
|
-
|
|
52556
|
-
];
|
|
52505
|
+
const materializedEntries = [];
|
|
52506
|
+
const normalizedFiles = [];
|
|
52557
52507
|
for (const file of selectedFiles) {
|
|
52558
|
-
const entry =
|
|
52508
|
+
const entry = manifestEntry
|
|
52509
|
+
? zip.file(`${manifestDirectory}${file.archive_path}`)
|
|
52510
|
+
: entries.find(candidate => getProtocolV2LocalResourceArchivePath(candidate.name) === file.archive_path);
|
|
52559
52511
|
if (!entry) {
|
|
52560
52512
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource ZIP is missing ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
52561
52513
|
}
|
|
@@ -52566,11 +52518,15 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52566
52518
|
}
|
|
52567
52519
|
const fileBinary = yield entry.async('arraybuffer');
|
|
52568
52520
|
const digest = bytesToHex(sha256.sha256(new Uint8Array(fileBinary)));
|
|
52569
|
-
if (fileBinary.byteLength !== file.size ||
|
|
52521
|
+
if (fileBinary.byteLength !== file.size ||
|
|
52522
|
+
(file.sha256 && digest !== file.sha256.toLowerCase())) {
|
|
52570
52523
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 local resource file does not match manifest: ${file.archive_path}`, { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52571
52524
|
}
|
|
52525
|
+
normalizedFiles.push(Object.assign(Object.assign({}, file), { sha256: digest }));
|
|
52572
52526
|
materializedEntries.push({ entryName: file.archive_path, binary: fileBinary });
|
|
52573
52527
|
}
|
|
52528
|
+
manifestBinary !== null && manifestBinary !== void 0 ? manifestBinary : (manifestBinary = new TextEncoder().encode(JSON.stringify({ files: normalizedFiles })).buffer);
|
|
52529
|
+
materializedEntries.unshift({ entryName: 'manifest.json', binary: manifestBinary });
|
|
52574
52530
|
return { binary, materializedEntries };
|
|
52575
52531
|
});
|
|
52576
52532
|
}
|
|
@@ -52589,7 +52545,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52589
52545
|
});
|
|
52590
52546
|
}
|
|
52591
52547
|
prepareProtocolV2ResourceArchiveSources() {
|
|
52592
|
-
var _a, _b, _c
|
|
52548
|
+
var _a, _b, _c;
|
|
52593
52549
|
return __awaiter(this, void 0, void 0, function* () {
|
|
52594
52550
|
const archiveArtifacts = (_b = (_a = this.params.preparedPlan) === null || _a === void 0 ? void 0 : _a.artifacts.filter(artifact => artifact.role === 'resourceBundle' &&
|
|
52595
52551
|
artifact.target === 'resource' &&
|
|
@@ -52617,18 +52573,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52617
52573
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 prepared resource archive does not match its approved receipt', { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52618
52574
|
}
|
|
52619
52575
|
const verifiedArchive = yield this.prepareProtocolV2LocalResourceArchive(archiveBinary);
|
|
52620
|
-
const entries = (_c = archiveArtifact.materializedEntries) !== null && _c !== void 0 ? _c : [];
|
|
52621
|
-
const entriesByName = new Map(entries.map(entry => [entry.entryName, entry]));
|
|
52622
|
-
if (entries.length !== verifiedArchive.materializedEntries.length ||
|
|
52623
|
-
verifiedArchive.materializedEntries.some(entry => {
|
|
52624
|
-
const preparedEntry = entriesByName.get(entry.entryName);
|
|
52625
|
-
const digest = bytesToHex(sha256.sha256(new Uint8Array(entry.binary)));
|
|
52626
|
-
return (!preparedEntry ||
|
|
52627
|
-
preparedEntry.artifact.size !== entry.binary.byteLength ||
|
|
52628
|
-
preparedEntry.artifact.sha256.toLowerCase() !== digest);
|
|
52629
|
-
})) {
|
|
52630
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 prepared resource entries do not match the approved archive', { firmwareUpdateCode: 'FirmwareArtifactReceiptMismatch' });
|
|
52631
|
-
}
|
|
52632
52576
|
const verifiedEntriesByName = new Map(verifiedArchive.materializedEntries.map(entry => [entry.entryName, entry.binary]));
|
|
52633
52577
|
const manifestBinary = verifiedEntriesByName.get('manifest.json');
|
|
52634
52578
|
if (!manifestBinary) {
|
|
@@ -52644,7 +52588,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52644
52588
|
const manifest = parseProtocolV2ResourceManifest(manifestValue);
|
|
52645
52589
|
const selectedFiles = selectProtocolV2ResourceManifestFiles({
|
|
52646
52590
|
manifest,
|
|
52647
|
-
targetsToUpdate: (
|
|
52591
|
+
targetsToUpdate: (_c = this.params.targetsToUpdate) !== null && _c !== void 0 ? _c : [],
|
|
52648
52592
|
});
|
|
52649
52593
|
if (selectedFiles.length > PROTOCOL_V2_RESOURCE_FILE_MAX_COUNT) {
|
|
52650
52594
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 prepared resource archive contains too many files', { firmwareUpdateCode: 'FirmwareArtifactsNotPrepared' });
|
|
@@ -52964,13 +52908,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
52964
52908
|
if (!isProtocolV2FirmwareFingerprintValid(binary, component.fingerprint)) {
|
|
52965
52909
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 firmware fingerprint mismatch: ${key}/${component.target}`);
|
|
52966
52910
|
}
|
|
52967
|
-
const expectedPayloadHash = normalizeProtocolV2Hex(component.payloadHash);
|
|
52968
|
-
if (expectedPayloadHash) {
|
|
52969
|
-
const header = parseProtocolV2OkppHeader(toProtocolV2Bytes(binary));
|
|
52970
|
-
if (!header || header.payloadHash !== expectedPayloadHash) {
|
|
52971
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Protocol V2 firmware payload hash mismatch: ${key}/${component.target}`);
|
|
52972
|
-
}
|
|
52973
|
-
}
|
|
52974
52911
|
return Object.assign(Object.assign({}, target), { binary });
|
|
52975
52912
|
});
|
|
52976
52913
|
}
|
|
@@ -53157,11 +53094,6 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53157
53094
|
}
|
|
53158
53095
|
return ((_a = this.device.features) === null || _a === void 0 ? void 0 : _a.mode) === 'romloader';
|
|
53159
53096
|
}
|
|
53160
|
-
isLegacyProtocolV2Runtime() {
|
|
53161
|
-
var _a, _b;
|
|
53162
|
-
const protocolInfo = (_b = (_a = this.device.state) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.protocolV2ProtocolInfo;
|
|
53163
|
-
return protocolInfo ? isLegacyProtocolV2ProtocolInfo(protocolInfo) : false;
|
|
53164
|
-
}
|
|
53165
53097
|
rebootProtocolV2ToBootloader() {
|
|
53166
53098
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53167
53099
|
try {
|
|
@@ -53184,16 +53116,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53184
53116
|
}
|
|
53185
53117
|
enterProtocolV2BootloaderMode() {
|
|
53186
53118
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53187
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53188
53119
|
if (this.isProtocolV2RomloaderMode()) {
|
|
53189
53120
|
Log$6.debug('Protocol V2 device is in romloader mode; start firmware update directly');
|
|
53190
|
-
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53191
53121
|
this.protocolV2ExecutionInLoader = true;
|
|
53192
53122
|
return false;
|
|
53193
53123
|
}
|
|
53194
53124
|
if (this.isProtocolV2BootloaderMode()) {
|
|
53195
53125
|
Log$6.debug('Protocol V2 device is already in bootloader mode, skip reboot');
|
|
53196
|
-
this.protocolV2LegacyDirectUpdate = this.isLegacyProtocolV2Runtime();
|
|
53197
53126
|
this.protocolV2ExecutionInLoader = true;
|
|
53198
53127
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.GoToBootloaderSuccess);
|
|
53199
53128
|
return false;
|
|
@@ -53374,7 +53303,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53374
53303
|
path: item.path,
|
|
53375
53304
|
}));
|
|
53376
53305
|
yield this.protocolV2StartFirmwareUpdate({ targets });
|
|
53377
|
-
yield
|
|
53306
|
+
yield hdShared.wait(PROTOCOL_V2_INSTALL_STATUS_INITIAL_DELAY);
|
|
53307
|
+
yield this.waitForProtocolV2FirmwareUpdateComplete(targets, true);
|
|
53378
53308
|
});
|
|
53379
53309
|
}
|
|
53380
53310
|
protocolV2SourceUpdateProcess({ source, filePath, processedSize, totalSize, }) {
|
|
@@ -53540,7 +53470,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53540
53470
|
previousVersion !== currentVersion);
|
|
53541
53471
|
});
|
|
53542
53472
|
}
|
|
53543
|
-
waitForProtocolV2FirmwareUpdateComplete(targets) {
|
|
53473
|
+
waitForProtocolV2FirmwareUpdateComplete(targets, requireCurrentInstallStatus = false) {
|
|
53544
53474
|
var _a, _b;
|
|
53545
53475
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53546
53476
|
this.protocolV2FinalStatusVerified = false;
|
|
@@ -53553,7 +53483,8 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53553
53483
|
let missingTargetStatusSince;
|
|
53554
53484
|
let missingTargetStatusKey;
|
|
53555
53485
|
let normalModeWithoutInstallEvidenceSince;
|
|
53556
|
-
let installEvidenceObserved =
|
|
53486
|
+
let installEvidenceObserved = false;
|
|
53487
|
+
let currentInstallStatusObserved = false;
|
|
53557
53488
|
const resetMissingTargetStatusGrace = () => {
|
|
53558
53489
|
missingTargetStatusSince = undefined;
|
|
53559
53490
|
missingTargetStatusKey = undefined;
|
|
@@ -53568,25 +53499,53 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53568
53499
|
}
|
|
53569
53500
|
const currentDeviceInfo = deviceInfo;
|
|
53570
53501
|
try {
|
|
53571
|
-
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', 'DeviceFirmwareUpdateStatus', {
|
|
53502
|
+
const statusResponse = yield this.device.getCommands().typedCall('DeviceFirmwareUpdateStatusGet', ['DeviceFirmwareUpdateStatus', 'Success'], {
|
|
53572
53503
|
fields: {
|
|
53573
53504
|
status: true,
|
|
53574
53505
|
payload_version: true,
|
|
53575
53506
|
path: true,
|
|
53576
53507
|
},
|
|
53577
53508
|
}, { timeoutMs: PROTOCOL_V2_FIRMWARE_STATUS_RESPONSE_TIMEOUT });
|
|
53578
|
-
|
|
53509
|
+
if (statusResponse.type === 'Success') {
|
|
53510
|
+
installEvidenceObserved = true;
|
|
53511
|
+
resetMissingTargetStatusGrace();
|
|
53512
|
+
lastError = new Error('Protocol V2 firmware install acknowledged; waiting for target status');
|
|
53513
|
+
}
|
|
53514
|
+
const statusTargets = statusResponse.type === 'DeviceFirmwareUpdateStatus'
|
|
53515
|
+
? ((_a = statusResponse.message.records) !== null && _a !== void 0 ? _a : [])
|
|
53516
|
+
: [];
|
|
53579
53517
|
if (statusTargets.some(target => {
|
|
53580
53518
|
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53581
|
-
return targetId !== undefined &&
|
|
53519
|
+
return (targetId !== undefined &&
|
|
53520
|
+
expectedTargetIds.has(targetId) &&
|
|
53521
|
+
isProtocolV2TargetStatusInProgress(target.status));
|
|
53582
53522
|
})) {
|
|
53523
|
+
currentInstallStatusObserved = true;
|
|
53524
|
+
}
|
|
53525
|
+
const hasMatchingTargetStatus = statusTargets.some(target => {
|
|
53526
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53527
|
+
return targetId !== undefined && expectedTargetIds.has(targetId);
|
|
53528
|
+
});
|
|
53529
|
+
if (hasMatchingTargetStatus &&
|
|
53530
|
+
(!requireCurrentInstallStatus || currentInstallStatusObserved)) {
|
|
53583
53531
|
installEvidenceObserved = true;
|
|
53584
53532
|
normalModeWithoutInstallEvidenceSince = undefined;
|
|
53585
53533
|
}
|
|
53586
|
-
|
|
53534
|
+
const matchingStatusTargets = statusTargets.filter(target => {
|
|
53535
|
+
const targetId = normalizeProtocolV2TargetId(target.target_id);
|
|
53536
|
+
return targetId !== undefined && expectedTargetIds.has(targetId);
|
|
53537
|
+
});
|
|
53538
|
+
const shouldVerifyTargetCompletion = !requireCurrentInstallStatus || currentInstallStatusObserved;
|
|
53539
|
+
if (shouldVerifyTargetCompletion &&
|
|
53540
|
+
this.assertProtocolV2TargetStatus(statusTargets, expectedTargetIds, expectedPaths)) {
|
|
53587
53541
|
this.protocolV2FinalStatusVerified = true;
|
|
53588
53542
|
return;
|
|
53589
53543
|
}
|
|
53544
|
+
if (requireCurrentInstallStatus &&
|
|
53545
|
+
!currentInstallStatusObserved &&
|
|
53546
|
+
matchingStatusTargets.length > 0) {
|
|
53547
|
+
lastError = new Error('Protocol V2 firmware status is stale; waiting for the current install to start');
|
|
53548
|
+
}
|
|
53590
53549
|
if (statusTargets.length === 0 && currentDeviceInfo) {
|
|
53591
53550
|
const isNormalMode = yield this.probeProtocolV2NormalMode(currentDeviceInfo);
|
|
53592
53551
|
if (isNormalMode &&
|
|
@@ -53597,26 +53556,34 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53597
53556
|
return;
|
|
53598
53557
|
}
|
|
53599
53558
|
}
|
|
53600
|
-
|
|
53601
|
-
|
|
53602
|
-
|
|
53603
|
-
|
|
53604
|
-
if (missingTargetStatusSince === undefined || missingTargetStatusKey !== missingKey) {
|
|
53605
|
-
missingTargetStatusSince = now;
|
|
53606
|
-
missingTargetStatusKey = missingKey;
|
|
53607
|
-
}
|
|
53608
|
-
else if (now - missingTargetStatusSince >=
|
|
53609
|
-
PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT) {
|
|
53610
|
-
const reportedTargetIds = statusTargets
|
|
53611
|
-
.map(target => normalizeProtocolV2TargetId(target.target_id))
|
|
53612
|
-
.filter((targetId) => targetId !== undefined);
|
|
53613
|
-
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, `Protocol V2 firmware status is missing requested records: targetIds=${missingKey} reportedTargetIds=${reportedTargetIds.join(',')}`);
|
|
53559
|
+
if (statusTargets.length === 0) {
|
|
53560
|
+
resetMissingTargetStatusGrace();
|
|
53561
|
+
if (statusResponse.type !== 'Success') {
|
|
53562
|
+
lastError = new Error('Protocol V2 firmware update is waiting for user confirmation or target status');
|
|
53614
53563
|
}
|
|
53615
|
-
lastError = new Error(`Protocol V2 firmware status is temporarily missing targetIds=${missingKey}`);
|
|
53616
53564
|
}
|
|
53617
53565
|
else {
|
|
53618
|
-
|
|
53619
|
-
|
|
53566
|
+
const missingTargetIds = this.getProtocolV2MissingTargetIds(statusTargets, expectedTargetIds);
|
|
53567
|
+
if (missingTargetIds.length > 0) {
|
|
53568
|
+
const now = Date.now();
|
|
53569
|
+
const missingKey = missingTargetIds.join(',');
|
|
53570
|
+
if (missingTargetStatusSince === undefined || missingTargetStatusKey !== missingKey) {
|
|
53571
|
+
missingTargetStatusSince = now;
|
|
53572
|
+
missingTargetStatusKey = missingKey;
|
|
53573
|
+
}
|
|
53574
|
+
else if (now - missingTargetStatusSince >=
|
|
53575
|
+
PROTOCOL_V2_MISSING_TARGET_STATUS_GRACE_TIMEOUT) {
|
|
53576
|
+
const reportedTargetIds = statusTargets
|
|
53577
|
+
.map(target => normalizeProtocolV2TargetId(target.target_id))
|
|
53578
|
+
.filter((targetId) => targetId !== undefined);
|
|
53579
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FirmwareError, `Protocol V2 firmware status is missing requested records: targetIds=${missingKey} reportedTargetIds=${reportedTargetIds.join(',')}`);
|
|
53580
|
+
}
|
|
53581
|
+
lastError = new Error(`Protocol V2 firmware status is temporarily missing targetIds=${missingKey}`);
|
|
53582
|
+
}
|
|
53583
|
+
else {
|
|
53584
|
+
resetMissingTargetStatusGrace();
|
|
53585
|
+
lastError = new Error('Protocol V2 firmware targets are still installing');
|
|
53586
|
+
}
|
|
53620
53587
|
}
|
|
53621
53588
|
}
|
|
53622
53589
|
catch (error) {
|
|
@@ -53879,46 +53846,12 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
|
|
|
53879
53846
|
}
|
|
53880
53847
|
protocolV2StartFirmwareUpdate({ targets, }) {
|
|
53881
53848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53882
|
-
this.protocolV2InstallAckReceived = false;
|
|
53883
53849
|
this.protocolV2LastRuntimeProbeFeatures = undefined;
|
|
53884
|
-
const
|
|
53885
|
-
|
|
53886
|
-
|
|
53887
|
-
let response;
|
|
53888
|
-
try {
|
|
53889
|
-
response = yield startUpdate();
|
|
53890
|
-
this.protocolV2InstallAckReceived = true;
|
|
53891
|
-
}
|
|
53892
|
-
catch (error) {
|
|
53893
|
-
if (this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(error)) {
|
|
53894
|
-
this.throwIfAborted();
|
|
53895
|
-
Log$6.log('[FirmwareUpdateV4] install request interrupted by device reboot; continue status polling: ', error);
|
|
53896
|
-
}
|
|
53897
|
-
else if (this.protocolV2LegacyDirectUpdate &&
|
|
53898
|
-
isProtocolV2FirmwareUpdateEndpointUnavailable(error)) {
|
|
53899
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53900
|
-
Log$6.debug('[FirmwareUpdateV4] legacy App does not expose DeviceFirmwareUpdateRequest; rebooting to bootloader');
|
|
53901
|
-
yield this.rebootProtocolV2ToBootloader();
|
|
53902
|
-
try {
|
|
53903
|
-
response = yield startUpdate();
|
|
53904
|
-
this.protocolV2InstallAckReceived = true;
|
|
53905
|
-
}
|
|
53906
|
-
catch (retryError) {
|
|
53907
|
-
if (!(this.isBleReconnect() && isProtocolV2BleInstallInterruptionError(retryError))) {
|
|
53908
|
-
throw retryError;
|
|
53909
|
-
}
|
|
53910
|
-
this.throwIfAborted();
|
|
53911
|
-
Log$6.log('[FirmwareUpdateV4] install request interrupted after legacy reboot; continue status polling: ', retryError);
|
|
53912
|
-
}
|
|
53913
|
-
}
|
|
53914
|
-
else {
|
|
53915
|
-
throw error;
|
|
53916
|
-
}
|
|
53917
|
-
}
|
|
53918
|
-
this.protocolV2LegacyDirectUpdate = false;
|
|
53850
|
+
const commands = this.device.getCommands();
|
|
53851
|
+
yield commands.typedCall('DeviceFirmwareUpdateStage', 'Success', { targets });
|
|
53852
|
+
yield commands.call('DeviceFirmwareUpdateRequest', {}, { returnAfterWrite: true });
|
|
53919
53853
|
this.postTipMessage(exports.FirmwareUpdateTipMessage.FirmwareUpdating);
|
|
53920
53854
|
this.postProgressMessage(0, 'installingFirmware');
|
|
53921
|
-
return response;
|
|
53922
53855
|
});
|
|
53923
53856
|
}
|
|
53924
53857
|
protocolV2Reboot(rebootType) {
|
|
@@ -54938,7 +54871,7 @@ const resolvePreUnlockPinType = (method) => {
|
|
|
54938
54871
|
return targetsKnownHiddenWallet ? hdTransport.DeviceSessionPinType.Any : hdTransport.DeviceSessionPinType.Main;
|
|
54939
54872
|
};
|
|
54940
54873
|
function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
54941
|
-
var _a, _b;
|
|
54874
|
+
var _a, _b, _c;
|
|
54942
54875
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54943
54876
|
const { context = createProtocolV2UnlockContext(), uiCoordinator, afterStatusBeforeUnlock, prepare, run: configuredRun, } = options;
|
|
54944
54877
|
const run = configuredRun !== null && configuredRun !== void 0 ? configuredRun : (() => method.run());
|
|
@@ -54947,8 +54880,9 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
|
|
|
54947
54880
|
const shouldCoordinateUi = shouldEmitUi && uiCoordinator !== undefined;
|
|
54948
54881
|
const requiresPreUnlock = device.isProtocolV2() &&
|
|
54949
54882
|
(method.useDevicePassphraseState || method.unlockPolicy === 'unlock-before-run') &&
|
|
54950
|
-
|
|
54951
|
-
!((_b = device.
|
|
54883
|
+
((_a = device.state) === null || _a === void 0 ? void 0 : _a.status.initialized) !== false &&
|
|
54884
|
+
!((_b = device.isBootloader) === null || _b === void 0 ? void 0 : _b.call(device)) &&
|
|
54885
|
+
!((_c = device.isRomloader) === null || _c === void 0 ? void 0 : _c.call(device));
|
|
54952
54886
|
if (requiresPreUnlock && !context.preflightCompleted) {
|
|
54953
54887
|
const status = yield refreshProtocolV2DeviceStatus(device);
|
|
54954
54888
|
if (typeof (status === null || status === void 0 ? void 0 : status.unlocked) !== 'boolean') {
|