@onekeyfe/hd-core 1.2.0-alpha.22 → 1.2.0-alpha.23

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 (61) hide show
  1. package/__tests__/DeviceCommands.test.ts +8 -8
  2. package/__tests__/device-settings.test.ts +1 -1
  3. package/__tests__/device-wallet-session-store.test.ts +41 -0
  4. package/__tests__/firmware-update/check-all-firmware-release.test.ts +86 -0
  5. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +13 -0
  6. package/__tests__/logBlockEvent.test.ts +17 -0
  7. package/__tests__/open-wallet-session.test.ts +90 -31
  8. package/__tests__/protocol-v2.test.ts +301 -63
  9. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  10. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  11. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  12. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  13. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  14. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  15. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  16. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -1
  17. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -1
  18. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -1
  19. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -1
  20. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +6 -1
  21. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -1
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/device/Device.d.ts +3 -2
  24. package/dist/device/Device.d.ts.map +1 -1
  25. package/dist/device/DeviceCommands.d.ts.map +1 -1
  26. package/dist/events/device.d.ts +1 -0
  27. package/dist/events/device.d.ts.map +1 -1
  28. package/dist/events/logBlockEvent.d.ts.map +1 -1
  29. package/dist/events/ui-request.d.ts +1 -0
  30. package/dist/events/ui-request.d.ts.map +1 -1
  31. package/dist/index.d.ts +10 -6
  32. package/dist/index.js +157 -268
  33. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
  34. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  35. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  36. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  37. package/dist/utils/patch.d.ts +1 -1
  38. package/dist/utils/patch.d.ts.map +1 -1
  39. package/package.json +4 -4
  40. package/src/api/CheckAllFirmwareRelease.ts +15 -8
  41. package/src/api/FirmwareUpdateV2.ts +8 -1
  42. package/src/api/FirmwareUpdateV3.ts +8 -0
  43. package/src/api/FirmwareUpdateV4.ts +21 -19
  44. package/src/api/GetPassphraseState.ts +11 -5
  45. package/src/api/device/DeviceUpdateBootloader.ts +9 -1
  46. package/src/api/device/DeviceWipe.ts +2 -0
  47. package/src/api/firmware/FirmwareArtifactSource.ts +1 -1
  48. package/src/api/firmware/FirmwareUpdatePlan.ts +1 -1
  49. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +15 -1
  50. package/src/core/index.ts +1 -0
  51. package/src/data/messages/messages-protocol-v2.json +18 -57
  52. package/src/device/Device.ts +30 -7
  53. package/src/device/DeviceCommands.ts +24 -151
  54. package/src/events/device.ts +1 -0
  55. package/src/events/logBlockEvent.ts +1 -15
  56. package/src/events/ui-request.ts +1 -0
  57. package/src/protocols/protocol-v2/deviceSession.ts +1 -1
  58. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -1
  59. package/src/protocols/protocol-v2/walletSession.ts +41 -20
  60. package/src/types/api/getPassphraseState.ts +4 -3
  61. package/src/utils/deviceInfoUtils.ts +3 -16
@@ -1,10 +1,11 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+ import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
2
3
 
3
4
  import { DEVICE } from '../../events';
4
5
  import { assertCompleteDeviceSession } from './deviceSession';
5
6
  import { isDeviceLockedError } from './lockedError';
6
7
 
7
- import type { DeviceSessionOpen } from '@onekeyfe/hd-transport';
8
+ import type { DeviceSessionGet } from '@onekeyfe/hd-transport';
8
9
  import type { Device } from '../../device/Device';
9
10
 
10
11
  export async function requestProtocolV2DeviceStatus(device: Device) {
@@ -23,15 +24,36 @@ const negotiateEventlessWalletSession = async (device: Device) => {
23
24
  });
24
25
  };
25
26
 
26
- const openDeviceSession = async (device: Device, request: DeviceSessionOpen) => {
27
+ const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
27
28
  try {
28
- return await device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
29
+ return await device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
29
30
  } catch (error) {
30
31
  if (!isDeviceLockedError(error)) {
31
32
  throw error;
32
33
  }
33
- await device.unlockDevice();
34
- return device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
34
+ await device.unlockDevice(DeviceSessionPinType.Main);
35
+ return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
36
+ }
37
+ };
38
+
39
+ const askDevicePassphrase = async (device: Device) => {
40
+ const request = () =>
41
+ device.commands.typedCall(
42
+ 'DeviceSessionAskPassphrase',
43
+ 'Success',
44
+ {},
45
+ {
46
+ timeoutMs: 120_000,
47
+ }
48
+ );
49
+ try {
50
+ return await request();
51
+ } catch (error) {
52
+ if (!isDeviceLockedError(error)) {
53
+ throw error;
54
+ }
55
+ await device.unlockDevice(DeviceSessionPinType.Main);
56
+ return request();
35
57
  }
36
58
  };
37
59
 
@@ -42,13 +64,13 @@ const selectDeviceSession = async (device: Device) => {
42
64
  reason: 'open-wallet' as const,
43
65
  };
44
66
  const response = await device.commands.promptPassphrase(
45
- { existsAttachPinUser, ...metadata },
67
+ { existsAttachPinUser, deviceOnly: true, ...metadata },
46
68
  { cancelDeviceOnReject: false }
47
69
  );
48
- const hostPassphrase =
49
- typeof response.passphrase === 'string' ? response.passphrase.normalize('NFKD') : undefined;
70
+ const hasHostPassphrase =
71
+ typeof response.passphrase === 'string' && response.passphrase.length > 0;
50
72
  const selections = [
51
- !!hostPassphrase,
73
+ hasHostPassphrase,
52
74
  response.passphraseOnDevice === true,
53
75
  response.attachPinOnDevice === true,
54
76
  ].filter(Boolean).length;
@@ -68,17 +90,15 @@ const selectDeviceSession = async (device: Device) => {
68
90
  );
69
91
  }
70
92
  device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
71
- return openDeviceSession(device, { select: { attach_pin_on_device: {} } });
72
- }
73
-
74
- if (response.passphraseOnDevice) {
75
- device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
76
- return openDeviceSession(device, { select: { passphrase_on_device: {} } });
93
+ await device.unlockDevice(DeviceSessionPinType.AttachToPin);
94
+ return getDeviceSession(device, {});
77
95
  }
78
96
 
79
- return openDeviceSession(device, {
80
- select: { host_passphrase: { passphrase: hostPassphrase as string } },
81
- });
97
+ // Protocol V2 no longer accepts host-provided passphrase text. A legacy host
98
+ // response is treated only as the user's choice to continue on the device.
99
+ device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
100
+ await askDevicePassphrase(device);
101
+ return getDeviceSession(device, {});
82
102
  };
83
103
 
84
104
  export async function getProtocolV2WalletSession(
@@ -91,6 +111,7 @@ export async function getProtocolV2WalletSession(
91
111
  ) {
92
112
  if (options?.initSession) {
93
113
  device.clearInternalState();
114
+ device.passphraseState = undefined;
94
115
  }
95
116
 
96
117
  await negotiateEventlessWalletSession(device);
@@ -103,7 +124,7 @@ export async function getProtocolV2WalletSession(
103
124
  : options?.expectedPassphraseState ?? device.passphraseState;
104
125
 
105
126
  if (device.features?.unlocked === false) {
106
- await device.unlockDevice();
127
+ await device.unlockDevice(DeviceSessionPinType.Main);
107
128
  }
108
129
 
109
130
  if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
@@ -122,7 +143,7 @@ export async function getProtocolV2WalletSession(
122
143
 
123
144
  if (cachedSessionId && expectedPassphraseState) {
124
145
  try {
125
- response = await openDeviceSession(device, { resume: { session_id: cachedSessionId } });
146
+ response = await getDeviceSession(device, { session_id: cachedSessionId });
126
147
  resumed = true;
127
148
  } catch (error) {
128
149
  device.clearInternalState();
@@ -3,10 +3,11 @@ import type { CommonParams, Response } from '../params';
3
3
  export type GetPassphraseStateParams = CommonParams;
4
4
 
5
5
  /**
6
- * Legacy Protocol V1 wallet API.
6
+ * Compatibility wallet-state API for existing App integrations.
7
7
  *
8
- * This remains supported for Protocol V1 integrations. New cross-protocol integrations
9
- * and all Protocol V2 callers should use `openWalletSession`.
8
+ * Protocol V1 keeps its parameterless firmware flow. Protocol V2 maps the existing
9
+ * `useEmptyPassphrase` and `initSession` intent to the device-only wallet-session flow.
10
+ * New integrations should prefer `openWalletSession` for explicit wallet intent.
10
11
  */
11
12
  export declare function getPassphraseState(
12
13
  connectId?: string,
@@ -1,4 +1,3 @@
1
- import { isEmpty } from 'lodash';
2
1
  import { EDeviceType } from '@onekeyfe/hd-shared';
3
2
 
4
3
  import { DeviceModelToTypes } from '../types';
@@ -61,21 +60,9 @@ export const getDeviceUUID = getDeviceSerialNo;
61
60
  export const getDeviceLabel = (features?: DeviceFeaturesInput) => {
62
61
  if (!features) return null;
63
62
 
64
- const deviceType = getDeviceType(features);
65
- if (deviceType == null) return null;
66
-
67
- if ('label' in features && typeof features.label === 'string' && !isEmpty(features.label)) {
68
- return features.label;
69
- }
70
-
71
- const bleName = getDeviceBleName(features);
72
- if (!isEmpty(bleName)) return bleName;
73
-
74
- if (deviceType === EDeviceType.ClassicPure) {
75
- return 'OneKey Classic 1S';
76
- }
77
-
78
- return `OneKey ${deviceType.charAt(0).toUpperCase() + deviceType.slice(1)}`;
63
+ return 'label' in features && typeof features.label === 'string' && features.label.length > 0
64
+ ? features.label
65
+ : null;
79
66
  };
80
67
 
81
68
  /**