@onekeyfe/hd-core 1.2.2-alpha.0 → 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.
Files changed (69) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +4 -20
  2. package/__tests__/DeviceCommands.test.ts +0 -13
  3. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +2 -0
  4. package/__tests__/check-firmware-release-protocol-v2.test.ts +2 -0
  5. package/__tests__/device-lifecycle-events.test.ts +0 -19
  6. package/__tests__/deviceUploadNft.test.ts +0 -41
  7. package/__tests__/evmSignTypedData.test.ts +0 -42
  8. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -524
  9. package/__tests__/open-wallet-session.test.ts +1 -127
  10. package/__tests__/protocol-v2-resources.test.ts +4 -7
  11. package/__tests__/protocol-v2-unlock-policy.test.ts +1 -35
  12. package/__tests__/protocol-v2.test.ts +27 -673
  13. package/dist/api/FirmwareUpdateV4.d.ts +0 -3
  14. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  15. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  16. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  17. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  18. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +2 -2
  19. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  20. package/dist/api/firmware/getBinary.d.ts +2 -2
  21. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  22. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -1
  23. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  24. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  25. package/dist/core/index.d.ts +0 -1
  26. package/dist/core/index.d.ts.map +1 -1
  27. package/dist/device/Device.d.ts +1 -1
  28. package/dist/device/Device.d.ts.map +1 -1
  29. package/dist/device/DeviceConnector.d.ts +1 -1
  30. package/dist/device/DeviceConnector.d.ts.map +1 -1
  31. package/dist/events/ui-request.d.ts +0 -3
  32. package/dist/events/ui-request.d.ts.map +1 -1
  33. package/dist/index.d.ts +5 -10
  34. package/dist/index.js +398 -1116
  35. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -1
  36. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -2
  37. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -1
  38. package/dist/protocols/protocol-v2/walletSession.d.ts +0 -3
  39. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  40. package/dist/types/settings.d.ts +2 -2
  41. package/dist/types/settings.d.ts.map +1 -1
  42. package/dist/utils/deviceFeaturesUtils.d.ts +0 -3
  43. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  44. package/dist/utils/patch.d.ts +1 -1
  45. package/dist/utils/patch.d.ts.map +1 -1
  46. package/package.json +4 -4
  47. package/src/api/FirmwareUpdateV4.ts +75 -416
  48. package/src/api/OpenWalletSession.ts +9 -39
  49. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +1 -2
  50. package/src/api/evm/EVMSignTypedData.ts +0 -1
  51. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -9
  52. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +1 -7
  53. package/src/api/protocol-v2/DeviceUploadNft.ts +8 -28
  54. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -19
  55. package/src/api/protocol-v2/helpers.ts +0 -8
  56. package/src/core/index.ts +10 -121
  57. package/src/data/messages/messages-protocol-v2.json +1 -111
  58. package/src/device/Device.ts +1 -3
  59. package/src/device/DeviceConnector.ts +3 -7
  60. package/src/events/ui-request.ts +0 -3
  61. package/src/protocols/protocol-v2/resources.ts +1 -9
  62. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +1 -8
  63. package/src/protocols/protocol-v2/walletSession.ts +22 -65
  64. package/src/types/settings.ts +2 -4
  65. package/src/utils/deviceFeaturesUtils.ts +0 -4
  66. package/__tests__/pro2HostAssetPackage.test.ts +0 -58
  67. package/dist/utils/pro2HostAssetPackage.d.ts +0 -8
  68. package/dist/utils/pro2HostAssetPackage.d.ts.map +0 -1
  69. package/src/utils/pro2HostAssetPackage.ts +0 -315
@@ -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,
@@ -62,7 +60,6 @@ const createMethod = ({
62
60
  })
63
61
  ),
64
62
  getCurrentFirmwareType: jest.fn(),
65
- getCurrentFirmwareVersionString: jest.fn(() => firmwareVersion),
66
63
  };
67
64
  method.postMessage = jest.fn();
68
65
 
@@ -205,44 +202,6 @@ describe('DeviceUploadNft', () => {
205
202
  });
206
203
  });
207
204
 
208
- test('uploads one host asset package on firmware 1.0.1', async () => {
209
- const typedCall = jest.fn((request: string, _response: string, params: any) => {
210
- if (request === 'FilesystemFileWrite') return fileWriteSuccess(params);
211
- if (request === 'NftUpdate') return { message: { message: 'NFT updated' } };
212
- throw new Error(`Unexpected request: ${request}`);
213
- });
214
- const method = createMethod({
215
- typedCall,
216
- supportedMessages: [60805, 61500],
217
- firmwareVersion: '1.0.1',
218
- });
219
-
220
- const result = await method.run();
221
-
222
- const requests = typedCall.mock.calls.map(call => call[0]);
223
- expect(requests).not.toContain('FilesystemPathInfoQuery');
224
- expect(requests).not.toContain('FilesystemDirList');
225
- const fileWrites = typedCall.mock.calls.filter(call => call[0] === 'FilesystemFileWrite');
226
- expect(new Set(fileWrites.map(call => call[2].file.path))).toEqual(
227
- new Set(['vol1:/nft/nft-deadbeef-1760000000000.okpkg'])
228
- );
229
- expect(fileWrites[0][2].file.data.subarray(0, 4)).toEqual(
230
- new Uint8Array([0x4f, 0x4b, 0x50, 0x50])
231
- );
232
- expect(typedCall).toHaveBeenLastCalledWith(
233
- 'NftUpdate',
234
- 'Success',
235
- { file_name_no_ext: result.basename },
236
- { timeoutMs: 15_000 }
237
- );
238
- expect(result).toMatchObject({
239
- imagePath: 'vol1:/nft/nft-deadbeef-1760000000000.bin',
240
- thumbnailPath: 'vol1:/nft/nft-deadbeef-1760000000000_m.bin',
241
- metadataPath: 'vol1:/nft/nft-deadbeef-1760000000000.json',
242
- nftUpdated: true,
243
- });
244
- });
245
-
246
205
  test('treats a missing NFT directory as empty before the first upload', async () => {
247
206
  const typedCall = jest.fn((request: string, _response: string, params: any) => {
248
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
- });