@onekeyfe/hd-core 1.2.0-alpha.1 → 1.2.0-alpha.10
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__/connectSettings.test.ts +19 -0
- package/__tests__/device-wallet-session-store.test.ts +131 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +1784 -502
- package/dist/api/ClearSessionCache.d.ts +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +24 -3
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +4 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/index.d.ts +8 -10
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/{DeviceGetDeviceInfo.d.ts → DeviceInfoGet.d.ts} +10 -10
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts +9 -0
- package/dist/api/protocol-v2/DeviceSessionGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -1
- package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +27 -18
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -5
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +0 -1
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +0 -1
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -3
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/index.d.ts +96 -55
- package/dist/index.js +2077 -1609
- package/dist/inject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +12 -14
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +1 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +13 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdate.d.ts +4 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -0
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +11 -11
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +16 -17
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +10 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/device.d.ts +1 -0
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +21 -2
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +2 -0
- 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/ClearSessionCache.ts +28 -0
- package/src/api/FileRead.ts +16 -3
- package/src/api/FileWrite.ts +14 -1
- package/src/api/FirmwareUpdateV4.ts +1075 -264
- package/src/api/GetOnekeyFeatures.ts +1 -1
- package/src/api/GetPassphraseState.ts +4 -1
- package/src/api/device/DeviceRebootToBoardloader.ts +4 -4
- package/src/api/device/DeviceRebootToBootloader.ts +4 -4
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +18 -4
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/index.ts +8 -10
- package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +3 -3
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +3 -5
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +39 -5
- package/src/api/protocol-v2/{DeviceGetDeviceInfo.ts → DeviceInfoGet.ts} +52 -22
- package/src/api/protocol-v2/DeviceReboot.ts +1 -1
- package/src/api/protocol-v2/DeviceSessionGet.ts +26 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +14 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +4 -1
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +2 -2
- package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +2 -2
- package/src/api/protocol-v2/helpers.ts +71 -47
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/api/tron/TronSignMessage.ts +0 -1
- package/src/api/tron/TronSignTransaction.ts +0 -1
- package/src/core/index.ts +19 -5
- package/src/data/messages/messages-protocol-v2.json +599 -1033
- package/src/data/messages/messages.json +8 -0
- package/src/data-manager/DataManager.ts +7 -0
- package/src/data-manager/connectSettings.ts +2 -4
- package/src/device/Device.ts +89 -70
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +60 -63
- package/src/deviceProfile/buildDeviceProfile.ts +77 -58
- package/src/inject.ts +13 -16
- package/src/protocols/protocol-v2/features.ts +26 -63
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +1 -0
- package/src/protocols/protocol-v2/walletSession.ts +83 -0
- package/src/types/api/firmwareUpdate.ts +16 -20
- package/src/types/api/getDeviceInfo.ts +2 -0
- package/src/types/api/index.ts +17 -20
- package/src/types/api/protocolV2.ts +36 -40
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +1 -0
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -35
- package/src/utils/deviceFeaturesUtils.ts +44 -13
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +0 -6
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +0 -16
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
|
@@ -1,43 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 当前 firmware-pro2 子模块的
|
|
3
|
-
*
|
|
4
|
-
* 注意:仓库里的 hd-transport 生成物暂时仍带旧 target 名称;这里显式按
|
|
5
|
-
* submodules/firmware-pro2/sys/protobuf/onekey_protocol/latest/messages_device.proto
|
|
6
|
-
* 对齐当前子模块,避免运行时取到 undefined。
|
|
2
|
+
* 当前 firmware-pro2 子模块的 DeviceFirmwareTargetType。
|
|
7
3
|
*/
|
|
8
4
|
export const ProtocolV2FirmwareTargetType = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
FW_MGMT_TARGET_INVALID: 0,
|
|
6
|
+
FW_MGMT_TARGET_CRATE: 1,
|
|
7
|
+
FW_MGMT_TARGET_ROMLOADER: 2,
|
|
8
|
+
FW_MGMT_TARGET_BOOTLOADER: 3,
|
|
9
|
+
FW_MGMT_TARGET_APPLICATION_P1: 4,
|
|
10
|
+
FW_MGMT_TARGET_APPLICATION_P2: 5,
|
|
11
|
+
FW_MGMT_TARGET_COPROCESSOR: 6,
|
|
12
|
+
FW_MGMT_TARGET_SE01: 7,
|
|
13
|
+
FW_MGMT_TARGET_SE02: 8,
|
|
14
|
+
FW_MGMT_TARGET_SE03: 9,
|
|
15
|
+
FW_MGMT_TARGET_SE04: 10,
|
|
17
16
|
} as const;
|
|
18
17
|
|
|
19
18
|
export type ProtocolV2FirmwareTargetType =
|
|
20
19
|
(typeof ProtocolV2FirmwareTargetType)[keyof typeof ProtocolV2FirmwareTargetType];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Map Protocol V2 firmware file name to DevFirmwareUpdate target_id.
|
|
24
|
-
*/
|
|
25
|
-
export function protocolV2FileNameToTargetId(fileName: string): ProtocolV2FirmwareTargetType {
|
|
26
|
-
const normalized = fileName.toLowerCase();
|
|
27
|
-
if (normalized.includes('bootloader') || normalized.includes('update_rom')) {
|
|
28
|
-
return ProtocolV2FirmwareTargetType.TARGET_MAIN_BOOT;
|
|
29
|
-
}
|
|
30
|
-
if (
|
|
31
|
-
normalized.includes('coprocessor') ||
|
|
32
|
-
normalized.includes('ble') ||
|
|
33
|
-
normalized.includes('bluetooth') ||
|
|
34
|
-
normalized.includes('bt')
|
|
35
|
-
) {
|
|
36
|
-
return ProtocolV2FirmwareTargetType.TARGET_BT;
|
|
37
|
-
}
|
|
38
|
-
if (normalized.includes('se4')) return ProtocolV2FirmwareTargetType.TARGET_SE4;
|
|
39
|
-
if (normalized.includes('se3')) return ProtocolV2FirmwareTargetType.TARGET_SE3;
|
|
40
|
-
if (normalized.includes('se2')) return ProtocolV2FirmwareTargetType.TARGET_SE2;
|
|
41
|
-
if (normalized.includes('se')) return ProtocolV2FirmwareTargetType.TARGET_SE1;
|
|
42
|
-
return ProtocolV2FirmwareTargetType.TARGET_MAIN_APP;
|
|
43
|
-
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import type { Device } from '../../device/Device';
|
|
4
|
+
|
|
5
|
+
const getErrorText = (error: unknown) => {
|
|
6
|
+
if (error instanceof Error) return `${error.name} ${error.message}`;
|
|
7
|
+
if (typeof error === 'string') return error;
|
|
8
|
+
if (error && typeof error === 'object') {
|
|
9
|
+
const record = error as Record<string, unknown>;
|
|
10
|
+
return [record.code, record.errorCode, record.message, record.reason]
|
|
11
|
+
.filter(value => value !== undefined && value !== null)
|
|
12
|
+
.join(' ');
|
|
13
|
+
}
|
|
14
|
+
return String(error ?? '');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const isProtocolV2InvalidSessionError = (error: unknown) =>
|
|
18
|
+
getErrorText(error).toLowerCase().includes('failure_invalidsession');
|
|
19
|
+
|
|
20
|
+
export async function requestProtocolV2DeviceStatus(device: Device) {
|
|
21
|
+
const { message } = await device.commands.typedCall('DeviceStatusGet', 'DeviceStatus', {});
|
|
22
|
+
return message;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function refreshProtocolV2DeviceStatus(device: Device) {
|
|
26
|
+
const status = await requestProtocolV2DeviceStatus(device);
|
|
27
|
+
return device.updateProtocolV2Status(status);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function getProtocolV2WalletSession(
|
|
31
|
+
device: Device,
|
|
32
|
+
options?: { initSession?: boolean; expectedPassphraseState?: string }
|
|
33
|
+
) {
|
|
34
|
+
if (device.features?.unlocked === false) {
|
|
35
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Device is locked');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (options?.initSession) {
|
|
39
|
+
device.clearInternalState();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cachedSessionId =
|
|
43
|
+
typeof device.getInternalState === 'function' ? device.getInternalState() : undefined;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const { message } = await device.commands.typedCall(
|
|
47
|
+
'DeviceSessionGet',
|
|
48
|
+
'DeviceSession',
|
|
49
|
+
cachedSessionId ? { session_id: cachedSessionId } : {}
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
options?.expectedPassphraseState &&
|
|
54
|
+
options.expectedPassphraseState !== message.btc_test_address
|
|
55
|
+
) {
|
|
56
|
+
device.clearInternalState();
|
|
57
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (message.btc_test_address && device.getCurrentPassphraseProtection() !== true) {
|
|
61
|
+
await refreshProtocolV2DeviceStatus(device);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
device.updateInternalState(
|
|
65
|
+
(device.getCurrentPassphraseProtection() ?? false) || Boolean(message.btc_test_address),
|
|
66
|
+
message.btc_test_address,
|
|
67
|
+
device.getCurrentDeviceId(),
|
|
68
|
+
message.session_id,
|
|
69
|
+
options?.initSession ? null : device.features?.sessionId
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
passphraseState: message.btc_test_address,
|
|
74
|
+
newSession: message.session_id,
|
|
75
|
+
unlockedAttachPin: device.features?.unlockedAttachPin ?? undefined,
|
|
76
|
+
};
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (isProtocolV2InvalidSessionError(error)) {
|
|
79
|
+
device.clearInternalState();
|
|
80
|
+
}
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -58,42 +58,38 @@ export interface FirmwareUpdateV3Params {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
|
-
* firmwareUpdateV4(Protocol V2)按
|
|
62
|
-
*
|
|
61
|
+
* firmwareUpdateV4(Protocol V2)按 DeviceFirmwareTargetType 拆分的目标二进制。
|
|
62
|
+
* 除 romloader 外,每个字段对应一个 bootloader 可接受的固件升级 target。
|
|
63
63
|
*/
|
|
64
64
|
export interface FirmwareUpdateV4Params {
|
|
65
65
|
platform: IPlatform;
|
|
66
66
|
chunkSize?: number;
|
|
67
67
|
firmwareType?: EFirmwareType;
|
|
68
68
|
|
|
69
|
-
/**
|
|
69
|
+
/** FW_MGMT_TARGET_ROMLOADER = 2;当前 Pro2 bootloader 不接受通过 firmwareUpdateV4 安装 */
|
|
70
70
|
romloaderBinary?: ArrayBuffer;
|
|
71
|
-
/**
|
|
71
|
+
/** FW_MGMT_TARGET_BOOTLOADER = 3 */
|
|
72
72
|
bootloaderBinary?: ArrayBuffer;
|
|
73
|
-
/**
|
|
73
|
+
/** FW_MGMT_TARGET_APPLICATION_P1 = 4 */
|
|
74
74
|
applicationP1Binary?: ArrayBuffer;
|
|
75
|
-
/**
|
|
75
|
+
/** FW_MGMT_TARGET_APPLICATION_P2 = 5 */
|
|
76
76
|
applicationP2Binary?: ArrayBuffer;
|
|
77
|
-
/**
|
|
77
|
+
/** FW_MGMT_TARGET_COPROCESSOR = 6 */
|
|
78
78
|
coprocessorBinary?: ArrayBuffer;
|
|
79
|
-
/**
|
|
79
|
+
/** FW_MGMT_TARGET_SE01-04 = 7-10 */
|
|
80
80
|
se01Binary?: ArrayBuffer;
|
|
81
81
|
se02Binary?: ArrayBuffer;
|
|
82
82
|
se03Binary?: ArrayBuffer;
|
|
83
83
|
se04Binary?: ArrayBuffer;
|
|
84
|
-
/** TARGET_RESOURCE = 10(zip 包,解压后逐文件上传) */
|
|
85
|
-
resourceBinary?: ArrayBuffer;
|
|
86
84
|
forcedUpdateRes?: boolean;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
/** legacy 别名:等价 coprocessorBinary */
|
|
96
|
-
bleBinary?: ArrayBuffer;
|
|
85
|
+
/**
|
|
86
|
+
* RESC bundle okpkg 列表,通过 FilesystemFileWrite 直写到 devicePath(vol0:/bundles/...)。
|
|
87
|
+
* 手动传入模式:SDK 直接 FileWrite 安装,不做版本比对。
|
|
88
|
+
*/
|
|
89
|
+
resourceBundleFiles?: Array<{
|
|
90
|
+
binary: ArrayBuffer;
|
|
91
|
+
devicePath: string;
|
|
92
|
+
}>;
|
|
97
93
|
}
|
|
98
94
|
|
|
99
95
|
export declare function firmwareUpdateV3(
|
|
@@ -24,6 +24,8 @@ export type DeviceInfoStatus = {
|
|
|
24
24
|
bootloaderMode: boolean | null;
|
|
25
25
|
unlocked: boolean | null;
|
|
26
26
|
passphraseProtection: boolean | null;
|
|
27
|
+
attachToPinEnabled?: boolean | null;
|
|
28
|
+
unlockedAttachPin?: boolean | null;
|
|
27
29
|
backupRequired: boolean | null;
|
|
28
30
|
noBackup: boolean | null;
|
|
29
31
|
language: string | null;
|
package/src/types/api/index.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
deviceFactoryInfoGet,
|
|
3
|
+
deviceFactoryInfoSet,
|
|
2
4
|
deviceFirmwareUpdate,
|
|
3
|
-
deviceGetDeviceInfo,
|
|
4
5
|
deviceGetFirmwareUpdateStatus,
|
|
5
|
-
|
|
6
|
+
deviceInfoGet,
|
|
6
7
|
deviceReboot,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
devGetFirmwareUpdateStatus,
|
|
10
|
-
devReboot,
|
|
8
|
+
deviceSessionGet,
|
|
9
|
+
deviceStatusGet,
|
|
11
10
|
dirList,
|
|
12
11
|
dirMake,
|
|
13
12
|
dirRemove,
|
|
14
|
-
factoryDeviceInfoSettings,
|
|
15
|
-
factoryGetDeviceInfo,
|
|
16
13
|
fileDelete,
|
|
17
14
|
fileRead,
|
|
18
15
|
fileWrite,
|
|
@@ -23,12 +20,12 @@ import type {
|
|
|
23
20
|
filesystemFileDelete,
|
|
24
21
|
filesystemFileRead,
|
|
25
22
|
filesystemFileWrite,
|
|
26
|
-
filesystemFixPermission,
|
|
27
23
|
filesystemFormat,
|
|
28
24
|
filesystemPathInfoQuery,
|
|
29
|
-
|
|
25
|
+
filesystemPermissionFix,
|
|
30
26
|
pathInfo,
|
|
31
27
|
ping,
|
|
28
|
+
protocolInfoRequest,
|
|
32
29
|
} from './protocolV2';
|
|
33
30
|
import type { off, on, removeAllListeners } from './event';
|
|
34
31
|
import type { uiResponse } from './uiResponse';
|
|
@@ -36,6 +33,7 @@ import type { init, updateSettings } from './init';
|
|
|
36
33
|
import type { testInitializeDeviceDuration } from './testInitializeDeviceDuration';
|
|
37
34
|
import type { preInitialize } from './preInitialize';
|
|
38
35
|
import type { getLogs } from './getLogs';
|
|
36
|
+
import type { clearSessionCache } from './sessionCache';
|
|
39
37
|
import type { checkBridgeStatus } from './checkBridgeStatus';
|
|
40
38
|
import type { checkBridgeRelease } from './checkBridgeRelease';
|
|
41
39
|
import type { checkBootloaderRelease } from './checkBootloaderRelease';
|
|
@@ -182,6 +180,7 @@ export type {
|
|
|
182
180
|
DeviceProfileVersions,
|
|
183
181
|
} from './getDeviceInfo';
|
|
184
182
|
export type { GetPassphraseStateParams, GetPassphraseStatePayload } from './getPassphraseState';
|
|
183
|
+
export type { ClearSessionCacheParams, ClearSessionCachePayload } from './sessionCache';
|
|
185
184
|
|
|
186
185
|
export type CoreApi = {
|
|
187
186
|
/**
|
|
@@ -199,6 +198,7 @@ export type CoreApi = {
|
|
|
199
198
|
updateSettings: typeof updateSettings;
|
|
200
199
|
switchTransport: (env: ConnectSettings['env']) => Promise<{ success: boolean }>;
|
|
201
200
|
getLogs: typeof getLogs;
|
|
201
|
+
clearSessionCache: typeof clearSessionCache;
|
|
202
202
|
|
|
203
203
|
/**
|
|
204
204
|
* Test function
|
|
@@ -255,20 +255,17 @@ export type CoreApi = {
|
|
|
255
255
|
/**
|
|
256
256
|
* File system & device control API (Protocol V2 only)
|
|
257
257
|
*/
|
|
258
|
-
|
|
258
|
+
protocolInfoRequest: typeof protocolInfoRequest;
|
|
259
259
|
ping: typeof ping;
|
|
260
260
|
deviceReboot: typeof deviceReboot;
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
deviceInfoGet: typeof deviceInfoGet;
|
|
262
|
+
deviceStatusGet: typeof deviceStatusGet;
|
|
263
|
+
deviceSessionGet: typeof deviceSessionGet;
|
|
263
264
|
deviceFirmwareUpdate: typeof deviceFirmwareUpdate;
|
|
264
265
|
deviceGetFirmwareUpdateStatus: typeof deviceGetFirmwareUpdateStatus;
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
devGetFirmwareUpdateStatus: typeof devGetFirmwareUpdateStatus;
|
|
269
|
-
factoryDeviceInfoSettings: typeof factoryDeviceInfoSettings;
|
|
270
|
-
factoryGetDeviceInfo: typeof factoryGetDeviceInfo;
|
|
271
|
-
filesystemFixPermission: typeof filesystemFixPermission;
|
|
266
|
+
deviceFactoryInfoSet: typeof deviceFactoryInfoSet;
|
|
267
|
+
deviceFactoryInfoGet: typeof deviceFactoryInfoGet;
|
|
268
|
+
filesystemPermissionFix: typeof filesystemPermissionFix;
|
|
272
269
|
fileRead: typeof fileRead;
|
|
273
270
|
fileWrite: typeof fileWrite;
|
|
274
271
|
fileDelete: typeof fileDelete;
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import type { CommonParams, Response } from '../params';
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
DeviceFactoryInfo,
|
|
4
|
+
DeviceFirmwareUpdateStatus,
|
|
5
|
+
DeviceSession,
|
|
6
|
+
DeviceStatus,
|
|
7
|
+
ProtocolInfo,
|
|
7
8
|
ProtocolV2DeviceInfo,
|
|
8
9
|
Success,
|
|
9
10
|
} from '@onekeyfe/hd-transport';
|
|
10
11
|
import type {
|
|
12
|
+
DeviceFactoryInfoSetParams,
|
|
11
13
|
DeviceFirmwareUpdateParams,
|
|
14
|
+
DeviceFirmwareUpdateStatusGetParams,
|
|
12
15
|
DeviceRebootParams,
|
|
13
|
-
FactoryDeviceInfoSettingsParams,
|
|
14
16
|
} from '../../api/protocol-v2/helpers';
|
|
15
|
-
import type {
|
|
17
|
+
import type { DeviceInfoGetParams } from '../../api/protocol-v2/DeviceInfoGet';
|
|
18
|
+
import type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
|
|
16
19
|
|
|
17
20
|
// 参数类型单源:以 api/protocol-v2 的实现为准(type-only re-export,无运行时依赖)
|
|
18
21
|
export type {
|
|
19
22
|
DeviceFirmwareTargetInput,
|
|
20
23
|
DeviceFirmwareUpdateParams,
|
|
24
|
+
DeviceFirmwareUpdateStatusGetParams,
|
|
21
25
|
DeviceRebootParams,
|
|
22
|
-
|
|
26
|
+
DeviceFactoryInfoSetParams,
|
|
23
27
|
RebootTypeInput,
|
|
24
28
|
} from '../../api/protocol-v2/helpers';
|
|
25
29
|
export type {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} from '../../api/protocol-v2/
|
|
30
|
+
DeviceInfoGetParams,
|
|
31
|
+
DeviceInfoGetTargets,
|
|
32
|
+
DeviceInfoGetTypes,
|
|
33
|
+
} from '../../api/protocol-v2/DeviceInfoGet';
|
|
34
|
+
export type { DeviceSessionGetParams } from '../../api/protocol-v2/DeviceSessionGet';
|
|
30
35
|
|
|
31
36
|
// ── Shared response shapes (Protocol V2 file system) ────────────────────
|
|
32
37
|
|
|
@@ -67,10 +72,10 @@ export type PathInfoResult = {
|
|
|
67
72
|
|
|
68
73
|
// ── Method signatures ─────────────────────────────────────────────────────
|
|
69
74
|
|
|
70
|
-
export declare function
|
|
75
|
+
export declare function protocolInfoRequest(
|
|
71
76
|
connectId: string,
|
|
72
77
|
params?: CommonParams
|
|
73
|
-
): Response<
|
|
78
|
+
): Response<ProtocolInfo>;
|
|
74
79
|
|
|
75
80
|
export declare function ping(
|
|
76
81
|
connectId: string,
|
|
@@ -82,55 +87,46 @@ export declare function deviceReboot(
|
|
|
82
87
|
params: CommonParams & DeviceRebootParams
|
|
83
88
|
): Response<Success>;
|
|
84
89
|
|
|
85
|
-
export declare function
|
|
90
|
+
export declare function deviceInfoGet(
|
|
86
91
|
connectId: string,
|
|
87
|
-
params?: CommonParams &
|
|
92
|
+
params?: CommonParams & DeviceInfoGetParams
|
|
88
93
|
): Response<ProtocolV2DeviceInfo>;
|
|
89
94
|
|
|
90
|
-
export declare function
|
|
95
|
+
export declare function deviceStatusGet(
|
|
91
96
|
connectId: string,
|
|
92
97
|
params?: CommonParams
|
|
93
|
-
): Response<
|
|
98
|
+
): Response<DeviceStatus>;
|
|
99
|
+
|
|
100
|
+
export declare function deviceSessionGet(
|
|
101
|
+
connectId: string,
|
|
102
|
+
params?: CommonParams & DeviceSessionGetParams
|
|
103
|
+
): Response<DeviceSession>;
|
|
94
104
|
|
|
95
105
|
export declare function deviceFirmwareUpdate(
|
|
96
106
|
connectId: string,
|
|
97
107
|
params: CommonParams & DeviceFirmwareUpdateParams
|
|
98
|
-
): Response<Success |
|
|
108
|
+
): Response<Success | DeviceFirmwareUpdateStatus>;
|
|
99
109
|
|
|
100
110
|
export declare function deviceGetFirmwareUpdateStatus(
|
|
101
111
|
connectId: string,
|
|
102
|
-
params?: CommonParams
|
|
103
|
-
): Response<
|
|
112
|
+
params?: CommonParams & DeviceFirmwareUpdateStatusGetParams
|
|
113
|
+
): Response<DeviceFirmwareUpdateStatus>;
|
|
104
114
|
|
|
105
|
-
export declare function
|
|
115
|
+
export declare function deviceFactoryInfoSet(
|
|
106
116
|
connectId: string,
|
|
107
|
-
params: CommonParams &
|
|
117
|
+
params: CommonParams & DeviceFactoryInfoSetParams
|
|
108
118
|
): Response<Success>;
|
|
109
119
|
|
|
110
|
-
export declare function
|
|
111
|
-
connectId: string,
|
|
112
|
-
params?: CommonParams & DeviceGetDeviceInfoParams
|
|
113
|
-
): Response<ProtocolV2DeviceInfo>;
|
|
114
|
-
|
|
115
|
-
export declare function devFirmwareUpdate(
|
|
116
|
-
connectId: string,
|
|
117
|
-
params: CommonParams & DeviceFirmwareUpdateParams
|
|
118
|
-
): Response<Success | DevFirmwareUpdateStatus>;
|
|
119
|
-
|
|
120
|
-
export declare function devGetFirmwareUpdateStatus(
|
|
120
|
+
export declare function deviceFactoryInfoGet(
|
|
121
121
|
connectId: string,
|
|
122
122
|
params?: CommonParams
|
|
123
|
-
): Response<
|
|
123
|
+
): Response<DeviceFactoryInfo>;
|
|
124
124
|
|
|
125
|
-
export declare function
|
|
125
|
+
export declare function filesystemPermissionFix(
|
|
126
126
|
connectId: string,
|
|
127
|
-
params
|
|
127
|
+
params?: CommonParams
|
|
128
128
|
): Response<Success>;
|
|
129
129
|
|
|
130
|
-
export declare function factoryGetDeviceInfo(connectId: string): Response<FactoryDeviceInfo>;
|
|
131
|
-
|
|
132
|
-
export declare function filesystemFixPermission(connectId: string): Response<Success>;
|
|
133
|
-
|
|
134
130
|
export declare function fileRead(
|
|
135
131
|
connectId: string,
|
|
136
132
|
params: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Response } from '../params';
|
|
2
|
+
|
|
3
|
+
export type ClearSessionCacheParams = {
|
|
4
|
+
deviceId?: string;
|
|
5
|
+
passphraseState?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ClearSessionCachePayload = {
|
|
9
|
+
cleared: true;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export declare function clearSessionCache(
|
|
13
|
+
params?: ClearSessionCacheParams
|
|
14
|
+
): Response<ClearSessionCachePayload>;
|
package/src/types/device.ts
CHANGED
|
@@ -157,6 +157,7 @@ export type Features = {
|
|
|
157
157
|
sdProtection: boolean | null;
|
|
158
158
|
wipeCodeProtection: boolean | null;
|
|
159
159
|
passphraseAlwaysOnDevice: boolean | null;
|
|
160
|
+
attachToPinEnabled?: boolean | null;
|
|
160
161
|
safetyChecks: string | null;
|
|
161
162
|
autoLockDelayMs: number | null;
|
|
162
163
|
displayRotation: number | null;
|
package/src/types/params.ts
CHANGED
package/src/types/settings.ts
CHANGED
|
@@ -34,17 +34,46 @@ export type ConnectSettings = {
|
|
|
34
34
|
fetchConfig?: boolean;
|
|
35
35
|
extension?: string;
|
|
36
36
|
configFetcher?: (url: string) => Promise<RemoteConfigResponse | null>;
|
|
37
|
-
/**
|
|
38
|
-
* 临时开关:Protocol V2 DevGetDeviceInfo 未稳定前用于 mock 设备信息。
|
|
39
|
-
* 正式 app 可显式设置为 false 以调用真实 DevGetDeviceInfo;固件稳定后删除。
|
|
40
|
-
*/
|
|
41
|
-
protocolV2DeviceInfoMockEnabled?: boolean;
|
|
42
37
|
};
|
|
43
38
|
|
|
44
39
|
export type IVersionArray = [number, number, number];
|
|
45
40
|
|
|
46
41
|
export type ILocale = 'zh-CN' | 'en-US';
|
|
47
42
|
|
|
43
|
+
export type IProtocolV2FirmwareComponentTarget =
|
|
44
|
+
| 'ROMLOADER'
|
|
45
|
+
| 'BOOTLOADER'
|
|
46
|
+
| 'APPLICATION_P1'
|
|
47
|
+
| 'APPLICATION_P2'
|
|
48
|
+
| 'COPROCESSOR'
|
|
49
|
+
| 'SE01'
|
|
50
|
+
| 'SE02'
|
|
51
|
+
| 'SE03'
|
|
52
|
+
| 'SE04';
|
|
53
|
+
|
|
54
|
+
export type IProtocolV2FirmwareComponent = {
|
|
55
|
+
target: IProtocolV2FirmwareComponentTarget;
|
|
56
|
+
url: string;
|
|
57
|
+
fingerprint?: string;
|
|
58
|
+
version?: IVersionArray;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Pro2 RESC bundle okpkg 描述,用于 FileWrite 直写方式增量同步资源 */
|
|
62
|
+
export type IProtocolV2ResourceBundle = {
|
|
63
|
+
/** bundle 名称,如 images / animation / translations / fonts_roobert */
|
|
64
|
+
name: string;
|
|
65
|
+
/** 下载 URL */
|
|
66
|
+
url: string;
|
|
67
|
+
/** 设备上的目标路径,如 vol0:/bundles/images/images.okpkg */
|
|
68
|
+
devicePath: string;
|
|
69
|
+
/** okpkg container 的 payload_version(用于 FileRead 比对跳过) */
|
|
70
|
+
version?: IVersionArray;
|
|
71
|
+
/** okpkg container 的 payload_hash(SHA3-512,用于 FileRead 比对) */
|
|
72
|
+
payloadHash?: string;
|
|
73
|
+
/** okpkg container 的 header_hash(SHA3-512,用于 FileRead 比对) */
|
|
74
|
+
headerHash?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
48
77
|
/** STM32 firmware config */
|
|
49
78
|
export type IFirmwareReleaseInfo = {
|
|
50
79
|
required: boolean;
|
|
@@ -63,6 +92,11 @@ export type IFirmwareReleaseInfo = {
|
|
|
63
92
|
bootloaderVersion?: IVersionArray;
|
|
64
93
|
displayBootloaderVersion?: IVersionArray;
|
|
65
94
|
bootloaderRelatedFirmwareVersion?: IVersionArray;
|
|
95
|
+
upgradeType?: 'payload-package-set' | string;
|
|
96
|
+
components?: Record<string, IProtocolV2FirmwareComponent>;
|
|
97
|
+
installOrder?: string[];
|
|
98
|
+
/** Pro2 RESC bundle 列表(FileWrite 直写增量同步模式) */
|
|
99
|
+
resourceBundles?: IProtocolV2ResourceBundle[];
|
|
66
100
|
bootloaderChangelog?: {
|
|
67
101
|
[k in ILocale]: string;
|
|
68
102
|
};
|
|
@@ -88,43 +122,16 @@ export type IBLEFirmwareReleaseInfo = {
|
|
|
88
122
|
};
|
|
89
123
|
};
|
|
90
124
|
|
|
91
|
-
type IKnownDevice = Exclude<IDeviceType, 'unknown'
|
|
125
|
+
type IKnownDevice = Exclude<IDeviceType, 'unknown'>;
|
|
92
126
|
|
|
93
|
-
/**
|
|
94
|
-
* Device firmware configuration map
|
|
95
|
-
*
|
|
96
|
-
* IMPORTANT: This type is used for firmware update logic.
|
|
97
|
-
* - DO NOT remove existing firmware fields
|
|
98
|
-
* - Only ADD new optional firmware fields for new versions
|
|
99
|
-
* - 'firmware' field is required for backward compatibility
|
|
100
|
-
* - 'ble' field is required for BLE firmware updates
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* // When adding firmware-v8:
|
|
104
|
-
* // {
|
|
105
|
-
* // firmware: IFirmwareReleaseInfo[];
|
|
106
|
-
* // 'firmware-v2'?: IFirmwareReleaseInfo[];
|
|
107
|
-
* // 'firmware-v8'?: IFirmwareReleaseInfo[];
|
|
108
|
-
* // 'firmware-v8'?: IFirmwareReleaseInfo[]; // New
|
|
109
|
-
* // 'firmware-btc-v8'?: IFirmwareReleaseInfo[];
|
|
110
|
-
* // 'firmware-btc-v8'?: IFirmwareReleaseInfo[]; // New
|
|
111
|
-
* // ble: IBLEFirmwareReleaseInfo[];
|
|
112
|
-
* // }
|
|
113
|
-
*/
|
|
114
127
|
export type DeviceTypeMap = {
|
|
115
128
|
[k in IKnownDevice]: {
|
|
116
|
-
/** Base firmware field (required for backward compatibility) */
|
|
117
129
|
firmware: IFirmwareReleaseInfo[];
|
|
118
|
-
/**
|
|
130
|
+
/** Pro2 Protocol V2 payload package set */
|
|
131
|
+
'firmware-v1'?: IFirmwareReleaseInfo[];
|
|
119
132
|
'firmware-v2'?: IFirmwareReleaseInfo[];
|
|
120
|
-
/** Universal firmware v7 */
|
|
121
133
|
'firmware-v8'?: IFirmwareReleaseInfo[];
|
|
122
|
-
/** Bitcoin-only firmware v7 */
|
|
123
134
|
'firmware-btc-v8'?: IFirmwareReleaseInfo[];
|
|
124
|
-
// Future firmware versions should be added here as optional fields:
|
|
125
|
-
// 'firmware-v8'?: IFirmwareReleaseInfo[];
|
|
126
|
-
// 'firmware-btc-v8'?: IFirmwareReleaseInfo[];
|
|
127
|
-
/** BLE firmware (required) */
|
|
128
135
|
ble: IBLEFirmwareReleaseInfo[];
|
|
129
136
|
};
|
|
130
137
|
};
|