@onekeyfe/hd-core 1.2.2-alpha.100 → 1.2.2-alpha.12
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__/AllNetworkGetAddressBase.tracing.test.ts +20 -4
- package/__tests__/DeviceCommands.test.ts +13 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/check-firmware-release-protocol-v2.test.ts +0 -2
- package/__tests__/device-lifecycle-events.test.ts +86 -0
- package/__tests__/deviceUploadNft.test.ts +68 -0
- package/__tests__/evmSignTypedData.test.ts +42 -0
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +825 -12
- package/__tests__/logBlockEvent.test.ts +45 -122
- package/__tests__/open-wallet-session.test.ts +781 -69
- package/__tests__/pro2HostAssetPackage.test.ts +165 -0
- package/__tests__/protocol-v2-resources.test.ts +7 -4
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -1
- package/__tests__/protocol-v2.test.ts +925 -97
- package/__tests__/protocolV2FileWrite.test.ts +40 -0
- package/dist/api/FirmwareUpdateV4.d.ts +5 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +2 -2
- package/dist/api/helpers/protocolV2FileWrite.d.ts +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.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 +3 -1
- package/dist/core/index.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/DeviceConnector.d.ts +1 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +3 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.js +2511 -1538
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +2 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +3 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/types/settings.d.ts +2 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -0
- package/dist/utils/deviceFeaturesUtils.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/pro2HostAssetPackage.d.ts +8 -0
- package/dist/utils/pro2HostAssetPackage.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +474 -83
- package/src/api/OpenWalletSession.ts +39 -12
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +5 -2
- package/src/api/evm/EVMSignTypedData.ts +1 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +9 -3
- package/src/api/helpers/protocolV2FileWrite.ts +11 -5
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +7 -1
- package/src/api/protocol-v2/DeviceUploadNft.ts +31 -8
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +33 -8
- package/src/api/protocol-v2/helpers.ts +8 -0
- package/src/core/RequestQueue.ts +16 -1
- package/src/core/index.ts +164 -26
- package/src/data/messages/messages-protocol-v2.json +1589 -1375
- package/src/device/Device.ts +3 -1
- package/src/device/DeviceConnector.ts +7 -3
- package/src/events/logBlockEvent.ts +6 -75
- package/src/events/ui-request.ts +3 -0
- package/src/protocols/protocol-v2/resources.ts +9 -1
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +8 -1
- package/src/protocols/protocol-v2/walletSession.ts +223 -56
- package/src/types/settings.ts +4 -2
- package/src/utils/deviceFeaturesUtils.ts +4 -0
- package/src/utils/pro2HostAssetPackage.ts +400 -0
|
@@ -95,7 +95,8 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
95
95
|
'hidden-state',
|
|
96
96
|
false,
|
|
97
97
|
undefined,
|
|
98
|
-
|
|
98
|
+
undefined,
|
|
99
|
+
undefined
|
|
99
100
|
);
|
|
100
101
|
expect(calls).toEqual(['resume-hidden-session', 'run-chain-method']);
|
|
101
102
|
expect(typedCall).not.toHaveBeenCalled();
|
|
@@ -173,7 +174,13 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
173
174
|
0
|
|
174
175
|
);
|
|
175
176
|
|
|
176
|
-
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
177
|
+
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
178
|
+
'hidden-state',
|
|
179
|
+
false,
|
|
180
|
+
undefined,
|
|
181
|
+
true,
|
|
182
|
+
undefined
|
|
183
|
+
);
|
|
177
184
|
expect(calls).toEqual(['resume-cardano-session', 'run-cardano-method']);
|
|
178
185
|
expect(typedCall).not.toHaveBeenCalled();
|
|
179
186
|
});
|
|
@@ -212,7 +219,10 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
212
219
|
bundle: [],
|
|
213
220
|
},
|
|
214
221
|
});
|
|
215
|
-
method.protocolV2UnlockContext = {
|
|
222
|
+
method.protocolV2UnlockContext = {
|
|
223
|
+
preflightCompleted: true,
|
|
224
|
+
preflightMainPinSelected: true,
|
|
225
|
+
};
|
|
216
226
|
const typedCall = jest.fn();
|
|
217
227
|
method.device = {
|
|
218
228
|
checkPassphraseStateSafety,
|
|
@@ -250,7 +260,13 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
250
260
|
0
|
|
251
261
|
);
|
|
252
262
|
|
|
253
|
-
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
263
|
+
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
264
|
+
undefined,
|
|
265
|
+
true,
|
|
266
|
+
undefined,
|
|
267
|
+
undefined,
|
|
268
|
+
true
|
|
269
|
+
);
|
|
254
270
|
expect(calls).toEqual(['resume-standard-session', 'run-chain-method']);
|
|
255
271
|
expect(typedCall).not.toHaveBeenCalled();
|
|
256
272
|
});
|
|
@@ -126,6 +126,19 @@ describe('DeviceCommands failure mapping', () => {
|
|
|
126
126
|
);
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
it('preserves the Protocol V2 peer-removed pairing error code', async () => {
|
|
130
|
+
const commands = createCommands();
|
|
131
|
+
const transportError = Object.assign(new Error('Peer removed pairing information'), {
|
|
132
|
+
errorCode: HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
133
|
+
});
|
|
134
|
+
commands.mainId = 'main-id';
|
|
135
|
+
commands.transport = {
|
|
136
|
+
call: jest.fn().mockRejectedValue(transportError),
|
|
137
|
+
} as any;
|
|
138
|
+
|
|
139
|
+
await expect(commands._commonCall('DeviceInfoGet', {})).rejects.toBe(transportError);
|
|
140
|
+
});
|
|
141
|
+
|
|
129
142
|
it('logs canonical DeviceStatus response fields without exposing the device ID', async () => {
|
|
130
143
|
const commands = createCommands();
|
|
131
144
|
const log = getLogger(LoggerNames.DeviceCommands);
|
|
@@ -33,8 +33,6 @@ const validComponentIntegrity = {
|
|
|
33
33
|
const release: IFirmwareReleaseInfo = {
|
|
34
34
|
required: true,
|
|
35
35
|
version: [2, 0, 0],
|
|
36
|
-
url: 'https://example.com/application-p1.bin',
|
|
37
|
-
fingerprint: 'release-fingerprint',
|
|
38
36
|
changelog: {
|
|
39
37
|
'zh-CN': '更新',
|
|
40
38
|
'en-US': 'Update',
|
|
@@ -16,8 +16,6 @@ jest.mock('../src/data/config', () => ({
|
|
|
16
16
|
const release: IFirmwareReleaseInfo = {
|
|
17
17
|
required: false,
|
|
18
18
|
version: [2, 0, 0],
|
|
19
|
-
url: 'https://example.com/application-p1.okpkg',
|
|
20
|
-
fingerprint: 'release-fingerprint',
|
|
21
19
|
changelog: {
|
|
22
20
|
'zh-CN': '更新',
|
|
23
21
|
'en-US': 'Update',
|
|
@@ -2,11 +2,14 @@ import { EDeviceType, ERRORS, HardwareErrorCode, createDeferred } from '@onekeyf
|
|
|
2
2
|
import { DeviceType, TRANSPORT_EVENT } from '@onekeyfe/hd-transport';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
+
cancel,
|
|
5
6
|
initConnector,
|
|
6
7
|
initCore,
|
|
7
8
|
isMissingDetectedProtocolV2Error,
|
|
9
|
+
isProtocolV2PeerRemovedPairingError,
|
|
8
10
|
isRetryableBleConnectionError,
|
|
9
11
|
isRetryableBleProtocolV2ProbeError,
|
|
12
|
+
resolveBleConnectProtocol,
|
|
10
13
|
} from '../src/core';
|
|
11
14
|
import { DataManager } from '../src/data-manager';
|
|
12
15
|
import TransportManager from '../src/data-manager/TransportManager';
|
|
@@ -70,6 +73,19 @@ describe('public device lifecycle events', () => {
|
|
|
70
73
|
jest.restoreAllMocks();
|
|
71
74
|
});
|
|
72
75
|
|
|
76
|
+
test('prefers Protocol V2 only when the method contract is explicitly V2-only', () => {
|
|
77
|
+
const createMethod = (protocols: readonly ('V1' | 'V2')[], connectProtocol?: 'V1' | 'V2') =>
|
|
78
|
+
({
|
|
79
|
+
payload: { connectProtocol },
|
|
80
|
+
getSupportedProtocols: () => protocols,
|
|
81
|
+
} as never);
|
|
82
|
+
|
|
83
|
+
expect(resolveBleConnectProtocol(createMethod(['V2']))).toBe('V2');
|
|
84
|
+
expect(resolveBleConnectProtocol(createMethod(['V1']))).toBeUndefined();
|
|
85
|
+
expect(resolveBleConnectProtocol(createMethod(['V1', 'V2']))).toBeUndefined();
|
|
86
|
+
expect(resolveBleConnectProtocol(createMethod(['V2'], 'V1'))).toBe('V1');
|
|
87
|
+
});
|
|
88
|
+
|
|
73
89
|
test('registers the shared device lifecycle listeners exactly once', async () => {
|
|
74
90
|
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
75
91
|
core = initCore();
|
|
@@ -105,6 +121,58 @@ describe('public device lifecycle events', () => {
|
|
|
105
121
|
expect(context.getPrePendingCallPromise('device-a')).toBe(replacementCleanup.promise);
|
|
106
122
|
});
|
|
107
123
|
|
|
124
|
+
test('cancels only requests associated with the requested connect id', () => {
|
|
125
|
+
core = initCore();
|
|
126
|
+
const context = (core as any).getCoreContext();
|
|
127
|
+
const deviceA = {
|
|
128
|
+
mainId: 'transport-session-a',
|
|
129
|
+
getConnectId: jest.fn(() => 'serial-a'),
|
|
130
|
+
interruptionFromUser: jest.fn().mockResolvedValue(undefined),
|
|
131
|
+
};
|
|
132
|
+
const deviceB = {
|
|
133
|
+
mainId: 'device-b',
|
|
134
|
+
getConnectId: jest.fn(() => 'serial-b'),
|
|
135
|
+
interruptionFromUser: jest.fn().mockResolvedValue(undefined),
|
|
136
|
+
};
|
|
137
|
+
const taskA = context.requestQueue.createTask({
|
|
138
|
+
responseID: 101,
|
|
139
|
+
connectId: '',
|
|
140
|
+
device: deviceA,
|
|
141
|
+
} as never);
|
|
142
|
+
const taskB = context.requestQueue.createTask({
|
|
143
|
+
responseID: 102,
|
|
144
|
+
connectId: 'device-b',
|
|
145
|
+
device: deviceB,
|
|
146
|
+
} as never);
|
|
147
|
+
const signalA = taskA.abortController?.signal;
|
|
148
|
+
const signalB = taskB.abortController?.signal;
|
|
149
|
+
|
|
150
|
+
cancel(context, 'serial-a');
|
|
151
|
+
|
|
152
|
+
expect(signalA?.aborted).toBe(true);
|
|
153
|
+
expect(context.requestQueue.getTask(taskA.id)).toBeUndefined();
|
|
154
|
+
expect(signalB?.aborted).toBe(false);
|
|
155
|
+
expect(context.requestQueue.getTask(taskB.id)).toBe(taskB);
|
|
156
|
+
expect(deviceA.interruptionFromUser).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(deviceB.interruptionFromUser).not.toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('aborts every request before cancel-all rejects WebUSB tasks', () => {
|
|
161
|
+
jest.spyOn(DataManager, 'getSettings').mockReturnValue('webusb' as never);
|
|
162
|
+
core = initCore();
|
|
163
|
+
const context = (core as any).getCoreContext();
|
|
164
|
+
const task = context.requestQueue.createTask({
|
|
165
|
+
responseID: 103,
|
|
166
|
+
connectId: 'webusb-device',
|
|
167
|
+
} as never);
|
|
168
|
+
const signal = task.abortController?.signal;
|
|
169
|
+
|
|
170
|
+
cancel(context);
|
|
171
|
+
|
|
172
|
+
expect(signal?.aborted).toBe(true);
|
|
173
|
+
expect(context.requestQueue.getTask(task.id)).toBeUndefined();
|
|
174
|
+
});
|
|
175
|
+
|
|
108
176
|
test('keeps shared device lifecycle listeners across a device cache reset', () => {
|
|
109
177
|
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
110
178
|
core = initCore();
|
|
@@ -278,6 +346,7 @@ describe('public device lifecycle events', () => {
|
|
|
278
346
|
test.each([
|
|
279
347
|
[HardwareErrorCode.RuntimeError, true],
|
|
280
348
|
[HardwareErrorCode.BleDeviceBondError, false],
|
|
349
|
+
[HardwareErrorCode.BlePeerRemovedPairingInformation, false],
|
|
281
350
|
] as const)(
|
|
282
351
|
'retries a Protocol V2 probe mismatch with error code %s: %s',
|
|
283
352
|
(errorCode, expected) => {
|
|
@@ -297,6 +366,7 @@ describe('public device lifecycle events', () => {
|
|
|
297
366
|
[HardwareErrorCode.BleTimeoutError, true],
|
|
298
367
|
[HardwareErrorCode.PollingTimeout, false],
|
|
299
368
|
[HardwareErrorCode.BleDeviceBondError, false],
|
|
369
|
+
[HardwareErrorCode.BlePeerRemovedPairingInformation, false],
|
|
300
370
|
] as const)('retries a BLE connection error with error code %s: %s', (errorCode, expected) => {
|
|
301
371
|
const method = { payload: { connectProtocol: 'V2' } } as never;
|
|
302
372
|
const error = {
|
|
@@ -307,6 +377,22 @@ describe('public device lifecycle events', () => {
|
|
|
307
377
|
expect(isRetryableBleConnectionError(method, error)).toBe(expected);
|
|
308
378
|
});
|
|
309
379
|
|
|
380
|
+
test.each([
|
|
381
|
+
['V2', true],
|
|
382
|
+
['V1', false],
|
|
383
|
+
[undefined, false],
|
|
384
|
+
] as const)(
|
|
385
|
+
'treats peer-removed pairing as terminal only for Protocol %s: %s',
|
|
386
|
+
(connectProtocol, expected) => {
|
|
387
|
+
const method = { payload: { connectProtocol } } as never;
|
|
388
|
+
const error = {
|
|
389
|
+
errorCode: HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
expect(isProtocolV2PeerRemovedPairingError(method, error)).toBe(expected);
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
|
|
310
396
|
test('converts an internal transport disconnect into a public KnownDevice snapshot', () => {
|
|
311
397
|
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
312
398
|
core = initCore();
|
|
@@ -32,10 +32,12 @@ const createMethod = ({
|
|
|
32
32
|
typedCall,
|
|
33
33
|
supportedMessages = [60802, 60805, 60808, 61500],
|
|
34
34
|
useFullBundle = false,
|
|
35
|
+
firmwareVersion = '1.0.0',
|
|
35
36
|
}: {
|
|
36
37
|
typedCall: jest.Mock;
|
|
37
38
|
supportedMessages?: number[];
|
|
38
39
|
useFullBundle?: boolean;
|
|
40
|
+
firmwareVersion?: string;
|
|
39
41
|
}) => {
|
|
40
42
|
const method = new DeviceUploadNft({
|
|
41
43
|
id: 1,
|
|
@@ -52,6 +54,7 @@ const createMethod = ({
|
|
|
52
54
|
});
|
|
53
55
|
(method as any).device = {
|
|
54
56
|
commands: { typedCall },
|
|
57
|
+
state: { versions: { firmware: firmwareVersion } },
|
|
55
58
|
ensureProtocolV2RuntimeContext: jest.fn(() =>
|
|
56
59
|
Promise.resolve({
|
|
57
60
|
version: 2,
|
|
@@ -60,6 +63,7 @@ const createMethod = ({
|
|
|
60
63
|
})
|
|
61
64
|
),
|
|
62
65
|
getCurrentFirmwareType: jest.fn(),
|
|
66
|
+
getCurrentFirmwareVersionString: jest.fn(() => firmwareVersion),
|
|
63
67
|
};
|
|
64
68
|
method.postMessage = jest.fn();
|
|
65
69
|
|
|
@@ -202,6 +206,70 @@ describe('DeviceUploadNft', () => {
|
|
|
202
206
|
});
|
|
203
207
|
});
|
|
204
208
|
|
|
209
|
+
test('uploads one host asset package on firmware 1.0.1', async () => {
|
|
210
|
+
const typedCall = jest.fn((request: string, _response: string, params: any) => {
|
|
211
|
+
if (request === 'FilesystemFileWrite') return fileWriteSuccess(params);
|
|
212
|
+
if (request === 'NftUpdate') return { message: { message: 'NFT updated' } };
|
|
213
|
+
throw new Error(`Unexpected request: ${request}`);
|
|
214
|
+
});
|
|
215
|
+
const method = createMethod({
|
|
216
|
+
typedCall,
|
|
217
|
+
supportedMessages: [60805, 61500],
|
|
218
|
+
firmwareVersion: '1.0.1',
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const result = await method.run();
|
|
222
|
+
|
|
223
|
+
const requests = typedCall.mock.calls.map(call => call[0]);
|
|
224
|
+
expect(requests).not.toContain('FilesystemPathInfoQuery');
|
|
225
|
+
expect(requests).not.toContain('FilesystemDirList');
|
|
226
|
+
const fileWrites = typedCall.mock.calls.filter(call => call[0] === 'FilesystemFileWrite');
|
|
227
|
+
expect(new Set(fileWrites.map(call => call[2].file.path))).toEqual(
|
|
228
|
+
new Set(['vol1:/nft/nft-deadbeef-1760000000000.okpkg'])
|
|
229
|
+
);
|
|
230
|
+
expect(fileWrites[0][2].file.data.subarray(0, 4)).toEqual(
|
|
231
|
+
new Uint8Array([0x4f, 0x4b, 0x50, 0x50])
|
|
232
|
+
);
|
|
233
|
+
expect(typedCall).toHaveBeenLastCalledWith(
|
|
234
|
+
'NftUpdate',
|
|
235
|
+
'Success',
|
|
236
|
+
{ file_name_no_ext: result.basename },
|
|
237
|
+
{ timeoutMs: 15_000 }
|
|
238
|
+
);
|
|
239
|
+
expect(result).toMatchObject({
|
|
240
|
+
imagePath: 'vol1:/nft/nft-deadbeef-1760000000000.bin',
|
|
241
|
+
thumbnailPath: 'vol1:/nft/nft-deadbeef-1760000000000_m.bin',
|
|
242
|
+
metadataPath: 'vol1:/nft/nft-deadbeef-1760000000000.json',
|
|
243
|
+
nftUpdated: true,
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('keeps the legacy upload flow on a 1.0.1 prerelease', async () => {
|
|
248
|
+
const typedCall = jest.fn((request: string, _response: string, params: any) => {
|
|
249
|
+
if (request === 'FilesystemPathInfoQuery') {
|
|
250
|
+
return { message: { exist: true, directory: true } };
|
|
251
|
+
}
|
|
252
|
+
if (request === 'FilesystemDirList') {
|
|
253
|
+
return { message: { path: 'vol1:/nft', child_files: '' } };
|
|
254
|
+
}
|
|
255
|
+
if (request === 'FilesystemFileWrite') return fileWriteSuccess(params);
|
|
256
|
+
if (request === 'NftUpdate') return { message: {} };
|
|
257
|
+
throw new Error(`Unexpected request: ${request}`);
|
|
258
|
+
});
|
|
259
|
+
const method = createMethod({ typedCall, firmwareVersion: '1.0.1-beta.1' });
|
|
260
|
+
|
|
261
|
+
await method.run();
|
|
262
|
+
|
|
263
|
+
const requests = typedCall.mock.calls.map(call => call[0]);
|
|
264
|
+
expect(requests).toContain('FilesystemPathInfoQuery');
|
|
265
|
+
expect(requests).toContain('FilesystemDirList');
|
|
266
|
+
const paths = typedCall.mock.calls
|
|
267
|
+
.filter(call => call[0] === 'FilesystemFileWrite')
|
|
268
|
+
.map(call => call[2].file.path as string);
|
|
269
|
+
expect(paths.some(path => path.endsWith('.okpkg'))).toBe(false);
|
|
270
|
+
expect(paths).toContain('vol1:/nft/nft-deadbeef-1760000000000.bin');
|
|
271
|
+
});
|
|
272
|
+
|
|
205
273
|
test('treats a missing NFT directory as empty before the first upload', async () => {
|
|
206
274
|
const typedCall = jest.fn((request: string, _response: string, params: any) => {
|
|
207
275
|
if (request === 'FilesystemPathInfoQuery') {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
1
3
|
import EVMSignTypedData from '../src/api/evm/EVMSignTypedData';
|
|
2
4
|
|
|
3
5
|
import type { EthereumSignTypedDataMessage, EthereumSignTypedDataTypes } from '../src/types';
|
|
@@ -577,3 +579,43 @@ describe('EVMSignTypedData — OneKey Pro Safe Protocol V1', () => {
|
|
|
577
579
|
});
|
|
578
580
|
});
|
|
579
581
|
});
|
|
582
|
+
|
|
583
|
+
describe('EVMSignTypedData — Protocol V2 data size routing', () => {
|
|
584
|
+
const buildSafeTxData = (
|
|
585
|
+
dataSize: number
|
|
586
|
+
): EthereumSignTypedDataMessage<EthereumSignTypedDataTypes> =>
|
|
587
|
+
({
|
|
588
|
+
types: {
|
|
589
|
+
EIP712Domain: [],
|
|
590
|
+
SafeTx: [{ name: 'data', type: 'bytes' }],
|
|
591
|
+
},
|
|
592
|
+
primaryType: 'SafeTx',
|
|
593
|
+
domain: {},
|
|
594
|
+
message: { data: `0x${'ab'.repeat(dataSize)}` },
|
|
595
|
+
} as EthereumSignTypedDataMessage<EthereumSignTypedDataTypes>);
|
|
596
|
+
|
|
597
|
+
test.each([EDeviceType.Pro2, EDeviceType.Neo])(
|
|
598
|
+
'keeps SafeTx data up to 1536 bytes on the structured route for %s',
|
|
599
|
+
deviceType => {
|
|
600
|
+
const data = buildSafeTxData(1316);
|
|
601
|
+
const method = createMethod(data);
|
|
602
|
+
method.device.getCurrentDeviceType = jest.fn(() => deviceType);
|
|
603
|
+
method.device.getCurrentFirmwareVersionString = jest.fn(() => '1.0.0');
|
|
604
|
+
|
|
605
|
+
expect(method.hasBiggerData(data)).toBe(false);
|
|
606
|
+
expect(method.hasBiggerData(buildSafeTxData(1536))).toBe(false);
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
test.each([EDeviceType.Pro2, EDeviceType.Neo])(
|
|
611
|
+
'falls back to the hash route above 1536 bytes for %s',
|
|
612
|
+
deviceType => {
|
|
613
|
+
const data = buildSafeTxData(1537);
|
|
614
|
+
const method = createMethod(data);
|
|
615
|
+
method.device.getCurrentDeviceType = jest.fn(() => deviceType);
|
|
616
|
+
method.device.getCurrentFirmwareVersionString = jest.fn(() => '1.0.0');
|
|
617
|
+
|
|
618
|
+
expect(method.hasBiggerData(data)).toBe(true);
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
});
|