@onekeyfe/hd-core 1.1.26 → 1.1.27-alpha.31

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 (186) hide show
  1. package/__tests__/evmSignTransaction.test.ts +1 -1
  2. package/__tests__/evmSignTypedData.test.ts +1 -1
  3. package/__tests__/protocol-v2.test.ts +1096 -0
  4. package/dist/api/BaseMethod.d.ts +1 -3
  5. package/dist/api/BaseMethod.d.ts.map +1 -1
  6. package/dist/api/DirList.d.ts +10 -0
  7. package/dist/api/DirList.d.ts.map +1 -0
  8. package/dist/api/DirMake.d.ts +9 -0
  9. package/dist/api/DirMake.d.ts.map +1 -0
  10. package/dist/api/DirRemove.d.ts +9 -0
  11. package/dist/api/DirRemove.d.ts.map +1 -0
  12. package/dist/api/FileDelete.d.ts +9 -0
  13. package/dist/api/FileDelete.d.ts.map +1 -0
  14. package/dist/api/FileRead.d.ts +19 -0
  15. package/dist/api/FileRead.d.ts.map +1 -0
  16. package/dist/api/FileWrite.d.ts +23 -0
  17. package/dist/api/FileWrite.d.ts.map +1 -0
  18. package/dist/api/FirmwareUpdateV3.d.ts +1 -0
  19. package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
  20. package/dist/api/FirmwareUpdateV4.d.ts +32 -0
  21. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
  22. package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
  23. package/dist/api/GetPassphraseState.d.ts +6 -1
  24. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  25. package/dist/api/PathInfo.d.ts +9 -0
  26. package/dist/api/PathInfo.d.ts.map +1 -0
  27. package/dist/api/SearchDevices.d.ts +2 -1
  28. package/dist/api/SearchDevices.d.ts.map +1 -1
  29. package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
  30. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
  31. package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
  32. package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
  33. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  34. package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
  35. package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
  36. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
  37. package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
  38. package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
  39. package/dist/api/index.d.ts +26 -0
  40. package/dist/api/index.d.ts.map +1 -1
  41. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
  42. package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
  43. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
  44. package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
  45. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
  46. package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
  47. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
  48. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
  49. package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
  50. package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
  51. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
  52. package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
  53. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
  54. package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
  55. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
  56. package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
  57. package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
  58. package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
  59. package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
  60. package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
  61. package/dist/api/protocol-v2/Ping.d.ts +8 -0
  62. package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
  63. package/dist/api/protocol-v2/helpers.d.ts +49 -0
  64. package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
  65. package/dist/core/index.d.ts.map +1 -1
  66. package/dist/data-manager/DataManager.d.ts +7 -4
  67. package/dist/data-manager/DataManager.d.ts.map +1 -1
  68. package/dist/data-manager/MessagesConfig.d.ts +2 -2
  69. package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
  70. package/dist/data-manager/TransportManager.d.ts +5 -4
  71. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  72. package/dist/device/Device.d.ts +5 -3
  73. package/dist/device/Device.d.ts.map +1 -1
  74. package/dist/device/DeviceCommands.d.ts +8 -8
  75. package/dist/device/DeviceCommands.d.ts.map +1 -1
  76. package/dist/device/DeviceConnector.d.ts +2 -1
  77. package/dist/device/DeviceConnector.d.ts.map +1 -1
  78. package/dist/events/ui-request.d.ts +8 -0
  79. package/dist/events/ui-request.d.ts.map +1 -1
  80. package/dist/index.d.ts +198 -23
  81. package/dist/index.js +15726 -806
  82. package/dist/inject.d.ts.map +1 -1
  83. package/dist/protocols/protocol-v2/features.d.ts +57 -0
  84. package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
  85. package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
  86. package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
  87. package/dist/protocols/protocol-v2/index.d.ts +3 -0
  88. package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
  89. package/dist/types/api/export.d.ts +1 -1
  90. package/dist/types/api/export.d.ts.map +1 -1
  91. package/dist/types/api/firmwareUpdate.d.ts +7 -0
  92. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  93. package/dist/types/api/getPassphraseState.d.ts +7 -1
  94. package/dist/types/api/getPassphraseState.d.ts.map +1 -1
  95. package/dist/types/api/index.d.ts +29 -1
  96. package/dist/types/api/index.d.ts.map +1 -1
  97. package/dist/types/api/protocolV2.d.ts +123 -0
  98. package/dist/types/api/protocolV2.d.ts.map +1 -0
  99. package/dist/types/api/searchDevices.d.ts +2 -2
  100. package/dist/types/api/searchDevices.d.ts.map +1 -1
  101. package/dist/types/device.d.ts +1 -1
  102. package/dist/types/device.d.ts.map +1 -1
  103. package/dist/types/params.d.ts +2 -0
  104. package/dist/types/params.d.ts.map +1 -1
  105. package/dist/types/settings.d.ts +1 -1
  106. package/dist/types/settings.d.ts.map +1 -1
  107. package/dist/utils/deviceFeaturesUtils.d.ts +3 -3
  108. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  109. package/dist/utils/deviceInfoUtils.d.ts +1 -0
  110. package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
  111. package/dist/utils/index.d.ts +1 -1
  112. package/dist/utils/index.d.ts.map +1 -1
  113. package/dist/utils/patch.d.ts +1 -1
  114. package/dist/utils/patch.d.ts.map +1 -1
  115. package/dist/utils/versionUtils.d.ts +1 -1
  116. package/package.json +4 -4
  117. package/src/api/BaseMethod.ts +12 -60
  118. package/src/api/DirList.ts +25 -0
  119. package/src/api/DirMake.ts +20 -0
  120. package/src/api/DirRemove.ts +20 -0
  121. package/src/api/FileDelete.ts +20 -0
  122. package/src/api/FileRead.ts +158 -0
  123. package/src/api/FileWrite.ts +191 -0
  124. package/src/api/FirmwareUpdateV3.ts +21 -4
  125. package/src/api/FirmwareUpdateV4.ts +810 -0
  126. package/src/api/GetOnekeyFeatures.ts +75 -3
  127. package/src/api/GetPassphraseState.ts +14 -2
  128. package/src/api/PathInfo.ts +24 -0
  129. package/src/api/SearchDevices.ts +7 -2
  130. package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -9
  131. package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
  132. package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
  133. package/src/api/device/DeviceRebootToBootloader.ts +10 -1
  134. package/src/api/dynex/DnxGetAddress.ts +7 -0
  135. package/src/api/dynex/DnxSignTransaction.ts +7 -0
  136. package/src/api/evm/EVMGetAddress.ts +1 -1
  137. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  138. package/src/api/evm/EVMSignMessage.ts +1 -1
  139. package/src/api/evm/EVMSignTransaction.ts +1 -1
  140. package/src/api/evm/EVMSignTypedData.ts +6 -6
  141. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  142. package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
  143. package/src/api/helpers/batchGetPublickeys.ts +4 -2
  144. package/src/api/index.ts +28 -0
  145. package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +33 -0
  146. package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
  147. package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
  148. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
  149. package/src/api/protocol-v2/DeviceReboot.ts +22 -0
  150. package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
  151. package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
  152. package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
  153. package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
  154. package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
  155. package/src/api/protocol-v2/Ping.ts +16 -0
  156. package/src/api/protocol-v2/helpers.ts +138 -0
  157. package/src/api/tron/TronSignMessage.ts +1 -1
  158. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  159. package/src/core/index.ts +31 -5
  160. package/src/data/messages/messages-pro2.json +13106 -0
  161. package/src/data-manager/DataManager.ts +12 -7
  162. package/src/data-manager/MessagesConfig.ts +14 -14
  163. package/src/data-manager/TransportManager.ts +38 -12
  164. package/src/device/Device.ts +73 -9
  165. package/src/device/DeviceCommands.ts +162 -26
  166. package/src/device/DeviceConnector.ts +29 -4
  167. package/src/device/DevicePool.ts +1 -1
  168. package/src/events/ui-request.ts +8 -0
  169. package/src/inject.ts +42 -1
  170. package/src/protocols/protocol-v2/features.ts +267 -0
  171. package/src/protocols/protocol-v2/firmware.ts +26 -0
  172. package/src/protocols/protocol-v2/index.ts +2 -0
  173. package/src/types/api/export.ts +1 -0
  174. package/src/types/api/firmwareUpdate.ts +12 -0
  175. package/src/types/api/getPassphraseState.ts +10 -1
  176. package/src/types/api/index.ts +64 -1
  177. package/src/types/api/protocolV2.ts +221 -0
  178. package/src/types/api/searchDevices.ts +2 -2
  179. package/src/types/device.ts +3 -1
  180. package/src/types/params.ts +7 -0
  181. package/src/types/settings.ts +1 -1
  182. package/src/utils/deviceFeaturesUtils.ts +33 -15
  183. package/src/utils/deviceInfoUtils.ts +14 -5
  184. package/src/utils/index.ts +1 -0
  185. package/__tests__/DeviceCommands.test.ts +0 -99
  186. package/__tests__/evmLedgerLegacySafety.test.ts +0 -261
@@ -12,7 +12,12 @@ import {
12
12
  } from '../utils/tracing';
13
13
 
14
14
  import type { Device } from './Device';
15
- import type { FailureType, Messages, Transport } from '@onekeyfe/hd-transport';
15
+ import type {
16
+ FailureType,
17
+ Messages,
18
+ Transport,
19
+ TransportCallOptions,
20
+ } from '@onekeyfe/hd-transport';
16
21
 
17
22
  export type PassphrasePromptResponse = {
18
23
  passphrase?: string;
@@ -22,16 +27,119 @@ export type PassphrasePromptResponse = {
22
27
  };
23
28
 
24
29
  type MessageType = Messages.MessageType;
25
- type MessageKey = keyof MessageType;
30
+ type MessageKey = Extract<keyof MessageType, string>;
26
31
  export type TypedResponseMessage<T extends MessageKey> = {
27
32
  type: T;
28
33
  message: MessageType[T];
29
34
  };
30
35
  type TypedCallResponseMap = {
31
- [K in keyof MessageType]: TypedResponseMessage<K>;
36
+ [K in MessageKey]: TypedResponseMessage<K>;
32
37
  };
33
38
  export type DefaultMessageResponse = TypedCallResponseMap[keyof MessageType];
34
39
 
40
+ const MAX_DEBUG_ARRAY_ITEMS = 20;
41
+ const MAX_DEBUG_OBJECT_KEYS = 40;
42
+ const MAX_DEBUG_STRING_LENGTH = 512;
43
+ const MAX_DEBUG_DEPTH = 4;
44
+ const HIGH_VOLUME_DEBUG_CALLS = new Set([
45
+ 'FilesystemFileRead',
46
+ 'FilesystemFileWrite',
47
+ 'FileRead',
48
+ 'FileWrite',
49
+ 'EmmcFileRead',
50
+ 'EmmcFileWrite',
51
+ 'FirmwareUpload',
52
+ 'ResourceAck',
53
+ ]);
54
+
55
+ function shouldReduceDebugForCall(type: string) {
56
+ return HIGH_VOLUME_DEBUG_CALLS.has(type);
57
+ }
58
+
59
+ function getBinaryByteLength(value: unknown): number | undefined {
60
+ if (value instanceof ArrayBuffer) {
61
+ return value.byteLength;
62
+ }
63
+
64
+ if (ArrayBuffer.isView(value)) {
65
+ return value.byteLength;
66
+ }
67
+
68
+ if (typeof Blob !== 'undefined' && value instanceof Blob) {
69
+ return value.size;
70
+ }
71
+
72
+ return undefined;
73
+ }
74
+
75
+ function summarizeRedactedData(value: unknown): string {
76
+ const byteLength = getBinaryByteLength(value);
77
+ if (byteLength !== undefined) {
78
+ return `[redacted data: ${byteLength} bytes]`;
79
+ }
80
+
81
+ if (typeof value === 'string') {
82
+ return `[redacted data: string length=${value.length}]`;
83
+ }
84
+
85
+ if (Array.isArray(value)) {
86
+ return `[redacted data: array length=${value.length}]`;
87
+ }
88
+
89
+ if (value && typeof value === 'object') {
90
+ return `[redacted data: object keys=${Object.keys(value).length}]`;
91
+ }
92
+
93
+ return `[redacted data: ${typeof value}]`;
94
+ }
95
+
96
+ function sanitizeDebugPayload(value: unknown, key = '', depth = 0): unknown {
97
+ if (key === 'data' && value !== null && value !== undefined) {
98
+ return summarizeRedactedData(value);
99
+ }
100
+
101
+ const byteLength = getBinaryByteLength(value);
102
+ if (byteLength !== undefined) {
103
+ return `[binary: ${byteLength} bytes]`;
104
+ }
105
+
106
+ if (typeof value === 'string') {
107
+ return value.length > MAX_DEBUG_STRING_LENGTH
108
+ ? `${value.slice(0, MAX_DEBUG_STRING_LENGTH)}... (len=${value.length})`
109
+ : value;
110
+ }
111
+
112
+ if (!value || typeof value !== 'object') {
113
+ return value;
114
+ }
115
+
116
+ if (depth >= MAX_DEBUG_DEPTH) {
117
+ return Array.isArray(value)
118
+ ? `[array length=${value.length}]`
119
+ : `[object keys=${Object.keys(value).length}]`;
120
+ }
121
+
122
+ if (Array.isArray(value)) {
123
+ const items = value
124
+ .slice(0, MAX_DEBUG_ARRAY_ITEMS)
125
+ .map(item => sanitizeDebugPayload(item, key, depth + 1));
126
+ if (value.length > MAX_DEBUG_ARRAY_ITEMS) {
127
+ items.push(`... (${value.length - MAX_DEBUG_ARRAY_ITEMS} more)`);
128
+ }
129
+ return items;
130
+ }
131
+
132
+ const entries = Object.entries(value).slice(0, MAX_DEBUG_OBJECT_KEYS);
133
+ const sanitized: Record<string, unknown> = {};
134
+ entries.forEach(([entryKey, entryValue]) => {
135
+ sanitized[entryKey] = sanitizeDebugPayload(entryValue, entryKey, depth + 1);
136
+ });
137
+ if (Object.keys(value).length > MAX_DEBUG_OBJECT_KEYS) {
138
+ sanitized.__truncated__ = `${Object.keys(value).length - MAX_DEBUG_OBJECT_KEYS} more keys`;
139
+ }
140
+ return sanitized;
141
+ }
142
+
35
143
  const assertType = (res: DefaultMessageResponse, resType: string | string[]) => {
36
144
  const splitResTypes = Array.isArray(resType) ? resType : resType.split('|');
37
145
  if (!splitResTypes.includes(res.type)) {
@@ -224,17 +332,21 @@ export class DeviceCommands {
224
332
  // Sends an async message to the opened device.
225
333
  async call(
226
334
  type: MessageKey,
227
- msg: DefaultMessageResponse['message'] = {}
335
+ msg?: DefaultMessageResponse['message'],
336
+ options?: TransportCallOptions
228
337
  ): Promise<DefaultMessageResponse> {
229
- Log.debug('[DeviceCommands] [call] Sending', type);
338
+ const shouldReduceDebug = shouldReduceDebugForCall(type);
339
+ if (!shouldReduceDebug) {
340
+ Log.debug('[DeviceCommands] [call] Sending', type);
341
+ }
230
342
 
231
343
  try {
232
- const promise = this.transport.call(this.mainId, type, msg) as any;
344
+ const promise = this.transport.call(this.mainId, type, msg ?? {}, options) as any;
233
345
  this.callPromise = promise;
234
346
  const res = await promise;
235
347
  if (res.type === 'Failure') {
236
348
  LogCore.debug('[DeviceCommands] [call] Received', res.type, res.message);
237
- } else {
349
+ } else if (!shouldReduceDebug) {
238
350
  LogCore.debug('[DeviceCommands] [call] Received', res.type);
239
351
  }
240
352
  return res;
@@ -283,19 +395,22 @@ export class DeviceCommands {
283
395
  typedCall<T extends MessageKey, R extends MessageKey[]>(
284
396
  type: T,
285
397
  resType: R,
286
- msg?: MessageType[T]
398
+ msg?: MessageType[T],
399
+ options?: TransportCallOptions
287
400
  ): Promise<TypedCallResponseMap[R[number]]>;
288
401
 
289
402
  typedCall<T extends MessageKey, R extends MessageKey>(
290
403
  type: T,
291
404
  resType: R,
292
- msg?: MessageType[T]
405
+ msg?: MessageType[T],
406
+ options?: TransportCallOptions
293
407
  ): Promise<TypedResponseMessage<R>>;
294
408
 
295
409
  async typedCall(
296
410
  type: MessageKey,
297
411
  resType: MessageKey | MessageKey[],
298
- msg?: DefaultMessageResponse['message']
412
+ msg?: DefaultMessageResponse['message'],
413
+ options?: TransportCallOptions
299
414
  ) {
300
415
  if (this.disposed) {
301
416
  throw ERRORS.TypedError(
@@ -312,16 +427,24 @@ export class DeviceCommands {
312
427
  'PassphraseAck',
313
428
  'Cancel',
314
429
  'BixinPinInputOnDevice',
430
+ 'FilesystemFileRead',
431
+ 'FilesystemFileWrite',
432
+ 'FileRead',
433
+ 'FileWrite',
434
+ 'EmmcFileRead',
435
+ 'EmmcFileWrite',
436
+ 'FirmwareUpload',
437
+ 'ResourceAck',
315
438
  ] as any;
316
439
  if (!skipTypes.includes(type) && msg) {
317
440
  // Use debug channel to avoid noise escalation
318
- Log.debug('[DeviceCommands] [typedCall] Sending payload', type, msg);
441
+ Log.debug('[DeviceCommands] [typedCall] Sending payload', type, sanitizeDebugPayload(msg));
319
442
  }
320
443
  } catch (e) {
321
444
  // ignore logging errors
322
445
  }
323
446
 
324
- const response = await this._commonCall(type, msg);
447
+ const response = await this._commonCall(type, msg, options);
325
448
  try {
326
449
  assertType(response, resType);
327
450
  } catch (error) {
@@ -334,6 +457,12 @@ export class DeviceCommands {
334
457
  // throw bridge network error
335
458
  if (error instanceof HardwareError) {
336
459
  if (error.errorCode === HardwareErrorCode.ResponseUnexpectTypeError) {
460
+ Log.debug('[DeviceCommands] [typedCall] Unexpected response type', {
461
+ request: type,
462
+ expected: resType,
463
+ received: response.type,
464
+ response: sanitizeDebugPayload(response.message),
465
+ });
337
466
  // Do not intercept CallMethodError
338
467
  // Do not intercept “assertType: Response of unexpected type” error
339
468
  // Blocking the above two messages will not know what the specific error message is, and the specific error should be handled by the subsequent business logic.
@@ -347,7 +476,7 @@ export class DeviceCommands {
347
476
  if (error.message.indexOf('BridgeDeviceDisconnected') > -1) {
348
477
  throw ERRORS.TypedError(HardwareErrorCode.BridgeDeviceDisconnected);
349
478
  }
350
- throw ERRORS.TypedError(HardwareErrorCode.ResponseUnexpectTypeError);
479
+ throw error;
351
480
  }
352
481
  } else {
353
482
  // throw error anyway, next call should be resolved properly// throw error anyway, next call should be resolved properly
@@ -357,20 +486,27 @@ export class DeviceCommands {
357
486
  return response;
358
487
  }
359
488
 
360
- async _commonCall(type: MessageKey, msg?: DefaultMessageResponse['message']) {
361
- const resp = await this.call(type, msg);
362
- return this._filterCommonTypes(resp, type);
489
+ async _commonCall(
490
+ type: MessageKey,
491
+ msg?: DefaultMessageResponse['message'],
492
+ options?: TransportCallOptions
493
+ ) {
494
+ const resp = await this.call(type, msg, options);
495
+ return this._filterCommonTypes(resp, type, options);
363
496
  }
364
497
 
365
498
  _filterCommonTypes(
366
499
  res: DefaultMessageResponse,
367
- callType: MessageKey
500
+ callType: MessageKey,
501
+ options?: TransportCallOptions
368
502
  ): Promise<DefaultMessageResponse> {
369
503
  try {
370
- if (DataManager.getSettings('env') === 'react-native') {
371
- Log.debug('_filterCommonTypes: ', JSON.stringify(res));
504
+ if (shouldReduceDebugForCall(callType)) {
505
+ // 高频文件写入每个 chunk 都会经过这里,避免 debug log 反向拖慢传输。
506
+ } else if (DataManager.getSettings('env') === 'react-native') {
507
+ Log.debug('_filterCommonTypes: ', JSON.stringify(sanitizeDebugPayload(res)));
372
508
  } else {
373
- Log.debug('_filterCommonTypes: ', res);
509
+ Log.debug('_filterCommonTypes: ', sanitizeDebugPayload(res));
374
510
  }
375
511
  } catch (error) {
376
512
  // ignore
@@ -472,7 +608,7 @@ export class DeviceCommands {
472
608
  } else {
473
609
  this.device.emit(DEVICE.BUTTON, this.device, res.message);
474
610
  }
475
- return this._commonCall('ButtonAck', {});
611
+ return this._commonCall('ButtonAck', {}, options);
476
612
  }
477
613
 
478
614
  if (res.type === 'EntropyRequest') {
@@ -485,11 +621,11 @@ export class DeviceCommands {
485
621
  if (pin === '@@ONEKEY_INPUT_PIN_IN_DEVICE') {
486
622
  // only classic\1s\mini\pure
487
623
  this.device.setCancelableAction(() => this.cancelDeviceOnOneKeyDevice());
488
- return this._commonCall('BixinPinInputOnDevice').finally(() => {
624
+ return this._commonCall('BixinPinInputOnDevice', {}, options).finally(() => {
489
625
  this.device.clearCancelableAction();
490
626
  });
491
627
  }
492
- return this._commonCall('PinMatrixAck', { pin });
628
+ return this._commonCall('PinMatrixAck', { pin }, options);
493
629
  },
494
630
  error => Promise.reject(error)
495
631
  );
@@ -504,12 +640,12 @@ export class DeviceCommands {
504
640
 
505
641
  // Attach PIN on device
506
642
  if (attachPinOnDevice && existsAttachPinUser) {
507
- return this._commonCall('PassphraseAck', { on_device_attach_pin: true });
643
+ return this._commonCall('PassphraseAck', { on_device_attach_pin: true }, options);
508
644
  }
509
645
 
510
646
  return !passphraseOnDevice
511
- ? this._commonCall('PassphraseAck', { passphrase })
512
- : this._commonCall('PassphraseAck', { on_device: true });
647
+ ? this._commonCall('PassphraseAck', { passphrase }, options)
648
+ : this._commonCall('PassphraseAck', { on_device: true }, options);
513
649
  });
514
650
  }
515
651
 
@@ -1,3 +1,5 @@
1
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
+
1
3
  import { safeThrowError } from '../constants';
2
4
  import { DataManager } from '../data-manager';
3
5
  import TransportManager from '../data-manager/TransportManager';
@@ -6,6 +8,7 @@ import { resolveAfter } from '../utils/promiseUtils';
6
8
  import { LoggerNames, getLogger } from '../utils';
7
9
 
8
10
  import type { DeviceDescriptorDiff } from './DevicePool';
11
+ import type { HardwareConnectProtocol } from '@onekeyfe/hd-shared';
9
12
  import type { OneKeyDeviceInfo as DeviceDescriptor, Transport } from '@onekeyfe/hd-transport';
10
13
 
11
14
  const Log = getLogger(LoggerNames.DeviceConnector);
@@ -75,15 +78,37 @@ export default class DeviceConnector {
75
78
  this.listening = false;
76
79
  }
77
80
 
78
- async acquire(path: string, session?: string | null, forceCleanRunPromise?: boolean) {
79
- Log.debug('acquire', path, session);
81
+ async acquire(
82
+ path: string,
83
+ session?: string | null,
84
+ forceCleanRunPromise?: boolean,
85
+ connectProtocol?: HardwareConnectProtocol
86
+ ) {
87
+ Log.debug('acquire', path, session, connectProtocol);
80
88
  const env = DataManager.getSettings('env');
81
89
  try {
82
90
  let res;
83
91
  if (DataManager.isBleConnect(env)) {
84
- res = await this.transport.acquire({ uuid: path, forceCleanRunPromise });
92
+ res = await this.transport.acquire({
93
+ uuid: path,
94
+ forceCleanRunPromise,
95
+ expectedProtocol: connectProtocol,
96
+ });
85
97
  } else {
86
- res = await this.transport.acquire({ path, previous: session ?? null });
98
+ res = await this.transport.acquire({
99
+ path,
100
+ previous: session ?? null,
101
+ expectedProtocol: connectProtocol,
102
+ });
103
+ }
104
+ if (connectProtocol) {
105
+ const detectedProtocol = this.transport.getProtocolType(path);
106
+ if (detectedProtocol !== connectProtocol) {
107
+ throw ERRORS.TypedError(
108
+ HardwareErrorCode.RuntimeError,
109
+ `Device protocol mismatch: expected ${connectProtocol}, detected ${detectedProtocol}`
110
+ );
111
+ }
87
112
  }
88
113
  return res;
89
114
  } catch (error) {
@@ -150,7 +150,7 @@ export class DevicePool extends EventEmitter {
150
150
  if (!device) {
151
151
  device = Device.fromDescriptor(descriptor);
152
152
  device.deviceConnector = this.connector;
153
- await device.connect();
153
+ await device.connect(initOptions?.connectProtocol);
154
154
  await device.initialize(initOptions);
155
155
  await device.release();
156
156
  }
@@ -129,6 +129,10 @@ export interface FirmwareProgress {
129
129
  device: Device;
130
130
  progress: number;
131
131
  progressType: IFirmwareUpdateProgressType;
132
+ transferredBytes?: number;
133
+ totalBytes?: number;
134
+ rateBytesPerSecond?: number;
135
+ elapsedMs?: number;
132
136
  };
133
137
  }
134
138
 
@@ -144,6 +148,10 @@ export interface DeviceProgress {
144
148
  type: typeof UI_REQUEST.DEVICE_PROGRESS;
145
149
  payload: {
146
150
  progress?: number;
151
+ transferredBytes?: number;
152
+ totalBytes?: number;
153
+ rateBytesPerSecond?: number;
154
+ elapsedMs?: number;
147
155
  };
148
156
  }
149
157
 
package/src/inject.ts CHANGED
@@ -103,7 +103,7 @@ export const createCoreApi = (
103
103
  /**
104
104
  * 搜索设备
105
105
  */
106
- searchDevices: () => call({ method: 'searchDevices' }),
106
+ searchDevices: params => call({ ...params, method: 'searchDevices' }),
107
107
 
108
108
  /**
109
109
  * 获取设备信息
@@ -148,6 +148,45 @@ export const createCoreApi = (
148
148
  deviceFlags: (connectId, params) => call({ ...params, connectId, method: 'deviceFlags' }),
149
149
  deviceRebootToBoardloader: connectId => call({ connectId, method: 'deviceRebootToBoardloader' }),
150
150
  deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
151
+
152
+ // File system & device control API (Protocol V2 only)
153
+ getProtoVersion: (connectId, params) => call({ ...params, connectId, method: 'getProtoVersion' }),
154
+ ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
155
+ deviceReboot: (connectId, params) => call({ ...params, connectId, method: 'deviceReboot' }),
156
+ deviceGetDeviceInfo: (connectId, params) =>
157
+ call({ ...params, connectId, method: 'deviceGetDeviceInfo' }),
158
+ deviceGetOnboardingStatus: (connectId, params) =>
159
+ call({ ...params, connectId, method: 'deviceGetOnboardingStatus' }),
160
+ deviceFirmwareUpdate: (connectId, params) =>
161
+ call({ ...params, connectId, method: 'deviceFirmwareUpdate' }),
162
+ deviceGetFirmwareUpdateStatus: (connectId, params) =>
163
+ call({ ...params, connectId, method: 'deviceGetFirmwareUpdateStatus' }),
164
+ factoryDeviceInfoSettings: (connectId, params) =>
165
+ call({ ...params, connectId, method: 'factoryDeviceInfoSettings' }),
166
+ factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
167
+ filesystemFixPermission: connectId => call({ connectId, method: 'filesystemFixPermission' }),
168
+ fileRead: (connectId, params) => call({ ...params, connectId, method: 'fileRead' }),
169
+ fileWrite: (connectId, params) => call({ ...params, connectId, method: 'fileWrite' }),
170
+ fileDelete: (connectId, params) => call({ ...params, connectId, method: 'fileDelete' }),
171
+ dirList: (connectId, params) => call({ ...params, connectId, method: 'dirList' }),
172
+ dirMake: (connectId, params) => call({ ...params, connectId, method: 'dirMake' }),
173
+ dirRemove: (connectId, params) => call({ ...params, connectId, method: 'dirRemove' }),
174
+ pathInfo: (connectId, params) => call({ ...params, connectId, method: 'pathInfo' }),
175
+ filesystemFileRead: (connectId, params) =>
176
+ call({ ...params, connectId, method: 'filesystemFileRead' }),
177
+ filesystemFileWrite: (connectId, params) =>
178
+ call({ ...params, connectId, method: 'filesystemFileWrite' }),
179
+ filesystemFileDelete: (connectId, params) =>
180
+ call({ ...params, connectId, method: 'filesystemFileDelete' }),
181
+ filesystemDirList: (connectId, params) =>
182
+ call({ ...params, connectId, method: 'filesystemDirList' }),
183
+ filesystemDirMake: (connectId, params) =>
184
+ call({ ...params, connectId, method: 'filesystemDirMake' }),
185
+ filesystemDirRemove: (connectId, params) =>
186
+ call({ ...params, connectId, method: 'filesystemDirRemove' }),
187
+ filesystemPathInfoQuery: (connectId, params) =>
188
+ call({ ...params, connectId, method: 'filesystemPathInfoQuery' }),
189
+ filesystemFormat: connectId => call({ connectId, method: 'filesystemFormat' }),
151
190
  deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
152
191
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
153
192
  deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
@@ -260,6 +299,8 @@ export const createCoreApi = (
260
299
  call({ ...params, connectId, method: 'firmwareUpdateV2' }),
261
300
  firmwareUpdateV3: (connectId, params) =>
262
301
  call({ ...params, connectId, method: 'firmwareUpdateV3' }),
302
+ firmwareUpdateV4: (connectId, params) =>
303
+ call({ ...params, connectId, method: 'firmwareUpdateV4' }),
263
304
  promptWebDeviceAccess: params => call({ ...params, method: 'promptWebDeviceAccess' }),
264
305
 
265
306
  tronGetAddress: (connectId, deviceId, params) =>