@onekeyfe/hd-core 1.2.0-alpha.10 → 1.2.0-alpha.11
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 +25 -0
- package/__tests__/RequestQueue.test.ts +34 -0
- package/__tests__/pro2Wallpaper.test.ts +50 -0
- package/__tests__/protocol-v2.test.ts +426 -60
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +1 -6
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +18 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +1 -4
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +16 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +12 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +26 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
- package/dist/core/RequestQueue.d.ts +2 -0
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/call.d.ts +7 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +1 -0
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +76 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +694 -253
- package/dist/inject.d.ts +3 -2
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +2 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +9 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +2 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +2 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +8 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +19 -4
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -2
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +12 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +18 -0
- package/src/api/FileWrite.ts +9 -1
- package/src/api/FirmwareUpdateV4.ts +21 -91
- package/src/api/GetPassphraseState.ts +9 -18
- package/src/api/UploadPortfolio.ts +37 -0
- package/src/api/index.ts +5 -0
- package/src/api/protocol-v2/DeviceSessionGet.ts +3 -14
- package/src/api/protocol-v2/DeviceSettingsGet.ts +16 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +59 -0
- package/src/api/protocol-v2/DeviceSettingsSet.ts +39 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +160 -0
- package/src/core/RequestQueue.ts +19 -0
- package/src/core/index.ts +10 -1
- package/src/data/messages/messages-protocol-v2.json +92 -8
- package/src/device/Device.ts +17 -3
- package/src/device/DeviceCommands.ts +9 -3
- package/src/events/call.ts +6 -0
- package/src/events/core.ts +2 -0
- package/src/events/iframe.ts +1 -0
- package/src/index.ts +4 -0
- package/src/inject.ts +13 -0
- package/src/lowLevelInject.ts +3 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +46 -0
- package/src/protocols/protocol-v2/walletSession.ts +14 -5
- package/src/topLevelInject.ts +2 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/getPassphraseState.ts +2 -11
- package/src/types/api/index.ts +12 -1
- package/src/types/api/protocolV2.ts +46 -3
- package/src/utils/deviceFeaturesUtils.ts +3 -8
- package/src/utils/index.ts +6 -0
- package/src/utils/pro2Wallpaper.ts +111 -0
|
@@ -16,6 +16,31 @@ const createCommands = () => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
describe('DeviceCommands failure mapping', () => {
|
|
19
|
+
it('maps Protocol V2 DeviceLocked failure to a structured hardware error', async () => {
|
|
20
|
+
const commands = createCommands();
|
|
21
|
+
|
|
22
|
+
await expect(
|
|
23
|
+
commands._filterCommonTypes(
|
|
24
|
+
{
|
|
25
|
+
type: 'Failure',
|
|
26
|
+
message: {
|
|
27
|
+
code: 'Failure_ProcessError',
|
|
28
|
+
subcode: 9,
|
|
29
|
+
message: 'Device locked',
|
|
30
|
+
},
|
|
31
|
+
} as any,
|
|
32
|
+
'DeviceSettingsPageShow'
|
|
33
|
+
)
|
|
34
|
+
).rejects.toMatchObject({
|
|
35
|
+
errorCode: HardwareErrorCode.DeviceLocked,
|
|
36
|
+
params: {
|
|
37
|
+
failureCode: 'Failure_ProcessError',
|
|
38
|
+
subcode: 9,
|
|
39
|
+
firmwareMessage: 'Device locked',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
19
44
|
it.each([
|
|
20
45
|
['ButtonAck', 'Not in Ethereum signing mode'],
|
|
21
46
|
['PinMatrixAck', 'Not in Conflux signing mode'],
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import RequestQueue from '../src/core/RequestQueue';
|
|
2
|
+
|
|
3
|
+
import type { BaseMethod } from '../src/api/BaseMethod';
|
|
4
|
+
|
|
5
|
+
jest.mock('../src/data/config', () => ({
|
|
6
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
7
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
function buildMethod(responseID: number, operationId?: string) {
|
|
11
|
+
return {
|
|
12
|
+
payload: { operationId },
|
|
13
|
+
responseID,
|
|
14
|
+
} as unknown as BaseMethod;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('RequestQueue operation cancellation', () => {
|
|
18
|
+
test('aborts only the request matching the operation id', () => {
|
|
19
|
+
const queue = new RequestQueue();
|
|
20
|
+
const portfolio = queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
21
|
+
const userAction = queue.createTask(buildMethod(2, 'user-action'));
|
|
22
|
+
|
|
23
|
+
expect(queue.abortOperation('portfolio-1')).toBe(true);
|
|
24
|
+
expect(portfolio.abortController?.signal.aborted).toBe(true);
|
|
25
|
+
expect(userAction.abortController?.signal.aborted).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('returns false for an unknown operation id', () => {
|
|
29
|
+
const queue = new RequestQueue();
|
|
30
|
+
queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
31
|
+
|
|
32
|
+
expect(queue.abortOperation('missing')).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { encodePro2Wallpaper } from '../src/utils/pro2Wallpaper';
|
|
2
|
+
|
|
3
|
+
describe('encodePro2Wallpaper', () => {
|
|
4
|
+
test('encodes opaque pixels as aligned LVGL v9 RGB565 data', () => {
|
|
5
|
+
const result = encodePro2Wallpaper({
|
|
6
|
+
width: 2,
|
|
7
|
+
height: 1,
|
|
8
|
+
rgba: new Uint8Array([255, 0, 0, 255, 0, 255, 0, 255]),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
expect(result.colorFormat).toBe('RGB565');
|
|
12
|
+
expect(Array.from(result.data.slice(0, 12))).toEqual([
|
|
13
|
+
0x19,
|
|
14
|
+
0x12,
|
|
15
|
+
0,
|
|
16
|
+
0,
|
|
17
|
+
2,
|
|
18
|
+
0,
|
|
19
|
+
1,
|
|
20
|
+
0,
|
|
21
|
+
4,
|
|
22
|
+
0,
|
|
23
|
+
0,
|
|
24
|
+
0,
|
|
25
|
+
]);
|
|
26
|
+
expect(Array.from(result.data.slice(12))).toEqual([0x00, 0xf0, 0xc0, 0x07]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('encodes transparent pixels as RGB565A8 with alpha plane after RGB data', () => {
|
|
30
|
+
const result = encodePro2Wallpaper({
|
|
31
|
+
width: 2,
|
|
32
|
+
height: 1,
|
|
33
|
+
rgba: new Uint8Array([0, 0, 255, 128, 255, 255, 255, 255]),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(result.colorFormat).toBe('RGB565A8');
|
|
37
|
+
expect(result.data[1]).toBe(0x14);
|
|
38
|
+
expect(Array.from(result.data.slice(8, 10))).toEqual([4, 0]);
|
|
39
|
+
expect(Array.from(result.data.slice(12))).toEqual([0x1f, 0x00, 0xff, 0xff, 128, 255]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('rejects invalid dimensions and RGBA byte length', () => {
|
|
43
|
+
expect(() =>
|
|
44
|
+
encodePro2Wallpaper({ width: 0, height: 1, rgba: new Uint8Array() })
|
|
45
|
+
).toThrow('width');
|
|
46
|
+
expect(() =>
|
|
47
|
+
encodePro2Wallpaper({ width: 2, height: 1, rgba: new Uint8Array(4) })
|
|
48
|
+
).toThrow('8');
|
|
49
|
+
});
|
|
50
|
+
});
|