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

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 (195) hide show
  1. package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -78
  2. package/__tests__/DeviceEventRegistration.test.ts +0 -6
  3. package/__tests__/connectSettings.test.ts +47 -5
  4. package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
  5. package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
  6. package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
  7. package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
  8. package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
  9. package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
  10. package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
  11. package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
  12. package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
  13. package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
  14. package/__tests__/get-device-state.test.ts +12 -132
  15. package/__tests__/homescreen.test.ts +1 -41
  16. package/__tests__/logBlockEvent.test.ts +1 -1
  17. package/__tests__/open-wallet-session.test.ts +18 -259
  18. package/__tests__/protocol-v2-unlock-policy.test.ts +35 -86
  19. package/__tests__/protocol-v2.test.ts +632 -333
  20. package/__tests__/public-pro2-api-boundary.test.ts +0 -1
  21. package/dist/api/BaseMethod.d.ts +1 -3
  22. package/dist/api/BaseMethod.d.ts.map +1 -1
  23. package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
  24. package/dist/api/FirmwareUpdateV2.d.ts +11 -0
  25. package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
  26. package/dist/api/FirmwareUpdateV3.d.ts +7 -3
  27. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  28. package/dist/api/FirmwareUpdateV4.d.ts +22 -5
  29. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  30. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  31. package/dist/api/OpenWalletSession.d.ts.map +1 -1
  32. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  33. package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
  34. package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
  35. package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
  36. package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
  37. package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
  38. package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
  39. package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
  40. package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
  41. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +8 -0
  42. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  43. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
  44. package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
  45. package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
  46. package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
  47. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +30 -0
  48. package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
  49. package/dist/api/firmware/getBinary.d.ts +7 -0
  50. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  51. package/dist/api/firmware/progressThrottle.d.ts +3 -0
  52. package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
  53. package/dist/api/firmware/updateBootloader.d.ts +2 -0
  54. package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
  55. package/dist/api/firmware/uploadFirmware.d.ts +9 -1
  56. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  57. package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -2
  58. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  59. package/dist/api/index.d.ts +0 -1
  60. package/dist/api/index.d.ts.map +1 -1
  61. package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
  62. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  63. package/dist/core/deviceEventRegistration.d.ts +0 -2
  64. package/dist/core/deviceEventRegistration.d.ts.map +1 -1
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/data-manager/DataManager.d.ts +1 -0
  67. package/dist/data-manager/DataManager.d.ts.map +1 -1
  68. package/dist/data-manager/connectSettings.d.ts.map +1 -1
  69. package/dist/device/Device.d.ts +4 -22
  70. package/dist/device/Device.d.ts.map +1 -1
  71. package/dist/events/device.d.ts +0 -4
  72. package/dist/events/device.d.ts.map +1 -1
  73. package/dist/events/logBlockEvent.d.ts.map +1 -1
  74. package/dist/events/ui-request.d.ts +2 -27
  75. package/dist/events/ui-request.d.ts.map +1 -1
  76. package/dist/index.d.ts +181 -88
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +3162 -1614
  79. package/dist/inject.d.ts.map +1 -1
  80. package/dist/lowLevelInject.d.ts.map +1 -1
  81. package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
  82. package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
  83. package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
  84. package/dist/protocols/protocol-v2/uiInteraction.d.ts +3 -3
  85. package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
  86. package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
  87. package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
  88. package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
  89. package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
  90. package/dist/protocols/protocol-v2/walletSession.d.ts +1 -4
  91. package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
  92. package/dist/topLevelInject.d.ts.map +1 -1
  93. package/dist/types/api/checkAllFirmwareRelease.d.ts +4 -0
  94. package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
  95. package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
  96. package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
  97. package/dist/types/api/export.d.ts +4 -1
  98. package/dist/types/api/export.d.ts.map +1 -1
  99. package/dist/types/api/firmwareUpdate.d.ts +69 -0
  100. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  101. package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
  102. package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
  103. package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
  104. package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
  105. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
  106. package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
  107. package/dist/types/api/index.d.ts +10 -3
  108. package/dist/types/api/index.d.ts.map +1 -1
  109. package/dist/types/api/protocolV2.d.ts +0 -3
  110. package/dist/types/api/protocolV2.d.ts.map +1 -1
  111. package/dist/types/settings.d.ts +13 -0
  112. package/dist/types/settings.d.ts.map +1 -1
  113. package/dist/utils/deviceFeaturesUtils.d.ts +0 -2
  114. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  115. package/dist/utils/homescreen.d.ts +0 -4
  116. package/dist/utils/homescreen.d.ts.map +1 -1
  117. package/dist/utils/index.d.ts +1 -1
  118. package/dist/utils/index.d.ts.map +1 -1
  119. package/dist/utils/patch.d.ts +1 -1
  120. package/dist/utils/patch.d.ts.map +1 -1
  121. package/dist/utils/pro2Wallpaper.d.ts +0 -10
  122. package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
  123. package/package.json +4 -4
  124. package/src/api/BaseMethod.ts +10 -8
  125. package/src/api/CheckAllFirmwareRelease.ts +51 -6
  126. package/src/api/FirmwareUpdateV2.ts +298 -120
  127. package/src/api/FirmwareUpdateV3.ts +263 -57
  128. package/src/api/FirmwareUpdateV4.ts +748 -281
  129. package/src/api/GetPassphraseState.ts +1 -7
  130. package/src/api/OpenWalletSession.ts +17 -54
  131. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -32
  132. package/src/api/device/DeviceUnlock.ts +1 -1
  133. package/src/api/device/DeviceUpdateBootloader.ts +122 -6
  134. package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
  135. package/src/api/firmware/FirmwareHostBinding.ts +100 -0
  136. package/src/api/firmware/FirmwarePreparationError.ts +12 -0
  137. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +57 -0
  138. package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
  139. package/src/api/firmware/FirmwareUpdatePlan.ts +745 -0
  140. package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +392 -0
  141. package/src/api/firmware/progressThrottle.ts +44 -0
  142. package/src/api/firmware/updateBootloader.ts +19 -4
  143. package/src/api/firmware/uploadFirmware.ts +140 -22
  144. package/src/api/helpers/protocolV2FileWrite.ts +4 -11
  145. package/src/api/index.ts +0 -1
  146. package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
  147. package/src/core/deviceEventRegistration.ts +0 -4
  148. package/src/core/index.ts +75 -118
  149. package/src/data/messages/messages-protocol-v2.json +0 -10
  150. package/src/data-manager/DataManager.ts +33 -33
  151. package/src/data-manager/connectSettings.ts +11 -0
  152. package/src/device/Device.ts +21 -193
  153. package/src/events/device.ts +0 -4
  154. package/src/events/logBlockEvent.ts +0 -1
  155. package/src/events/ui-request.ts +2 -32
  156. package/src/index.ts +5 -0
  157. package/src/inject.ts +22 -3
  158. package/src/lowLevelInject.ts +5 -1
  159. package/src/protocols/protocol-v2/features.ts +2 -9
  160. package/src/protocols/protocol-v2/lockedError.ts +10 -0
  161. package/src/protocols/protocol-v2/uiInteraction.ts +5 -31
  162. package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
  163. package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
  164. package/src/protocols/protocol-v2/walletSession.ts +18 -93
  165. package/src/topLevelInject.ts +5 -1
  166. package/src/types/api/checkAllFirmwareRelease.ts +4 -0
  167. package/src/types/api/deviceUpdateBootloader.ts +6 -0
  168. package/src/types/api/export.ts +18 -0
  169. package/src/types/api/firmwareUpdate.ts +76 -0
  170. package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
  171. package/src/types/api/firmwareUpdatePlan.ts +38 -0
  172. package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
  173. package/src/types/api/index.ts +14 -2
  174. package/src/types/api/protocolV2.ts +0 -13
  175. package/src/types/settings.ts +13 -0
  176. package/src/utils/deviceFeaturesUtils.ts +0 -4
  177. package/src/utils/homescreen.ts +6 -32
  178. package/src/utils/index.ts +1 -6
  179. package/src/utils/pro2Wallpaper.ts +8 -35
  180. package/__tests__/deviceUploadNft.test.ts +0 -187
  181. package/__tests__/pro2Nft.test.ts +0 -108
  182. package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -56
  183. package/__tests__/uiProgressThrottle.test.ts +0 -74
  184. package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -30
  185. package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
  186. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
  187. package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
  188. package/dist/utils/pro2Nft.d.ts +0 -29
  189. package/dist/utils/pro2Nft.d.ts.map +0 -1
  190. package/dist/utils/uiProgressThrottle.d.ts +0 -3
  191. package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
  192. package/src/api/protocol-v2/DeviceUploadNft.ts +0 -166
  193. package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -117
  194. package/src/utils/pro2Nft.ts +0 -91
  195. package/src/utils/uiProgressThrottle.ts +0 -63
@@ -399,7 +399,17 @@ export default class DataManager {
399
399
 
400
400
  static async load(settings: ConnectSettings) {
401
401
  this.settings = settings;
402
- if (!settings.fetchConfig) {
402
+ const manifestMode =
403
+ settings.firmwareManifestMode ?? (settings.fetchConfig ? 'sdk-managed' : undefined);
404
+ if (settings.preloadedConfig) {
405
+ this.applyRemoteConfig(settings.preloadedConfig);
406
+ Log.log('[DataConfig] Preloaded firmware config loaded');
407
+ return;
408
+ }
409
+ if (manifestMode === 'external-only') {
410
+ throw new Error('External firmware config snapshot is required');
411
+ }
412
+ if (manifestMode !== 'sdk-managed') {
403
413
  return;
404
414
  }
405
415
 
@@ -409,60 +419,50 @@ export default class DataManager {
409
419
 
410
420
  const urlWithCache = `${url}?noCache=${getTimeStamp()}`;
411
421
  let data: RemoteConfigResponse | null = null;
412
- let fetchMethod: 'configFetcher' | 'axios' | 'none' = 'none';
413
-
414
- // 1. Try custom configFetcher first (client-side IP direct connection support)
415
422
  if (settings.configFetcher) {
416
- Log.debug('[DataConfig] Trying configFetcher (client-side fetcher)...');
423
+ Log.debug('[DataConfig] Trying client configFetcher...');
417
424
  try {
418
425
  data = await settings.configFetcher(urlWithCache);
419
- if (data) {
420
- fetchMethod = 'configFetcher';
421
- Log.log('[DataConfig] ConfigFetcher success');
422
- } else {
423
- Log.debug('[DataConfig] ConfigFetcher returned null, will fallback to axios');
424
- }
425
426
  } catch (e) {
426
- Log.warn('[DataConfig] ConfigFetcher error, will fallback to axios:', e);
427
+ Log.warn('[DataConfig] Client configFetcher failed:', e);
427
428
  }
428
429
  }
429
-
430
- // 2. Fallback to default axios request
431
430
  if (!data) {
432
- Log.debug('[DataConfig] Trying axios (SDK default fetcher)...');
431
+ Log.debug('[DataConfig] Trying SDK-managed config request...');
433
432
  try {
434
433
  const response = await axios.get<RemoteConfigResponse>(urlWithCache, {
435
434
  // because of iframe timeout is 10000
436
435
  timeout: 7000,
437
436
  });
438
437
  data = response.data;
439
- fetchMethod = 'axios';
440
- Log.log('[DataConfig] Axios fetch success');
438
+ Log.log('[DataConfig] SDK-managed config request succeeded');
441
439
  } catch (e) {
442
- Log.warn('[DataConfig] Axios fetch error:', e);
440
+ Log.warn('[DataConfig] SDK-managed config request failed:', e);
443
441
  }
444
442
  }
445
443
 
446
- // 3. Apply config if available
447
444
  if (data) {
448
- Log.log(`[DataConfig] Config loaded successfully via [${fetchMethod}]`);
449
- this.deviceMap = {
450
- [EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
451
- [EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
452
- [EDeviceType.ClassicPure]: this.enrichFirmwareReleaseInfo(data.classicpure),
453
- [EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
454
- [EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
455
- [EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
456
- [EDeviceType.Pro2]: this.enrichFirmwareReleaseInfo(data.pro2),
457
- };
458
- this.assets = {
459
- bridge: data.bridge,
460
- };
445
+ this.applyRemoteConfig(data);
461
446
  } else {
462
- Log.warn('[DataConfig] All fetch methods failed, using built-in default config');
447
+ Log.warn('[DataConfig] SDK-managed config request failed, using built-in default config');
463
448
  }
464
449
  }
465
450
 
451
+ private static applyRemoteConfig(data: RemoteConfigResponse) {
452
+ this.deviceMap = {
453
+ [EDeviceType.Classic]: this.enrichFirmwareReleaseInfo(data.classic),
454
+ [EDeviceType.Classic1s]: this.enrichFirmwareReleaseInfo(data.classic1s),
455
+ [EDeviceType.ClassicPure]: this.enrichFirmwareReleaseInfo(data.classicpure),
456
+ [EDeviceType.Mini]: this.enrichFirmwareReleaseInfo(data.mini),
457
+ [EDeviceType.Touch]: this.enrichFirmwareReleaseInfo(data.touch),
458
+ [EDeviceType.Pro]: this.enrichFirmwareReleaseInfo(data.pro),
459
+ [EDeviceType.Pro2]: this.enrichFirmwareReleaseInfo(data.pro2),
460
+ };
461
+ this.assets = {
462
+ bridge: data.bridge,
463
+ };
464
+ }
465
+
466
466
  static updateEnv(newEnv: ConnectSettings['env']) {
467
467
  if (this.settings) {
468
468
  const prevEnv = this.settings.env;
@@ -115,10 +115,21 @@ export const parseConnectSettings = (input: Partial<ConnectSettings> = {}) => {
115
115
  settings.fetchConfig = input.fetchConfig;
116
116
  }
117
117
 
118
+ if (
119
+ input.firmwareManifestMode === 'sdk-managed' ||
120
+ input.firmwareManifestMode === 'external-only'
121
+ ) {
122
+ settings.firmwareManifestMode = input.firmwareManifestMode;
123
+ }
124
+
118
125
  if (input.configFetcher) {
119
126
  settings.configFetcher = input.configFetcher;
120
127
  }
121
128
 
129
+ if (input.preloadedConfig) {
130
+ settings.preloadedConfig = input.preloadedConfig;
131
+ }
132
+
122
133
  return settings;
123
134
  };
124
135
 
@@ -74,9 +74,7 @@ import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
74
74
  import type {
75
75
  DeviceButtonRequestPayload,
76
76
  DeviceFeaturesPayload,
77
- HardwareUiInteractionMeta,
78
77
  PassphraseRequestPayload,
79
- ProtocolV2UiEventMetadata,
80
78
  } from '../events';
81
79
  import type { PassphrasePromptResponse } from './DeviceCommands';
82
80
  import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
@@ -134,8 +132,6 @@ const isProtocolV2DeviceStatusUnsupportedError = (error: unknown) => {
134
132
 
135
133
  export interface DeviceEvents {
136
134
  [DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
137
- [DEVICE.PIN_ON_DEVICE]: [Device, DeviceSessionPinType, ProtocolV2UiEventMetadata?];
138
- [DEVICE.PIN_ON_DEVICE_COMPLETE]: [Device, HardwareUiInteractionMeta];
139
135
  [DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
140
136
  [DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
141
137
  [DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
@@ -234,24 +230,6 @@ export class Device extends EventEmitter {
234
230
  /** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
235
231
  private protocolV2StateNeedsReload = false;
236
232
 
237
- /** Runtime context negotiated once per active Protocol V2 link. */
238
- private protocolV2RuntimeContext?: ProtocolInfo;
239
-
240
- /** Coalesces concurrent first-use runtime negotiation on the same active link. */
241
- private protocolV2RuntimeContextPromise?: Promise<ProtocolInfo>;
242
-
243
- /** Invalidates an in-flight runtime-context response without adding a transport epoch. */
244
- private protocolV2RuntimeContextRequestToken?: object;
245
-
246
- private protocolV2UiInteraction?: {
247
- interactionId: string;
248
- phaseCounter: number;
249
- sequence: number;
250
- opened: boolean;
251
- };
252
-
253
- private protocolV2UiInteractionCounter = 0;
254
-
255
233
  get state() {
256
234
  return this.stateStore.getState();
257
235
  }
@@ -986,10 +964,7 @@ export class Device extends EventEmitter {
986
964
  await this.getFeatures();
987
965
  }
988
966
 
989
- const supportsProtocolV1OnekeyFeatures =
990
- this.getCurrentDeviceType() === EDeviceType.Touch ||
991
- this.getCurrentDeviceType() === EDeviceType.Pro;
992
- if (!this.isProtocolV2() && refresh.has('verification') && supportsProtocolV1OnekeyFeatures) {
967
+ if (!this.isProtocolV2() && refresh.has('verification')) {
993
968
  const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
994
969
  this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
995
970
  }
@@ -1012,7 +987,13 @@ export class Device extends EventEmitter {
1012
987
  }
1013
988
 
1014
989
  if (refresh.has('status') && !initializedWithDeviceInfo) {
1015
- await this.probeProtocolV2RuntimeState(refreshedDeviceInfo);
990
+ const deviceInfo =
991
+ refreshedDeviceInfo ??
992
+ (await requestProtocolV2DeviceInfo({
993
+ commands: this.commands,
994
+ request: getProtocolV2DeviceInfoRequest(),
995
+ }));
996
+ await this.probeProtocolV2RuntimeState(deviceInfo);
1016
997
  }
1017
998
 
1018
999
  if (refresh.has('settings') && this.state?.status.mode === 'normal') {
@@ -1083,58 +1064,15 @@ export class Device extends EventEmitter {
1083
1064
  return this.features;
1084
1065
  }
1085
1066
 
1086
- async ensureProtocolV2RuntimeContext(timeoutMs?: number): Promise<ProtocolInfo> {
1087
- const cachedProtocolInfo =
1088
- this.protocolV2RuntimeContext ??
1089
- (!this.protocolV2StateNeedsReload
1090
- ? this.state?.raw?.protocolV2ProtocolInfo ?? undefined
1091
- : undefined);
1092
- if (cachedProtocolInfo) {
1093
- this.protocolV2RuntimeContext = cachedProtocolInfo;
1094
- return cachedProtocolInfo;
1095
- }
1096
-
1097
- if (this.protocolV2RuntimeContextPromise) {
1098
- return this.protocolV2RuntimeContextPromise;
1099
- }
1100
-
1101
- const requestToken = {};
1102
- const pendingRequest = (async () => {
1103
- const protocolInfo = await requestProtocolV2ProtocolInfo({
1104
- commands: this.commands,
1105
- timeoutMs,
1106
- });
1107
- if (this.protocolV2RuntimeContextRequestToken !== requestToken) {
1108
- throw ERRORS.TypedError(
1109
- HardwareErrorCode.DeviceInitializeFailed,
1110
- 'Protocol V2 runtime context was invalidated while loading.'
1111
- );
1112
- }
1113
- this.protocolV2RuntimeContext = protocolInfo;
1114
- return protocolInfo;
1115
- })();
1116
- this.protocolV2RuntimeContextRequestToken = requestToken;
1117
- this.protocolV2RuntimeContextPromise = pendingRequest;
1118
-
1119
- try {
1120
- return await pendingRequest;
1121
- } finally {
1122
- if (this.protocolV2RuntimeContextPromise === pendingRequest) {
1123
- this.protocolV2RuntimeContextPromise = undefined;
1124
- }
1125
- if (this.protocolV2RuntimeContextRequestToken === requestToken) {
1126
- this.protocolV2RuntimeContextRequestToken = undefined;
1127
- }
1128
- }
1129
- }
1130
-
1131
- async probeProtocolV2RuntimeState(deviceInfo?: ProtocolV2DeviceInfo, timeoutMs?: number) {
1132
- const protocolInfo = await this.ensureProtocolV2RuntimeContext(timeoutMs);
1067
+ async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
1068
+ const protocolInfo = await requestProtocolV2ProtocolInfo({
1069
+ commands: this.commands,
1070
+ timeoutMs,
1071
+ });
1133
1072
  const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
1134
- const runtimeDeviceInfo = deviceInfo ?? this.state?.raw?.protocolV2DeviceInfo;
1135
- const protocolV2DeviceType = runtimeDeviceInfo
1136
- ? resolveProtocolV2DeviceIdentity(runtimeDeviceInfo.hw?.Device_type).deviceType
1137
- : this.getCurrentDeviceType();
1073
+ const protocolV2DeviceType = resolveProtocolV2DeviceIdentity(
1074
+ deviceInfo.hw?.Device_type
1075
+ ).deviceType;
1138
1076
  if (runtimeMode === 'romloader' && protocolV2DeviceType !== EDeviceType.Pro2) {
1139
1077
  throw ERRORS.TypedError(
1140
1078
  HardwareErrorCode.DeviceInitializeFailed,
@@ -1209,9 +1147,6 @@ export class Device extends EventEmitter {
1209
1147
  this.deviceAcquired = false;
1210
1148
  if (!this.isProtocolV2()) return;
1211
1149
  this.protocolV2StateNeedsReload = true;
1212
- this.protocolV2RuntimeContext = undefined;
1213
- this.protocolV2RuntimeContextPromise = undefined;
1214
- this.protocolV2RuntimeContextRequestToken = undefined;
1215
1150
  this.clearPreInitialized();
1216
1151
  }
1217
1152
 
@@ -1220,14 +1155,9 @@ export class Device extends EventEmitter {
1220
1155
  if (deviceId) {
1221
1156
  deviceWalletSessionStore.deleteDevice(deviceId);
1222
1157
  }
1223
- if (this.isProtocolV2()) {
1224
- if (this.originalDescriptor.path !== deviceId) {
1225
- deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
1226
- }
1158
+ if (this.isProtocolV2() && this.originalDescriptor.path !== deviceId) {
1159
+ deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
1227
1160
  this.protocolV2StateNeedsReload = true;
1228
- this.protocolV2RuntimeContext = undefined;
1229
- this.protocolV2RuntimeContextPromise = undefined;
1230
- this.protocolV2RuntimeContextRequestToken = undefined;
1231
1161
  }
1232
1162
 
1233
1163
  this.passphraseState = undefined;
@@ -1240,9 +1170,6 @@ export class Device extends EventEmitter {
1240
1170
  if (!this.isProtocolV2()) return;
1241
1171
 
1242
1172
  this.protocolV2StateNeedsReload = true;
1243
- this.protocolV2RuntimeContext = undefined;
1244
- this.protocolV2RuntimeContextPromise = undefined;
1245
- this.protocolV2RuntimeContextRequestToken = undefined;
1246
1173
  this.clearPreInitialized();
1247
1174
  let loaderMode: 'bootloader' | 'romloader' | undefined;
1248
1175
  if (rebootType === DeviceRebootType.Bootloader) {
@@ -1595,75 +1522,6 @@ export class Device extends EventEmitter {
1595
1522
  return res.message;
1596
1523
  }
1597
1524
 
1598
- beginProtocolV2UiInteraction() {
1599
- if (!this.isProtocolV2()) return;
1600
- this.protocolV2UiInteraction = {
1601
- interactionId: `${this.instanceId}:${Date.now()}:${++this.protocolV2UiInteractionCounter}`,
1602
- phaseCounter: 0,
1603
- sequence: 0,
1604
- opened: false,
1605
- };
1606
- }
1607
-
1608
- createProtocolV2UiPhaseMetadata(
1609
- phase: HardwareUiInteractionMeta['phase'],
1610
- transition: HardwareUiInteractionMeta['transition'],
1611
- options?: {
1612
- phaseId?: string;
1613
- outcome?: HardwareUiInteractionMeta['outcome'];
1614
- }
1615
- ): HardwareUiInteractionMeta | undefined {
1616
- if (!this.isProtocolV2()) return undefined;
1617
- if (!this.protocolV2UiInteraction) this.beginProtocolV2UiInteraction();
1618
-
1619
- const interaction = this.protocolV2UiInteraction;
1620
- if (!interaction) return undefined;
1621
- const phaseId =
1622
- options?.phaseId ?? `${interaction.interactionId}:phase-${++interaction.phaseCounter}`;
1623
- interaction.opened = true;
1624
- interaction.sequence += 1;
1625
-
1626
- return {
1627
- interactionId: interaction.interactionId,
1628
- phaseId,
1629
- sequence: interaction.sequence,
1630
- phase,
1631
- transition,
1632
- ...(options?.outcome ? { outcome: options.outcome } : {}),
1633
- protocol: 'V2',
1634
- };
1635
- }
1636
-
1637
- completeProtocolV2UiPhase(
1638
- phase: HardwareUiInteractionMeta,
1639
- outcome: HardwareUiInteractionMeta['outcome'] = 'succeeded'
1640
- ) {
1641
- return this.createProtocolV2UiPhaseMetadata(phase.phase, 'complete', {
1642
- phaseId: phase.phaseId,
1643
- outcome,
1644
- });
1645
- }
1646
-
1647
- finishProtocolV2UiInteraction(outcome: HardwareUiInteractionMeta['outcome'] = 'succeeded') {
1648
- const interaction = this.protocolV2UiInteraction;
1649
- if (!interaction?.opened) {
1650
- this.protocolV2UiInteraction = undefined;
1651
- return undefined;
1652
- }
1653
-
1654
- const phaseId = `${interaction.interactionId}:phase-${Math.max(interaction.phaseCounter, 1)}`;
1655
- const metadata = this.createProtocolV2UiPhaseMetadata('processing', 'finish', {
1656
- phaseId,
1657
- outcome,
1658
- });
1659
- this.protocolV2UiInteraction = undefined;
1660
- return metadata;
1661
- }
1662
-
1663
- hasOpenProtocolV2UiInteraction() {
1664
- return this.protocolV2UiInteraction?.opened === true;
1665
- }
1666
-
1667
1525
  supportUnlockVersionRange(): DeviceFirmwareRange {
1668
1526
  // This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
1669
1527
  return {
@@ -1673,33 +1531,10 @@ export class Device extends EventEmitter {
1673
1531
  };
1674
1532
  }
1675
1533
 
1676
- async unlockDevice(
1677
- pinType?: DeviceSessionPinType,
1678
- options?: ProtocolV2UiEventMetadata & { emitUiEvent?: boolean }
1679
- ) {
1534
+ async unlockDevice(pinType: DeviceSessionPinType = DeviceSessionPinType.Main) {
1680
1535
  if (this.isProtocolV2()) {
1681
- const requestedPinType = pinType ?? DeviceSessionPinType.Main;
1682
- const interaction =
1683
- options?.interaction ??
1684
- (options?.emitUiEvent === false
1685
- ? undefined
1686
- : this.createProtocolV2UiPhaseMetadata('pin', 'start'));
1687
- if (options?.emitUiEvent !== false) {
1688
- this.emit(DEVICE.PIN_ON_DEVICE, this, requestedPinType, {
1689
- source: options?.source ?? 'unlock-coordinator',
1690
- reason: options?.reason ?? 'device-unlock',
1691
- deviceOnly: options?.deviceOnly ?? true,
1692
- completion: options?.completion,
1693
- method: options?.method,
1694
- page: options?.page,
1695
- operation: options?.operation,
1696
- interaction: options?.interaction ?? interaction,
1697
- });
1698
- }
1699
1536
  try {
1700
- await this.commands.typedCall('DeviceSessionAskPin', 'Success', {
1701
- type: requestedPinType,
1702
- });
1537
+ await this.commands.typedCall('DeviceSessionAskPin', 'Success', { type: pinType });
1703
1538
  } catch (error) {
1704
1539
  const errorText =
1705
1540
  error instanceof Error
@@ -1711,11 +1546,6 @@ export class Device extends EventEmitter {
1711
1546
  throw error;
1712
1547
  }
1713
1548
 
1714
- const completion = interaction ? this.completeProtocolV2UiPhase(interaction) : undefined;
1715
- if (completion) {
1716
- this.emit(DEVICE.PIN_ON_DEVICE_COMPLETE, this, completion);
1717
- }
1718
-
1719
1549
  const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
1720
1550
  return this.updateProtocolV2Status(status);
1721
1551
  }
@@ -1777,8 +1607,7 @@ export class Device extends EventEmitter {
1777
1607
  async checkPassphraseStateSafety(
1778
1608
  passphraseState?: string,
1779
1609
  useEmptyPassphrase?: boolean,
1780
- skipPassphraseCheck?: boolean,
1781
- deriveCardano?: boolean
1610
+ skipPassphraseCheck?: boolean
1782
1611
  ) {
1783
1612
  if (this.isUnacquired()) return false;
1784
1613
 
@@ -1787,7 +1616,6 @@ export class Device extends EventEmitter {
1787
1616
  await getPassphraseStateWithRefreshDeviceInfo(this, {
1788
1617
  expectPassphraseState: expectedPassphraseState,
1789
1618
  onlyMainPin: useEmptyPassphrase,
1790
- deriveCardano,
1791
1619
  });
1792
1620
 
1793
1621
  // Main wallet and unlock Attach Pin, throw safe error
@@ -1,5 +1,4 @@
1
1
  import type { MessageFactoryFn } from './utils';
2
- import type { HardwareUiInteractionMeta } from './ui-request';
3
2
  import type { PROTO } from '../constants';
4
3
  import type {
5
4
  KnownDevice as Device,
@@ -27,8 +26,6 @@ export const DEVICE = {
27
26
  // onekey-transport events in protobuf format
28
27
  BUTTON: 'button',
29
28
  PIN: 'pin',
30
- PIN_ON_DEVICE: 'pin_on_device',
31
- PIN_ON_DEVICE_COMPLETE: 'pin_on_device_complete',
32
29
  PASSPHRASE: 'passphrase',
33
30
  PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
34
31
  ATTACH_PIN_ON_DEVICE: 'attach_pin_on_device',
@@ -61,7 +58,6 @@ export type PassphraseRequestPayload = {
61
58
  source?: 'wallet-session-coordinator';
62
59
  reason?: 'open-wallet' | 'session-recovery';
63
60
  expectedPassphraseState?: string;
64
- interaction?: HardwareUiInteractionMeta;
65
61
  };
66
62
 
67
63
  export interface DeviceButtonRequest {
@@ -10,7 +10,6 @@ export const LogBlockEvent: Set<string> = new Set([
10
10
 
11
11
  const LogLabelMethod: Set<string> = new Set([
12
12
  'openWalletSession',
13
- 'deviceUploadNft',
14
13
  'deviceUploadWallpaper',
15
14
  'uploadPortfolio',
16
15
  'fileWrite',
@@ -56,16 +56,6 @@ export type ProtocolV2UiEventSource =
56
56
 
57
57
  export type ProtocolV2UiCompletion = 'page-accepted' | 'operation-completed';
58
58
 
59
- export type HardwareUiInteractionMeta = {
60
- interactionId: string;
61
- phaseId: string;
62
- sequence: number;
63
- phase: 'pin' | 'passphrase' | 'passphrase-on-device' | 'button' | 'processing';
64
- transition: 'start' | 'complete' | 'finish';
65
- outcome?: 'submitted' | 'succeeded' | 'failed' | 'cancelled' | 'disconnected';
66
- protocol: 'V2';
67
- };
68
-
69
59
  export type ProtocolV2UiEventMetadata = {
70
60
  source?: ProtocolV2UiEventSource;
71
61
  reason?: string;
@@ -74,29 +64,12 @@ export type ProtocolV2UiEventMetadata = {
74
64
  method?: string;
75
65
  page?: string | number;
76
66
  operation?: string;
77
- interaction?: HardwareUiInteractionMeta;
78
67
  };
79
68
 
80
- export type UiRequestWindowClose =
81
- | {
82
- type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
83
- payload: HardwareUiInteractionMeta;
84
- }
85
- | {
86
- type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
87
- payload: HardwareUiInteractionMeta;
88
- }
89
- | {
90
- type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
91
- payload?: undefined;
92
- }
93
- | {
94
- type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
95
- payload?: undefined;
96
- };
97
-
98
69
  export interface UiRequestWithoutPayload {
99
70
  type:
71
+ | typeof UI_REQUEST.CLOSE_UI_WINDOW
72
+ | typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW
100
73
  | typeof UI_REQUEST.BLUETOOTH_PERMISSION
101
74
  | typeof UI_REQUEST.BLUETOOTH_UNSUPPORTED
102
75
  | typeof UI_REQUEST.BLUETOOTH_POWERED_OFF
@@ -138,7 +111,6 @@ export interface UiRequestPassphrase {
138
111
  source?: 'wallet-session-coordinator';
139
112
  reason?: 'open-wallet' | 'session-recovery';
140
113
  expectedPassphraseState?: string;
141
- interaction?: HardwareUiInteractionMeta;
142
114
  };
143
115
  }
144
116
 
@@ -149,7 +121,6 @@ export interface UiRequestPassphraseOnDevice {
149
121
  passphraseState?: string;
150
122
  source?: 'wallet-session-coordinator';
151
123
  reason?: 'open-wallet' | 'session-recovery';
152
- interaction?: HardwareUiInteractionMeta;
153
124
  };
154
125
  }
155
126
 
@@ -220,7 +191,6 @@ export interface PreviousAddressResult {
220
191
 
221
192
  export type UiEvent =
222
193
  | UiRequestWithoutPayload
223
- | UiRequestWindowClose
224
194
  | UiRequestDeviceAction
225
195
  | UiRequestButton
226
196
  | UiRequestPassphraseOnDevice
package/src/index.ts CHANGED
@@ -19,6 +19,11 @@ export * from './types';
19
19
  export { whitelist, whitelistExtension } from './data/config';
20
20
  export { executeCallback, cleanupCallback };
21
21
  export { preloadSessionCache } from './device/Device';
22
+ export {
23
+ getFirmwareUpdateHostBindingGeneration,
24
+ registerFirmwareUpdateHostBinding,
25
+ unregisterFirmwareUpdateHostBinding,
26
+ } from './api/firmware/FirmwareHostBinding';
22
27
 
23
28
  const HardwareSdk = ({
24
29
  init,
package/src/inject.ts CHANGED
@@ -1,6 +1,17 @@
1
- import type { Unsuccessful } from './types';
1
+ import { getFirmwareUpdateCapabilities } from './api/firmware/FirmwareUpdateCapabilities';
2
+ import {
3
+ prepareFirmwareUpdatePlan,
4
+ validateFirmwareUpdatePreparedPlan,
5
+ } from './api/firmware/FirmwareUpdatePreparedPlan';
6
+ import {
7
+ getFirmwareUpdateHostBindingGeneration,
8
+ registerFirmwareUpdateHostBinding,
9
+ unregisterFirmwareUpdateHostBinding,
10
+ } from './api/firmware/FirmwareHostBinding';
11
+
2
12
  import type { EventEmitter } from 'events';
3
13
  import type { CallMethod } from './events';
14
+ import type { Unsuccessful } from './types';
4
15
  import type { CoreApi } from './types/api';
5
16
  import type { AllNetworkAddress } from './types/api/allNetworkGetAddress';
6
17
 
@@ -68,7 +79,10 @@ export const inject = ({
68
79
 
69
80
  call,
70
81
 
71
- dispose,
82
+ dispose: async () => {
83
+ unregisterFirmwareUpdateHostBinding();
84
+ await dispose();
85
+ },
72
86
 
73
87
  uiResponse,
74
88
 
@@ -99,6 +113,12 @@ export const createCoreApi = (
99
113
  | 'updateSettings'
100
114
  | 'switchTransport'
101
115
  > => ({
116
+ getFirmwareUpdateCapabilities,
117
+ registerFirmwareUpdateHostBinding,
118
+ unregisterFirmwareUpdateHostBinding,
119
+ getFirmwareUpdateHostBindingGeneration,
120
+ prepareFirmwareUpdatePlan,
121
+ validateFirmwareUpdatePreparedPlan,
102
122
  getLogs: () => call({ method: 'getLogs' }),
103
123
  clearSessionCache: params => call({ ...params, method: 'clearSessionCache' }),
104
124
  /**
@@ -162,7 +182,6 @@ export const createCoreApi = (
162
182
  call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
163
183
  deviceUploadWallpaper: (connectId, params) =>
164
184
  call({ ...params, connectId, method: 'deviceUploadWallpaper' }),
165
- deviceUploadNft: (connectId, params) => call({ ...params, connectId, method: 'deviceUploadNft' }),
166
185
  uploadPortfolio: (connectId, params) => call({ ...params, connectId, method: 'uploadPortfolio' }),
167
186
  deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
168
187
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
@@ -1,4 +1,5 @@
1
1
  import { createCoreApi } from './inject';
2
+ import { unregisterFirmwareUpdateHostBinding } from './api/firmware/FirmwareHostBinding';
2
3
 
3
4
  import type { EventEmitter } from 'events';
4
5
  import type { CallMethod, CoreMessage } from './events';
@@ -43,7 +44,10 @@ export const lowLevelInject = ({
43
44
 
44
45
  call,
45
46
 
46
- dispose,
47
+ dispose: async () => {
48
+ unregisterFirmwareUpdateHostBinding();
49
+ await dispose();
50
+ },
47
51
 
48
52
  uiResponse,
49
53
 
@@ -168,15 +168,8 @@ export async function requestProtocolV2ProtocolInfo({
168
168
  }): Promise<ProtocolInfo> {
169
169
  const response =
170
170
  timeoutMs === undefined
171
- ? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {
172
- eventless_wallet_session: true,
173
- })
174
- : await commands.typedCall(
175
- 'ProtocolInfoRequest',
176
- 'ProtocolInfo',
177
- { eventless_wallet_session: true },
178
- { timeoutMs }
179
- );
171
+ ? await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {})
172
+ : await commands.typedCall('ProtocolInfoRequest', 'ProtocolInfo', {}, { timeoutMs });
180
173
  return response.message;
181
174
  }
182
175
 
@@ -0,0 +1,10 @@
1
+ import { HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+
3
+ export function isDeviceLockedError(error: unknown): boolean {
4
+ return (
5
+ typeof error === 'object' &&
6
+ error !== null &&
7
+ 'errorCode' in error &&
8
+ error.errorCode === HardwareErrorCode.DeviceLocked
9
+ );
10
+ }