@onekeyfe/hd-core 1.2.0-alpha.19 → 1.2.0-alpha.20

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 (256) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +75 -0
  2. package/__tests__/DeviceCommands.test.ts +143 -7
  3. package/__tests__/RequestQueue.test.ts +106 -0
  4. package/__tests__/UploadPortfolio.test.ts +46 -0
  5. package/__tests__/core-dispose.test.ts +34 -0
  6. package/__tests__/core-error-output.test.ts +39 -0
  7. package/__tests__/device-lifecycle-events.test.ts +117 -0
  8. package/__tests__/device-pool-state.test.ts +20 -1
  9. package/__tests__/device-settings.test.ts +184 -6
  10. package/__tests__/device-state-events.test.ts +1 -2
  11. package/__tests__/device-state-mapper.test.ts +33 -26
  12. package/__tests__/device-state-store.test.ts +1 -34
  13. package/__tests__/device-utils.test.ts +106 -0
  14. package/__tests__/device-wallet-session-store.test.ts +65 -29
  15. package/__tests__/deviceSettings.test.ts +21 -12
  16. package/__tests__/evmLedgerLegacySafety.test.ts +2 -2
  17. package/__tests__/evmSignTypedData.test.ts +80 -0
  18. package/__tests__/filesystemValidation.test.ts +53 -0
  19. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +402 -0
  20. package/__tests__/get-device-state.test.ts +77 -41
  21. package/__tests__/logBlockEvent.test.ts +24 -11
  22. package/__tests__/networkUtils.test.ts +386 -0
  23. package/__tests__/open-wallet-session-error-response.test.ts +43 -0
  24. package/__tests__/open-wallet-session.test.ts +559 -0
  25. package/__tests__/protocol-v2.test.ts +756 -452
  26. package/__tests__/public-device-state-api.test.ts +113 -13
  27. package/__tests__/public-pro2-api-boundary.test.ts +91 -0
  28. package/__tests__/search-devices.test.ts +43 -0
  29. package/dist/api/BaseMethod.d.ts +3 -0
  30. package/dist/api/BaseMethod.d.ts.map +1 -1
  31. package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
  32. package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
  33. package/dist/api/ClearSessionCache.d.ts.map +1 -1
  34. package/dist/api/DirList.d.ts.map +1 -1
  35. package/dist/api/FileRead.d.ts.map +1 -1
  36. package/dist/api/FirmwareUpdateV2.d.ts +2 -2
  37. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  38. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  39. package/dist/api/FirmwareUpdateV4.d.ts +3 -2
  40. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  41. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  42. package/dist/api/OpenWalletSession.d.ts +14 -0
  43. package/dist/api/OpenWalletSession.d.ts.map +1 -0
  44. package/dist/api/PathInfo.d.ts.map +1 -1
  45. package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
  46. package/dist/api/SearchDevices.d.ts +3 -0
  47. package/dist/api/SearchDevices.d.ts.map +1 -1
  48. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  49. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  50. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  51. package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
  52. package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
  53. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  54. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  55. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  56. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  57. package/dist/api/firmware/getBinary.d.ts +7 -3
  58. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  59. package/dist/api/helpers/filesystemValidation.d.ts +3 -0
  60. package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
  61. package/dist/api/helpers/paramsValidator.d.ts +1 -0
  62. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  63. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  64. package/dist/api/index.d.ts +7 -11
  65. package/dist/api/index.d.ts.map +1 -1
  66. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
  67. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -1
  68. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -1
  69. package/dist/api/utils.d.ts.map +1 -1
  70. package/dist/core/RequestQueue.d.ts +17 -1
  71. package/dist/core/RequestQueue.d.ts.map +1 -1
  72. package/dist/core/index.d.ts +3 -1
  73. package/dist/core/index.d.ts.map +1 -1
  74. package/dist/device/Device.d.ts +6 -5
  75. package/dist/device/Device.d.ts.map +1 -1
  76. package/dist/device/DeviceCommands.d.ts +5 -5
  77. package/dist/device/DeviceCommands.d.ts.map +1 -1
  78. package/dist/device/DevicePool.d.ts +1 -0
  79. package/dist/device/DevicePool.d.ts.map +1 -1
  80. package/dist/device/DeviceStateMapper.d.ts +2 -2
  81. package/dist/device/DeviceStateMapper.d.ts.map +1 -1
  82. package/dist/device/DeviceStateProjector.d.ts +1 -2
  83. package/dist/device/DeviceStateProjector.d.ts.map +1 -1
  84. package/dist/device/DeviceStateStore.d.ts +1 -3
  85. package/dist/device/DeviceStateStore.d.ts.map +1 -1
  86. package/dist/device/DeviceWalletSessionStore.d.ts +6 -1
  87. package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -1
  88. package/dist/device/cloneDeviceState.d.ts +2 -0
  89. package/dist/device/cloneDeviceState.d.ts.map +1 -0
  90. package/dist/deviceProfile/buildDeviceFeatures.d.ts +3 -1
  91. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  92. package/dist/events/logBlockEvent.d.ts.map +1 -1
  93. package/dist/index.d.ts +608 -75
  94. package/dist/index.js +2287 -1706
  95. package/dist/inject.d.ts.map +1 -1
  96. package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
  97. package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
  98. package/dist/protocols/protocol-v2/features.d.ts +11 -4
  99. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  100. package/dist/protocols/protocol-v2/index.d.ts +2 -2
  101. package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
  102. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts +16 -0
  103. package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
  104. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  105. package/dist/protocols/protocol-v2/walletSession.d.ts +8 -3
  106. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  107. package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -2
  108. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  109. package/dist/types/api/deviceSettings.d.ts +1 -0
  110. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  111. package/dist/types/api/deviceUnlock.d.ts +1 -1
  112. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  113. package/dist/types/api/getFeatures.d.ts.map +1 -1
  114. package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
  115. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  116. package/dist/types/api/index.d.ts +13 -15
  117. package/dist/types/api/index.d.ts.map +1 -1
  118. package/dist/types/api/openWalletSession.d.ts +41 -0
  119. package/dist/types/api/openWalletSession.d.ts.map +1 -0
  120. package/dist/types/api/protocolV2.d.ts +6 -11
  121. package/dist/types/api/protocolV2.d.ts.map +1 -1
  122. package/dist/types/device.d.ts +2 -9
  123. package/dist/types/device.d.ts.map +1 -1
  124. package/dist/utils/assets.d.ts +2 -1
  125. package/dist/utils/assets.d.ts.map +1 -1
  126. package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
  127. package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
  128. package/dist/utils/deviceFeaturesUtils.d.ts +11 -1
  129. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  130. package/dist/utils/deviceInfoUtils.d.ts +9 -8
  131. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  132. package/dist/utils/deviceSettings.d.ts +2 -0
  133. package/dist/utils/deviceSettings.d.ts.map +1 -1
  134. package/dist/utils/deviceVersionUtils.d.ts +6 -5
  135. package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
  136. package/dist/utils/index.d.ts +2 -2
  137. package/dist/utils/index.d.ts.map +1 -1
  138. package/dist/utils/networkUtils.d.ts +9 -1
  139. package/dist/utils/networkUtils.d.ts.map +1 -1
  140. package/dist/utils/patch.d.ts +1 -1
  141. package/dist/utils/patch.d.ts.map +1 -1
  142. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  143. package/package.json +4 -4
  144. package/src/api/BaseMethod.ts +17 -10
  145. package/src/api/CheckBootloaderRelease.ts +1 -2
  146. package/src/api/CheckFirmwareRelease.ts +1 -2
  147. package/src/api/ClearSessionCache.ts +0 -4
  148. package/src/api/DirList.ts +5 -3
  149. package/src/api/DirMake.ts +3 -3
  150. package/src/api/DirRemove.ts +3 -3
  151. package/src/api/FileDelete.ts +3 -3
  152. package/src/api/FileRead.ts +9 -6
  153. package/src/api/FileWrite.ts +3 -3
  154. package/src/api/FirmwareUpdate.ts +4 -4
  155. package/src/api/FirmwareUpdateV2.ts +133 -45
  156. package/src/api/FirmwareUpdateV3.ts +3 -5
  157. package/src/api/FirmwareUpdateV4.ts +192 -154
  158. package/src/api/GetPassphraseState.ts +10 -16
  159. package/src/api/OpenWalletSession.ts +221 -0
  160. package/src/api/PathInfo.ts +5 -3
  161. package/src/api/PromptWebDeviceAccess.ts +2 -3
  162. package/src/api/SearchDevices.ts +6 -2
  163. package/src/api/UploadPortfolio.ts +12 -3
  164. package/src/api/alephium/AlephiumSignTransaction.ts +2 -2
  165. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +4 -8
  166. package/src/api/benfen/BenfenGetAddress.ts +1 -1
  167. package/src/api/btc/BTCGetPublicKey.ts +1 -1
  168. package/src/api/device/DeviceChangePin.ts +1 -0
  169. package/src/api/device/DeviceFullyUploadResource.ts +4 -5
  170. package/src/api/device/DeviceSettings.ts +93 -0
  171. package/src/api/device/DeviceUpdateBootloader.ts +1 -2
  172. package/src/api/device/DeviceWipe.ts +1 -0
  173. package/src/api/evm/EVMSignTypedData.ts +3 -5
  174. package/src/api/evm/legacyV1/getAddress.ts +2 -2
  175. package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
  176. package/src/api/evm/legacyV1/signMessage.ts +2 -2
  177. package/src/api/evm/legacyV1/signTypedData.ts +2 -2
  178. package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
  179. package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
  180. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +3 -3
  181. package/src/api/firmware/getBinary.ts +8 -3
  182. package/src/api/helpers/batchGetPublickeys.ts +2 -2
  183. package/src/api/helpers/filesystemValidation.ts +61 -0
  184. package/src/api/helpers/paramsValidator.ts +1 -1
  185. package/src/api/helpers/protocolV2FileWrite.ts +3 -2
  186. package/src/api/index.ts +9 -12
  187. package/src/api/nervos/NervosSignTransaction.ts +2 -2
  188. package/src/api/nexa/NexaSignTransaction.ts +1 -1
  189. package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +1 -1
  190. package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +1 -1
  191. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +4 -4
  192. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +6 -5
  193. package/src/api/protocol-v2/DeviceInfoGet.ts +4 -4
  194. package/src/api/protocol-v2/DeviceReboot.ts +1 -1
  195. package/src/api/protocol-v2/DeviceSettingsPageShow.ts +11 -8
  196. package/src/api/protocol-v2/DeviceSettingsSet.ts +4 -11
  197. package/src/api/protocol-v2/FilesystemFormat.ts +1 -1
  198. package/src/api/protocol-v2/FilesystemPermissionFix.ts +1 -1
  199. package/src/api/protocol-v2/Ping.ts +1 -1
  200. package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -1
  201. package/src/api/utils.ts +1 -3
  202. package/src/core/RequestQueue.ts +107 -6
  203. package/src/core/index.ts +91 -46
  204. package/src/data/messages/messages-protocol-v2.json +25 -79
  205. package/src/data-manager/DataManager.ts +6 -6
  206. package/src/device/Device.ts +186 -102
  207. package/src/device/DeviceCommands.ts +51 -21
  208. package/src/device/DeviceFeaturesState.ts +4 -4
  209. package/src/device/DevicePool.ts +17 -3
  210. package/src/device/DeviceStateMapper.ts +13 -29
  211. package/src/device/DeviceStateProjector.ts +11 -8
  212. package/src/device/DeviceStateStore.ts +11 -52
  213. package/src/device/DeviceWalletSessionStore.ts +31 -4
  214. package/src/device/cloneDeviceState.ts +39 -0
  215. package/src/device/deviceIdentity.ts +2 -2
  216. package/src/deviceProfile/buildDeviceFeatures.ts +29 -88
  217. package/src/events/logBlockEvent.ts +8 -1
  218. package/src/inject.ts +14 -24
  219. package/src/protocols/protocol-v2/deviceSession.ts +24 -0
  220. package/src/protocols/protocol-v2/features.ts +37 -49
  221. package/src/protocols/protocol-v2/firmware.ts +1 -1
  222. package/src/protocols/protocol-v2/index.ts +2 -3
  223. package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +61 -0
  224. package/src/protocols/protocol-v2/uiInteraction.ts +4 -3
  225. package/src/protocols/protocol-v2/walletSession.ts +57 -146
  226. package/src/types/api/checkAllFirmwareRelease.ts +1 -2
  227. package/src/types/api/deviceSettings.ts +1 -0
  228. package/src/types/api/deviceUnlock.ts +1 -1
  229. package/src/types/api/firmwareUpdate.ts +5 -5
  230. package/src/types/api/getDeviceState.ts +1 -1
  231. package/src/types/api/getFeatures.ts +3 -0
  232. package/src/types/api/getOnekeyFeatures.ts +3 -0
  233. package/src/types/api/getPassphraseState.ts +6 -0
  234. package/src/types/api/index.ts +16 -23
  235. package/src/types/api/openWalletSession.ts +64 -0
  236. package/src/types/api/protocolV2.ts +36 -18
  237. package/src/types/device.ts +20 -14
  238. package/src/types/params.ts +1 -1
  239. package/src/types/settings.ts +8 -8
  240. package/src/utils/assets.ts +4 -1
  241. package/src/utils/deviceFeaturesCompat.ts +173 -0
  242. package/src/utils/deviceFeaturesUtils.ts +9 -8
  243. package/src/utils/deviceInfoUtils.ts +26 -64
  244. package/src/utils/deviceSettings.ts +18 -11
  245. package/src/utils/deviceVersionUtils.ts +25 -44
  246. package/src/utils/findDefectiveBatchDevice.ts +3 -3
  247. package/src/utils/index.ts +2 -5
  248. package/src/utils/networkUtils.ts +270 -14
  249. package/src/utils/pro2Wallpaper.ts +11 -13
  250. package/src/utils/tracing.ts +2 -2
  251. package/dist/api/internal.d.ts +0 -4
  252. package/dist/api/internal.d.ts.map +0 -1
  253. package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +0 -28
  254. package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +0 -1
  255. package/src/api/internal.ts +0 -9
  256. package/src/api/protocol-v2/DeviceSessionOpen.ts +0 -100
@@ -1,37 +1,10 @@
1
1
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
 
3
- import { DEVICE, type PassphraseRequestPayload } from '../../events';
3
+ import { assertCompleteDeviceSession } from './deviceSession';
4
4
  import { isDeviceLockedError } from './lockedError';
5
5
 
6
- import type { DeviceSessionOpen } from '@onekeyfe/hd-transport';
6
+ import type { DeviceSessionGet } from '@onekeyfe/hd-transport';
7
7
  import type { Device } from '../../device/Device';
8
- import type { PassphrasePromptResponse } from '../../device/DeviceCommands';
9
-
10
- const getErrorText = (error: unknown) => {
11
- if (error instanceof Error) return `${error.name} ${error.message}`;
12
- if (typeof error === 'string') return error;
13
- if (error && typeof error === 'object') {
14
- const record = error as Record<string, unknown>;
15
- return [record.code, record.errorCode, record.message, record.reason]
16
- .filter(value => value !== undefined && value !== null)
17
- .join(' ');
18
- }
19
- return String(error ?? '');
20
- };
21
-
22
- export const isProtocolV2InvalidSessionError = (error: unknown) =>
23
- getErrorText(error).toLowerCase().includes('failure_invalidsession');
24
-
25
- const normalizeHostPassphrase = (passphrase: string | undefined) => {
26
- const normalized = (passphrase ?? '').normalize('NFKD');
27
- if (!normalized || normalized.includes('\0') || normalized.length > 50) {
28
- throw ERRORS.TypedError(
29
- HardwareErrorCode.CallMethodInvalidParameter,
30
- 'Invalid hidden wallet passphrase.'
31
- );
32
- }
33
- return normalized;
34
- };
35
8
 
36
9
  export async function requestProtocolV2DeviceStatus(device: Device) {
37
10
  const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
@@ -43,69 +16,16 @@ export async function refreshProtocolV2DeviceStatus(device: Device) {
43
16
  return device.updateProtocolV2Status(status);
44
17
  }
45
18
 
46
- const openDeviceSession = async (device: Device, request: DeviceSessionOpen) => {
19
+ const getDeviceSession = async (device: Device, request: DeviceSessionGet) => {
47
20
  try {
48
- return await device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
21
+ return await device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
49
22
  } catch (error) {
50
23
  if (!isDeviceLockedError(error)) {
51
24
  throw error;
52
25
  }
53
26
  await device.unlockDevice();
54
- return device.commands.typedCall('DeviceSessionOpen', 'DeviceSession', request);
55
- }
56
- };
57
-
58
- const createHiddenWalletRequest = (
59
- response: PassphrasePromptResponse
60
- ): {
61
- request: DeviceSessionOpen;
62
- deviceEvent?: typeof DEVICE.PASSPHRASE_ON_DEVICE | typeof DEVICE.ATTACH_PIN_ON_DEVICE;
63
- } => {
64
- if (response.attachPinOnDevice) {
65
- return {
66
- request: {
67
- select: {
68
- attach_pin_on_device: {},
69
- },
70
- },
71
- deviceEvent: DEVICE.ATTACH_PIN_ON_DEVICE,
72
- };
73
- }
74
-
75
- if (response.passphraseOnDevice) {
76
- return {
77
- request: {
78
- select: {
79
- passphrase_on_device: {},
80
- },
81
- },
82
- deviceEvent: DEVICE.PASSPHRASE_ON_DEVICE,
83
- };
27
+ return device.commands.typedCall('DeviceSessionGet', 'DeviceSession', request);
84
28
  }
85
-
86
- return {
87
- request: {
88
- select: {
89
- host_passphrase: { passphrase: normalizeHostPassphrase(response.passphrase) },
90
- },
91
- },
92
- };
93
- };
94
-
95
- const openSelectedHiddenWallet = async (
96
- device: Device,
97
- promptPayload: PassphraseRequestPayload
98
- ) => {
99
- const response = await device.commands.promptPassphrase(promptPayload, {
100
- cancelDeviceOnReject: false,
101
- });
102
- const { request, deviceEvent } = createHiddenWalletRequest(response);
103
-
104
- if (deviceEvent) {
105
- device.emit(deviceEvent, device, promptPayload);
106
- }
107
-
108
- return openDeviceSession(device, request);
109
29
  };
110
30
 
111
31
  export async function getProtocolV2WalletSession(
@@ -122,75 +42,66 @@ export async function getProtocolV2WalletSession(
122
42
 
123
43
  const expectedPassphraseState = options?.expectedPassphraseState ?? device.passphraseState;
124
44
 
125
- try {
126
- // 锁屏时先完成 PIN 解锁;解锁成功只更新已确认的 unlocked 字段,
127
- // 不为了补全状态隐式轮询 DeviceStatus。
128
- if (device.features?.unlocked === false) {
129
- await device.unlockDevice();
130
- }
131
-
132
- // 标准钱包不需要 DeviceSession。锁屏时先解锁刷新状态,
133
- // 确认未开启 passphrase 后不得再生成或传递隐藏钱包 passphraseState。
134
- if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
135
- return {
136
- passphraseState: undefined,
137
- newSession: undefined,
138
- unlockedAttachPin: false,
139
- };
140
- }
141
-
142
- const cachedSessionId =
143
- typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
144
- let response;
145
- let recoveryFailed = false;
45
+ // Unlock with PIN first. DeviceSessionGet operates on the wallet selected by
46
+ // the device unlock flow; Protocol V2 does not accept a host passphrase here.
47
+ if (device.features?.unlocked === false) {
48
+ await device.unlockDevice();
49
+ }
146
50
 
147
- if (cachedSessionId && expectedPassphraseState) {
148
- try {
149
- response = await openDeviceSession(device, {
150
- resume: { session_id: cachedSessionId },
151
- });
152
- } catch (error) {
153
- if (!isProtocolV2InvalidSessionError(error)) {
154
- throw error;
155
- }
156
- device.clearInternalState();
157
- recoveryFailed = true;
158
- }
159
- }
51
+ // A standard wallet needs no DeviceSession. After unlock confirms passphrase is
52
+ // disabled, do not create or forward a hidden-wallet passphraseState.
53
+ if (options?.onlyMainPin || device.getCurrentPassphraseProtection() === false) {
54
+ return {
55
+ passphraseState: undefined,
56
+ newSession: undefined,
57
+ unlockedAttachPin: device.features?.unlockedAttachPin ?? false,
58
+ resumed: false,
59
+ };
60
+ }
160
61
 
161
- if (!response) {
162
- const promptPayload: PassphraseRequestPayload = {
163
- source: 'wallet-session-coordinator',
164
- reason: recoveryFailed ? 'session-recovery' : 'open-wallet',
165
- expectedPassphraseState,
166
- existsAttachPinUser: device.features?.attachToPinEnabled === true,
167
- };
168
- response = await openSelectedHiddenWallet(device, promptPayload);
169
- }
62
+ const cachedSessionId =
63
+ typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
64
+ let response;
65
+ let resumed = false;
170
66
 
171
- const { message } = response;
172
- if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
67
+ if (cachedSessionId && expectedPassphraseState) {
68
+ try {
69
+ response = await getDeviceSession(device, { session_id: cachedSessionId });
70
+ resumed = true;
71
+ } catch (error) {
173
72
  device.clearInternalState();
174
- throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
73
+ throw error;
175
74
  }
75
+ }
176
76
 
177
- device.updateInternalState(
178
- true,
179
- message.btc_test_address,
180
- device.getCurrentDeviceId(),
181
- message.session_id,
182
- options?.initSession ? null : device.features?.sessionId ?? null
183
- );
77
+ if (!response) {
78
+ response = await getDeviceSession(device, {});
79
+ }
184
80
 
185
- return {
186
- passphraseState: message.btc_test_address,
187
- newSession: message.session_id,
188
- unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
189
- };
81
+ const { message } = response;
82
+ try {
83
+ assertCompleteDeviceSession(message);
190
84
  } catch (error) {
191
- if (isProtocolV2InvalidSessionError(error)) {
192
- device.clearInternalState();
193
- }
85
+ device.clearInternalState();
194
86
  throw error;
195
87
  }
88
+ if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
89
+ device.clearInternalState();
90
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
91
+ }
92
+
93
+ device.updateInternalState(
94
+ true,
95
+ message.btc_test_address,
96
+ device.getCurrentDeviceId(),
97
+ message.session_id,
98
+ options?.initSession ? null : device.features?.sessionId ?? null
99
+ );
100
+
101
+ return {
102
+ passphraseState: message.btc_test_address,
103
+ newSession: message.session_id,
104
+ unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
105
+ resumed,
106
+ };
196
107
  }
@@ -1,8 +1,7 @@
1
1
  import type { IBLEFirmwareReleaseInfo } from '../settings';
2
2
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
3
- import type { Features } from '@onekeyfe/hd-transport';
4
3
  import type { CommonParams, Response } from '../params';
5
- import type { IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus } from '../device';
4
+ import type { Features, IDeviceBLEFirmwareStatus, IDeviceFirmwareStatus } from '../device';
6
5
 
7
6
  export type FirmwareRelease = {
8
7
  shouldUpdate?: boolean;
@@ -17,6 +17,7 @@ export type DeviceSettingsParams = {
17
17
  brightness?: number;
18
18
  hapticFeedback?: boolean;
19
19
  bluetoothEnabled?: boolean;
20
+ airgapMode?: boolean;
20
21
  animationEnabled?: boolean;
21
22
  tapToWake?: boolean;
22
23
  deviceNameDisplayEnabled?: boolean;
@@ -1,4 +1,4 @@
1
- import type { Features } from '@onekeyfe/hd-transport';
1
+ import type { Features } from '../device';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export declare function deviceUnlock(connectId: string, params?: CommonParams): Response<Features>;
@@ -58,8 +58,8 @@ export interface FirmwareUpdateV3Params {
58
58
  }
59
59
 
60
60
  /**
61
- * firmwareUpdateV4(Protocol V2)按 DeviceFirmwareTargetType 拆分的目标二进制。
62
- * romloader 外,每个字段对应一个 bootloader 可接受的固件升级 target
61
+ * firmwareUpdateV4 target binaries grouped by DeviceFirmwareTargetType.
62
+ * Except for romloader, each field maps to a target accepted by bootloader.
63
63
  */
64
64
  export type FirmwareUpdateV4Target =
65
65
  | 'boot'
@@ -78,7 +78,7 @@ export interface FirmwareUpdateV4Params {
78
78
  firmwareType?: EFirmwareType;
79
79
  targetsToUpdate?: FirmwareUpdateV4Target[];
80
80
 
81
- /** FW_MGMT_TARGET_ROMLOADER = 2;当前 Pro2 bootloader 不接受通过 firmwareUpdateV4 安装 */
81
+ /** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
82
82
  romloaderBinary?: ArrayBuffer;
83
83
  /** FW_MGMT_TARGET_BOOTLOADER = 3 */
84
84
  bootloaderBinary?: ArrayBuffer;
@@ -95,8 +95,8 @@ export interface FirmwareUpdateV4Params {
95
95
  se04Binary?: ArrayBuffer;
96
96
  forcedUpdateRes?: boolean;
97
97
  /**
98
- * RESC bundle okpkg 列表,通过 FilesystemFileWrite 直写到 devicePath(vol0:/bundles/...)。
99
- * 手动传入模式:SDK 直接 FileWrite 安装,不做版本比对。
98
+ * RESC bundle okpkg files written directly to devicePath through FilesystemFileWrite.
99
+ * Manual mode installs them without version comparison.
100
100
  */
101
101
  resourceBundleFiles?: Array<{
102
102
  binary: ArrayBuffer;
@@ -7,7 +7,7 @@ export type GetDeviceStateParams = CommonParams & {
7
7
  scope?: DeviceStateScope;
8
8
  };
9
9
 
10
- /** SDK 内部状态读取选项,不属于公共 CoreApi */
10
+ /** Internal state-read options, not part of the public CoreApi. */
11
11
  export type DeviceStateReadOptions = {
12
12
  refreshSections?: DeviceStateSection[];
13
13
  includeRaw?: boolean;
@@ -1,4 +1,7 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type { Features } from '../device';
3
3
 
4
+ /**
5
+ * @deprecated Use `getDeviceState` for both Protocol V1 and Protocol V2 devices.
6
+ */
4
7
  export declare function getFeatures(connectId?: string, params?: CommonParams): Response<Features>;
@@ -1,6 +1,9 @@
1
1
  import type { CommonParams, Response } from '../params';
2
2
  import type { OnekeyFeatures } from '../device';
3
3
 
4
+ /**
5
+ * @deprecated Use `getDeviceState(connectId, { scope: 'firmware' })`.
6
+ */
4
7
  export declare function getOnekeyFeatures(
5
8
  connectId?: string,
6
9
  params?: CommonParams
@@ -2,6 +2,12 @@ import type { CommonParams, Response } from '../params';
2
2
 
3
3
  export type GetPassphraseStateParams = CommonParams;
4
4
 
5
+ /**
6
+ * Legacy Protocol V1 wallet API.
7
+ *
8
+ * This remains supported for Protocol V1 integrations. New cross-protocol integrations
9
+ * and all Protocol V2 callers should use `openWalletSession`.
10
+ */
5
11
  export declare function getPassphraseState(
6
12
  connectId?: string,
7
13
  params?: GetPassphraseStateParams
@@ -4,10 +4,12 @@ import type {
4
4
  deviceFirmwareUpdate,
5
5
  deviceGetFirmwareUpdateStatus,
6
6
  deviceGetOnboardingStatus,
7
+ deviceInfoGet,
7
8
  deviceReboot,
8
- deviceSessionOpen,
9
+ deviceSettingsGet,
9
10
  deviceSettingsPageShow,
10
11
  deviceSettingsSet,
12
+ deviceStatusGet,
11
13
  deviceUploadWallpaper,
12
14
  dirList,
13
15
  dirMake,
@@ -15,14 +17,7 @@ import type {
15
17
  fileDelete,
16
18
  fileRead,
17
19
  fileWrite,
18
- filesystemDirList,
19
- filesystemDirMake,
20
- filesystemDirRemove,
21
- filesystemFileDelete,
22
- filesystemFileRead,
23
- filesystemFileWrite,
24
20
  filesystemFormat,
25
- filesystemPathInfoQuery,
26
21
  filesystemPermissionFix,
27
22
  pathInfo,
28
23
  ping,
@@ -46,6 +41,7 @@ import type { getFeatures } from './getFeatures';
46
41
  import type { getDeviceState } from './getDeviceState';
47
42
  import type { getOnekeyFeatures } from './getOnekeyFeatures';
48
43
  import type { getPassphraseState } from './getPassphraseState';
44
+ import type { openWalletSession } from './openWalletSession';
49
45
  import type { checkFirmwareRelease } from './checkFirmwareRelease';
50
46
  import type { checkBLEFirmwareRelease } from './checkBLEFirmwareRelease';
51
47
  import type {
@@ -171,6 +167,7 @@ import type { ConnectSettings } from '../settings';
171
167
  export * from './export';
172
168
  export type { DeviceStateScope, GetDeviceStateParams } from './getDeviceState';
173
169
  export type { GetPassphraseStateParams } from './getPassphraseState';
170
+ export type { OpenWalletSessionParams, OpenWalletSessionPayload } from './openWalletSession';
174
171
  export type { ClearSessionCacheParams, ClearSessionCachePayload } from './sessionCache';
175
172
 
176
173
  export type CoreApi = {
@@ -182,7 +179,7 @@ export type CoreApi = {
182
179
  off: typeof off;
183
180
  emit: (event: string, ...args: any[]) => void;
184
181
  removeAllListeners: typeof removeAllListeners;
185
- dispose: () => void;
182
+ dispose: () => void | Promise<void>;
186
183
  call: (params: any) => Promise<any>;
187
184
  uiResponse: typeof uiResponse;
188
185
  cancel: (connectId?: string) => void;
@@ -216,6 +213,7 @@ export type CoreApi = {
216
213
  getDeviceState: typeof getDeviceState;
217
214
  getOnekeyFeatures: typeof getOnekeyFeatures;
218
215
  getPassphraseState: typeof getPassphraseState;
216
+ openWalletSession: typeof openWalletSession;
219
217
  deviceBackup: typeof deviceBackup;
220
218
  deviceChangePin: typeof deviceChangePin;
221
219
  deviceFlags: typeof deviceFlags;
@@ -245,21 +243,25 @@ export type CoreApi = {
245
243
  cipherKeyValue: typeof cipherKeyValue;
246
244
 
247
245
  /**
248
- * File system & device control API (Protocol V2 only)
246
+ * Pro2 business API
249
247
  */
250
- protocolInfoRequest: typeof protocolInfoRequest;
251
- ping: typeof ping;
252
248
  deviceReboot: typeof deviceReboot;
253
249
  deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
254
- deviceSessionOpen: typeof deviceSessionOpen;
250
+ deviceUploadWallpaper: typeof deviceUploadWallpaper;
251
+ deviceInfoGet: typeof deviceInfoGet;
252
+ deviceStatusGet: typeof deviceStatusGet;
253
+ deviceSettingsGet: typeof deviceSettingsGet;
254
+ protocolInfoRequest: typeof protocolInfoRequest;
255
+ ping: typeof ping;
255
256
  deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
256
257
  deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
257
258
  deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
258
259
  deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
259
260
  deviceSettingsSet: typeof deviceSettingsSet;
260
261
  deviceSettingsPageShow: typeof deviceSettingsPageShow;
261
- deviceUploadWallpaper: typeof deviceUploadWallpaper;
262
262
  filesystemPermissionFix: typeof filesystemPermissionFix;
263
+ filesystemFormat: typeof filesystemFormat;
264
+ uploadPortfolio: typeof uploadPortfolio;
263
265
  fileRead: typeof fileRead;
264
266
  fileWrite: typeof fileWrite;
265
267
  fileDelete: typeof fileDelete;
@@ -267,15 +269,6 @@ export type CoreApi = {
267
269
  dirMake: typeof dirMake;
268
270
  dirRemove: typeof dirRemove;
269
271
  pathInfo: typeof pathInfo;
270
- filesystemFileRead: typeof filesystemFileRead;
271
- filesystemFileWrite: typeof filesystemFileWrite;
272
- uploadPortfolio: typeof uploadPortfolio;
273
- filesystemFileDelete: typeof filesystemFileDelete;
274
- filesystemDirList: typeof filesystemDirList;
275
- filesystemDirMake: typeof filesystemDirMake;
276
- filesystemDirRemove: typeof filesystemDirRemove;
277
- filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
278
- filesystemFormat: typeof filesystemFormat;
279
272
 
280
273
  /**
281
274
  * All network function
@@ -0,0 +1,64 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ export type OpenWalletSessionParams =
4
+ | {
5
+ mode: 'standard';
6
+ deviceId?: never;
7
+ passphraseState?: never;
8
+ useEmptyPassphrase?: never;
9
+ initSession?: never;
10
+ }
11
+ | {
12
+ mode: 'select-hidden';
13
+ deviceId?: never;
14
+ passphraseState?: never;
15
+ useEmptyPassphrase?: never;
16
+ initSession?: never;
17
+ }
18
+ | {
19
+ mode: 'resume-hidden';
20
+ deviceId: string;
21
+ passphraseState: string;
22
+ useEmptyPassphrase?: never;
23
+ initSession?: never;
24
+ }
25
+ | {
26
+ /**
27
+ * Compatibility form. `useEmptyPassphrase: true` opens the standard wallet;
28
+ * otherwise `initSession: true` starts a fresh hidden-wallet selection, a
29
+ * complete wallet binding resumes a hidden wallet, and no binding starts the
30
+ * hidden-wallet selection flow.
31
+ */
32
+ mode?: undefined;
33
+ useEmptyPassphrase?: boolean;
34
+ initSession?: boolean;
35
+ deviceId?: string;
36
+ passphraseState?: string;
37
+ };
38
+
39
+ type OpenWalletSessionPayloadBase = {
40
+ protocol: 'V1' | 'V2';
41
+ deviceId: string;
42
+ resumed: boolean;
43
+ };
44
+
45
+ export type OpenWalletSessionPayload = OpenWalletSessionPayloadBase &
46
+ (
47
+ | {
48
+ walletType: 'standard';
49
+ passphraseState: null;
50
+ }
51
+ | {
52
+ walletType: 'hidden';
53
+ passphraseState: string;
54
+ }
55
+ );
56
+
57
+ /**
58
+ * Opens the standard, hidden, or Attach-to-PIN wallet flow through a unified
59
+ * Protocol V1/V2 API.
60
+ */
61
+ export declare function openWalletSession(
62
+ connectId: string,
63
+ params: CommonParams & OpenWalletSessionParams
64
+ ): Response<OpenWalletSessionPayload>;
@@ -3,8 +3,10 @@ import type {
3
3
  DevOnboardingStatus,
4
4
  DeviceFactoryInfo,
5
5
  DeviceFirmwareUpdateStatus,
6
- DeviceSession,
6
+ DeviceSettings,
7
+ DeviceStatus,
7
8
  ProtocolInfo,
9
+ ProtocolV2DeviceInfo,
8
10
  Success,
9
11
  } from '@onekeyfe/hd-transport';
10
12
  import type {
@@ -13,7 +15,7 @@ import type {
13
15
  DeviceFirmwareUpdateStatusGetParams,
14
16
  DeviceRebootParams,
15
17
  } from '../../api/protocol-v2/helpers';
16
- import type { DeviceSessionOpenParams } from '../../api/protocol-v2/DeviceSessionOpen';
18
+ import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
17
19
  import type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
18
20
  import type { DeviceSettingsPageShowParams } from '../../api/protocol-v2/DeviceSettingsPageShow';
19
21
  import type {
@@ -21,7 +23,7 @@ import type {
21
23
  DeviceUploadWallpaperResponse,
22
24
  } from '../../api/protocol-v2/DeviceUploadWallpaper';
23
25
 
24
- // 参数类型单源:以 api/protocol-v2 的实现为准(type-only re-export,无运行时依赖)
26
+ // Re-export implementation parameter types as the single source of truth.
25
27
  export type {
26
28
  DeviceFirmwareTargetInput,
27
29
  DeviceFirmwareUpdateParams,
@@ -30,7 +32,11 @@ export type {
30
32
  DeviceFactoryInfoSetParams,
31
33
  RebootTypeInput,
32
34
  } from '../../api/protocol-v2/helpers';
33
- export type { DeviceSessionOpenParams } from '../../api/protocol-v2/DeviceSessionOpen';
35
+ export type {
36
+ DeviceInfoGetParams,
37
+ DeviceInfoGetTargets,
38
+ DeviceInfoGetTypes,
39
+ } from '../../api/protocol-v2/DeviceInfoGet';
34
40
  export type { DeviceSettingsSetParams } from '../../api/protocol-v2/DeviceSettingsSet';
35
41
  export type {
36
42
  DeviceSettingsPageShowParams,
@@ -61,7 +67,7 @@ export type DirInfo = {
61
67
  child_files?: string;
62
68
  };
63
69
 
64
- // proto FilesystemPathInfo 的全部字段均为 required,类型与之保持一致
70
+ // All FilesystemPathInfo proto fields are required; keep this type aligned.
65
71
  export type PathInfoResult = {
66
72
  exist: boolean;
67
73
  size: number;
@@ -80,6 +86,25 @@ export type PathInfoResult = {
80
86
 
81
87
  // ── Method signatures ─────────────────────────────────────────────────────
82
88
 
89
+ /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
90
+ export declare function deviceInfoGet(
91
+ connectId: string,
92
+ params?: CommonParams & DeviceInfoGetParams
93
+ ): Response<ProtocolV2DeviceInfo>;
94
+
95
+ /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
96
+ export declare function deviceStatusGet(
97
+ connectId: string,
98
+ params?: CommonParams
99
+ ): Response<DeviceStatus>;
100
+
101
+ /** @deprecated Development-only raw Protocol V2 command. Use `getDeviceState`. */
102
+ export declare function deviceSettingsGet(
103
+ connectId: string,
104
+ params?: CommonParams
105
+ ): Response<DeviceSettings>;
106
+
107
+ /** @deprecated Development-only raw Protocol V2 command. */
83
108
  export declare function protocolInfoRequest(
84
109
  connectId: string,
85
110
  params?: CommonParams
@@ -100,11 +125,6 @@ export declare function deviceGetOnboardingStatus(
100
125
  params?: CommonParams
101
126
  ): Response<DevOnboardingStatus>;
102
127
 
103
- export declare function deviceSessionOpen(
104
- connectId: string,
105
- params: CommonParams & DeviceSessionOpenParams
106
- ): Response<DeviceSession>;
107
-
108
128
  export declare function deviceFirmwareUpdate(
109
129
  connectId: string,
110
130
  params: CommonParams & DeviceFirmwareUpdateParams
@@ -125,11 +145,17 @@ export declare function deviceFactoryInfoGet(
125
145
  params?: CommonParams
126
146
  ): Response<DeviceFactoryInfo>;
127
147
 
148
+ /**
149
+ * @deprecated Use the protocol-independent `deviceSettings`.
150
+ */
128
151
  export declare function deviceSettingsSet(
129
152
  connectId: string,
130
153
  params: CommonParams & DeviceSettingsSetParams
131
154
  ): Response<Success>;
132
155
 
156
+ /**
157
+ * @deprecated Use `deviceSettings`, `deviceChangePin`, or `deviceWipe`.
158
+ */
133
159
  export declare function deviceSettingsPageShow(
134
160
  connectId: string,
135
161
  params: CommonParams & DeviceSettingsPageShowParams
@@ -197,9 +223,6 @@ export declare function pathInfo(
197
223
  params: { path: string; timeoutMs?: number | string }
198
224
  ): Response<PathInfoResult>;
199
225
 
200
- export declare const filesystemFileRead: typeof fileRead;
201
- export declare const filesystemFileWrite: typeof fileWrite;
202
-
203
226
  export declare function uploadPortfolio(
204
227
  connectId: string,
205
228
  params: {
@@ -208,10 +231,5 @@ export declare function uploadPortfolio(
208
231
  timeoutMs?: number | string;
209
232
  }
210
233
  ): Response<FileInfo & { portfolioUpdated: true }>;
211
- export declare const filesystemFileDelete: typeof fileDelete;
212
- export declare const filesystemDirList: typeof dirList;
213
- export declare const filesystemDirMake: typeof dirMake;
214
- export declare const filesystemDirRemove: typeof dirRemove;
215
- export declare const filesystemPathInfoQuery: typeof pathInfo;
216
234
 
217
235
  export declare function filesystemFormat(connectId: string): Response<Success>;