@onekeyfe/hd-core 1.2.0-alpha.98 → 1.2.0-alpha.99
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__/check-all-firmware-release-protocol-v2.test.ts +66 -61
- package/__tests__/check-firmware-release-protocol-v2.test.ts +1 -1
- package/__tests__/firmware-memory-host.test.ts +18 -4
- package/__tests__/firmware-update/device-update-bootloader.test.ts +1 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +65 -2
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +80 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +61 -1
- package/__tests__/protocol-v2-firmware-targets.test.ts +16 -0
- package/__tests__/protocol-v2.test.ts +96 -0
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
- package/dist/index.js +207 -54
- package/package.json +4 -4
- package/src/api/CheckAllFirmwareRelease.ts +6 -1
- package/src/api/FirmwareUpdateV2.ts +123 -65
- package/src/api/FirmwareUpdateV4.ts +54 -8
- package/src/api/firmware/FirmwareHostBinding.ts +10 -0
- package/src/api/firmware/FirmwareMemoryHost.ts +4 -3
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +122 -73
- package/src/api/firmware/FirmwareUpdatePlan.ts +18 -5
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +22 -9
|
@@ -321,23 +321,34 @@ export const getFirmwareUpdatePreparedRawArtifact = ({
|
|
|
321
321
|
|
|
322
322
|
/**
|
|
323
323
|
* Identity observed on the live device while a degraded recovery plan runs, keyed by
|
|
324
|
-
* the plan
|
|
325
|
-
* reports one only after the firmware phase reboots it, so the later
|
|
326
|
-
* SAME workflow must be allowed to continue — but only for the device
|
|
327
|
-
* answered, never for a second one that appears mid-recovery.
|
|
324
|
+
* the approved prepared-plan digest. Bootloader recovery starts with no serial and
|
|
325
|
+
* the device reports one only after the firmware phase reboots it, so the later
|
|
326
|
+
* phases of the SAME workflow must be allowed to continue — but only for the device
|
|
327
|
+
* that first answered, never for a second one that appears mid-recovery.
|
|
328
328
|
*/
|
|
329
329
|
const degradedPlanIdentityPins = new Map<string, string>();
|
|
330
330
|
/** Keep the pin map from growing without bound across many workflows. */
|
|
331
331
|
const DEGRADED_PLAN_IDENTITY_PIN_LIMIT = 32;
|
|
332
332
|
|
|
333
|
-
const pinDegradedPlanIdentity = (
|
|
334
|
-
|
|
333
|
+
const pinDegradedPlanIdentity = (preparedPlanDigest: string, deviceIdentity: string) => {
|
|
334
|
+
const key = preparedPlanDigest.toLowerCase();
|
|
335
|
+
if (
|
|
336
|
+
!degradedPlanIdentityPins.has(key) &&
|
|
337
|
+
degradedPlanIdentityPins.size >= DEGRADED_PLAN_IDENTITY_PIN_LIMIT
|
|
338
|
+
) {
|
|
335
339
|
const oldest = degradedPlanIdentityPins.keys().next();
|
|
336
340
|
if (!oldest.done) {
|
|
337
341
|
degradedPlanIdentityPins.delete(oldest.value);
|
|
338
342
|
}
|
|
339
343
|
}
|
|
340
|
-
degradedPlanIdentityPins.set(
|
|
344
|
+
degradedPlanIdentityPins.set(key, deviceIdentity);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
/** Release recovery identity state when its digest-bound host workflow ends. */
|
|
348
|
+
export const clearFirmwareUpdatePreparedPlanDeviceIdentityPin = (
|
|
349
|
+
preparedPlanDigest: string
|
|
350
|
+
): void => {
|
|
351
|
+
degradedPlanIdentityPins.delete(preparedPlanDigest.toLowerCase());
|
|
341
352
|
};
|
|
342
353
|
|
|
343
354
|
export const assertFirmwareUpdatePreparedPlanDeviceIdentity = ({
|
|
@@ -364,7 +375,9 @@ export const assertFirmwareUpdatePreparedPlanDeviceIdentity = ({
|
|
|
364
375
|
if (deviceModel === undefined || preparedPlan.deviceModel !== deviceModel) {
|
|
365
376
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
366
377
|
}
|
|
367
|
-
const pinnedIdentity = degradedPlanIdentityPins.get(
|
|
378
|
+
const pinnedIdentity = degradedPlanIdentityPins.get(
|
|
379
|
+
preparedPlan.preparedPlanDigest.toLowerCase()
|
|
380
|
+
);
|
|
368
381
|
if (!deviceIdentity) {
|
|
369
382
|
// V4 设备可能尚未写入序列号;V2 则只允许 bootloader 恢复流程缺少身份。
|
|
370
383
|
if (preparedPlan.executor !== 'v4' && bootloaderMode !== true) {
|
|
@@ -375,7 +388,7 @@ export const assertFirmwareUpdatePreparedPlanDeviceIdentity = ({
|
|
|
375
388
|
// The recovered device now reports a serial: bind this recovery to it, and hold
|
|
376
389
|
// every later phase to the same one.
|
|
377
390
|
if (!pinnedIdentity) {
|
|
378
|
-
pinDegradedPlanIdentity(preparedPlan.
|
|
391
|
+
pinDegradedPlanIdentity(preparedPlan.preparedPlanDigest, deviceIdentity);
|
|
379
392
|
return preparedPlan;
|
|
380
393
|
}
|
|
381
394
|
if (pinnedIdentity !== deviceIdentity) {
|