@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.
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/protocol-v2.test.ts +1096 -0
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/DirList.d.ts +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +23 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts +1 -0
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +32 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +6 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/PathInfo.d.ts +9 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/SearchDevices.d.ts +2 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/index.d.ts +26 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +7 -0
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +1 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +6 -0
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +6 -0
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +49 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +7 -4
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +5 -4
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +5 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -8
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +8 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +198 -23
- package/dist/index.js +15726 -806
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +57 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +12 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +3 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- package/dist/types/api/export.d.ts +1 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +7 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +7 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +29 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +123 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.d.ts.map +1 -1
- package/dist/types/device.d.ts +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +2 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +3 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +1 -0
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +12 -60
- package/src/api/DirList.ts +25 -0
- package/src/api/DirMake.ts +20 -0
- package/src/api/DirRemove.ts +20 -0
- package/src/api/FileDelete.ts +20 -0
- package/src/api/FileRead.ts +158 -0
- package/src/api/FileWrite.ts +191 -0
- package/src/api/FirmwareUpdateV3.ts +21 -4
- package/src/api/FirmwareUpdateV4.ts +810 -0
- package/src/api/GetOnekeyFeatures.ts +75 -3
- package/src/api/GetPassphraseState.ts +14 -2
- package/src/api/PathInfo.ts +24 -0
- package/src/api/SearchDevices.ts +7 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -9
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
- package/src/api/device/DeviceRebootToBootloader.ts +10 -1
- package/src/api/dynex/DnxGetAddress.ts +7 -0
- package/src/api/dynex/DnxSignTransaction.ts +7 -0
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +1 -1
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +6 -6
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
- package/src/api/helpers/batchGetPublickeys.ts +4 -2
- package/src/api/index.ts +28 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +33 -0
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +35 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceReboot.ts +22 -0
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +27 -0
- package/src/api/protocol-v2/FactoryGetDeviceInfo.ts +18 -0
- package/src/api/protocol-v2/FilesystemFixPermission.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +14 -0
- package/src/api/protocol-v2/GetProtoVersion.ts +14 -0
- package/src/api/protocol-v2/Ping.ts +16 -0
- package/src/api/protocol-v2/helpers.ts +138 -0
- package/src/api/tron/TronSignMessage.ts +1 -1
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/core/index.ts +31 -5
- package/src/data/messages/messages-pro2.json +13106 -0
- package/src/data-manager/DataManager.ts +12 -7
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/device/Device.ts +73 -9
- package/src/device/DeviceCommands.ts +162 -26
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DevicePool.ts +1 -1
- package/src/events/ui-request.ts +8 -0
- package/src/inject.ts +42 -1
- package/src/protocols/protocol-v2/features.ts +267 -0
- package/src/protocols/protocol-v2/firmware.ts +26 -0
- package/src/protocols/protocol-v2/index.ts +2 -0
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/getPassphraseState.ts +10 -1
- package/src/types/api/index.ts +64 -1
- package/src/types/api/protocolV2.ts +221 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/device.ts +3 -1
- package/src/types/params.ts +7 -0
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceFeaturesUtils.ts +33 -15
- package/src/utils/deviceInfoUtils.ts +14 -5
- package/src/utils/index.ts +1 -0
- package/__tests__/DeviceCommands.test.ts +0 -99
- 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 {
|
|
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
|
|
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
|
|
335
|
+
msg?: DefaultMessageResponse['message'],
|
|
336
|
+
options?: TransportCallOptions
|
|
228
337
|
): Promise<DefaultMessageResponse> {
|
|
229
|
-
|
|
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
|
|
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(
|
|
361
|
-
|
|
362
|
-
|
|
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 (
|
|
371
|
-
|
|
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(
|
|
79
|
-
|
|
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({
|
|
92
|
+
res = await this.transport.acquire({
|
|
93
|
+
uuid: path,
|
|
94
|
+
forceCleanRunPromise,
|
|
95
|
+
expectedProtocol: connectProtocol,
|
|
96
|
+
});
|
|
85
97
|
} else {
|
|
86
|
-
res = await this.transport.acquire({
|
|
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) {
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -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
|
}
|
package/src/events/ui-request.ts
CHANGED
|
@@ -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:
|
|
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) =>
|