@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.
- package/__tests__/DeviceCommands.test.ts +77 -0
- package/__tests__/DeviceEventRegistration.test.ts +8 -3
- package/__tests__/deviceFeaturesUtils.test.ts +27 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +3 -0
- package/__tests__/homescreen.test.ts +24 -0
- package/__tests__/protocol-v2.test.ts +1006 -204
- package/__tests__/protocolV2FileWrite.test.ts +28 -3
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +3 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +3 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +3 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts +2 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -2
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -2
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/events/device.d.ts +4 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +18 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +56 -11
- package/dist/index.js +1014 -559
- package/dist/protocols/protocol-v2/features.d.ts +6 -18
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -1
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +5 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +2 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -1
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -2
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -2
- package/src/api/FirmwareUpdateV4.ts +27 -73
- package/src/api/GetDeviceInfo.ts +9 -2
- package/src/api/GetPassphraseState.ts +5 -2
- package/src/api/UploadPortfolio.ts +2 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +8 -13
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +23 -0
- package/src/api/device/DeviceLock.ts +1 -0
- package/src/api/device/DeviceUnlock.ts +9 -0
- package/src/api/device/DeviceWipe.ts +18 -0
- package/src/api/helpers/protocolV2FileWrite.ts +35 -11
- package/src/api/index.ts +1 -1
- package/src/api/protocol-v2/DeviceInfoGet.ts +0 -1
- package/src/api/protocol-v2/DeviceSessionOpen.ts +100 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +9 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +11 -1
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +2 -1
- package/src/core/deviceEventRegistration.ts +3 -8
- package/src/core/index.ts +36 -3
- package/src/data/messages/messages-protocol-v2.json +122 -23
- package/src/device/Device.ts +33 -41
- package/src/device/DeviceCommands.ts +22 -4
- package/src/device/DevicePool.ts +14 -6
- package/src/deviceProfile/buildDeviceFeatures.ts +21 -9
- package/src/deviceProfile/buildDeviceProfile.ts +27 -11
- package/src/events/device.ts +4 -0
- package/src/events/ui-request.ts +24 -2
- package/src/inject.ts +2 -2
- package/src/protocols/protocol-v2/features.ts +27 -20
- package/src/protocols/protocol-v2/index.ts +0 -1
- package/src/protocols/protocol-v2/uiInteraction.ts +209 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +43 -3
- package/src/protocols/protocol-v2/walletSession.ts +122 -31
- package/src/types/api/getDeviceInfo.ts +6 -1
- package/src/types/api/index.ts +2 -2
- package/src/types/api/protocolV2.ts +5 -3
- package/src/types/device.ts +6 -1
- package/src/utils/deviceFeaturesUtils.ts +13 -0
- package/src/utils/homescreen.ts +10 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +0 -1
- 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('
|
|
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(
|
|
21
|
-
expect(device.on
|
|
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
|
+
});
|