@onekeyfe/hd-core 1.2.0-alpha.53 → 1.2.0-alpha.54

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 (251) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -78
  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__/firmware-update/check-all-firmware-release.test.ts +175 -0
  9. package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
  10. package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
  11. package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
  12. package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
  13. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
  14. package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +294 -0
  15. package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
  16. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
  17. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
  18. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
  19. package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
  20. package/__tests__/get-device-state.test.ts +12 -132
  21. package/__tests__/homescreen.test.ts +1 -41
  22. package/__tests__/logBlockEvent.test.ts +1 -1
  23. package/__tests__/method-protocol-support.test.ts +0 -19
  24. package/__tests__/open-wallet-session.test.ts +33 -446
  25. package/__tests__/protocol-v2-unlock-policy.test.ts +35 -201
  26. package/__tests__/protocol-v2.test.ts +1034 -1378
  27. package/__tests__/protocolV2UiInteraction.test.ts +0 -63
  28. package/__tests__/public-pro2-api-boundary.test.ts +0 -1
  29. package/__tests__/search-devices.test.ts +3 -12
  30. package/dist/api/BaseMethod.d.ts +1 -3
  31. package/dist/api/BaseMethod.d.ts.map +1 -1
  32. package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
  33. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  34. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  35. package/dist/api/FirmwareUpdateV2.d.ts +11 -0
  36. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  37. package/dist/api/FirmwareUpdateV3.d.ts +7 -3
  38. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  39. package/dist/api/FirmwareUpdateV4.d.ts +25 -11
  40. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  41. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  42. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  43. package/dist/api/SearchDevices.d.ts.map +1 -1
  44. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  45. package/dist/api/device/DeviceUnlock.d.ts +2 -2
  46. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  47. package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
  48. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  49. package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
  50. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
  51. package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
  52. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
  53. package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
  54. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
  55. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +9 -0
  56. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  57. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
  58. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
  59. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
  60. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
  61. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -0
  62. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
  63. package/dist/api/firmware/getBinary.d.ts +7 -0
  64. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  65. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  66. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  67. package/dist/api/firmware/updateBootloader.d.ts +2 -0
  68. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  69. package/dist/api/firmware/uploadFirmware.d.ts +9 -1
  70. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  71. package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -2
  72. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  73. package/dist/api/index.d.ts +0 -2
  74. package/dist/api/index.d.ts.map +1 -1
  75. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  76. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  77. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  78. package/dist/core/deviceEventRegistration.d.ts +0 -2
  79. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  80. package/dist/core/index.d.ts.map +1 -1
  81. package/dist/data-manager/DataManager.d.ts +2 -4
  82. package/dist/data-manager/DataManager.d.ts.map +1 -1
  83. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  84. package/dist/device/Device.d.ts +6 -29
  85. package/dist/device/Device.d.ts.map +1 -1
  86. package/dist/device/DeviceCommands.d.ts +4 -4
  87. package/dist/device/DeviceCommands.d.ts.map +1 -1
  88. package/dist/device/DevicePool.d.ts.map +1 -1
  89. package/dist/events/device.d.ts +0 -4
  90. package/dist/events/device.d.ts.map +1 -1
  91. package/dist/events/logBlockEvent.d.ts.map +1 -1
  92. package/dist/events/ui-promise.d.ts +2 -4
  93. package/dist/events/ui-promise.d.ts.map +1 -1
  94. package/dist/events/ui-request.d.ts +2 -31
  95. package/dist/events/ui-request.d.ts.map +1 -1
  96. package/dist/events/ui-response.d.ts +2 -10
  97. package/dist/events/ui-response.d.ts.map +1 -1
  98. package/dist/index.d.ts +231 -214
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +3497 -2559
  101. package/dist/inject.d.ts +1 -6
  102. package/dist/inject.d.ts.map +1 -1
  103. package/dist/lowLevelInject.d.ts.map +1 -1
  104. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  105. package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
  106. package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
  107. package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
  108. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  109. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
  110. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  111. package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
  112. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
  113. package/dist/protocols/protocol-v2/walletSession.d.ts +1 -5
  114. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  115. package/dist/topLevelInject.d.ts.map +1 -1
  116. package/dist/types/api/checkAllFirmwareRelease.d.ts +4 -2
  117. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  118. package/dist/types/api/deviceUnlock.d.ts +1 -5
  119. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  120. package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
  121. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  122. package/dist/types/api/export.d.ts +4 -2
  123. package/dist/types/api/export.d.ts.map +1 -1
  124. package/dist/types/api/firmwareUpdate.d.ts +70 -2
  125. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  126. package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
  127. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
  128. package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
  129. package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
  130. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
  131. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
  132. package/dist/types/api/index.d.ts +10 -7
  133. package/dist/types/api/index.d.ts.map +1 -1
  134. package/dist/types/api/protocolV2.d.ts +0 -3
  135. package/dist/types/api/protocolV2.d.ts.map +1 -1
  136. package/dist/types/device.d.ts.map +1 -1
  137. package/dist/types/params.d.ts +0 -1
  138. package/dist/types/params.d.ts.map +1 -1
  139. package/dist/types/settings.d.ts +13 -22
  140. package/dist/types/settings.d.ts.map +1 -1
  141. package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
  142. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
  143. package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
  144. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  145. package/dist/utils/homescreen.d.ts +0 -4
  146. package/dist/utils/homescreen.d.ts.map +1 -1
  147. package/dist/utils/index.d.ts +1 -1
  148. package/dist/utils/index.d.ts.map +1 -1
  149. package/dist/utils/patch.d.ts +1 -1
  150. package/dist/utils/patch.d.ts.map +1 -1
  151. package/dist/utils/pro2Wallpaper.d.ts +0 -10
  152. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  153. package/package.json +4 -4
  154. package/src/api/BaseMethod.ts +10 -8
  155. package/src/api/CheckAllFirmwareRelease.ts +57 -54
  156. package/src/api/FirmwareUpdate.ts +15 -7
  157. package/src/api/FirmwareUpdateV2.ts +316 -126
  158. package/src/api/FirmwareUpdateV3.ts +265 -63
  159. package/src/api/FirmwareUpdateV4.ts +965 -566
  160. package/src/api/GetPassphraseState.ts +1 -7
  161. package/src/api/OpenWalletSession.ts +17 -54
  162. package/src/api/SearchDevices.ts +1 -3
  163. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -32
  164. package/src/api/device/DeviceUnlock.ts +3 -8
  165. package/src/api/device/DeviceUpdateBootloader.ts +122 -6
  166. package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
  167. package/src/api/firmware/FirmwareHostBinding.ts +100 -0
  168. package/src/api/firmware/FirmwarePreparationError.ts +12 -0
  169. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -16
  170. package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
  171. package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
  172. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +415 -0
  173. package/src/api/firmware/progressThrottle.ts +44 -0
  174. package/src/api/firmware/updateBootloader.ts +19 -4
  175. package/src/api/firmware/uploadFirmware.ts +144 -39
  176. package/src/api/helpers/protocolV2FileWrite.ts +4 -11
  177. package/src/api/index.ts +0 -2
  178. package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
  179. package/src/api/protocol-v2/helpers.ts +0 -1
  180. package/src/core/deviceEventRegistration.ts +0 -4
  181. package/src/core/index.ts +83 -167
  182. package/src/data/messages/messages-protocol-v2.json +0 -25
  183. package/src/data-manager/DataManager.ts +38 -67
  184. package/src/data-manager/connectSettings.ts +11 -0
  185. package/src/device/Device.ts +42 -258
  186. package/src/device/DeviceCommands.ts +1 -7
  187. package/src/device/DevicePool.ts +2 -7
  188. package/src/events/device.ts +0 -4
  189. package/src/events/logBlockEvent.ts +0 -1
  190. package/src/events/ui-promise.ts +2 -4
  191. package/src/events/ui-request.ts +2 -36
  192. package/src/events/ui-response.ts +2 -12
  193. package/src/index.ts +5 -0
  194. package/src/inject.ts +24 -60
  195. package/src/lowLevelInject.ts +8 -7
  196. package/src/protocols/protocol-v2/features.ts +3 -10
  197. package/src/protocols/protocol-v2/lockedError.ts +10 -0
  198. package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
  199. package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
  200. package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
  201. package/src/protocols/protocol-v2/walletSession.ts +30 -180
  202. package/src/topLevelInject.ts +8 -7
  203. package/src/types/api/checkAllFirmwareRelease.ts +4 -2
  204. package/src/types/api/deviceUnlock.ts +1 -12
  205. package/src/types/api/deviceUpdateBootloader.ts +6 -0
  206. package/src/types/api/export.ts +18 -1
  207. package/src/types/api/firmwareUpdate.ts +76 -3
  208. package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
  209. package/src/types/api/firmwareUpdatePlan.ts +38 -0
  210. package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
  211. package/src/types/api/index.ts +14 -13
  212. package/src/types/api/protocolV2.ts +0 -13
  213. package/src/types/device.ts +0 -3
  214. package/src/types/params.ts +1 -7
  215. package/src/types/settings.ts +13 -42
  216. package/src/utils/deviceFeaturesCompat.ts +6 -0
  217. package/src/utils/deviceFeaturesUtils.ts +0 -8
  218. package/src/utils/homescreen.ts +6 -32
  219. package/src/utils/index.ts +1 -6
  220. package/src/utils/pro2Wallpaper.ts +8 -35
  221. package/__tests__/deviceUploadNft.test.ts +0 -293
  222. package/__tests__/pro2Nft.test.ts +0 -108
  223. package/__tests__/protocol-binding.test.ts +0 -89
  224. package/__tests__/protocol-v2-resources.test.ts +0 -284
  225. package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
  226. package/__tests__/uiProgressThrottle.test.ts +0 -74
  227. package/__tests__/uiPromiseRegistry.test.ts +0 -86
  228. package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
  229. package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
  230. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
  231. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
  232. package/dist/core/uiPromiseRegistry.d.ts +0 -4
  233. package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
  234. package/dist/protocols/protocol-v2/resources.d.ts +0 -30
  235. package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
  236. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
  237. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
  238. package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
  239. package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
  240. package/dist/utils/pro2Nft.d.ts +0 -31
  241. package/dist/utils/pro2Nft.d.ts.map +0 -1
  242. package/dist/utils/uiProgressThrottle.d.ts +0 -3
  243. package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
  244. package/src/api/DetectDeviceConnectProtocol.ts +0 -18
  245. package/src/api/protocol-v2/DeviceUploadNft.ts +0 -189
  246. package/src/core/uiPromiseRegistry.ts +0 -41
  247. package/src/protocols/protocol-v2/resources.ts +0 -359
  248. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -118
  249. package/src/types/api/detectDeviceConnectProtocol.ts +0 -7
  250. package/src/utils/pro2Nft.ts +0 -142
  251. 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,18 +185,12 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
216
185
  }
217
186
 
218
187
  this.device.passphraseState = undefined;
219
- await ensureProtocolV2WalletStatus();
188
+ await unlockProtocolV2IfLocked();
220
189
  const session = isProtocolV2
221
- ? await getProtocolV2WalletSession(this.device, {
222
- forceWalletSelection: true,
223
- deriveCardano: this.payload.deriveCardano,
224
- })
190
+ ? await getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
225
191
  : await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
226
- const refreshedState = isProtocolV2
227
- ? requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState())
228
- : state;
229
- const deviceId = requireDeviceId();
230
- if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
192
+ const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
193
+ if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
231
194
  this.device.clearInternalState();
232
195
  throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
233
196
  }
@@ -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);
@@ -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,34 +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 hidden wallet before it sends its own device command.
395
- if (this.device.isProtocolV2() && this.payload.passphraseState) {
396
- const passphraseStateSafety = await this.device.checkPassphraseStateSafety(
397
- this.payload.passphraseState,
398
- false,
399
- this.payload.skipPassphraseCheck
400
- );
401
- if (!passphraseStateSafety) {
402
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
403
- }
404
- }
405
- },
406
- });
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();
407
388
 
408
389
  if (!Array.isArray(response) || response.length === 0) {
409
390
  throw new Error('No response');
@@ -458,9 +439,7 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
458
439
  show_display: false,
459
440
  });
460
441
 
461
- if (!this.device.isProtocolV2()) {
462
- this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
463
- }
442
+ this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
464
443
 
465
444
  if (res.message.root_fingerprint == null) {
466
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);