@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
|
@@ -4,6 +4,7 @@ import { EDeviceType, EFirmwareType } from '@onekeyfe/hd-shared';
|
|
|
4
4
|
|
|
5
5
|
import MessagesJSON from '../data/messages/messages.json';
|
|
6
6
|
import MessagesLegacyV1JSON from '../data/messages/messages_legacy_v1.json';
|
|
7
|
+
import MessagesPro2JSON from '../data/messages/messages-pro2.json';
|
|
7
8
|
import {
|
|
8
9
|
LoggerNames,
|
|
9
10
|
getDeviceBLEFirmwareVersion,
|
|
@@ -40,7 +41,8 @@ export const FIRMWARE_FIELDS = [
|
|
|
40
41
|
|
|
41
42
|
export type IFirmwareField = (typeof FIRMWARE_FIELDS)[number];
|
|
42
43
|
|
|
43
|
-
export type
|
|
44
|
+
export type ProtocolV1MessageSchema = 'protocolV1Current' | 'protocolV1Legacy';
|
|
45
|
+
export type ProtobufMessageSchema = ProtocolV1MessageSchema | 'protocolV2';
|
|
44
46
|
|
|
45
47
|
const FIRMWARE_FIELD_TYPE_MAP: Readonly<Record<IFirmwareField, EFirmwareType>> = {
|
|
46
48
|
firmware: EFirmwareType.Universal,
|
|
@@ -62,7 +64,9 @@ function getFirmwareTypeFromField(firmwareField: IFirmwareField): EFirmwareType
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export default class DataManager {
|
|
65
|
-
static deviceMap: DeviceTypeMap
|
|
67
|
+
static deviceMap: DeviceTypeMap & {
|
|
68
|
+
[k: string]: DeviceTypeMap[keyof DeviceTypeMap] | undefined;
|
|
69
|
+
} = {
|
|
66
70
|
[EDeviceType.Classic]: {
|
|
67
71
|
firmware: [],
|
|
68
72
|
ble: [],
|
|
@@ -93,9 +97,10 @@ export default class DataManager {
|
|
|
93
97
|
|
|
94
98
|
static settings: ConnectSettings;
|
|
95
99
|
|
|
96
|
-
static messages: { [
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
static messages: { [schema in ProtobufMessageSchema]: JSON } = {
|
|
101
|
+
protocolV1Current: MessagesJSON as unknown as JSON,
|
|
102
|
+
protocolV1Legacy: MessagesLegacyV1JSON as unknown as JSON,
|
|
103
|
+
protocolV2: MessagesPro2JSON as unknown as JSON,
|
|
99
104
|
};
|
|
100
105
|
|
|
101
106
|
static lastCheckTimestamp = 0;
|
|
@@ -472,8 +477,8 @@ export default class DataManager {
|
|
|
472
477
|
}
|
|
473
478
|
}
|
|
474
479
|
|
|
475
|
-
static getProtobufMessages(
|
|
476
|
-
return this.messages[
|
|
480
|
+
static getProtobufMessages(schema: ProtobufMessageSchema = 'protocolV1Current'): JSON {
|
|
481
|
+
return this.messages[schema];
|
|
477
482
|
}
|
|
478
483
|
|
|
479
484
|
static getSettings(key?: undefined): ConnectSettings;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import type { IDeviceModel, IDeviceType } from '../types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ProtocolV1MessageSchema } from './DataManager';
|
|
3
3
|
|
|
4
4
|
type DeviceVersionConfig = {
|
|
5
5
|
[deviceType in IDeviceType | IDeviceModel]?: {
|
|
6
6
|
minVersion: string;
|
|
7
|
-
|
|
7
|
+
protocolV1MessageSchema: ProtocolV1MessageSchema;
|
|
8
8
|
}[];
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const PROTOBUF_MESSAGE_CONFIG: DeviceVersionConfig = {
|
|
12
12
|
model_mini: [
|
|
13
|
-
// Classic1s starts from 3.5.0, so use
|
|
14
|
-
// Only use
|
|
15
|
-
{ minVersion: '3.3.0',
|
|
16
|
-
{ minVersion: '0.0.1',
|
|
17
|
-
// Fallback to
|
|
18
|
-
{ minVersion: '0.0.0',
|
|
13
|
+
// Classic1s starts from 3.5.0, so use the current Protocol V1 schema by default.
|
|
14
|
+
// Only use the legacy Protocol V1 schema for specific old versions (< 3.3.0).
|
|
15
|
+
{ minVersion: '3.3.0', protocolV1MessageSchema: 'protocolV1Current' },
|
|
16
|
+
{ minVersion: '0.0.1', protocolV1MessageSchema: 'protocolV1Legacy' },
|
|
17
|
+
// Fallback to current Protocol V1 schema for unknown versions (0.0.0).
|
|
18
|
+
{ minVersion: '0.0.0', protocolV1MessageSchema: 'protocolV1Current' },
|
|
19
19
|
],
|
|
20
20
|
model_touch: [
|
|
21
|
-
// Use
|
|
22
|
-
// Only use
|
|
23
|
-
{ minVersion: '4.5.0',
|
|
24
|
-
{ minVersion: '0.0.1',
|
|
25
|
-
// Fallback to
|
|
26
|
-
{ minVersion: '0.0.0',
|
|
21
|
+
// Use the current Protocol V1 schema by default for Touch/Pro.
|
|
22
|
+
// Only use the legacy Protocol V1 schema for specific old versions (< 4.5.0).
|
|
23
|
+
{ minVersion: '4.5.0', protocolV1MessageSchema: 'protocolV1Current' },
|
|
24
|
+
{ minVersion: '0.0.1', protocolV1MessageSchema: 'protocolV1Legacy' },
|
|
25
|
+
// Fallback to current Protocol V1 schema for unknown versions (0.0.0).
|
|
26
|
+
{ minVersion: '0.0.0', protocolV1MessageSchema: 'protocolV1Current' },
|
|
27
27
|
],
|
|
28
28
|
};
|
|
@@ -4,9 +4,9 @@ import DataManager from './DataManager';
|
|
|
4
4
|
import { LoggerNames, getLogger } from '../utils';
|
|
5
5
|
// eslint-disable-next-line import/no-cycle
|
|
6
6
|
import { DevicePool } from '../device/DevicePool';
|
|
7
|
-
import {
|
|
7
|
+
import { getSupportProtocolV1MessageSchema } from '../utils/deviceFeaturesUtils';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { ProtocolV1MessageSchema } from './DataManager';
|
|
10
10
|
import type { LowlevelTransportSharedPlugin, Transport } from '@onekeyfe/hd-transport';
|
|
11
11
|
import type { Features } from '../types';
|
|
12
12
|
|
|
@@ -17,6 +17,7 @@ const LowLevelLogger = getLogger(LoggerNames.HdTransportLowLevel);
|
|
|
17
17
|
const NodeUsbLogger = getLogger(LoggerNames.HdTransportNodeUsb);
|
|
18
18
|
const WebBleLogger = getLogger(LoggerNames.HdWebBleTransport);
|
|
19
19
|
const WebUsbLogger = getLogger(LoggerNames.HdTransportWebUsb);
|
|
20
|
+
const REACT_NATIVE_BLE_SCAN_TIMEOUT_MS = 8000;
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* transport 在同一个环境中只会存在一个
|
|
@@ -32,7 +33,7 @@ export default class TransportManager {
|
|
|
32
33
|
|
|
33
34
|
static reactNativeInit = false;
|
|
34
35
|
|
|
35
|
-
static
|
|
36
|
+
static protocolV1MessageSchema: ProtocolV1MessageSchema = 'protocolV1Current';
|
|
36
37
|
|
|
37
38
|
static plugin: LowlevelTransportSharedPlugin | null = null;
|
|
38
39
|
|
|
@@ -40,7 +41,7 @@ export default class TransportManager {
|
|
|
40
41
|
Log.debug('transport manager load');
|
|
41
42
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
42
43
|
this.currentMessages = this.defaultMessages;
|
|
43
|
-
this.
|
|
44
|
+
this.protocolV1MessageSchema = 'protocolV1Current';
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
static async configure() {
|
|
@@ -74,6 +75,9 @@ export default class TransportManager {
|
|
|
74
75
|
}
|
|
75
76
|
Log.debug('Configuring transports');
|
|
76
77
|
await this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
78
|
+
this.currentMessages = this.defaultMessages;
|
|
79
|
+
this.protocolV1MessageSchema = 'protocolV1Current';
|
|
80
|
+
await this.configureProtocolV2Messages();
|
|
77
81
|
Log.debug('Configuring transports done');
|
|
78
82
|
} catch (error) {
|
|
79
83
|
Log.debug('Initializing transports error: ', error);
|
|
@@ -83,20 +87,31 @@ export default class TransportManager {
|
|
|
83
87
|
}
|
|
84
88
|
}
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Re-load the transport's main protobuf schema based on a device's reported features.
|
|
92
|
+
*
|
|
93
|
+
* This handles protobuf schema compatibility within Protocol V1 (e.g. Touch's legacy
|
|
94
|
+
* vs current Protocol V1 schema). It is NOT used to switch between Protocol V1 and Protocol V2 —
|
|
95
|
+
* the transport already holds both schemas after initial configure(), and routes per
|
|
96
|
+
* device by `getProtocolType()`.
|
|
97
|
+
*/
|
|
98
|
+
static async reconfigure(features?: Features) {
|
|
99
|
+
if (!features) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const { protocolV1MessageSchema, messages } = getSupportProtocolV1MessageSchema(features);
|
|
89
104
|
|
|
90
105
|
if (this.currentMessages === messages || !messages) {
|
|
91
106
|
return;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
Log.debug(`Reconfiguring transports
|
|
109
|
+
Log.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
95
110
|
|
|
96
111
|
try {
|
|
97
112
|
await this.transport.configure(JSON.stringify(messages));
|
|
98
113
|
this.currentMessages = messages;
|
|
99
|
-
this.
|
|
114
|
+
this.protocolV1MessageSchema = protocolV1MessageSchema;
|
|
100
115
|
} catch (error) {
|
|
101
116
|
throw ERRORS.TypedError(
|
|
102
117
|
HardwareErrorCode.TransportInvalidProtobuf,
|
|
@@ -109,7 +124,9 @@ export default class TransportManager {
|
|
|
109
124
|
const env = DataManager.getSettings('env');
|
|
110
125
|
if (env === 'react-native') {
|
|
111
126
|
/** Actually initializes the ReactNativeTransport */
|
|
112
|
-
this.transport = new TransportConstructor({
|
|
127
|
+
this.transport = new TransportConstructor({
|
|
128
|
+
scanTimeout: REACT_NATIVE_BLE_SCAN_TIMEOUT_MS,
|
|
129
|
+
}) as unknown as Transport;
|
|
113
130
|
} else {
|
|
114
131
|
/** Actually initializes the HttpTransport */
|
|
115
132
|
this.transport = new TransportConstructor() as unknown as Transport;
|
|
@@ -130,6 +147,15 @@ export default class TransportManager {
|
|
|
130
147
|
return this.transport;
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
private static async configureProtocolV2Messages() {
|
|
151
|
+
const protocolV2Messages = DataManager.getProtobufMessages('protocolV2');
|
|
152
|
+
const { configureProtocolV2 } = this.transport;
|
|
153
|
+
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
154
|
+
await configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
155
|
+
Log.debug('Protocol V2 messages configured');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
133
159
|
static getDefaultMessages() {
|
|
134
160
|
return this.defaultMessages;
|
|
135
161
|
}
|
|
@@ -138,7 +164,7 @@ export default class TransportManager {
|
|
|
138
164
|
return this.currentMessages;
|
|
139
165
|
}
|
|
140
166
|
|
|
141
|
-
static
|
|
142
|
-
return this.
|
|
167
|
+
static getProtocolV1MessageSchema() {
|
|
168
|
+
return this.protocolV1MessageSchema;
|
|
143
169
|
}
|
|
144
170
|
}
|
package/src/device/Device.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { DataManager } from '../data-manager';
|
|
|
41
41
|
import TransportManager from '../data-manager/TransportManager';
|
|
42
42
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
43
43
|
import { existCapability } from '../utils/capabilitieUtils';
|
|
44
|
+
import { getProtocolV2Features } from '../protocols/protocol-v2';
|
|
44
45
|
|
|
45
46
|
import type { PROTO } from '../constants';
|
|
46
47
|
import type {
|
|
@@ -49,7 +50,7 @@ import type {
|
|
|
49
50
|
PassphraseRequestPayload,
|
|
50
51
|
} from '../events';
|
|
51
52
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
52
|
-
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
53
|
+
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
53
54
|
import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
|
|
54
55
|
import type DeviceConnector from './DeviceConnector';
|
|
55
56
|
|
|
@@ -58,6 +59,7 @@ export type InitOptions = {
|
|
|
58
59
|
deviceId?: string;
|
|
59
60
|
passphraseState?: string;
|
|
60
61
|
deriveCardano?: boolean;
|
|
62
|
+
connectProtocol?: HardwareConnectProtocol;
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
export type RunOptions = {
|
|
@@ -252,13 +254,13 @@ export class Device extends EventEmitter {
|
|
|
252
254
|
* Device connect
|
|
253
255
|
* @returns {Promise<boolean>}
|
|
254
256
|
*/
|
|
255
|
-
connect() {
|
|
257
|
+
connect(connectProtocol?: HardwareConnectProtocol) {
|
|
256
258
|
const env = DataManager.getSettings('env');
|
|
257
259
|
// eslint-disable-next-line no-async-promise-executor
|
|
258
260
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
259
261
|
if (DataManager.isBleConnect(env)) {
|
|
260
262
|
try {
|
|
261
|
-
await this.acquire();
|
|
263
|
+
await this.acquire(connectProtocol);
|
|
262
264
|
resolve(true);
|
|
263
265
|
} catch (error) {
|
|
264
266
|
reject(error);
|
|
@@ -268,7 +270,7 @@ export class Device extends EventEmitter {
|
|
|
268
270
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
269
271
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
270
272
|
try {
|
|
271
|
-
await this.acquire();
|
|
273
|
+
await this.acquire(connectProtocol);
|
|
272
274
|
resolve(true);
|
|
273
275
|
} catch (error) {
|
|
274
276
|
reject(error);
|
|
@@ -283,23 +285,40 @@ export class Device extends EventEmitter {
|
|
|
283
285
|
});
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
async acquire() {
|
|
288
|
+
async acquire(connectProtocol?: HardwareConnectProtocol) {
|
|
287
289
|
const env = DataManager.getSettings('env');
|
|
288
290
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
291
|
+
const expectedProtocol = connectProtocol ?? this.originalDescriptor.protocolType;
|
|
289
292
|
try {
|
|
290
293
|
if (DataManager.isBleConnect(env)) {
|
|
291
|
-
const res = await this.deviceConnector?.acquire(
|
|
294
|
+
const res = await this.deviceConnector?.acquire(
|
|
295
|
+
this.originalDescriptor.id,
|
|
296
|
+
undefined,
|
|
297
|
+
true,
|
|
298
|
+
expectedProtocol
|
|
299
|
+
);
|
|
292
300
|
this.mainId = (res as unknown as any).uuid ?? '';
|
|
293
301
|
Log.debug('Expected uuid:', this.mainId);
|
|
294
302
|
} else {
|
|
295
303
|
this.mainId = await this.deviceConnector?.acquire(
|
|
296
304
|
this.originalDescriptor.path,
|
|
297
|
-
this.originalDescriptor.session
|
|
305
|
+
this.originalDescriptor.session,
|
|
306
|
+
undefined,
|
|
307
|
+
expectedProtocol
|
|
298
308
|
);
|
|
299
309
|
Log.debug('Expected session id:', this.mainId);
|
|
300
310
|
}
|
|
301
311
|
this.deviceAcquired = true;
|
|
302
312
|
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
313
|
+
|
|
314
|
+
// Propagate protocol version detected during acquire.
|
|
315
|
+
const detectedProtocol = TransportManager.transport?.getProtocolType?.(
|
|
316
|
+
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
317
|
+
);
|
|
318
|
+
if (detectedProtocol) {
|
|
319
|
+
this.originalDescriptor.protocolType = detectedProtocol;
|
|
320
|
+
}
|
|
321
|
+
|
|
303
322
|
if (this.commands) {
|
|
304
323
|
await this.commands.dispose(false);
|
|
305
324
|
}
|
|
@@ -462,6 +481,17 @@ export class Device extends EventEmitter {
|
|
|
462
481
|
}
|
|
463
482
|
|
|
464
483
|
async initialize(options?: InitOptions) {
|
|
484
|
+
// Protocol V2 不支持传统 Initialize,直接使用协议专用初始化流程。
|
|
485
|
+
if (this.originalDescriptor.protocolType === 'V2') {
|
|
486
|
+
this.passphraseState = options?.passphraseState;
|
|
487
|
+
if (this.features && !this.featuresNeedsReload && !options?.initSession) {
|
|
488
|
+
Log.debug('Skip Protocol V2 feature adapter; cached features are available');
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
await this._initializeProtocolV2();
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
465
495
|
// Log.debug('initialize param:', options);
|
|
466
496
|
|
|
467
497
|
this.passphraseState = options?.passphraseState;
|
|
@@ -510,6 +540,36 @@ export class Device extends EventEmitter {
|
|
|
510
540
|
}
|
|
511
541
|
}
|
|
512
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Device initialization over Protocol V2.
|
|
545
|
+
*
|
|
546
|
+
* Protocol V2 不走传统 Initialize/GetFeatures,当前仅通过 Ping 验证链路,
|
|
547
|
+
* 然后使用 descriptor 生成临时 Features 视图。
|
|
548
|
+
*/
|
|
549
|
+
private async _initializeProtocolV2() {
|
|
550
|
+
Log.debug('Initialize device via Protocol V2 feature adapter');
|
|
551
|
+
|
|
552
|
+
try {
|
|
553
|
+
const features = await Promise.race([
|
|
554
|
+
getProtocolV2Features({
|
|
555
|
+
commands: this.commands,
|
|
556
|
+
descriptor: this.originalDescriptor,
|
|
557
|
+
timeoutMs: 10 * 1000,
|
|
558
|
+
}),
|
|
559
|
+
new Promise<never>((_, reject) => {
|
|
560
|
+
setTimeout(() => {
|
|
561
|
+
reject(ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed));
|
|
562
|
+
}, 10 * 1000);
|
|
563
|
+
}),
|
|
564
|
+
]);
|
|
565
|
+
Log.debug('Protocol V2 normalized features:', features);
|
|
566
|
+
this._updateFeatures(features);
|
|
567
|
+
} catch (error) {
|
|
568
|
+
Log.error('Protocol V2 initialization failed:', error);
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
513
573
|
async getFeatures() {
|
|
514
574
|
const { message } = await this.commands.typedCall('GetFeatures', 'Features', {});
|
|
515
575
|
this._updateFeatures(message);
|
|
@@ -580,7 +640,7 @@ export class Device extends EventEmitter {
|
|
|
580
640
|
const env = DataManager.getSettings('env');
|
|
581
641
|
if (env !== 'react-native') {
|
|
582
642
|
try {
|
|
583
|
-
await this.acquire();
|
|
643
|
+
await this.acquire(options.connectProtocol);
|
|
584
644
|
} catch (error) {
|
|
585
645
|
this.runPromise = null;
|
|
586
646
|
return Promise.reject(error);
|
|
@@ -822,9 +882,13 @@ export class Device extends EventEmitter {
|
|
|
822
882
|
this.features,
|
|
823
883
|
Enum_Capability.Capability_AttachToPin
|
|
824
884
|
);
|
|
885
|
+
const isPro2 = getDeviceType(this.features) === EDeviceType.Pro2;
|
|
825
886
|
|
|
826
887
|
const supportUnlock =
|
|
827
|
-
supportAttachPinCapability ||
|
|
888
|
+
supportAttachPinCapability ||
|
|
889
|
+
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
890
|
+
isPro2 ||
|
|
891
|
+
(versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
828
892
|
|
|
829
893
|
if (supportUnlock) {
|
|
830
894
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|