@onekeyfe/hd-core 1.2.0-alpha.0 → 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 +1930 -765
- 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/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +26 -5
- 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/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +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/bootloaderHelper.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/firmware/uploadFirmware.d.ts.map +1 -1
- 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 -19
- 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/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/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 +17 -18
- 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 +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 +657 -539
- package/dist/index.js +2579 -2161
- 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 +4 -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/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 +88 -8
- 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 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.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/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/ClearSessionCache.ts +28 -0
- package/src/api/FileRead.ts +16 -3
- package/src/api/FileWrite.ts +14 -1
- package/src/api/FirmwareUpdateV2.ts +9 -2
- package/src/api/FirmwareUpdateV3.ts +2 -1
- package/src/api/FirmwareUpdateV4.ts +1089 -285
- package/src/api/GetDeviceInfo.ts +6 -13
- package/src/api/GetOnekeyFeatures.ts +3 -14
- package/src/api/GetPassphraseState.ts +7 -4
- 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/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/uploadFirmware.ts +5 -2
- 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 +2 -2
- 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 +58 -59
- 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/constants/index.ts +10 -1
- package/src/core/index.ts +22 -10
- package/src/data/messages/messages-protocol-v2.json +992 -1420
- package/src/data/messages/messages.json +8 -0
- package/src/data-manager/DataManager.ts +11 -4
- package/src/data-manager/connectSettings.ts +4 -0
- package/src/device/Device.ts +158 -294
- package/src/device/DevicePool.ts +9 -9
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +365 -0
- package/src/deviceProfile/buildDeviceProfile.ts +165 -200
- package/src/deviceProfile/index.ts +4 -1
- package/src/inject.ts +13 -16
- package/src/protocols/protocol-v2/features.ts +28 -67
- 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 +4 -2
- package/src/types/api/getPassphraseState.ts +4 -4
- package/src/types/api/index.ts +17 -20
- package/src/types/api/protocolV2.ts +35 -40
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +98 -34
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -30
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesUtils.ts +54 -29
- package/src/utils/deviceInfoUtils.ts +11 -29
- package/src/utils/deviceVersionUtils.ts +7 -25
- package/src/utils/findDefectiveBatchDevice.ts +6 -6
- 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/dist/deviceProfile/legacyFeaturesView.d.ts +0 -5
- package/dist/deviceProfile/legacyFeaturesView.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
- package/src/deviceProfile/legacyFeaturesView.ts +0 -123
package/src/api/GetDeviceInfo.ts
CHANGED
|
@@ -57,7 +57,7 @@ function shouldReadOnekeyFeatures(params: GetDeviceInfoParams) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
function supportOnekeyFeatures(features?: Features) {
|
|
60
|
-
if (!features || features.
|
|
60
|
+
if (!features || features.bootloaderMode) return false;
|
|
61
61
|
|
|
62
62
|
const deviceType = getDeviceType(features);
|
|
63
63
|
return ![
|
|
@@ -109,14 +109,8 @@ export default class GetDeviceInfo extends BaseMethod<GetDeviceInfoParams> {
|
|
|
109
109
|
sources,
|
|
110
110
|
scope: this.params.scope,
|
|
111
111
|
includeRaw: this.params.includeRaw,
|
|
112
|
-
fallbackSerialNo: this.device.originalDescriptor?.path,
|
|
113
112
|
});
|
|
114
|
-
|
|
115
|
-
if (typeof this.device.applyProfileUpdate === 'function') {
|
|
116
|
-
this.device.applyProfileUpdate(profile, protocolV2DeviceInfo);
|
|
117
|
-
} else {
|
|
118
|
-
this.device.updateProfile?.(profile);
|
|
119
|
-
}
|
|
113
|
+
this.device.updateProtocolV2Features(protocolV2DeviceInfo);
|
|
120
114
|
return profile;
|
|
121
115
|
}
|
|
122
116
|
|
|
@@ -127,26 +121,25 @@ export default class GetDeviceInfo extends BaseMethod<GetDeviceInfoParams> {
|
|
|
127
121
|
|
|
128
122
|
const sources: DeviceInfoSource[] = ['features'];
|
|
129
123
|
const { features } = this.device;
|
|
130
|
-
let
|
|
124
|
+
let protocolV1OneKeyFeatures: OnekeyFeatures | undefined;
|
|
131
125
|
|
|
132
126
|
if (shouldReadOnekeyFeatures(this.params) && supportOnekeyFeatures(features)) {
|
|
133
127
|
const { message } = await this.device.commands.typedCall(
|
|
134
128
|
'OnekeyGetFeatures',
|
|
135
129
|
'OnekeyFeatures'
|
|
136
130
|
);
|
|
137
|
-
|
|
138
|
-
sources.push('
|
|
131
|
+
protocolV1OneKeyFeatures = normalizeOnekeyFeatures(message);
|
|
132
|
+
sources.push('protocolV1OneKeyFeatures');
|
|
139
133
|
}
|
|
140
134
|
|
|
141
135
|
const profile = buildProfileFromProtocolV1({
|
|
142
136
|
protocol: 'V1',
|
|
143
137
|
features,
|
|
144
|
-
|
|
138
|
+
protocolV1OneKeyFeatures,
|
|
145
139
|
sources,
|
|
146
140
|
scope: this.params.scope,
|
|
147
141
|
includeRaw: this.params.includeRaw,
|
|
148
142
|
});
|
|
149
|
-
this.device.updateProfile?.(profile);
|
|
150
143
|
return profile;
|
|
151
144
|
}
|
|
152
145
|
}
|
|
@@ -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
|
-
// 取完整
|
|
93
|
+
// 取完整 DeviceInfoGet(含 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');
|
|
@@ -16,6 +16,7 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
16
16
|
expectPassphraseState: this.payload.passphraseState,
|
|
17
17
|
onlyMainPin: this.payload.useEmptyPassphrase,
|
|
18
18
|
allowCreateAttachPin: this.payload.allowCreateAttachPin,
|
|
19
|
+
initSession: this.payload.initSession,
|
|
19
20
|
});
|
|
20
21
|
|
|
21
22
|
const { features } = this.device;
|
|
@@ -25,10 +26,12 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
25
26
|
|
|
26
27
|
// refresh device info
|
|
27
28
|
return Promise.resolve({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
passphraseState: isProSeries || passphraseProtection === true ? passphraseState : undefined,
|
|
30
|
+
sessionId: this.payload.initSession
|
|
31
|
+
? newSession ?? undefined
|
|
32
|
+
: newSession ?? features?.sessionId ?? undefined,
|
|
33
|
+
unlockedAttachPin: unlockedAttachPin ?? features?.unlockedAttachPin,
|
|
34
|
+
passphraseProtection,
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
37
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBoardloader extends BaseMethod<RebootToBoardl
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 submodule firmware uses
|
|
26
|
+
// Protocol V2 submodule firmware uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.isProtocolV2()) {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Romloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceRebootType } from '@onekeyfe/hd-transport';
|
|
2
2
|
|
|
3
3
|
import { BaseMethod } from '../BaseMethod';
|
|
4
4
|
|
|
@@ -23,10 +23,10 @@ export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloa
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
async run() {
|
|
26
|
-
// Protocol V2 submodule firmware uses
|
|
26
|
+
// Protocol V2 submodule firmware uses DeviceReboot with reboot_type enum.
|
|
27
27
|
if (this.device.isProtocolV2()) {
|
|
28
|
-
const res = await this.device.commands.typedCall('
|
|
29
|
-
reboot_type:
|
|
28
|
+
const res = await this.device.commands.typedCall('DeviceReboot', 'Success', {
|
|
29
|
+
reboot_type: DeviceRebootType.Bootloader,
|
|
30
30
|
});
|
|
31
31
|
return Promise.resolve(res.message);
|
|
32
32
|
}
|
|
@@ -13,6 +13,7 @@ import { DeviceModelToTypes } from '../../types';
|
|
|
13
13
|
import { DataManager } from '../../data-manager';
|
|
14
14
|
import { BaseMethod } from '../BaseMethod';
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
|
+
import { createFirmwareProgressThrottle } from './progressThrottle';
|
|
16
17
|
|
|
17
18
|
import type {
|
|
18
19
|
IFirmwareUpdateProgressType,
|
|
@@ -40,6 +41,8 @@ const isDeviceDisconnectedError = (error: unknown) => {
|
|
|
40
41
|
export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
41
42
|
checkPromise: Deferred<any> | null = null;
|
|
42
43
|
|
|
44
|
+
private shouldPostFirmwareProgress = createFirmwareProgressThrottle();
|
|
45
|
+
|
|
43
46
|
init(): void {}
|
|
44
47
|
|
|
45
48
|
run(): Promise<any> {
|
|
@@ -83,6 +86,10 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
83
86
|
* @param progress Post the percentage of the progress
|
|
84
87
|
*/
|
|
85
88
|
postProgressMessage = (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
89
|
+
if (!this.shouldPostFirmwareProgress(progress, progressType)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
86
93
|
this.postMessage(
|
|
87
94
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
95
|
device: this.device.toMessageObject() as KnownDevice,
|
|
@@ -138,6 +145,8 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
138
145
|
// check device goto bootloader mode
|
|
139
146
|
let isFirstCheck = true;
|
|
140
147
|
let checkCount = 0;
|
|
148
|
+
let hasPromptedWebDevice = false;
|
|
149
|
+
let isPromptingWebDevice = false;
|
|
141
150
|
// eslint-disable-next-line prefer-const
|
|
142
151
|
let timeoutTimer: ReturnType<typeof setTimeout> | undefined;
|
|
143
152
|
|
|
@@ -158,23 +167,28 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
158
167
|
if (
|
|
159
168
|
checkCount > 4 &&
|
|
160
169
|
DataManager.isBrowserWebUsb(DataManager.getSettings('env')) &&
|
|
161
|
-
!this.payload.skipWebDevicePrompt
|
|
170
|
+
!this.payload.skipWebDevicePrompt &&
|
|
171
|
+
!hasPromptedWebDevice &&
|
|
172
|
+
!isPromptingWebDevice
|
|
162
173
|
) {
|
|
163
|
-
|
|
164
|
-
clearTimeout(timeoutTimer);
|
|
165
|
-
|
|
174
|
+
isPromptingWebDevice = true;
|
|
166
175
|
try {
|
|
167
176
|
this.postTipMessage(FirmwareUpdateTipMessage.SelectDeviceInBootloaderForWebDevice);
|
|
168
177
|
const confirmed = await this._promptDeviceInBootloaderForWebDevice();
|
|
178
|
+
hasPromptedWebDevice = true;
|
|
169
179
|
if (confirmed) {
|
|
170
180
|
await this._checkDeviceInBootloaderMode(connectId, intervalTimer, timeoutTimer);
|
|
171
181
|
}
|
|
172
182
|
} catch (e) {
|
|
183
|
+
clearInterval(intervalTimer);
|
|
184
|
+
clearTimeout(timeoutTimer);
|
|
173
185
|
Log.log(
|
|
174
186
|
'FirmwareUpdateBaseMethod [checkDeviceToBootloader] _promptDeviceInBootloaderForWebDevice failed: ',
|
|
175
187
|
e
|
|
176
188
|
);
|
|
177
189
|
this.checkPromise?.reject(e);
|
|
190
|
+
} finally {
|
|
191
|
+
isPromptingWebDevice = false;
|
|
178
192
|
}
|
|
179
193
|
return;
|
|
180
194
|
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IFirmwareUpdateProgressType } from '../../events/ui-request';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS = 250;
|
|
4
|
+
|
|
5
|
+
type FirmwareProgressThrottleState = {
|
|
6
|
+
lastEmittedAt: number;
|
|
7
|
+
lastProgress?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createFirmwareProgressThrottle = (
|
|
11
|
+
intervalMs = DEFAULT_FIRMWARE_PROGRESS_INTERVAL_MS
|
|
12
|
+
) => {
|
|
13
|
+
const stateByType = new Map<IFirmwareUpdateProgressType, FirmwareProgressThrottleState>();
|
|
14
|
+
|
|
15
|
+
return (progress: number, progressType: IFirmwareUpdateProgressType) => {
|
|
16
|
+
if (progressType !== 'transferData') {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const normalizedProgress = Math.max(0, Math.min(100, Math.floor(progress)));
|
|
21
|
+
if (normalizedProgress === 0 || normalizedProgress === 100) {
|
|
22
|
+
stateByType.set(progressType, {
|
|
23
|
+
lastEmittedAt: Date.now(),
|
|
24
|
+
lastProgress: normalizedProgress,
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
const state = stateByType.get(progressType);
|
|
31
|
+
if (
|
|
32
|
+
state &&
|
|
33
|
+
(state.lastProgress === normalizedProgress || now - state.lastEmittedAt < intervalMs)
|
|
34
|
+
) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
stateByType.set(progressType, {
|
|
39
|
+
lastEmittedAt: now,
|
|
40
|
+
lastProgress: normalizedProgress,
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
@@ -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
|
|
package/src/api/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as getDeviceInfo } from './GetDeviceInfo';
|
|
|
7
7
|
export { default as getOnekeyFeatures } from './GetOnekeyFeatures';
|
|
8
8
|
export { default as getPassphraseState } from './GetPassphraseState';
|
|
9
9
|
export { default as getLogs } from './GetLogs';
|
|
10
|
+
export { default as clearSessionCache } from './ClearSessionCache';
|
|
10
11
|
export { default as checkFirmwareRelease } from './CheckFirmwareRelease';
|
|
11
12
|
export { default as checkBLEFirmwareRelease } from './CheckBLEFirmwareRelease';
|
|
12
13
|
export { default as checkBridgeStatus } from './CheckBridgeStatus';
|
|
@@ -43,20 +44,17 @@ export { default as firmwareUpdateV4 } from './FirmwareUpdateV4';
|
|
|
43
44
|
export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
44
45
|
|
|
45
46
|
// File system & device control API (Protocol V2 only)
|
|
46
|
-
export { default as
|
|
47
|
+
export { default as protocolInfoRequest } from './protocol-v2/ProtocolInfoRequest';
|
|
47
48
|
export { default as ping } from './protocol-v2/Ping';
|
|
48
49
|
export { default as deviceReboot } from './protocol-v2/DeviceReboot';
|
|
49
|
-
export { default as
|
|
50
|
-
export { default as
|
|
50
|
+
export { default as deviceInfoGet } from './protocol-v2/DeviceInfoGet';
|
|
51
|
+
export { default as deviceStatusGet } from './protocol-v2/DeviceStatusGet';
|
|
52
|
+
export { default as deviceSessionGet } from './protocol-v2/DeviceSessionGet';
|
|
51
53
|
export { default as deviceFirmwareUpdate } from './protocol-v2/DeviceFirmwareUpdate';
|
|
52
54
|
export { default as deviceGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
53
|
-
export { default as
|
|
54
|
-
export { default as
|
|
55
|
-
export { default as
|
|
56
|
-
export { default as devGetFirmwareUpdateStatus } from './protocol-v2/DeviceGetFirmwareUpdateStatus';
|
|
57
|
-
export { default as factoryDeviceInfoSettings } from './protocol-v2/FactoryDeviceInfoSettings';
|
|
58
|
-
export { default as factoryGetDeviceInfo } from './protocol-v2/FactoryGetDeviceInfo';
|
|
59
|
-
export { default as filesystemFixPermission } from './protocol-v2/FilesystemFixPermission';
|
|
55
|
+
export { default as deviceFactoryInfoSet } from './protocol-v2/DeviceFactoryInfoSet';
|
|
56
|
+
export { default as deviceFactoryInfoGet } from './protocol-v2/DeviceFactoryInfoGet';
|
|
57
|
+
export { default as filesystemPermissionFix } from './protocol-v2/FilesystemPermissionFix';
|
|
60
58
|
export { default as filesystemFormat } from './protocol-v2/FilesystemFormat';
|
|
61
59
|
export { default as filesystemDiskControl } from './protocol-v2/FilesystemDiskControl';
|
|
62
60
|
export { default as fileRead } from './FileRead';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
2
|
|
|
3
|
-
export default class
|
|
3
|
+
export default class DeviceFactoryInfoGet extends BaseMethod {
|
|
4
4
|
init() {
|
|
5
5
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
6
|
this.requireProtocolV2 = true;
|
|
@@ -11,8 +11,8 @@ export default class FactoryGetDeviceInfo extends BaseMethod {
|
|
|
11
11
|
|
|
12
12
|
async run() {
|
|
13
13
|
const res = await this.device.commands.typedCall(
|
|
14
|
-
'
|
|
15
|
-
'
|
|
14
|
+
'DeviceFactoryInfoGet',
|
|
15
|
+
'DeviceFactoryInfo',
|
|
16
16
|
{}
|
|
17
17
|
);
|
|
18
18
|
return Promise.resolve(res.message);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
|
|
3
|
+
import type { DeviceFactoryInfoSetParams } from './helpers';
|
|
4
|
+
|
|
5
|
+
export default class DeviceFactoryInfoSet extends BaseMethod<DeviceFactoryInfoSetParams> {
|
|
6
|
+
init() {
|
|
7
|
+
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
8
|
+
this.requireProtocolV2 = true;
|
|
9
|
+
this.skipForceUpdateCheck = true;
|
|
10
|
+
this.useDevicePassphraseState = false;
|
|
11
|
+
this.params = {
|
|
12
|
+
version: this.payload.version,
|
|
13
|
+
serial_number: this.payload.serial_number,
|
|
14
|
+
burn_in_completed: this.payload.burn_in_completed,
|
|
15
|
+
factory_test_completed: this.payload.factory_test_completed,
|
|
16
|
+
manufacture_time: this.payload.manufacture_time,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async run() {
|
|
21
|
+
const res = await this.device.commands.typedCall('DeviceFactoryInfoSet', 'Success', {
|
|
22
|
+
info: {
|
|
23
|
+
version: this.params.version,
|
|
24
|
+
serial_number: this.params.serial_number,
|
|
25
|
+
burn_in_completed: this.params.burn_in_completed,
|
|
26
|
+
factory_test_completed: this.params.factory_test_completed,
|
|
27
|
+
manufacture_time: this.params.manufacture_time,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
return Promise.resolve(res.message);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -29,7 +29,7 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
29
29
|
const targets = normalizeFirmwareTargets(this.params);
|
|
30
30
|
try {
|
|
31
31
|
const res = await this.device.commands.typedCall(
|
|
32
|
-
'
|
|
32
|
+
'DeviceFirmwareUpdateRequest',
|
|
33
33
|
PROTOCOL_V2_FIRMWARE_UPDATE_RESPONSE_TYPES,
|
|
34
34
|
{
|
|
35
35
|
targets,
|
|
@@ -37,13 +37,11 @@ export default class DeviceFirmwareUpdate extends BaseMethod<DeviceFirmwareUpdat
|
|
|
37
37
|
{
|
|
38
38
|
...PROTOCOL_V2_FIRMWARE_UPDATE_OPTIONS,
|
|
39
39
|
onIntermediateResponse: (response: MessageFromOneKey) => {
|
|
40
|
-
if (response.type !== '
|
|
41
|
-
const progress = Number(response.message?.progress);
|
|
42
|
-
if (!Number.isFinite(progress)) return;
|
|
40
|
+
if (response.type !== 'DeviceFirmwareUpdateStatus') return;
|
|
43
41
|
this.postMessage(
|
|
44
42
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
45
43
|
device: this.device.toMessageObject() as KnownDevice,
|
|
46
|
-
progress:
|
|
44
|
+
progress: 99,
|
|
47
45
|
progressType: 'installingFirmware',
|
|
48
46
|
})
|
|
49
47
|
);
|
|
@@ -1,19 +1,53 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
+
import { invalidParameter } from '../helpers/filesystemValidation';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import type { DeviceFirmwareUpdateStatusGetParams } from './helpers';
|
|
5
|
+
import type { DeviceFirmwareUpdateRecordFields } from '@onekeyfe/hd-transport';
|
|
6
|
+
|
|
7
|
+
const DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS = ['status', 'payload_version', 'path'] as const;
|
|
8
|
+
|
|
9
|
+
function normalizeStatusFields(
|
|
10
|
+
fields: DeviceFirmwareUpdateStatusGetParams['fields']
|
|
11
|
+
): DeviceFirmwareUpdateRecordFields | undefined {
|
|
12
|
+
if (fields === undefined || fields === null) return undefined;
|
|
13
|
+
if (typeof fields !== 'object' || Array.isArray(fields)) {
|
|
14
|
+
throw invalidParameter('Parameter [fields] must be an object.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const unknownField = Object.keys(fields).find(
|
|
18
|
+
field => !DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS.includes(field as any)
|
|
19
|
+
);
|
|
20
|
+
if (unknownField) {
|
|
21
|
+
throw invalidParameter(`Unsupported firmware update status field: ${unknownField}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalized: DeviceFirmwareUpdateRecordFields = {};
|
|
25
|
+
for (const field of DEVICE_FIRMWARE_UPDATE_STATUS_FIELDS) {
|
|
26
|
+
const value = fields[field];
|
|
27
|
+
if (value === undefined) continue;
|
|
28
|
+
if (typeof value !== 'boolean') {
|
|
29
|
+
throw invalidParameter(`Parameter [fields.${field}] must be a boolean.`);
|
|
30
|
+
}
|
|
31
|
+
normalized[field] = value;
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default class DeviceGetFirmwareUpdateStatus extends BaseMethod<DeviceFirmwareUpdateStatusGetParams> {
|
|
4
37
|
init() {
|
|
5
38
|
// Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
|
|
6
39
|
this.requireProtocolV2 = true;
|
|
7
40
|
this.skipForceUpdateCheck = true;
|
|
8
41
|
this.useDevicePassphraseState = false;
|
|
9
|
-
|
|
42
|
+
const fields = normalizeStatusFields(this.payload.fields);
|
|
43
|
+
this.params = fields ? { fields } : {};
|
|
10
44
|
}
|
|
11
45
|
|
|
12
46
|
async run() {
|
|
13
47
|
const res = await this.device.commands.typedCall(
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
|
|
48
|
+
'DeviceFirmwareUpdateStatusGet',
|
|
49
|
+
'DeviceFirmwareUpdateStatus',
|
|
50
|
+
this.params
|
|
17
51
|
);
|
|
18
52
|
return Promise.resolve(res.message);
|
|
19
53
|
}
|