@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.
Files changed (29) hide show
  1. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +66 -61
  2. package/__tests__/check-firmware-release-protocol-v2.test.ts +1 -1
  3. package/__tests__/firmware-memory-host.test.ts +18 -4
  4. package/__tests__/firmware-update/device-update-bootloader.test.ts +1 -0
  5. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +65 -2
  6. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +80 -0
  7. package/__tests__/firmware-update/firmware-update-plan.test.ts +61 -1
  8. package/__tests__/protocol-v2-firmware-targets.test.ts +16 -0
  9. package/__tests__/protocol-v2.test.ts +96 -0
  10. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  12. package/dist/api/FirmwareUpdateV4.d.ts +3 -1
  13. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  14. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -1
  15. package/dist/api/firmware/FirmwareMemoryHost.d.ts.map +1 -1
  16. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  17. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
  18. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +1 -0
  19. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
  20. package/dist/index.js +207 -54
  21. package/package.json +4 -4
  22. package/src/api/CheckAllFirmwareRelease.ts +6 -1
  23. package/src/api/FirmwareUpdateV2.ts +123 -65
  24. package/src/api/FirmwareUpdateV4.ts +54 -8
  25. package/src/api/firmware/FirmwareHostBinding.ts +10 -0
  26. package/src/api/firmware/FirmwareMemoryHost.ts +4 -3
  27. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +122 -73
  28. package/src/api/firmware/FirmwareUpdatePlan.ts +18 -5
  29. 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's opaque lease. Bootloader recovery starts with no serial and the device
325
- * reports one only after the firmware phase reboots it, so the later phases of the
326
- * SAME workflow must be allowed to continue — but only for the device that first
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 = (leaseRef: string, deviceIdentity: string) => {
334
- if (degradedPlanIdentityPins.size >= DEGRADED_PLAN_IDENTITY_PIN_LIMIT) {
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(leaseRef, deviceIdentity);
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(preparedPlan.leaseRef);
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.leaseRef, deviceIdentity);
391
+ pinDegradedPlanIdentity(preparedPlan.preparedPlanDigest, deviceIdentity);
379
392
  return preparedPlan;
380
393
  }
381
394
  if (pinnedIdentity !== deviceIdentity) {