@onekeyfe/hd-core 1.2.0-alpha.183 → 1.2.0-alpha.184

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 (30) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +20 -4
  2. package/__tests__/DeviceCommands.test.ts +13 -0
  3. package/__tests__/device-lifecycle-events.test.ts +19 -0
  4. package/__tests__/open-wallet-session.test.ts +127 -1
  5. package/__tests__/protocol-v2-unlock-policy.test.ts +35 -1
  6. package/__tests__/protocol-v2.test.ts +50 -0
  7. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  8. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  9. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  10. package/dist/core/index.d.ts +1 -0
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/device/Device.d.ts +1 -1
  13. package/dist/device/Device.d.ts.map +1 -1
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +103 -35
  16. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +2 -0
  17. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
  18. package/dist/protocols/protocol-v2/walletSession.d.ts +3 -0
  19. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  20. package/dist/utils/deviceFeaturesUtils.d.ts +3 -0
  21. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  22. package/package.json +4 -4
  23. package/src/api/FirmwareUpdateV4.ts +25 -8
  24. package/src/api/OpenWalletSession.ts +39 -9
  25. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +2 -1
  26. package/src/core/index.ts +16 -2
  27. package/src/device/Device.ts +3 -1
  28. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +8 -1
  29. package/src/protocols/protocol-v2/walletSession.ts +65 -22
  30. package/src/utils/deviceFeaturesUtils.ts +4 -0
package/dist/index.js CHANGED
@@ -41579,11 +41579,12 @@ const buildDeviceSessionGetRequest = ({ sessionId, expectedPassphraseState, deri
41579
41579
  hdTransport.DeviceSessionSeedDomain.SeedDomain_Standard,
41580
41580
  ...(deriveCardano ? [hdTransport.DeviceSessionSeedDomain.SeedDomain_Cardano] : []),
41581
41581
  ] }));
41582
- const askDevicePassphrase = (device, requestPayload) => __awaiter(void 0, void 0, void 0, function* () {
41582
+ const askDevicePassphrase = (device, requestPayload, onStatusRefreshed) => __awaiter(void 0, void 0, void 0, function* () {
41583
41583
  yield device.commands.typedCall('DeviceSessionAskPassphrase', 'Success', requestPayload);
41584
41584
  yield refreshProtocolV2DeviceStatus(device);
41585
+ onStatusRefreshed === null || onStatusRefreshed === void 0 ? void 0 : onStatusRefreshed();
41585
41586
  });
41586
- const selectDeviceSession = (device, expectedPassphraseState, deriveCardano) => __awaiter(void 0, void 0, void 0, function* () {
41587
+ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano, onStatusRefreshed) => __awaiter(void 0, void 0, void 0, function* () {
41587
41588
  var _a, _b, _c, _d;
41588
41589
  const existsAttachPinUser = ((_a = device.features) === null || _a === void 0 ? void 0 : _a.attachToPinEnabled) === true;
41589
41590
  const metadata = Object.assign({ source: 'wallet-session-coordinator', reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet' }, (expectedPassphraseState ? { expectedPassphraseState } : {}));
@@ -41616,18 +41617,19 @@ const selectDeviceSession = (device, expectedPassphraseState, deriveCardano) =>
41616
41617
  emitUiEvent: false,
41617
41618
  interaction: attachPinInteraction,
41618
41619
  });
41620
+ onStatusRefreshed === null || onStatusRefreshed === void 0 ? void 0 : onStatusRefreshed();
41619
41621
  return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
41620
41622
  }
41621
41623
  if (hasHostPassphrase) {
41622
41624
  yield askDevicePassphrase(device, {
41623
41625
  passphrase: hostPassphrase,
41624
41626
  on_device: false,
41625
- });
41627
+ }, onStatusRefreshed);
41626
41628
  return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
41627
41629
  }
41628
41630
  const passphraseOnDeviceInteraction = (_d = device.createProtocolV2UiPhaseMetadata) === null || _d === void 0 ? void 0 : _d.call(device, 'passphrase-on-device', 'start');
41629
41631
  device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, Object.assign(Object.assign({}, metadata), (passphraseOnDeviceInteraction ? { interaction: passphraseOnDeviceInteraction } : {})));
41630
- yield askDevicePassphrase(device, { on_device: true });
41632
+ yield askDevicePassphrase(device, { on_device: true }, onStatusRefreshed);
41631
41633
  return getDeviceSession(device, buildDeviceSessionGetRequest({ deriveCardano }));
41632
41634
  });
41633
41635
  function getProtocolV2WalletSession(device, options) {
@@ -41661,9 +41663,15 @@ function getProtocolV2WalletSession(device, options) {
41661
41663
  : undefined;
41662
41664
  let response;
41663
41665
  let resumed = false;
41664
- let mainPinSelected = (options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
41665
- ((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlocked) === true &&
41666
- ((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) === false;
41666
+ let walletStatusRefreshed = false;
41667
+ const markWalletStatusRefreshed = () => {
41668
+ walletStatusRefreshed = true;
41669
+ };
41670
+ let mainPinAuthenticated = (options === null || options === void 0 ? void 0 : options.mainPinSelected) === true ||
41671
+ ((options === null || options === void 0 ? void 0 : options.onlyMainPin) === true &&
41672
+ ((_d = device.features) === null || _d === void 0 ? void 0 : _d.unlocked) === true &&
41673
+ ((_e = device.features) === null || _e === void 0 ? void 0 : _e.unlockedAttachPin) === false);
41674
+ let standardWalletSelected = (options === null || options === void 0 ? void 0 : options.mainPinSelected) === true;
41667
41675
  const clearCurrentWalletSession = () => {
41668
41676
  var _a;
41669
41677
  if (options === null || options === void 0 ? void 0 : options.onlyMainPin) {
@@ -41676,6 +41684,7 @@ function getProtocolV2WalletSession(device, options) {
41676
41684
  const rejectMismatchedAttachPinWallet = () => __awaiter(this, void 0, void 0, function* () {
41677
41685
  var _k;
41678
41686
  const features = yield refreshProtocolV2DeviceStatus(device);
41687
+ markWalletStatusRefreshed();
41679
41688
  if (features.unlockedAttachPin !== true) {
41680
41689
  return;
41681
41690
  }
@@ -41697,28 +41706,35 @@ function getProtocolV2WalletSession(device, options) {
41697
41706
  yield rejectMismatchedAttachPinWallet();
41698
41707
  }
41699
41708
  const selectMainPin = (force = false) => __awaiter(this, void 0, void 0, function* () {
41700
- if (force || !mainPinSelected) {
41709
+ if (force || !mainPinAuthenticated) {
41701
41710
  yield device.unlockDevice(hdTransport.DeviceSessionPinType.Main, {
41702
41711
  source: 'wallet-session-coordinator',
41703
41712
  reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
41704
41713
  deviceOnly: true,
41705
41714
  });
41706
- mainPinSelected = true;
41715
+ markWalletStatusRefreshed();
41716
+ mainPinAuthenticated = true;
41717
+ standardWalletSelected = true;
41707
41718
  }
41708
41719
  });
41709
41720
  const selectStandardWallet = () => __awaiter(this, void 0, void 0, function* () {
41710
41721
  var _m;
41711
- yield selectMainPin();
41712
41722
  if (((_m = device.features) === null || _m === void 0 ? void 0 : _m.passphraseProtection) === true) {
41723
+ yield selectMainPin();
41713
41724
  yield askDevicePassphrase(device, {
41714
41725
  passphrase: '',
41715
41726
  on_device: false,
41716
- });
41727
+ }, markWalletStatusRefreshed);
41728
+ standardWalletSelected = true;
41729
+ }
41730
+ else if (!standardWalletSelected) {
41731
+ yield selectMainPin(true);
41717
41732
  }
41718
41733
  });
41719
41734
  if (readCurrentAttachPinSession) {
41720
41735
  const status = yield requestProtocolV2DeviceStatus$1(device);
41721
41736
  device.updateProtocolV2Status(status);
41737
+ markWalletStatusRefreshed();
41722
41738
  if (status.unlocked !== true ||
41723
41739
  status.passphrase_enabled !== true ||
41724
41740
  status.unlocked_by_attach_to_pin !== true) {
@@ -41789,7 +41805,7 @@ function getProtocolV2WalletSession(device, options) {
41789
41805
  device.clearInternalState();
41790
41806
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WalletSessionInvalid);
41791
41807
  }
41792
- response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano);
41808
+ response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano, markWalletStatusRefreshed);
41793
41809
  }
41794
41810
  let { message } = response;
41795
41811
  try {
@@ -41818,7 +41834,7 @@ function getProtocolV2WalletSession(device, options) {
41818
41834
  }
41819
41835
  else {
41820
41836
  device.clearInternalState();
41821
- response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano);
41837
+ response = yield selectDeviceSession(device, expectedPassphraseState, options === null || options === void 0 ? void 0 : options.deriveCardano, markWalletStatusRefreshed);
41822
41838
  }
41823
41839
  message = response.message;
41824
41840
  try {
@@ -41856,7 +41872,7 @@ function getProtocolV2WalletSession(device, options) {
41856
41872
  if (readCurrentAttachPinSession) {
41857
41873
  unlockedAttachPin = true;
41858
41874
  }
41859
- else if (mainPinSelected) {
41875
+ else if (mainPinAuthenticated) {
41860
41876
  unlockedAttachPin = false;
41861
41877
  }
41862
41878
  return {
@@ -41864,6 +41880,7 @@ function getProtocolV2WalletSession(device, options) {
41864
41880
  newSession: message.session_id,
41865
41881
  unlockedAttachPin,
41866
41882
  resumed,
41883
+ walletStatusRefreshed,
41867
41884
  };
41868
41885
  });
41869
41886
  }
@@ -41931,6 +41948,7 @@ const getPassphraseStateWithRefreshDeviceInfo = (device, options) => __awaiter(v
41931
41948
  onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
41932
41949
  deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano,
41933
41950
  rejectAttachPinForMainWallet: options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet,
41951
+ mainPinSelected: options === null || options === void 0 ? void 0 : options.mainPinSelected,
41934
41952
  });
41935
41953
  }
41936
41954
  const { features } = device;
@@ -41976,6 +41994,7 @@ const getPassphraseState = (device, options) => __awaiter(void 0, void 0, void 0
41976
41994
  onlyMainPin: options === null || options === void 0 ? void 0 : options.onlyMainPin,
41977
41995
  deriveCardano: options === null || options === void 0 ? void 0 : options.deriveCardano,
41978
41996
  rejectAttachPinForMainWallet: options === null || options === void 0 ? void 0 : options.rejectAttachPinForMainWallet,
41997
+ mainPinSelected: options === null || options === void 0 ? void 0 : options.mainPinSelected,
41979
41998
  });
41980
41999
  }
41981
42000
  const supportAttachPinCapability = existCapability(features, hdTransport.Enum_Capability.Capability_AttachToPin);
@@ -46460,7 +46479,7 @@ class Device extends events.exports {
46460
46479
  return Promise.resolve(features);
46461
46480
  });
46462
46481
  }
46463
- checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck, deriveCardano) {
46482
+ checkPassphraseStateSafety(passphraseState, useEmptyPassphrase, skipPassphraseCheck, deriveCardano, mainPinSelected) {
46464
46483
  return __awaiter(this, void 0, void 0, function* () {
46465
46484
  if (this.isUnacquired())
46466
46485
  return false;
@@ -46470,6 +46489,7 @@ class Device extends events.exports {
46470
46489
  onlyMainPin: useEmptyPassphrase,
46471
46490
  deriveCardano,
46472
46491
  rejectAttachPinForMainWallet: useEmptyPassphrase === true,
46492
+ mainPinSelected,
46473
46493
  });
46474
46494
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
46475
46495
  const useErrorAttachPin = unlockedAttachPin &&
@@ -47294,6 +47314,10 @@ const wasResumed = (session) => !!session &&
47294
47314
  typeof session === 'object' &&
47295
47315
  'resumed' in session &&
47296
47316
  session.resumed === true;
47317
+ const wasWalletStatusRefreshed = (session) => !!session &&
47318
+ typeof session === 'object' &&
47319
+ 'walletStatusRefreshed' in session &&
47320
+ session.walletStatusRefreshed === true;
47297
47321
  const requireHiddenWalletResponse = (session) => {
47298
47322
  if (!session.passphraseState) {
47299
47323
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceInitializeFailed, 'Hidden wallet response is missing passphraseState');
@@ -47336,12 +47360,20 @@ class OpenWalletSession extends BaseMethod {
47336
47360
  this.unlockPolicy = 'unlock-before-run';
47337
47361
  this.skipForceUpdateCheck = true;
47338
47362
  this.params = normalizeParams(this.payload);
47363
+ this.protocolV2PreUnlockPinType =
47364
+ this.params.mode === OpenWalletSessionMode.SelectHidden
47365
+ ? hdTransport.DeviceSessionPinType.Any
47366
+ : hdTransport.DeviceSessionPinType.Main;
47339
47367
  this.payload.useEmptyPassphrase = this.params.mode === OpenWalletSessionMode.Standard;
47340
47368
  }
47341
47369
  run() {
47370
+ var _a, _b;
47342
47371
  return __awaiter(this, void 0, void 0, function* () {
47343
47372
  const isProtocolV2 = this.device.isProtocolV2();
47344
- let state = yield this.device.getDeviceState({ refreshSections: ['status'] });
47373
+ const reusePreflightStatus = isProtocolV2 && ((_a = this.protocolV2UnlockContext) === null || _a === void 0 ? void 0 : _a.preflightStatusRefreshed) === true;
47374
+ let state = reusePreflightStatus
47375
+ ? yield this.device.getDeviceState()
47376
+ : yield this.device.getDeviceState({ refreshSections: ['status'] });
47345
47377
  let currentDeviceId = state.identity.deviceId;
47346
47378
  const hasAuthoritativeProtocolV2WalletStatus = (candidate) => candidate.status.unlocked === true &&
47347
47379
  typeof candidate.status.passphraseProtection === 'boolean' &&
@@ -47363,9 +47395,18 @@ class OpenWalletSession extends BaseMethod {
47363
47395
  currentDeviceId = state.identity.deviceId;
47364
47396
  return state;
47365
47397
  });
47398
+ const resolveProtocolV2DeviceStateAfterSession = (session) => __awaiter(this, void 0, void 0, function* () {
47399
+ if (!wasWalletStatusRefreshed(session)) {
47400
+ return refreshProtocolV2DeviceState();
47401
+ }
47402
+ state = yield this.device.getDeviceState();
47403
+ currentDeviceId = state.identity.deviceId;
47404
+ return state;
47405
+ });
47366
47406
  const ensureProtocolV2WalletStatus = () => __awaiter(this, void 0, void 0, function* () {
47407
+ var _d;
47367
47408
  if (isProtocolV2 && !hasAuthoritativeProtocolV2WalletStatus(state)) {
47368
- yield this.device.unlockDevice(hdTransport.DeviceSessionPinType.Main, {
47409
+ yield this.device.unlockDevice((_d = this.protocolV2PreUnlockPinType) !== null && _d !== void 0 ? _d : hdTransport.DeviceSessionPinType.Main, {
47369
47410
  source: 'unlock-coordinator',
47370
47411
  reason: 'device-locked',
47371
47412
  deviceOnly: true,
@@ -47384,13 +47425,14 @@ class OpenWalletSession extends BaseMethod {
47384
47425
  deriveCardano: this.payload.deriveCardano,
47385
47426
  selectMainWalletBeforeRestore: !hasAuthoritativeProtocolV2WalletStatus(state) ||
47386
47427
  state.status.unlockedAttachPin === true,
47428
+ mainPinSelected: (_b = this.protocolV2UnlockContext) === null || _b === void 0 ? void 0 : _b.preflightMainPinSelected,
47387
47429
  })
47388
47430
  : yield getPassphraseStateWithRefreshDeviceInfo(this.device, {
47389
47431
  onlyMainPin: true,
47390
47432
  initSession: this.payload.initSession,
47391
47433
  });
47392
47434
  const refreshedState = isProtocolV2
47393
- ? requireAuthoritativeProtocolV2WalletStatus(yield refreshProtocolV2DeviceState())
47435
+ ? requireAuthoritativeProtocolV2WalletStatus(yield resolveProtocolV2DeviceStateAfterSession(session))
47394
47436
  : state;
47395
47437
  const deviceId = requireDeviceId();
47396
47438
  if (session.unlockedAttachPin ||
@@ -47398,7 +47440,7 @@ class OpenWalletSession extends BaseMethod {
47398
47440
  try {
47399
47441
  yield this.device.lockDevice();
47400
47442
  }
47401
- catch (_a) {
47443
+ catch (_c) {
47402
47444
  }
47403
47445
  this.device.clearInternalState();
47404
47446
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckUnlockTypeError);
@@ -47462,7 +47504,7 @@ class OpenWalletSession extends BaseMethod {
47462
47504
  : { forceWalletSelection: true })), { deriveCardano: this.payload.deriveCardano }))
47463
47505
  : yield getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
47464
47506
  const refreshedState = isProtocolV2
47465
- ? requireAuthoritativeProtocolV2WalletStatus(yield refreshProtocolV2DeviceState())
47507
+ ? requireAuthoritativeProtocolV2WalletStatus(yield resolveProtocolV2DeviceStateAfterSession(session))
47466
47508
  : state;
47467
47509
  const deviceId = requireDeviceId();
47468
47510
  if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
@@ -51871,11 +51913,12 @@ const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
51871
51913
  };
51872
51914
  const isProtocolV2TerminalInstallStatusError = (error) => {
51873
51915
  var _a;
51874
- return error instanceof hdShared.HardwareError &&
51875
- (error.errorCode === hdShared.HardwareErrorCode.ActionCancelled ||
51876
- error.errorCode === hdShared.HardwareErrorCode.FirmwareError ||
51877
- error.errorCode === hdShared.HardwareErrorCode.FirmwareVerificationFailed ||
51878
- ((_a = error.params) === null || _a === void 0 ? void 0 : _a.firmwareUpdateCode) === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE);
51916
+ return hdShared.isBleStaleBondHardwareError(error) ||
51917
+ (error instanceof hdShared.HardwareError &&
51918
+ (error.errorCode === hdShared.HardwareErrorCode.ActionCancelled ||
51919
+ error.errorCode === hdShared.HardwareErrorCode.FirmwareError ||
51920
+ error.errorCode === hdShared.HardwareErrorCode.FirmwareVerificationFailed ||
51921
+ ((_a = error.params) === null || _a === void 0 ? void 0 : _a.firmwareUpdateCode) === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE));
51879
51922
  };
51880
51923
  const isProtocolV2TargetStatusFinished = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
51881
51924
  const isProtocolV2TargetStatusInProgress = (status) => normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_PENDING ||
@@ -52949,6 +52992,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
52949
52992
  return true;
52950
52993
  }
52951
52994
  catch (error) {
52995
+ if (hdShared.isBleStaleBondHardwareError(error)) {
52996
+ throw error;
52997
+ }
52952
52998
  Log$7.log(`[FirmwareUpdateV4] RESC bundle ${bundle.name} header check failed: `, error);
52953
52999
  return false;
52954
53000
  }
@@ -53033,7 +53079,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53033
53079
  lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
53034
53080
  }
53035
53081
  catch (error) {
53036
- if (this.isProtocolV2ReconnectIdentityError(error)) {
53082
+ if (hdShared.isBleStaleBondHardwareError(error) || this.isProtocolV2ReconnectIdentityError(error)) {
53037
53083
  throw error;
53038
53084
  }
53039
53085
  shouldReconnect = true;
@@ -53236,6 +53282,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53236
53282
  return processedSize + source.size;
53237
53283
  }
53238
53284
  catch (error) {
53285
+ if (hdShared.isBleStaleBondHardwareError(error)) {
53286
+ throw error;
53287
+ }
53239
53288
  lastError = error;
53240
53289
  if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
53241
53290
  yield this.recoverProtocolV2FileTransfer();
@@ -53589,6 +53638,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53589
53638
  }
53590
53639
  }
53591
53640
  catch (error) {
53641
+ if (hdShared.isBleStaleBondHardwareError(error)) {
53642
+ throw error;
53643
+ }
53592
53644
  Log$7.log('[FirmwareUpdateV4] unable to confirm App mode before Normal reboot: ', error);
53593
53645
  }
53594
53646
  yield this.protocolV2Reboot(hdTransport.DeviceRebootType.Normal);
@@ -53663,7 +53715,7 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
53663
53715
  lastError = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceNotFound, 'Protocol V2 device is still in bootloader mode');
53664
53716
  }
53665
53717
  catch (error) {
53666
- if (this.isProtocolV2ReconnectIdentityError(error)) {
53718
+ if (hdShared.isBleStaleBondHardwareError(error) || this.isProtocolV2ReconnectIdentityError(error)) {
53667
53719
  throw error;
53668
53720
  }
53669
53721
  shouldReconnect = true;
@@ -54861,6 +54913,8 @@ class ProtocolV2UiInteractionCoordinator {
54861
54913
  const Log$3 = getLogger(exports.LoggerNames.Core);
54862
54914
  const createProtocolV2UnlockContext = () => ({
54863
54915
  preflightCompleted: false,
54916
+ preflightStatusRefreshed: false,
54917
+ preflightMainPinSelected: false,
54864
54918
  });
54865
54919
  const resolvePreUnlockPinType = (method) => {
54866
54920
  var _a, _b;
@@ -54893,10 +54947,11 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
54893
54947
  }
54894
54948
  yield (afterStatusBeforeUnlock === null || afterStatusBeforeUnlock === void 0 ? void 0 : afterStatusBeforeUnlock());
54895
54949
  if (!status.unlocked) {
54950
+ const preUnlockPinType = resolvePreUnlockPinType(method);
54896
54951
  const unlockInteraction = shouldCoordinateUi
54897
54952
  ? uiCoordinator.enterUnlockInteraction(method.name)
54898
54953
  : undefined;
54899
- const unlockedStatus = yield device.unlockDevice(resolvePreUnlockPinType(method), shouldCoordinateUi
54954
+ const unlockedStatus = yield device.unlockDevice(preUnlockPinType, shouldCoordinateUi
54900
54955
  ? { emitUiEvent: false, interaction: unlockInteraction }
54901
54956
  : {
54902
54957
  source: 'unlock-coordinator',
@@ -54907,8 +54962,10 @@ function runMethodWithUnlockPolicy(method, device, options = {}) {
54907
54962
  if ((unlockedStatus === null || unlockedStatus === void 0 ? void 0 : unlockedStatus.unlocked) !== true) {
54908
54963
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'Protocol V2 device remained locked after the unlock flow.');
54909
54964
  }
54965
+ context.preflightMainPinSelected = preUnlockPinType === hdTransport.DeviceSessionPinType.Main;
54910
54966
  Log$3.debug('Protocol V2 pre-unlock completed', { method: method.name });
54911
54967
  }
54968
+ context.preflightStatusRefreshed = true;
54912
54969
  context.preflightCompleted = true;
54913
54970
  }
54914
54971
  yield (prepare === null || prepare === void 0 ? void 0 : prepare());
@@ -55197,6 +55254,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
55197
55254
  const response = yield runMethodWithUnlockPolicy(method, this.device, {
55198
55255
  context: this.protocolV2UnlockContext,
55199
55256
  prepare: () => __awaiter(this, void 0, void 0, function* () {
55257
+ var _d;
55200
55258
  if (this.temporarySafetyCheckPrompted) {
55201
55259
  method.temporarySafetyCheckPrompted = true;
55202
55260
  }
@@ -55210,7 +55268,7 @@ class AllNetworkGetAddressBase extends BaseMethod {
55210
55268
  const deriveCardano = method.name.startsWith('cardano');
55211
55269
  const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
55212
55270
  if (this.device.isProtocolV2() && shouldResumeWalletSession) {
55213
- const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano);
55271
+ const passphraseStateSafety = yield this.device.checkPassphraseStateSafety(this.payload.passphraseState, useEmptyPassphrase, this.payload.skipPassphraseCheck, deriveCardano, (_d = this.protocolV2UnlockContext) === null || _d === void 0 ? void 0 : _d.preflightMainPinSelected);
55214
55272
  if (!passphraseStateSafety) {
55215
55273
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceCheckPassphraseStateError);
55216
55274
  }
@@ -65307,7 +65365,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
65307
65365
  }
65308
65366
  },
65309
65367
  prepare: () => __awaiter(void 0, void 0, void 0, function* () {
65310
- var _o, _p, _q, _r, _s;
65368
+ var _o, _p, _q, _r, _s, _t;
65311
65369
  if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
65312
65370
  const isSameDeviceID = yield checkLiveDeviceId(device, method.deviceId);
65313
65371
  if (!isSameDeviceID) {
@@ -65327,7 +65385,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
65327
65385
  require: support.require,
65328
65386
  });
65329
65387
  }
65330
- const passphraseStateSafety = yield device.checkPassphraseStateSafety((_o = method.payload) === null || _o === void 0 ? void 0 : _o.passphraseState, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.useEmptyPassphrase, (_q = method.payload) === null || _q === void 0 ? void 0 : _q.skipPassphraseCheck, hasDeriveCardano(method));
65388
+ const passphraseStateSafety = yield device.checkPassphraseStateSafety((_o = method.payload) === null || _o === void 0 ? void 0 : _o.passphraseState, (_p = method.payload) === null || _p === void 0 ? void 0 : _p.useEmptyPassphrase, (_q = method.payload) === null || _q === void 0 ? void 0 : _q.skipPassphraseCheck, hasDeriveCardano(method), (_r = method.protocolV2UnlockContext) === null || _r === void 0 ? void 0 : _r.preflightMainPinSelected);
65331
65389
  checkPassphraseEnableState(method, device.features);
65332
65390
  if (!passphraseStateSafety) {
65333
65391
  DevicePool.clearDeviceCache(method.payload.connectId);
@@ -65345,7 +65403,7 @@ const onCallDevice = (context, message, method) => __awaiter(void 0, void 0, voi
65345
65403
  ? e
65346
65404
  : hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'open safety check failed.');
65347
65405
  }
65348
- (_s = (_r = method.device) === null || _r === void 0 ? void 0 : _r.commands) === null || _s === void 0 ? void 0 : _s.checkDisposed();
65406
+ (_t = (_s = method.device) === null || _s === void 0 ? void 0 : _s.commands) === null || _t === void 0 ? void 0 : _t.checkDisposed();
65349
65407
  }),
65350
65408
  });
65351
65409
  messageResponse = createResponseMessage(method.responseID, true, response);
@@ -65561,6 +65619,11 @@ function isMissingDetectedProtocolV2Error(method, error) {
65561
65619
  typeof typedError.message === 'string' &&
65562
65620
  typedError.message.includes('Device protocol has not been detected'));
65563
65621
  }
65622
+ function isProtocolV2PeerRemovedPairingError(method, error) {
65623
+ return (method.payload.connectProtocol === 'V2' &&
65624
+ (error === null || error === void 0 ? void 0 : error.errorCode) ===
65625
+ hdShared.HardwareErrorCode.BlePeerRemovedPairingInformation);
65626
+ }
65564
65627
  const BLE_ACQUIRE_DEADLINE_MS = 60 * 1000;
65565
65628
  function raceBleAcquire(acquirePromise, abortSignal) {
65566
65629
  return new Promise((resolve, reject) => {
@@ -65672,7 +65735,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
65672
65735
  Log.debug(`EnsureConnected function start, MAX_RETRY_COUNT=${MAX_RETRY_COUNT}, POLL_INTERVAL_TIME=${POLL_INTERVAL_TIME} `);
65673
65736
  const poll = (time = POLL_INTERVAL_TIME) => __awaiter(void 0, void 0, void 0, function* () {
65674
65737
  return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
65675
- var _t;
65738
+ var _u;
65676
65739
  const abort = () => {
65677
65740
  if (abortSignal && abortSignal.aborted) {
65678
65741
  if (timer) {
@@ -65782,7 +65845,8 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
65782
65845
  hdShared.HardwareErrorCode.BridgeNeedsPermission,
65783
65846
  hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
65784
65847
  hdShared.HardwareErrorCode.CallQueueActionCancelled,
65785
- ].includes(error.errorCode)) {
65848
+ ].includes(error.errorCode) ||
65849
+ isProtocolV2PeerRemovedPairingError(method, error)) {
65786
65850
  reject(error);
65787
65851
  return;
65788
65852
  }
@@ -65792,7 +65856,7 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
65792
65856
  clearTimeout(timer);
65793
65857
  }
65794
65858
  Log.debug('EnsureConnected get to max try count, will return: ', tryCount);
65795
- if (DataManager.isBrowserWebUsb(env) && !((_t = method.payload) === null || _t === void 0 ? void 0 : _t.skipWebDevicePrompt)) {
65859
+ if (DataManager.isBrowserWebUsb(env) && !((_u = method.payload) === null || _u === void 0 ? void 0 : _u.skipWebDevicePrompt)) {
65796
65860
  postMessage(createUiMessage(UI_REQUEST.WEB_DEVICE_PROMPT_ACCESS_PERMISSION));
65797
65861
  reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.WebDeviceNotFoundOrNeedsPermission));
65798
65862
  }
@@ -65905,8 +65969,12 @@ const checkPassphraseEnableState = (method, features) => {
65905
65969
  }
65906
65970
  };
65907
65971
  const shouldCheckPassphraseState = (method, device) => {
65972
+ var _a;
65908
65973
  if (!method.useDevicePassphraseState)
65909
65974
  return false;
65975
+ if (device.isProtocolV2() && ((_a = method.payload) === null || _a === void 0 ? void 0 : _a.useEmptyPassphrase) === true) {
65976
+ return true;
65977
+ }
65910
65978
  return device.hasUsePassphrase();
65911
65979
  };
65912
65980
  const cleanup = () => {
@@ -3,6 +3,8 @@ import type { Device } from '../../device/Device';
3
3
  import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
4
4
  export type ProtocolV2UnlockContext = {
5
5
  preflightCompleted: boolean;
6
+ preflightStatusRefreshed?: boolean;
7
+ preflightMainPinSelected?: boolean;
6
8
  };
7
9
  export declare const createProtocolV2UnlockContext: () => ProtocolV2UnlockContext;
8
10
  type RunnableMethod = Pick<BaseMethod, 'run' | 'unlockPolicy' | 'useDevicePassphraseState' | 'protocolV2UiInteraction' | 'protocolV2UiMode' | 'protocolV2PreUnlockPinType' | 'params' | 'payload'> & {
@@ -1 +1 @@
1
- {"version":3,"file":"unlockPolicyRunner.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/unlockPolicyRunner.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,iBAAiB,CAAC;AAI1E,MAAM,MAAM,uBAAuB,GAAG;IACpC,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,6BAA6B,QAAO,uBAE/C,CAAC;AAEH,KAAK,cAAc,GAAG,IAAI,CACxB,UAAU,EACR,KAAK,GACL,cAAc,GACd,0BAA0B,GAC1B,yBAAyB,GACzB,kBAAkB,GAClB,4BAA4B,GAC5B,QAAQ,GACR,SAAS,CACZ,GAAG;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD,CAAC;AAEF,KA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AAC,EAAE,MAAM,CAAC;IACd,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD,CAAC;AAEF,KAAK,wBAAwB,GAAG,IAAI,CAClC,kCAAkC,EAClC,wBAAwB,GAAG,wBAAwB,CACpD,CAAC;AAEF,KAAK,gCAAgC,CAAC,CAAC,IAAI;IACzC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,aAAa,CAAC,EAAE,wBAAwB,CAAC;IACzC,uBAAuB,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;CACxB,CAAC;AAkBF,wBAAsB,yBAAyB,CAAC,CAAC,GAAG,OAAO,EACzD,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,gCAAgC,CAAC,CAAC,CAAM,GAChD,OAAO,CAAC,CAAC,CAAC,CAoEZ"}
@@ -12,16 +12,19 @@ export declare function getProtocolV2WalletSession(device: Device, options?: {
12
12
  resumeOnly?: boolean;
13
13
  deriveCardano?: boolean;
14
14
  readCurrentAttachPinSession?: boolean;
15
+ mainPinSelected?: boolean;
15
16
  }): Promise<{
16
17
  passphraseState: string;
17
18
  newSession: string;
18
19
  unlockedAttachPin: boolean | undefined;
19
20
  resumed: boolean;
21
+ walletStatusRefreshed: boolean;
20
22
  }>;
21
23
  export declare function restoreProtocolV2WalletSession(device: Device, expectedPassphraseState: string, deriveCardano?: boolean): Promise<{
22
24
  passphraseState: string;
23
25
  newSession: string;
24
26
  unlockedAttachPin: boolean | undefined;
25
27
  resumed: boolean;
28
+ walletStatusRefreshed: boolean;
26
29
  }>;
27
30
  //# sourceMappingURL=walletSession.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AA0HD,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACvC;;;;;GAiQF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;GAOxB"}
1
+ {"version":3,"file":"walletSession.d.ts","sourceRoot":"","sources":["../../../src/protocols/protocol-v2/walletSession.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAuBlD,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,0DAGjE;AAED,wBAAsB,6BAA6B,CAAC,MAAM,EAAE,MAAM,qCAGjE;AAED,wBAAsB,qCAAqC,CAAC,MAAM,EAAE,MAAM,oBAgBzE;AAqID,wBAAsB,0BAA0B,CAC9C,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,6BAA6B,CAAC,EAAE,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,2BAA2B,CAAC,EAAE,OAAO,CAAC;IAEtC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;;;;;;GA+RF;AAED,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,MAAM,EACd,uBAAuB,EAAE,MAAM,EAC/B,aAAa,CAAC,EAAE,OAAO;;;;;;GAOxB"}
@@ -14,11 +14,13 @@ export declare const getPassphraseStateWithRefreshDeviceInfo: (device: Device, o
14
14
  initSession?: boolean;
15
15
  deriveCardano?: boolean;
16
16
  rejectAttachPinForMainWallet?: boolean;
17
+ mainPinSelected?: boolean;
17
18
  }) => Promise<{
18
19
  passphraseState: string;
19
20
  newSession: string;
20
21
  unlockedAttachPin: boolean | undefined;
21
22
  resumed: boolean;
23
+ walletStatusRefreshed: boolean;
22
24
  } | {
23
25
  passphraseState: string | undefined;
24
26
  newSession: string | undefined;
@@ -30,6 +32,7 @@ export declare const getPassphraseState: (device: Device, options?: {
30
32
  initSession?: boolean;
31
33
  deriveCardano?: boolean;
32
34
  rejectAttachPinForMainWallet?: boolean;
35
+ mainPinSelected?: boolean;
33
36
  }) => Promise<{
34
37
  passphraseState: string | undefined;
35
38
  newSession: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"deviceFeaturesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/deviceFeaturesUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,KAAK,aAAa,EAA6B,MAAM,qBAAqB,CAAC;AAKjG,OAAoB,EAClB,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC7B,MAAM,6BAA6B,CAAC;AAOrC,O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AAM,YACJ;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,KACA,QAAQ;IACT,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iBAAiB,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC,CAoEA,CAAC;AAKF,eAAO,MAAM,uBAAuB,cAAe,QAAQ,KAAG,kBAU7D,CAAC;AAEF,eAAO,MAAM,sBAAsB,kBAAmB,aAAa,KAAG,cAKrE,CAAC;AAKF,eAAO,MAAM,sBAAsB;cAMvB,QAAQ;gBACN,UAAU,GAAG,KAAK;;kBAEhB,aAAa;MACzB,KAAK,GAAG,cA6BX,CAAC;AAMF,eAAO,MAAM,2BAA2B,aAC5B,QAAQ,cACN,UAAU,GAAG,KAAK,GAAG,YAAY,KAC5C,CAAC,KAAK,GAAG,cAAc,CAAC,EAsC1B,CAAC;AAEF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,UASzC;AAED,eAAO,MAAM,0BAA0B,aAAc,QAAQ,KAAG,QAU/D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.183",
3
+ "version": "1.2.0-alpha.184",
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.183",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.183",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.184",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.184",
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": "fd9b6e749495b0144e734dbe32c57cf483547349"
49
+ "gitHead": "833ce30a921a49ca0ed60cfc491062c26f5b90ae"
50
50
  }
@@ -1,4 +1,11 @@
1
- import { EDeviceType, ERRORS, HardwareError, HardwareErrorCode, wait } from '@onekeyfe/hd-shared';
1
+ import {
2
+ EDeviceType,
3
+ ERRORS,
4
+ HardwareError,
5
+ HardwareErrorCode,
6
+ isBleStaleBondHardwareError,
7
+ wait,
8
+ } from '@onekeyfe/hd-shared';
2
9
  import JSZip from 'jszip';
3
10
  import {
4
11
  DeviceRebootType,
@@ -360,11 +367,12 @@ const isProtocolV2FirmwareStatusEndpointUnavailable = (error: unknown) => {
360
367
  };
361
368
 
362
369
  const isProtocolV2TerminalInstallStatusError = (error: unknown) =>
363
- error instanceof HardwareError &&
364
- (error.errorCode === HardwareErrorCode.ActionCancelled ||
365
- error.errorCode === HardwareErrorCode.FirmwareError ||
366
- error.errorCode === HardwareErrorCode.FirmwareVerificationFailed ||
367
- error.params?.firmwareUpdateCode === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE);
370
+ isBleStaleBondHardwareError(error) ||
371
+ (error instanceof HardwareError &&
372
+ (error.errorCode === HardwareErrorCode.ActionCancelled ||
373
+ error.errorCode === HardwareErrorCode.FirmwareError ||
374
+ error.errorCode === HardwareErrorCode.FirmwareVerificationFailed ||
375
+ error.params?.firmwareUpdateCode === PROTOCOL_V2_INSTALL_STATUS_CONFLICT_CODE));
368
376
 
369
377
  const isProtocolV2TargetStatusFinished = (status: ProtocolV2FirmwareUpdateStatusTarget['status']) =>
370
378
  normalizeProtocolV2TargetStatus(status) === PROTOCOL_V2_TARGET_STATUS_FINISHED;
@@ -1812,6 +1820,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
1812
1820
  if (!expectedHeaderHash || header.headerHash !== expectedHeaderHash) return false;
1813
1821
  return true;
1814
1822
  } catch (error) {
1823
+ if (isBleStaleBondHardwareError(error)) {
1824
+ throw error;
1825
+ }
1815
1826
  Log.log(`[FirmwareUpdateV4] RESC bundle ${bundle.name} header check failed: `, error);
1816
1827
  return false;
1817
1828
  }
@@ -1905,7 +1916,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
1905
1916
  }
1906
1917
  lastError = new Error('Protocol V2 device is reachable but is not in bootloader mode');
1907
1918
  } catch (error) {
1908
- if (this.isProtocolV2ReconnectIdentityError(error)) {
1919
+ if (isBleStaleBondHardwareError(error) || this.isProtocolV2ReconnectIdentityError(error)) {
1909
1920
  throw error;
1910
1921
  }
1911
1922
  shouldReconnect = true;
@@ -2187,6 +2198,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2187
2198
  });
2188
2199
  return processedSize + source.size;
2189
2200
  } catch (error) {
2201
+ if (isBleStaleBondHardwareError(error)) {
2202
+ throw error;
2203
+ }
2190
2204
  lastError = error;
2191
2205
  if (attempt < PROTOCOL_V2_FILE_TRANSFER_RETRY_COUNT) {
2192
2206
  await this.recoverProtocolV2FileTransfer();
@@ -2683,6 +2697,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2683
2697
  return;
2684
2698
  }
2685
2699
  } catch (error) {
2700
+ if (isBleStaleBondHardwareError(error)) {
2701
+ throw error;
2702
+ }
2686
2703
  Log.log('[FirmwareUpdateV4] unable to confirm App mode before Normal reboot: ', error);
2687
2704
  }
2688
2705
  await this.protocolV2Reboot(DeviceRebootType.Normal);
@@ -2774,7 +2791,7 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
2774
2791
  'Protocol V2 device is still in bootloader mode'
2775
2792
  );
2776
2793
  } catch (error) {
2777
- if (this.isProtocolV2ReconnectIdentityError(error)) {
2794
+ if (isBleStaleBondHardwareError(error) || this.isProtocolV2ReconnectIdentityError(error)) {
2778
2795
  throw error;
2779
2796
  }
2780
2797
  shouldReconnect = true;