@onekeyfe/hd-core 1.2.0-alpha.17 → 1.2.0-alpha.19
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__/DeviceEventRegistration.test.ts +3 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +30 -0
- package/__tests__/device-pool-state.test.ts +113 -0
- package/__tests__/device-settings.test.ts +108 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +163 -0
- package/__tests__/device-state-mapper.test.ts +222 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +115 -0
- package/__tests__/device-wallet-session-store.test.ts +46 -0
- package/__tests__/deviceFeaturesUtils.test.ts +13 -1
- package/__tests__/deviceSettings.test.ts +54 -0
- package/__tests__/get-device-state.test.ts +367 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/logBlockEvent.test.ts +13 -0
- package/__tests__/protocol-v2.test.ts +358 -413
- package/__tests__/public-device-state-api.test.ts +153 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +93 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceState.d.ts +7 -0
- package/dist/api/GetDeviceState.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -4
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/internal.d.ts +4 -0
- package/dist/api/internal.d.ts.map +1 -0
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +0 -1
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceSettingsGet.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/utils.d.ts +2 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/device/Device.d.ts +22 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceFeaturesState.d.ts +4 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +1 -0
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +8 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +23 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/events/device.d.ts +7 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/index.d.ts +722 -648
- package/dist/index.js +1863 -1033
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +1 -0
- 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/walletSession.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +8 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/getDeviceState.d.ts +12 -0
- package/dist/types/api/getDeviceState.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +4 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +1 -6
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +121 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.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/tracing.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdateV4.ts +15 -7
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +8 -3
- package/src/api/GetOnekeyFeatures.ts +3 -72
- package/src/api/GetPassphraseState.ts +3 -1
- package/src/api/SearchDevices.ts +25 -4
- package/src/api/device/DeviceRebootToBoardloader.ts +1 -0
- package/src/api/device/DeviceRebootToBootloader.ts +1 -0
- package/src/api/device/DeviceSettings.ts +28 -0
- package/src/api/index.ts +1 -4
- package/src/api/internal.ts +9 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +3 -5
- package/src/api/protocol-v2/DeviceReboot.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsGet.ts +3 -1
- package/src/api/protocol-v2/DeviceSettingsSet.ts +2 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +1 -0
- package/src/api/utils.ts +9 -3
- package/src/constants/index.ts +1 -4
- package/src/core/index.ts +7 -1
- package/src/data/messages/messages-protocol-v2.json +22 -13
- package/src/data/messages/messages.json +286 -1
- package/src/device/Device.ts +256 -78
- package/src/device/DeviceFeaturesState.ts +34 -0
- package/src/device/DevicePool.ts +35 -9
- package/src/device/DeviceStateMapper.ts +364 -0
- package/src/device/DeviceStateProjector.ts +92 -0
- package/src/device/DeviceStateStore.ts +242 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +166 -109
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +13 -1
- package/src/events/logBlockEvent.ts +1 -1
- package/src/inject.ts +4 -5
- package/src/protocols/protocol-v2/features.ts +18 -9
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +5 -7
- package/src/types/api/deviceSettings.ts +8 -0
- package/src/types/api/getDeviceState.ts +19 -0
- package/src/types/api/index.ts +3 -20
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/protocolV2.ts +0 -24
- package/src/types/device.ts +148 -1
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceSettings.ts +41 -0
- package/src/utils/tracing.ts +3 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -22
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -88
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -152
- package/src/deviceProfile/buildDeviceProfile.ts +0 -370
- package/src/types/api/getDeviceInfo.ts +0 -106
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { Device } from '../src/device/Device';
|
|
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
|
+
const createV2Device = (typedCall: jest.Mock) => {
|
|
11
|
+
const device = Device.fromDescriptor({
|
|
12
|
+
id: 'pro2',
|
|
13
|
+
path: 'pro2',
|
|
14
|
+
protocolType: 'V2',
|
|
15
|
+
} as never);
|
|
16
|
+
(device as any).commands = { typedCall };
|
|
17
|
+
return device;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createV1Device = (typedCall: jest.Mock) => {
|
|
21
|
+
const device = Device.fromDescriptor({
|
|
22
|
+
id: 'pro',
|
|
23
|
+
path: 'pro',
|
|
24
|
+
protocolType: 'V1',
|
|
25
|
+
} as never);
|
|
26
|
+
(device as any).commands = { typedCall };
|
|
27
|
+
return device;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe('getDeviceState', () => {
|
|
31
|
+
test('does not expose the internal wallet session', async () => {
|
|
32
|
+
const device = createV2Device(jest.fn());
|
|
33
|
+
device.updateState(
|
|
34
|
+
{
|
|
35
|
+
protocol: 'V2',
|
|
36
|
+
session: { sessionId: 'private-session', passphraseState: 'private-state' },
|
|
37
|
+
},
|
|
38
|
+
'initialize'
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const state = await device.getDeviceState();
|
|
42
|
+
|
|
43
|
+
expect(state).not.toHaveProperty('session');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('hydrates Protocol V2 without status target or DeviceStatusGet by default', async () => {
|
|
47
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
48
|
+
message: {
|
|
49
|
+
protocol_version: 2,
|
|
50
|
+
hw: { serial_no: 'SERIAL-1' },
|
|
51
|
+
fw: { application: { version: '5.0.0' } },
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
const device = createV2Device(typedCall);
|
|
55
|
+
|
|
56
|
+
const state = await device.getDeviceState();
|
|
57
|
+
|
|
58
|
+
expect(state.identity.serialNo).toBe('SERIAL-1');
|
|
59
|
+
expect(typedCall).toHaveBeenCalledTimes(1);
|
|
60
|
+
expect(typedCall.mock.calls[0][0]).toBe('DeviceInfoGet');
|
|
61
|
+
expect(typedCall.mock.calls[0][2]?.targets?.status).not.toBe(true);
|
|
62
|
+
expect(typedCall).not.toHaveBeenCalledWith(
|
|
63
|
+
'DeviceStatusGet',
|
|
64
|
+
expect.anything(),
|
|
65
|
+
expect.anything()
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('uses a single full DeviceInfoGet when firmware refresh initializes the state', async () => {
|
|
70
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
71
|
+
message: {
|
|
72
|
+
protocol_version: 2,
|
|
73
|
+
hw: { serial_no: 'SERIAL-1' },
|
|
74
|
+
fw: { application: { version: '5.0.0', hash: 'HASH-1' } },
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const device = createV2Device(typedCall);
|
|
78
|
+
|
|
79
|
+
await device.getDeviceState({
|
|
80
|
+
refreshSections: ['identity', 'versions', 'verification'],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(typedCall).toHaveBeenCalledTimes(1);
|
|
84
|
+
expect(typedCall).toHaveBeenCalledWith(
|
|
85
|
+
'DeviceInfoGet',
|
|
86
|
+
'DeviceInfo',
|
|
87
|
+
expect.objectContaining({
|
|
88
|
+
types: expect.objectContaining({ hash: true, build_id: true }),
|
|
89
|
+
}),
|
|
90
|
+
expect.anything()
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('does not overwrite confirmed notInitialized mode during a versions refresh', async () => {
|
|
95
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
96
|
+
message: {
|
|
97
|
+
protocol_version: 2,
|
|
98
|
+
hw: { serial_no: 'SERIAL-1' },
|
|
99
|
+
fw: { application: { version: '5.0.0' } },
|
|
100
|
+
se1: { application: { version: '1.0.0' } },
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
const device = createV2Device(typedCall);
|
|
104
|
+
device.updateState(
|
|
105
|
+
{
|
|
106
|
+
protocol: 'V2',
|
|
107
|
+
status: { mode: 'notInitialized', initialized: false },
|
|
108
|
+
},
|
|
109
|
+
'device-status'
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const state = await device.getDeviceState({ refreshSections: ['versions'] });
|
|
113
|
+
|
|
114
|
+
expect(state.status.mode).toBe('notInitialized');
|
|
115
|
+
expect(state.status.initialized).toBe(false);
|
|
116
|
+
expect(state.versions.se01).toBe('1.0.0');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test.each(['bootloader', 'romloader'] as const)(
|
|
120
|
+
'does not call DeviceStatusGet in %s mode',
|
|
121
|
+
async mode => {
|
|
122
|
+
const typedCall = jest.fn();
|
|
123
|
+
const device = createV2Device(typedCall);
|
|
124
|
+
device.updateState({ protocol: 'V2', status: { mode } }, 'initialize');
|
|
125
|
+
|
|
126
|
+
const state = await device.getDeviceState({ refreshSections: ['status'] });
|
|
127
|
+
|
|
128
|
+
expect(state.status.mode).toBe(mode);
|
|
129
|
+
expect(typedCall).not.toHaveBeenCalled();
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
test('refreshes Protocol V2 status only when explicitly requested in normal mode', async () => {
|
|
134
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
135
|
+
message: { init_states: true, unlocked: true, device_id: 'device-1' },
|
|
136
|
+
});
|
|
137
|
+
const device = createV2Device(typedCall);
|
|
138
|
+
device.updateState({ protocol: 'V2', status: { mode: 'normal' } }, 'initialize');
|
|
139
|
+
|
|
140
|
+
const state = await device.getDeviceState({ refreshSections: ['status'] });
|
|
141
|
+
|
|
142
|
+
expect(typedCall).toHaveBeenCalledWith('DeviceStatusGet', 'DeviceStatus', {});
|
|
143
|
+
expect(state.status.unlocked).toBe(true);
|
|
144
|
+
expect(state.identity.deviceId).toBe('device-1');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('refreshes Protocol V2 settings without requesting status', async () => {
|
|
148
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
149
|
+
message: {
|
|
150
|
+
label: 'Renamed Pro 2',
|
|
151
|
+
language: 'ja-JP',
|
|
152
|
+
brightness: 70,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const device = createV2Device(typedCall);
|
|
156
|
+
device.updateState({ protocol: 'V2', status: { mode: 'normal' } }, 'initialize');
|
|
157
|
+
|
|
158
|
+
const state = await device.getDeviceState({ refreshSections: ['settings'] });
|
|
159
|
+
|
|
160
|
+
expect(typedCall).toHaveBeenCalledWith('DeviceSettingsGet', 'DeviceSettings', {});
|
|
161
|
+
expect(typedCall).not.toHaveBeenCalledWith(
|
|
162
|
+
'DeviceStatusGet',
|
|
163
|
+
expect.anything(),
|
|
164
|
+
expect.anything()
|
|
165
|
+
);
|
|
166
|
+
expect(state.identity.label).toBe('Renamed Pro 2');
|
|
167
|
+
expect(state.settings.language).toBe('ja-JP');
|
|
168
|
+
expect(state.settings.brightness).toBe(70);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('refreshes Protocol V2 status before settings in a combined read', async () => {
|
|
172
|
+
const typedCall = jest.fn().mockImplementation((requestType: string) => {
|
|
173
|
+
if (requestType === 'DeviceStatusGet') {
|
|
174
|
+
return {
|
|
175
|
+
message: { init_states: true, unlocked: false, device_id: 'device-1' },
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (requestType === 'DeviceSettingsGet') {
|
|
179
|
+
return { message: { label: 'Renamed Pro 2' } };
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`Unexpected request: ${requestType}`);
|
|
182
|
+
});
|
|
183
|
+
const device = createV2Device(typedCall);
|
|
184
|
+
device.updateState({ protocol: 'V2', status: { mode: 'normal' } }, 'initialize');
|
|
185
|
+
|
|
186
|
+
const state = await device.getDeviceState({ refreshSections: ['status', 'settings'] });
|
|
187
|
+
|
|
188
|
+
expect(typedCall.mock.calls.map(call => call[0])).toEqual([
|
|
189
|
+
'DeviceStatusGet',
|
|
190
|
+
'DeviceSettingsGet',
|
|
191
|
+
]);
|
|
192
|
+
expect(state.status.unlocked).toBe(false);
|
|
193
|
+
expect(state.identity.label).toBe('Renamed Pro 2');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('keeps the refreshed status when a following settings read fails', async () => {
|
|
197
|
+
const typedCall = jest.fn().mockImplementation((requestType: string) => {
|
|
198
|
+
if (requestType === 'DeviceStatusGet') {
|
|
199
|
+
return {
|
|
200
|
+
message: { init_states: true, unlocked: false, device_id: 'device-1' },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
throw Object.assign(new Error('Device locked'), {
|
|
204
|
+
errorCode: HardwareErrorCode.DeviceLocked,
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
const device = createV2Device(typedCall);
|
|
208
|
+
device.updateState(
|
|
209
|
+
{ protocol: 'V2', status: { mode: 'normal', unlocked: true } },
|
|
210
|
+
'initialize'
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
await expect(
|
|
214
|
+
device.getDeviceState({ refreshSections: ['status', 'settings'] })
|
|
215
|
+
).rejects.toMatchObject({ errorCode: HardwareErrorCode.DeviceLocked });
|
|
216
|
+
|
|
217
|
+
const state = await device.getDeviceState();
|
|
218
|
+
expect(state.status.unlocked).toBe(false);
|
|
219
|
+
expect(state.identity.deviceId).toBe('device-1');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('rejects an explicit settings refresh without mutating cached state', async () => {
|
|
223
|
+
const typedCall = jest.fn().mockRejectedValue(
|
|
224
|
+
Object.assign(new Error('Device locked'), {
|
|
225
|
+
errorCode: HardwareErrorCode.DeviceLocked,
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
const device = createV2Device(typedCall);
|
|
229
|
+
device.updateState(
|
|
230
|
+
{
|
|
231
|
+
protocol: 'V2',
|
|
232
|
+
identity: { label: 'Persisted label' },
|
|
233
|
+
status: { mode: 'normal', unlocked: false },
|
|
234
|
+
settings: { language: 'en-US' },
|
|
235
|
+
},
|
|
236
|
+
'initialize'
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
await expect(device.getDeviceState({ refreshSections: ['settings'] })).rejects.toMatchObject({
|
|
240
|
+
errorCode: HardwareErrorCode.DeviceLocked,
|
|
241
|
+
});
|
|
242
|
+
const state = await device.getDeviceState();
|
|
243
|
+
|
|
244
|
+
expect(state.identity.label).toBe('Persisted label');
|
|
245
|
+
expect(state.settings.language).toBe('en-US');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test('aggregates OnekeyGetFeatures into a Protocol V1 firmware refresh', async () => {
|
|
249
|
+
const typedCall = jest.fn().mockImplementation((requestType: string) => {
|
|
250
|
+
if (requestType === 'GetFeatures') {
|
|
251
|
+
return {
|
|
252
|
+
message: {
|
|
253
|
+
onekey_device_type: 'PRO',
|
|
254
|
+
label: 'Pro Wallet',
|
|
255
|
+
initialized: true,
|
|
256
|
+
onekey_firmware_version: '4.10.0',
|
|
257
|
+
onekey_firmware_build_id: 'firmware-build',
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
if (requestType === 'OnekeyGetFeatures') {
|
|
262
|
+
return {
|
|
263
|
+
message: {
|
|
264
|
+
onekey_firmware_version: '4.10.1',
|
|
265
|
+
onekey_board_build_id: 'board-build',
|
|
266
|
+
onekey_se01_boot_version: '1.0.0',
|
|
267
|
+
onekey_se01_boot_build_id: 'se-boot-build',
|
|
268
|
+
onekey_se01_boot_hash: 'abcd',
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
throw new Error(`Unexpected request: ${requestType}`);
|
|
273
|
+
});
|
|
274
|
+
const device = createV1Device(typedCall);
|
|
275
|
+
|
|
276
|
+
const state = await device.getDeviceState({
|
|
277
|
+
refreshSections: ['identity', 'versions', 'verification'],
|
|
278
|
+
includeRaw: true,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(typedCall.mock.calls.map(call => call[0])).toEqual(['GetFeatures', 'OnekeyGetFeatures']);
|
|
282
|
+
expect(state.versions.firmware).toBe('4.10.1');
|
|
283
|
+
expect(state.versions.se01Boot).toBe('1.0.0');
|
|
284
|
+
expect(state.verification).toMatchObject({
|
|
285
|
+
firmwareBuildId: 'firmware-build',
|
|
286
|
+
boardBuildId: 'board-build',
|
|
287
|
+
se01BootBuildId: 'se-boot-build',
|
|
288
|
+
se01BootHash: 'abcd',
|
|
289
|
+
});
|
|
290
|
+
expect(state.raw?.protocolV1OneKeyFeatures).toMatchObject({
|
|
291
|
+
onekey_board_build_id: 'board-build',
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test('does not clear Protocol V1 firmware details during a later runtime refresh', async () => {
|
|
296
|
+
let getFeaturesCount = 0;
|
|
297
|
+
const typedCall = jest.fn().mockImplementation((requestType: string) => {
|
|
298
|
+
if (requestType === 'GetFeatures') {
|
|
299
|
+
getFeaturesCount += 1;
|
|
300
|
+
return {
|
|
301
|
+
message: {
|
|
302
|
+
onekey_device_type: 'PRO',
|
|
303
|
+
initialized: true,
|
|
304
|
+
unlocked: getFeaturesCount === 1,
|
|
305
|
+
major_version: 4,
|
|
306
|
+
minor_version: 10,
|
|
307
|
+
patch_version: 1,
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
if (requestType === 'OnekeyGetFeatures') {
|
|
312
|
+
return {
|
|
313
|
+
message: {
|
|
314
|
+
onekey_se01_boot_version: '1.0.0',
|
|
315
|
+
onekey_se01_boot_build_id: 'se-boot-build',
|
|
316
|
+
onekey_se01_boot_hash: 'abcd',
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
throw new Error(`Unexpected request: ${requestType}`);
|
|
321
|
+
});
|
|
322
|
+
const device = createV1Device(typedCall);
|
|
323
|
+
|
|
324
|
+
await device.getDeviceState({
|
|
325
|
+
refreshSections: ['identity', 'versions', 'verification'],
|
|
326
|
+
});
|
|
327
|
+
const state = await device.getDeviceState({ refreshSections: ['status'] });
|
|
328
|
+
|
|
329
|
+
expect(state.status.unlocked).toBe(false);
|
|
330
|
+
expect(state.versions.se01Boot).toBe('1.0.0');
|
|
331
|
+
expect(state.verification).toMatchObject({
|
|
332
|
+
se01BootBuildId: 'se-boot-build',
|
|
333
|
+
se01BootHash: 'abcd',
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test('reloads Protocol V2 DeviceInfo after a physical reconnect', async () => {
|
|
338
|
+
const typedCall = jest.fn().mockResolvedValue({
|
|
339
|
+
message: {
|
|
340
|
+
protocol_version: 1,
|
|
341
|
+
hw: { serial_no: 'SERIAL-1' },
|
|
342
|
+
fw: { bootloader: { version: '1.0.0' } },
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
const device = createV2Device(typedCall);
|
|
346
|
+
device.updateState(
|
|
347
|
+
{
|
|
348
|
+
protocol: 'V2',
|
|
349
|
+
identity: { deviceId: 'wallet-1', serialNo: 'SERIAL-1' },
|
|
350
|
+
status: { mode: 'normal', initialized: true, unlocked: true },
|
|
351
|
+
},
|
|
352
|
+
'initialize'
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
device.markTransportDisconnected();
|
|
356
|
+
await device.initialize();
|
|
357
|
+
|
|
358
|
+
expect(typedCall).toHaveBeenCalledWith(
|
|
359
|
+
'DeviceInfoGet',
|
|
360
|
+
'DeviceInfo',
|
|
361
|
+
expect.anything(),
|
|
362
|
+
expect.anything()
|
|
363
|
+
);
|
|
364
|
+
expect(device.state?.status.mode).toBe('bootloader');
|
|
365
|
+
expect(device.state?.identity.deviceId).toBeNull();
|
|
366
|
+
});
|
|
367
|
+
});
|