@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.
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 -68
  7. package/__tests__/evmSignTypedData.test.ts +0 -42
  8. package/__tests__/firmware-update/firmware-update-v4-install-poll.test.ts +12 -825
  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 -710
  13. package/dist/api/FirmwareUpdateV4.d.ts +0 -4
  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 -21
  34. package/dist/index.js +402 -1136
  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 -434
  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 -31
  54. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +8 -27
  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 -354
@@ -148,7 +148,7 @@ describe('openWalletSession', () => {
148
148
  });
149
149
  });
150
150
 
151
- test('selects the Main PIN before opening the standard wallet when passphrase is disabled', async () => {
151
+ test('opens the standard wallet directly when passphrase is disabled', async () => {
152
152
  const typedCall = jest.fn((request: string) => {
153
153
  if (request === 'ProtocolInfoRequest') {
154
154
  return { message: { version: 2 } };
@@ -167,11 +167,6 @@ describe('openWalletSession', () => {
167
167
 
168
168
  await getProtocolV2WalletSession(device as any, { onlyMainPin: true });
169
169
 
170
- expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, {
171
- source: 'wallet-session-coordinator',
172
- reason: 'open-wallet',
173
- deviceOnly: true,
174
- });
175
170
  expect(typedCall).not.toHaveBeenCalledWith(
176
171
  'DeviceSessionAskPassphrase',
177
172
  'Success',
@@ -182,34 +177,6 @@ describe('openWalletSession', () => {
182
177
  });
183
178
  });
184
179
 
185
- test('reuses a Main PIN selected by the current preflight when passphrase is disabled', async () => {
186
- const typedCall = jest.fn((request: string) => {
187
- if (request === 'ProtocolInfoRequest') {
188
- return { message: { version: 2 } };
189
- }
190
- if (request === 'DeviceSessionGet') {
191
- return {
192
- message: {
193
- btc_test_address: 'standard-state',
194
- session_id: 'standard-session',
195
- },
196
- };
197
- }
198
- throw new Error(`Unexpected request: ${request}`);
199
- });
200
- const device = createDevice({ passphraseProtection: false, typedCall });
201
-
202
- await getProtocolV2WalletSession(device as any, {
203
- onlyMainPin: true,
204
- mainPinSelected: true,
205
- });
206
-
207
- expect(device.unlockDevice).not.toHaveBeenCalled();
208
- expect(typedCall).toHaveBeenCalledWith('DeviceSessionGet', 'DeviceSession', {
209
- seed_domains: [],
210
- });
211
- });
212
-
213
180
  test('does not treat an Attach PIN DeviceStatus as the Main wallet', async () => {
214
181
  const typedCall = jest.fn((request: string) => {
215
182
  if (request === 'ProtocolInfoRequest') {
@@ -1147,68 +1114,6 @@ describe('openWalletSession', () => {
1147
1114
  expect(device.getDeviceState).toHaveBeenCalledTimes(2);
1148
1115
  });
1149
1116
 
1150
- test('does not restrict a locked hidden-wallet selection to the Main PIN', async () => {
1151
- const typedCall = jest
1152
- .fn()
1153
- .mockResolvedValueOnce({ message: { version: 2 } })
1154
- .mockResolvedValueOnce({ message: {} })
1155
- .mockResolvedValueOnce({
1156
- message: {
1157
- btc_test_address: 'hidden-state',
1158
- session_id: 'hidden-session',
1159
- },
1160
- });
1161
- const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1162
- const method = new OpenWalletSession({
1163
- payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1164
- });
1165
- method.init();
1166
- const device = createDevice({ typedCall, promptPassphrase });
1167
- device.features.unlocked = false;
1168
- device.getDeviceState = jest
1169
- .fn()
1170
- .mockResolvedValueOnce({
1171
- identity: { deviceId: undefined },
1172
- status: { unlocked: false, passphraseProtection: true },
1173
- })
1174
- .mockResolvedValueOnce({
1175
- identity: { deviceId: 'device-1' },
1176
- status: {
1177
- unlocked: true,
1178
- passphraseProtection: true,
1179
- unlockedAttachPin: false,
1180
- },
1181
- })
1182
- .mockResolvedValueOnce({
1183
- identity: { deviceId: 'device-1' },
1184
- status: {
1185
- unlocked: true,
1186
- passphraseProtection: true,
1187
- unlockedAttachPin: false,
1188
- },
1189
- });
1190
- device.unlockDevice = jest.fn().mockImplementation(() => {
1191
- device.features.unlocked = true;
1192
- return Promise.resolve(device.features);
1193
- });
1194
- method.device = device as any;
1195
-
1196
- await expect(method.run()).resolves.toMatchObject({
1197
- walletType: 'hidden',
1198
- passphraseState: 'hidden-state',
1199
- });
1200
- expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Any, {
1201
- source: 'unlock-coordinator',
1202
- reason: 'device-locked',
1203
- deviceOnly: true,
1204
- method: 'openWalletSession',
1205
- });
1206
- expect(device.unlockDevice).not.toHaveBeenCalledWith(
1207
- DeviceSessionPinType.Main,
1208
- expect.anything()
1209
- );
1210
- });
1211
-
1212
1117
  test('switches from Attach PIN to Main PIN before opening the standard wallet', async () => {
1213
1118
  const typedCall = jest
1214
1119
  .fn()
@@ -1303,37 +1208,6 @@ describe('openWalletSession', () => {
1303
1208
  expect(deviceWalletSessionStore.get('device-1', 'hidden-state')).toBe('hidden-session');
1304
1209
  });
1305
1210
 
1306
- test('reuses the fresh unlock and wallet-selection statuses', async () => {
1307
- const typedCall = jest
1308
- .fn()
1309
- .mockResolvedValueOnce({ message: { version: 2 } })
1310
- .mockResolvedValueOnce({ message: {} })
1311
- .mockResolvedValueOnce({
1312
- message: {
1313
- btc_test_address: 'hidden-state',
1314
- session_id: 'hidden-session',
1315
- },
1316
- });
1317
- const promptPassphrase = jest.fn().mockResolvedValue({ passphrase: 'host hidden wallet' });
1318
- const method = new OpenWalletSession({
1319
- payload: { method: 'openWalletSession', connectId: 'connect-id', mode: 'select-hidden' },
1320
- });
1321
- method.init();
1322
- method.protocolV2UnlockContext = {
1323
- preflightCompleted: true,
1324
- preflightStatusRefreshed: true,
1325
- };
1326
- const device = createDevice({ typedCall, promptPassphrase });
1327
- method.device = device as any;
1328
-
1329
- await expect(method.run()).resolves.toMatchObject({
1330
- walletType: 'hidden',
1331
- passphraseState: 'hidden-state',
1332
- });
1333
-
1334
- expect(device.getDeviceState.mock.calls).toEqual([[], []]);
1335
- });
1336
-
1337
1211
  test('gets the prepared session after host passphrase entry', async () => {
1338
1212
  const typedCall = jest
1339
1213
  .fn()
@@ -66,6 +66,8 @@ const createRemoteConfig = (): RemoteConfigResponse =>
66
66
  {
67
67
  required: false,
68
68
  version: [1, 0, 0],
69
+ url: 'https://example.com/pro2.okpkg',
70
+ fingerprint: 'a'.repeat(64),
69
71
  changelog: { 'zh-CN': 'Pro2', 'en-US': 'Pro2' },
70
72
  resources: { source: resourceSource },
71
73
  },
@@ -77,6 +79,8 @@ const createRemoteConfig = (): RemoteConfigResponse =>
77
79
  {
78
80
  required: false,
79
81
  version: [1, 0, 0],
82
+ url: 'https://example.com/neo.okpkg',
83
+ fingerprint: 'b'.repeat(64),
80
84
  changelog: { 'zh-CN': 'Neo', 'en-US': 'Neo' },
81
85
  resources: { source: neoResourceSource },
82
86
  },
@@ -105,11 +109,6 @@ describe('Pro2 resource configuration', () => {
105
109
  expect(
106
110
  isProtocolV2ResourceArchiveEntryName('bundles/firmware_logo-pro2-prod_resource-signed.okpkg')
107
111
  ).toBe(true);
108
- expect(
109
- isProtocolV2ResourceArchiveEntryName(
110
- 'pro2-prod_resource/bundles/firmware_logo-pro2-prod_resource-signed.okpkg'
111
- )
112
- ).toBe(true);
113
112
  expect(
114
113
  isProtocolV2ResourceArchiveEntryName(
115
114
  '__MACOSX/pro2-prod_resource 2/bundles/._firmware_logo-pro2-prod_resource-signed.okpkg'
@@ -120,8 +119,6 @@ describe('Pro2 resource configuration', () => {
120
119
  'bundles/._firmware_logo-pro2-prod_resource-signed.okpkg'
121
120
  )
122
121
  ).toBe(false);
123
- expect(isProtocolV2ResourceArchiveEntryName('pro2-prod_resource/manifest.json')).toBe(false);
124
- expect(isProtocolV2ResourceArchiveEntryName('pro2-prod_resource/.DS_Store')).toBe(false);
125
122
  });
126
123
 
127
124
  test('reads the version, hashes, and direct device path from a RESC package', () => {
@@ -151,42 +151,8 @@ describe('Protocol V2 unlock semantics', () => {
151
151
  });
152
152
 
153
153
  expect(method.unlockPolicy).toBe('unlock-before-run');
154
- expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Main, expect.any(Object));
154
+ expect(device.unlockDevice).toHaveBeenCalledTimes(1);
155
155
  expect(run).toHaveBeenCalledTimes(1);
156
- expect(method.protocolV2UnlockContext).toMatchObject({
157
- preflightCompleted: true,
158
- preflightStatusRefreshed: true,
159
- preflightMainPinSelected: true,
160
- });
161
- });
162
-
163
- test('allows either PIN type when pre-unlocking hidden-wallet selection', async () => {
164
- const method = new OpenWalletSession({
165
- id: 1,
166
- payload: { method: 'openWalletSession', mode: 'select-hidden' },
167
- });
168
- method.init();
169
- method.run = jest.fn().mockResolvedValue({ walletType: 'hidden' }) as any;
170
- const features = { unlocked: false };
171
- const device = {
172
- features,
173
- commands: {
174
- typedCall: jest.fn().mockResolvedValue({ message: { unlocked: false } }),
175
- },
176
- isProtocolV2: () => true,
177
- isBootloader: () => false,
178
- isRomloader: () => false,
179
- updateProtocolV2Status: jest.fn(() => features),
180
- unlockDevice: jest.fn().mockImplementation(() => {
181
- features.unlocked = true;
182
- return Promise.resolve(features);
183
- }),
184
- };
185
-
186
- await runMethodWithUnlockPolicy(method, device as any);
187
-
188
- expect(device.unlockDevice).toHaveBeenCalledWith(DeviceSessionPinType.Any, expect.any(Object));
189
- expect(method.protocolV2UnlockContext?.preflightMainPinSelected).toBe(false);
190
156
  });
191
157
 
192
158
  test('pre-unlocks an unregistered wallet business method', async () => {