@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.68

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 (254) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +313 -0
  2. package/__tests__/DeviceCommands.test.ts +59 -13
  3. package/__tests__/DeviceEventRegistration.test.ts +6 -0
  4. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
  5. package/__tests__/core-initialization.test.ts +23 -0
  6. package/__tests__/device-connector-protocol.test.ts +81 -0
  7. package/__tests__/device-lifecycle-events.test.ts +105 -3
  8. package/__tests__/device-pool-state.test.ts +22 -0
  9. package/__tests__/device-settings.test.ts +39 -18
  10. package/__tests__/device-state-contract.test.ts +1 -0
  11. package/__tests__/device-state-mapper.test.ts +13 -1
  12. package/__tests__/device-utils.test.ts +48 -1
  13. package/__tests__/deviceSettings.test.ts +11 -1
  14. package/__tests__/deviceUploadNft.test.ts +316 -0
  15. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +5 -0
  16. package/__tests__/get-device-state.test.ts +132 -12
  17. package/__tests__/homescreen.test.ts +41 -1
  18. package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
  19. package/__tests__/kaspaSignTransaction.test.ts +3 -26
  20. package/__tests__/logBlockEvent.test.ts +1 -1
  21. package/__tests__/method-protocol-support.test.ts +19 -0
  22. package/__tests__/open-wallet-session.test.ts +568 -37
  23. package/__tests__/pro2Nft.test.ts +108 -0
  24. package/__tests__/protocol-binding.test.ts +89 -0
  25. package/__tests__/protocol-v2-resources.test.ts +340 -0
  26. package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
  27. package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
  28. package/__tests__/protocol-v2.test.ts +1449 -867
  29. package/__tests__/protocolV2FileWrite.test.ts +152 -0
  30. package/__tests__/protocolV2UiInteraction.test.ts +63 -0
  31. package/__tests__/public-pro2-api-boundary.test.ts +1 -0
  32. package/__tests__/search-devices.test.ts +12 -3
  33. package/__tests__/tron-sign-message-init.test.ts +2 -2
  34. package/__tests__/uiProgressThrottle.test.ts +74 -0
  35. package/__tests__/uiPromiseRegistry.test.ts +115 -0
  36. package/dist/api/BaseMethod.d.ts +3 -1
  37. package/dist/api/BaseMethod.d.ts.map +1 -1
  38. package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
  39. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  40. package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
  41. package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
  42. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  43. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  44. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  45. package/dist/api/FirmwareUpdateV4.d.ts +11 -4
  46. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  47. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  48. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  49. package/dist/api/SearchDevices.d.ts.map +1 -1
  50. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  51. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  52. package/dist/api/device/DeviceUnlock.d.ts +2 -2
  53. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  54. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -3
  55. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  56. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  57. package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
  58. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  59. package/dist/api/index.d.ts +2 -0
  60. package/dist/api/index.d.ts.map +1 -1
  61. package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
  62. package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
  63. package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
  64. package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
  65. package/dist/api/polkadot/networks.d.ts +1 -1
  66. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
  67. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
  68. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  69. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  70. package/dist/api/solana/SolSignMessage.d.ts +1 -1
  71. package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
  72. package/dist/api/solana/SolSignTransaction.d.ts +2 -2
  73. package/dist/api/sui/SuiGetAddress.d.ts +1 -1
  74. package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
  75. package/dist/api/sui/SuiSignMessage.d.ts +1 -1
  76. package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
  77. package/dist/api/ton/TonGetAddress.d.ts +1 -1
  78. package/dist/api/ton/TonSignMessage.d.ts +1 -1
  79. package/dist/api/ton/TonSignProof.d.ts +1 -1
  80. package/dist/api/tron/TronSignMessage.d.ts +2 -2
  81. package/dist/api/tron/TronSignTransaction.d.ts +1 -1
  82. package/dist/core/deviceEventRegistration.d.ts +2 -0
  83. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  84. package/dist/core/index.d.ts.map +1 -1
  85. package/dist/core/uiPromiseRegistry.d.ts +6 -0
  86. package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
  87. package/dist/data-manager/DataManager.d.ts +9 -3
  88. package/dist/data-manager/DataManager.d.ts.map +1 -1
  89. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  90. package/dist/device/Device.d.ts +29 -5
  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/DeviceConnector.d.ts +2 -1
  95. package/dist/device/DeviceConnector.d.ts.map +1 -1
  96. package/dist/device/DevicePool.d.ts.map +1 -1
  97. package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
  98. package/dist/events/device.d.ts +4 -0
  99. package/dist/events/device.d.ts.map +1 -1
  100. package/dist/events/logBlockEvent.d.ts.map +1 -1
  101. package/dist/events/ui-promise.d.ts +4 -2
  102. package/dist/events/ui-promise.d.ts.map +1 -1
  103. package/dist/events/ui-request.d.ts +31 -2
  104. package/dist/events/ui-request.d.ts.map +1 -1
  105. package/dist/events/ui-response.d.ts +10 -2
  106. package/dist/events/ui-response.d.ts.map +1 -1
  107. package/dist/index.d.ts +243 -69
  108. package/dist/index.js +2563 -1217
  109. package/dist/inject.d.ts +6 -1
  110. package/dist/inject.d.ts.map +1 -1
  111. package/dist/lowLevelInject.d.ts.map +1 -1
  112. package/dist/protocols/protocol-v2/features.d.ts +0 -4
  113. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  114. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
  115. package/dist/protocols/protocol-v2/resources.d.ts +30 -0
  116. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
  117. package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
  118. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  119. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
  120. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  121. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
  122. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
  123. package/dist/protocols/protocol-v2/walletSession.d.ts +6 -1
  124. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  125. package/dist/topLevelInject.d.ts.map +1 -1
  126. package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -1
  127. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  128. package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
  129. package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
  130. package/dist/types/api/deviceUnlock.d.ts +5 -1
  131. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  132. package/dist/types/api/export.d.ts +1 -0
  133. package/dist/types/api/export.d.ts.map +1 -1
  134. package/dist/types/api/firmwareUpdate.d.ts +4 -2
  135. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  136. package/dist/types/api/index.d.ts +6 -1
  137. package/dist/types/api/index.d.ts.map +1 -1
  138. package/dist/types/api/protocolV2.d.ts +3 -0
  139. package/dist/types/api/protocolV2.d.ts.map +1 -1
  140. package/dist/types/device.d.ts +2 -2
  141. package/dist/types/device.d.ts.map +1 -1
  142. package/dist/types/params.d.ts +1 -0
  143. package/dist/types/params.d.ts.map +1 -1
  144. package/dist/types/settings.d.ts +38 -8
  145. package/dist/types/settings.d.ts.map +1 -1
  146. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  147. package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
  148. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  149. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  150. package/dist/utils/deviceSettings.d.ts.map +1 -1
  151. package/dist/utils/homescreen.d.ts +4 -0
  152. package/dist/utils/homescreen.d.ts.map +1 -1
  153. package/dist/utils/index.d.ts +1 -1
  154. package/dist/utils/index.d.ts.map +1 -1
  155. package/dist/utils/patch.d.ts +1 -1
  156. package/dist/utils/patch.d.ts.map +1 -1
  157. package/dist/utils/pro2Nft.d.ts +31 -0
  158. package/dist/utils/pro2Nft.d.ts.map +1 -0
  159. package/dist/utils/pro2Wallpaper.d.ts +10 -0
  160. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  161. package/dist/utils/uiProgressThrottle.d.ts +3 -0
  162. package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
  163. package/package.json +4 -4
  164. package/src/api/BaseMethod.ts +8 -10
  165. package/src/api/CheckAllFirmwareRelease.ts +61 -11
  166. package/src/api/DetectDeviceConnectProtocol.ts +18 -0
  167. package/src/api/FirmwareUpdate.ts +6 -2
  168. package/src/api/FirmwareUpdateV2.ts +5 -2
  169. package/src/api/FirmwareUpdateV3.ts +6 -2
  170. package/src/api/FirmwareUpdateV4.ts +463 -258
  171. package/src/api/GetPassphraseState.ts +7 -1
  172. package/src/api/OpenWalletSession.ts +71 -17
  173. package/src/api/SearchDevices.ts +3 -1
  174. package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
  175. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
  176. package/src/api/device/DeviceSettings.ts +5 -4
  177. package/src/api/device/DeviceUnlock.ts +8 -3
  178. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -12
  179. package/src/api/firmware/uploadFirmware.ts +17 -4
  180. package/src/api/helpers/protocolV2FileWrite.ts +202 -63
  181. package/src/api/index.ts +2 -0
  182. package/src/api/kaspa/KaspaGetAddress.ts +1 -1
  183. package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
  184. package/src/api/polkadot/networks.ts +3 -3
  185. package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
  186. package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
  187. package/src/api/protocol-v2/helpers.ts +1 -1
  188. package/src/api/solana/SolSignMessage.ts +1 -1
  189. package/src/api/solana/SolSignOffchainMessage.ts +1 -1
  190. package/src/api/solana/SolSignTransaction.ts +2 -2
  191. package/src/api/sui/SuiGetAddress.ts +1 -1
  192. package/src/api/sui/SuiGetPublicKey.ts +1 -1
  193. package/src/api/sui/SuiSignMessage.ts +1 -1
  194. package/src/api/sui/SuiSignTransaction.ts +1 -1
  195. package/src/api/ton/TonGetAddress.ts +1 -1
  196. package/src/api/ton/TonSignMessage.ts +1 -1
  197. package/src/api/ton/TonSignProof.ts +1 -1
  198. package/src/api/tron/TronSignMessage.ts +2 -2
  199. package/src/api/tron/TronSignTransaction.ts +1 -1
  200. package/src/core/deviceEventRegistration.ts +4 -0
  201. package/src/core/index.ts +213 -111
  202. package/src/core/uiPromiseRegistry.ts +63 -0
  203. package/src/data/messages/messages-protocol-v2.json +25 -0
  204. package/src/data-manager/DataManager.ts +88 -11
  205. package/src/data-manager/TransportManager.ts +6 -0
  206. package/src/device/Device.ts +273 -43
  207. package/src/device/DeviceCommands.ts +31 -4
  208. package/src/device/DeviceConnector.ts +33 -13
  209. package/src/device/DevicePool.ts +21 -7
  210. package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
  211. package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
  212. package/src/events/device.ts +4 -0
  213. package/src/events/logBlockEvent.ts +1 -0
  214. package/src/events/ui-promise.ts +4 -2
  215. package/src/events/ui-request.ts +36 -2
  216. package/src/events/ui-response.ts +12 -2
  217. package/src/inject.ts +58 -2
  218. package/src/lowLevelInject.ts +6 -3
  219. package/src/protocols/protocol-v2/features.ts +10 -7
  220. package/src/protocols/protocol-v2/firmware.ts +2 -0
  221. package/src/protocols/protocol-v2/resources.ts +390 -0
  222. package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
  223. package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
  224. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
  225. package/src/protocols/protocol-v2/walletSession.ts +214 -36
  226. package/src/topLevelInject.ts +6 -3
  227. package/src/types/api/checkAllFirmwareRelease.ts +3 -1
  228. package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
  229. package/src/types/api/deviceUnlock.ts +12 -1
  230. package/src/types/api/export.ts +1 -0
  231. package/src/types/api/firmwareUpdate.ts +6 -3
  232. package/src/types/api/index.ts +13 -0
  233. package/src/types/api/protocolV2.ts +13 -0
  234. package/src/types/device.ts +15 -3
  235. package/src/types/params.ts +7 -1
  236. package/src/types/settings.ts +60 -9
  237. package/src/utils/deviceFeaturesCompat.ts +5 -0
  238. package/src/utils/deviceFeaturesUtils.ts +14 -3
  239. package/src/utils/deviceInfoUtils.ts +2 -0
  240. package/src/utils/deviceSettings.ts +3 -0
  241. package/src/utils/homescreen.ts +32 -6
  242. package/src/utils/index.ts +6 -1
  243. package/src/utils/pro2Nft.ts +142 -0
  244. package/src/utils/pro2Wallpaper.ts +35 -8
  245. package/src/utils/uiProgressThrottle.ts +63 -0
  246. package/dist/api/firmware/progressThrottle.d.ts +0 -3
  247. package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
  248. package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
  249. package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
  250. package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
  251. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
  252. package/src/api/firmware/progressThrottle.ts +0 -44
  253. package/src/protocols/protocol-v2/lockedError.ts +0 -10
  254. package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
@@ -1 +1 @@
1
- {"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,CAAC;AA8B7D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CA4D9D"}
1
+ {"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AA8BjE,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CA4E9D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CAE9D"}
@@ -0,0 +1,3 @@
1
+ import type { CoreMessage } from '../events';
2
+ export declare const createUiProgressMessageFilter: (intervalMs?: number, now?: () => number) => (message: CoreMessage) => boolean;
3
+ //# sourceMappingURL=uiProgressThrottle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uiProgressThrottle.d.ts","sourceRoot":"","sources":["../../src/utils/uiProgressThrottle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAiB7C,eAAO,MAAM,6BAA6B,yDAMvB,WAAW,YAqC7B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.67",
3
+ "version": "1.2.0-alpha.68",
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.67",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.67",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.68",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.68",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/w3c-web-usb": "^1.0.10",
45
45
  "@types/web-bluetooth": "^0.0.21"
46
46
  },
47
- "gitHead": "5fea66e8c65a1fab2ccc099b2811c8749b2487e0"
47
+ "gitHead": "6e8a931d08768980cfe7fa918bba447ed73e2724"
48
48
  }
@@ -16,16 +16,14 @@ import { getBleFirmwareReleaseInfo, getFirmwareReleaseInfo } from './firmware/re
16
16
  import { LoggerNames, getLogger } from '../utils';
17
17
  import { generateInstanceId } from '../utils/tracing';
18
18
  import { DeviceModelToTypes } from '../types';
19
- import {
20
- type UnlockPolicy,
21
- getProtocolV2UnlockPolicy,
22
- } from '../protocols/protocol-v2/unlockPolicy';
23
19
 
24
20
  import type { Device } from '../device/Device';
25
21
  import type DeviceConnector from '../device/DeviceConnector';
26
22
  import type { DeviceFirmwareRange, KnownDevice } from '../types';
27
23
  import type { CoreMessage } from '../events';
24
+ import type { UnlockPolicy } from '../protocols/protocol-v2/unlockPolicy';
28
25
  import type { ProtocolV2InteractionDescriptor } from '../protocols/protocol-v2/uiInteraction';
26
+ import type { ProtocolV2UnlockContext } from '../protocols/protocol-v2/unlockPolicyRunner';
29
27
  import type { RequestContext } from '../utils/tracing';
30
28
  import type { CoreContext } from '../core';
31
29
 
@@ -128,9 +126,7 @@ export abstract class BaseMethod<Params = undefined> {
128
126
  */
129
127
  checkDeviceId = false;
130
128
 
131
- /**
132
- * 该方法是否需要校验 passphrase state
133
- */
129
+ /** Whether the method requires wallet-session selection and Protocol V2 pre-unlock. */
134
130
  useDevicePassphraseState = true;
135
131
 
136
132
  /**
@@ -168,9 +164,12 @@ export abstract class BaseMethod<Params = undefined> {
168
164
  */
169
165
  strictCheckDeviceSupport = false;
170
166
 
171
- /** Core unlocks and retries only explicitly replay-safe Protocol V2 methods. */
167
+ /** Non-wallet methods may explicitly require Protocol V2 pre-unlock. */
172
168
  unlockPolicy: UnlockPolicy = 'none';
173
169
 
170
+ /** Shared by composite methods so nested calls do not repeat the root preflight. */
171
+ protocolV2UnlockContext?: ProtocolV2UnlockContext;
172
+
174
173
  getSupportedProtocols(): readonly ProtocolType[] {
175
174
  return ['V1'];
176
175
  }
@@ -188,7 +187,7 @@ export abstract class BaseMethod<Params = undefined> {
188
187
  /** Non-blocking Protocol V2 interaction synthesized by the SDK. */
189
188
  protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
190
189
 
191
- /** Special background methods may suppress all synthesized Protocol V2 UI events. */
190
+ /** Special background methods may suppress method-level Protocol V2 UI events. */
192
191
  protocolV2UiMode: ProtocolV2UiMode = 'auto';
193
192
 
194
193
  protected throwIfAborted() {
@@ -217,7 +216,6 @@ export abstract class BaseMethod<Params = undefined> {
217
216
  this.useDevice = true;
218
217
  this.allowDeviceMode = [UI_REQUEST.NOT_INITIALIZE];
219
218
  this.requireDeviceMode = [];
220
- this.unlockPolicy = getProtocolV2UnlockPolicy(this.name);
221
219
  }
222
220
 
223
221
  abstract init(): void;
@@ -1,4 +1,10 @@
1
- import { EFirmwareType, ERRORS, HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
1
+ import {
2
+ EDeviceType,
3
+ EFirmwareType,
4
+ ERRORS,
5
+ HardwareError,
6
+ HardwareErrorCode,
7
+ } from '@onekeyfe/hd-shared';
2
8
  import semver from 'semver';
3
9
 
4
10
  import { BaseMethod } from './BaseMethod';
@@ -14,6 +20,10 @@ import {
14
20
  validateFirmwareUpdatePlanForceTargets,
15
21
  } from './firmware/FirmwareUpdatePlan';
16
22
  import { getBridgeReleaseInfo } from '../utils/bridgeUpdate';
23
+ import {
24
+ buildProtocolV2ResourceUpdatePlan,
25
+ readProtocolV2ResourceInventory,
26
+ } from '../protocols/protocol-v2/resources';
17
27
  import {
18
28
  LoggerNames,
19
29
  getDeviceFirmwareVersion,
@@ -101,6 +111,7 @@ function buildComponentRelease({
101
111
  component,
102
112
  currentVersions,
103
113
  currentVerification,
114
+ checkFirmwareHash,
104
115
  remotePayloadHash,
105
116
  releaseRequired,
106
117
  }: {
@@ -108,6 +119,7 @@ function buildComponentRelease({
108
119
  component: IProtocolV2FirmwareComponent;
109
120
  currentVersions: DeviceStateVersions;
110
121
  currentVerification: Partial<DeviceFeaturesVerify>;
122
+ checkFirmwareHash: boolean;
111
123
  remotePayloadHash: string | null | undefined;
112
124
  releaseRequired: boolean;
113
125
  }): ProtocolV2FirmwareComponentRelease {
@@ -136,7 +148,7 @@ function buildComponentRelease({
136
148
  status = 'valid';
137
149
  } else {
138
150
  const currentHashKey = CURRENT_HASH_BY_COMPONENT_TARGET[componentTarget];
139
- if (!currentHashKey) {
151
+ if (!checkFirmwareHash || !currentHashKey) {
140
152
  status = 'valid';
141
153
  } else {
142
154
  const currentHash = normalizeHex(currentVerification[currentHashKey]);
@@ -175,12 +187,14 @@ type ProtocolV2FirmwareReleasePlan = {
175
187
  export function buildProtocolV2FirmwareRelease({
176
188
  currentVersions,
177
189
  currentVerification = {},
190
+ checkFirmwareHash = false,
178
191
  remotePayloadHashes = {},
179
192
  firmwareType,
180
193
  release,
181
194
  }: {
182
195
  currentVersions: DeviceStateVersions;
183
196
  currentVerification?: Partial<DeviceFeaturesVerify>;
197
+ checkFirmwareHash?: boolean;
184
198
  remotePayloadHashes?: Readonly<Record<string, string | null>>;
185
199
  firmwareType: EFirmwareType;
186
200
  release: IFirmwareReleaseInfo | undefined;
@@ -204,6 +218,7 @@ export function buildProtocolV2FirmwareRelease({
204
218
  component,
205
219
  currentVersions,
206
220
  currentVerification,
221
+ checkFirmwareHash,
207
222
  remotePayloadHash: Object.prototype.hasOwnProperty.call(remotePayloadHashes, configKey)
208
223
  ? remotePayloadHashes[configKey]
209
224
  : normalizeHex(component.payloadHash),
@@ -230,9 +245,6 @@ export function buildProtocolV2FirmwareRelease({
230
245
  const targetsToUpdate = components.flatMap(component =>
231
246
  component.status === 'outdated' && component.updateTarget ? [component.updateTarget] : []
232
247
  );
233
- if (targetsToUpdate.length > 0 && release.resourceBundles?.length) {
234
- targetsToUpdate.push('resource');
235
- }
236
248
  const uniqueTargetsToUpdate = Array.from(new Set(targetsToUpdate));
237
249
  const hasUpgrade = uniqueTargetsToUpdate.length > 0;
238
250
  const required = release.required && hasUpgrade;
@@ -358,13 +370,17 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
358
370
  }
359
371
 
360
372
  private async runProtocolV2(): Promise<AllFirmwareRelease> {
373
+ const { checkFirmwareHash = false, firmwareType: firmwareTypeParam } = this
374
+ .payload as CheckAllFirmwareReleaseParams;
361
375
  const state = await this.device.getDeviceState({
362
- refreshSections: ['identity', 'versions', 'verification'],
376
+ refreshSections: checkFirmwareHash
377
+ ? ['identity', 'versions', 'verification']
378
+ : ['identity', 'versions'],
363
379
  });
364
- if (state.identity.deviceType !== 'pro2') {
380
+ if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
365
381
  throw ERRORS.TypedError(
366
382
  HardwareErrorCode.DeviceNotSupportMethod,
367
- 'checkAllFirmwareRelease requires a Pro2 device for Protocol V2'
383
+ 'checkAllFirmwareRelease requires a Pro2 or Neo device for Protocol V2'
368
384
  );
369
385
  }
370
386
 
@@ -376,16 +392,47 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
376
392
  );
377
393
  }
378
394
 
379
- const { firmwareType: firmwareTypeParam } = this.payload as CheckAllFirmwareReleaseParams;
380
395
  const firmwareType =
381
396
  firmwareTypeParam ?? state.identity.firmwareType ?? EFirmwareType.Universal;
382
397
  const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
383
398
  const plan = buildProtocolV2FirmwareRelease({
384
399
  currentVersions: state.versions,
385
- currentVerification: state.verification,
400
+ currentVerification: checkFirmwareHash ? state.verification : undefined,
401
+ checkFirmwareHash,
386
402
  firmwareType,
387
403
  release,
388
404
  });
405
+ const resourceDeviceType =
406
+ state.identity.deviceType === 'neo' ? EDeviceType.Neo : EDeviceType.Pro2;
407
+ const resources = DataManager.getProtocolV2Resources(resourceDeviceType);
408
+ let resourceStatus: 'valid' | 'outdated' | 'unknown' = 'unknown';
409
+ if (resources?.length) {
410
+ const loaderMode = state.status.mode === 'bootloader' || state.status.mode === 'romloader';
411
+ // Application mode rejects host access to vol0:/bundles. Resource inventory is
412
+ // resolved after FirmwareUpdateV4 enters a loader instead of probing here.
413
+ if (loaderMode) {
414
+ try {
415
+ const inventory = await readProtocolV2ResourceInventory({
416
+ commands: this.device.getCommands(),
417
+ resources,
418
+ });
419
+ resourceStatus = buildProtocolV2ResourceUpdatePlan({
420
+ resources,
421
+ inventory,
422
+ mode: 'bootloader-recovery',
423
+ }).status;
424
+ } catch {
425
+ resourceStatus = buildProtocolV2ResourceUpdatePlan({
426
+ resources,
427
+ mode: 'bootloader-recovery',
428
+ }).status;
429
+ }
430
+ }
431
+ }
432
+ const targetsToUpdate = [
433
+ ...plan.targetsToUpdate,
434
+ ...(resourceStatus === 'outdated' ? (['resource'] as const) : []),
435
+ ];
389
436
  const firmwareStatus = plan.status === 'unavailable' ? 'unknown' : plan.status;
390
437
  const emptyRelease = 'none' as const;
391
438
 
@@ -406,8 +453,11 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
406
453
  },
407
454
  features,
408
455
  protocol: 'V2',
409
- deviceType: 'pro2',
456
+ deviceType: state.identity.deviceType,
410
457
  ...plan,
458
+ resourceStatus,
459
+ hasUpgrade: plan.hasUpgrade || resourceStatus === 'outdated',
460
+ targetsToUpdate,
411
461
  };
412
462
  }
413
463
  }
@@ -0,0 +1,18 @@
1
+ import { BaseMethod } from './BaseMethod';
2
+
3
+ export default class DetectDeviceConnectProtocol extends BaseMethod {
4
+ init() {
5
+ this.payload.forceProtocolDetection = true;
6
+ this.useDevicePassphraseState = false;
7
+ this.skipForceUpdateCheck = true;
8
+ this.unlockPolicy = 'none';
9
+ }
10
+
11
+ getSupportedProtocols() {
12
+ return ['V1', 'V2'] as const;
13
+ }
14
+
15
+ run() {
16
+ return Promise.resolve(this.device.getProtocol());
17
+ }
18
+ }
@@ -96,7 +96,8 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
96
96
  await this.device.deviceConnector?.acquire(
97
97
  this.device.originalDescriptor.id,
98
98
  null,
99
- true
99
+ true,
100
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
100
101
  );
101
102
  // Bound each probe so a request the rebooting device never received
102
103
  // frees the slot for the next tick instead of hanging into the
@@ -115,7 +116,10 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
115
116
  } else {
116
117
  const deviceDiff = await this.device.deviceConnector?.enumerate();
117
118
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
118
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
119
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId, {
120
+ connectProtocol:
121
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
122
+ });
119
123
 
120
124
  if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
121
125
  // should update current device from cache
@@ -304,7 +304,8 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
304
304
  await this.device.deviceConnector?.acquire(
305
305
  this.device.originalDescriptor.id,
306
306
  null,
307
- true
307
+ true,
308
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
308
309
  );
309
310
  // Bound each probe so a request the rebooting device never received
310
311
  // frees the slot for the next tick instead of hanging into the
@@ -343,7 +344,9 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
343
344
  ) {
344
345
  const deviceDiff = await this.device.deviceConnector?.enumerate();
345
346
  const devicesDescriptor = deviceDiff?.descriptors ?? [];
346
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId);
347
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId, {
348
+ connectProtocol: this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
349
+ });
347
350
 
348
351
  if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
349
352
  // should update current device from cache
@@ -705,7 +705,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
705
705
  await this.device.deviceConnector?.acquire(
706
706
  this.device.originalDescriptor.id,
707
707
  null,
708
- true
708
+ true,
709
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
709
710
  );
710
711
  const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
711
712
  await Promise.race([
@@ -742,7 +743,10 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
742
743
  webUsbCheckCount = 0;
743
744
  }
744
745
 
745
- const { deviceList } = await DevicePool.getDevices(devicesDescriptor, this.connectId);
746
+ const { deviceList } = await DevicePool.getDevices(devicesDescriptor, this.connectId, {
747
+ connectProtocol:
748
+ this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
749
+ });
746
750
 
747
751
  if (deviceList.length === 1) {
748
752
  this.device.updateFromCache(deviceList[0]);