@onekeyfe/hd-core 1.2.0-alpha.1 → 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__/connectSettings.test.ts +19 -0
- package/__tests__/device-wallet-session-store.test.ts +131 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +50 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +3253 -1605
- package/dist/api/BaseMethod.d.ts +4 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +20 -3
- 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/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +4 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/index.d.ts +13 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
- 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/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.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/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
- package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +27 -18
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -5
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +0 -1
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +0 -1
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- 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/data-manager/DataManager.d.ts +1 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -3
- 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/device/DeviceWalletSessionStore.d.ts +15 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.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 +166 -70
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2659 -1750
- 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/features.d.ts +12 -14
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -0
- package/dist/protocols/protocol-v2/index.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 +13 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +6 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -0
- package/dist/types/api/getDeviceInfo.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 +18 -12
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +31 -17
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +10 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/device.d.ts +1 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +21 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +2 -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/ClearSessionCache.ts +28 -0
- package/src/api/FileRead.ts +16 -3
- package/src/api/FileWrite.ts +22 -1
- package/src/api/FirmwareUpdateV4.ts +1006 -265
- package/src/api/GetOnekeyFeatures.ts +1 -1
- package/src/api/GetPassphraseState.ts +9 -15
- package/src/api/UploadPortfolio.ts +37 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
- package/src/api/device/DeviceRebootToBootloader.ts +4 -4
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/index.ts +13 -10
- package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
- package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
- package/src/api/protocol-v2/DeviceReboot.ts +1 -1
- package/src/api/protocol-v2/DeviceSessionGet.ts +15 -0
- package/src/api/protocol-v2/{DeviceGetOnboardingStatus.ts → DeviceSettingsGet.ts} +3 -3
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +59 -0
- package/src/api/protocol-v2/DeviceSettingsSet.ts +39 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +160 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
- package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
- package/src/api/protocol-v2/helpers.ts +71 -47
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/api/tron/TronSignMessage.ts +0 -1
- package/src/api/tron/TronSignTransaction.ts +0 -1
- package/src/core/RequestQueue.ts +19 -0
- package/src/core/index.ts +29 -6
- package/src/data/messages/messages-protocol-v2.json +760 -1110
- package/src/data/messages/messages.json +8 -0
- package/src/data-manager/DataManager.ts +7 -0
- package/src/data-manager/connectSettings.ts +2 -4
- package/src/device/Device.ts +103 -70
- package/src/device/DeviceCommands.ts +9 -3
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
- package/src/deviceProfile/buildDeviceProfile.ts +77 -58
- 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 +26 -16
- package/src/lowLevelInject.ts +3 -0
- package/src/protocols/protocol-v2/features.ts +26 -63
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +46 -0
- package/src/protocols/protocol-v2/walletSession.ts +92 -0
- package/src/topLevelInject.ts +2 -0
- package/src/types/api/firmwareUpdate.ts +28 -20
- package/src/types/api/getDeviceInfo.ts +2 -0
- package/src/types/api/getPassphraseState.ts +2 -11
- package/src/types/api/index.ts +29 -21
- package/src/types/api/protocolV2.ts +74 -35
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +1 -0
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -35
- package/src/utils/deviceFeaturesUtils.ts +46 -20
- package/src/utils/index.ts +6 -0
- package/src/utils/pro2Wallpaper.ts +111 -0
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
|
@@ -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,19 @@
|
|
|
1
|
+
import { parseConnectSettings } from '../src/data-manager/connectSettings';
|
|
2
|
+
|
|
3
|
+
jest.mock('../src/data/config', () => ({
|
|
4
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
5
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
describe('parseConnectSettings', () => {
|
|
9
|
+
it('keeps custom configFetcher in parsed settings', () => {
|
|
10
|
+
const configFetcher = jest.fn();
|
|
11
|
+
|
|
12
|
+
const settings = parseConnectSettings({
|
|
13
|
+
fetchConfig: true,
|
|
14
|
+
configFetcher,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(settings.configFetcher).toBe(configFetcher);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import ClearSessionCache from '../src/api/ClearSessionCache';
|
|
2
|
+
import {
|
|
3
|
+
DeviceWalletSessionStore,
|
|
4
|
+
deviceWalletSessionStore,
|
|
5
|
+
} from '../src/device/DeviceWalletSessionStore';
|
|
6
|
+
import { createCoreApi } from '../src/inject';
|
|
7
|
+
|
|
8
|
+
jest.mock('../src/data/config', () => ({
|
|
9
|
+
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
10
|
+
DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe('DeviceWalletSessionStore', () => {
|
|
14
|
+
test('requires passphraseState for wallet session lookup', () => {
|
|
15
|
+
const store = new DeviceWalletSessionStore();
|
|
16
|
+
store.set('device-1', 'hidden-a', 'session-a');
|
|
17
|
+
|
|
18
|
+
expect(store.get('device-1', undefined)).toBeUndefined();
|
|
19
|
+
expect(store.get('device-1', 'hidden-a')).toBe('session-a');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('isolates wallets and devices', () => {
|
|
23
|
+
const store = new DeviceWalletSessionStore();
|
|
24
|
+
store.set('device-1', 'hidden-a', 'session-a');
|
|
25
|
+
store.set('device-1', 'hidden-b', 'session-b');
|
|
26
|
+
store.set('device-2', 'hidden-a', 'session-c');
|
|
27
|
+
|
|
28
|
+
expect(store.get('device-1', 'hidden-a')).toBe('session-a');
|
|
29
|
+
expect(store.get('device-1', 'hidden-b')).toBe('session-b');
|
|
30
|
+
expect(store.get('device-2', 'hidden-a')).toBe('session-c');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('keeps pending sessions unreadable until wallet binding', () => {
|
|
34
|
+
const store = new DeviceWalletSessionStore();
|
|
35
|
+
store.setPending('device-1', 'pending-session');
|
|
36
|
+
|
|
37
|
+
expect(store.get('device-1', undefined)).toBeUndefined();
|
|
38
|
+
expect(store.getPending('device-1')).toBe('pending-session');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('migrates descriptor keys to stable device ids', () => {
|
|
42
|
+
const store = new DeviceWalletSessionStore();
|
|
43
|
+
store.set('ble-path', 'hidden-a', 'session-a');
|
|
44
|
+
store.setPending('ble-path', 'pending-session');
|
|
45
|
+
|
|
46
|
+
store.migrateDeviceKey('ble-path', 'stable-device-id');
|
|
47
|
+
|
|
48
|
+
expect(store.get('ble-path', 'hidden-a')).toBeUndefined();
|
|
49
|
+
expect(store.get('stable-device-id', 'hidden-a')).toBe('session-a');
|
|
50
|
+
expect(store.getPending('ble-path')).toBeUndefined();
|
|
51
|
+
expect(store.getPending('stable-device-id')).toBe('pending-session');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('clears one wallet, one device, or all sessions', () => {
|
|
55
|
+
const store = new DeviceWalletSessionStore();
|
|
56
|
+
store.set('device-1', 'hidden-a', 'session-a');
|
|
57
|
+
store.set('device-1', 'hidden-b', 'session-b');
|
|
58
|
+
store.set('device-2', 'hidden-a', 'session-c');
|
|
59
|
+
|
|
60
|
+
store.delete('device-1', 'hidden-a');
|
|
61
|
+
expect(store.get('device-1', 'hidden-a')).toBeUndefined();
|
|
62
|
+
expect(store.get('device-1', 'hidden-b')).toBe('session-b');
|
|
63
|
+
|
|
64
|
+
store.deleteDevice('device-1');
|
|
65
|
+
expect(store.get('device-1', 'hidden-b')).toBeUndefined();
|
|
66
|
+
expect(store.get('device-2', 'hidden-a')).toBe('session-c');
|
|
67
|
+
|
|
68
|
+
store.clear();
|
|
69
|
+
expect(store.get('device-2', 'hidden-a')).toBeUndefined();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('ClearSessionCache', () => {
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
deviceWalletSessionStore.clear();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('clears one wallet without using a device', async () => {
|
|
79
|
+
deviceWalletSessionStore.set('device-1', 'hidden-a', 'session-a');
|
|
80
|
+
deviceWalletSessionStore.set('device-1', 'hidden-b', 'session-b');
|
|
81
|
+
const method = new ClearSessionCache({
|
|
82
|
+
payload: {
|
|
83
|
+
method: 'clearSessionCache',
|
|
84
|
+
deviceId: 'device-1',
|
|
85
|
+
passphraseState: 'hidden-a',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
method.init();
|
|
90
|
+
|
|
91
|
+
expect(method.useDevice).toBe(false);
|
|
92
|
+
await expect(method.run()).resolves.toEqual({ cleared: true });
|
|
93
|
+
expect(deviceWalletSessionStore.get('device-1', 'hidden-a')).toBeUndefined();
|
|
94
|
+
expect(deviceWalletSessionStore.get('device-1', 'hidden-b')).toBe('session-b');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('clears one device or the full runtime store', async () => {
|
|
98
|
+
deviceWalletSessionStore.set('device-1', 'hidden-a', 'session-a');
|
|
99
|
+
deviceWalletSessionStore.set('device-2', 'hidden-a', 'session-b');
|
|
100
|
+
|
|
101
|
+
const clearDevice = new ClearSessionCache({
|
|
102
|
+
payload: { method: 'clearSessionCache', deviceId: 'device-1' },
|
|
103
|
+
});
|
|
104
|
+
clearDevice.init();
|
|
105
|
+
await clearDevice.run();
|
|
106
|
+
|
|
107
|
+
expect(deviceWalletSessionStore.get('device-1', 'hidden-a')).toBeUndefined();
|
|
108
|
+
expect(deviceWalletSessionStore.get('device-2', 'hidden-a')).toBe('session-b');
|
|
109
|
+
|
|
110
|
+
const clearAll = new ClearSessionCache({
|
|
111
|
+
payload: { method: 'clearSessionCache' },
|
|
112
|
+
});
|
|
113
|
+
clearAll.init();
|
|
114
|
+
await clearAll.run();
|
|
115
|
+
|
|
116
|
+
expect(deviceWalletSessionStore.get('device-2', 'hidden-a')).toBeUndefined();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('routes cache clearing through the active CoreApi call channel', async () => {
|
|
120
|
+
const call = jest.fn().mockResolvedValue({ success: true, payload: { cleared: true } });
|
|
121
|
+
const api = createCoreApi(call as any);
|
|
122
|
+
|
|
123
|
+
await api.clearSessionCache({ deviceId: 'device-1', passphraseState: 'hidden-a' });
|
|
124
|
+
|
|
125
|
+
expect(call).toHaveBeenCalledWith({
|
|
126
|
+
method: 'clearSessionCache',
|
|
127
|
+
deviceId: 'device-1',
|
|
128
|
+
passphraseState: 'hidden-a',
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { Device } from '../src/device/Device';
|
|
2
|
+
import { initCore } from '../src/core';
|
|
3
|
+
import PreInitialize from '../src/api/device/PreInitialize';
|
|
4
|
+
import { IFRAME } from '../src/events';
|
|
5
|
+
|
|
6
|
+
import type Core from '../src/core';
|
|
2
7
|
|
|
3
8
|
jest.mock('../src/data/config', () => ({
|
|
4
9
|
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
@@ -6,6 +11,10 @@ jest.mock('../src/data/config', () => ({
|
|
|
6
11
|
}));
|
|
7
12
|
|
|
8
13
|
describe('preInitialize', () => {
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
jest.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
9
18
|
it('matches pre-initialized state by passphraseState only', () => {
|
|
10
19
|
const device = Object.create(Device.prototype) as Device;
|
|
11
20
|
|
|
@@ -19,4 +28,28 @@ describe('preInitialize', () => {
|
|
|
19
28
|
})
|
|
20
29
|
).toBe(true);
|
|
21
30
|
});
|
|
31
|
+
|
|
32
|
+
it('cleans request lifecycle when preInitialize is acknowledged without connectId', async () => {
|
|
33
|
+
const core: Core = initCore();
|
|
34
|
+
const disposeSpy = jest.spyOn(PreInitialize.prototype, 'dispose');
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await core.handleMessage({
|
|
38
|
+
id: 1001,
|
|
39
|
+
type: IFRAME.CALL,
|
|
40
|
+
payload: {
|
|
41
|
+
method: 'preInitialize',
|
|
42
|
+
},
|
|
43
|
+
} as any);
|
|
44
|
+
|
|
45
|
+
expect(response).toMatchObject({
|
|
46
|
+
success: true,
|
|
47
|
+
payload: true,
|
|
48
|
+
});
|
|
49
|
+
expect((core as any).tracingContext.activeRequests.has(1001)).toBe(false);
|
|
50
|
+
expect(disposeSpy).toHaveBeenCalledTimes(1);
|
|
51
|
+
} finally {
|
|
52
|
+
core.dispose();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
22
55
|
});
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ProtocolV2FirmwareTargetType } from '../src/protocols/protocol-v2/firmware';
|
|
2
|
+
|
|
3
|
+
describe('Protocol V2 firmware target contract', () => {
|
|
4
|
+
test('matches the current firmware-pro2 target ids', () => {
|
|
5
|
+
expect(ProtocolV2FirmwareTargetType).toEqual({
|
|
6
|
+
FW_MGMT_TARGET_INVALID: 0,
|
|
7
|
+
FW_MGMT_TARGET_CRATE: 1,
|
|
8
|
+
FW_MGMT_TARGET_ROMLOADER: 2,
|
|
9
|
+
FW_MGMT_TARGET_BOOTLOADER: 3,
|
|
10
|
+
FW_MGMT_TARGET_APPLICATION_P1: 4,
|
|
11
|
+
FW_MGMT_TARGET_APPLICATION_P2: 5,
|
|
12
|
+
FW_MGMT_TARGET_COPROCESSOR: 6,
|
|
13
|
+
FW_MGMT_TARGET_SE01: 7,
|
|
14
|
+
FW_MGMT_TARGET_SE02: 8,
|
|
15
|
+
FW_MGMT_TARGET_SE03: 9,
|
|
16
|
+
FW_MGMT_TARGET_SE04: 10,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|