@onekeyfe/hd-core 1.2.0-alpha.12 → 1.2.0-alpha.13
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-bootloader-mode.test.ts +37 -0
- package/__tests__/protocol-v2.test.ts +126 -52
- package/__tests__/protocolV2FileWrite.test.ts +12 -0
- package/dist/api/FirmwareUpdateV4.d.ts +2 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.js +481 -145
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +1 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -4
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -1
- package/dist/types/device.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/FirmwareUpdateV4.ts +46 -6
- package/src/api/cardano/CardanoSignMessage.ts +1 -1
- package/src/api/cardano/CardanoSignTransaction.ts +1 -1
- package/src/api/helpers/protocolV2FileWrite.ts +10 -6
- package/src/api/index.ts +0 -1
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +9 -3
- package/src/api/protocol-v2/helpers.ts +0 -3
- package/src/data/messages/messages-protocol-v2.json +422 -16
- package/src/data/messages/messages.json +0 -8
- package/src/device/Device.ts +7 -17
- package/src/deviceProfile/buildDeviceFeatures.ts +8 -0
- package/src/inject.ts +0 -2
- package/src/types/api/index.ts +0 -2
- package/src/types/api/protocolV2.ts +0 -6
- package/src/types/device.ts +5 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
- package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
package/src/device/Device.ts
CHANGED
|
@@ -67,7 +67,6 @@ import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
|
67
67
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
68
68
|
import type {
|
|
69
69
|
OneKeyDeviceInfo as DeviceDescriptor,
|
|
70
|
-
DeviceSessionPinResult,
|
|
71
70
|
DeviceStatus,
|
|
72
71
|
ProtocolV2DeviceInfo,
|
|
73
72
|
Success,
|
|
@@ -1139,7 +1138,7 @@ export class Device extends EventEmitter {
|
|
|
1139
1138
|
// both allow and require cases might generate single unexpected mode
|
|
1140
1139
|
if (!this.isUnacquired()) {
|
|
1141
1140
|
// allow cases
|
|
1142
|
-
if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1141
|
+
if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
|
|
1143
1142
|
return UI_REQUEST.BOOTLOADER;
|
|
1144
1143
|
}
|
|
1145
1144
|
if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
|
|
@@ -1190,12 +1189,8 @@ export class Device extends EventEmitter {
|
|
|
1190
1189
|
|
|
1191
1190
|
async unlockDevice() {
|
|
1192
1191
|
if (this.isProtocolV2()) {
|
|
1193
|
-
let pinResult: DeviceSessionPinResult;
|
|
1194
1192
|
try {
|
|
1195
|
-
|
|
1196
|
-
'DeviceSessionAskPin',
|
|
1197
|
-
'DeviceSessionPinResult'
|
|
1198
|
-
));
|
|
1193
|
+
await this.commands.typedCall('DeviceSessionAskPin', 'Success');
|
|
1199
1194
|
} catch (error) {
|
|
1200
1195
|
const errorText =
|
|
1201
1196
|
error instanceof Error
|
|
@@ -1207,16 +1202,11 @@ export class Device extends EventEmitter {
|
|
|
1207
1202
|
throw error;
|
|
1208
1203
|
}
|
|
1209
1204
|
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
status.unlocked_by_attach_to_pin = pinResult.unlocked_attach_pin;
|
|
1216
|
-
}
|
|
1217
|
-
if (pinResult.passphrase_protection != null) {
|
|
1218
|
-
status.passphrase_enabled = pinResult.passphrase_protection;
|
|
1219
|
-
}
|
|
1205
|
+
const { message: status } = await this.commands.typedCall(
|
|
1206
|
+
'DeviceStatusGet',
|
|
1207
|
+
'DeviceStatus',
|
|
1208
|
+
{}
|
|
1209
|
+
);
|
|
1220
1210
|
return this.updateProtocolV2Status(status);
|
|
1221
1211
|
}
|
|
1222
1212
|
|
|
@@ -135,6 +135,7 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
135
135
|
const sessionId = features.session_id ?? previous?.sessionId ?? null;
|
|
136
136
|
|
|
137
137
|
return {
|
|
138
|
+
...features,
|
|
138
139
|
protocol: 'V1',
|
|
139
140
|
protocolVersion: features.protocol_version ?? previous?.protocolVersion ?? 1,
|
|
140
141
|
deviceType,
|
|
@@ -207,6 +208,7 @@ export const buildProtocolV1FeaturesPayload = (
|
|
|
207
208
|
se04BootHash: features.onekey_se04_boot_hash,
|
|
208
209
|
},
|
|
209
210
|
sessionId,
|
|
211
|
+
session_id: sessionId ?? undefined,
|
|
210
212
|
raw: {
|
|
211
213
|
protocolV1Features,
|
|
212
214
|
},
|
|
@@ -364,6 +366,12 @@ export const buildProtocolV2FeaturesPayload = (
|
|
|
364
366
|
se04BootHash: getImageHash(info?.se4?.bootloader) ?? previous?.verify?.se04BootHash,
|
|
365
367
|
},
|
|
366
368
|
sessionId: previous?.sessionId ?? null,
|
|
369
|
+
device_id: deviceId ?? undefined,
|
|
370
|
+
session_id: previous?.sessionId ?? undefined,
|
|
371
|
+
ble_name: bleName ?? undefined,
|
|
372
|
+
onekey_device_type: 'PRO2',
|
|
373
|
+
passphrase_protection: passphraseProtection ?? undefined,
|
|
374
|
+
bootloader_mode: bootloaderMode,
|
|
367
375
|
passphraseState: previous?.passphraseState,
|
|
368
376
|
unlockedAttachPin,
|
|
369
377
|
raw: {
|
package/src/inject.ts
CHANGED
|
@@ -207,8 +207,6 @@ export const createCoreApi = (
|
|
|
207
207
|
filesystemPathInfoQuery: (connectId, params) =>
|
|
208
208
|
call({ ...params, connectId, method: 'filesystemPathInfoQuery' }),
|
|
209
209
|
filesystemFormat: connectId => call({ connectId, method: 'filesystemFormat' }),
|
|
210
|
-
filesystemDiskControl: (connectId, params) =>
|
|
211
|
-
call({ ...params, connectId, method: 'filesystemDiskControl' }),
|
|
212
210
|
deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
|
|
213
211
|
deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
|
|
214
212
|
deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
|
package/src/types/api/index.ts
CHANGED
|
@@ -21,7 +21,6 @@ import type {
|
|
|
21
21
|
filesystemDirList,
|
|
22
22
|
filesystemDirMake,
|
|
23
23
|
filesystemDirRemove,
|
|
24
|
-
filesystemDiskControl,
|
|
25
24
|
filesystemFileDelete,
|
|
26
25
|
filesystemFileRead,
|
|
27
26
|
filesystemFileWrite,
|
|
@@ -294,7 +293,6 @@ export type CoreApi = {
|
|
|
294
293
|
filesystemDirRemove: typeof filesystemDirRemove;
|
|
295
294
|
filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
|
|
296
295
|
filesystemFormat: typeof filesystemFormat;
|
|
297
|
-
filesystemDiskControl: typeof filesystemDiskControl;
|
|
298
296
|
|
|
299
297
|
/**
|
|
300
298
|
* All network function
|
|
@@ -237,9 +237,3 @@ export declare const filesystemDirRemove: typeof dirRemove;
|
|
|
237
237
|
export declare const filesystemPathInfoQuery: typeof pathInfo;
|
|
238
238
|
|
|
239
239
|
export declare function filesystemFormat(connectId: string): Response<Success>;
|
|
240
|
-
|
|
241
|
-
export declare function filesystemDiskControl(
|
|
242
|
-
connectId: string,
|
|
243
|
-
// enable 收紧为 boolean | 0 | 1(兼容历史的 '0' / '1' 字符串输入,内部归一化为 0/1)
|
|
244
|
-
params: CommonParams & { enable: boolean | 0 | 1; timeoutMs?: number | string }
|
|
245
|
-
): Response<Success>;
|
package/src/types/device.ts
CHANGED
|
@@ -129,7 +129,7 @@ export type DeviceFeaturesRaw = {
|
|
|
129
129
|
protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
export type
|
|
132
|
+
export type NormalizedFeatures = {
|
|
133
133
|
protocol: DeviceFeaturesProtocol;
|
|
134
134
|
protocolVersion?: number | null;
|
|
135
135
|
deviceType: IDeviceType;
|
|
@@ -183,6 +183,10 @@ export type Features = {
|
|
|
183
183
|
raw?: DeviceFeaturesRaw;
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
+
export type Features = NormalizedFeatures &
|
|
187
|
+
Partial<Omit<PROTO.Features, keyof NormalizedFeatures>> &
|
|
188
|
+
Partial<Omit<PROTO.OnekeyFeatures, keyof NormalizedFeatures | keyof PROTO.Features>>;
|
|
189
|
+
|
|
186
190
|
export type OnekeyFeatures = PROTO.OnekeyFeatures;
|
|
187
191
|
|
|
188
192
|
export type IDeviceType =
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
export type FilesystemDiskControlParams = {
|
|
3
|
-
enable?: boolean | 0 | 1;
|
|
4
|
-
timeoutMs?: number | string;
|
|
5
|
-
};
|
|
6
|
-
export default class FilesystemDiskControl extends BaseMethod<{
|
|
7
|
-
enable: 0 | 1;
|
|
8
|
-
timeoutMs?: number;
|
|
9
|
-
}> {
|
|
10
|
-
init(): void;
|
|
11
|
-
run(): Promise<any>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=FilesystemDiskControl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FilesystemDiskControl.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FilesystemDiskControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,MAAM,MAAM,2BAA2B,GAAG;IAExC,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC;AAUF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC;IAC5D,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;IACA,IAAI;IAWE,GAAG;CAcV"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import {
|
|
3
|
-
invalidParameter,
|
|
4
|
-
validateOptionalNonNegativeInteger,
|
|
5
|
-
} from '../helpers/filesystemValidation';
|
|
6
|
-
|
|
7
|
-
export type FilesystemDiskControlParams = {
|
|
8
|
-
// 收紧为 boolean | 0 | 1;'0' / '1' 字符串仅作为历史输入向后兼容,内部归一化为 0/1
|
|
9
|
-
enable?: boolean | 0 | 1;
|
|
10
|
-
timeoutMs?: number | string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function normalizeDiskControlEnable(value: unknown): 0 | 1 {
|
|
14
|
-
if (value === undefined || value === null) return 0;
|
|
15
|
-
if (typeof value === 'boolean') return value ? 1 : 0;
|
|
16
|
-
if (value === 0 || value === '0') return 0;
|
|
17
|
-
if (value === 1 || value === '1') return 1;
|
|
18
|
-
throw invalidParameter('Parameter [enable] must be a boolean or 0 | 1.');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default class FilesystemDiskControl extends BaseMethod<{
|
|
22
|
-
enable: 0 | 1;
|
|
23
|
-
timeoutMs?: number;
|
|
24
|
-
}> {
|
|
25
|
-
init() {
|
|
26
|
-
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
27
|
-
this.requireProtocolV2 = true;
|
|
28
|
-
this.skipForceUpdateCheck = true;
|
|
29
|
-
this.useDevicePassphraseState = false;
|
|
30
|
-
this.params = {
|
|
31
|
-
enable: normalizeDiskControlEnable(this.payload.enable),
|
|
32
|
-
timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async run() {
|
|
37
|
-
const typedCall = this.device.commands.typedCall as any;
|
|
38
|
-
const res = await typedCall(
|
|
39
|
-
'FilesystemDiskControl',
|
|
40
|
-
'Success',
|
|
41
|
-
{
|
|
42
|
-
enable: this.params.enable,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
timeoutMs: this.params.timeoutMs,
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
return Promise.resolve(res.message);
|
|
49
|
-
}
|
|
50
|
-
}
|