@onekeyfe/hd-core 1.1.26-alpha.2 → 1.1.26-alpha.30
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__/protocol-v2.test.ts +912 -0
- 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/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/alephium/AlephiumSignTransaction.d.ts +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.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/firmware/FirmwareUpdateBaseMethod.d.ts +10 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/index.d.ts +27 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DevFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts +7 -0
- package/dist/api/protocol-v2/DevGetDeviceInfo.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DevGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DevGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DevReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DevReboot.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/api/ton/TonSignData.d.ts +7 -0
- package/dist/api/ton/TonSignData.d.ts.map +1 -0
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +4 -2
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +2 -1
- 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 +12 -12
- 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 +207 -23
- package/dist/index.js +2815 -182
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +56 -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 +2 -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/index.d.ts +30 -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/api/tonSignData.d.ts +18 -0
- package/dist/types/api/tonSignData.d.ts.map +1 -0
- 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/deviceInfoUtils.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 +5 -5
- 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 +161 -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/PathInfo.ts +24 -0
- package/src/api/SearchDevices.ts +7 -2
- package/src/api/alephium/AlephiumSignTransaction.ts +6 -5
- package/src/api/device/DeviceRebootToBoardloader.ts +10 -1
- package/src/api/device/DeviceRebootToBootloader.ts +10 -1
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -4
- package/src/api/index.ts +29 -0
- package/src/api/protocol-v2/DevFirmwareUpdate.ts +33 -0
- package/src/api/protocol-v2/DevGetDeviceInfo.ts +35 -0
- package/src/api/protocol-v2/DevGetFirmwareUpdateStatus.ts +18 -0
- package/src/api/protocol-v2/DevGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DevReboot.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 +140 -0
- package/src/api/ton/TonSignData.ts +60 -0
- package/src/constants/index.ts +1 -1
- package/src/core/index.ts +19 -2
- package/src/data/messages/messages-pro2.json +733 -0
- package/src/data/messages/messages.json +98 -0
- package/src/data-manager/DataManager.ts +6 -2
- package/src/data-manager/TransportManager.ts +29 -3
- package/src/device/Device.ts +66 -8
- package/src/device/DeviceCommands.ts +160 -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 +45 -1
- package/src/protocols/protocol-v2/features.ts +259 -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 +2 -0
- package/src/types/api/firmwareUpdate.ts +12 -0
- package/src/types/api/index.ts +65 -1
- package/src/types/api/protocolV2.ts +221 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/api/tonSignData.ts +29 -0
- package/src/types/device.ts +3 -1
- package/src/types/params.ts +7 -0
- package/src/types/settings.ts +1 -1
- package/src/utils/deviceInfoUtils.ts +9 -5
|
@@ -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,46 @@ 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) =>
|
|
154
|
+
call({ ...params, connectId, method: 'getProtoVersion' }),
|
|
155
|
+
ping: (connectId, params) => call({ ...params, connectId, method: 'ping' }),
|
|
156
|
+
devReboot: (connectId, params) => call({ ...params, connectId, method: 'devReboot' }),
|
|
157
|
+
devGetDeviceInfo: (connectId, params) =>
|
|
158
|
+
call({ ...params, connectId, method: 'devGetDeviceInfo' }),
|
|
159
|
+
devGetOnboardingStatus: (connectId, params) =>
|
|
160
|
+
call({ ...params, connectId, method: 'devGetOnboardingStatus' }),
|
|
161
|
+
devFirmwareUpdate: (connectId, params) =>
|
|
162
|
+
call({ ...params, connectId, method: 'devFirmwareUpdate' }),
|
|
163
|
+
devGetFirmwareUpdateStatus: (connectId, params) =>
|
|
164
|
+
call({ ...params, connectId, method: 'devGetFirmwareUpdateStatus' }),
|
|
165
|
+
factoryDeviceInfoSettings: (connectId, params) =>
|
|
166
|
+
call({ ...params, connectId, method: 'factoryDeviceInfoSettings' }),
|
|
167
|
+
factoryGetDeviceInfo: connectId => call({ connectId, method: 'factoryGetDeviceInfo' }),
|
|
168
|
+
filesystemFixPermission: connectId => call({ connectId, method: 'filesystemFixPermission' }),
|
|
169
|
+
fileRead: (connectId, params) => call({ ...params, connectId, method: 'fileRead' }),
|
|
170
|
+
fileWrite: (connectId, params) => call({ ...params, connectId, method: 'fileWrite' }),
|
|
171
|
+
fileDelete: (connectId, params) => call({ ...params, connectId, method: 'fileDelete' }),
|
|
172
|
+
dirList: (connectId, params) => call({ ...params, connectId, method: 'dirList' }),
|
|
173
|
+
dirMake: (connectId, params) => call({ ...params, connectId, method: 'dirMake' }),
|
|
174
|
+
dirRemove: (connectId, params) => call({ ...params, connectId, method: 'dirRemove' }),
|
|
175
|
+
pathInfo: (connectId, params) => call({ ...params, connectId, method: 'pathInfo' }),
|
|
176
|
+
filesystemFileRead: (connectId, params) =>
|
|
177
|
+
call({ ...params, connectId, method: 'filesystemFileRead' }),
|
|
178
|
+
filesystemFileWrite: (connectId, params) =>
|
|
179
|
+
call({ ...params, connectId, method: 'filesystemFileWrite' }),
|
|
180
|
+
filesystemFileDelete: (connectId, params) =>
|
|
181
|
+
call({ ...params, connectId, method: 'filesystemFileDelete' }),
|
|
182
|
+
filesystemDirList: (connectId, params) =>
|
|
183
|
+
call({ ...params, connectId, method: 'filesystemDirList' }),
|
|
184
|
+
filesystemDirMake: (connectId, params) =>
|
|
185
|
+
call({ ...params, connectId, method: 'filesystemDirMake' }),
|
|
186
|
+
filesystemDirRemove: (connectId, params) =>
|
|
187
|
+
call({ ...params, connectId, method: 'filesystemDirRemove' }),
|
|
188
|
+
filesystemPathInfoQuery: (connectId, params) =>
|
|
189
|
+
call({ ...params, connectId, method: 'filesystemPathInfoQuery' }),
|
|
190
|
+
filesystemFormat: connectId => call({ connectId, method: 'filesystemFormat' }),
|
|
151
191
|
deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
|
|
152
192
|
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
|
153
193
|
deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
|
|
@@ -260,6 +300,8 @@ export const createCoreApi = (
|
|
|
260
300
|
call({ ...params, connectId, method: 'firmwareUpdateV2' }),
|
|
261
301
|
firmwareUpdateV3: (connectId, params) =>
|
|
262
302
|
call({ ...params, connectId, method: 'firmwareUpdateV3' }),
|
|
303
|
+
firmwareUpdateV4: (connectId, params) =>
|
|
304
|
+
call({ ...params, connectId, method: 'firmwareUpdateV4' }),
|
|
263
305
|
promptWebDeviceAccess: params => call({ ...params, method: 'promptWebDeviceAccess' }),
|
|
264
306
|
|
|
265
307
|
tronGetAddress: (connectId, deviceId, params) =>
|
|
@@ -377,6 +419,8 @@ export const createCoreApi = (
|
|
|
377
419
|
call({ ...params, connectId, deviceId, method: 'tonSignMessage' }),
|
|
378
420
|
tonSignProof: (connectId, deviceId, params) =>
|
|
379
421
|
call({ ...params, connectId, deviceId, method: 'tonSignProof' }),
|
|
422
|
+
tonSignData: (connectId, deviceId, params) =>
|
|
423
|
+
call({ ...params, connectId, deviceId, method: 'tonSignData' }),
|
|
380
424
|
|
|
381
425
|
scdoGetAddress: (connectId, deviceId, params) =>
|
|
382
426
|
call({ ...params, connectId, deviceId, method: 'scdoGetAddress' }),
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import type { Features } from '../../types';
|
|
4
|
+
import type { DeviceCommands } from '../../device/DeviceCommands';
|
|
5
|
+
import type { OneKeyDeviceInfo as DeviceDescriptor, Messages } from '@onekeyfe/hd-transport';
|
|
6
|
+
|
|
7
|
+
type ProtocolV2Bytes = Uint8Array | number[] | string;
|
|
8
|
+
|
|
9
|
+
type ProtocolV2FirmwareImageInfo = {
|
|
10
|
+
version?: string;
|
|
11
|
+
build_id?: string;
|
|
12
|
+
hash?: ProtocolV2Bytes;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type ProtocolV2SEInfo = {
|
|
16
|
+
boot?: ProtocolV2FirmwareImageInfo;
|
|
17
|
+
app?: ProtocolV2FirmwareImageInfo;
|
|
18
|
+
type?: number;
|
|
19
|
+
state?: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type ProtocolV2DeviceInfo = {
|
|
23
|
+
protocol_version?: number;
|
|
24
|
+
hw?: {
|
|
25
|
+
device_type?: number;
|
|
26
|
+
serial_no?: string;
|
|
27
|
+
hardware_version?: string;
|
|
28
|
+
hardware_version_raw_adc?: number;
|
|
29
|
+
};
|
|
30
|
+
fw?: {
|
|
31
|
+
board?: ProtocolV2FirmwareImageInfo;
|
|
32
|
+
boot?: ProtocolV2FirmwareImageInfo;
|
|
33
|
+
app?: ProtocolV2FirmwareImageInfo;
|
|
34
|
+
};
|
|
35
|
+
bt?: {
|
|
36
|
+
boot?: ProtocolV2FirmwareImageInfo;
|
|
37
|
+
app?: ProtocolV2FirmwareImageInfo;
|
|
38
|
+
adv_name?: string;
|
|
39
|
+
mac?: ProtocolV2Bytes;
|
|
40
|
+
};
|
|
41
|
+
se1?: ProtocolV2SEInfo;
|
|
42
|
+
se2?: ProtocolV2SEInfo;
|
|
43
|
+
se3?: ProtocolV2SEInfo;
|
|
44
|
+
se4?: ProtocolV2SEInfo;
|
|
45
|
+
status?: {
|
|
46
|
+
language?: string;
|
|
47
|
+
bt_enable?: boolean;
|
|
48
|
+
init_states?: boolean;
|
|
49
|
+
backup_required?: boolean;
|
|
50
|
+
passphrase_protection?: boolean;
|
|
51
|
+
label?: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const PROTOCOL_V2_DEVICE_INFO_REQUEST: Messages.MessageType['DevGetDeviceInfo'] = {
|
|
56
|
+
targets: {
|
|
57
|
+
hw: true,
|
|
58
|
+
fw: true,
|
|
59
|
+
bt: true,
|
|
60
|
+
se1: true,
|
|
61
|
+
se2: true,
|
|
62
|
+
se3: true,
|
|
63
|
+
se4: true,
|
|
64
|
+
status: true,
|
|
65
|
+
},
|
|
66
|
+
types: {
|
|
67
|
+
version: true,
|
|
68
|
+
build_id: true,
|
|
69
|
+
hash: true,
|
|
70
|
+
specific: true,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function parseVersion(version?: string | null): [number, number, number] {
|
|
75
|
+
if (!version) return [0, 0, 0];
|
|
76
|
+
const [major = 0, minor = 0, patch = 0] = version.split('.').map(part => Number(part) || 0);
|
|
77
|
+
return [major, minor, patch];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function bytesToHex(value: unknown): string | undefined {
|
|
81
|
+
if (!value) return undefined;
|
|
82
|
+
if (typeof value === 'string') return value;
|
|
83
|
+
if (value instanceof Uint8Array) {
|
|
84
|
+
return Array.from(value)
|
|
85
|
+
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
86
|
+
.join('');
|
|
87
|
+
}
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
return value.map(byte => Number(byte).toString(16).padStart(2, '0')).join('');
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getDescriptorId(descriptor: DeviceDescriptor) {
|
|
95
|
+
return descriptor.path || descriptor.id || '';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function getImageVersion(image?: ProtocolV2FirmwareImageInfo) {
|
|
99
|
+
return image?.version || undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getImageBuildId(image?: ProtocolV2FirmwareImageInfo) {
|
|
103
|
+
return image?.build_id || undefined;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getImageHash(image?: ProtocolV2FirmwareImageInfo) {
|
|
107
|
+
return bytesToHex(image?.hash);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getSeState(se?: ProtocolV2SEInfo) {
|
|
111
|
+
switch (se?.state) {
|
|
112
|
+
case 0:
|
|
113
|
+
return 'BOOT';
|
|
114
|
+
case 51:
|
|
115
|
+
return 'APP_FACTORY';
|
|
116
|
+
case 85:
|
|
117
|
+
return 'APP';
|
|
118
|
+
default:
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function createBaseFeatures(descriptor: DeviceDescriptor): Features {
|
|
124
|
+
const descriptorId = getDescriptorId(descriptor);
|
|
125
|
+
return {
|
|
126
|
+
vendor: 'onekey.so',
|
|
127
|
+
major_version: 0,
|
|
128
|
+
minor_version: 0,
|
|
129
|
+
patch_version: 0,
|
|
130
|
+
bootloader_mode: false,
|
|
131
|
+
device_id: descriptorId,
|
|
132
|
+
pin_protection: null,
|
|
133
|
+
passphrase_protection: false,
|
|
134
|
+
language: null,
|
|
135
|
+
label: null,
|
|
136
|
+
initialized: false,
|
|
137
|
+
revision: null,
|
|
138
|
+
bootloader_hash: null,
|
|
139
|
+
imported: null,
|
|
140
|
+
unlocked: false,
|
|
141
|
+
firmware_present: false,
|
|
142
|
+
needs_backup: null,
|
|
143
|
+
flags: null,
|
|
144
|
+
model: 'pro2',
|
|
145
|
+
fw_major: 0,
|
|
146
|
+
fw_minor: 0,
|
|
147
|
+
fw_patch: 0,
|
|
148
|
+
fw_vendor: null,
|
|
149
|
+
unfinished_backup: null,
|
|
150
|
+
no_backup: null,
|
|
151
|
+
recovery_mode: null,
|
|
152
|
+
capabilities: [],
|
|
153
|
+
backup_type: null,
|
|
154
|
+
sd_card_present: null,
|
|
155
|
+
sd_protection: null,
|
|
156
|
+
wipe_code_protection: null,
|
|
157
|
+
session_id: null,
|
|
158
|
+
passphrase_always_on_device: null,
|
|
159
|
+
safety_checks: null,
|
|
160
|
+
auto_lock_delay_ms: null,
|
|
161
|
+
display_rotation: null,
|
|
162
|
+
experimental_features: null,
|
|
163
|
+
onekey_device_type: EDeviceType.Pro2,
|
|
164
|
+
onekey_serial_no: descriptorId,
|
|
165
|
+
serial_no: descriptorId,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function normalizeProtocolV2Features(
|
|
170
|
+
descriptor: DeviceDescriptor,
|
|
171
|
+
deviceInfo?: ProtocolV2DeviceInfo
|
|
172
|
+
): Features {
|
|
173
|
+
const features = createBaseFeatures(descriptor);
|
|
174
|
+
if (!deviceInfo) return features;
|
|
175
|
+
|
|
176
|
+
const serialNo =
|
|
177
|
+
deviceInfo.hw?.serial_no || features.onekey_serial_no || getDescriptorId(descriptor);
|
|
178
|
+
const firmwareVersion = getImageVersion(deviceInfo.fw?.app);
|
|
179
|
+
const [fwMajor, fwMinor, fwPatch] = parseVersion(firmwareVersion);
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
...features,
|
|
183
|
+
major_version: fwMajor,
|
|
184
|
+
minor_version: fwMinor,
|
|
185
|
+
patch_version: fwPatch,
|
|
186
|
+
fw_major: fwMajor,
|
|
187
|
+
fw_minor: fwMinor,
|
|
188
|
+
fw_patch: fwPatch,
|
|
189
|
+
device_id: serialNo,
|
|
190
|
+
serial_no: serialNo,
|
|
191
|
+
onekey_serial_no: serialNo,
|
|
192
|
+
label: deviceInfo.status?.label ?? features.label,
|
|
193
|
+
language: deviceInfo.status?.language ?? features.language,
|
|
194
|
+
initialized: deviceInfo.status?.init_states ?? features.initialized,
|
|
195
|
+
passphrase_protection:
|
|
196
|
+
deviceInfo.status?.passphrase_protection ?? features.passphrase_protection,
|
|
197
|
+
needs_backup: deviceInfo.status?.backup_required ?? features.needs_backup,
|
|
198
|
+
ble_enable: deviceInfo.status?.bt_enable,
|
|
199
|
+
onekey_ble_name: deviceInfo.bt?.adv_name,
|
|
200
|
+
ble_name: deviceInfo.bt?.adv_name,
|
|
201
|
+
onekey_firmware_version: firmwareVersion,
|
|
202
|
+
onekey_firmware_build_id: getImageBuildId(deviceInfo.fw?.app),
|
|
203
|
+
onekey_firmware_hash: getImageHash(deviceInfo.fw?.app),
|
|
204
|
+
onekey_boot_version: getImageVersion(deviceInfo.fw?.boot),
|
|
205
|
+
bootloader_version: getImageVersion(deviceInfo.fw?.boot),
|
|
206
|
+
onekey_boot_build_id: getImageBuildId(deviceInfo.fw?.boot),
|
|
207
|
+
onekey_boot_hash: getImageHash(deviceInfo.fw?.boot),
|
|
208
|
+
onekey_board_version: getImageVersion(deviceInfo.fw?.board),
|
|
209
|
+
onekey_board_hash: getImageHash(deviceInfo.fw?.board),
|
|
210
|
+
onekey_ble_version: getImageVersion(deviceInfo.bt?.app),
|
|
211
|
+
ble_ver: getImageVersion(deviceInfo.bt?.app),
|
|
212
|
+
onekey_ble_build_id: getImageBuildId(deviceInfo.bt?.app),
|
|
213
|
+
onekey_ble_hash: getImageHash(deviceInfo.bt?.app),
|
|
214
|
+
onekey_se01_version: getImageVersion(deviceInfo.se1?.app),
|
|
215
|
+
onekey_se01_hash: getImageHash(deviceInfo.se1?.app),
|
|
216
|
+
onekey_se01_build_id: getImageBuildId(deviceInfo.se1?.app),
|
|
217
|
+
onekey_se01_state: getSeState(deviceInfo.se1),
|
|
218
|
+
onekey_se02_version: getImageVersion(deviceInfo.se2?.app),
|
|
219
|
+
onekey_se02_state: getSeState(deviceInfo.se2),
|
|
220
|
+
onekey_se03_version: getImageVersion(deviceInfo.se3?.app),
|
|
221
|
+
onekey_se03_state: getSeState(deviceInfo.se3),
|
|
222
|
+
onekey_se04_version: getImageVersion(deviceInfo.se4?.app),
|
|
223
|
+
onekey_se04_state: getSeState(deviceInfo.se4),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function getProtocolV2Features({
|
|
228
|
+
commands,
|
|
229
|
+
descriptor,
|
|
230
|
+
onDeviceInfoError,
|
|
231
|
+
timeoutMs,
|
|
232
|
+
}: {
|
|
233
|
+
commands: DeviceCommands;
|
|
234
|
+
descriptor: DeviceDescriptor;
|
|
235
|
+
onDeviceInfoError?: (error: unknown) => void;
|
|
236
|
+
timeoutMs?: number;
|
|
237
|
+
}) {
|
|
238
|
+
const callOptions = timeoutMs ? { timeoutMs } : undefined;
|
|
239
|
+
if (callOptions) {
|
|
240
|
+
await commands.typedCall('Ping', 'Success', { message: 'init' }, callOptions);
|
|
241
|
+
} else {
|
|
242
|
+
await commands.typedCall('Ping', 'Success', { message: 'init' });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
const { message } = callOptions
|
|
247
|
+
? await commands.typedCall(
|
|
248
|
+
'DevGetDeviceInfo',
|
|
249
|
+
'DeviceInfo',
|
|
250
|
+
PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
251
|
+
callOptions
|
|
252
|
+
)
|
|
253
|
+
: await commands.typedCall('DevGetDeviceInfo', 'DeviceInfo', PROTOCOL_V2_DEVICE_INFO_REQUEST);
|
|
254
|
+
return normalizeProtocolV2Features(descriptor, message as unknown as ProtocolV2DeviceInfo);
|
|
255
|
+
} catch (error) {
|
|
256
|
+
onDeviceInfoError?.(error);
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol V2 DevFirmwareTargetType enum (from messages-pro2.json).
|
|
3
|
+
*/
|
|
4
|
+
export const ProtocolV2FirmwareTargetType = {
|
|
5
|
+
TARGET_MAIN_APP: 0,
|
|
6
|
+
TARGET_MAIN_BOOT: 1,
|
|
7
|
+
TARGET_BT: 2,
|
|
8
|
+
TARGET_SE1: 3,
|
|
9
|
+
TARGET_SE2: 4,
|
|
10
|
+
TARGET_SE3: 5,
|
|
11
|
+
TARGET_SE4: 6,
|
|
12
|
+
TARGET_RESOURCE: 10,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Map Protocol V2 firmware file name to DevFirmwareUpdate target_id.
|
|
17
|
+
*/
|
|
18
|
+
export function protocolV2FileNameToTargetId(fileName: string): number {
|
|
19
|
+
if (fileName.includes('ble')) return ProtocolV2FirmwareTargetType.TARGET_BT;
|
|
20
|
+
if (fileName.includes('bootloader')) return ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT;
|
|
21
|
+
if (fileName.includes('se1')) return ProtocolV2FirmwareTargetType.TARGET_SE1;
|
|
22
|
+
if (fileName.includes('se2')) return ProtocolV2FirmwareTargetType.TARGET_SE2;
|
|
23
|
+
if (fileName.includes('se3')) return ProtocolV2FirmwareTargetType.TARGET_SE3;
|
|
24
|
+
if (fileName.includes('se4')) return ProtocolV2FirmwareTargetType.TARGET_SE4;
|
|
25
|
+
return ProtocolV2FirmwareTargetType.TARGET_MAIN_APP;
|
|
26
|
+
}
|
package/src/types/api/export.ts
CHANGED
|
@@ -28,6 +28,7 @@ export type {
|
|
|
28
28
|
FirmwareUpdateParams,
|
|
29
29
|
FirmwareUpdateBinaryParams,
|
|
30
30
|
FirmwareUpdateV3Params,
|
|
31
|
+
FirmwareUpdateV4Params,
|
|
31
32
|
} from './firmwareUpdate';
|
|
32
33
|
export type { AllFirmwareRelease } from './checkAllFirmwareRelease';
|
|
33
34
|
|
|
@@ -179,6 +180,7 @@ export type { DnxTxKey, DnxSignTransactionParams, DnxSignature } from './dnxSign
|
|
|
179
180
|
export type { TonAddress, TonGetAddressParams } from './tonGetAddress';
|
|
180
181
|
export type { TonSignMessageParams } from './tonSignMessage';
|
|
181
182
|
export type { TonSignProofParams } from './tonSignProof';
|
|
183
|
+
export type { TonSignDataParams } from './tonSignData';
|
|
182
184
|
|
|
183
185
|
export type { ScdoAddress, ScdoGetAddressParams } from './scdoGetAddress';
|
|
184
186
|
export type { ScdoSignMessageParams } from './scdoSignMessage';
|
|
@@ -41,6 +41,7 @@ export declare function firmwareUpdateV2(
|
|
|
41
41
|
export interface FirmwareUpdateV3Params {
|
|
42
42
|
bleVersion?: number[];
|
|
43
43
|
bleBinary?: ArrayBuffer;
|
|
44
|
+
chunkSize?: number;
|
|
44
45
|
|
|
45
46
|
firmwareVersion?: number[];
|
|
46
47
|
firmwareBinary?: ArrayBuffer;
|
|
@@ -56,6 +57,8 @@ export interface FirmwareUpdateV3Params {
|
|
|
56
57
|
platform: IPlatform;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
export type FirmwareUpdateV4Params = FirmwareUpdateV3Params;
|
|
61
|
+
|
|
59
62
|
export declare function firmwareUpdateV3(
|
|
60
63
|
connectId: string | undefined,
|
|
61
64
|
params: Params<FirmwareUpdateV3Params>
|
|
@@ -64,3 +67,12 @@ export declare function firmwareUpdateV3(
|
|
|
64
67
|
firmwareVersion: string;
|
|
65
68
|
bootloaderVersion: string;
|
|
66
69
|
}>;
|
|
70
|
+
|
|
71
|
+
export declare function firmwareUpdateV4(
|
|
72
|
+
connectId: string | undefined,
|
|
73
|
+
params: Params<FirmwareUpdateV4Params>
|
|
74
|
+
): Response<{
|
|
75
|
+
bleVersion: string;
|
|
76
|
+
firmwareVersion: string;
|
|
77
|
+
bootloaderVersion: string;
|
|
78
|
+
}>;
|
package/src/types/api/index.ts
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
devFirmwareUpdate,
|
|
3
|
+
devGetDeviceInfo,
|
|
4
|
+
devGetFirmwareUpdateStatus,
|
|
5
|
+
devGetOnboardingStatus,
|
|
6
|
+
devReboot,
|
|
7
|
+
dirList,
|
|
8
|
+
dirMake,
|
|
9
|
+
dirRemove,
|
|
10
|
+
factoryDeviceInfoSettings,
|
|
11
|
+
factoryGetDeviceInfo,
|
|
12
|
+
fileDelete,
|
|
13
|
+
fileRead,
|
|
14
|
+
fileWrite,
|
|
15
|
+
filesystemDirList,
|
|
16
|
+
filesystemDirMake,
|
|
17
|
+
filesystemDirRemove,
|
|
18
|
+
filesystemFileDelete,
|
|
19
|
+
filesystemFileRead,
|
|
20
|
+
filesystemFileWrite,
|
|
21
|
+
filesystemFixPermission,
|
|
22
|
+
filesystemFormat,
|
|
23
|
+
filesystemPathInfoQuery,
|
|
24
|
+
getProtoVersion,
|
|
25
|
+
pathInfo,
|
|
26
|
+
ping,
|
|
27
|
+
} from './protocolV2';
|
|
1
28
|
import type { off, on, removeAllListeners } from './event';
|
|
2
29
|
import type { uiResponse } from './uiResponse';
|
|
3
30
|
import type { init, updateSettings } from './init';
|
|
@@ -14,7 +41,12 @@ import type { getOnekeyFeatures } from './getOnekeyFeatures';
|
|
|
14
41
|
import type { getPassphraseState } from './getPassphraseState';
|
|
15
42
|
import type { checkFirmwareRelease } from './checkFirmwareRelease';
|
|
16
43
|
import type { checkBLEFirmwareRelease } from './checkBLEFirmwareRelease';
|
|
17
|
-
import type {
|
|
44
|
+
import type {
|
|
45
|
+
firmwareUpdate,
|
|
46
|
+
firmwareUpdateV2,
|
|
47
|
+
firmwareUpdateV3,
|
|
48
|
+
firmwareUpdateV4,
|
|
49
|
+
} from './firmwareUpdate';
|
|
18
50
|
import type { promptWebDeviceAccess } from './promptWebDeviceAccess';
|
|
19
51
|
import type { deviceReset } from './deviceReset';
|
|
20
52
|
import type { deviceRecovery } from './deviceRecovery';
|
|
@@ -114,6 +146,7 @@ import type { dnxSignTransaction } from './dnxSignTransaction';
|
|
|
114
146
|
import type { tonGetAddress } from './tonGetAddress';
|
|
115
147
|
import type { tonSignMessage } from './tonSignMessage';
|
|
116
148
|
import type { tonSignProof } from './tonSignProof';
|
|
149
|
+
import type { tonSignData } from './tonSignData';
|
|
117
150
|
import type { scdoGetAddress } from './scdoGetAddress';
|
|
118
151
|
import type { scdoSignMessage } from './scdoSignMessage';
|
|
119
152
|
import type { scdoSignTransaction } from './scdoSignTransaction';
|
|
@@ -194,8 +227,38 @@ export type CoreApi = {
|
|
|
194
227
|
firmwareUpdate: typeof firmwareUpdate;
|
|
195
228
|
firmwareUpdateV2: typeof firmwareUpdateV2;
|
|
196
229
|
firmwareUpdateV3: typeof firmwareUpdateV3;
|
|
230
|
+
firmwareUpdateV4: typeof firmwareUpdateV4;
|
|
197
231
|
cipherKeyValue: typeof cipherKeyValue;
|
|
198
232
|
|
|
233
|
+
/**
|
|
234
|
+
* File system & device control API (Protocol V2 only)
|
|
235
|
+
*/
|
|
236
|
+
getProtoVersion: typeof getProtoVersion;
|
|
237
|
+
ping: typeof ping;
|
|
238
|
+
devReboot: typeof devReboot;
|
|
239
|
+
devGetDeviceInfo: typeof devGetDeviceInfo;
|
|
240
|
+
devGetOnboardingStatus: typeof devGetOnboardingStatus;
|
|
241
|
+
devFirmwareUpdate: typeof devFirmwareUpdate;
|
|
242
|
+
devGetFirmwareUpdateStatus: typeof devGetFirmwareUpdateStatus;
|
|
243
|
+
factoryDeviceInfoSettings: typeof factoryDeviceInfoSettings;
|
|
244
|
+
factoryGetDeviceInfo: typeof factoryGetDeviceInfo;
|
|
245
|
+
filesystemFixPermission: typeof filesystemFixPermission;
|
|
246
|
+
fileRead: typeof fileRead;
|
|
247
|
+
fileWrite: typeof fileWrite;
|
|
248
|
+
fileDelete: typeof fileDelete;
|
|
249
|
+
dirList: typeof dirList;
|
|
250
|
+
dirMake: typeof dirMake;
|
|
251
|
+
dirRemove: typeof dirRemove;
|
|
252
|
+
pathInfo: typeof pathInfo;
|
|
253
|
+
filesystemFileRead: typeof filesystemFileRead;
|
|
254
|
+
filesystemFileWrite: typeof filesystemFileWrite;
|
|
255
|
+
filesystemFileDelete: typeof filesystemFileDelete;
|
|
256
|
+
filesystemDirList: typeof filesystemDirList;
|
|
257
|
+
filesystemDirMake: typeof filesystemDirMake;
|
|
258
|
+
filesystemDirRemove: typeof filesystemDirRemove;
|
|
259
|
+
filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
|
|
260
|
+
filesystemFormat: typeof filesystemFormat;
|
|
261
|
+
|
|
199
262
|
/**
|
|
200
263
|
* All network function
|
|
201
264
|
*/
|
|
@@ -373,6 +436,7 @@ export type CoreApi = {
|
|
|
373
436
|
tonGetAddress: typeof tonGetAddress;
|
|
374
437
|
tonSignMessage: typeof tonSignMessage;
|
|
375
438
|
tonSignProof: typeof tonSignProof;
|
|
439
|
+
tonSignData: typeof tonSignData;
|
|
376
440
|
|
|
377
441
|
/**
|
|
378
442
|
* SCDO Network
|