@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
@@ -1,5 +1,4 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
- import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
3
2
 
4
3
  import { UI_REQUEST } from '../constants/ui-request';
5
4
  import { refreshProtocolV2DeviceStatus } from '../protocols/protocol-v2/walletSession';
@@ -25,12 +24,7 @@ export default class GetPassphraseState extends BaseMethod {
25
24
  if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
26
25
  const features = await refreshProtocolV2DeviceStatus(this.device);
27
26
  if (features.unlocked === false) {
28
- await this.device.unlockDevice(DeviceSessionPinType.Main, {
29
- source: 'unlock-coordinator',
30
- reason: 'device-locked',
31
- deviceOnly: true,
32
- method: 'getPassphraseState',
33
- });
27
+ await this.device.unlockDevice();
34
28
  }
35
29
  }
36
30
  const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
@@ -1,5 +1,4 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
- import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
3
2
 
4
3
  import { deviceWalletSessionStore } from '../device/DeviceWalletSessionStore';
5
4
  import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
@@ -91,40 +90,23 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
91
90
 
92
91
  async run(): Promise<OpenWalletSessionPayload> {
93
92
  const isProtocolV2 = this.device.isProtocolV2();
94
- let state = await this.device.getDeviceState({ refreshSections: ['status'] });
93
+ const state = await this.device.getDeviceState({ refreshSections: ['status'] });
95
94
  let currentDeviceId = state.identity.deviceId;
96
- const hasAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) =>
97
- candidate.status.unlocked === true &&
98
- typeof candidate.status.passphraseProtection === 'boolean' &&
99
- typeof candidate.status.unlockedAttachPin === 'boolean';
100
- const requireAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) => {
101
- if (!hasAuthoritativeProtocolV2WalletStatus(candidate)) {
102
- throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
103
- }
104
- return candidate;
105
- };
106
95
  const requireDeviceId = () => {
107
96
  if (!currentDeviceId) {
108
97
  throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
109
98
  }
110
99
  return currentDeviceId;
111
100
  };
112
- const refreshProtocolV2DeviceState = async () => {
113
- state = await this.device.getDeviceState({ refreshSections: ['status'] });
114
- currentDeviceId = state.identity.deviceId;
115
- return state;
101
+ const refreshProtocolV2DeviceId = async () => {
102
+ const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
103
+ currentDeviceId = refreshedState.identity.deviceId;
104
+ return requireDeviceId();
116
105
  };
117
- const ensureProtocolV2WalletStatus = async () => {
118
- if (isProtocolV2 && !hasAuthoritativeProtocolV2WalletStatus(state)) {
119
- await this.device.unlockDevice(DeviceSessionPinType.Main, {
120
- source: 'unlock-coordinator',
121
- reason: 'device-locked',
122
- deviceOnly: true,
123
- method: 'openWalletSession',
124
- });
125
- requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState());
106
+ const unlockProtocolV2IfLocked = async () => {
107
+ if (isProtocolV2 && state.status.unlocked === false) {
108
+ await this.device.unlockDevice();
126
109
  }
127
- return state;
128
110
  };
129
111
 
130
112
  const protocol = isProtocolV2 ? 'V2' : 'V1';
@@ -132,25 +114,13 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
132
114
  if (this.params.mode === OpenWalletSessionMode.Standard) {
133
115
  this.device.passphraseState = undefined;
134
116
  const session = isProtocolV2
135
- ? await getProtocolV2WalletSession(this.device, {
136
- onlyMainPin: true,
137
- deriveCardano: this.payload.deriveCardano,
138
- selectMainWalletBeforeRestore:
139
- !hasAuthoritativeProtocolV2WalletStatus(state) ||
140
- state.status.unlockedAttachPin === true,
141
- })
117
+ ? await getProtocolV2WalletSession(this.device, { onlyMainPin: true })
142
118
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, {
143
119
  onlyMainPin: true,
144
120
  initSession: this.payload.initSession,
145
121
  });
146
- const refreshedState = isProtocolV2
147
- ? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
148
- : state;
149
- const deviceId = requireDeviceId();
150
- if (
151
- session.unlockedAttachPin ||
152
- (isProtocolV2 && refreshedState.status.unlockedAttachPin === true)
153
- ) {
122
+ const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
123
+ if (session.unlockedAttachPin) {
154
124
  try {
155
125
  await this.device.lockDevice();
156
126
  } catch {
@@ -170,8 +140,8 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
170
140
 
171
141
  if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
172
142
  if (isProtocolV2) {
173
- await ensureProtocolV2WalletStatus();
174
- const refreshedDeviceId = requireDeviceId();
143
+ await unlockProtocolV2IfLocked();
144
+ const refreshedDeviceId = await refreshProtocolV2DeviceId();
175
145
  if (refreshedDeviceId !== this.params.deviceId) {
176
146
  deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
177
147
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
@@ -196,7 +166,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
196
166
  const session = isProtocolV2
197
167
  ? await getProtocolV2WalletSession(this.device, {
198
168
  expectedPassphraseState: this.params.passphraseState,
199
- deriveCardano: this.payload.deriveCardano,
200
169
  })
201
170
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, {
202
171
  expectPassphraseState: this.params.passphraseState,
@@ -216,37 +185,15 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
216
185
  }
217
186
 
218
187
  this.device.passphraseState = undefined;
219
- const walletStatus = await ensureProtocolV2WalletStatus();
220
- if (isProtocolV2 && walletStatus.status.passphraseProtection !== true) {
221
- this.device.clearInternalState();
222
- throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
223
- }
224
- const readCurrentAttachPinSession =
225
- isProtocolV2 && walletStatus.status.unlockedAttachPin === true;
188
+ await unlockProtocolV2IfLocked();
226
189
  const session = isProtocolV2
227
- ? await getProtocolV2WalletSession(this.device, {
228
- ...(readCurrentAttachPinSession
229
- ? { readCurrentAttachPinSession: true }
230
- : { forceWalletSelection: true }),
231
- deriveCardano: this.payload.deriveCardano,
232
- })
190
+ ? await getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
233
191
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
234
- const refreshedState = isProtocolV2
235
- ? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
236
- : state;
237
- const deviceId = requireDeviceId();
238
- if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
192
+ const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
193
+ if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
239
194
  this.device.clearInternalState();
240
195
  throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
241
196
  }
242
- if (
243
- isProtocolV2 &&
244
- readCurrentAttachPinSession &&
245
- refreshedState.status.unlockedAttachPin !== true
246
- ) {
247
- this.device.clearInternalState();
248
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
249
- }
250
197
  const responseBase = {
251
198
  protocol,
252
199
  deviceId,
@@ -59,9 +59,7 @@ export default class SearchDevices extends BaseMethod {
59
59
  // Discovery is best effort. Browsers may retain WebUSB grants for devices that
60
60
  // are offline, busy, or not ready, so one descriptor must not abort the scan.
61
61
  const result = await DevicePool.getDevices([descriptor], descriptor.path, {
62
- // Discovery must actively identify the protocol instead of trusting a caller hint.
63
- connectProtocol: undefined,
64
- forceProtocolDetection: true,
62
+ connectProtocol: this.payload.connectProtocol,
65
63
  refreshRuntimeState: true,
66
64
  });
67
65
  deviceList.push(...result.deviceList);
@@ -24,28 +24,24 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
24
24
  const resultMap: Record<string, AllNetworkAddress> = {};
25
25
  const { bundle } = this.payload as AllNetworkGetAddressParams;
26
26
 
27
- const methodParams = bundle.map((param, index) =>
28
- this.generateMethodName({
29
- network: param.network,
30
- payload: param,
31
- originalIndex: index,
32
- })
33
- );
34
- const groupedMethodParams = methodParams.reduce((groups, param) => {
35
- const group = groups.get(param.methodName) ?? [];
36
- group.push(param);
37
- groups.set(param.methodName, group);
38
- return groups;
39
- }, new Map<keyof CoreApi, MethodParams[]>());
40
- const requiresProtocolV2WalletHandoff =
41
- this.device.isProtocolV2() &&
42
- (this.payload.useEmptyPassphrase === true || !!this.payload.passphraseState);
43
- const methodGroups: [keyof CoreApi, MethodParams[]][] = requiresProtocolV2WalletHandoff
44
- ? methodParams.map(param => [param.methodName, [param]])
45
- : Array.from(groupedMethodParams.entries());
27
+ const methodGroups = bundle
28
+ .map((param, index) =>
29
+ this.generateMethodName({
30
+ network: param.network,
31
+ payload: param,
32
+ originalIndex: index,
33
+ })
34
+ )
35
+ .reduce((acc, cur) => {
36
+ if (!acc[cur.methodName]) {
37
+ acc[cur.methodName] = [];
38
+ }
39
+ acc[cur.methodName].push(cur);
40
+ return acc;
41
+ }, {} as Record<keyof CoreApi, MethodParams[]>);
46
42
 
47
43
  let i = 0;
48
- for (const [methodName, params] of methodGroups) {
44
+ for (const [methodName, params] of Object.entries(methodGroups)) {
49
45
  const methodParams = {
50
46
  bundle: params.map(param => ({
51
47
  ...param.params,
@@ -56,7 +52,11 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
56
52
  throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
57
53
  }
58
54
  // call method
59
- const response = await this.callMethod(methodName, methodParams, rootFingerprint);
55
+ const response = await this.callMethod(
56
+ methodName as keyof CoreApi,
57
+ methodParams,
58
+ rootFingerprint
59
+ );
60
60
 
61
61
  if (this.abortController?.signal.aborted) {
62
62
  throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
@@ -14,7 +14,6 @@ import { findMethod } from '../utils';
14
14
  import { DEVICE, IFRAME, createUiMessage } from '../../events';
15
15
  import { UI_REQUEST } from '../../constants/ui-request';
16
16
  import { onDeviceButtonHandler } from '../../core';
17
- import { runMethodWithUnlockPolicy } from '../../protocols/protocol-v2/unlockPolicyRunner';
18
17
  import {
19
18
  completeRequestContext,
20
19
  createRequestContext,
@@ -376,36 +375,16 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
376
375
  this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
377
376
 
378
377
  preCheckDeviceSupport(this.device, method);
379
- const response = await runMethodWithUnlockPolicy<any[]>(method, this.device, {
380
- context: this.protocolV2UnlockContext,
381
- prepare: async () => {
382
- if (this.temporarySafetyCheckPrompted) {
383
- method.temporarySafetyCheckPrompted = true;
384
- } else {
385
- const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
386
- if (appliedTemporarySafetyCheck) {
387
- this.temporarySafetyCheckPrompted = true;
388
- }
389
- }
390
-
391
- // Protocol V2 hands a wallet session to exactly one blockchain request.
392
- // The parent all-network call consumes its first handoff while fetching
393
- // the root fingerprint, so each nested chain method must resume the
394
- // requested standard or hidden wallet before sending its device command.
395
- const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
396
- const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
397
- if (this.device.isProtocolV2() && shouldResumeWalletSession) {
398
- const passphraseStateSafety = await this.device.checkPassphraseStateSafety(
399
- this.payload.passphraseState,
400
- useEmptyPassphrase,
401
- this.payload.skipPassphraseCheck
402
- );
403
- if (!passphraseStateSafety) {
404
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
405
- }
406
- }
407
- },
408
- });
378
+ if (this.temporarySafetyCheckPrompted) {
379
+ method.temporarySafetyCheckPrompted = true;
380
+ } else {
381
+ const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
382
+ if (appliedTemporarySafetyCheck) {
383
+ this.temporarySafetyCheckPrompted = true;
384
+ }
385
+ }
386
+
387
+ const response = await method.run();
409
388
 
410
389
  if (!Array.isArray(response) || response.length === 0) {
411
390
  throw new Error('No response');
@@ -460,9 +439,7 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
460
439
  show_display: false,
461
440
  });
462
441
 
463
- if (!this.device.isProtocolV2()) {
464
- this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
465
- }
442
+ this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
466
443
 
467
444
  if (res.message.root_fingerprint == null) {
468
445
  throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
@@ -1,18 +1,13 @@
1
- import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
-
3
1
  import { BaseMethod } from '../BaseMethod';
4
2
 
5
- import type { DeviceUnlockParams } from '../../types/api/deviceUnlock';
3
+ import type { LockDevice } from '@onekeyfe/hd-transport';
6
4
 
7
- export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
5
+ export default class DeviceUnlock extends BaseMethod<LockDevice> {
8
6
  getSupportedProtocols() {
9
7
  return ['V1', 'V2'] as const;
10
8
  }
11
9
 
12
10
  init() {
13
- this.params = {
14
- pinType: this.payload.pinType ?? DeviceSessionPinType.Main,
15
- };
16
11
  this.useDevicePassphraseState = false;
17
12
  this.unlockPolicy = 'none';
18
13
  this.protocolV2UiInteraction = {
@@ -26,6 +21,6 @@ export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
26
21
  }
27
22
 
28
23
  async run() {
29
- return this.device.unlockDevice(this.params.pinType, { emitUiEvent: false });
24
+ return this.device.unlockDevice();
30
25
  }
31
26
  }
@@ -5,15 +5,23 @@ import { UI_REQUEST } from '../../constants/ui-request';
5
5
  import { FirmwareUpdateTipMessage } from '../../events/ui-request';
6
6
  import { FirmwareUpdateBaseMethod } from '../firmware/FirmwareUpdateBaseMethod';
7
7
  import { getSysResourceBinary } from '../firmware/getBinary';
8
- import { updateBootloader } from '../firmware/uploadFirmware';
8
+ import { updateBootloader, updateBootloaderFromSource } from '../firmware/uploadFirmware';
9
9
  import { DeviceModelToTypes } from '../../types';
10
10
  import { DataManager } from '../../data-manager';
11
- import { checkBootloaderLength } from '../firmware/updateBootloader';
11
+ import { checkBootloaderLength, checkBootloaderSourceLength } from '../firmware/updateBootloader';
12
+ import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
13
+ import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
14
+ import {
15
+ assertFirmwareUpdatePreparedPlanBinding,
16
+ assertFirmwareUpdatePreparedPlanDeviceIdentity,
17
+ } from '../firmware/FirmwareUpdatePreparedPlan';
18
+ import { getDeviceUUID } from '../../utils';
12
19
 
13
20
  import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
14
21
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
15
22
  import type { Device } from '../../device/Device';
16
23
  import type { Features } from '../../types';
24
+ import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
17
25
 
18
26
  export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
19
27
  init() {
@@ -43,17 +51,68 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
43
51
  return true;
44
52
  }
45
53
 
54
+ async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
55
+ const filePath = '0:boot/bootloader.bin';
56
+
57
+ this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
58
+ await this.emmcCommonUpdateProcessFromSource({
59
+ source,
60
+ filePath,
61
+ });
62
+ this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
63
+ await this.reboot(RebootType.Normal);
64
+ this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
65
+ return true;
66
+ }
67
+
46
68
  async updateTouchBootloader({
47
69
  device,
48
70
  features,
49
71
  firmwareType,
72
+ binary: preparedBinary,
73
+ source: preparedSource,
50
74
  }: {
51
75
  device: Device;
52
76
  features?: Features;
53
77
  firmwareType: EFirmwareType;
78
+ binary?: ArrayBuffer;
79
+ source?: FirmwareByteSource;
54
80
  }) {
55
- let { binary } = this.payload;
81
+ if (preparedSource) {
82
+ if (!(await checkBootloaderSourceLength(preparedSource))) {
83
+ throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
84
+ }
85
+ if (features && device.isBootloader()) {
86
+ this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
87
+ const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
88
+ device,
89
+ preparedSource
90
+ );
91
+ return result;
92
+ }
93
+ if (features && !device.isBootloader()) {
94
+ await updateBootloaderFromSource(
95
+ this.device.getCommands().typedCall.bind(this.device.getCommands()),
96
+ this.postMessage,
97
+ device,
98
+ preparedSource
99
+ );
100
+ return true;
101
+ }
102
+ }
103
+
104
+ let binary = preparedBinary;
56
105
  if (!binary) {
106
+ if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
107
+ throw ERRORS.TypedError(
108
+ HardwareErrorCode.RuntimeError,
109
+ 'Bootloader must be prepared by the external firmware host',
110
+ {
111
+ firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
112
+ artifactName: 'bootloader',
113
+ }
114
+ );
115
+ }
57
116
  this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
58
117
  const resourceUrl = features
59
118
  ? DataManager.getBootloaderResource(features, firmwareType)
@@ -68,7 +127,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
68
127
  }
69
128
  }
70
129
 
71
- if (!checkBootloaderLength(binary)) {
130
+ if (!binary || !checkBootloaderLength(binary)) {
72
131
  throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
73
132
  }
74
133
 
@@ -76,7 +135,8 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
76
135
  if (features && device.isBootloader()) {
77
136
  // Use emmcFileWrite + reboot logic for bootloader mode
78
137
  this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
79
- return this.updateBootloaderWithEmmcFileWrite(device, binary);
138
+ const result = await this.updateBootloaderWithEmmcFileWrite(device, binary);
139
+ return result;
80
140
  }
81
141
 
82
142
  if (features && !device.isBootloader()) {
@@ -96,13 +156,69 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
96
156
  const { features } = device;
97
157
 
98
158
  const payload = this.payload as DeviceUpdateBootloaderParams;
159
+ const hostBinding = payload.artifact
160
+ ? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
161
+ : undefined;
162
+ const executionParams = {
163
+ ...payload,
164
+ artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
165
+ };
166
+ if (payload.artifact) {
167
+ assertFirmwareUpdatePreparedPlanDeviceIdentity({
168
+ preparedPlan: payload.preparedPlan,
169
+ deviceIdentity: getDeviceUUID(features) || undefined,
170
+ });
171
+ assertFirmwareUpdatePreparedPlanBinding({
172
+ preparedPlan: payload.preparedPlan,
173
+ executor: 'v2',
174
+ scopeTargets: ['bootloader'],
175
+ bindings: [
176
+ {
177
+ target: 'bootloader',
178
+ artifact: payload.artifact,
179
+ },
180
+ ],
181
+ });
182
+ const source = await openFirmwareByteSource({
183
+ artifact: payload.artifact,
184
+ reader: executionParams.artifactReader,
185
+ });
186
+ if (!source) {
187
+ throw ERRORS.TypedError(
188
+ HardwareErrorCode.RuntimeError,
189
+ 'Bootloader artifact is not prepared'
190
+ );
191
+ }
192
+ try {
193
+ const deviceType = device.getCurrentDeviceType();
194
+ const deviceFirmwareType = device.getCurrentFirmwareType();
195
+ const firmwareType = payload.firmwareType ?? deviceFirmwareType;
196
+ if (DeviceModelToTypes.model_touch.includes(deviceType)) {
197
+ return await this.updateTouchBootloader({
198
+ device,
199
+ features,
200
+ firmwareType,
201
+ source,
202
+ });
203
+ }
204
+ return true;
205
+ } finally {
206
+ await source.close();
207
+ }
208
+ }
99
209
 
210
+ const { binary } = payload;
100
211
  const deviceType = device.getCurrentDeviceType();
101
212
  const deviceFirmwareType = device.getCurrentFirmwareType();
102
213
  const firmwareType = payload.firmwareType ?? deviceFirmwareType;
103
214
 
104
215
  if (DeviceModelToTypes.model_touch.includes(deviceType)) {
105
- return this.updateTouchBootloader({ device, features, firmwareType });
216
+ return this.updateTouchBootloader({
217
+ device,
218
+ features,
219
+ firmwareType,
220
+ binary,
221
+ });
106
222
  }
107
223
 
108
224
  return Promise.resolve(true);