@onekeyfe/hd-core 1.2.0-alpha.56 → 1.2.0-alpha.62

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 (262) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -231
  2. package/__tests__/DeviceCommands.test.ts +0 -45
  3. package/__tests__/DeviceEventRegistration.test.ts +0 -6
  4. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -198
  5. package/__tests__/connectSettings.test.ts +47 -5
  6. package/__tests__/device-initialize-timeout.test.ts +56 -0
  7. package/__tests__/device-lifecycle-events.test.ts +3 -105
  8. package/__tests__/device-state-contract.test.ts +0 -1
  9. package/__tests__/device-state-mapper.test.ts +1 -1
  10. package/__tests__/deviceSettings.test.ts +1 -1
  11. package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
  12. package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
  13. package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
  14. package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
  15. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
  16. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
  17. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +294 -0
  18. package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
  19. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
  20. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
  21. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
  22. package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
  23. package/__tests__/get-device-state.test.ts +12 -132
  24. package/__tests__/homescreen.test.ts +1 -41
  25. package/__tests__/kaspaSignTransaction.test.ts +26 -3
  26. package/__tests__/logBlockEvent.test.ts +1 -1
  27. package/__tests__/method-protocol-support.test.ts +0 -19
  28. package/__tests__/open-wallet-session.test.ts +37 -568
  29. package/__tests__/protocol-v2-unlock-policy.test.ts +35 -201
  30. package/__tests__/protocol-v2.test.ts +1046 -1388
  31. package/__tests__/protocolV2FileWrite.test.ts +0 -39
  32. package/__tests__/protocolV2UiInteraction.test.ts +0 -63
  33. package/__tests__/public-pro2-api-boundary.test.ts +0 -1
  34. package/__tests__/search-devices.test.ts +3 -12
  35. package/dist/api/BaseMethod.d.ts +1 -3
  36. package/dist/api/BaseMethod.d.ts.map +1 -1
  37. package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
  38. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  39. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  40. package/dist/api/FirmwareUpdateV2.d.ts +11 -0
  41. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  42. package/dist/api/FirmwareUpdateV3.d.ts +7 -3
  43. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  44. package/dist/api/FirmwareUpdateV4.d.ts +25 -11
  45. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  46. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  47. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  48. package/dist/api/SearchDevices.d.ts.map +1 -1
  49. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  50. package/dist/api/device/DeviceUnlock.d.ts +2 -2
  51. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  52. package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
  53. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  54. package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
  55. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
  56. package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
  57. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
  58. package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
  59. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
  60. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +9 -0
  61. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  62. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
  63. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
  64. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
  65. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
  66. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -0
  67. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
  68. package/dist/api/firmware/getBinary.d.ts +7 -0
  69. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  70. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  71. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  72. package/dist/api/firmware/updateBootloader.d.ts +2 -0
  73. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  74. package/dist/api/firmware/uploadFirmware.d.ts +9 -1
  75. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  76. package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -2
  77. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  78. package/dist/api/index.d.ts +0 -2
  79. package/dist/api/index.d.ts.map +1 -1
  80. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  81. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  82. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  83. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  84. package/dist/core/deviceEventRegistration.d.ts +0 -2
  85. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  86. package/dist/core/index.d.ts.map +1 -1
  87. package/dist/data-manager/DataManager.d.ts +2 -4
  88. package/dist/data-manager/DataManager.d.ts.map +1 -1
  89. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  90. package/dist/device/Device.d.ts +6 -29
  91. package/dist/device/Device.d.ts.map +1 -1
  92. package/dist/device/DeviceCommands.d.ts +4 -4
  93. package/dist/device/DeviceCommands.d.ts.map +1 -1
  94. package/dist/device/DevicePool.d.ts.map +1 -1
  95. package/dist/events/device.d.ts +0 -4
  96. package/dist/events/device.d.ts.map +1 -1
  97. package/dist/events/logBlockEvent.d.ts.map +1 -1
  98. package/dist/events/ui-promise.d.ts +2 -4
  99. package/dist/events/ui-promise.d.ts.map +1 -1
  100. package/dist/events/ui-request.d.ts +2 -31
  101. package/dist/events/ui-request.d.ts.map +1 -1
  102. package/dist/events/ui-response.d.ts +2 -10
  103. package/dist/events/ui-response.d.ts.map +1 -1
  104. package/dist/index.d.ts +231 -214
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +3530 -2634
  107. package/dist/inject.d.ts +1 -6
  108. package/dist/inject.d.ts.map +1 -1
  109. package/dist/lowLevelInject.d.ts.map +1 -1
  110. package/dist/protocols/protocol-v2/features.d.ts +4 -0
  111. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  112. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  113. package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
  114. package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
  115. package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
  116. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  117. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
  118. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  119. package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
  120. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
  121. package/dist/protocols/protocol-v2/walletSession.d.ts +1 -6
  122. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  123. package/dist/topLevelInject.d.ts.map +1 -1
  124. package/dist/types/api/checkAllFirmwareRelease.d.ts +4 -2
  125. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  126. package/dist/types/api/deviceUnlock.d.ts +1 -5
  127. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  128. package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
  129. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  130. package/dist/types/api/export.d.ts +4 -2
  131. package/dist/types/api/export.d.ts.map +1 -1
  132. package/dist/types/api/firmwareUpdate.d.ts +70 -2
  133. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  134. package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
  135. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
  136. package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
  137. package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
  138. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
  139. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
  140. package/dist/types/api/index.d.ts +10 -7
  141. package/dist/types/api/index.d.ts.map +1 -1
  142. package/dist/types/api/protocolV2.d.ts +0 -3
  143. package/dist/types/api/protocolV2.d.ts.map +1 -1
  144. package/dist/types/device.d.ts.map +1 -1
  145. package/dist/types/params.d.ts +0 -1
  146. package/dist/types/params.d.ts.map +1 -1
  147. package/dist/types/settings.d.ts +13 -22
  148. package/dist/types/settings.d.ts.map +1 -1
  149. package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
  150. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  151. package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
  152. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  153. package/dist/utils/homescreen.d.ts +0 -4
  154. package/dist/utils/homescreen.d.ts.map +1 -1
  155. package/dist/utils/index.d.ts +1 -1
  156. package/dist/utils/index.d.ts.map +1 -1
  157. package/dist/utils/patch.d.ts +1 -1
  158. package/dist/utils/patch.d.ts.map +1 -1
  159. package/dist/utils/pro2Wallpaper.d.ts +0 -10
  160. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  161. package/package.json +4 -4
  162. package/src/api/BaseMethod.ts +10 -8
  163. package/src/api/CheckAllFirmwareRelease.ts +57 -54
  164. package/src/api/FirmwareUpdate.ts +15 -7
  165. package/src/api/FirmwareUpdateV2.ts +316 -126
  166. package/src/api/FirmwareUpdateV3.ts +265 -63
  167. package/src/api/FirmwareUpdateV4.ts +975 -584
  168. package/src/api/GetPassphraseState.ts +1 -7
  169. package/src/api/OpenWalletSession.ts +17 -70
  170. package/src/api/SearchDevices.ts +1 -3
  171. package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
  172. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -34
  173. package/src/api/device/DeviceUnlock.ts +3 -8
  174. package/src/api/device/DeviceUpdateBootloader.ts +122 -6
  175. package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
  176. package/src/api/firmware/FirmwareHostBinding.ts +100 -0
  177. package/src/api/firmware/FirmwarePreparationError.ts +12 -0
  178. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -16
  179. package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
  180. package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
  181. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +415 -0
  182. package/src/api/firmware/progressThrottle.ts +44 -0
  183. package/src/api/firmware/updateBootloader.ts +19 -4
  184. package/src/api/firmware/uploadFirmware.ts +144 -39
  185. package/src/api/helpers/protocolV2FileWrite.ts +7 -27
  186. package/src/api/index.ts +0 -2
  187. package/src/api/kaspa/KaspaSignTransaction.ts +12 -1
  188. package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
  189. package/src/api/protocol-v2/helpers.ts +0 -1
  190. package/src/core/deviceEventRegistration.ts +0 -4
  191. package/src/core/index.ts +83 -167
  192. package/src/data/messages/messages-protocol-v2.json +0 -25
  193. package/src/data-manager/DataManager.ts +39 -71
  194. package/src/data-manager/connectSettings.ts +11 -0
  195. package/src/device/Device.ts +43 -259
  196. package/src/device/DeviceCommands.ts +1 -7
  197. package/src/device/DevicePool.ts +2 -7
  198. package/src/events/device.ts +0 -4
  199. package/src/events/logBlockEvent.ts +0 -1
  200. package/src/events/ui-promise.ts +2 -4
  201. package/src/events/ui-request.ts +2 -36
  202. package/src/events/ui-response.ts +2 -12
  203. package/src/index.ts +5 -0
  204. package/src/inject.ts +24 -60
  205. package/src/lowLevelInject.ts +8 -7
  206. package/src/protocols/protocol-v2/features.ts +7 -10
  207. package/src/protocols/protocol-v2/firmware.ts +0 -2
  208. package/src/protocols/protocol-v2/lockedError.ts +10 -0
  209. package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
  210. package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
  211. package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
  212. package/src/protocols/protocol-v2/walletSession.ts +36 -214
  213. package/src/topLevelInject.ts +8 -7
  214. package/src/types/api/checkAllFirmwareRelease.ts +4 -2
  215. package/src/types/api/deviceUnlock.ts +1 -12
  216. package/src/types/api/deviceUpdateBootloader.ts +6 -0
  217. package/src/types/api/export.ts +18 -1
  218. package/src/types/api/firmwareUpdate.ts +76 -3
  219. package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
  220. package/src/types/api/firmwareUpdatePlan.ts +38 -0
  221. package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
  222. package/src/types/api/index.ts +14 -13
  223. package/src/types/api/protocolV2.ts +0 -13
  224. package/src/types/device.ts +0 -3
  225. package/src/types/params.ts +1 -7
  226. package/src/types/settings.ts +13 -42
  227. package/src/utils/deviceFeaturesCompat.ts +6 -0
  228. package/src/utils/deviceFeaturesUtils.ts +0 -8
  229. package/src/utils/homescreen.ts +6 -32
  230. package/src/utils/index.ts +1 -6
  231. package/src/utils/pro2Wallpaper.ts +8 -35
  232. package/__tests__/deviceUploadNft.test.ts +0 -293
  233. package/__tests__/pro2Nft.test.ts +0 -108
  234. package/__tests__/protocol-binding.test.ts +0 -89
  235. package/__tests__/protocol-v2-resources.test.ts +0 -286
  236. package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
  237. package/__tests__/uiProgressThrottle.test.ts +0 -74
  238. package/__tests__/uiPromiseRegistry.test.ts +0 -86
  239. package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
  240. package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
  241. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
  242. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
  243. package/dist/core/uiPromiseRegistry.d.ts +0 -4
  244. package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
  245. package/dist/protocols/protocol-v2/resources.d.ts +0 -30
  246. package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
  247. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
  248. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
  249. package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
  250. package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
  251. package/dist/utils/pro2Nft.d.ts +0 -31
  252. package/dist/utils/pro2Nft.d.ts.map +0 -1
  253. package/dist/utils/uiProgressThrottle.d.ts +0 -3
  254. package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
  255. package/src/api/DetectDeviceConnectProtocol.ts +0 -18
  256. package/src/api/protocol-v2/DeviceUploadNft.ts +0 -189
  257. package/src/core/uiPromiseRegistry.ts +0 -41
  258. package/src/protocols/protocol-v2/resources.ts +0 -359
  259. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -118
  260. package/src/types/api/detectDeviceConnectProtocol.ts +0 -6
  261. package/src/utils/pro2Nft.ts +0 -142
  262. package/src/utils/uiProgressThrottle.ts +0 -63
package/src/core/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import semver from 'semver';
2
2
  import EventEmitter from 'events';
3
- import { DeviceSessionPinType, TRANSPORT_EVENT } from '@onekeyfe/hd-transport';
3
+ import { TRANSPORT_EVENT } from '@onekeyfe/hd-transport';
4
4
  import {
5
5
  ERRORS,
6
6
  ERROR_CODES_REQUIRE_RELEASE,
@@ -26,7 +26,6 @@ import {
26
26
  createRequestContext,
27
27
  createSdkTracingContext,
28
28
  formatRequestContext,
29
- generateInstanceId,
30
29
  getActiveRequestsByDeviceInstance,
31
30
  updateRequestContext,
32
31
  } from '../utils/tracing';
@@ -54,15 +53,13 @@ import {
54
53
  import TransportManager from '../data-manager/TransportManager';
55
54
  import DeviceConnector from '../device/DeviceConnector';
56
55
  import RequestQueue from './RequestQueue';
57
- import { findUiPromiseForResponse } from './uiPromiseRegistry';
58
56
  import { registerHardwareUiEventListeners } from './deviceEventRegistration';
59
57
  import { getSynchronize } from '../utils/getSynchronize';
60
- import { runMethodWithUnlockPolicy } from '../protocols/protocol-v2/unlockPolicyRunner';
58
+ import { runMethodWithUnlockRetry } from '../protocols/protocol-v2/unlockRetry';
61
59
  import {
62
60
  ProtocolV2UiInteractionCoordinator,
63
61
  isProtocolV2UiEnabled,
64
62
  } from '../protocols/protocol-v2/uiInteraction';
65
- import { createUiProgressMessageFilter } from '../utils/uiProgressThrottle';
66
63
 
67
64
  import type { ConnectSettings, Features, KnownDevice } from '../types';
68
65
  import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
@@ -106,7 +103,6 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
106
103
  deviceId: method?.payload.deviceId,
107
104
  deriveCardano: method && hasDeriveCardano(method),
108
105
  connectProtocol: method?.payload.connectProtocol,
109
- forceProtocolDetection: method?.payload.forceProtocolDetection,
110
106
  protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
111
107
  });
112
108
 
@@ -158,12 +154,7 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
158
154
  try {
159
155
  method = findMethod(message as IFrameCallMessage);
160
156
  method.connector = _connector;
161
- const shouldPostMessage = createUiProgressMessageFilter();
162
- method.postMessage = event => {
163
- if (shouldPostMessage(event)) {
164
- postMessage(event);
165
- }
166
- };
157
+ method.postMessage = postMessage;
167
158
  method.setContext?.(context);
168
159
 
169
160
  method.requestContext = createRequestContext(method.responseID, method.name, {
@@ -415,8 +406,6 @@ const onCallDevice = async (
415
406
 
416
407
  registerHardwareUiEventListeners(device, {
417
408
  pin: onDevicePinHandler,
418
- pinOnDevice: onEnterPinOnDeviceHandler,
419
- pinOnDeviceComplete: onPinOnDeviceCompleteHandler,
420
409
  button: onDeviceButtonHandler,
421
410
  passphrase: message.payload.useEmptyPassphrase
422
411
  ? onEmptyPassphraseHandler
@@ -432,9 +421,6 @@ const onCallDevice = async (
432
421
  );
433
422
 
434
423
  const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
435
- let protocolV2Operation = false;
436
- let protocolV2CloseEmitted = false;
437
- device.beginProtocolV2UiInteraction();
438
424
  device.on(
439
425
  DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
440
426
  onSelectDeviceForSwitchFirmwareWebDeviceHandler
@@ -452,7 +438,6 @@ const onCallDevice = async (
452
438
  // Protocol is established from an active device response during acquire/initialize.
453
439
  // Reject unsupported methods before any method-specific device command is sent.
454
440
  method.assertProtocolSupported(device.getProtocol(), device.getCurrentFirmwareType());
455
- protocolV2Operation = device.isProtocolV2();
456
441
 
457
442
  // check firmware version
458
443
  const versionRange = device.getCurrentMethodVersionRange(
@@ -562,92 +547,89 @@ const onCallDevice = async (
562
547
  );
563
548
  }
564
549
 
565
- try {
566
- let deviceIdCheckedDuringUnlockPreflight = false;
567
- const response = await runMethodWithUnlockPolicy<object>(method, device, {
568
- uiCoordinator: protocolV2UiCoordinator,
569
- afterStatusBeforeUnlock: () => {
570
- if (method.deviceId && method.checkDeviceId) {
571
- if (!device.checkDeviceId(method.deviceId)) {
572
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
573
- }
574
- deviceIdCheckedDuringUnlockPreflight = true;
575
- }
576
- },
577
- prepare: async () => {
578
- if (method.deviceId && method.checkDeviceId && !deviceIdCheckedDuringUnlockPreflight) {
579
- const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
580
- if (!isSameDeviceID) {
581
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
582
- }
583
- }
550
+ if (method.deviceId && method.checkDeviceId) {
551
+ const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
552
+ if (!isSameDeviceID) {
553
+ return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
554
+ }
555
+ }
584
556
 
585
- /**
586
- * check firmware release info
587
- */
588
- method.checkFirmwareRelease();
557
+ /**
558
+ * check firmware release info
559
+ */
560
+ method.checkFirmwareRelease();
589
561
 
590
- /**
591
- * check additional supported feature
592
- */
593
- method.checkDeviceSupportFeature();
562
+ /**
563
+ * check additional supported feature
564
+ */
565
+ method.checkDeviceSupportFeature();
594
566
 
595
- // reconfigure messages
596
- if (_deviceList && device.features && !device.isProtocolV2()) {
597
- await TransportManager.reconfigure(device.features);
598
- }
567
+ // reconfigure messages
568
+ if (_deviceList && device.features && !device.isProtocolV2()) {
569
+ await TransportManager.reconfigure(device.features);
570
+ }
571
+
572
+ // Check to see if it is safe to use Passphrase
573
+ checkPassphraseEnableState(method, device.features);
599
574
 
600
- // Check to see if it is safe to use Passphrase
601
- checkPassphraseEnableState(method, device.features);
602
-
603
- if (shouldCheckPassphraseState(method, device)) {
604
- // check version
605
- const support = device.supportNewPassphrase();
606
- if (!support.support) {
607
- throw ERRORS.TypedError(
608
- HardwareErrorCode.DeviceNotSupportPassphrase,
609
- `Device not support passphrase, please update to ${support.require}`,
610
- {
611
- require: support.require,
612
- }
613
- );
575
+ if (shouldCheckPassphraseState(method, device)) {
576
+ // check version
577
+ const support = device.supportNewPassphrase();
578
+ if (!support.support) {
579
+ return Promise.reject(
580
+ ERRORS.TypedError(
581
+ HardwareErrorCode.DeviceNotSupportPassphrase,
582
+ `Device not support passphrase, please update to ${support.require}`,
583
+ {
584
+ require: support.require,
614
585
  }
586
+ )
587
+ );
588
+ }
615
589
 
616
- // Check Device passphrase State after the Protocol V2 pre-unlock gate.
617
- const passphraseStateSafety = await device.checkPassphraseStateSafety(
618
- method.payload?.passphraseState,
619
- method.payload?.useEmptyPassphrase,
620
- method.payload?.skipPassphraseCheck,
621
- hasDeriveCardano(method)
622
- );
590
+ // Check Device passphrase State
591
+ const passphraseStateSafety = await device.checkPassphraseStateSafety(
592
+ method.payload?.passphraseState,
593
+ method.payload?.useEmptyPassphrase,
594
+ method.payload?.skipPassphraseCheck
595
+ );
623
596
 
624
- // Double check, handles the special case of Touch/Pro
625
- checkPassphraseEnableState(method, device.features);
597
+ // Double check, handles the special case of Touch/Pro
598
+ checkPassphraseEnableState(method, device.features);
626
599
 
627
- if (!passphraseStateSafety) {
628
- DevicePool.clearDeviceCache(method.payload.connectId);
629
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
630
- }
600
+ if (!passphraseStateSafety) {
601
+ DevicePool.clearDeviceCache(method.payload.connectId);
602
+ return Promise.reject(
603
+ ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError)
604
+ );
605
+ }
631
606
 
632
- // Protocol V2 emits the PIN phase completion from DeviceSessionAskPin.
633
- // Keep the legacy compatibility close for Protocol V1 only.
634
- if (!device.isProtocolV2()) {
635
- postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
636
- }
637
- }
607
+ // close pin popup window
608
+ postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
609
+ }
638
610
 
639
- // Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
640
- try {
641
- await method.checkSafetyLevelOnTestNet();
642
- } catch (e) {
643
- throw e instanceof HardwareError
644
- ? e
645
- : ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
646
- }
611
+ // Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
612
+ try {
613
+ await method.checkSafetyLevelOnTestNet();
614
+ } catch (e) {
615
+ const error =
616
+ e instanceof HardwareError
617
+ ? e
618
+ : ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'open safety check failed.');
619
+ // messageResponse = createResponseMessage(method.responseID, false, { error });
620
+ // requestQueue.resolveRequest(method.responseID, messageResponse);
621
+ // return;
622
+ throw error;
623
+ }
647
624
 
648
- method.device?.commands?.checkDisposed();
649
- },
650
- });
625
+ method.device?.commands?.checkDisposed();
626
+
627
+ try {
628
+ const response: object = await runMethodWithUnlockRetry(
629
+ method,
630
+ device,
631
+ protocolV2UiCoordinator
632
+ );
651
633
  messageResponse = createResponseMessage(method.responseID, true, response);
652
634
  requestQueue.resolveRequest(method.responseID, messageResponse);
653
635
  completeMethodRequestContext(method);
@@ -665,12 +647,7 @@ const onCallDevice = async (
665
647
  throw error;
666
648
  }
667
649
  } finally {
668
- if (isProtocolV2UiEnabled(method)) {
669
- protocolV2CloseEmitted = protocolV2UiCoordinator.close({
670
- ensureOperationClose: protocolV2Operation,
671
- protocolV2Operation,
672
- });
673
- }
650
+ protocolV2UiCoordinator.close();
674
651
  }
675
652
  };
676
653
  Log.debug('Call API - Device Run: ', device.mainId);
@@ -725,15 +702,7 @@ const onCallDevice = async (
725
702
  requestQueue.releaseTask(method.responseID);
726
703
 
727
704
  if (isProtocolV2UiEnabled(method)) {
728
- if (!protocolV2CloseEmitted && protocolV2Operation) {
729
- protocolV2CloseEmitted = protocolV2UiCoordinator.close({
730
- ensureOperationClose: true,
731
- protocolV2Operation: true,
732
- });
733
- }
734
- if (!protocolV2CloseEmitted) {
735
- closePopup();
736
- }
705
+ closePopup();
737
706
  }
738
707
 
739
708
  cleanup();
@@ -896,18 +865,10 @@ function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown)
896
865
  */
897
866
  async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
898
867
  try {
899
- if (method.payload.forceProtocolDetection && device.hasDeviceAcquire()) {
900
- await device.release();
901
- }
902
868
  const shouldAcquire =
903
- method.payload.forceProtocolDetection ||
904
- !device.hasDeviceAcquire() ||
905
- !device.commands ||
906
- device.commands.disposed;
869
+ !device.hasDeviceAcquire() || !device.commands || device.commands.disposed;
907
870
  if (shouldAcquire) {
908
- await device.acquire(method.payload.connectProtocol, {
909
- forceProtocolDetection: method.payload.forceProtocolDetection,
910
- });
871
+ await device.acquire(method.payload.connectProtocol);
911
872
  }
912
873
  if (method.payload?.onlyConnectBleDevice) {
913
874
  if (shouldAcquire) {
@@ -1271,7 +1232,6 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
1271
1232
  createUiMessage(UI_REQUEST.REQUEST_PIN, {
1272
1233
  device: device.toMessageObject() as unknown as KnownDevice,
1273
1234
  type,
1274
- responseCorrelation: uiPromise.responseCorrelation,
1275
1235
  })
1276
1236
  );
1277
1237
  // wait for pin
@@ -1319,8 +1279,6 @@ const onDevicePassphraseHandler = async (
1319
1279
  source: requestPayload.source,
1320
1280
  reason: requestPayload.reason,
1321
1281
  expectedPassphraseState: requestPayload.expectedPassphraseState,
1322
- ...(requestPayload.interaction ? { interaction: requestPayload.interaction } : {}),
1323
- responseCorrelation: uiPromise.responseCorrelation,
1324
1282
  })
1325
1283
  );
1326
1284
  // wait for passphrase
@@ -1350,7 +1308,6 @@ const onEnterPassphraseOnDeviceHandler = (
1350
1308
  passphraseState: device.passphraseState,
1351
1309
  source: requestPayload?.source,
1352
1310
  reason: requestPayload?.reason,
1353
- ...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
1354
1311
  })
1355
1312
  );
1356
1313
  };
@@ -1364,39 +1321,10 @@ const onEnterAttachPinOnDeviceHandler = (
1364
1321
  type: 'ButtonRequest_AttachPin',
1365
1322
  source: requestPayload?.source,
1366
1323
  reason: requestPayload?.reason,
1367
- ...(requestPayload?.interaction ? { interaction: requestPayload.interaction } : {}),
1368
- })
1369
- );
1370
- };
1371
-
1372
- const onEnterPinOnDeviceHandler = (
1373
- ...[device, pinType, metadata]: [...DeviceEvents['pin_on_device']]
1374
- ) => {
1375
- postMessage(
1376
- createUiMessage(UI_REQUEST.REQUEST_PIN, {
1377
- device: device.toMessageObject() as KnownDevice,
1378
- type:
1379
- pinType === DeviceSessionPinType.AttachToPin
1380
- ? 'ButtonRequest_AttachPin'
1381
- : 'ButtonRequest_PinEntry',
1382
- source: metadata?.source,
1383
- reason: metadata?.reason,
1384
- deviceOnly: metadata?.deviceOnly ?? true,
1385
- completion: metadata?.completion,
1386
- method: metadata?.method,
1387
- page: metadata?.page,
1388
- operation: metadata?.operation,
1389
- ...(metadata?.interaction ? { interaction: metadata.interaction } : {}),
1390
1324
  })
1391
1325
  );
1392
1326
  };
1393
1327
 
1394
- const onPinOnDeviceCompleteHandler = (
1395
- ...[_, metadata]: [...DeviceEvents['pin_on_device_complete']]
1396
- ) => {
1397
- postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW, metadata));
1398
- };
1399
-
1400
1328
  const onSelectDeviceInBootloaderForWebDeviceHandler = async (
1401
1329
  ...[device, callback]: [...DeviceEvents['select_device_in_bootloader_for_web_device']]
1402
1330
  ) => {
@@ -1444,21 +1372,14 @@ const postMessage = (message: CoreMessage) => {
1444
1372
 
1445
1373
  const createUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T, device?: Device) => {
1446
1374
  const uiPromise: UiPromise<T> = createDeferred(promiseEvent, device);
1447
- if (
1448
- device &&
1449
- (promiseEvent === UI_RESPONSE.RECEIVE_PIN || promiseEvent === UI_RESPONSE.RECEIVE_PASSPHRASE)
1450
- ) {
1451
- const publicDeviceId = device.toMessageObject()?.deviceId;
1452
- uiPromise.responseCorrelation = {
1453
- interactionId: generateInstanceId('UiResponse', device.sdkInstanceId),
1454
- deviceId: publicDeviceId || device.instanceId,
1455
- };
1456
- }
1457
1375
  _uiPromises.push(uiPromise as any);
1458
1376
 
1459
1377
  return uiPromise;
1460
1378
  };
1461
1379
 
1380
+ const findUiPromise = <T extends UiPromiseResponse['type']>(promiseEvent: T) =>
1381
+ _uiPromises.find(p => p.id === promiseEvent);
1382
+
1462
1383
  const removeUiPromise = (promise: Deferred<any>) => {
1463
1384
  _uiPromises = _uiPromises.filter(p => p !== promise);
1464
1385
  };
@@ -1510,16 +1431,11 @@ export default class Core extends EventEmitter {
1510
1431
  case UI_RESPONSE.RECEIVE_PASSPHRASE:
1511
1432
  case UI_RESPONSE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE:
1512
1433
  case UI_RESPONSE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE: {
1513
- const uiPromise = findUiPromiseForResponse(_uiPromises, message);
1434
+ const uiPromise = findUiPromise(message.type);
1514
1435
  if (uiPromise) {
1515
1436
  Log.log('receive UI Response: ', message.type);
1516
1437
  uiPromise.resolve(message);
1517
1438
  removeUiPromise(uiPromise);
1518
- } else if (
1519
- message.type === UI_RESPONSE.RECEIVE_PIN ||
1520
- message.type === UI_RESPONSE.RECEIVE_PASSPHRASE
1521
- ) {
1522
- Log.warn('Ignored unmatched or ambiguous sensitive UI response:', message.type);
1523
1439
  }
1524
1440
  break;
1525
1441
  }
@@ -470,7 +470,6 @@
470
470
  "MessageType_DeviceSessionAskPin": 61202,
471
471
  "MessageType_DeviceSessionAskPassphrase": 61203,
472
472
  "MessageType_PortfolioUpdate": 61400,
473
- "MessageType_NftUpdate": 61500,
474
473
  "MessageType_OnboardingStatusGet": 61600,
475
474
  "MessageType_OnboardingStatus": 61601
476
475
  },
@@ -12201,26 +12200,11 @@
12201
12200
  "DeviceSessionError_Busy": 5
12202
12201
  }
12203
12202
  },
12204
- "DeviceSessionSeedDomain": {
12205
- "values": {
12206
- "SeedDomain_Standard": 1,
12207
- "SeedDomain_Cardano": 2
12208
- }
12209
- },
12210
12203
  "DeviceSessionGet": {
12211
12204
  "fields": {
12212
12205
  "session_id": {
12213
12206
  "type": "bytes",
12214
12207
  "id": 1
12215
- },
12216
- "btc_test_address": {
12217
- "type": "string",
12218
- "id": 2
12219
- },
12220
- "seed_domains": {
12221
- "rule": "repeated",
12222
- "type": "DeviceSessionSeedDomain",
12223
- "id": 3
12224
12208
  }
12225
12209
  }
12226
12210
  },
@@ -12554,15 +12538,6 @@
12554
12538
  }
12555
12539
  }
12556
12540
  },
12557
- "NftUpdate": {
12558
- "fields": {
12559
- "file_name_no_ext": {
12560
- "rule": "required",
12561
- "type": "string",
12562
- "id": 1
12563
- }
12564
- }
12565
- },
12566
12541
  "OnboardingStep": {
12567
12542
  "values": {
12568
12543
  "ONBOARDING_STEP_UNKNOWN": 0,
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import semver from 'semver';
3
- import { EDeviceType, EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
4
4
 
5
5
  import MessagesJSON from '../data/messages/messages.json';
6
6
  import MessagesLegacyV1JSON from '../data/messages/messages_legacy_v1.json';
@@ -17,7 +17,6 @@ import {
17
17
  } from '../utils';
18
18
  import { DeviceModelToTypes } from '../types';
19
19
  import { findLatestRelease, getReleaseChangelog, getReleaseStatus } from '../utils/release';
20
- import { parseProtocolV2Resources } from '../protocols/protocol-v2/resources';
21
20
 
22
21
  import type {
23
22
  AssetsMap,
@@ -398,10 +397,20 @@ export default class DataManager {
398
397
  return enrichedData;
399
398
  }
400
399
 
401
- static async load(settings: ConnectSettings): Promise<boolean> {
400
+ static async load(settings: ConnectSettings) {
402
401
  this.settings = settings;
403
- if (!settings.fetchConfig) {
404
- return false;
402
+ const manifestMode =
403
+ settings.firmwareManifestMode ?? (settings.fetchConfig ? 'sdk-managed' : undefined);
404
+ if (settings.preloadedConfig) {
405
+ this.applyRemoteConfig(settings.preloadedConfig);
406
+ Log.log('[DataConfig] Preloaded firmware config loaded');
407
+ return;
408
+ }
409
+ if (manifestMode === 'external-only') {
410
+ throw new Error('External firmware config snapshot is required');
411
+ }
412
+ if (manifestMode !== 'sdk-managed') {
413
+ return;
405
414
  }
406
415
 
407
416
  const url = settings.preRelease
@@ -410,65 +419,48 @@ export default class DataManager {
410
419
 
411
420
  const urlWithCache = `${url}?noCache=${getTimeStamp()}`;
412
421
  let data: RemoteConfigResponse | null = null;
413
- let fetchMethod: 'configFetcher' | 'axios' | 'none' = 'none';
414
-
415
- // 1. Try custom configFetcher first (client-side IP direct connection support)
416
422
  if (settings.configFetcher) {
417
- Log.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
423
+ Log.debug('[DataConfig] Trying client configFetcher...');
418
424
  try {
419
425
  data = await settings.configFetcher(urlWithCache);
420
- if (data) {
421
- fetchMethod = 'configFetcher';
422
- Log.log('[DataConfig] ConfigFetcher success');
423
- } else {
424
- Log.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
425
- }
426
426
  } catch (e) {
427
- Log.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
427
+ Log.warn('[DataConfig] Client configFetcher failed:', e);
428
428
  }
429
429
  }
430
-
431
- // 2. Fallback to default axios request
432
430
  if (!data) {
433
- Log.debug('[DataConfig] Trying axios (SDK default fetcher)...');
431
+ Log.debug('[DataConfig] Trying SDK-managed config request...');
434
432
  try {
435
433
  const response = await axios.get<RemoteConfigResponse>(urlWithCache, {
436
434
  // because of iframe timeout is 10000
437
435
  timeout: 7000,
438
436
  });
439
437
  data = response.data;
440
- fetchMethod = 'axios';
441
- Log.log('[DataConfig] Axios fetch success');
438
+ Log.log('[DataConfig] SDK-managed config request succeeded');
442
439
  } catch (e) {
443
- Log.warn('[DataConfig] Axios fetch error:', e);
440
+ Log.warn('[DataConfig] SDK-managed config request failed:', e);
444
441
  }
445
442
  }
446
443
 
447
- // 3. Apply config if available
448
444
  if (data) {
449
- const pro2Resources = parseProtocolV2Resources(
450
- (data.pro2 as { resources?: unknown } | undefined)?.resources
451
- );
452
- Log.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
453
- this.deviceMap = {
454
- [EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
455
- [EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
456
- [EDeviceType.ClassicPure]: this.enrichFirmwareReleaseInfo(data.classicpure),
457
- [EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
458
- [EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
459
- [EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
460
- [EDeviceType.Pro2]: {
461
- ...this.enrichFirmwareReleaseInfo(data.pro2),
462
- ...(pro2Resources ? { resources: pro2Resources } : undefined),
463
- },
464
- };
465
- this.assets = {
466
- bridge: data.bridge,
467
- };
468
- return true;
445
+ this.applyRemoteConfig(data);
446
+ } else {
447
+ Log.warn('[DataConfig] SDK-managed config request failed, using built-in default config');
469
448
  }
470
- Log.warn('[DataConfig] All fetch methods failed, using built-in default config');
471
- return false;
449
+ }
450
+
451
+ private static applyRemoteConfig(data: RemoteConfigResponse) {
452
+ this.deviceMap = {
453
+ [EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
454
+ [EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
455
+ [EDeviceType.ClassicPure]: this.enrichFirmwareReleaseInfo(data.classicpure),
456
+ [EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
457
+ [EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
458
+ [EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
459
+ [EDeviceType.Pro2]: this.enrichFirmwareReleaseInfo(data.pro2),
460
+ };
461
+ this.assets = {
462
+ bridge: data.bridge,
463
+ };
472
464
  }
473
465
 
474
466
  static updateEnv(newEnv: ConnectSettings['env']) {
@@ -486,36 +478,12 @@ export default class DataManager {
486
478
 
487
479
  static async checkAndReloadData() {
488
480
  if (getTimeStamp() - this.lastCheckTimestamp > 1000 * 60 * 60 * 3) {
489
- const loaded = await this.load(this.settings);
490
- if (loaded) {
481
+ await this.load(this.settings).then(() => {
491
482
  this.lastCheckTimestamp = getTimeStamp();
492
- }
483
+ });
493
484
  }
494
485
  }
495
486
 
496
- /** Force a fresh remote config before an update is allowed to mutate the device. */
497
- static async forceReloadData(): Promise<void> {
498
- if (!this.settings) {
499
- throw new Error('Remote config settings are not initialized');
500
- }
501
- const loaded = await this.load(this.settings);
502
- if (!loaded) {
503
- throw ERRORS.TypedError(
504
- HardwareErrorCode.NetworkError,
505
- 'Unable to refresh the latest remote config'
506
- );
507
- }
508
- this.lastCheckTimestamp = getTimeStamp();
509
- }
510
-
511
- static getProtocolV2Resources() {
512
- return this.deviceMap[EDeviceType.Pro2]?.resources?.stable;
513
- }
514
-
515
- static getProtocolV2BootResources() {
516
- return this.deviceMap[EDeviceType.Pro2]?.resources?.boot;
517
- }
518
-
519
487
  static getProtobufMessages(schema: ProtobufMessageSchema = 'v1CurrentSchema'): JSON {
520
488
  return this.messages[schema];
521
489
  }
@@ -115,10 +115,21 @@ export const parseConnectSettings = (input: Partial<ConnectSettings> = {}) => {
115
115
  settings.fetchConfig = input.fetchConfig;
116
116
  }
117
117
 
118
+ if (
119
+ input.firmwareManifestMode === 'sdk-managed' ||
120
+ input.firmwareManifestMode === 'external-only'
121
+ ) {
122
+ settings.firmwareManifestMode = input.firmwareManifestMode;
123
+ }
124
+
118
125
  if (input.configFetcher) {
119
126
  settings.configFetcher = input.configFetcher;
120
127
  }
121
128
 
129
+ if (input.preloadedConfig) {
130
+ settings.preloadedConfig = input.preloadedConfig;
131
+ }
132
+
122
133
  return settings;
123
134
  };
124
135