@onekeyfe/hd-core 1.2.0-alpha.15 → 1.2.0-alpha.17

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 (118) hide show
  1. package/__tests__/DeviceCommands.test.ts +77 -0
  2. package/__tests__/DeviceEventRegistration.test.ts +8 -3
  3. package/__tests__/deviceFeaturesUtils.test.ts +27 -0
  4. package/__tests__/evmLedgerLegacySafety.test.ts +3 -0
  5. package/__tests__/homescreen.test.ts +24 -0
  6. package/__tests__/protocol-v2.test.ts +1006 -204
  7. package/__tests__/protocolV2FileWrite.test.ts +28 -3
  8. package/__tests__/protocolV2UiInteraction.test.ts +266 -0
  9. package/dist/api/BaseMethod.d.ts +4 -0
  10. package/dist/api/BaseMethod.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV4.d.ts +3 -3
  12. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  13. package/dist/api/GetDeviceInfo.d.ts.map +1 -1
  14. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  15. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  16. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  17. package/dist/api/device/DeviceCancel.d.ts.map +1 -1
  18. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  19. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  20. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  21. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  22. package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
  23. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  24. package/dist/api/index.d.ts +1 -1
  25. package/dist/api/index.d.ts.map +1 -1
  26. package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
  27. package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
  28. package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
  29. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
  30. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
  31. package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
  32. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  33. package/dist/core/deviceEventRegistration.d.ts +2 -2
  34. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  35. package/dist/core/index.d.ts.map +1 -1
  36. package/dist/device/Device.d.ts +3 -3
  37. package/dist/device/Device.d.ts.map +1 -1
  38. package/dist/device/DeviceCommands.d.ts +3 -1
  39. package/dist/device/DeviceCommands.d.ts.map +1 -1
  40. package/dist/device/DevicePool.d.ts +2 -2
  41. package/dist/device/DevicePool.d.ts.map +1 -1
  42. package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -2
  43. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  44. package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -2
  45. package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
  46. package/dist/events/device.d.ts +4 -0
  47. package/dist/events/device.d.ts.map +1 -1
  48. package/dist/events/ui-request.d.ts +18 -2
  49. package/dist/events/ui-request.d.ts.map +1 -1
  50. package/dist/index.d.ts +56 -11
  51. package/dist/index.js +1014 -559
  52. package/dist/protocols/protocol-v2/features.d.ts +6 -18
  53. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  54. package/dist/protocols/protocol-v2/index.d.ts +1 -1
  55. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  56. package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
  57. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
  58. package/dist/protocols/protocol-v2/unlockRetry.d.ts +5 -3
  59. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
  60. package/dist/protocols/protocol-v2/walletSession.d.ts +2 -1
  61. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  62. package/dist/types/api/getDeviceInfo.d.ts +2 -1
  63. package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
  64. package/dist/types/api/index.d.ts +2 -2
  65. package/dist/types/api/index.d.ts.map +1 -1
  66. package/dist/types/api/protocolV2.d.ts +4 -2
  67. package/dist/types/api/protocolV2.d.ts.map +1 -1
  68. package/dist/types/device.d.ts +2 -1
  69. package/dist/types/device.d.ts.map +1 -1
  70. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  71. package/dist/utils/homescreen.d.ts.map +1 -1
  72. package/dist/utils/patch.d.ts +1 -1
  73. package/dist/utils/patch.d.ts.map +1 -1
  74. package/package.json +4 -4
  75. package/src/api/BaseMethod.ts +10 -2
  76. package/src/api/FirmwareUpdateV4.ts +27 -73
  77. package/src/api/GetDeviceInfo.ts +9 -2
  78. package/src/api/GetPassphraseState.ts +5 -2
  79. package/src/api/UploadPortfolio.ts +2 -0
  80. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +8 -13
  81. package/src/api/device/DeviceCancel.ts +1 -0
  82. package/src/api/device/DeviceChangePin.ts +23 -0
  83. package/src/api/device/DeviceLock.ts +1 -0
  84. package/src/api/device/DeviceUnlock.ts +9 -0
  85. package/src/api/device/DeviceWipe.ts +18 -0
  86. package/src/api/helpers/protocolV2FileWrite.ts +35 -11
  87. package/src/api/index.ts +1 -1
  88. package/src/api/protocol-v2/DeviceInfoGet.ts +0 -1
  89. package/src/api/protocol-v2/DeviceSessionOpen.ts +100 -0
  90. package/src/api/protocol-v2/DeviceSettingsPageShow.ts +9 -1
  91. package/src/api/protocol-v2/DeviceSettingsSet.ts +11 -1
  92. package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
  93. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +2 -1
  94. package/src/core/deviceEventRegistration.ts +3 -8
  95. package/src/core/index.ts +36 -3
  96. package/src/data/messages/messages-protocol-v2.json +122 -23
  97. package/src/device/Device.ts +33 -41
  98. package/src/device/DeviceCommands.ts +22 -4
  99. package/src/device/DevicePool.ts +14 -6
  100. package/src/deviceProfile/buildDeviceFeatures.ts +21 -9
  101. package/src/deviceProfile/buildDeviceProfile.ts +27 -11
  102. package/src/events/device.ts +4 -0
  103. package/src/events/ui-request.ts +24 -2
  104. package/src/inject.ts +2 -2
  105. package/src/protocols/protocol-v2/features.ts +27 -20
  106. package/src/protocols/protocol-v2/index.ts +0 -1
  107. package/src/protocols/protocol-v2/uiInteraction.ts +209 -0
  108. package/src/protocols/protocol-v2/unlockRetry.ts +43 -3
  109. package/src/protocols/protocol-v2/walletSession.ts +122 -31
  110. package/src/types/api/getDeviceInfo.ts +6 -1
  111. package/src/types/api/index.ts +2 -2
  112. package/src/types/api/protocolV2.ts +5 -3
  113. package/src/types/device.ts +6 -1
  114. package/src/utils/deviceFeaturesUtils.ts +13 -0
  115. package/src/utils/homescreen.ts +10 -0
  116. package/dist/api/protocol-v2/DeviceSessionGet.d.ts +0 -6
  117. package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +0 -1
  118. package/src/api/protocol-v2/DeviceSessionGet.ts +0 -15
@@ -1,6 +1,7 @@
1
1
  import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
 
3
3
  import { DeviceCommands } from '../src/device/DeviceCommands';
4
+ import { DEVICE } from '../src/events';
4
5
 
5
6
  jest.mock('../src/data/config', () => ({
6
7
  getSDKVersion: jest.fn(() => '1.0.0'),
@@ -169,3 +170,79 @@ describe('DeviceCommands failure mapping', () => {
169
170
  });
170
171
  });
171
172
  });
173
+
174
+ describe('DeviceCommands Protocol V2 interactive response compatibility', () => {
175
+ it('still auto-acks ButtonRequest when no hardware UI listener is registered', async () => {
176
+ const commands = createCommands();
177
+ commands.device = {
178
+ ...commands.device,
179
+ getCurrentDeviceType: jest.fn(() => 'pro2'),
180
+ setCancelableAction: jest.fn(),
181
+ emit: jest.fn(),
182
+ listenerCount: jest.fn(() => 0),
183
+ } as any;
184
+ commands._commonCall = jest.fn().mockResolvedValue({
185
+ type: 'Success',
186
+ message: {},
187
+ }) as any;
188
+
189
+ await expect(
190
+ commands._filterCommonTypes(
191
+ {
192
+ type: 'ButtonRequest',
193
+ message: { code: 'ButtonRequest_PinEntry' },
194
+ } as any,
195
+ 'GetAddress'
196
+ )
197
+ ).resolves.toMatchObject({ type: 'Success' });
198
+
199
+ expect(commands.device.emit).toHaveBeenCalledWith(
200
+ DEVICE.BUTTON,
201
+ commands.device,
202
+ expect.objectContaining({ code: 'ButtonRequest_PinEntry' })
203
+ );
204
+ expect(commands._commonCall).toHaveBeenCalledWith('ButtonAck', {}, undefined);
205
+ });
206
+
207
+ it('rejects PassphraseRequest when the Pro2 UI listener is not registered', async () => {
208
+ const commands = createCommands();
209
+ commands.device = {
210
+ ...commands.device,
211
+ listenerCount: jest.fn(() => 0),
212
+ } as any;
213
+
214
+ await expect(
215
+ commands._filterCommonTypes(
216
+ {
217
+ type: 'PassphraseRequest',
218
+ message: { exists_attach_pin_user: true },
219
+ } as any,
220
+ 'GetAddress'
221
+ )
222
+ ).rejects.toMatchObject({
223
+ errorCode: HardwareErrorCode.RuntimeError,
224
+ message: '_promptPassphrase: Passphrase callback not configured',
225
+ });
226
+ });
227
+
228
+ it('rejects PinMatrixRequest when the Pro2 UI listener is not registered', async () => {
229
+ const commands = createCommands();
230
+ commands.device = {
231
+ ...commands.device,
232
+ instanceId: 'pro2-test-device',
233
+ listenerCount: jest.fn(() => 0),
234
+ } as any;
235
+
236
+ await expect(
237
+ commands._filterCommonTypes(
238
+ {
239
+ type: 'PinMatrixRequest',
240
+ message: { type: 'PinMatrixRequestType_Current' },
241
+ } as any,
242
+ 'GetAddress'
243
+ )
244
+ ).rejects.toMatchObject({
245
+ errorCode: HardwareErrorCode.RuntimeError,
246
+ });
247
+ });
248
+ });
@@ -14,11 +14,16 @@ const createDevice = (protocolV2: boolean) => ({
14
14
  });
15
15
 
16
16
  describe('hardware UI event registration', () => {
17
- test('does not register hardware-originated UI events for Protocol V2 devices', () => {
17
+ test('keeps all interactive UI events for Protocol V2 devices during compatibility mode', () => {
18
18
  const device = createDevice(true);
19
19
 
20
- expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(false);
21
- expect(device.on).not.toHaveBeenCalled();
20
+ expect(registerHardwareUiEventListeners(device as any, handlers)).toBe(true);
21
+ expect(device.on.mock.calls.map(([type]) => type)).toEqual([
22
+ DEVICE.PIN,
23
+ DEVICE.BUTTON,
24
+ DEVICE.PASSPHRASE,
25
+ DEVICE.PASSPHRASE_ON_DEVICE,
26
+ ]);
22
27
  });
23
28
 
24
29
  test('keeps the existing interactive event listeners for Protocol V1 devices', () => {
@@ -0,0 +1,27 @@
1
+ import { EDeviceType } from '@onekeyfe/hd-shared';
2
+
3
+ import DataManager from '../src/data-manager/DataManager';
4
+ import { getSupportProtocolV1MessageSchema } from '../src/utils/deviceFeaturesUtils';
5
+
6
+ import type { Features } from '../src/types';
7
+
8
+ jest.mock('../src/data/config', () => ({
9
+ getSDKVersion: () => '1.0.0',
10
+ DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
11
+ }));
12
+
13
+ describe('getSupportProtocolV1MessageSchema', () => {
14
+ test('Classic Pure 在无主固件的 Bootloader 模式下使用当前协议结构', () => {
15
+ const features = {
16
+ deviceType: EDeviceType.ClassicPure,
17
+ bootloaderMode: true,
18
+ firmwarePresent: false,
19
+ firmwareVersion: '2.0.8',
20
+ } as Features;
21
+
22
+ const result = getSupportProtocolV1MessageSchema(features);
23
+
24
+ expect(result.protocolV1MessageSchema).toBe('v1CurrentSchema');
25
+ expect(result.messages).toBe(DataManager.messages.v1CurrentSchema);
26
+ });
27
+ });
@@ -5,6 +5,8 @@ import { findMethod } from '../src/api/utils';
5
5
  import { getDeviceType, getFirmwareType, getMethodVersionRange } from '../src/utils';
6
6
  import { getDeviceFirmwareVersion } from '../src/utils/deviceVersionUtils';
7
7
 
8
+ import { EDeviceType } from '@onekeyfe/hd-shared';
9
+
8
10
  jest.mock('../src/data/config', () => ({
9
11
  getSDKVersion: jest.fn(() => '1.0.0'),
10
12
  DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
@@ -18,6 +20,7 @@ const createDevice = (onekeyDeviceType: string) => {
18
20
  const typedCall = jest.fn();
19
21
  const features = {
20
22
  onekey_device_type: onekeyDeviceType,
23
+ deviceType: onekeyDeviceType.toLowerCase() as EDeviceType,
21
24
  safety_checks: 'Strict',
22
25
  };
23
26
  return {
@@ -0,0 +1,24 @@
1
+ import { EDeviceType } from '@onekeyfe/hd-shared';
2
+
3
+ import { getHomeScreenSize } from '../src/utils/homescreen';
4
+
5
+ describe('getHomeScreenSize', () => {
6
+ it('returns the Pro 2 wallpaper dimensions', () => {
7
+ expect(
8
+ getHomeScreenSize({
9
+ deviceType: EDeviceType.Pro2,
10
+ homeScreenType: 'WallPaper',
11
+ })
12
+ ).toEqual({ width: 604, height: 1024 });
13
+ });
14
+
15
+ it('does not require a legacy thumbnail for Pro 2 wallpapers', () => {
16
+ expect(
17
+ getHomeScreenSize({
18
+ deviceType: EDeviceType.Pro2,
19
+ homeScreenType: 'WallPaper',
20
+ thumbnail: true,
21
+ })
22
+ ).toBeUndefined();
23
+ });
24
+ });