@onekeyfe/hd-core 1.2.2-alpha.1 → 1.2.2-alpha.100
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 +4 -20
- package/__tests__/DeviceCommands.test.ts +0 -13
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
- package/__tests__/device-lifecycle-events.test.ts +0 -19
- package/__tests__/deviceUploadNft.test.ts +0 -68
- package/__tests__/evmSignTypedData.test.ts +0 -42
- package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -825
- package/__tests__/open-wallet-session.test.ts +1 -127
- package/__tests__/protocol-v2-resources.test.ts +4 -7
- package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
- package/__tests__/protocol-v2.test.ts +27 -710
- package/dist/api/FirmwareUpdateV4.d.ts +0 -4
- 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/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/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/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/ui-request.d.ts +0 -3
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +5 -21
- package/dist/index.js +402 -1136
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
- 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 +0 -3
- 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/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +75 -434
- package/src/api/OpenWalletSession.ts +9 -39
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
- package/src/api/evm/EVMSignTypedData.ts +0 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
- package/src/api/protocol-v2/DeviceUploadNft.ts +8 -31
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -27
- package/src/api/protocol-v2/helpers.ts +0 -8
- package/src/core/index.ts +10 -121
- package/src/data/messages/messages-protocol-v2.json +1 -111
- package/src/device/Device.ts +1 -3
- package/src/device/DeviceConnector.ts +3 -7
- package/src/events/ui-request.ts +0 -3
- package/src/protocols/protocol-v2/resources.ts +1 -9
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
- package/src/protocols/protocol-v2/walletSession.ts +22 -65
- package/src/types/settings.ts +2 -4
- package/src/utils/deviceFeaturesUtils.ts +0 -4
- package/__tests__/pro2HostAssetPackage.test.ts +0 -58
- package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
- package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
- package/src/utils/pro2HostAssetPackage.ts +0 -354
|
@@ -95,8 +95,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
95
95
|
'hidden-state',
|
|
96
96
|
false,
|
|
97
97
|
undefined,
|
|
98
|
-
false
|
|
99
|
-
undefined
|
|
98
|
+
false
|
|
100
99
|
);
|
|
101
100
|
expect(calls).toEqual(['resume-hidden-session', 'run-chain-method']);
|
|
102
101
|
expect(typedCall).not.toHaveBeenCalled();
|
|
@@ -174,13 +173,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
174
173
|
0
|
|
175
174
|
);
|
|
176
175
|
|
|
177
|
-
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
178
|
-
'hidden-state',
|
|
179
|
-
false,
|
|
180
|
-
undefined,
|
|
181
|
-
true,
|
|
182
|
-
undefined
|
|
183
|
-
);
|
|
176
|
+
expect(checkPassphraseStateSafety).toHaveBeenCalledWith('hidden-state', false, undefined, true);
|
|
184
177
|
expect(calls).toEqual(['resume-cardano-session', 'run-cardano-method']);
|
|
185
178
|
expect(typedCall).not.toHaveBeenCalled();
|
|
186
179
|
});
|
|
@@ -219,10 +212,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
219
212
|
bundle: [],
|
|
220
213
|
},
|
|
221
214
|
});
|
|
222
|
-
method.protocolV2UnlockContext = {
|
|
223
|
-
preflightCompleted: true,
|
|
224
|
-
preflightMainPinSelected: true,
|
|
225
|
-
};
|
|
215
|
+
method.protocolV2UnlockContext = { preflightCompleted: true };
|
|
226
216
|
const typedCall = jest.fn();
|
|
227
217
|
method.device = {
|
|
228
218
|
checkPassphraseStateSafety,
|
|
@@ -260,13 +250,7 @@ describe('AllNetworkGetAddressBase tracing', () => {
|
|
|
260
250
|
0
|
|
261
251
|
);
|
|
262
252
|
|
|
263
|
-
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(
|
|
264
|
-
undefined,
|
|
265
|
-
true,
|
|
266
|
-
undefined,
|
|
267
|
-
false,
|
|
268
|
-
true
|
|
269
|
-
);
|
|
253
|
+
expect(checkPassphraseStateSafety).toHaveBeenCalledWith(undefined, true, undefined, false);
|
|
270
254
|
expect(calls).toEqual(['resume-standard-session', 'run-chain-method']);
|
|
271
255
|
expect(typedCall).not.toHaveBeenCalled();
|
|
272
256
|
});
|
|
@@ -126,19 +126,6 @@ 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
|
-
|
|
142
129
|
it('logs canonical DeviceStatus response fields without exposing the device ID', async () => {
|
|
143
130
|
const commands = createCommands();
|
|
144
131
|
const log = getLogger(LoggerNames.DeviceCommands);
|
|
@@ -33,6 +33,8 @@ 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',
|
|
36
38
|
changelog: {
|
|
37
39
|
'zh-CN': '更新',
|
|
38
40
|
'en-US': 'Update',
|
|
@@ -16,6 +16,8 @@ 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',
|
|
19
21
|
changelog: {
|
|
20
22
|
'zh-CN': '更新',
|
|
21
23
|
'en-US': 'Update',
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
initConnector,
|
|
6
6
|
initCore,
|
|
7
7
|
isMissingDetectedProtocolV2Error,
|
|
8
|
-
isProtocolV2PeerRemovedPairingError,
|
|
9
8
|
isRetryableBleConnectionError,
|
|
10
9
|
isRetryableBleProtocolV2ProbeError,
|
|
11
10
|
} from '../src/core';
|
|
@@ -279,7 +278,6 @@ describe('public device lifecycle events', () => {
|
|
|
279
278
|
test.each([
|
|
280
279
|
[HardwareErrorCode.RuntimeError, true],
|
|
281
280
|
[HardwareErrorCode.BleDeviceBondError, false],
|
|
282
|
-
[HardwareErrorCode.BlePeerRemovedPairingInformation, false],
|
|
283
281
|
] as const)(
|
|
284
282
|
'retries a Protocol V2 probe mismatch with error code %s: %s',
|
|
285
283
|
(errorCode, expected) => {
|
|
@@ -299,7 +297,6 @@ describe('public device lifecycle events', () => {
|
|
|
299
297
|
[HardwareErrorCode.BleTimeoutError, true],
|
|
300
298
|
[HardwareErrorCode.PollingTimeout, false],
|
|
301
299
|
[HardwareErrorCode.BleDeviceBondError, false],
|
|
302
|
-
[HardwareErrorCode.BlePeerRemovedPairingInformation, false],
|
|
303
300
|
] as const)('retries a BLE connection error with error code %s: %s', (errorCode, expected) => {
|
|
304
301
|
const method = { payload: { connectProtocol: 'V2' } } as never;
|
|
305
302
|
const error = {
|
|
@@ -310,22 +307,6 @@ describe('public device lifecycle events', () => {
|
|
|
310
307
|
expect(isRetryableBleConnectionError(method, error)).toBe(expected);
|
|
311
308
|
});
|
|
312
309
|
|
|
313
|
-
test.each([
|
|
314
|
-
['V2', true],
|
|
315
|
-
['V1', false],
|
|
316
|
-
[undefined, false],
|
|
317
|
-
] as const)(
|
|
318
|
-
'treats peer-removed pairing as terminal only for Protocol %s: %s',
|
|
319
|
-
(connectProtocol, expected) => {
|
|
320
|
-
const method = { payload: { connectProtocol } } as never;
|
|
321
|
-
const error = {
|
|
322
|
-
errorCode: HardwareErrorCode.BlePeerRemovedPairingInformation,
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
expect(isProtocolV2PeerRemovedPairingError(method, error)).toBe(expected);
|
|
326
|
-
}
|
|
327
|
-
);
|
|
328
|
-
|
|
329
310
|
test('converts an internal transport disconnect into a public KnownDevice snapshot', () => {
|
|
330
311
|
jest.spyOn(DataManager, 'getSettings').mockReturnValue('react-native' as never);
|
|
331
312
|
core = initCore();
|
|
@@ -32,12 +32,10 @@ const createMethod = ({
|
|
|
32
32
|
typedCall,
|
|
33
33
|
supportedMessages = [60802, 60805, 60808, 61500],
|
|
34
34
|
useFullBundle = false,
|
|
35
|
-
firmwareVersion = '1.0.0',
|
|
36
35
|
}: {
|
|
37
36
|
typedCall: jest.Mock;
|
|
38
37
|
supportedMessages?: number[];
|
|
39
38
|
useFullBundle?: boolean;
|
|
40
|
-
firmwareVersion?: string;
|
|
41
39
|
}) => {
|
|
42
40
|
const method = new DeviceUploadNft({
|
|
43
41
|
id: 1,
|
|
@@ -54,7 +52,6 @@ const createMethod = ({
|
|
|
54
52
|
});
|
|
55
53
|
(method as any).device = {
|
|
56
54
|
commands: { typedCall },
|
|
57
|
-
state: { versions: { firmware: firmwareVersion } },
|
|
58
55
|
ensureProtocolV2RuntimeContext: jest.fn(() =>
|
|
59
56
|
Promise.resolve({
|
|
60
57
|
version: 2,
|
|
@@ -63,7 +60,6 @@ const createMethod = ({
|
|
|
63
60
|
})
|
|
64
61
|
),
|
|
65
62
|
getCurrentFirmwareType: jest.fn(),
|
|
66
|
-
getCurrentFirmwareVersionString: jest.fn(() => firmwareVersion),
|
|
67
63
|
};
|
|
68
64
|
method.postMessage = jest.fn();
|
|
69
65
|
|
|
@@ -206,70 +202,6 @@ describe('DeviceUploadNft', () => {
|
|
|
206
202
|
});
|
|
207
203
|
});
|
|
208
204
|
|
|
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
|
-
|
|
273
205
|
test('treats a missing NFT directory as empty before the first upload', async () => {
|
|
274
206
|
const typedCall = jest.fn((request: string, _response: string, params: any) => {
|
|
275
207
|
if (request === 'FilesystemPathInfoQuery') {
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
|
-
|
|
3
1
|
import EVMSignTypedData from '../src/api/evm/EVMSignTypedData';
|
|
4
2
|
|
|
5
3
|
import type { EthereumSignTypedDataMessage, EthereumSignTypedDataTypes } from '../src/types';
|
|
@@ -579,43 +577,3 @@ describe('EVMSignTypedData — OneKey Pro Safe Protocol V1', () => {
|
|
|
579
577
|
});
|
|
580
578
|
});
|
|
581
579
|
});
|
|
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
|
-
});
|