@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 AllNetworkGetAddressBase from '../src/api/allnetwork/AllNetworkGetAddressBase';
2
- import AllNetworkGetAddress from '../src/api/allnetwork/AllNetworkGetAddress';
3
2
  import { findMethod } from '../src/api/utils';
4
3
  import { getActiveRequestsByDeviceInstance } from '../src/utils/tracing';
5
4
 
@@ -19,235 +18,6 @@ class TestAllNetworkMethod extends AllNetworkGetAddressBase {
19
18
  }
20
19
 
21
20
  describe('AllNetworkGetAddressBase tracing', () => {
22
- test('resumes a Protocol V2 hidden wallet before running a nested chain method', async () => {
23
- const calls: string[] = [];
24
- const checkPassphraseStateSafety = jest.fn().mockImplementation(() => {
25
- calls.push('resume-hidden-session');
26
- return Promise.resolve(true);
27
- });
28
- const innerMethod = {
29
- checkSafetyLevelOnTestNet: jest.fn().mockResolvedValue(false),
30
- connectId: 'connect-id',
31
- deviceId: 'device-id',
32
- getVersionRange: jest.fn().mockReturnValue({}),
33
- assertProtocolSupported: jest.fn(),
34
- init: jest.fn(),
35
- name: 'evmGetAddress',
36
- responseID: 43,
37
- unlockPolicy: 'unlock-before-run',
38
- run: jest.fn().mockImplementation(() => {
39
- calls.push('run-chain-method');
40
- return Promise.resolve([{ address: '0xhidden' }]);
41
- }),
42
- setDevice: jest.fn(),
43
- strictCheckDeviceSupport: false,
44
- };
45
- (findMethod as jest.Mock).mockReturnValue(innerMethod);
46
- const method = new TestAllNetworkMethod({
47
- id: 1,
48
- payload: {
49
- method: 'allNetworkGetAddress',
50
- connectId: 'connect-id',
51
- deviceId: 'device-id',
52
- passphraseState: 'hidden-state',
53
- bundle: [],
54
- },
55
- });
56
- method.protocolV2UnlockContext = { preflightCompleted: true };
57
- const typedCall = jest.fn();
58
- method.device = {
59
- checkPassphraseStateSafety,
60
- commands: {
61
- typedCall,
62
- },
63
- getCurrentFirmwareType: jest.fn(),
64
- getProtocol: jest.fn().mockReturnValue('V2'),
65
- getCurrentFirmwareVersionString: jest.fn().mockReturnValue('1.0.0'),
66
- getCurrentMethodVersionRange: jest
67
- .fn()
68
- .mockImplementation((getRange: (type: string) => unknown) => getRange('pro2')),
69
- instanceId: 'device-instance',
70
- isProtocolV2: jest.fn().mockReturnValue(true),
71
- isBootloader: jest.fn().mockReturnValue(false),
72
- isRomloader: jest.fn().mockReturnValue(false),
73
- off: jest.fn(),
74
- on: jest.fn(),
75
- state: { status: { unlocked: true } },
76
- updateProtocolV2Status: jest.fn(),
77
- } as any;
78
-
79
- await method.callMethod(
80
- 'evmGetAddress',
81
- {
82
- bundle: [
83
- {
84
- _originRequestParams: {
85
- network: 'evm',
86
- path: "m/44'/60'/0'/0/0",
87
- },
88
- },
89
- ],
90
- },
91
- 0
92
- );
93
-
94
- expect(checkPassphraseStateSafety).toHaveBeenCalledWith('hidden-state', false, undefined);
95
- expect(calls).toEqual(['resume-hidden-session', 'run-chain-method']);
96
- expect(typedCall).not.toHaveBeenCalled();
97
- });
98
-
99
- test('resumes a Protocol V2 standard wallet before running a nested chain method', async () => {
100
- const calls: string[] = [];
101
- const checkPassphraseStateSafety = jest.fn().mockImplementation(() => {
102
- calls.push('resume-standard-session');
103
- return Promise.resolve(true);
104
- });
105
- const innerMethod = {
106
- checkSafetyLevelOnTestNet: jest.fn().mockResolvedValue(false),
107
- connectId: 'connect-id',
108
- deviceId: 'device-id',
109
- getVersionRange: jest.fn().mockReturnValue({}),
110
- assertProtocolSupported: jest.fn(),
111
- init: jest.fn(),
112
- name: 'evmGetAddress',
113
- responseID: 44,
114
- unlockPolicy: 'unlock-before-run',
115
- run: jest.fn().mockImplementation(() => {
116
- calls.push('run-chain-method');
117
- return Promise.resolve([{ address: '0xstandard' }]);
118
- }),
119
- setDevice: jest.fn(),
120
- strictCheckDeviceSupport: false,
121
- };
122
- (findMethod as jest.Mock).mockReturnValue(innerMethod);
123
- const method = new TestAllNetworkMethod({
124
- id: 2,
125
- payload: {
126
- method: 'allNetworkGetAddress',
127
- connectId: 'connect-id',
128
- deviceId: 'device-id',
129
- useEmptyPassphrase: true,
130
- bundle: [],
131
- },
132
- });
133
- method.protocolV2UnlockContext = { preflightCompleted: true };
134
- const typedCall = jest.fn();
135
- method.device = {
136
- checkPassphraseStateSafety,
137
- commands: {
138
- typedCall,
139
- },
140
- getCurrentFirmwareType: jest.fn(),
141
- getProtocol: jest.fn().mockReturnValue('V2'),
142
- getCurrentFirmwareVersionString: jest.fn().mockReturnValue('1.0.0'),
143
- getCurrentMethodVersionRange: jest
144
- .fn()
145
- .mockImplementation((getRange: (type: string) => unknown) => getRange('pro2')),
146
- instanceId: 'device-instance',
147
- isProtocolV2: jest.fn().mockReturnValue(true),
148
- isBootloader: jest.fn().mockReturnValue(false),
149
- isRomloader: jest.fn().mockReturnValue(false),
150
- off: jest.fn(),
151
- on: jest.fn(),
152
- state: { status: { unlocked: true } },
153
- updateProtocolV2Status: jest.fn(),
154
- } as any;
155
-
156
- await method.callMethod(
157
- 'evmGetAddress',
158
- {
159
- bundle: [
160
- {
161
- _originRequestParams: {
162
- network: 'evm',
163
- path: "m/44'/60'/0'/0/0",
164
- },
165
- },
166
- ],
167
- },
168
- 0
169
- );
170
-
171
- expect(checkPassphraseStateSafety).toHaveBeenCalledWith(undefined, true, undefined);
172
- expect(calls).toEqual(['resume-standard-session', 'run-chain-method']);
173
- expect(typedCall).not.toHaveBeenCalled();
174
- });
175
-
176
- test('runs Protocol V2 addresses one at a time so each command receives a wallet session', async () => {
177
- const method = new AllNetworkGetAddress({
178
- id: 3,
179
- payload: {
180
- method: 'allNetworkGetAddress',
181
- connectId: 'connect-id',
182
- deviceId: 'device-id',
183
- useEmptyPassphrase: true,
184
- bundle: [
185
- { network: 'evm', path: "m/44'/60'/0'/0/0" },
186
- { network: 'evm', path: "m/44'/60'/0'/0/1" },
187
- ],
188
- },
189
- });
190
- method.device = {
191
- isProtocolV2: jest.fn().mockReturnValue(true),
192
- } as any;
193
- method.postMessage = jest.fn();
194
- const callMethod = jest
195
- .fn()
196
- .mockResolvedValueOnce([{ payload: { address: '0x1' }, success: true }])
197
- .mockResolvedValueOnce([{ payload: { address: '0x2' }, success: true }]);
198
- method.callMethod = callMethod;
199
-
200
- await method.getAllNetworkAddress(7);
201
-
202
- expect(callMethod).toHaveBeenCalledTimes(2);
203
- expect(callMethod).toHaveBeenNthCalledWith(
204
- 1,
205
- 'evmGetAddress',
206
- expect.objectContaining({ bundle: [expect.any(Object)] }),
207
- 7
208
- );
209
- expect(callMethod).toHaveBeenNthCalledWith(
210
- 2,
211
- 'evmGetAddress',
212
- expect.objectContaining({ bundle: [expect.any(Object)] }),
213
- 7
214
- );
215
- });
216
-
217
- test('keeps same-method address batching for Protocol V1', async () => {
218
- const method = new AllNetworkGetAddress({
219
- id: 4,
220
- payload: {
221
- method: 'allNetworkGetAddress',
222
- connectId: 'connect-id',
223
- deviceId: 'device-id',
224
- useEmptyPassphrase: true,
225
- bundle: [
226
- { network: 'evm', path: "m/44'/60'/0'/0/0" },
227
- { network: 'evm', path: "m/44'/60'/0'/0/1" },
228
- ],
229
- },
230
- });
231
- method.device = {
232
- isProtocolV2: jest.fn().mockReturnValue(false),
233
- } as any;
234
- method.postMessage = jest.fn();
235
- const callMethod = jest.fn().mockResolvedValue([
236
- { payload: { address: '0x1' }, success: true },
237
- { payload: { address: '0x2' }, success: true },
238
- ]);
239
- method.callMethod = callMethod;
240
-
241
- await method.getAllNetworkAddress(7);
242
-
243
- expect(callMethod).toHaveBeenCalledTimes(1);
244
- expect(callMethod).toHaveBeenCalledWith(
245
- 'evmGetAddress',
246
- expect.objectContaining({ bundle: [expect.any(Object), expect.any(Object)] }),
247
- 7
248
- );
249
- });
250
-
251
21
  test('releases the nested request context when an unhandled error escapes', async () => {
252
22
  const deviceInstanceId = 'device-instance';
253
23
  const innerMethod = {
@@ -281,7 +51,6 @@ describe('AllNetworkGetAddressBase tracing', () => {
281
51
  getCurrentMethodVersionRange: jest
282
52
  .fn()
283
53
  .mockImplementation((getRange: (type: string) => unknown) => getRange('classic')),
284
- isProtocolV2: jest.fn().mockReturnValue(false),
285
54
  off: jest.fn(),
286
55
  on: jest.fn(),
287
56
  } as any;
@@ -125,51 +125,6 @@ describe('DeviceCommands failure mapping', () => {
125
125
  expect(JSON.stringify(log.messages)).not.toContain('secret-wallet-address');
126
126
  });
127
127
 
128
- it('logs the sanitized DeviceFirmwareUpdateStatus response payload', async () => {
129
- const commands = createCommands();
130
- const log = getLogger(LoggerNames.DeviceCommands);
131
- log.messages.length = 0;
132
-
133
- await expect(
134
- commands._filterCommonTypes(
135
- {
136
- type: 'DeviceFirmwareUpdateStatus',
137
- message: {
138
- records: [
139
- {
140
- target_id: 4,
141
- status: 2,
142
- payload_version: 0x010203,
143
- path: 'vol0:/application_p1.bin',
144
- },
145
- ],
146
- },
147
- } as any,
148
- 'DeviceFirmwareUpdateStatusGet'
149
- )
150
- ).resolves.toMatchObject({ type: 'DeviceFirmwareUpdateStatus' });
151
-
152
- expect(log.messages.at(-1)?.message).toEqual([
153
- '_filterCommonTypes: ',
154
- {
155
- request: 'DeviceFirmwareUpdateStatusGet',
156
- response: {
157
- type: 'DeviceFirmwareUpdateStatus',
158
- message: {
159
- records: [
160
- {
161
- target_id: 4,
162
- status: 2,
163
- payload_version: 0x010203,
164
- path: 'vol0:/application_p1.bin',
165
- },
166
- ],
167
- },
168
- },
169
- },
170
- ]);
171
- });
172
-
173
128
  it('maps an invalid DeviceSessionGet resume to WalletSessionInvalid', async () => {
174
129
  const commands = createCommands();
175
130
 
@@ -3,8 +3,6 @@ import { registerHardwareUiEventListeners } from '../src/core/deviceEventRegistr
3
3
 
4
4
  const handlers = {
5
5
  pin: jest.fn(),
6
- pinOnDevice: jest.fn(),
7
- pinOnDeviceComplete: jest.fn(),
8
6
  button: jest.fn(),
9
7
  passphrase: jest.fn(),
10
8
  passphraseOnDevice: jest.fn(),
@@ -23,8 +21,6 @@ describe('hardware UI event registration', () => {
23
21
  expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(true);
24
22
  expect(device.on.mock.calls.map(([type]) => type)).toEqual([
25
23
  DEVICE.PIN,
26
- DEVICE.PIN_ON_DEVICE,
27
- DEVICE.PIN_ON_DEVICE_COMPLETE,
28
24
  DEVICE.BUTTON,
29
25
  DEVICE.PASSPHRASE,
30
26
  DEVICE.PASSPHRASE_ON_DEVICE,
@@ -38,8 +34,6 @@ describe('hardware UI event registration', () => {
38
34
  expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(true);
39
35
  expect(device.on.mock.calls.map(([type]) => type)).toEqual([
40
36
  DEVICE.PIN,
41
- DEVICE.PIN_ON_DEVICE,
42
- DEVICE.PIN_ON_DEVICE_COMPLETE,
43
37
  DEVICE.BUTTON,
44
38
  DEVICE.PASSPHRASE,
45
39
  DEVICE.PASSPHRASE_ON_DEVICE,
@@ -5,7 +5,6 @@ import CheckAllFirmwareRelease, {
5
5
  } from '../src/api/CheckAllFirmwareRelease';
6
6
  import { DataManager } from '../src/data-manager';
7
7
  import { createCoreApi } from '../src/inject';
8
- import { PROTOCOL_V2_RESOURCE_DEVICE_PATHS } from '../src/protocols/protocol-v2/resources';
9
8
 
10
9
  import type { CoreApi } from '../src/types/api';
11
10
  import type { DeviceStateVersions, IFirmwareReleaseInfo } from '../src/types';
@@ -73,74 +72,7 @@ const release: IFirmwareReleaseInfo = {
73
72
  ],
74
73
  };
75
74
 
76
- const stableResources = ['images', 'animation', 'wallpaper', 'translations', 'roobert', 'noto'].map(
77
- (type, index) => ({
78
- type,
79
- url: `https://example.com/${type}.okpkg`,
80
- size: 0x52a0 + index + 1,
81
- fileHash: 'a'.repeat(64),
82
- headerHash: index.toString(16).padStart(128, '0'),
83
- })
84
- );
85
-
86
- const createFilesystemTypedCall = (missingAll = false) => {
87
- const resourceByPath = new Map(
88
- stableResources.map(resource => [
89
- PROTOCOL_V2_RESOURCE_DEVICE_PATHS[
90
- resource.type as keyof typeof PROTOCOL_V2_RESOURCE_DEVICE_PATHS
91
- ],
92
- resource,
93
- ])
94
- );
95
- return jest.fn((requestType: string, _responseType: string, payload: Record<string, any>) => {
96
- if (requestType === 'ResourceInventoryGet') {
97
- throw new Error('ResourceInventoryGet is unavailable on released firmware');
98
- }
99
- if (requestType === 'FilesystemPathInfoQuery') {
100
- const resource = resourceByPath.get(payload.path);
101
- return {
102
- message: {
103
- exist: Boolean(resource) && !missingAll,
104
- directory: false,
105
- size: missingAll ? 0 : resource?.size,
106
- },
107
- };
108
- }
109
- if (requestType === 'FilesystemFileRead') {
110
- const resource = resourceByPath.get(payload.file.path);
111
- if (!resource || missingAll) throw new Error('missing resource');
112
- const header = new Uint8Array(0x52a0);
113
- const view = new DataView(header.buffer);
114
- 'OKPP'.split('').forEach((char, index) => {
115
- header[index] = char.charCodeAt(0);
116
- });
117
- 'RESC'.split('').forEach((char, index) => {
118
- header[0x08 + index] = char.charCodeAt(0);
119
- });
120
- view.setUint32(0x0c, header.byteLength, true);
121
- for (let index = 0; index < resource.headerHash.length / 2; index++) {
122
- header[0x240 + index] = Number.parseInt(
123
- resource.headerHash.slice(index * 2, index * 2 + 2),
124
- 16
125
- );
126
- }
127
- const offset = Number(payload.file.offset);
128
- const chunkLength = Number(payload.chunk_len);
129
- return {
130
- message: {
131
- data: header.slice(offset, offset + chunkLength),
132
- },
133
- };
134
- }
135
- throw new Error(`Unexpected request: ${requestType}`);
136
- });
137
- };
138
-
139
75
  describe('checkAllFirmwareRelease Protocol V2 support', () => {
140
- afterEach(() => {
141
- jest.restoreAllMocks();
142
- });
143
-
144
76
  test('builds ordered firmwareUpdateV4 targets from recommended component versions', () => {
145
77
  const result = buildProtocolV2FirmwareRelease({
146
78
  currentVersions,
@@ -152,7 +84,7 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
152
84
  status: 'required',
153
85
  hasUpgrade: true,
154
86
  required: true,
155
- targetsToUpdate: ['boot', 'app_v1'],
87
+ targetsToUpdate: ['boot', 'app_v1', 'resource'],
156
88
  components: [
157
89
  { configKey: 'bootloader', status: 'outdated', updateTarget: 'boot' },
158
90
  { configKey: 'applicationP1', status: 'outdated', updateTarget: 'app_v1' },
@@ -210,7 +142,6 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
210
142
  applicationP1Hash: 'aa'.repeat(32),
211
143
  applicationP2Hash: 'bb'.repeat(32),
212
144
  },
213
- checkFirmwareHash: true,
214
145
  remotePayloadHashes: {
215
146
  applicationP1: 'aa'.repeat(64),
216
147
  applicationP2: 'cc'.repeat(64),
@@ -229,37 +160,6 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
229
160
  });
230
161
  });
231
162
 
232
- test('uses version-only comparison for same-version packages by default', () => {
233
- const packageSet: IFirmwareReleaseInfo = {
234
- ...release,
235
- required: false,
236
- resourceBundles: undefined,
237
- installOrder: ['applicationP1'],
238
- components: {
239
- applicationP1: {
240
- target: 'APPLICATION_P1',
241
- version: [1, 0, 0],
242
- url: 'https://example.com/application-p1.okpkg',
243
- payloadHash: 'cc'.repeat(64),
244
- },
245
- },
246
- };
247
-
248
- expect(
249
- buildProtocolV2FirmwareRelease({
250
- currentVersions: { ...currentVersions, applicationP1: '1.0.0' },
251
- currentVerification: { applicationP1Hash: 'aa'.repeat(32) },
252
- firmwareType: EFirmwareType.Universal,
253
- release: packageSet,
254
- })
255
- ).toMatchObject({
256
- status: 'valid',
257
- hasUpgrade: false,
258
- targetsToUpdate: [],
259
- components: [{ configKey: 'applicationP1', status: 'valid' }],
260
- });
261
- });
262
-
263
163
  test('keeps same-version hash-aware components unknown without metadata payloadHash', () => {
264
164
  const packageSet: IFirmwareReleaseInfo = {
265
165
  ...release,
@@ -280,7 +180,6 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
280
180
  buildProtocolV2FirmwareRelease({
281
181
  currentVersions: { ...currentVersions, applicationP1: '1.0.0' },
282
182
  currentVerification: { applicationP1Hash: 'aa'.repeat(32) },
283
- checkFirmwareHash: true,
284
183
  firmwareType: EFirmwareType.Universal,
285
184
  release: packageSet,
286
185
  })
@@ -316,7 +215,6 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
316
215
  const result = buildProtocolV2FirmwareRelease({
317
216
  currentVersions,
318
217
  currentVerification: { applicationP1Hash: 'aa'.repeat(32) },
319
- checkFirmwareHash: true,
320
218
  remotePayloadHashes: { applicationP1: 'cc'.repeat(64) },
321
219
  firmwareType: EFirmwareType.Universal,
322
220
  release: packageSet,
@@ -325,7 +223,7 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
325
223
  expect(result.targetsToUpdate).toEqual(['app_v1', 'app_v2']);
326
224
  });
327
225
 
328
- test('does not read vol0 resource inventory while Protocol V2 is in Application mode', async () => {
226
+ test('uses the existing method on Protocol V2 and keeps its public API name', async () => {
329
227
  const method = new CheckAllFirmwareRelease({
330
228
  id: 1,
331
229
  payload: {
@@ -342,7 +240,6 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
342
240
  status: { mode: 'normal' },
343
241
  versions: currentVersions,
344
242
  });
345
- const typedCall = createFilesystemTypedCall(true);
346
243
  method.device = {
347
244
  isProtocolV2: () => true,
348
245
  features: {
@@ -350,124 +247,32 @@ describe('checkAllFirmwareRelease Protocol V2 support', () => {
350
247
  firmwareVersion: '1.0.0',
351
248
  },
352
249
  getDeviceState,
353
- getCommands: () => ({ typedCall }),
354
250
  } as unknown as CheckAllFirmwareRelease['device'];
355
251
  jest.spyOn(DataManager, 'getFirmwareLatestRelease').mockReturnValue(release);
356
- jest.spyOn(DataManager, 'getProtocolV2Resources').mockReturnValue(stableResources as any);
357
252
 
358
253
  await expect(method.run()).resolves.toMatchObject({
359
254
  protocol: 'V2',
360
255
  deviceType: 'pro2',
361
256
  status: 'required',
362
- resourceStatus: 'unknown',
363
- targetsToUpdate: ['boot', 'app_v1'],
257
+ targetsToUpdate: ['boot', 'app_v1', 'resource'],
364
258
  firmware: {
365
259
  status: 'required',
366
260
  },
367
261
  });
368
- expect(typedCall).not.toHaveBeenCalled();
369
- expect(getDeviceState).toHaveBeenCalledWith({
370
- refreshSections: ['identity', 'versions'],
371
- });
372
262
  expect(method.getSupportedProtocols()).toEqual(['V1', 'V2']);
373
263
  });
374
264
 
375
- test('requests and compares firmware hashes only when explicitly enabled', async () => {
376
- const packageSet: IFirmwareReleaseInfo = {
377
- ...release,
378
- required: false,
379
- resourceBundles: undefined,
380
- installOrder: ['applicationP1'],
381
- components: {
382
- applicationP1: {
383
- target: 'APPLICATION_P1',
384
- version: [1, 0, 0],
385
- url: 'https://example.com/application-p1.okpkg',
386
- payloadHash: 'cc'.repeat(64),
387
- },
388
- },
389
- };
390
- const method = new CheckAllFirmwareRelease({
391
- id: 1,
392
- payload: {
393
- method: 'checkAllFirmwareRelease',
394
- firmwareType: EFirmwareType.Universal,
395
- checkFirmwareHash: true,
396
- },
397
- });
398
- method.init();
399
- const getDeviceState = jest.fn().mockResolvedValue({
400
- identity: { deviceType: 'pro2', firmwareType: EFirmwareType.Universal },
401
- status: { mode: 'normal' },
402
- versions: { ...currentVersions, applicationP1: '1.0.0' },
403
- verification: { applicationP1Hash: 'aa'.repeat(32) },
404
- });
405
- method.device = {
406
- isProtocolV2: () => true,
407
- features: { deviceType: 'pro2', firmwareVersion: '1.0.0' },
408
- getDeviceState,
409
- getCommands: () => ({ typedCall: jest.fn() }),
410
- } as unknown as CheckAllFirmwareRelease['device'];
411
- jest.spyOn(DataManager, 'getFirmwareLatestRelease').mockReturnValue(packageSet);
412
- jest.spyOn(DataManager, 'getProtocolV2Resources').mockReturnValue(undefined);
413
-
414
- await expect(method.run()).resolves.toMatchObject({
415
- status: 'outdated',
416
- targetsToUpdate: ['app_v1'],
417
- });
418
- expect(getDeviceState).toHaveBeenCalledWith({
419
- refreshSections: ['identity', 'versions', 'verification'],
420
- });
421
- });
422
-
423
- test.each(['bootloader', 'romloader'] as const)(
424
- 'uses filesystem inventory in %s mode instead of forcing all resources',
425
- async mode => {
426
- const method = new CheckAllFirmwareRelease({
427
- id: 1,
428
- payload: {
429
- method: 'checkAllFirmwareRelease',
430
- firmwareType: EFirmwareType.Universal,
431
- },
432
- });
433
- method.init();
434
- const typedCall = createFilesystemTypedCall();
435
- method.device = {
436
- isProtocolV2: () => true,
437
- features: { deviceType: 'pro2', firmwareVersion: '1.0.0' },
438
- getDeviceState: jest.fn().mockResolvedValue({
439
- identity: { deviceType: 'pro2', firmwareType: EFirmwareType.Universal },
440
- status: { mode },
441
- versions: currentVersions,
442
- }),
443
- getCommands: () => ({ typedCall }),
444
- } as unknown as CheckAllFirmwareRelease['device'];
445
- jest.spyOn(DataManager, 'getFirmwareLatestRelease').mockReturnValue(release);
446
- jest.spyOn(DataManager, 'getProtocolV2Resources').mockReturnValue(stableResources as any);
447
-
448
- await expect(method.run()).resolves.toMatchObject({
449
- protocol: 'V2',
450
- resourceStatus: 'valid',
451
- targetsToUpdate: ['boot', 'app_v1'],
452
- });
453
- expect(typedCall.mock.calls.some(call => call[0] === 'ResourceInventoryGet')).toBe(false);
454
- expect(typedCall.mock.calls.some(call => call[0] === 'FilesystemFileRead')).toBe(true);
455
- }
456
- );
457
-
458
265
  test('continues forwarding the existing public method', async () => {
459
266
  const call = jest.fn().mockResolvedValue({ success: true, payload: {} });
460
267
  const api = createCoreApi(call as CoreApi['call']) as CoreApi;
461
268
 
462
269
  await api.checkAllFirmwareRelease('pro2-connect-id', {
463
- checkFirmwareHash: true,
464
270
  firmwareType: EFirmwareType.Universal,
465
271
  retryCount: 0,
466
272
  });
467
273
 
468
274
  expect(call).toHaveBeenCalledWith({
469
275
  connectId: 'pro2-connect-id',
470
- checkFirmwareHash: true,
471
276
  firmwareType: EFirmwareType.Universal,
472
277
  retryCount: 0,
473
278
  method: 'checkAllFirmwareRelease',
@@ -1,19 +1,61 @@
1
+ import DataManager from '../src/data-manager/DataManager';
1
2
  import { parseConnectSettings } from '../src/data-manager/connectSettings';
2
3
 
4
+ import type { RemoteConfigResponse } from '../src/types';
5
+
6
+ jest.mock('axios', () => ({
7
+ get: jest.fn(),
8
+ }));
9
+
3
10
  jest.mock('../src/data/config', () => ({
4
11
  getSDKVersion: jest.fn(() => '1.0.0'),
5
12
  DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
6
13
  }));
7
14
 
15
+ const mockAxiosGet: jest.Mock = jest.requireMock('axios').get;
16
+
8
17
  describe('parseConnectSettings', () => {
9
- it('keeps custom configFetcher in parsed settings', () => {
10
- const configFetcher = jest.fn();
18
+ const preloadedConfig = {
19
+ bridge: {},
20
+ classic: { firmware: [], ble: [] },
21
+ classic1s: { firmware: [], ble: [] },
22
+ classicpure: { firmware: [], ble: [] },
23
+ mini: { firmware: [], ble: [] },
24
+ touch: { firmware: [], ble: [] },
25
+ pro: { firmware: [], ble: [] },
26
+ pro2: { firmware: [], ble: [] },
27
+ } as unknown as RemoteConfigResponse;
28
+
29
+ it('keeps a serializable preloaded config in parsed settings', () => {
30
+ const settings = parseConnectSettings({
31
+ firmwareManifestMode: 'sdk-managed',
32
+ preloadedConfig,
33
+ });
34
+
35
+ expect(settings.firmwareManifestMode).toBe('sdk-managed');
36
+ expect(settings.preloadedConfig).toBe(preloadedConfig);
37
+ });
38
+
39
+ it('uses the preloaded config before the SDK network client', async () => {
40
+ const settings = parseConnectSettings({
41
+ firmwareManifestMode: 'sdk-managed',
42
+ preloadedConfig,
43
+ });
44
+
45
+ await DataManager.load(settings);
46
+
47
+ expect(mockAxiosGet).not.toHaveBeenCalled();
48
+ expect(DataManager.deviceMap.classic).toEqual({ firmware: [], ble: [] });
49
+ });
11
50
 
51
+ it('fails closed without a preloaded config in external-only mode', async () => {
12
52
  const settings = parseConnectSettings({
13
- fetchConfig: true,
14
- configFetcher,
53
+ firmwareManifestMode: 'external-only',
15
54
  });
16
55
 
17
- expect(settings.configFetcher).toBe(configFetcher);
56
+ await expect(DataManager.load(settings)).rejects.toThrow(
57
+ 'External firmware config snapshot is required'
58
+ );
59
+ expect(mockAxiosGet).not.toHaveBeenCalled();
18
60
  });
19
61
  });