@onekeyfe/hd-core 1.2.0-alpha.20 → 1.2.0-alpha.22
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 +87 -2
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-identity.test.ts +24 -2
- package/__tests__/device-lifecycle-events.test.ts +1 -1
- package/__tests__/device-settings.test.ts +111 -6
- package/__tests__/device-state-events.test.ts +3 -3
- package/__tests__/device-state-mapper.test.ts +15 -3
- package/__tests__/device-state-store.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +111 -7
- package/__tests__/deviceSettings.test.ts +55 -15
- package/__tests__/evmLedgerLegacySafety.test.ts +6 -5
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +326 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +39 -30
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +7 -0
- package/__tests__/open-wallet-session.test.ts +253 -13
- package/__tests__/pro2Wallpaper.test.ts +7 -18
- package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
- package/__tests__/protocol-v2.test.ts +439 -282
- package/__tests__/public-device-state-api.test.ts +79 -68
- package/__tests__/public-pro2-api-boundary.test.ts +22 -29
- package/dist/api/BaseMethod.d.ts +2 -4
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +11 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +29 -10
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +0 -1
- package/dist/api/UploadPortfolio.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxGetAddress.d.ts +1 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +26 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +7 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +24 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -20
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/RequestQueue.d.ts +1 -19
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -0
- 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 +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +0 -1
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/events/call.d.ts +0 -7
- 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 +0 -1
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/index.d.ts +320 -277
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3210 -1856
- package/dist/inject.d.ts +2 -3
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +1 -2
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +4 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +3 -0
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +2 -2
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +69 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +27 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +10 -23
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +1 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -84
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +4 -1
- package/dist/types/api/sessionCache.d.ts.map +1 -1
- package/dist/types/device.d.ts +4 -4
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +36 -7
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- 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/package.json +4 -4
- package/src/api/BaseMethod.ts +11 -12
- package/src/api/CheckAllFirmwareRelease.ts +16 -3
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdate.ts +8 -1
- package/src/api/FirmwareUpdateV2.ts +284 -119
- package/src/api/FirmwareUpdateV3.ts +248 -55
- package/src/api/FirmwareUpdateV4.ts +816 -328
- package/src/api/OpenWalletSession.ts +74 -25
- package/src/api/UploadPortfolio.ts +3 -13
- package/src/api/conflux/ConfluxGetAddress.ts +2 -0
- package/src/api/conflux/ConfluxSignMessage.ts +2 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +2 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -0
- package/src/api/device/DeviceChangePin.ts +1 -1
- package/src/api/device/DeviceSettings.ts +66 -5
- package/src/api/device/DeviceUpdateBootloader.ts +114 -6
- package/src/api/device/DeviceWipe.ts +1 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +50 -0
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +621 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +378 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +140 -22
- package/src/api/helpers/protocolV2FileWrite.ts +6 -0
- package/src/api/index.ts +0 -21
- package/src/api/nexa/NexaSignTransaction.ts +2 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
- package/src/core/RequestQueue.ts +4 -123
- package/src/core/index.ts +25 -31
- package/src/data/messages/messages-protocol-v2.json +77 -4
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +51 -61
- package/src/device/DeviceCommands.ts +58 -14
- package/src/device/DeviceFeaturesState.ts +0 -9
- package/src/device/DeviceStateMapper.ts +26 -8
- package/src/device/DeviceStateProjector.ts +7 -1
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -1
- package/src/events/call.ts +0 -6
- package/src/events/core.ts +0 -2
- package/src/events/iframe.ts +0 -1
- package/src/events/logBlockEvent.ts +1 -0
- package/src/index.ts +5 -4
- package/src/inject.ts +22 -35
- package/src/lowLevelInject.ts +5 -4
- package/src/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +2 -2
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +1 -3
- package/src/protocols/protocol-v2/walletSession.ts +68 -12
- package/src/topLevelInject.ts +5 -3
- package/src/types/api/checkAllFirmwareRelease.ts +3 -0
- package/src/types/api/deviceSettings.ts +17 -2
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -0
- package/src/types/api/firmwareUpdate.ts +76 -0
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +36 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -41
- package/src/types/api/openWalletSession.ts +2 -0
- package/src/types/api/protocolV2.ts +3 -187
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/device.ts +5 -3
- package/src/types/settings.ts +13 -0
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceSettings.ts +130 -56
- package/src/utils/index.ts +18 -1
- package/__tests__/RequestQueue.test.ts +0 -140
- package/__tests__/UploadPortfolio.test.ts +0 -46
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +0 -16
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +0 -12
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +0 -1
- package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -18
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -70
- package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -44
package/src/utils/index.ts
CHANGED
|
@@ -30,7 +30,24 @@ export {
|
|
|
30
30
|
checkNeedUpdateBootForTouch,
|
|
31
31
|
checkNeedUpdateBootForClassicAndMini,
|
|
32
32
|
} from '../api/firmware/updateBootloader';
|
|
33
|
-
export {
|
|
33
|
+
export {
|
|
34
|
+
DEVICE_SETTINGS_SHARED_FIELDS,
|
|
35
|
+
DEVICE_SETTINGS_V1_ONLY_FIELDS,
|
|
36
|
+
DEVICE_SETTINGS_V2_ONLY_FIELDS,
|
|
37
|
+
PROTOCOL_V2_NEVER_TIMEOUT_MS,
|
|
38
|
+
getAutoLockOptions,
|
|
39
|
+
getAutoShutDownOptions,
|
|
40
|
+
getDeviceSettingsCapabilities,
|
|
41
|
+
getLanguageConfig,
|
|
42
|
+
normalizeSafetyCheckLevel,
|
|
43
|
+
} from './deviceSettings';
|
|
44
|
+
export type {
|
|
45
|
+
DeviceSettingsCapabilities,
|
|
46
|
+
DeviceSettingsDurationOption,
|
|
47
|
+
DeviceSettingsField,
|
|
48
|
+
DeviceSettingsProtocol,
|
|
49
|
+
DeviceSettingsValueOption,
|
|
50
|
+
} from './deviceSettings';
|
|
34
51
|
|
|
35
52
|
// Helpers utils
|
|
36
53
|
|
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
connectId: 'device-1',
|
|
13
|
-
executionPriority: 'normal',
|
|
14
|
-
payload: { operationId },
|
|
15
|
-
responseID,
|
|
16
|
-
} as unknown as BaseMethod;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function buildBackgroundMethod(responseID: number, operationId?: string) {
|
|
20
|
-
return {
|
|
21
|
-
...buildMethod(responseID, operationId),
|
|
22
|
-
executionPriority: 'background',
|
|
23
|
-
} as unknown as BaseMethod;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
describe('RequestQueue operation cancellation', () => {
|
|
27
|
-
test('aborts only the request matching the operation id', () => {
|
|
28
|
-
const queue = new RequestQueue();
|
|
29
|
-
const portfolio = queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
30
|
-
const userAction = queue.createTask(buildMethod(2, 'user-action'));
|
|
31
|
-
|
|
32
|
-
expect(queue.abortOperation('portfolio-1')).toBe(true);
|
|
33
|
-
expect(portfolio.abortController?.signal.aborted).toBe(true);
|
|
34
|
-
expect(userAction.abortController?.signal.aborted).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('returns false for an unknown operation id', () => {
|
|
38
|
-
const queue = new RequestQueue();
|
|
39
|
-
queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
40
|
-
|
|
41
|
-
expect(queue.abortOperation('missing')).toBe(false);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('honors cancellation that arrives before the request is registered', () => {
|
|
45
|
-
const queue = new RequestQueue();
|
|
46
|
-
|
|
47
|
-
expect(queue.abortOperation('portfolio-1')).toBe(false);
|
|
48
|
-
|
|
49
|
-
const portfolio = queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
50
|
-
const userAction = queue.createTask(buildMethod(2, 'user-action'));
|
|
51
|
-
|
|
52
|
-
expect(portfolio.abortController?.signal.aborted).toBe(true);
|
|
53
|
-
expect(userAction.abortController?.signal.aborted).toBe(false);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('expires a cancellation that is never matched', () => {
|
|
57
|
-
const nowSpy = jest.spyOn(Date, 'now');
|
|
58
|
-
nowSpy.mockReturnValueOnce(1_000);
|
|
59
|
-
const queue = new RequestQueue();
|
|
60
|
-
queue.abortOperation('portfolio-1');
|
|
61
|
-
nowSpy.mockReturnValue(31_001);
|
|
62
|
-
|
|
63
|
-
const portfolio = queue.createTask(buildMethod(1, 'portfolio-1'));
|
|
64
|
-
|
|
65
|
-
expect(portfolio.abortController?.signal.aborted).toBe(false);
|
|
66
|
-
nowSpy.mockRestore();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('rejects a background request while the device has an active user request', async () => {
|
|
70
|
-
const queue = new RequestQueue();
|
|
71
|
-
queue.createTask(buildMethod(1, 'user-action'));
|
|
72
|
-
|
|
73
|
-
await expect(
|
|
74
|
-
queue.admitTask(buildBackgroundMethod(2, 'portfolio-1'), {
|
|
75
|
-
backgroundPreemptTimeoutMs: 100,
|
|
76
|
-
})
|
|
77
|
-
).resolves.toMatchObject({ status: 'busy' });
|
|
78
|
-
expect(queue.getTask(2)).toBeUndefined();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('aborts and waits for an active background request before admitting a user request', async () => {
|
|
82
|
-
const queue = new RequestQueue();
|
|
83
|
-
const portfolio = queue.createTask(buildBackgroundMethod(1, 'portfolio-1'));
|
|
84
|
-
|
|
85
|
-
const admission = queue.admitTask(buildMethod(2, 'user-action'), {
|
|
86
|
-
backgroundPreemptTimeoutMs: 100,
|
|
87
|
-
});
|
|
88
|
-
await Promise.resolve();
|
|
89
|
-
|
|
90
|
-
expect(portfolio.abortController?.signal.aborted).toBe(true);
|
|
91
|
-
expect(queue.getTask(2)).toBeUndefined();
|
|
92
|
-
|
|
93
|
-
portfolio.settled.resolve();
|
|
94
|
-
await Promise.resolve();
|
|
95
|
-
expect(queue.getTask(2)).toBeUndefined();
|
|
96
|
-
|
|
97
|
-
queue.releaseTask(1);
|
|
98
|
-
|
|
99
|
-
await expect(admission).resolves.toMatchObject({
|
|
100
|
-
status: 'reserved',
|
|
101
|
-
task: { id: 2 },
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('uses the background method abort latency when no admission override is provided', async () => {
|
|
106
|
-
const queue = new RequestQueue();
|
|
107
|
-
const portfolio = queue.createTask(buildBackgroundMethod(1, 'portfolio-1'));
|
|
108
|
-
portfolio.method.maxAbortLatencyMs = 12_000;
|
|
109
|
-
const waitForTasksReleased = jest
|
|
110
|
-
.spyOn(queue as any, 'waitForTasksReleased')
|
|
111
|
-
.mockResolvedValue(false);
|
|
112
|
-
|
|
113
|
-
await expect(queue.admitTask(buildMethod(2, 'user-action'))).resolves.toMatchObject({
|
|
114
|
-
status: 'busy',
|
|
115
|
-
});
|
|
116
|
-
expect(waitForTasksReleased).toHaveBeenCalledWith([portfolio], 12_000);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('returns busy when an aborted background request does not release in time', async () => {
|
|
120
|
-
const queue = new RequestQueue();
|
|
121
|
-
const portfolio = queue.createTask(buildBackgroundMethod(1, 'portfolio-1'));
|
|
122
|
-
|
|
123
|
-
await expect(
|
|
124
|
-
queue.admitTask(buildMethod(2, 'user-action'), {
|
|
125
|
-
backgroundPreemptTimeoutMs: 1,
|
|
126
|
-
})
|
|
127
|
-
).resolves.toMatchObject({
|
|
128
|
-
status: 'busy',
|
|
129
|
-
blockingTask: { id: 1 },
|
|
130
|
-
});
|
|
131
|
-
expect(portfolio.abortController?.signal.aborted).toBe(true);
|
|
132
|
-
expect(queue.getTask(2)).toBeUndefined();
|
|
133
|
-
|
|
134
|
-
queue.releaseTask(1);
|
|
135
|
-
await expect(queue.admitTask(buildMethod(3, 'user-retry'))).resolves.toMatchObject({
|
|
136
|
-
status: 'reserved',
|
|
137
|
-
task: { id: 3 },
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import UploadPortfolio from '../src/api/UploadPortfolio';
|
|
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('UploadPortfolio timeout', () => {
|
|
9
|
-
test('applies the command timeout to staging and PortfolioUpdate', async () => {
|
|
10
|
-
const packageBytes = new Uint8Array([1, 2, 3]);
|
|
11
|
-
const typedCall = jest
|
|
12
|
-
.fn()
|
|
13
|
-
.mockResolvedValueOnce({ message: { processed_byte: 3 } })
|
|
14
|
-
.mockResolvedValueOnce({ message: {} });
|
|
15
|
-
const method = new UploadPortfolio({
|
|
16
|
-
id: 1,
|
|
17
|
-
payload: {
|
|
18
|
-
method: 'uploadPortfolio',
|
|
19
|
-
packageBytes,
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
method.device = {
|
|
23
|
-
commands: { typedCall },
|
|
24
|
-
} as any;
|
|
25
|
-
method.postMessage = jest.fn();
|
|
26
|
-
|
|
27
|
-
method.init();
|
|
28
|
-
await method.run();
|
|
29
|
-
|
|
30
|
-
expect(method.executionPriority).toBe('background');
|
|
31
|
-
expect(typedCall).toHaveBeenNthCalledWith(
|
|
32
|
-
1,
|
|
33
|
-
'FilesystemFileWrite',
|
|
34
|
-
'FilesystemFile',
|
|
35
|
-
expect.any(Object),
|
|
36
|
-
{ timeoutMs: 5_000 }
|
|
37
|
-
);
|
|
38
|
-
expect(typedCall).toHaveBeenNthCalledWith(
|
|
39
|
-
2,
|
|
40
|
-
'PortfolioUpdate',
|
|
41
|
-
'Success',
|
|
42
|
-
{},
|
|
43
|
-
{ timeoutMs: 5_000 }
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceSettingsGet.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceSettingsGet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU;IACvD,IAAI;IAQE,GAAG;CAKV"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { DeviceSettingsPage } from '@onekeyfe/hd-transport';
|
|
2
|
-
import { BaseMethod } from '../BaseMethod';
|
|
3
|
-
export type SupportedDeviceSettingsPage = DeviceSettingsPage;
|
|
4
|
-
export type DeviceSettingsPageShowParams = {
|
|
5
|
-
page?: SupportedDeviceSettingsPage | 'DeviceReset' | 'DevicePinChange' | 'DevicePassphrase' | 'DeviceAirgap';
|
|
6
|
-
fieldName?: string;
|
|
7
|
-
field_name?: string;
|
|
8
|
-
};
|
|
9
|
-
export default class DeviceSettingsPageShow extends BaseMethod<{
|
|
10
|
-
page: SupportedDeviceSettingsPage;
|
|
11
|
-
field_name?: string;
|
|
12
|
-
}> {
|
|
13
|
-
init(): void;
|
|
14
|
-
run(): Promise<import("@onekeyfe/hd-transport").Success>;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=DeviceSettingsPageShow.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceSettingsPageShow.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceSettingsPageShow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,MAAM,2BAA2B,GAAG,kBAAkB,CAAC;AAE7D,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,CAAC,EACD,2BAA2B,GAC3B,aAAa,GACb,iBAAiB,GACjB,kBAAkB,GAClB,cAAc,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAmBF,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU,CAAC;IAC7D,IAAI,EAAE,2BAA2B,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;IACA,IAAI;IAgBE,GAAG;CAaV"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import type { DeviceSettings } from '@onekeyfe/hd-transport';
|
|
3
|
-
export type DeviceSettingsSetParams = {
|
|
4
|
-
settings?: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
|
|
5
|
-
};
|
|
6
|
-
export default class DeviceSettingsSet extends BaseMethod<{
|
|
7
|
-
settings: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
|
|
8
|
-
}> {
|
|
9
|
-
init(): void;
|
|
10
|
-
run(): Promise<import("@onekeyfe/hd-transport").Success>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=DeviceSettingsSet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceSettingsSet.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceSettingsSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,aAAa,CAAC,CAAC;CACtE,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC;IACxD,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,aAAa,CAAC,CAAC;CACrE,CAAC;IACA,IAAI;IAwBE,GAAG;CAKV"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
|
|
3
|
-
|
|
4
|
-
export default class DeviceSettingsGet extends BaseMethod {
|
|
5
|
-
init() {
|
|
6
|
-
this.requireProtocolV2 = true;
|
|
7
|
-
this.unlockPolicy = 'none';
|
|
8
|
-
this.skipForceUpdateCheck = true;
|
|
9
|
-
this.useDevicePassphraseState = false;
|
|
10
|
-
this.params = undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async run() {
|
|
14
|
-
const res = await this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
|
|
15
|
-
this.device.updateState(mapDeviceSettingsToState(res.message), 'apply-settings');
|
|
16
|
-
return Promise.resolve(res.message);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { DeviceSettingsPage } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
|
-
import { BaseMethod } from '../BaseMethod';
|
|
4
|
-
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
5
|
-
import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
|
|
6
|
-
|
|
7
|
-
export type SupportedDeviceSettingsPage = DeviceSettingsPage;
|
|
8
|
-
|
|
9
|
-
export type DeviceSettingsPageShowParams = {
|
|
10
|
-
page?:
|
|
11
|
-
| SupportedDeviceSettingsPage
|
|
12
|
-
| 'DeviceReset'
|
|
13
|
-
| 'DevicePinChange'
|
|
14
|
-
| 'DevicePassphrase'
|
|
15
|
-
| 'DeviceAirgap';
|
|
16
|
-
fieldName?: string;
|
|
17
|
-
field_name?: string;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const SUPPORTED_PAGES = new Set<number>([
|
|
21
|
-
DeviceSettingsPage.DeviceReset,
|
|
22
|
-
DeviceSettingsPage.DevicePinChange,
|
|
23
|
-
DeviceSettingsPage.DevicePassphrase,
|
|
24
|
-
DeviceSettingsPage.DeviceAirgap,
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
function normalizePage(value: DeviceSettingsPageShowParams['page']): SupportedDeviceSettingsPage {
|
|
28
|
-
const page = typeof value === 'string' ? DeviceSettingsPage[value] : value;
|
|
29
|
-
if (page !== undefined && SUPPORTED_PAGES.has(page)) {
|
|
30
|
-
return page;
|
|
31
|
-
}
|
|
32
|
-
throw invalidParameter(
|
|
33
|
-
'Parameter [page] must be DeviceReset, DevicePinChange, DevicePassphrase, or DeviceAirgap.'
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default class DeviceSettingsPageShow extends BaseMethod<{
|
|
38
|
-
page: SupportedDeviceSettingsPage;
|
|
39
|
-
field_name?: string;
|
|
40
|
-
}> {
|
|
41
|
-
init() {
|
|
42
|
-
this.requireProtocolV2 = true;
|
|
43
|
-
this.skipForceUpdateCheck = true;
|
|
44
|
-
this.useDevicePassphraseState = false;
|
|
45
|
-
this.params = {
|
|
46
|
-
page: normalizePage(this.payload.page),
|
|
47
|
-
field_name: this.payload.field_name ?? this.payload.fieldName,
|
|
48
|
-
};
|
|
49
|
-
const behavior = getProtocolV2SettingsBehavior({
|
|
50
|
-
kind: 'page',
|
|
51
|
-
page: this.params.page,
|
|
52
|
-
});
|
|
53
|
-
this.unlockPolicy = behavior.unlockPolicy;
|
|
54
|
-
this.protocolV2UiInteraction = behavior.uiInteraction;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async run() {
|
|
58
|
-
const res = await this.device.commands.typedCall(
|
|
59
|
-
'DeviceSettingsPageShow',
|
|
60
|
-
'Success',
|
|
61
|
-
this.params
|
|
62
|
-
);
|
|
63
|
-
if (this.params.page === DeviceSettingsPage.DevicePassphrase) {
|
|
64
|
-
await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
65
|
-
} else if (this.params.page === DeviceSettingsPage.DeviceAirgap) {
|
|
66
|
-
await this.device.getDeviceState({ refreshSections: ['settings'] });
|
|
67
|
-
}
|
|
68
|
-
return Promise.resolve(res.message);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
|
|
3
|
-
import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
|
|
4
|
-
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
5
|
-
|
|
6
|
-
import type { DeviceSettings } from '@onekeyfe/hd-transport';
|
|
7
|
-
|
|
8
|
-
export type DeviceSettingsSetParams = {
|
|
9
|
-
settings?: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export default class DeviceSettingsSet extends BaseMethod<{
|
|
13
|
-
settings: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
|
|
14
|
-
}> {
|
|
15
|
-
init() {
|
|
16
|
-
const { settings } = this.payload;
|
|
17
|
-
if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
|
|
18
|
-
throw invalidParameter('Parameter [settings] must be an object.');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
passphrase_enable: _passphraseEnable,
|
|
23
|
-
airgap_mode: _airgapMode,
|
|
24
|
-
...supported
|
|
25
|
-
} = settings as DeviceSettings;
|
|
26
|
-
if (Object.keys(supported).length === 0) {
|
|
27
|
-
throw invalidParameter('Parameter [settings] must contain at least one supported setting.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.requireProtocolV2 = true;
|
|
31
|
-
const behavior = getProtocolV2SettingsBehavior({ kind: 'direct', settings: supported });
|
|
32
|
-
this.unlockPolicy = behavior.unlockPolicy;
|
|
33
|
-
this.skipForceUpdateCheck = true;
|
|
34
|
-
this.useDevicePassphraseState = false;
|
|
35
|
-
this.params = { settings: supported };
|
|
36
|
-
this.protocolV2UiInteraction = behavior.uiInteraction;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async run() {
|
|
40
|
-
const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', this.params);
|
|
41
|
-
this.device.updateState(mapDeviceSettingsToState(this.params.settings), 'apply-settings');
|
|
42
|
-
return Promise.resolve(res.message);
|
|
43
|
-
}
|
|
44
|
-
}
|