@onekeyfe/hd-core 1.2.0-alpha.0 → 1.2.0-alpha.1
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 +147 -264
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +2 -2
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetDeviceInfo.d.ts.map +1 -1
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts +4 -4
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts +2 -3
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +11 -15
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +6 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceProfile.d.ts +3 -4
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +1 -1
- package/dist/deviceProfile/index.d.ts.map +1 -1
- package/dist/index.d.ts +579 -502
- package/dist/index.js +881 -931
- package/dist/protocols/protocol-v2/features.d.ts +2 -2
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/types/api/getDeviceInfo.d.ts +2 -2
- package/dist/types/api/getDeviceInfo.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +4 -4
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +87 -8
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/settings.d.ts +1 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/findDefectiveBatchDevice.d.ts +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/FirmwareUpdateV2.ts +9 -2
- package/src/api/FirmwareUpdateV3.ts +2 -1
- package/src/api/FirmwareUpdateV4.ts +24 -31
- package/src/api/GetDeviceInfo.ts +6 -13
- package/src/api/GetOnekeyFeatures.ts +3 -14
- package/src/api/GetPassphraseState.ts +4 -4
- package/src/api/firmware/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/uploadFirmware.ts +5 -2
- package/src/api/protocol-v2/DeviceReboot.ts +3 -3
- package/src/api/protocol-v2/helpers.ts +1 -26
- package/src/constants/index.ts +10 -1
- package/src/core/index.ts +5 -7
- package/src/data/messages/messages-protocol-v2.json +329 -323
- package/src/data-manager/DataManager.ts +4 -4
- package/src/data-manager/connectSettings.ts +6 -0
- package/src/device/Device.ts +86 -241
- package/src/device/DevicePool.ts +9 -9
- package/src/deviceProfile/buildDeviceFeatures.ts +368 -0
- package/src/deviceProfile/buildDeviceProfile.ts +101 -155
- package/src/deviceProfile/index.ts +4 -1
- package/src/protocols/protocol-v2/features.ts +14 -16
- package/src/types/api/getDeviceInfo.ts +2 -2
- package/src/types/api/getPassphraseState.ts +4 -4
- package/src/types/api/protocolV2.ts +2 -3
- package/src/types/device.ts +97 -34
- package/src/types/settings.ts +5 -0
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesUtils.ts +11 -17
- package/src/utils/deviceInfoUtils.ts +11 -29
- package/src/utils/deviceVersionUtils.ts +7 -25
- package/src/utils/findDefectiveBatchDevice.ts +6 -6
- package/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
- package/dist/deviceProfile/legacyFeaturesView.d.ts.map +0 -1
- package/src/deviceProfile/legacyFeaturesView.ts +0 -123
|
@@ -4,7 +4,6 @@ import { UI_REQUEST } from '../constants/ui-request';
|
|
|
4
4
|
import { fixVersion } from '../utils/deviceFeaturesUtils';
|
|
5
5
|
import { PROTOCOL_V2_DEVICE_INFO_REQUEST } from '../protocols/protocol-v2';
|
|
6
6
|
import { requestProtocolV2DeviceInfo } from '../protocols/protocol-v2/features';
|
|
7
|
-
import { buildProfileFromProtocolV2, buildProtocolV2GetFeaturesPayload } from '../deviceProfile';
|
|
8
7
|
import { BaseMethod } from './BaseMethod';
|
|
9
8
|
|
|
10
9
|
import type { OnekeyFeatures } from '../types';
|
|
@@ -91,23 +90,13 @@ export default class GetOnekeyFeatures extends BaseMethod {
|
|
|
91
90
|
async run() {
|
|
92
91
|
if (this.device.isProtocolV2()) {
|
|
93
92
|
// V2 没有 OnekeyGetFeatures 消息:
|
|
94
|
-
// 取完整 DevGetDeviceInfo(含 SE/hash/build_id
|
|
93
|
+
// 取完整 DevGetDeviceInfo(含 SE/hash/build_id)后刷新结构化 features 缓存。
|
|
95
94
|
const deviceInfo = await requestProtocolV2DeviceInfo({
|
|
96
95
|
commands: this.device.commands,
|
|
97
96
|
request: PROTOCOL_V2_DEVICE_INFO_REQUEST,
|
|
98
97
|
});
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
deviceInfo,
|
|
102
|
-
sources: ['deviceInfo'],
|
|
103
|
-
scope: 'verify',
|
|
104
|
-
fallbackSerialNo: this.device.originalDescriptor?.path,
|
|
105
|
-
}),
|
|
106
|
-
deviceInfo
|
|
107
|
-
);
|
|
108
|
-
return pickOnekeyFeatures(
|
|
109
|
-
buildProtocolV2GetFeaturesPayload(profile, deviceInfo) as OnekeyFeatures
|
|
110
|
-
);
|
|
98
|
+
const features = this.device.updateProtocolV2Features(deviceInfo);
|
|
99
|
+
return pickOnekeyFeatures(features as OnekeyFeatures);
|
|
111
100
|
}
|
|
112
101
|
|
|
113
102
|
const { message } = await this.device.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
@@ -25,10 +25,10 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
25
25
|
|
|
26
26
|
// refresh device info
|
|
27
27
|
return Promise.resolve({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
passphraseState: isProSeries || passphraseProtection === true ? passphraseState : undefined,
|
|
29
|
+
sessionId: newSession ?? features?.sessionId ?? undefined,
|
|
30
|
+
unlockedAttachPin: unlockedAttachPin ?? features?.unlockedAttachPin,
|
|
31
|
+
passphraseProtection,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { EDeviceType } from '@onekeyfe/hd-shared';
|
|
3
3
|
|
|
4
|
-
import { getDeviceType } from '../../utils';
|
|
4
|
+
import { getDeviceBootloaderVersion, getDeviceType } from '../../utils';
|
|
5
5
|
|
|
6
6
|
import type { Features, IVersionArray } from '../../types';
|
|
7
7
|
|
|
@@ -38,9 +38,10 @@ export function shouldUpdateBootloaderForClassicAndMini({
|
|
|
38
38
|
export function isEnteredManuallyBoot(features: Features, updateType: string) {
|
|
39
39
|
const deviceType = getDeviceType(features);
|
|
40
40
|
const isMini = deviceType === EDeviceType.Mini;
|
|
41
|
+
const bootloaderVersion = getDeviceBootloaderVersion(features).join('.');
|
|
41
42
|
const isBoot183ClassicUpBle =
|
|
42
43
|
updateType === 'firmware' &&
|
|
43
44
|
deviceType === EDeviceType.Classic &&
|
|
44
|
-
|
|
45
|
+
bootloaderVersion === '1.8.3';
|
|
45
46
|
return isMini || isBoot183ClassicUpBle;
|
|
46
47
|
}
|
|
@@ -41,7 +41,7 @@ export const getBinary = async ({
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (version && !semver.eq(releaseInfo.version.join('.'), version.join('.'))) {
|
|
44
|
-
const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.
|
|
44
|
+
const touchWithoutVersion = getDeviceType(features) === 'touch' && !features.firmwareVersion;
|
|
45
45
|
if (!touchWithoutVersion) {
|
|
46
46
|
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
|
|
47
47
|
}
|
|
@@ -12,7 +12,7 @@ export const getFirmwareReleaseInfo = (features: Features, firmwareType: EFirmwa
|
|
|
12
12
|
const firmwareStatus = DataManager.getFirmwareStatus(features, firmwareType);
|
|
13
13
|
const changelog = DataManager.getFirmwareChangelog(features, firmwareType);
|
|
14
14
|
const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
|
|
15
|
-
const bootloaderMode = !!features.
|
|
15
|
+
const bootloaderMode = !!features.bootloaderMode;
|
|
16
16
|
return {
|
|
17
17
|
status: firmwareStatus,
|
|
18
18
|
changelog,
|
|
@@ -25,7 +25,7 @@ export const getBleFirmwareReleaseInfo = (features: Features) => {
|
|
|
25
25
|
const firmwareStatus = DataManager.getBLEFirmwareStatus(features);
|
|
26
26
|
const changelog = DataManager.getBleFirmwareChangelog(features);
|
|
27
27
|
const release = DataManager.getBleFirmwareLatestRelease(features);
|
|
28
|
-
const bootloaderMode = !!features.
|
|
28
|
+
const bootloaderMode = !!features.bootloaderMode;
|
|
29
29
|
return {
|
|
30
30
|
status: firmwareStatus,
|
|
31
31
|
changelog,
|
|
@@ -52,7 +52,7 @@ export const getBootloaderReleaseInfo = ({
|
|
|
52
52
|
Object.prototype.hasOwnProperty.call(item, 'en-US')
|
|
53
53
|
);
|
|
54
54
|
|
|
55
|
-
const bootloaderMode = !!features.
|
|
55
|
+
const bootloaderMode = !!features.bootloaderMode;
|
|
56
56
|
|
|
57
57
|
let shouldUpdate = false;
|
|
58
58
|
|
|
@@ -9,6 +9,7 @@ import { DeviceModelToTypes } from '../../types';
|
|
|
9
9
|
import { bytesToHex } from '../helpers/hexUtils';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
11
|
import { DevicePool } from '../../device/DevicePool';
|
|
12
|
+
import { buildProtocolV1FeaturesPayload } from '../../deviceProfile';
|
|
12
13
|
|
|
13
14
|
import type { KnownDevice } from '../../types';
|
|
14
15
|
import type { TypedCall, TypedResponseMessage } from '../../device/DeviceCommands';
|
|
@@ -34,7 +35,7 @@ const isDeviceDisconnectedError = (error: unknown) => {
|
|
|
34
35
|
|
|
35
36
|
const postConfirmationMessage = (device: Device) => {
|
|
36
37
|
// only if firmware is already installed. fresh device does not require button confirmation
|
|
37
|
-
if (device.features?.
|
|
38
|
+
if (device.features?.firmwarePresent) {
|
|
38
39
|
device.emit(DEVICE.BUTTON, device, { code: 'ButtonRequest_FirmwareUpdate' });
|
|
39
40
|
}
|
|
40
41
|
};
|
|
@@ -109,7 +110,9 @@ export const uploadFirmware = async (
|
|
|
109
110
|
|
|
110
111
|
if (isFirmware && !isUpdateBootloader) {
|
|
111
112
|
const newFeatures = await typedCall('GetFeatures', 'Features', {});
|
|
112
|
-
const deviceBootloaderVersion = getDeviceBootloaderVersion(
|
|
113
|
+
const deviceBootloaderVersion = getDeviceBootloaderVersion(
|
|
114
|
+
buildProtocolV1FeaturesPayload(newFeatures.message, device.features)
|
|
115
|
+
).join('.');
|
|
113
116
|
const supportUpgradeFileHeader = semver.gte(deviceBootloaderVersion, '2.1.0');
|
|
114
117
|
Log.debug('supportUpgradeFileHeader:', supportUpgradeFileHeader);
|
|
115
118
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeRebootType } from './helpers';
|
|
3
3
|
|
|
4
4
|
import type { DeviceRebootParams } from './helpers';
|
|
5
5
|
|
|
@@ -16,8 +16,8 @@ export default class DeviceReboot extends BaseMethod<DeviceRebootParams> {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
async run() {
|
|
19
|
-
const res = await this.device.commands.typedCall('
|
|
20
|
-
reboot_type:
|
|
19
|
+
const res = await this.device.commands.typedCall('DevReboot', 'Success', {
|
|
20
|
+
reboot_type: normalizeRebootType(this.params.reboot_type ?? this.params.rebootType),
|
|
21
21
|
});
|
|
22
22
|
return Promise.resolve(res.message);
|
|
23
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DevRebootType
|
|
1
|
+
import { DevRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { invalidParameter, validateNonEmptyString } from '../helpers/filesystemValidation';
|
|
4
4
|
|
|
@@ -10,9 +10,7 @@ import type {
|
|
|
10
10
|
|
|
11
11
|
export type RebootTypeInput =
|
|
12
12
|
| DevRebootType
|
|
13
|
-
| DeviceRebootType
|
|
14
13
|
| keyof typeof DevRebootType
|
|
15
|
-
| keyof typeof DeviceRebootType
|
|
16
14
|
| string
|
|
17
15
|
| number;
|
|
18
16
|
|
|
@@ -56,17 +54,6 @@ const DEV_REBOOT_TYPES: Record<string, DevRebootType> = {
|
|
|
56
54
|
bootloader: DevRebootType.Bootloader,
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
60
|
-
Normal: DeviceRebootType.Normal,
|
|
61
|
-
normal: DeviceRebootType.Normal,
|
|
62
|
-
Romloader: DeviceRebootType.Romloader,
|
|
63
|
-
romloader: DeviceRebootType.Romloader,
|
|
64
|
-
Boardloader: DeviceRebootType.Romloader,
|
|
65
|
-
boardloader: DeviceRebootType.Romloader,
|
|
66
|
-
Bootloader: DeviceRebootType.Bootloader,
|
|
67
|
-
bootloader: DeviceRebootType.Bootloader,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
57
|
export const PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS: TransportCallOptions = {
|
|
71
58
|
intermediateTypes: ['DevFirmwareInstallProgress'],
|
|
72
59
|
};
|
|
@@ -143,18 +130,6 @@ export function normalizeRebootType(value: RebootTypeInput | undefined): DevRebo
|
|
|
143
130
|
return DevRebootType.Normal;
|
|
144
131
|
}
|
|
145
132
|
|
|
146
|
-
export function normalizeDeviceRebootType(
|
|
147
|
-
value: RebootTypeInput | undefined
|
|
148
|
-
): DeviceRebootType {
|
|
149
|
-
if (typeof value === 'number') return value;
|
|
150
|
-
if (typeof value === 'string') {
|
|
151
|
-
const numeric = Number(value);
|
|
152
|
-
if (Number.isFinite(numeric)) return numeric;
|
|
153
|
-
if (value in DEVICE_REBOOT_TYPES) return DEVICE_REBOOT_TYPES[value];
|
|
154
|
-
}
|
|
155
|
-
return DeviceRebootType.Normal;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
133
|
// 当前 firmware-pro2 子模块的 DevFirmwareTargetType 合法值。
|
|
159
134
|
const VALID_FIRMWARE_TARGET_IDS = new Set<number>([0, 1, 2, 3, 4, 5, 6, 10]);
|
|
160
135
|
|
package/src/constants/index.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export { safeThrowError } from './errors';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
Messages as PROTO,
|
|
4
|
+
ResourceType,
|
|
5
|
+
TonSignDataType,
|
|
6
|
+
TonWalletVersion,
|
|
7
|
+
} from '@onekeyfe/hd-transport';
|
|
8
|
+
export type {
|
|
9
|
+
HDNodeType,
|
|
10
|
+
Success as DeviceSuccess,
|
|
11
|
+
} from '@onekeyfe/hd-transport';
|
package/src/core/index.ts
CHANGED
|
@@ -56,17 +56,14 @@ import TransportManager from '../data-manager/TransportManager';
|
|
|
56
56
|
import DeviceConnector from '../device/DeviceConnector';
|
|
57
57
|
import RequestQueue from './RequestQueue';
|
|
58
58
|
import { getSynchronize } from '../utils/getSynchronize';
|
|
59
|
+
import { setProtocolV2DeviceInfoMock } from '../protocols/protocol-v2/features';
|
|
59
60
|
|
|
60
|
-
import type { ConnectSettings, KnownDevice } from '../types';
|
|
61
|
+
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
61
62
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
62
63
|
import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
63
64
|
import type { SdkTracingContext } from '../utils/tracing';
|
|
64
65
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
65
|
-
import type {
|
|
66
|
-
Features,
|
|
67
|
-
LowlevelTransportSharedPlugin,
|
|
68
|
-
OneKeyDeviceInfo,
|
|
69
|
-
} from '@onekeyfe/hd-transport';
|
|
66
|
+
import type { LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
70
67
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
71
68
|
|
|
72
69
|
const Log = getLogger(LoggerNames.Core);
|
|
@@ -1115,7 +1112,7 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
|
|
|
1115
1112
|
|
|
1116
1113
|
const passphraseProtection = method.device
|
|
1117
1114
|
? method.device.getCurrentPassphraseProtection()
|
|
1118
|
-
: features?.
|
|
1115
|
+
: features?.passphraseProtection;
|
|
1119
1116
|
|
|
1120
1117
|
if (passphraseProtection === true) {
|
|
1121
1118
|
const hasNoPassphraseState =
|
|
@@ -1442,6 +1439,7 @@ export const init = async (
|
|
|
1442
1439
|
try {
|
|
1443
1440
|
try {
|
|
1444
1441
|
await DataManager.load(settings);
|
|
1442
|
+
setProtocolV2DeviceInfoMock(settings.protocolV2DeviceInfoMockEnabled ?? false);
|
|
1445
1443
|
initTransport(Transport, plugin);
|
|
1446
1444
|
} catch {
|
|
1447
1445
|
Log.error('DataManager.load error');
|