@onekeyfe/hd-core 1.2.0-alpha.41 → 1.2.0-alpha.42

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 (200) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +78 -0
  2. package/__tests__/DeviceEventRegistration.test.ts +6 -0
  3. package/__tests__/check-all-firmware-release-protocol-v2.test.ts +14 -1
  4. package/__tests__/connectSettings.test.ts +5 -47
  5. package/__tests__/deviceUploadNft.test.ts +187 -0
  6. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +31 -59
  7. package/__tests__/get-device-state.test.ts +132 -12
  8. package/__tests__/homescreen.test.ts +41 -1
  9. package/__tests__/logBlockEvent.test.ts +1 -1
  10. package/__tests__/open-wallet-session.test.ts +259 -18
  11. package/__tests__/pro2Nft.test.ts +108 -0
  12. package/__tests__/protocol-v2-resources.test.ts +204 -0
  13. package/__tests__/protocol-v2-ui-lifecycle.test.ts +56 -0
  14. package/__tests__/protocol-v2-unlock-policy.test.ts +86 -35
  15. package/__tests__/protocol-v2.test.ts +526 -955
  16. package/__tests__/public-pro2-api-boundary.test.ts +1 -0
  17. package/__tests__/uiProgressThrottle.test.ts +74 -0
  18. package/dist/api/BaseMethod.d.ts +3 -1
  19. package/dist/api/BaseMethod.d.ts.map +1 -1
  20. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  21. package/dist/api/FirmwareUpdateV2.d.ts +0 -11
  22. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  23. package/dist/api/FirmwareUpdateV3.d.ts +3 -7
  24. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  25. package/dist/api/FirmwareUpdateV4.d.ts +6 -25
  26. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  27. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  28. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  29. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  30. package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
  31. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  32. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -8
  33. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  34. package/dist/api/firmware/getBinary.d.ts +0 -7
  35. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  36. package/dist/api/firmware/updateBootloader.d.ts +0 -2
  37. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  38. package/dist/api/firmware/uploadFirmware.d.ts +1 -9
  39. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  40. package/dist/api/helpers/protocolV2FileWrite.d.ts +2 -0
  41. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  42. package/dist/api/index.d.ts +1 -0
  43. package/dist/api/index.d.ts.map +1 -1
  44. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +30 -0
  45. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
  46. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  47. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  48. package/dist/core/deviceEventRegistration.d.ts +2 -0
  49. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  50. package/dist/core/index.d.ts.map +1 -1
  51. package/dist/data-manager/DataManager.d.ts +3 -2
  52. package/dist/data-manager/DataManager.d.ts.map +1 -1
  53. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  54. package/dist/device/Device.d.ts +22 -4
  55. package/dist/device/Device.d.ts.map +1 -1
  56. package/dist/events/device.d.ts +4 -0
  57. package/dist/events/device.d.ts.map +1 -1
  58. package/dist/events/logBlockEvent.d.ts.map +1 -1
  59. package/dist/events/ui-request.d.ts +27 -2
  60. package/dist/events/ui-request.d.ts.map +1 -1
  61. package/dist/index.d.ts +110 -182
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +1919 -3336
  64. package/dist/inject.d.ts.map +1 -1
  65. package/dist/lowLevelInject.d.ts.map +1 -1
  66. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  67. package/dist/protocols/protocol-v2/resources.d.ts +30 -0
  68. package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
  69. package/dist/protocols/protocol-v2/uiInteraction.d.ts +3 -3
  70. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  71. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
  72. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  73. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
  74. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
  75. package/dist/protocols/protocol-v2/walletSession.d.ts +4 -1
  76. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  77. package/dist/topLevelInject.d.ts.map +1 -1
  78. package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -4
  79. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  80. package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
  81. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  82. package/dist/types/api/export.d.ts +1 -4
  83. package/dist/types/api/export.d.ts.map +1 -1
  84. package/dist/types/api/firmwareUpdate.d.ts +0 -69
  85. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  86. package/dist/types/api/index.d.ts +3 -10
  87. package/dist/types/api/index.d.ts.map +1 -1
  88. package/dist/types/api/protocolV2.d.ts +3 -0
  89. package/dist/types/api/protocolV2.d.ts.map +1 -1
  90. package/dist/types/settings.d.ts +12 -13
  91. package/dist/types/settings.d.ts.map +1 -1
  92. package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
  93. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  94. package/dist/utils/homescreen.d.ts +4 -0
  95. package/dist/utils/homescreen.d.ts.map +1 -1
  96. package/dist/utils/index.d.ts +1 -1
  97. package/dist/utils/index.d.ts.map +1 -1
  98. package/dist/utils/patch.d.ts +1 -1
  99. package/dist/utils/patch.d.ts.map +1 -1
  100. package/dist/utils/pro2Nft.d.ts +29 -0
  101. package/dist/utils/pro2Nft.d.ts.map +1 -0
  102. package/dist/utils/pro2Wallpaper.d.ts +10 -0
  103. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  104. package/dist/utils/uiProgressThrottle.d.ts +3 -0
  105. package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
  106. package/package.json +4 -4
  107. package/src/api/BaseMethod.ts +8 -10
  108. package/src/api/CheckAllFirmwareRelease.ts +40 -53
  109. package/src/api/FirmwareUpdateV2.ts +120 -298
  110. package/src/api/FirmwareUpdateV3.ts +57 -263
  111. package/src/api/FirmwareUpdateV4.ts +307 -912
  112. package/src/api/GetPassphraseState.ts +7 -1
  113. package/src/api/OpenWalletSession.ts +54 -17
  114. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +32 -11
  115. package/src/api/device/DeviceUnlock.ts +1 -1
  116. package/src/api/device/DeviceUpdateBootloader.ts +6 -122
  117. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +0 -57
  118. package/src/api/firmware/updateBootloader.ts +4 -19
  119. package/src/api/firmware/uploadFirmware.ts +22 -140
  120. package/src/api/helpers/protocolV2FileWrite.ts +11 -4
  121. package/src/api/index.ts +1 -0
  122. package/src/api/protocol-v2/DeviceUploadNft.ts +166 -0
  123. package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
  124. package/src/core/deviceEventRegistration.ts +4 -0
  125. package/src/core/index.ts +118 -75
  126. package/src/data/messages/messages-protocol-v2.json +53 -0
  127. package/src/data-manager/DataManager.ts +63 -38
  128. package/src/data-manager/connectSettings.ts +0 -11
  129. package/src/device/Device.ts +193 -21
  130. package/src/events/device.ts +4 -0
  131. package/src/events/logBlockEvent.ts +1 -0
  132. package/src/events/ui-request.ts +32 -2
  133. package/src/index.ts +0 -5
  134. package/src/inject.ts +3 -22
  135. package/src/lowLevelInject.ts +1 -5
  136. package/src/protocols/protocol-v2/features.ts +9 -2
  137. package/src/protocols/protocol-v2/resources.ts +233 -0
  138. package/src/protocols/protocol-v2/uiInteraction.ts +31 -5
  139. package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
  140. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +117 -0
  141. package/src/protocols/protocol-v2/walletSession.ts +93 -18
  142. package/src/topLevelInject.ts +1 -5
  143. package/src/types/api/checkAllFirmwareRelease.ts +1 -4
  144. package/src/types/api/deviceUpdateBootloader.ts +0 -6
  145. package/src/types/api/export.ts +0 -18
  146. package/src/types/api/firmwareUpdate.ts +0 -76
  147. package/src/types/api/index.ts +2 -14
  148. package/src/types/api/protocolV2.ts +13 -0
  149. package/src/types/settings.ts +26 -13
  150. package/src/utils/deviceFeaturesUtils.ts +4 -0
  151. package/src/utils/homescreen.ts +32 -6
  152. package/src/utils/index.ts +6 -1
  153. package/src/utils/pro2Nft.ts +91 -0
  154. package/src/utils/pro2Wallpaper.ts +35 -8
  155. package/src/utils/uiProgressThrottle.ts +63 -0
  156. package/__tests__/firmware-update/check-all-firmware-release.test.ts +0 -175
  157. package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
  158. package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
  159. package/__tests__/firmware-update/firmware-preparation-error.test.ts +0 -27
  160. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
  161. package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -593
  162. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -213
  163. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +0 -58
  164. package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
  165. package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -25
  166. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
  167. package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
  168. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
  169. package/dist/api/firmware/FirmwarePreparationError.d.ts +0 -3
  170. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +0 -1
  171. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
  172. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
  173. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -25
  174. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
  175. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -30
  176. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
  177. package/dist/api/firmware/progressThrottle.d.ts +0 -3
  178. package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
  179. package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
  180. package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
  181. package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
  182. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
  183. package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
  184. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
  185. package/dist/types/api/firmwareUpdatePlan.d.ts +0 -28
  186. package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
  187. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
  188. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
  189. package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
  190. package/src/api/firmware/FirmwareHostBinding.ts +0 -100
  191. package/src/api/firmware/FirmwarePreparationError.ts +0 -12
  192. package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
  193. package/src/api/firmware/FirmwareUpdatePlan.ts +0 -745
  194. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -392
  195. package/src/api/firmware/progressThrottle.ts +0 -44
  196. package/src/protocols/protocol-v2/lockedError.ts +0 -10
  197. package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
  198. package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
  199. package/src/types/api/firmwareUpdatePlan.ts +0 -38
  200. package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
@@ -38,10 +38,26 @@ export async function refreshProtocolV2DeviceStatus(device: Device) {
38
38
  return device.updateProtocolV2Status(status);
39
39
  }
40
40
 
41
- const negotiateEventlessWalletSession = async (device: Device) => {
42
- await device.commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
43
- eventless_wallet_session: true,
41
+ export async function ensureProtocolV2WalletSessionUnlocked(device: Device) {
42
+ if (!device.isProtocolV2() || device.isBootloader?.() || device.isRomloader?.()) {
43
+ return false;
44
+ }
45
+
46
+ await refreshProtocolV2DeviceStatus(device);
47
+ if (device.state?.status.unlocked !== false) {
48
+ return false;
49
+ }
50
+
51
+ await device.unlockDevice(DeviceSessionPinType.Main, {
52
+ source: 'unlock-coordinator',
53
+ reason: 'device-locked',
54
+ deviceOnly: true,
44
55
  });
56
+ return true;
57
+ }
58
+
59
+ const negotiateEventlessWalletSession = async (device: Device) => {
60
+ await device.ensureProtocolV2RuntimeContext();
45
61
  };
46
62
 
47
63
  const getDeviceSession = async (device: Device, request: DeviceSessionGet) =>
@@ -59,11 +75,13 @@ const selectDeviceSession = async (device: Device, expectedPassphraseState?: str
59
75
  reason: expectedPassphraseState ? ('session-recovery' as const) : ('open-wallet' as const),
60
76
  ...(expectedPassphraseState ? { expectedPassphraseState } : {}),
61
77
  };
78
+ const passphraseInteraction = device.createProtocolV2UiPhaseMetadata?.('passphrase', 'start');
62
79
  const response = await device.commands.promptPassphrase(
63
80
  {
64
81
  existsAttachPinUser,
65
82
  deviceOnly: false,
66
83
  ...metadata,
84
+ ...(passphraseInteraction ? { interaction: passphraseInteraction } : {}),
67
85
  },
68
86
  { cancelDeviceOnReject: false }
69
87
  );
@@ -102,8 +120,15 @@ const selectDeviceSession = async (device: Device, expectedPassphraseState?: str
102
120
  'Attach PIN wallet selection is unavailable on this device.'
103
121
  );
104
122
  }
105
- device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, metadata);
106
- await device.unlockDevice(DeviceSessionPinType.AttachToPin);
123
+ const attachPinInteraction = device.createProtocolV2UiPhaseMetadata?.('pin', 'start');
124
+ device.emit(DEVICE.ATTACH_PIN_ON_DEVICE, device, {
125
+ ...metadata,
126
+ ...(attachPinInteraction ? { interaction: attachPinInteraction } : {}),
127
+ });
128
+ await device.unlockDevice(DeviceSessionPinType.AttachToPin, {
129
+ emitUiEvent: false,
130
+ interaction: attachPinInteraction,
131
+ });
107
132
  return getDeviceSession(device, {});
108
133
  }
109
134
 
@@ -115,7 +140,10 @@ const selectDeviceSession = async (device: Device, expectedPassphraseState?: str
115
140
  return getDeviceSession(device, {});
116
141
  }
117
142
 
118
- device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, metadata);
143
+ device.emit(DEVICE.PASSPHRASE_ON_DEVICE, device, {
144
+ ...metadata,
145
+ ...(passphraseInteraction ? { interaction: passphraseInteraction } : {}),
146
+ });
119
147
  await askDevicePassphrase(device, { on_device: true });
120
148
  return getDeviceSession(device, {});
121
149
  };
@@ -128,7 +156,9 @@ export async function getProtocolV2WalletSession(
128
156
  initSession?: boolean;
129
157
  expectedPassphraseState?: string;
130
158
  onlyMainPin?: boolean;
159
+ selectMainWalletBeforeRestore?: boolean;
131
160
  resumeOnly?: boolean;
161
+ deriveCardano?: boolean;
132
162
  }
133
163
  ) {
134
164
  const forceWalletSelection =
@@ -161,13 +191,48 @@ export async function getProtocolV2WalletSession(
161
191
  : undefined;
162
192
  let response;
163
193
  let resumed = false;
194
+ let mainWalletSelected = false;
195
+
196
+ const clearCurrentWalletSession = () => {
197
+ if (options?.onlyMainPin) {
198
+ device.clearStandardInternalState?.();
199
+ } else {
200
+ device.clearInternalState();
201
+ }
202
+ };
203
+
204
+ const rejectMismatchedAttachPinWallet = async () => {
205
+ const features = await refreshProtocolV2DeviceStatus(device);
206
+ if (features.unlockedAttachPin !== true) {
207
+ return;
208
+ }
209
+
210
+ try {
211
+ await device.lockDevice();
212
+ } catch {
213
+ // Reject the mismatched Attach PIN wallet even when older firmware cannot lock.
214
+ }
215
+ clearCurrentWalletSession();
216
+ throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
217
+ };
218
+
219
+ const selectMainWallet = async (force = false) => {
220
+ if (force || !mainWalletSelected) {
221
+ await device.unlockDevice(DeviceSessionPinType.Main, {
222
+ source: 'wallet-session-coordinator',
223
+ reason: expectedPassphraseState ? 'session-recovery' : 'open-wallet',
224
+ deviceOnly: true,
225
+ });
226
+ mainWalletSelected = true;
227
+ }
228
+ };
164
229
 
165
230
  if (options?.onlyMainPin) {
166
231
  expectedPassphraseState = cachedStandardSession?.passphraseState;
167
232
  if (cachedStandardSession) {
168
233
  try {
169
- if (device.features?.unlockedAttachPin === true) {
170
- await device.unlockDevice(DeviceSessionPinType.Main);
234
+ if (options?.selectMainWalletBeforeRestore) {
235
+ await selectMainWallet();
171
236
  }
172
237
  response = await getDeviceSession(device, {
173
238
  session_id: cachedStandardSession.sessionId,
@@ -183,12 +248,14 @@ export async function getProtocolV2WalletSession(
183
248
  }
184
249
 
185
250
  if (!response) {
186
- await device.unlockDevice(DeviceSessionPinType.Main);
251
+ await selectMainWallet();
187
252
  response = await getDeviceSession(device, {});
188
253
  }
189
254
  } else if (cachedSessionId && expectedPassphraseState) {
190
255
  try {
191
- response = await getDeviceSession(device, { session_id: cachedSessionId });
256
+ response = await getDeviceSession(device, {
257
+ session_id: cachedSessionId,
258
+ });
192
259
  resumed = true;
193
260
  } catch (error) {
194
261
  device.clearInternalState();
@@ -197,6 +264,14 @@ export async function getProtocolV2WalletSession(
197
264
  }
198
265
  resumed = false;
199
266
  }
267
+ } else if (expectedPassphraseState) {
268
+ try {
269
+ response = await getDeviceSession(device, {});
270
+ } catch (error) {
271
+ if (options?.resumeOnly || !isWalletSessionInvalidError(error)) {
272
+ throw error;
273
+ }
274
+ }
200
275
  }
201
276
 
202
277
  if (!response) {
@@ -220,13 +295,14 @@ export async function getProtocolV2WalletSession(
220
295
  }
221
296
  if (expectedPassphraseState && expectedPassphraseState !== message.btc_test_address) {
222
297
  resumed = false;
298
+ await rejectMismatchedAttachPinWallet();
223
299
  if (options?.resumeOnly) {
224
300
  device.clearInternalState();
225
301
  throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
226
302
  }
227
303
  if (options?.onlyMainPin) {
228
304
  device.clearStandardInternalState?.();
229
- await device.unlockDevice(DeviceSessionPinType.Main);
305
+ await selectMainWallet(true);
230
306
  response = await getDeviceSession(device, {});
231
307
  } else {
232
308
  device.clearInternalState();
@@ -244,11 +320,8 @@ export async function getProtocolV2WalletSession(
244
320
  throw error;
245
321
  }
246
322
  if (expectedPassphraseState !== message.btc_test_address) {
247
- if (options?.onlyMainPin) {
248
- device.clearStandardInternalState?.();
249
- } else {
250
- device.clearInternalState();
251
- }
323
+ await rejectMismatchedAttachPinWallet();
324
+ clearCurrentWalletSession();
252
325
  throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
253
326
  }
254
327
  }
@@ -269,17 +342,19 @@ export async function getProtocolV2WalletSession(
269
342
  return {
270
343
  passphraseState: message.btc_test_address,
271
344
  newSession: message.session_id,
272
- unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
345
+ unlockedAttachPin: mainWalletSelected ? false : undefined,
273
346
  resumed,
274
347
  };
275
348
  }
276
349
 
277
350
  export async function restoreProtocolV2WalletSession(
278
351
  device: Device,
279
- expectedPassphraseState: string
352
+ expectedPassphraseState: string,
353
+ deriveCardano?: boolean
280
354
  ) {
281
355
  return getProtocolV2WalletSession(device, {
282
356
  expectedPassphraseState,
283
357
  resumeOnly: true,
358
+ deriveCardano,
284
359
  });
285
360
  }
@@ -1,7 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
 
3
3
  import { createCoreApi } from './inject';
4
- import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
5
4
 
6
5
  import type { ConnectSettings } from './types/settings';
7
6
  import type { CoreApi } from './types/api';
@@ -47,10 +46,7 @@ export const topLevelInject = () => {
47
46
  lowLevelApi?.removeAllListeners(type);
48
47
  },
49
48
 
50
- dispose: async () => {
51
- unregisterFirmwareUpdateHostBinding();
52
- await lowLevelApi?.dispose();
53
- },
49
+ dispose: () => lowLevelApi?.dispose(),
54
50
 
55
51
  uiResponse: response => lowLevelApi?.uiResponse(response),
56
52
 
@@ -12,7 +12,6 @@ import type {
12
12
  IProtocolV2FirmwareComponentTarget,
13
13
  } from '../settings';
14
14
  import type { FirmwareUpdateV4Target } from './firmwareUpdate';
15
- import type { FirmwareUpdatePlan, FirmwareUpdatePlanForceTarget } from './firmwareUpdatePlan';
16
15
 
17
16
  export type FirmwareRelease = {
18
17
  shouldUpdate?: boolean;
@@ -60,18 +59,16 @@ export type AllFirmwareRelease = {
60
59
  status?: ProtocolV2FirmwareReleaseStatus;
61
60
  hasUpgrade?: boolean;
62
61
  required?: boolean;
62
+ resourceStatus?: 'valid' | 'outdated' | 'unknown';
63
63
  currentVersions?: DeviceStateVersions;
64
64
  components?: ProtocolV2FirmwareComponentRelease[];
65
65
  targetsToUpdate?: FirmwareUpdateV4Target[];
66
66
  release?: IFirmwareReleaseInfo;
67
- firmwareUpdatePlan?: FirmwareUpdatePlan;
68
67
  };
69
68
 
70
69
  export type CheckAllFirmwareReleaseParams = {
71
70
  checkBridgeRelease?: boolean;
72
71
  firmwareType?: EFirmwareType;
73
- platform?: 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
74
- forceUpdateTargets?: FirmwareUpdatePlanForceTarget[];
75
72
  };
76
73
 
77
74
  export declare function checkAllFirmwareRelease(
@@ -1,15 +1,9 @@
1
1
  import type { Success } from '@onekeyfe/hd-transport';
2
2
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
3
- import type { FirmwareArtifactReader, FirmwareArtifactReference } from './firmwareUpdate';
4
- import type { FirmwareUpdatePreparedPlan } from './firmwareUpdatePreparedPlan';
5
3
  import type { Response } from '../params';
6
4
 
7
5
  export type DeviceUpdateBootloaderParams = {
8
- preparedPlan?: FirmwareUpdatePreparedPlan;
9
- hostBindingGeneration?: number;
10
6
  binary?: ArrayBuffer;
11
- artifact?: FirmwareArtifactReference;
12
- artifactReader?: FirmwareArtifactReader;
13
7
  firmwareType?: EFirmwareType;
14
8
  };
15
9
 
@@ -25,30 +25,12 @@ export type {
25
25
  DeviceUploadResourceResponse,
26
26
  } from './deviceUploadResource';
27
27
  export type {
28
- FirmwareArtifactReader,
29
- FirmwareArtifactReference,
30
- FirmwareUpdateHostBinding,
31
- FirmwareUpdateArtifactParams,
32
28
  FirmwareUpdateParams,
33
29
  FirmwareUpdateBinaryParams,
34
30
  FirmwareUpdateV3Params,
35
31
  FirmwareUpdateV4Params,
36
32
  FirmwareUpdateV4Target,
37
33
  } from './firmwareUpdate';
38
- export type {
39
- FirmwareUpdatePlan,
40
- FirmwareUpdatePlanArtifact,
41
- FirmwareUpdatePlanArtifactRole,
42
- FirmwareUpdatePlanForceTarget,
43
- FirmwareUpdatePlanTarget,
44
- } from './firmwareUpdatePlan';
45
- export type {
46
- FirmwareUpdatePreparedArtifact,
47
- FirmwareUpdatePreparedArtifactInput,
48
- FirmwareUpdatePreparedEntry,
49
- FirmwareUpdatePreparedPlan,
50
- } from './firmwareUpdatePreparedPlan';
51
- export type { FirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
52
34
  export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
53
35
  export type {
54
36
  ProtocolV2FirmwareComponentRelease,
@@ -1,53 +1,14 @@
1
1
  import type { EFirmwareType } from '@onekeyfe/hd-shared';
2
2
  import type { PROTO } from '../../constants';
3
3
  import type { Params, Response } from '../params';
4
- import type { FirmwareUpdatePreparedPlan } from './firmwareUpdatePreparedPlan';
5
4
 
6
5
  type IUpdateType = 'firmware' | 'ble';
7
6
 
8
- export interface FirmwareArtifactReference {
9
- artifactRef: string;
10
- size: number;
11
- sha256: string;
12
- }
13
-
14
- export interface FirmwareArtifactReader {
15
- open(input: { artifactRef: string }): Promise<{
16
- readerId: string;
17
- size: number;
18
- }>;
19
- read(input: { readerId: string; offset: number; length: number }): Promise<{
20
- data: ArrayBuffer;
21
- bytesRead: number;
22
- eof: boolean;
23
- }>;
24
- close(input: { readerId: string }): Promise<void>;
25
- }
26
-
27
- export interface FirmwareUpdateHostBinding {
28
- artifactReader: FirmwareArtifactReader;
29
- }
30
-
31
7
  export interface FirmwareUpdateBinaryParams {
32
8
  binary: ArrayBuffer;
33
9
  updateType: IUpdateType;
34
10
  }
35
11
 
36
- export interface FirmwareUpdateArtifactParams {
37
- preparedPlan: FirmwareUpdatePreparedPlan;
38
- hostBindingGeneration: number;
39
- artifact: FirmwareArtifactReference;
40
- resourceArtifact?: FirmwareArtifactReference;
41
- resourceEntries?: Array<{
42
- entryName: string;
43
- artifact: FirmwareArtifactReference;
44
- }>;
45
- updateType: IUpdateType;
46
- forcedUpdateRes?: boolean;
47
- isUpdateBootloader?: boolean;
48
- firmwareType?: EFirmwareType;
49
- }
50
-
51
12
  export interface FirmwareUpdateParams {
52
13
  version?: number[];
53
14
  updateType: IUpdateType;
@@ -76,14 +37,8 @@ export declare function firmwareUpdateV2(
76
37
  connectId: string | undefined,
77
38
  params: Params<FirmwareUpdateBinaryParams & Platform>
78
39
  ): Response<PROTO.Success>;
79
- export declare function firmwareUpdateV2(
80
- connectId: string | undefined,
81
- params: Params<FirmwareUpdateArtifactParams & Platform>
82
- ): Response<PROTO.Success>;
83
40
 
84
41
  export interface FirmwareUpdateV3Params {
85
- preparedPlan?: FirmwareUpdatePreparedPlan;
86
- hostBindingGeneration?: number;
87
42
  bleVersion?: number[];
88
43
  bleBinary?: ArrayBuffer;
89
44
  chunkSize?: number;
@@ -100,17 +55,6 @@ export interface FirmwareUpdateV3Params {
100
55
  firmwareType?: EFirmwareType;
101
56
 
102
57
  platform: IPlatform;
103
-
104
- artifactReader?: FirmwareArtifactReader;
105
- artifacts?: {
106
- ble?: FirmwareArtifactReference;
107
- firmware?: FirmwareArtifactReference;
108
- bootloader?: FirmwareArtifactReference;
109
- resourceEntries?: Array<{
110
- entryName: string;
111
- artifact: FirmwareArtifactReference;
112
- }>;
113
- };
114
58
  }
115
59
 
116
60
  /**
@@ -129,14 +73,10 @@ export type FirmwareUpdateV4Target =
129
73
  | 'se04';
130
74
 
131
75
  export interface FirmwareUpdateV4Params {
132
- preparedPlan?: FirmwareUpdatePreparedPlan;
133
- hostBindingGeneration?: number;
134
76
  platform: IPlatform;
135
- expectedDeviceId?: string;
136
77
  chunkSize?: number;
137
78
  firmwareType?: EFirmwareType;
138
79
  targetsToUpdate?: FirmwareUpdateV4Target[];
139
- expectedTargetVersions?: Partial<Record<FirmwareUpdateV4Target, string>>;
140
80
 
141
81
  /** FW_MGMT_TARGET_ROMLOADER = 2; Pro2 cannot install it through firmwareUpdateV4. */
142
82
  romloaderBinary?: ArrayBuffer;
@@ -162,24 +102,8 @@ export interface FirmwareUpdateV4Params {
162
102
  binary: ArrayBuffer;
163
103
  devicePath: string;
164
104
  }>;
165
- artifactReader?: FirmwareArtifactReader;
166
- componentArtifacts?: Partial<
167
- Record<Exclude<FirmwareUpdateV4Target, 'resource'>, FirmwareArtifactReference>
168
- >;
169
- resourceBundleArtifacts?: Array<{
170
- name: string;
171
- artifact: FirmwareArtifactReference;
172
- }>;
173
105
  }
174
106
 
175
- export declare function registerFirmwareUpdateHostBinding(
176
- binding: FirmwareUpdateHostBinding
177
- ): number;
178
-
179
- export declare function unregisterFirmwareUpdateHostBinding(generation?: number): boolean;
180
-
181
- export declare function getFirmwareUpdateHostBindingGeneration(): number;
182
-
183
107
  export declare function firmwareUpdateV3(
184
108
  connectId: string | undefined,
185
109
  params: Params<FirmwareUpdateV3Params>
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  deviceGetOnboardingStatus,
3
3
  deviceReboot,
4
+ deviceUploadNft,
4
5
  deviceUploadWallpaper,
5
6
  testProtocolV2Ping,
6
7
  uploadPortfolio,
@@ -30,15 +31,7 @@ import type {
30
31
  firmwareUpdateV2,
31
32
  firmwareUpdateV3,
32
33
  firmwareUpdateV4,
33
- getFirmwareUpdateHostBindingGeneration,
34
- registerFirmwareUpdateHostBinding,
35
- unregisterFirmwareUpdateHostBinding,
36
34
  } from './firmwareUpdate';
37
- import type { getFirmwareUpdateCapabilities } from './firmwareUpdateCapabilities';
38
- import type {
39
- prepareFirmwareUpdatePlan,
40
- validateFirmwareUpdatePreparedPlan,
41
- } from './firmwareUpdatePreparedPlan';
42
35
  import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
43
36
  import type { deviceReset } from './deviceReset';
44
37
  import type { deviceRecovery } from './deviceRecovery';
@@ -235,12 +228,6 @@ export type CoreApi = {
235
228
  firmwareUpdateV2: typeof firmwareUpdateV2;
236
229
  firmwareUpdateV3: typeof firmwareUpdateV3;
237
230
  firmwareUpdateV4: typeof firmwareUpdateV4;
238
- registerFirmwareUpdateHostBinding: typeof registerFirmwareUpdateHostBinding;
239
- unregisterFirmwareUpdateHostBinding: typeof unregisterFirmwareUpdateHostBinding;
240
- getFirmwareUpdateHostBindingGeneration: typeof getFirmwareUpdateHostBindingGeneration;
241
- getFirmwareUpdateCapabilities: typeof getFirmwareUpdateCapabilities;
242
- prepareFirmwareUpdatePlan: typeof prepareFirmwareUpdatePlan;
243
- validateFirmwareUpdatePreparedPlan: typeof validateFirmwareUpdatePreparedPlan;
244
231
  cipherKeyValue: typeof cipherKeyValue;
245
232
 
246
233
  /**
@@ -248,6 +235,7 @@ export type CoreApi = {
248
235
  */
249
236
  deviceReboot: typeof deviceReboot;
250
237
  deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
238
+ deviceUploadNft: typeof deviceUploadNft;
251
239
  deviceUploadWallpaper: typeof deviceUploadWallpaper;
252
240
  uploadPortfolio: typeof uploadPortfolio;
253
241
 
@@ -5,6 +5,10 @@ import type {
5
5
  DeviceUploadWallpaperParams,
6
6
  DeviceUploadWallpaperResponse,
7
7
  } from '../../api/protocol-v2/DeviceUploadWallpaper';
8
+ import type {
9
+ DeviceUploadNftParams,
10
+ DeviceUploadNftResponse,
11
+ } from '../../api/protocol-v2/DeviceUploadNft';
8
12
 
9
13
  // Re-export implementation parameter types as the single source of truth.
10
14
  export type { DeviceRebootParams, RebootTypeInput } from '../../api/protocol-v2/helpers';
@@ -12,6 +16,10 @@ export type {
12
16
  DeviceUploadWallpaperParams,
13
17
  DeviceUploadWallpaperResponse,
14
18
  } from '../../api/protocol-v2/DeviceUploadWallpaper';
19
+ export type {
20
+ DeviceUploadNftParams,
21
+ DeviceUploadNftResponse,
22
+ } from '../../api/protocol-v2/DeviceUploadNft';
15
23
 
16
24
  // ── Shared response shapes (Protocol V2 file system) ────────────────────
17
25
 
@@ -52,6 +60,11 @@ export declare function deviceUploadWallpaper(
52
60
  params: CommonParams & DeviceUploadWallpaperParams
53
61
  ): Response<DeviceUploadWallpaperResponse>;
54
62
 
63
+ export declare function deviceUploadNft(
64
+ connectId: string,
65
+ params: CommonParams & DeviceUploadNftParams
66
+ ): Response<DeviceUploadNftResponse>;
67
+
55
68
  export declare function uploadPortfolio(
56
69
  connectId: string,
57
70
  params: {
@@ -31,8 +31,6 @@ export type ConnectSettings = {
31
31
  timestamp: number;
32
32
  isFrame?: boolean;
33
33
  preRelease?: boolean;
34
- firmwareManifestMode?: 'sdk-managed' | 'external-only';
35
- preloadedConfig?: RemoteConfigResponse;
36
34
  fetchConfig?: boolean;
37
35
  extension?: string;
38
36
  configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
@@ -60,18 +58,39 @@ export type IProtocolV2FirmwareComponent = {
60
58
  fingerprint?: string;
61
59
  /** OKPP payload hash, used to detect same-version package changes. */
62
60
  payloadHash?: string;
63
- expectedSize?: number;
64
61
  version?: IVersionArray;
65
62
  };
66
63
 
64
+ export type IProtocolV2ResourceType =
65
+ | 'images'
66
+ | 'animation'
67
+ | 'wallpaper'
68
+ | 'translations'
69
+ | 'roobert'
70
+ | 'noto';
71
+
72
+ /** Pro2 RES package descriptor. Hashes identify content without a human-managed version. */
73
+ export type IProtocolV2Resource = {
74
+ type: IProtocolV2ResourceType;
75
+ url: string;
76
+ /** Complete okpkg file size in bytes. */
77
+ size: number;
78
+ /** SHA-256 of the complete okpkg file. */
79
+ fileHash: string;
80
+ /** SHA3-512 header_hash from the signed okpkg header. */
81
+ headerHash: string;
82
+ };
83
+
84
+ export type IProtocolV2Resources = {
85
+ stable: IProtocolV2Resource[];
86
+ };
87
+
67
88
  /** Pro2 RESC bundle okpkg descriptor for incremental FileWrite synchronization. */
68
89
  export type IProtocolV2ResourceBundle = {
69
90
  /** Bundle name, such as images, animation, translations, or fonts_roobert. */
70
91
  name: string;
71
92
  /** Download URL. */
72
93
  url: string;
73
- fingerprint?: string;
74
- expectedSize?: number;
75
94
  /** Device target path, such as vol0:/bundles/images/images.okpkg. */
76
95
  devicePath: string;
77
96
  /** okpkg payload_version used to skip matching content after FileRead. */
@@ -93,16 +112,10 @@ export type IFirmwareReleaseInfo = {
93
112
  firmwareType?: EFirmwareType;
94
113
  /** Firmware UI resource */
95
114
  resource?: string;
96
- resourceFingerprint?: string;
97
- resourceExpectedSize?: number;
98
115
  /** Firmware full UI resource */
99
116
  fullResource?: string;
100
- fullResourceFingerprint?: string;
101
- fullResourceExpectedSize?: number;
102
117
  fullResourceRange?: string[];
103
118
  bootloaderResource?: string;
104
- bootloaderFingerprint?: string;
105
- bootloaderExpectedSize?: number;
106
119
  bootloaderVersion?: IVersionArray;
107
120
  displayBootloaderVersion?: IVersionArray;
108
121
  bootloaderRelatedFirmwareVersion?: IVersionArray;
@@ -115,7 +128,6 @@ export type IFirmwareReleaseInfo = {
115
128
  [k in ILocale]: string;
116
129
  };
117
130
  fingerprint: string;
118
- expectedSize?: number;
119
131
  version: IVersionArray;
120
132
  changelog: {
121
133
  [k in ILocale]: string;
@@ -131,7 +143,6 @@ export type IBLEFirmwareReleaseInfo = {
131
143
  webUpdate: string;
132
144
  fingerprint: string;
133
145
  fingerprintWeb: string;
134
- expectedSize?: number;
135
146
  version: IVersionArray;
136
147
  changelog: {
137
148
  [k in ILocale]: string;
@@ -149,6 +160,8 @@ export type DeviceTypeMap = {
149
160
  'firmware-v8'?: IFirmwareReleaseInfo[];
150
161
  'firmware-btc-v8'?: IFirmwareReleaseInfo[];
151
162
  ble: IBLEFirmwareReleaseInfo[];
163
+ /** Independent Pro2 resource release configuration. */
164
+ resources?: IProtocolV2Resources;
152
165
  };
153
166
  };
154
167
 
@@ -106,6 +106,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
106
106
  expectPassphraseState?: string;
107
107
  onlyMainPin?: boolean;
108
108
  initSession?: boolean;
109
+ deriveCardano?: boolean;
109
110
  }
110
111
  ) => {
111
112
  if (device.isProtocolV2()) {
@@ -121,6 +122,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
121
122
  initSession: options?.initSession,
122
123
  expectedPassphraseState: options?.expectPassphraseState,
123
124
  onlyMainPin: options?.onlyMainPin,
125
+ deriveCardano: options?.deriveCardano,
124
126
  });
125
127
  }
126
128
 
@@ -185,6 +187,7 @@ export const getPassphraseState = async (
185
187
  expectPassphraseState?: string;
186
188
  onlyMainPin?: boolean;
187
189
  initSession?: boolean;
190
+ deriveCardano?: boolean;
188
191
  }
189
192
  ): Promise<{
190
193
  passphraseState: string | undefined;
@@ -205,6 +208,7 @@ export const getPassphraseState = async (
205
208
  initSession: options?.initSession,
206
209
  expectedPassphraseState: options?.expectPassphraseState,
207
210
  onlyMainPin: options?.onlyMainPin,
211
+ deriveCardano: options?.deriveCardano,
208
212
  });
209
213
  }
210
214