@onekeyfe/hd-core 1.1.27-alpha.30 → 1.1.27-alpha.32
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 +503 -37
- package/dist/api/DirList.d.ts.map +1 -1
- package/dist/api/DirMake.d.ts.map +1 -1
- package/dist/api/DirRemove.d.ts.map +1 -1
- package/dist/api/FileDelete.d.ts.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.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.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.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/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +7 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- package/dist/api/index.d.ts +5 -5
- 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/helpers.d.ts +19 -19
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -3
- 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 +3 -3
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/index.d.ts +37 -27
- package/dist/index.js +385 -236
- package/dist/protocols/protocol-v2/features.d.ts +2 -1
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +7 -7
- package/dist/types/api/getPassphraseState.d.ts +10 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +7 -6
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +16 -16
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +5 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/DirList.ts +6 -2
- package/src/api/DirMake.ts +2 -1
- package/src/api/DirRemove.ts +2 -1
- package/src/api/FileDelete.ts +2 -1
- package/src/api/FileRead.ts +12 -5
- package/src/api/FileWrite.ts +19 -7
- package/src/api/FirmwareUpdateV4.ts +13 -13
- package/src/api/GetPassphraseState.ts +18 -2
- package/src/api/PathInfo.ts +2 -1
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +15 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
- package/src/api/device/DeviceRebootToBootloader.ts +4 -4
- 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/helpers/batchGetPublickeys.ts +4 -2
- package/src/api/helpers/filesystemValidation.ts +51 -0
- package/src/api/index.ts +5 -5
- package/src/api/protocol-v2/{DevFirmwareUpdate.ts → DeviceFirmwareUpdate.ts} +5 -4
- package/src/api/protocol-v2/{DevGetDeviceInfo.ts → DeviceGetDeviceInfo.ts} +3 -3
- package/src/api/protocol-v2/{DevGetFirmwareUpdateStatus.ts → DeviceGetFirmwareUpdateStatus.ts} +3 -3
- package/src/api/protocol-v2/{DevGetOnboardingStatus.ts → DeviceGetOnboardingStatus.ts} +3 -3
- package/src/api/protocol-v2/{DevReboot.ts → DeviceReboot.ts} +3 -3
- package/src/api/protocol-v2/helpers.ts +68 -45
- package/src/api/tron/TronSignMessage.ts +1 -1
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/core/index.ts +13 -1
- package/src/data/messages/{messages-pro2.json → messages-protocol-v2.json} +67 -63
- package/src/data-manager/DataManager.ts +9 -8
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +13 -13
- package/src/device/Device.ts +7 -3
- package/src/inject.ts +9 -9
- package/src/protocols/protocol-v2/features.ts +39 -41
- package/src/protocols/protocol-v2/firmware.ts +16 -16
- package/src/types/api/getPassphraseState.ts +15 -2
- package/src/types/api/index.ts +11 -10
- package/src/types/api/protocolV2.ts +27 -27
- package/src/utils/deviceFeaturesUtils.ts +53 -19
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +0 -7
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +0 -7
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
|
@@ -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
|
|
|
@@ -33,7 +33,7 @@ export default class TransportManager {
|
|
|
33
33
|
|
|
34
34
|
static reactNativeInit = false;
|
|
35
35
|
|
|
36
|
-
static
|
|
36
|
+
static protocolV1MessageSchema: ProtocolV1MessageSchema = 'v1CurrentSchema';
|
|
37
37
|
|
|
38
38
|
static plugin: LowlevelTransportSharedPlugin | null = null;
|
|
39
39
|
|
|
@@ -41,7 +41,7 @@ export default class TransportManager {
|
|
|
41
41
|
Log.debug('transport manager load');
|
|
42
42
|
this.defaultMessages = DataManager.getProtobufMessages();
|
|
43
43
|
this.currentMessages = this.defaultMessages;
|
|
44
|
-
this.
|
|
44
|
+
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
static async configure() {
|
|
@@ -76,7 +76,7 @@ export default class TransportManager {
|
|
|
76
76
|
Log.debug('Configuring transports');
|
|
77
77
|
await this.transport.configure(JSON.stringify(this.defaultMessages));
|
|
78
78
|
this.currentMessages = this.defaultMessages;
|
|
79
|
-
this.
|
|
79
|
+
this.protocolV1MessageSchema = 'v1CurrentSchema';
|
|
80
80
|
await this.configureProtocolV2Messages();
|
|
81
81
|
Log.debug('Configuring transports done');
|
|
82
82
|
} catch (error) {
|
|
@@ -90,8 +90,8 @@ export default class TransportManager {
|
|
|
90
90
|
/**
|
|
91
91
|
* Re-load the transport's main protobuf schema based on a device's reported features.
|
|
92
92
|
*
|
|
93
|
-
* This handles
|
|
94
|
-
* vs
|
|
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
95
|
* the transport already holds both schemas after initial configure(), and routes per
|
|
96
96
|
* device by `getProtocolType()`.
|
|
97
97
|
*/
|
|
@@ -100,18 +100,18 @@ export default class TransportManager {
|
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const {
|
|
103
|
+
const { protocolV1MessageSchema, messages } = getSupportProtocolV1MessageSchema(features);
|
|
104
104
|
|
|
105
105
|
if (this.currentMessages === messages || !messages) {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
Log.debug(`Reconfiguring transports
|
|
109
|
+
Log.debug(`Reconfiguring transports Protocol V1 schema:${protocolV1MessageSchema}`);
|
|
110
110
|
|
|
111
111
|
try {
|
|
112
112
|
await this.transport.configure(JSON.stringify(messages));
|
|
113
113
|
this.currentMessages = messages;
|
|
114
|
-
this.
|
|
114
|
+
this.protocolV1MessageSchema = protocolV1MessageSchema;
|
|
115
115
|
} catch (error) {
|
|
116
116
|
throw ERRORS.TypedError(
|
|
117
117
|
HardwareErrorCode.TransportInvalidProtobuf,
|
|
@@ -148,7 +148,7 @@ export default class TransportManager {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
private static async configureProtocolV2Messages() {
|
|
151
|
-
const protocolV2Messages = DataManager.getProtobufMessages('
|
|
151
|
+
const protocolV2Messages = DataManager.getProtobufMessages('v2Schema');
|
|
152
152
|
const { configureProtocolV2 } = this.transport;
|
|
153
153
|
if (protocolV2Messages && typeof configureProtocolV2 === 'function') {
|
|
154
154
|
await configureProtocolV2.call(this.transport, JSON.stringify(protocolV2Messages));
|
|
@@ -164,7 +164,7 @@ export default class TransportManager {
|
|
|
164
164
|
return this.currentMessages;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
static
|
|
168
|
-
return this.
|
|
167
|
+
static getProtocolV1MessageSchema() {
|
|
168
|
+
return this.protocolV1MessageSchema;
|
|
169
169
|
}
|
|
170
170
|
}
|
package/src/device/Device.ts
CHANGED
|
@@ -543,8 +543,8 @@ export class Device extends EventEmitter {
|
|
|
543
543
|
/**
|
|
544
544
|
* Device initialization over Protocol V2.
|
|
545
545
|
*
|
|
546
|
-
* Protocol V2 不走传统 Initialize/GetFeatures
|
|
547
|
-
*
|
|
546
|
+
* Protocol V2 不走传统 Initialize/GetFeatures,当前通过 Ping 验证链路,
|
|
547
|
+
* 再用 DeviceGetDeviceInfo 归一成 legacy-style Features 视图。
|
|
548
548
|
*/
|
|
549
549
|
private async _initializeProtocolV2() {
|
|
550
550
|
Log.debug('Initialize device via Protocol V2 feature adapter');
|
|
@@ -882,9 +882,13 @@ export class Device extends EventEmitter {
|
|
|
882
882
|
this.features,
|
|
883
883
|
Enum_Capability.Capability_AttachToPin
|
|
884
884
|
);
|
|
885
|
+
const isPro2 = getDeviceType(this.features) === EDeviceType.Pro2;
|
|
885
886
|
|
|
886
887
|
const supportUnlock =
|
|
887
|
-
supportAttachPinCapability ||
|
|
888
|
+
supportAttachPinCapability ||
|
|
889
|
+
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
890
|
+
isPro2 ||
|
|
891
|
+
(versionRange && semver.gte(firmwareVersion, versionRange.min));
|
|
888
892
|
|
|
889
893
|
if (supportUnlock) {
|
|
890
894
|
const res = await this.commands.typedCall('UnLockDevice', 'UnLockDeviceResponse');
|
package/src/inject.ts
CHANGED
|
@@ -152,15 +152,15 @@ export const createCoreApi = (
|
|
|
152
152
|
// File system & device control API (Protocol V2 only)
|
|
153
153
|
getProtoVersion: (connectId, params) => call({ ...params, connectId, method: 'getProtoVersion' }),
|
|
154
154
|
ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
call({ ...params, connectId, method: '
|
|
158
|
-
|
|
159
|
-
call({ ...params, connectId, method: '
|
|
160
|
-
|
|
161
|
-
call({ ...params, connectId, method: '
|
|
162
|
-
|
|
163
|
-
call({ ...params, connectId, method: '
|
|
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
164
|
factoryDeviceInfoSettings: (connectId, params) =>
|
|
165
165
|
call({ ...params, connectId, method: 'factoryDeviceInfoSettings' }),
|
|
166
166
|
factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
|
|
@@ -22,6 +22,7 @@ type ProtocolV2SEInfo = {
|
|
|
22
22
|
type ProtocolV2DeviceInfo = {
|
|
23
23
|
protocol_version?: number;
|
|
24
24
|
hw?: {
|
|
25
|
+
Device_type?: number;
|
|
25
26
|
device_type?: number;
|
|
26
27
|
serial_no?: string;
|
|
27
28
|
hardware_version?: string;
|
|
@@ -52,24 +53,24 @@ type ProtocolV2DeviceInfo = {
|
|
|
52
53
|
};
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
56
|
+
const PROTOCOL_V2_DEVICE_INFO_REQUEST = {
|
|
57
|
+
targets: {
|
|
58
|
+
hw: true,
|
|
59
|
+
fw: true,
|
|
60
|
+
bt: true,
|
|
61
|
+
se1: true,
|
|
62
|
+
se2: true,
|
|
63
|
+
se3: true,
|
|
64
|
+
se4: true,
|
|
65
|
+
status: true,
|
|
66
|
+
},
|
|
67
|
+
types: {
|
|
68
|
+
version: true,
|
|
69
|
+
build_id: true,
|
|
70
|
+
hash: true,
|
|
71
|
+
specific: true,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
73
74
|
|
|
74
75
|
function parseVersion(version?: string | null): [number, number, number] {
|
|
75
76
|
if (!version) return [0, 0, 0];
|
|
@@ -130,7 +131,7 @@ function createBaseFeatures(descriptor: DeviceDescriptor): Features {
|
|
|
130
131
|
bootloader_mode: false,
|
|
131
132
|
device_id: descriptorId,
|
|
132
133
|
pin_protection: null,
|
|
133
|
-
passphrase_protection:
|
|
134
|
+
passphrase_protection: null,
|
|
134
135
|
language: null,
|
|
135
136
|
label: null,
|
|
136
137
|
initialized: false,
|
|
@@ -227,6 +228,7 @@ export function normalizeProtocolV2Features(
|
|
|
227
228
|
export async function getProtocolV2Features({
|
|
228
229
|
commands,
|
|
229
230
|
descriptor,
|
|
231
|
+
onDeviceInfoError,
|
|
230
232
|
timeoutMs,
|
|
231
233
|
}: {
|
|
232
234
|
commands: DeviceCommands;
|
|
@@ -241,26 +243,22 @@ export async function getProtocolV2Features({
|
|
|
241
243
|
await commands.typedCall('Ping', 'Success', { message: 'init' });
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
// throw error;
|
|
263
|
-
// }
|
|
264
|
-
|
|
265
|
-
return normalizeProtocolV2Features(descriptor);
|
|
246
|
+
try {
|
|
247
|
+
const { message } = callOptions
|
|
248
|
+
? await commands.typedCall(
|
|
249
|
+
'DeviceGetDeviceInfo',
|
|
250
|
+
'DeviceInfo',
|
|
251
|
+
PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
252
|
+
callOptions
|
|
253
|
+
)
|
|
254
|
+
: await commands.typedCall(
|
|
255
|
+
'DeviceGetDeviceInfo',
|
|
256
|
+
'DeviceInfo',
|
|
257
|
+
PROTOCOL_V2_DEVICE_INFO_REQUEST
|
|
258
|
+
);
|
|
259
|
+
return normalizeProtocolV2Features(descriptor, message as unknown as ProtocolV2DeviceInfo);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
onDeviceInfoError?.(error);
|
|
262
|
+
return normalizeProtocolV2Features(descriptor);
|
|
263
|
+
}
|
|
266
264
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Protocol V2
|
|
2
|
+
* Protocol V2 DeviceFirmwareTargetType enum (from messages-protocol-v2.json).
|
|
3
3
|
*/
|
|
4
4
|
export const ProtocolV2FirmwareTargetType = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
TARGET_INVALID: 0,
|
|
6
|
+
TARGET_ROMLOADER: 1,
|
|
7
|
+
TARGET_BOOTLOADER: 2,
|
|
8
|
+
TARGET_FIRMWARE_P1: 3,
|
|
9
|
+
TARGET_FIRMWARE_P2: 4,
|
|
10
|
+
TARGET_COPROCESSOR: 5,
|
|
11
|
+
TARGET_SE: 6,
|
|
12
12
|
TARGET_RESOURCE: 10,
|
|
13
13
|
} as const;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Map Protocol V2 firmware file name to
|
|
16
|
+
* Map Protocol V2 firmware file name to DeviceFirmwareUpdate target_id.
|
|
17
17
|
*/
|
|
18
18
|
export function protocolV2FileNameToTargetId(fileName: string): number {
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
if (
|
|
22
|
-
if (
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
25
|
-
return ProtocolV2FirmwareTargetType.
|
|
19
|
+
const normalized = fileName.toLowerCase();
|
|
20
|
+
if (normalized.includes('romloader')) return ProtocolV2FirmwareTargetType.TARGET_ROMLOADER;
|
|
21
|
+
if (normalized.includes('bootloader')) return ProtocolV2FirmwareTargetType.TARGET_BOOTLOADER;
|
|
22
|
+
if (normalized.includes('ble')) return ProtocolV2FirmwareTargetType.TARGET_COPROCESSOR;
|
|
23
|
+
if (normalized.includes('se')) return ProtocolV2FirmwareTargetType.TARGET_SE;
|
|
24
|
+
if (normalized.includes('p2')) return ProtocolV2FirmwareTargetType.TARGET_FIRMWARE_P2;
|
|
25
|
+
return ProtocolV2FirmwareTargetType.TARGET_FIRMWARE_P1;
|
|
26
26
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
|
|
3
|
+
export type GetPassphraseStatePayload =
|
|
4
|
+
| string
|
|
5
|
+
| {
|
|
6
|
+
passphrase_state?: string;
|
|
7
|
+
session_id?: string;
|
|
8
|
+
unlocked_attach_pin?: boolean;
|
|
9
|
+
passphrase_protection?: boolean | null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type GetPassphraseStateParams = CommonParams & {
|
|
13
|
+
allowCreateAttachPin?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
3
16
|
export declare function getPassphraseState(
|
|
4
17
|
connectId?: string,
|
|
5
|
-
params?:
|
|
6
|
-
): Response<
|
|
18
|
+
params?: GetPassphraseStateParams
|
|
19
|
+
): Response<GetPassphraseStatePayload>;
|
package/src/types/api/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
deviceFirmwareUpdate,
|
|
3
|
+
deviceGetDeviceInfo,
|
|
4
|
+
deviceGetFirmwareUpdateStatus,
|
|
5
|
+
deviceGetOnboardingStatus,
|
|
6
|
+
deviceReboot,
|
|
7
7
|
dirList,
|
|
8
8
|
dirMake,
|
|
9
9
|
dirRemove,
|
|
@@ -162,6 +162,7 @@ import type { neoSignTransaction } from './neoSignTransaction';
|
|
|
162
162
|
import type { ConnectSettings } from '../settings';
|
|
163
163
|
|
|
164
164
|
export * from './export';
|
|
165
|
+
export type { GetPassphraseStateParams, GetPassphraseStatePayload } from './getPassphraseState';
|
|
165
166
|
|
|
166
167
|
export type CoreApi = {
|
|
167
168
|
/**
|
|
@@ -235,11 +236,11 @@ export type CoreApi = {
|
|
|
235
236
|
*/
|
|
236
237
|
getProtoVersion: typeof getProtoVersion;
|
|
237
238
|
ping: typeof ping;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
deviceReboot: typeof deviceReboot;
|
|
240
|
+
deviceGetDeviceInfo: typeof deviceGetDeviceInfo;
|
|
241
|
+
deviceGetOnboardingStatus: typeof deviceGetOnboardingStatus;
|
|
242
|
+
deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
|
|
243
|
+
deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
|
|
243
244
|
factoryDeviceInfoSettings: typeof factoryDeviceInfoSettings;
|
|
244
245
|
factoryGetDeviceInfo: typeof factoryGetDeviceInfo;
|
|
245
246
|
filesystemFixPermission: typeof filesystemFixPermission;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
DeviceFirmwareTarget,
|
|
4
|
+
DeviceFirmwareUpdateStatus,
|
|
5
|
+
DeviceOnboardingStatus,
|
|
6
|
+
DeviceInfoTargets,
|
|
7
|
+
DeviceInfoTypes,
|
|
8
|
+
DeviceRebootType,
|
|
9
9
|
FactoryDeviceInfo,
|
|
10
10
|
ProtoVersion,
|
|
11
11
|
ProtocolV2DeviceInfo,
|
|
@@ -48,14 +48,14 @@ export type PathInfoResult = {
|
|
|
48
48
|
directory?: boolean;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export type
|
|
52
|
-
rebootType?:
|
|
53
|
-
reboot_type?:
|
|
51
|
+
export type DeviceRebootParams = {
|
|
52
|
+
rebootType?: DeviceRebootType | string | number;
|
|
53
|
+
reboot_type?: DeviceRebootType | string | number;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
export type
|
|
57
|
-
targets?:
|
|
58
|
-
types?:
|
|
56
|
+
export type DeviceGetDeviceInfoParams = {
|
|
57
|
+
targets?: DeviceInfoTargets;
|
|
58
|
+
types?: DeviceInfoTypes;
|
|
59
59
|
targetHw?: boolean;
|
|
60
60
|
targetFw?: boolean;
|
|
61
61
|
targetBt?: boolean;
|
|
@@ -70,10 +70,10 @@ export type DevGetDeviceInfoParams = {
|
|
|
70
70
|
includeSpecific?: boolean;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
export type
|
|
74
|
-
targets?:
|
|
75
|
-
targetId?:
|
|
76
|
-
target_id?:
|
|
73
|
+
export type DeviceFirmwareUpdateParams = {
|
|
74
|
+
targets?: DeviceFirmwareTarget[];
|
|
75
|
+
targetId?: DeviceFirmwareTarget['target_id'] | string | number;
|
|
76
|
+
target_id?: DeviceFirmwareTarget['target_id'] | string | number;
|
|
77
77
|
path?: string;
|
|
78
78
|
};
|
|
79
79
|
|
|
@@ -149,30 +149,30 @@ export declare function ping(
|
|
|
149
149
|
params?: CommonParams & { message?: string }
|
|
150
150
|
): Response<Success>;
|
|
151
151
|
|
|
152
|
-
export declare function
|
|
152
|
+
export declare function deviceReboot(
|
|
153
153
|
connectId: string,
|
|
154
|
-
params: CommonParams &
|
|
154
|
+
params: CommonParams & DeviceRebootParams
|
|
155
155
|
): Response<Success>;
|
|
156
156
|
|
|
157
|
-
export declare function
|
|
157
|
+
export declare function deviceGetDeviceInfo(
|
|
158
158
|
connectId: string,
|
|
159
|
-
params?: CommonParams &
|
|
159
|
+
params?: CommonParams & DeviceGetDeviceInfoParams
|
|
160
160
|
): Response<ProtocolV2DeviceInfo>;
|
|
161
161
|
|
|
162
|
-
export declare function
|
|
162
|
+
export declare function deviceGetOnboardingStatus(
|
|
163
163
|
connectId: string,
|
|
164
164
|
params?: CommonParams
|
|
165
|
-
): Response<
|
|
165
|
+
): Response<DeviceOnboardingStatus>;
|
|
166
166
|
|
|
167
|
-
export declare function
|
|
167
|
+
export declare function deviceFirmwareUpdate(
|
|
168
168
|
connectId: string,
|
|
169
|
-
params: CommonParams &
|
|
170
|
-
): Response<Success |
|
|
169
|
+
params: CommonParams & DeviceFirmwareUpdateParams
|
|
170
|
+
): Response<Success | DeviceFirmwareUpdateStatus>;
|
|
171
171
|
|
|
172
|
-
export declare function
|
|
172
|
+
export declare function deviceGetFirmwareUpdateStatus(
|
|
173
173
|
connectId: string,
|
|
174
174
|
params?: CommonParams
|
|
175
|
-
): Response<
|
|
175
|
+
): Response<DeviceFirmwareUpdateStatus>;
|
|
176
176
|
|
|
177
177
|
export declare function factoryDeviceInfoSettings(
|
|
178
178
|
connectId: string,
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { isNaN } from 'lodash';
|
|
3
3
|
import { EDeviceType, type EFirmwareType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Enum_Capability,
|
|
6
|
+
type GetPassphraseState as GetPassphraseStateMessage,
|
|
7
|
+
} from '@onekeyfe/hd-transport';
|
|
5
8
|
|
|
6
9
|
import { toHardened } from '../api/helpers/pathUtils';
|
|
7
10
|
import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
|
|
8
|
-
import DataManager, {
|
|
11
|
+
import DataManager, {
|
|
12
|
+
type IFirmwareField,
|
|
13
|
+
type ProtocolV1MessageSchema,
|
|
14
|
+
} from '../data-manager/DataManager';
|
|
9
15
|
import { PROTOBUF_MESSAGE_CONFIG } from '../data-manager/MessagesConfig';
|
|
10
16
|
import { getDeviceType } from './deviceInfoUtils';
|
|
11
17
|
import { getDeviceFirmwareVersion } from './deviceVersionUtils';
|
|
@@ -15,13 +21,13 @@ import type { Device } from '../device/Device';
|
|
|
15
21
|
import type { DeviceCommands } from '../device/DeviceCommands';
|
|
16
22
|
import type { Features, SupportFeatureType } from '../types';
|
|
17
23
|
|
|
18
|
-
export const
|
|
24
|
+
export const getSupportProtocolV1MessageSchema = (
|
|
19
25
|
features: Features | undefined
|
|
20
|
-
): { messages: JSON;
|
|
26
|
+
): { messages: JSON; protocolV1MessageSchema: ProtocolV1MessageSchema } => {
|
|
21
27
|
if (!features)
|
|
22
28
|
return {
|
|
23
|
-
messages: DataManager.messages.
|
|
24
|
-
|
|
29
|
+
messages: DataManager.messages.v1CurrentSchema,
|
|
30
|
+
protocolV1MessageSchema: 'v1CurrentSchema',
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
const currentDeviceVersion = getDeviceFirmwareVersion(features).join('.');
|
|
@@ -37,18 +43,18 @@ export const getSupportMessageVersion = (
|
|
|
37
43
|
const sortedDeviceVersionConfigs =
|
|
38
44
|
deviceVersionConfigs?.sort((a, b) => semver.compare(b.minVersion, a.minVersion)) ?? [];
|
|
39
45
|
|
|
40
|
-
for (const { minVersion,
|
|
46
|
+
for (const { minVersion, protocolV1MessageSchema } of sortedDeviceVersionConfigs) {
|
|
41
47
|
if (semver.gte(currentDeviceVersion, minVersion)) {
|
|
42
48
|
return {
|
|
43
|
-
messages: DataManager.messages[
|
|
44
|
-
|
|
49
|
+
messages: DataManager.messages[protocolV1MessageSchema],
|
|
50
|
+
protocolV1MessageSchema,
|
|
45
51
|
};
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
return {
|
|
50
|
-
messages: DataManager.messages.
|
|
51
|
-
|
|
56
|
+
messages: DataManager.messages.v1CurrentSchema,
|
|
57
|
+
protocolV1MessageSchema: 'v1CurrentSchema',
|
|
52
58
|
};
|
|
53
59
|
};
|
|
54
60
|
|
|
@@ -68,7 +74,11 @@ export const supportNewPassphrase = (features?: Features): SupportFeatureType =>
|
|
|
68
74
|
if (!features) return { support: false };
|
|
69
75
|
|
|
70
76
|
const deviceType = getDeviceType(features);
|
|
71
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
deviceType === EDeviceType.Touch ||
|
|
79
|
+
deviceType === EDeviceType.Pro ||
|
|
80
|
+
deviceType === EDeviceType.Pro2
|
|
81
|
+
) {
|
|
72
82
|
return { support: true };
|
|
73
83
|
}
|
|
74
84
|
|
|
@@ -82,10 +92,13 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
82
92
|
options?: {
|
|
83
93
|
expectPassphraseState?: string;
|
|
84
94
|
onlyMainPin?: boolean;
|
|
95
|
+
allowCreateAttachPin?: boolean;
|
|
85
96
|
}
|
|
86
97
|
) => {
|
|
87
98
|
const { features, commands } = device;
|
|
88
99
|
const locked = features?.unlocked === false;
|
|
100
|
+
const deviceType = getDeviceType(features);
|
|
101
|
+
const isPro2 = deviceType === EDeviceType.Pro2;
|
|
89
102
|
|
|
90
103
|
const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
|
|
91
104
|
features,
|
|
@@ -95,12 +108,12 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
95
108
|
}
|
|
96
109
|
);
|
|
97
110
|
|
|
98
|
-
const isModeT =
|
|
99
|
-
getDeviceType(features) === EDeviceType.Touch || getDeviceType(features) === EDeviceType.Pro;
|
|
111
|
+
const isModeT = deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro;
|
|
100
112
|
|
|
101
113
|
// 如果可以获取到 passphraseState,但是设备 features 显示设备未开启 passphrase,需要刷新设备状态
|
|
102
114
|
// if passphraseState can be obtained, but the device features show that the device has not enabled passphrase, the device status needs to be refreshed
|
|
103
|
-
const needRefreshWithPassphrase =
|
|
115
|
+
const needRefreshWithPassphrase =
|
|
116
|
+
!isPro2 && passphraseState && features?.passphrase_protection !== true;
|
|
104
117
|
// 如果 Touch/Pro 在之前是锁定状态,刷新设备状态
|
|
105
118
|
// if Touch/Pro was locked before, refresh the device state
|
|
106
119
|
const needRefreshWithLocked = isModeT && locked;
|
|
@@ -110,10 +123,19 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
|
|
|
110
123
|
await device.getFeatures();
|
|
111
124
|
}
|
|
112
125
|
|
|
126
|
+
if (isPro2 && device.features) {
|
|
127
|
+
if (passphraseState) {
|
|
128
|
+
device.features.passphrase_protection = true;
|
|
129
|
+
}
|
|
130
|
+
if (newSession) {
|
|
131
|
+
device.features.session_id = newSession;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
113
135
|
// Attach to pin try to fix internal state
|
|
114
136
|
if (features?.device_id) {
|
|
115
137
|
device.updateInternalState(
|
|
116
|
-
device.features?.passphrase_protection ?? false,
|
|
138
|
+
(device.features?.passphrase_protection ?? false) || isPro2,
|
|
117
139
|
passphraseState,
|
|
118
140
|
device.features?.device_id ?? '',
|
|
119
141
|
newSession,
|
|
@@ -130,6 +152,7 @@ export const getPassphraseState = async (
|
|
|
130
152
|
options?: {
|
|
131
153
|
expectPassphraseState?: string;
|
|
132
154
|
onlyMainPin?: boolean;
|
|
155
|
+
allowCreateAttachPin?: boolean;
|
|
133
156
|
}
|
|
134
157
|
): Promise<{
|
|
135
158
|
passphraseState: string | undefined;
|
|
@@ -148,12 +171,23 @@ export const getPassphraseState = async (
|
|
|
148
171
|
);
|
|
149
172
|
const supportGetPassphraseState =
|
|
150
173
|
supportAttachPinCapability ||
|
|
174
|
+
// Pro2 V2 暂未从 features 暴露 capabilities,先直连该方法用于固件联调。
|
|
175
|
+
deviceType === EDeviceType.Pro2 ||
|
|
151
176
|
(deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.15.0'));
|
|
152
177
|
|
|
153
178
|
if (supportGetPassphraseState) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
179
|
+
const payload: GetPassphraseStateMessage = options?.onlyMainPin
|
|
180
|
+
? { _only_main_pin: true }
|
|
181
|
+
: { passphrase_state: options?.expectPassphraseState };
|
|
182
|
+
if (options?.allowCreateAttachPin) {
|
|
183
|
+
payload.allow_create_attach_pin = true;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const { message, type } = await commands.typedCall(
|
|
187
|
+
'GetPassphraseState',
|
|
188
|
+
'PassphraseState',
|
|
189
|
+
payload
|
|
190
|
+
);
|
|
157
191
|
|
|
158
192
|
// @ts-expect-error
|
|
159
193
|
if (type === 'CallMethodError') {
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import type { DevFirmwareUpdateParams } from './helpers';
|
|
3
|
-
export default class DevFirmwareUpdate extends BaseMethod<DevFirmwareUpdateParams> {
|
|
4
|
-
init(): void;
|
|
5
|
-
run(): Promise<import("packages/hd-transport/dist").Success | import("packages/hd-transport/dist").DevFirmwareUpdateStatus>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=DevFirmwareUpdate.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DevFirmwareUpdate.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DevFirmwareUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEzD,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC,uBAAuB,CAAC;IAChF,IAAI;IAWE,GAAG;CAWV"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import type { DevGetDeviceInfoParams } from './helpers';
|
|
3
|
-
export default class DevGetDeviceInfo extends BaseMethod<DevGetDeviceInfoParams> {
|
|
4
|
-
init(): void;
|
|
5
|
-
run(): Promise<import("packages/hd-transport/dist").ProtocolV2DeviceInfo | import("packages/hd-transport/dist").DeviceInfo>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=DevGetDeviceInfo.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DevGetDeviceInfo.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DevGetDeviceInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,sBAAsB,CAAC;IAC9E,IAAI;IAqBE,GAAG;CAOV"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
export default class DevGetFirmwareUpdateStatus extends BaseMethod {
|
|
3
|
-
init(): void;
|
|
4
|
-
run(): Promise<import("packages/hd-transport/dist").DevFirmwareUpdateStatus>;
|
|
5
|
-
}
|
|
6
|
-
//# sourceMappingURL=DevGetFirmwareUpdateStatus.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DevGetFirmwareUpdateStatus.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,0BAA2B,SAAQ,UAAU;IAChE,IAAI;IAME,GAAG;CAQV"}
|