@onekeyfe/hd-core 1.2.0-alpha.20 → 1.2.0-alpha.21
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__/device-lifecycle-events.test.ts +1 -1
- package/__tests__/device-settings.test.ts +110 -5
- 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__/deviceSettings.test.ts +55 -15
- package/__tests__/evmLedgerLegacySafety.test.ts +6 -5
- package/__tests__/get-device-state.test.ts +7 -0
- package/__tests__/protocol-v2.test.ts +40 -153
- package/__tests__/public-device-state-api.test.ts +19 -15
- package/__tests__/public-pro2-api-boundary.test.ts +20 -1
- package/dist/api/BaseMethod.d.ts +0 -3
- package/dist/api/BaseMethod.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/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -3
- package/dist/api/index.d.ts.map +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/device/Device.d.ts +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/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/index.d.ts +59 -55
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -310
- 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/topLevelInject.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/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +1 -5
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -9
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +4 -4
- package/dist/types/device.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/package.json +4 -4
- package/src/api/BaseMethod.ts +3 -9
- package/src/api/UploadPortfolio.ts +2 -12
- package/src/api/device/DeviceSettings.ts +66 -5
- package/src/api/device/DeviceUnlock.ts +2 -1
- package/src/api/index.ts +0 -3
- package/src/core/RequestQueue.ts +4 -123
- package/src/core/index.ts +25 -31
- package/src/device/Device.ts +1 -1
- package/src/device/DeviceFeaturesState.ts +0 -9
- package/src/device/DeviceStateMapper.ts +8 -7
- 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/index.ts +0 -4
- package/src/inject.ts +0 -10
- package/src/lowLevelInject.ts +0 -3
- package/src/topLevelInject.ts +0 -2
- package/src/types/api/deviceSettings.ts +17 -2
- package/src/types/api/deviceUnlock.ts +5 -2
- package/src/types/api/index.ts +0 -7
- package/src/types/api/protocolV2.ts +0 -31
- package/src/types/device.ts +5 -3
- 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
|
@@ -83,7 +83,7 @@ describe('public device lifecycle events', () => {
|
|
|
83
83
|
const internalDevice = createInitializedDevice(protocol);
|
|
84
84
|
|
|
85
85
|
DevicePool.emitter.emit(DEVICE.CONNECT, internalDevice);
|
|
86
|
-
internalDevice.updateState({ identity: { label: 'Updated label' } }, '
|
|
86
|
+
internalDevice.updateState({ identity: { label: 'Updated label' } }, 'settings-write');
|
|
87
87
|
DevicePool.emitter.emit(DEVICE.DISCONNECT, internalDevice);
|
|
88
88
|
|
|
89
89
|
const connectMessage = messages.find(message => message.type === DEVICE.CONNECT);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
1
|
+
import { EDeviceType, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
import { DeviceSettingsPage } from '@onekeyfe/hd-transport';
|
|
3
3
|
|
|
4
4
|
import DeviceSettings from '../src/api/device/DeviceSettings';
|
|
@@ -24,6 +24,7 @@ function createDevice({ protocol }: { protocol: 'V1' | 'V2' }) {
|
|
|
24
24
|
device: {
|
|
25
25
|
features,
|
|
26
26
|
isProtocolV2: () => protocol === 'V2',
|
|
27
|
+
getCurrentDeviceType: () => (protocol === 'V2' ? EDeviceType.Pro2 : EDeviceType.Pro),
|
|
27
28
|
commands: { typedCall },
|
|
28
29
|
updateState,
|
|
29
30
|
getDeviceState,
|
|
@@ -80,6 +81,7 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
80
81
|
method: 'deviceSettings',
|
|
81
82
|
label: 'Shared Label',
|
|
82
83
|
language: 'ja',
|
|
84
|
+
bluetoothEnabled: true,
|
|
83
85
|
},
|
|
84
86
|
});
|
|
85
87
|
method.init();
|
|
@@ -98,14 +100,15 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
98
100
|
safety_checks: undefined,
|
|
99
101
|
experimental_features: undefined,
|
|
100
102
|
auto_shutdown_delay_ms: undefined,
|
|
103
|
+
use_ble: true,
|
|
101
104
|
haptic_feedback: undefined,
|
|
102
105
|
});
|
|
103
106
|
expect(updateState).toHaveBeenCalledWith(
|
|
104
107
|
{
|
|
105
108
|
identity: { label: 'Shared Label' },
|
|
106
|
-
settings: { language: 'ja' },
|
|
109
|
+
settings: { language: 'ja', bleEnabled: true },
|
|
107
110
|
},
|
|
108
|
-
'
|
|
111
|
+
'settings-write'
|
|
109
112
|
);
|
|
110
113
|
});
|
|
111
114
|
|
|
@@ -119,6 +122,7 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
119
122
|
language: 'ja',
|
|
120
123
|
autoLockDelayMs: 60_000,
|
|
121
124
|
hapticFeedback: true,
|
|
125
|
+
bluetoothEnabled: true,
|
|
122
126
|
},
|
|
123
127
|
});
|
|
124
128
|
method.init();
|
|
@@ -129,6 +133,7 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
129
133
|
settings: {
|
|
130
134
|
label: 'Shared Label',
|
|
131
135
|
language: 'ja-Jpan-JP',
|
|
136
|
+
bt_enable: true,
|
|
132
137
|
autolock_delay_ms: 60_000,
|
|
133
138
|
haptic_feedback: true,
|
|
134
139
|
},
|
|
@@ -137,12 +142,13 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
137
142
|
{
|
|
138
143
|
identity: { label: 'Shared Label' },
|
|
139
144
|
settings: {
|
|
140
|
-
language: 'ja
|
|
145
|
+
language: 'ja',
|
|
146
|
+
bleEnabled: true,
|
|
141
147
|
autoLockDelayMs: 60_000,
|
|
142
148
|
hapticFeedback: true,
|
|
143
149
|
},
|
|
144
150
|
},
|
|
145
|
-
'
|
|
151
|
+
'settings-write'
|
|
146
152
|
);
|
|
147
153
|
expect(typedCall.mock.calls.map(call => call[0])).not.toEqual(
|
|
148
154
|
expect.arrayContaining(['DeviceInfoGet', 'DeviceStatusGet', 'DeviceSettingsGet'])
|
|
@@ -283,4 +289,103 @@ describe('DeviceSettings protocol routing', () => {
|
|
|
283
289
|
});
|
|
284
290
|
expect(typedCall).not.toHaveBeenCalled();
|
|
285
291
|
});
|
|
292
|
+
|
|
293
|
+
it('rejects Protocol V1-only settings on Protocol V2 without partially applying the request', async () => {
|
|
294
|
+
const { device, typedCall } = createDevice({ protocol: 'V2' });
|
|
295
|
+
const method = new DeviceSettings({
|
|
296
|
+
id: 9,
|
|
297
|
+
payload: {
|
|
298
|
+
method: 'deviceSettings',
|
|
299
|
+
label: 'Must not be partially applied',
|
|
300
|
+
safetyChecks: 0,
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
method.init();
|
|
304
|
+
(method as any).device = device;
|
|
305
|
+
|
|
306
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
307
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
308
|
+
message: 'Protocol V2 does not support settings: safetyChecks.',
|
|
309
|
+
});
|
|
310
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('rejects Protocol V2-only settings on Protocol V1 without partially applying the request', async () => {
|
|
314
|
+
const { device, typedCall } = createDevice({ protocol: 'V1' });
|
|
315
|
+
const method = new DeviceSettings({
|
|
316
|
+
id: 10,
|
|
317
|
+
payload: {
|
|
318
|
+
method: 'deviceSettings',
|
|
319
|
+
label: 'Must not be partially applied',
|
|
320
|
+
brightness: 80,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
method.init();
|
|
324
|
+
(method as any).device = device;
|
|
325
|
+
|
|
326
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
327
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
328
|
+
message: 'Protocol V1 does not support settings: brightness.',
|
|
329
|
+
});
|
|
330
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('accepts the Protocol V2 never timeout wire value', async () => {
|
|
334
|
+
const { device, typedCall } = createDevice({ protocol: 'V2' });
|
|
335
|
+
const method = new DeviceSettings({
|
|
336
|
+
id: 11,
|
|
337
|
+
payload: {
|
|
338
|
+
method: 'deviceSettings',
|
|
339
|
+
autoLockDelayMs: 0x10000000,
|
|
340
|
+
autoShutdownDelayMs: 0x10000000,
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
method.init();
|
|
344
|
+
(method as any).device = device;
|
|
345
|
+
|
|
346
|
+
await method.run();
|
|
347
|
+
|
|
348
|
+
expect(typedCall).toHaveBeenCalledWith('DeviceSettingsSet', 'Success', {
|
|
349
|
+
settings: {
|
|
350
|
+
autolock_delay_ms: 0x10000000,
|
|
351
|
+
autoshutdown_delay_ms: 0x10000000,
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('rejects unsupported Protocol V2 timeout values before sending a command', async () => {
|
|
357
|
+
const { device, typedCall } = createDevice({ protocol: 'V2' });
|
|
358
|
+
const method = new DeviceSettings({
|
|
359
|
+
id: 12,
|
|
360
|
+
payload: {
|
|
361
|
+
method: 'deviceSettings',
|
|
362
|
+
autoLockDelayMs: 0,
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
method.init();
|
|
366
|
+
(method as any).device = device;
|
|
367
|
+
|
|
368
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
369
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
370
|
+
});
|
|
371
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('rejects unknown Protocol V1 safety check levels before sending a command', async () => {
|
|
375
|
+
const { device, typedCall } = createDevice({ protocol: 'V1' });
|
|
376
|
+
const method = new DeviceSettings({
|
|
377
|
+
id: 13,
|
|
378
|
+
payload: {
|
|
379
|
+
method: 'deviceSettings',
|
|
380
|
+
safetyChecks: 3,
|
|
381
|
+
},
|
|
382
|
+
} as never);
|
|
383
|
+
method.init();
|
|
384
|
+
(method as any).device = device;
|
|
385
|
+
|
|
386
|
+
await expect(method.run()).rejects.toMatchObject({
|
|
387
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
388
|
+
});
|
|
389
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
390
|
+
});
|
|
286
391
|
});
|
|
@@ -27,7 +27,7 @@ describe('Device state events', () => {
|
|
|
27
27
|
protocolV2DeviceInfo: { protocol_version: 2 },
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
|
-
'
|
|
30
|
+
'settings-write'
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
expect(state?.identity.label).toBe('Renamed');
|
|
@@ -36,7 +36,7 @@ describe('Device state events', () => {
|
|
|
36
36
|
expect.objectContaining({
|
|
37
37
|
state: expect.objectContaining({ revision: 1 }),
|
|
38
38
|
revision: 1,
|
|
39
|
-
source: '
|
|
39
|
+
source: 'settings-write',
|
|
40
40
|
})
|
|
41
41
|
);
|
|
42
42
|
expect(onFeatures).not.toHaveBeenCalled();
|
|
@@ -96,7 +96,7 @@ describe('Device state events', () => {
|
|
|
96
96
|
protocol: 'V1',
|
|
97
97
|
identity: { label: 'Legacy' },
|
|
98
98
|
},
|
|
99
|
-
'
|
|
99
|
+
'settings-write'
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
expect(onFeatures).toHaveBeenCalledWith(device, expect.objectContaining({ label: 'Legacy' }));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
|
+
import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
|
|
3
4
|
import {
|
|
4
5
|
mapApplySettingsToState,
|
|
5
6
|
mapDeviceSettingsToState,
|
|
@@ -208,22 +209,33 @@ describe('DeviceStateMapper', () => {
|
|
|
208
209
|
|
|
209
210
|
test('maps common settings into identity, status and settings sections', () => {
|
|
210
211
|
expect(
|
|
211
|
-
mapApplySettingsToState({
|
|
212
|
+
mapApplySettingsToState({
|
|
213
|
+
label: 'Renamed',
|
|
214
|
+
use_passphrase: true,
|
|
215
|
+
haptic_feedback: false,
|
|
216
|
+
use_ble: true,
|
|
217
|
+
safety_checks: 'Strict',
|
|
218
|
+
})
|
|
212
219
|
).toEqual({
|
|
213
220
|
identity: { label: 'Renamed' },
|
|
214
221
|
status: { passphraseProtection: true },
|
|
215
|
-
settings: {
|
|
222
|
+
settings: {
|
|
223
|
+
hapticFeedback: false,
|
|
224
|
+
bleEnabled: true,
|
|
225
|
+
safetyChecks: Enum_SafetyCheckLevel.Strict,
|
|
226
|
+
},
|
|
216
227
|
});
|
|
217
228
|
|
|
218
229
|
expect(
|
|
219
230
|
mapDeviceSettingsToState({
|
|
220
231
|
label: 'Pro2',
|
|
232
|
+
language: 'en-Latn-US',
|
|
221
233
|
brightness: 80,
|
|
222
234
|
autolock_delay_ms: 30_000,
|
|
223
235
|
} as DeviceSettings)
|
|
224
236
|
).toEqual({
|
|
225
237
|
identity: { label: 'Pro2' },
|
|
226
|
-
settings: { brightness: 80, autoLockDelayMs: 30_000 },
|
|
238
|
+
settings: { language: 'en', brightness: 80, autoLockDelayMs: 30_000 },
|
|
227
239
|
});
|
|
228
240
|
});
|
|
229
241
|
});
|
|
@@ -14,7 +14,7 @@ describe('DeviceStateStore', () => {
|
|
|
14
14
|
store.update({ identity: { bleName: 'Pro2 1234', label: null } }, 'initialize');
|
|
15
15
|
const result = store.update(
|
|
16
16
|
{ identity: { label: 'My Wallet', bleName: undefined } },
|
|
17
|
-
'
|
|
17
|
+
'settings-write'
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
expect(result.state.identity).toMatchObject({
|
|
@@ -3,8 +3,11 @@ import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
|
3
3
|
import {
|
|
4
4
|
getAutoLockOptions,
|
|
5
5
|
getAutoShutDownOptions,
|
|
6
|
+
getDeviceSettingsCapabilities,
|
|
6
7
|
getLanguageConfig,
|
|
8
|
+
mapLanguageFromProtocolV2,
|
|
7
9
|
mapLanguageToProtocolV2,
|
|
10
|
+
PROTOCOL_V2_NEVER_TIMEOUT_MS,
|
|
8
11
|
} from '../src/utils/deviceSettings';
|
|
9
12
|
|
|
10
13
|
describe('Pro 2 device settings options', () => {
|
|
@@ -38,26 +41,63 @@ describe('Pro 2 device settings options', () => {
|
|
|
38
41
|
expect(mapLanguageToProtocolV2(undefined)).toBeUndefined();
|
|
39
42
|
});
|
|
40
43
|
|
|
44
|
+
test('maps Protocol V2 tags back to the shared SDK language keys', () => {
|
|
45
|
+
expect(mapLanguageFromProtocolV2('en-Latn-US')).toBe('en');
|
|
46
|
+
expect(mapLanguageFromProtocolV2('zh-Hans-CN')).toBe('zh_cn');
|
|
47
|
+
expect(mapLanguageFromProtocolV2('pt-Latn-BR')).toBe('pt_br');
|
|
48
|
+
expect(mapLanguageFromProtocolV2('vi-Latn-VN')).toBe('vi-Latn-VN');
|
|
49
|
+
expect(mapLanguageFromProtocolV2(undefined)).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
41
52
|
test('returns the firmware-supported auto-lock delays', () => {
|
|
42
|
-
expect(getAutoLockOptions(EDeviceType.Pro2)).toEqual([
|
|
43
|
-
{
|
|
44
|
-
{
|
|
45
|
-
{
|
|
46
|
-
{
|
|
47
|
-
{
|
|
48
|
-
{
|
|
49
|
-
{
|
|
53
|
+
expect(getAutoLockOptions(EDeviceType.Pro2, 'V2')).toEqual([
|
|
54
|
+
{ label: '30 seconds', valueMs: 30_000 },
|
|
55
|
+
{ label: '1 minute', valueMs: 60_000 },
|
|
56
|
+
{ label: '2 minutes', valueMs: 120_000 },
|
|
57
|
+
{ label: '5 minutes', valueMs: 300_000 },
|
|
58
|
+
{ label: '10 minutes', valueMs: 600_000 },
|
|
59
|
+
{ label: '30 minutes', valueMs: 1_800_000 },
|
|
60
|
+
{ label: 'Never', valueMs: PROTOCOL_V2_NEVER_TIMEOUT_MS },
|
|
50
61
|
]);
|
|
51
62
|
});
|
|
52
63
|
|
|
53
64
|
test('returns the firmware-supported auto-shutdown delays', () => {
|
|
54
|
-
expect(getAutoShutDownOptions(EDeviceType.Pro2)).toEqual([
|
|
55
|
-
{
|
|
56
|
-
{
|
|
57
|
-
{
|
|
58
|
-
{
|
|
59
|
-
{
|
|
60
|
-
{
|
|
65
|
+
expect(getAutoShutDownOptions(EDeviceType.Pro2, 'V2')).toEqual([
|
|
66
|
+
{ label: '1 minute', valueMs: 60_000 },
|
|
67
|
+
{ label: '2 minutes', valueMs: 120_000 },
|
|
68
|
+
{ label: '5 minutes', valueMs: 300_000 },
|
|
69
|
+
{ label: '10 minutes', valueMs: 600_000 },
|
|
70
|
+
{ label: '30 minutes', valueMs: 1_800_000 },
|
|
71
|
+
{ label: 'Never', valueMs: PROTOCOL_V2_NEVER_TIMEOUT_MS },
|
|
61
72
|
]);
|
|
62
73
|
});
|
|
74
|
+
|
|
75
|
+
test('keeps the legacy and Protocol V2 never values protocol-specific', () => {
|
|
76
|
+
expect(getAutoLockOptions(EDeviceType.Pro, 'V1').slice(-1)[0]).toEqual({
|
|
77
|
+
label: 'Never',
|
|
78
|
+
valueMs: 0,
|
|
79
|
+
});
|
|
80
|
+
expect(getAutoLockOptions(EDeviceType.Pro2, 'V2').slice(-1)[0]).toEqual({
|
|
81
|
+
label: 'Never',
|
|
82
|
+
valueMs: PROTOCOL_V2_NEVER_TIMEOUT_MS,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('returns one capability model for Protocol V1 and V2 consumers', () => {
|
|
87
|
+
const v1 = getDeviceSettingsCapabilities(EDeviceType.Pro, 'V1');
|
|
88
|
+
const v2 = getDeviceSettingsCapabilities(EDeviceType.Pro2, 'V2');
|
|
89
|
+
|
|
90
|
+
expect(v1.supportedFields).toEqual(
|
|
91
|
+
expect.arrayContaining(['label', 'safetyChecks', 'experimentalFeatures'])
|
|
92
|
+
);
|
|
93
|
+
expect(v1.supportedFields).not.toContain('brightness');
|
|
94
|
+
expect(v2.supportedFields).toEqual(
|
|
95
|
+
expect.arrayContaining(['label', 'brightness', 'airgapMode'])
|
|
96
|
+
);
|
|
97
|
+
expect(v2.supportedFields).not.toContain('safetyChecks');
|
|
98
|
+
expect(v2.ranges.brightness).toEqual({ min: 10, max: 100 });
|
|
99
|
+
expect(v1.safetyCheckOptions.map(option => option.value)).toEqual([0, 1, 2]);
|
|
100
|
+
expect(v2.safetyCheckOptions).toEqual([]);
|
|
101
|
+
expect(v2.onDeviceConfirmationFields).toEqual(['usePassphrase', 'airgapMode']);
|
|
102
|
+
});
|
|
63
103
|
});
|
|
@@ -4,6 +4,7 @@ import EVMGetPublicKey from '../src/api/evm/EVMGetPublicKey';
|
|
|
4
4
|
import { findMethod } from '../src/api/utils';
|
|
5
5
|
import { getDeviceType, getFirmwareType, getMethodVersionRange } from '../src/utils';
|
|
6
6
|
import { getDeviceFirmwareVersion } from '../src/utils/deviceVersionUtils';
|
|
7
|
+
import { Enum_SafetyCheckLevel } from '@onekeyfe/hd-transport';
|
|
7
8
|
|
|
8
9
|
import type { EDeviceType } from '@onekeyfe/hd-shared';
|
|
9
10
|
|
|
@@ -21,7 +22,7 @@ const createDevice = (onekeyDeviceType: string) => {
|
|
|
21
22
|
const features = {
|
|
22
23
|
onekey_device_type: onekeyDeviceType,
|
|
23
24
|
deviceType: onekeyDeviceType.toLowerCase() as EDeviceType,
|
|
24
|
-
safety_checks:
|
|
25
|
+
safety_checks: Enum_SafetyCheckLevel.Strict,
|
|
25
26
|
};
|
|
26
27
|
return {
|
|
27
28
|
typedCall,
|
|
@@ -68,7 +69,7 @@ describe('EVM Ledger legacy path safety checks', () => {
|
|
|
68
69
|
await method.checkSafetyLevelOnTestNet();
|
|
69
70
|
|
|
70
71
|
expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
|
|
71
|
-
safety_checks:
|
|
72
|
+
safety_checks: Enum_SafetyCheckLevel.PromptTemporarily,
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
);
|
|
@@ -87,7 +88,7 @@ describe('EVM Ledger legacy path safety checks', () => {
|
|
|
87
88
|
await method.checkSafetyLevelOnTestNet();
|
|
88
89
|
|
|
89
90
|
expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
|
|
90
|
-
safety_checks:
|
|
91
|
+
safety_checks: Enum_SafetyCheckLevel.PromptTemporarily,
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
|
|
@@ -136,7 +137,7 @@ describe('EVM Ledger legacy path safety checks', () => {
|
|
|
136
137
|
);
|
|
137
138
|
|
|
138
139
|
expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
|
|
139
|
-
safety_checks:
|
|
140
|
+
safety_checks: Enum_SafetyCheckLevel.PromptTemporarily,
|
|
140
141
|
});
|
|
141
142
|
|
|
142
143
|
runSpy.mockRestore();
|
|
@@ -216,7 +217,7 @@ describe('EVM Ledger legacy path safety checks', () => {
|
|
|
216
217
|
|
|
217
218
|
expect(typedCall).toHaveBeenCalledTimes(1);
|
|
218
219
|
expect(typedCall).toHaveBeenCalledWith('ApplySettings', 'Success', {
|
|
219
|
-
safety_checks:
|
|
220
|
+
safety_checks: Enum_SafetyCheckLevel.PromptTemporarily,
|
|
220
221
|
});
|
|
221
222
|
|
|
222
223
|
runSpy.mockRestore();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { Device } from '../src/device/Device';
|
|
4
|
+
import { DEVICE } from '../src/events';
|
|
4
5
|
|
|
5
6
|
jest.mock('../src/data/config', () => ({
|
|
6
7
|
getSDKVersion: jest.fn(() => '1.0.0'),
|
|
@@ -167,6 +168,8 @@ describe('getDeviceState', () => {
|
|
|
167
168
|
});
|
|
168
169
|
const device = createV2Device(typedCall);
|
|
169
170
|
device.updateState({ protocol: 'V2', status: { mode: 'normal' } }, 'initialize');
|
|
171
|
+
const onState = jest.fn();
|
|
172
|
+
device.on(DEVICE.STATE, onState);
|
|
170
173
|
|
|
171
174
|
const state = await device.getDeviceState({ refreshSections: ['settings'] });
|
|
172
175
|
|
|
@@ -179,6 +182,10 @@ describe('getDeviceState', () => {
|
|
|
179
182
|
expect(state.identity.label).toBe('Renamed Pro 2');
|
|
180
183
|
expect(state.settings.language).toBe('ja-JP');
|
|
181
184
|
expect(state.settings.brightness).toBe(70);
|
|
185
|
+
expect(onState).toHaveBeenCalledWith(
|
|
186
|
+
device,
|
|
187
|
+
expect.objectContaining({ source: 'settings-read' })
|
|
188
|
+
);
|
|
182
189
|
});
|
|
183
190
|
|
|
184
191
|
test('refreshes Protocol V2 status before settings in a combined read', async () => {
|