@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
@@ -11,22 +11,12 @@ export const UI_RESPONSE = {
11
11
  'ui-receive_select-device-for-switch-firmware-web-device',
12
12
  } as const;
13
13
 
14
- export interface UiResponseCorrelation {
15
- interactionId: string;
16
- deviceId: string;
17
- }
18
-
19
- export interface UiResponseCorrelationFields {
20
- interactionId?: string;
21
- deviceId?: string;
22
- }
23
-
24
- export interface UiResponsePin extends UiResponseCorrelationFields {
14
+ export interface UiResponsePin {
25
15
  type: typeof UI_RESPONSE.RECEIVE_PIN;
26
16
  payload: string;
27
17
  }
28
18
 
29
- export interface UiResponsePassphrase extends UiResponseCorrelationFields {
19
+ export interface UiResponsePassphrase {
30
20
  type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
31
21
  payload: {
32
22
  value: string;
package/src/index.ts CHANGED
@@ -19,6 +19,11 @@ export * from './types';
19
19
  export { whitelist, whitelistExtension } from './data/config';
20
20
  export { executeCallback, cleanupCallback };
21
21
  export { preloadSessionCache } from './device/Device';
22
+ export {
23
+ getFirmwareUpdateHostBindingGeneration,
24
+ registerFirmwareUpdateHostBinding,
25
+ unregisterFirmwareUpdateHostBinding,
26
+ } from './api/firmware/FirmwareHostBinding';
22
27
 
23
28
  const HardwareSdk = ({
24
29
  init,
package/src/inject.ts CHANGED
@@ -1,7 +1,17 @@
1
- import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
2
- import type { Unsuccessful } from './types';
1
+ import { getFirmwareUpdateCapabilities } from './api/firmware/FirmwareUpdateCapabilities';
2
+ import {
3
+ prepareFirmwareUpdatePlan,
4
+ validateFirmwareUpdatePreparedPlan,
5
+ } from './api/firmware/FirmwareUpdatePreparedPlan';
6
+ import {
7
+ getFirmwareUpdateHostBindingGeneration,
8
+ registerFirmwareUpdateHostBinding,
9
+ unregisterFirmwareUpdateHostBinding,
10
+ } from './api/firmware/FirmwareHostBinding';
11
+
3
12
  import type { EventEmitter } from 'events';
4
13
  import type { CallMethod } from './events';
14
+ import type { Unsuccessful } from './types';
5
15
  import type { CoreApi } from './types/api';
6
16
  import type { AllNetworkAddress } from './types/api/allNetworkGetAddress';
7
17
 
@@ -40,50 +50,6 @@ export interface InjectApi {
40
50
  switchTransport: CoreApi['switchTransport'];
41
51
  }
42
52
 
43
- const normalizeConnectId = (connectId: string) => connectId.trim().toLowerCase();
44
-
45
- /**
46
- * Keeps verified protocols isolated per transport endpoint and injects them at
47
- * the single public call boundary, including APIs that do not expose params.
48
- */
49
- export const createProtocolAwareCall = (rawCall: CoreApi['call']) => {
50
- const protocolByConnectId = new Map<string, HardwareConnectProtocol>();
51
-
52
- const setDeviceConnectProtocol: CoreApi['setDeviceConnectProtocol'] = (
53
- connectId,
54
- connectProtocol
55
- ) => {
56
- const normalizedConnectId = normalizeConnectId(connectId);
57
- if (!normalizedConnectId) return;
58
- if (connectProtocol) {
59
- protocolByConnectId.set(normalizedConnectId, connectProtocol);
60
- } else {
61
- protocolByConnectId.delete(normalizedConnectId);
62
- }
63
- };
64
-
65
- const call: CoreApi['call'] = params => {
66
- if (!params || typeof params !== 'object') {
67
- return rawCall(params);
68
- }
69
-
70
- const connectId = typeof params.connectId === 'string' ? params.connectId : undefined;
71
- const boundProtocol = connectId
72
- ? protocolByConnectId.get(normalizeConnectId(connectId))
73
- : undefined;
74
- if (
75
- boundProtocol &&
76
- params.connectProtocol === undefined &&
77
- params.forceProtocolDetection !== true
78
- ) {
79
- return rawCall({ ...params, connectProtocol: boundProtocol });
80
- }
81
- return rawCall(params);
82
- };
83
-
84
- return { call, setDeviceConnectProtocol };
85
- };
86
-
87
53
  export const inject = ({
88
54
  call,
89
55
  cancel,
@@ -94,7 +60,6 @@ export const inject = ({
94
60
  switchTransport,
95
61
  uiResponse,
96
62
  }: InjectApi): CoreApi => {
97
- const protocolAwareCall = createProtocolAwareCall(call);
98
63
  const api: CoreApi = {
99
64
  on: <T extends string, P extends (...args: any[]) => any>(type: T, fn: P) => {
100
65
  eventEmitter.on(type, fn);
@@ -112,11 +77,12 @@ export const inject = ({
112
77
 
113
78
  init,
114
79
 
115
- call: protocolAwareCall.call,
80
+ call,
116
81
 
117
- setDeviceConnectProtocol: protocolAwareCall.setDeviceConnectProtocol,
118
-
119
- dispose,
82
+ dispose: async () => {
83
+ unregisterFirmwareUpdateHostBinding();
84
+ await dispose();
85
+ },
120
86
 
121
87
  uiResponse,
122
88
 
@@ -126,7 +92,7 @@ export const inject = ({
126
92
 
127
93
  switchTransport,
128
94
 
129
- ...createCoreApi(protocolAwareCall.call),
95
+ ...createCoreApi(call),
130
96
  };
131
97
  return api;
132
98
  };
@@ -141,25 +107,24 @@ export const createCoreApi = (
141
107
  | 'removeAllListeners'
142
108
  | 'init'
143
109
  | 'call'
144
- | 'setDeviceConnectProtocol'
145
110
  | 'dispose'
146
111
  | 'uiResponse'
147
112
  | 'cancel'
148
113
  | 'updateSettings'
149
114
  | 'switchTransport'
150
115
  > => ({
116
+ getFirmwareUpdateCapabilities,
117
+ registerFirmwareUpdateHostBinding,
118
+ unregisterFirmwareUpdateHostBinding,
119
+ getFirmwareUpdateHostBindingGeneration,
120
+ prepareFirmwareUpdatePlan,
121
+ validateFirmwareUpdatePreparedPlan,
151
122
  getLogs: () => call({ method: 'getLogs' }),
152
123
  clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
153
124
  /**
154
125
  * 搜索设备
155
126
  */
156
127
  searchDevices: params => call({ ...params, method: 'searchDevices' }),
157
- detectDeviceConnectProtocol: connectId =>
158
- call({
159
- connectId,
160
- method: 'detectDeviceConnectProtocol',
161
- forceProtocolDetection: true,
162
- }),
163
128
 
164
129
  /**
165
130
  * 获取设备信息
@@ -217,7 +182,6 @@ export const createCoreApi = (
217
182
  call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
218
183
  deviceUploadWallpaper: (connectId, params) =>
219
184
  call({ ...params, connectId, method: 'deviceUploadWallpaper' }),
220
- deviceUploadNft: (connectId, params) => call({ ...params, connectId, method: 'deviceUploadNft' }),
221
185
  uploadPortfolio: (connectId, params) => call({ ...params, connectId, method: 'uploadPortfolio' }),
222
186
  deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
223
187
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
@@ -1,4 +1,5 @@
1
- import { createCoreApi, createProtocolAwareCall } from './inject';
1
+ import { createCoreApi } from './inject';
2
+ import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
2
3
 
3
4
  import type { EventEmitter } from 'events';
4
5
  import type { CallMethod, CoreMessage } from './events';
@@ -33,7 +34,6 @@ export const lowLevelInject = ({
33
34
  switchTransport,
34
35
  addHardwareGlobalEventListener,
35
36
  }: LowLevelInjectApi): LowLevelCoreApi => {
36
- const protocolAwareCall = createProtocolAwareCall(call);
37
37
  const api: LowLevelCoreApi = {
38
38
  addHardwareGlobalEventListener,
39
39
  removeAllListeners: type => {
@@ -42,11 +42,12 @@ export const lowLevelInject = ({
42
42
 
43
43
  init,
44
44
 
45
- call: protocolAwareCall.call,
45
+ call,
46
46
 
47
- setDeviceConnectProtocol: protocolAwareCall.setDeviceConnectProtocol,
48
-
49
- dispose,
47
+ dispose: async () => {
48
+ unregisterFirmwareUpdateHostBinding();
49
+ await dispose();
50
+ },
50
51
 
51
52
  uiResponse,
52
53
 
@@ -58,7 +59,7 @@ export const lowLevelInject = ({
58
59
 
59
60
  emit: () => {},
60
61
 
61
- ...createCoreApi(protocolAwareCall.call),
62
+ ...createCoreApi(call),
62
63
  };
63
64
  return api;
64
65
  };
@@ -107,6 +107,10 @@ export const PROTOCOL_V2_FEATURES_DEVICE_INFO_REQUEST = {
107
107
  hw: true,
108
108
  fw: true,
109
109
  coprocessor: true,
110
+ se1: true,
111
+ se2: true,
112
+ se3: true,
113
+ se4: true,
110
114
  },
111
115
  types: {
112
116
  version: true,
@@ -153,7 +157,7 @@ export const PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST = {
153
157
  };
154
158
 
155
159
  export const PROTOCOL_V2_DEVICE_INFO_REQUEST = PROTOCOL_V2_FULL_DEVICE_INFO_REQUEST;
156
- export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 30 * 1000;
160
+ export const PROTOCOL_V2_DEVICE_INFO_TIMEOUT_MS = 10 * 1000;
157
161
 
158
162
  export async function requestProtocolV2ProtocolInfo({
159
163
  commands,
@@ -164,15 +168,8 @@ export async function requestProtocolV2ProtocolInfo({
164
168
  }): Promise<ProtocolInfo> {
165
169
  const response =
166
170
  timeoutMs === undefined
167
- ? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
168
- eventless_wallet_session: true,
169
- })
170
- : await commands.typedCall(
171
- 'ProtocolInfoRequest',
172
- 'ProtocolInfo',
173
- { eventless_wallet_session: true },
174
- { timeoutMs }
175
- );
171
+ ? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {})
172
+ : await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {}, { timeoutMs });
176
173
  return response.message;
177
174
  }
178
175
 
@@ -15,7 +15,5 @@ export const ProtocolV2FirmwareTargetType = {
15
15
  FW_MGMT_TARGET_SE04: 10,
16
16
  } as const;
17
17
 
18
- // 这里有意同时导出同名值与类型,以保持现有公共 API 不变。
19
- // eslint-disable-next-line @typescript-eslint/no-redeclare
20
18
  export type ProtocolV2FirmwareTargetType =
21
19
  (typeof ProtocolV2FirmwareTargetType)[keyof typeof ProtocolV2FirmwareTargetType];
@@ -0,0 +1,10 @@
1
+ import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+
3
+ export function isDeviceLockedError(error: unknown): boolean {
4
+ return (
5
+ typeof error === 'object' &&
6
+ error !== null &&
7
+ 'errorCode' in error &&
8
+ error.errorCode === HardwareErrorCode.DeviceLocked
9
+ );
10
+ }
@@ -1,6 +1,6 @@
1
1
  import { UI_REQUEST, createUiMessage } from '../../events';
2
2
 
3
- import type { CoreMessage, HardwareUiInteractionMeta, ProtocolV2UiCompletion } from '../../events';
3
+ import type { CoreMessage, ProtocolV2UiCompletion } from '../../events';
4
4
  import type { Device } from '../../device/Device';
5
5
  import type { KnownDevice } from '../../types';
6
6
 
@@ -28,15 +28,7 @@ type ProtocolV2InteractionMethod = {
28
28
  protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
29
29
  };
30
30
 
31
- type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'> &
32
- Partial<
33
- Pick<
34
- Device,
35
- | 'createProtocolV2UiPhaseMetadata'
36
- | 'finishProtocolV2UiInteraction'
37
- | 'hasOpenProtocolV2UiInteraction'
38
- >
39
- >;
31
+ type InteractionDevice = Pick<Device, 'isProtocolV2' | 'toMessageObject'>;
40
32
  type PostMessage = (message: CoreMessage) => void;
41
33
 
42
34
  export const isProtocolV2UiEnabled = (method: { protocolV2UiMode?: 'auto' | 'none' }) =>
@@ -164,17 +156,12 @@ export class ProtocolV2UiInteractionCoordinator {
164
156
  this.methodInteraction = interaction;
165
157
  if (!interaction) return;
166
158
  const { request, ...metadata } = interaction;
167
- const interactionMeta = this.device.createProtocolV2UiPhaseMetadata?.(
168
- request === 'pin' ? 'pin' : 'button',
169
- 'start'
170
- );
171
159
 
172
160
  this.emit(
173
161
  request === 'pin' ? UI_REQUEST.REQUEST_PIN : UI_REQUEST.REQUEST_BUTTON,
174
162
  {
175
163
  device: this.device.toMessageObject() as KnownDevice,
176
164
  ...metadata,
177
- ...(interactionMeta ? { interaction: interactionMeta } : {}),
178
165
  },
179
166
  `method:${request}:${interaction.reason}:${interaction.page ?? ''}:${
180
167
  interaction.operation ?? ''
@@ -182,8 +169,7 @@ export class ProtocolV2UiInteractionCoordinator {
182
169
  );
183
170
  }
184
171
 
185
- enterUnlockInteraction(method?: string): HardwareUiInteractionMeta | undefined {
186
- const interaction = this.device.createProtocolV2UiPhaseMetadata?.('pin', 'start');
172
+ enterUnlockInteraction(method?: string) {
187
173
  this.emit(
188
174
  UI_REQUEST.REQUEST_PIN,
189
175
  {
@@ -192,45 +178,19 @@ export class ProtocolV2UiInteractionCoordinator {
192
178
  reason: 'device-locked',
193
179
  deviceOnly: true,
194
180
  method,
195
- ...(interaction ? { interaction } : {}),
196
181
  },
197
182
  `unlock:${method ?? ''}`
198
183
  );
199
- return interaction;
200
184
  }
201
185
 
202
186
  resumeMethodInteraction() {
203
187
  this.enterMethodInteraction(this.methodInteraction);
204
188
  }
205
189
 
206
- close(
207
- options: {
208
- ensureOperationClose?: boolean;
209
- protocolV2Operation?: boolean;
210
- } = {}
211
- ): boolean {
212
- if (
213
- (!options.protocolV2Operation && !this.device.isProtocolV2()) ||
214
- (!options.ensureOperationClose &&
215
- !this.opened &&
216
- !this.device.hasOpenProtocolV2UiInteraction?.()) ||
217
- this.closed
218
- )
219
- return false;
190
+ close() {
191
+ if (!this.device.isProtocolV2() || !this.opened || this.closed) return;
220
192
  this.closed = true;
221
- const interaction = this.device.finishProtocolV2UiInteraction?.('succeeded', {
222
- ensureMetadata: options.ensureOperationClose,
223
- });
224
- const device = this.device.toMessageObject();
225
- this.postMessage(
226
- interaction
227
- ? createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW, {
228
- ...interaction,
229
- ...(device ? { device } : {}),
230
- })
231
- : createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW)
232
- );
233
- return true;
193
+ this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
234
194
  }
235
195
 
236
196
  private emit(
@@ -1 +1,105 @@
1
- export type UnlockPolicy = 'none' | 'unlock-before-run';
1
+ export type UnlockPolicy = 'none' | 'unlock-before-run' | 'retry-on-locked';
2
+
3
+ /**
4
+ * Protocol V2 methods that are safe to replay after a locked response.
5
+ *
6
+ * Keep this as an exact allowlist. Name-pattern matching can silently make a new
7
+ * state-changing method replayable when it happens to share a suffix.
8
+ */
9
+ export const PROTOCOL_V2_RETRY_ON_LOCKED_METHODS = [
10
+ 'cipherKeyValue',
11
+ 'allNetworkGetAddress',
12
+ 'allNetworkGetAddressByLoop',
13
+ 'btcGetAddress',
14
+ 'btcGetPublicKey',
15
+ 'btcSignMessage',
16
+ 'btcSignPsbt',
17
+ 'btcSignTransaction',
18
+ 'btcVerifyMessage',
19
+ 'confluxGetAddress',
20
+ 'confluxSignMessage',
21
+ 'confluxSignTransaction',
22
+ 'evmGetAddress',
23
+ 'evmGetPublicKey',
24
+ 'evmSignMessage',
25
+ 'evmSignTransaction',
26
+ 'evmSignTypedData',
27
+ 'evmVerifyMessage',
28
+ 'starcoinGetAddress',
29
+ 'starcoinGetPublicKey',
30
+ 'starcoinSignMessage',
31
+ 'starcoinSignTransaction',
32
+ 'starcoinVerifyMessage',
33
+ 'nemGetAddress',
34
+ 'nemSignTransaction',
35
+ 'solGetAddress',
36
+ 'solSignTransaction',
37
+ 'solSignOffchainMessage',
38
+ 'solSignMessage',
39
+ 'stellarGetAddress',
40
+ 'stellarSignTransaction',
41
+ 'tronGetAddress',
42
+ 'tronSignMessage',
43
+ 'tronSignTransaction',
44
+ 'nearGetAddress',
45
+ 'nearSignTransaction',
46
+ 'aptosGetAddress',
47
+ 'aptosGetPublicKey',
48
+ 'aptosSignTransaction',
49
+ 'aptosSignMessage',
50
+ 'aptosSignInMessage',
51
+ 'algoGetAddress',
52
+ 'algoSignTransaction',
53
+ 'cosmosGetAddress',
54
+ 'cosmosGetPublicKey',
55
+ 'cosmosSignTransaction',
56
+ 'xrpGetAddress',
57
+ 'xrpSignTransaction',
58
+ 'suiGetAddress',
59
+ 'suiGetPublicKey',
60
+ 'suiSignMessage',
61
+ 'suiSignTransaction',
62
+ 'cardanoGetAddress',
63
+ 'cardanoGetPublicKey',
64
+ 'cardanoSignTransaction',
65
+ 'cardanoSignMessage',
66
+ 'filecoinGetAddress',
67
+ 'filecoinSignTransaction',
68
+ 'polkadotGetAddress',
69
+ 'polkadotSignTransaction',
70
+ 'kaspaGetAddress',
71
+ 'kaspaSignTransaction',
72
+ 'nexaGetAddress',
73
+ 'nexaSignTransaction',
74
+ 'nostrGetPublicKey',
75
+ 'nostrSignEvent',
76
+ 'nostrEncryptMessage',
77
+ 'nostrDecryptMessage',
78
+ 'nostrSignSchnorr',
79
+ 'lnurlAuth',
80
+ 'nervosGetAddress',
81
+ 'nervosSignTransaction',
82
+ 'dnxGetAddress',
83
+ 'dnxSignTransaction',
84
+ 'tonGetAddress',
85
+ 'tonSignMessage',
86
+ 'tonSignProof',
87
+ 'tonSignData',
88
+ 'scdoGetAddress',
89
+ 'scdoSignTransaction',
90
+ 'scdoSignMessage',
91
+ 'alephiumGetAddress',
92
+ 'alephiumSignTransaction',
93
+ 'alephiumSignMessage',
94
+ 'benfenGetAddress',
95
+ 'benfenGetPublicKey',
96
+ 'benfenSignMessage',
97
+ 'benfenSignTransaction',
98
+ 'neoGetAddress',
99
+ 'neoSignTransaction',
100
+ ] as const;
101
+
102
+ const retryOnLockedMethods = new Set<string>(PROTOCOL_V2_RETRY_ON_LOCKED_METHODS);
103
+
104
+ export const getProtocolV2UnlockPolicy = (methodName: string): UnlockPolicy =>
105
+ retryOnLockedMethods.has(methodName) ? 'retry-on-locked' : 'none';
@@ -0,0 +1,109 @@
1
+ import { LoggerNames, getLogger } from '../../utils';
2
+ import { isDeviceLockedError } from './lockedError';
3
+ import { isProtocolV2UiEnabled, resolveProtocolV2UiInteraction } from './uiInteraction';
4
+ import { refreshProtocolV2DeviceStatus, restoreProtocolV2WalletSession } from './walletSession';
5
+
6
+ import type { BaseMethod } from '../../api/BaseMethod';
7
+ import type { Device } from '../../device/Device';
8
+ import type { ProtocolV2UiInteractionCoordinator } from './uiInteraction';
9
+
10
+ const Log = getLogger(LoggerNames.Core);
11
+
12
+ type RunnableMethod = Pick<
13
+ BaseMethod,
14
+ | 'run'
15
+ | 'unlockPolicy'
16
+ | 'protocolV2UiInteraction'
17
+ | 'protocolV2UiMode'
18
+ | 'params'
19
+ | 'payload'
20
+ | 'useDevicePassphraseState'
21
+ > & { name?: string };
22
+ type UiInteractionCoordinator = Pick<
23
+ ProtocolV2UiInteractionCoordinator,
24
+ 'enterMethodInteraction' | 'enterUnlockInteraction' | 'resumeMethodInteraction'
25
+ >;
26
+
27
+ const restoreExpectedWalletSessionAfterUnlock = async (method: RunnableMethod, device: Device) => {
28
+ const expectedPassphraseState = method.payload?.useEmptyPassphrase
29
+ ? undefined
30
+ : method.payload?.passphraseState ?? device.passphraseState;
31
+ if (
32
+ !method.useDevicePassphraseState ||
33
+ typeof expectedPassphraseState !== 'string' ||
34
+ expectedPassphraseState.length === 0
35
+ ) {
36
+ return;
37
+ }
38
+
39
+ await restoreProtocolV2WalletSession(device, expectedPassphraseState);
40
+ Log.debug('Protocol V2 wallet session restored after unlock', { method: method.name });
41
+ };
42
+
43
+ export async function runMethodWithUnlockRetry(
44
+ method: RunnableMethod,
45
+ device: Device,
46
+ uiCoordinator?: UiInteractionCoordinator
47
+ ) {
48
+ const shouldEmitUi = isProtocolV2UiEnabled(method);
49
+ const isProtocolV2 = device.isProtocolV2();
50
+ const requiresFreshStatus =
51
+ isProtocolV2 &&
52
+ method.unlockPolicy === 'unlock-before-run' &&
53
+ !device.isBootloader?.() &&
54
+ !device.isRomloader?.();
55
+
56
+ if (requiresFreshStatus) {
57
+ await refreshProtocolV2DeviceStatus(device);
58
+ }
59
+
60
+ const shouldUnlockBeforeRun =
61
+ isProtocolV2 &&
62
+ method.unlockPolicy !== 'none' &&
63
+ !device.isBootloader?.() &&
64
+ !device.isRomloader?.() &&
65
+ device.features?.unlocked === false;
66
+
67
+ if (shouldUnlockBeforeRun) {
68
+ if (shouldEmitUi) {
69
+ uiCoordinator?.enterUnlockInteraction(method.name);
70
+ }
71
+ await device.unlockDevice();
72
+ Log.debug('Protocol V2 pre-unlock completed', { method: method.name });
73
+ await restoreExpectedWalletSessionAfterUnlock(method, device);
74
+ if (shouldEmitUi) {
75
+ uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
76
+ }
77
+ return method.run();
78
+ }
79
+
80
+ if (shouldEmitUi) {
81
+ uiCoordinator?.enterMethodInteraction(resolveProtocolV2UiInteraction(method));
82
+ }
83
+ try {
84
+ return await method.run();
85
+ } catch (error) {
86
+ if (!isProtocolV2 || method.unlockPolicy !== 'retry-on-locked' || !isDeviceLockedError(error)) {
87
+ throw error;
88
+ }
89
+
90
+ Log.debug('Protocol V2 unlock retry triggered', { method: method.name });
91
+ if (shouldEmitUi) {
92
+ uiCoordinator?.enterUnlockInteraction(method.name);
93
+ }
94
+ await device.unlockDevice();
95
+ Log.debug('Protocol V2 unlock completed', { method: method.name });
96
+ await restoreExpectedWalletSessionAfterUnlock(method, device);
97
+ if (shouldEmitUi) {
98
+ uiCoordinator?.resumeMethodInteraction();
99
+ }
100
+ try {
101
+ const response = await method.run();
102
+ Log.debug('Protocol V2 method retry completed', { method: method.name, success: true });
103
+ return response;
104
+ } catch (retryError) {
105
+ Log.debug('Protocol V2 method retry completed', { method: method.name, success: false });
106
+ throw retryError;
107
+ }
108
+ }
109
+ }