@onekeyfe/hd-core 1.2.0-alpha.22 → 1.2.0-alpha.24
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__/DeviceCommands.test.ts +43 -8
- package/__tests__/connectSettings.test.ts +5 -47
- package/__tests__/device-lifecycle-events.test.ts +59 -0
- package/__tests__/device-settings.test.ts +1 -1
- package/__tests__/device-wallet-session-store.test.ts +41 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +30 -39
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +233 -111
- package/__tests__/protocol-v2-ping.test.ts +28 -0
- package/__tests__/protocol-v2.test.ts +513 -313
- package/__tests__/public-pro2-api-boundary.test.ts +22 -0
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +0 -11
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +3 -7
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +5 -21
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +1 -8
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +1 -5
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +0 -7
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +0 -7
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +0 -2
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +1 -9
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/Ping.d.ts +2 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +0 -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 +3 -2
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/events/device.d.ts +1 -0
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +1 -0
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +98 -278
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +876 -2647
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +2 -3
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/walletSession.d.ts +12 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +0 -3
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +0 -6
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -4
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +0 -69
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +4 -10
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +0 -12
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +4 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/settings.d.ts +0 -13
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/CheckAllFirmwareRelease.ts +3 -16
- package/src/api/FirmwareUpdateV2.ts +119 -284
- package/src/api/FirmwareUpdateV3.ts +55 -248
- package/src/api/FirmwareUpdateV4.ts +293 -751
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/OpenWalletSession.ts +23 -86
- package/src/api/device/DeviceUpdateBootloader.ts +6 -114
- package/src/api/device/DeviceWipe.ts +2 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +0 -50
- package/src/api/firmware/updateBootloader.ts +4 -19
- package/src/api/firmware/uploadFirmware.ts +22 -140
- package/src/api/index.ts +1 -0
- package/src/api/protocol-v2/Ping.ts +32 -1
- package/src/core/index.ts +40 -7
- package/src/data/messages/messages-protocol-v2.json +49 -56
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +0 -11
- package/src/device/Device.ts +29 -8
- package/src/device/DeviceCommands.ts +43 -151
- package/src/events/device.ts +1 -0
- package/src/events/logBlockEvent.ts +1 -15
- package/src/events/ui-request.ts +1 -0
- package/src/index.ts +0 -5
- package/src/inject.ts +4 -22
- package/src/lowLevelInject.ts +1 -5
- package/src/protocols/protocol-v2/deviceSession.ts +1 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +0 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +20 -3
- package/src/protocols/protocol-v2/walletSession.ts +57 -18
- package/src/topLevelInject.ts +1 -5
- package/src/types/api/checkAllFirmwareRelease.ts +0 -3
- package/src/types/api/deviceUpdateBootloader.ts +0 -6
- package/src/types/api/export.ts +0 -18
- package/src/types/api/firmwareUpdate.ts +0 -76
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/types/api/index.ts +3 -14
- package/src/types/api/openWalletSession.ts +0 -19
- package/src/types/api/protocolV2.ts +10 -0
- package/src/types/settings.ts +0 -13
- package/src/utils/deviceInfoUtils.ts +2 -3
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +0 -119
- package/__tests__/firmware-update/firmware-host-binding.test.ts +0 -70
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +0 -13
- package/__tests__/firmware-update/firmware-update-plan.test.ts +0 -326
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +0 -200
- package/__tests__/firmware-update/firmware-upload-source.test.ts +0 -70
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +0 -26
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareHostBinding.d.ts +0 -6
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +0 -3
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +0 -24
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +0 -25
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +0 -9
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePlan.d.ts +0 -27
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +0 -42
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +0 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +0 -278
- package/src/api/firmware/FirmwareHostBinding.ts +0 -100
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +0 -9
- package/src/api/firmware/FirmwareUpdatePlan.ts +0 -621
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +0 -378
- package/src/types/api/firmwareUpdateCapabilities.ts +0 -9
- package/src/types/api/firmwareUpdatePlan.ts +0 -36
- package/src/types/api/firmwareUpdatePreparedPlan.ts +0 -53
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ERRORS, HardwareErrorCode
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
2
|
|
|
3
3
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
4
4
|
import { getPassphraseStateWithRefreshDeviceInfo } from '../utils/deviceFeaturesUtils';
|
|
@@ -11,14 +11,20 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
async run() {
|
|
14
|
-
if (this.device.isProtocolV2()) {
|
|
15
|
-
throw createDeviceNotSupportMethodError(this.name, this.device.getCurrentFirmwareType());
|
|
16
|
-
}
|
|
17
14
|
if (!this.device.features) {
|
|
18
15
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
19
16
|
}
|
|
20
17
|
|
|
21
|
-
const
|
|
18
|
+
const isProtocolV2 = this.device.isProtocolV2();
|
|
19
|
+
const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
|
|
20
|
+
this.device,
|
|
21
|
+
isProtocolV2
|
|
22
|
+
? {
|
|
23
|
+
onlyMainPin: this.payload.useEmptyPassphrase === true,
|
|
24
|
+
initSession: this.payload.initSession === true,
|
|
25
|
+
}
|
|
26
|
+
: undefined
|
|
27
|
+
);
|
|
22
28
|
|
|
23
29
|
const passphraseProtection = this.device.getCurrentPassphraseProtection();
|
|
24
30
|
|
|
@@ -21,13 +21,6 @@ const requiredString = (value: unknown, name: string) => {
|
|
|
21
21
|
return value.trim();
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const optionalBoolean = (value: unknown, name: string) => {
|
|
25
|
-
if (value !== undefined && typeof value !== 'boolean') {
|
|
26
|
-
throw invalidParameter(`Parameter [${name}] must be a boolean.`);
|
|
27
|
-
}
|
|
28
|
-
return value;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
24
|
const wasResumed = (session: unknown) =>
|
|
32
25
|
!!session &&
|
|
33
26
|
typeof session === 'object' &&
|
|
@@ -53,72 +46,31 @@ const requireHiddenWalletResponse = (session: {
|
|
|
53
46
|
};
|
|
54
47
|
};
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
passphraseState: string;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const normalizeParams = (payload: Record<string, unknown>): NormalizedOpenWalletSessionParams => {
|
|
64
|
-
if (payload.mode !== undefined) {
|
|
65
|
-
if (
|
|
66
|
-
payload.mode !== 'standard' &&
|
|
67
|
-
payload.mode !== 'select-hidden' &&
|
|
68
|
-
payload.mode !== 'resume-hidden'
|
|
69
|
-
) {
|
|
70
|
-
throw invalidParameter(
|
|
71
|
-
'Parameter [mode] must be one of standard, select-hidden, or resume-hidden.'
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
if (payload.useEmptyPassphrase !== undefined || payload.initSession !== undefined) {
|
|
75
|
-
throw invalidParameter(
|
|
76
|
-
'Parameters [useEmptyPassphrase] and [initSession] cannot be used with [mode].'
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if (payload.mode === 'standard' || payload.mode === 'select-hidden') {
|
|
80
|
-
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
81
|
-
throw invalidParameter(
|
|
82
|
-
'Parameters [deviceId] and [passphraseState] are only allowed with mode [resume-hidden].'
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
return { mode: payload.mode };
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
mode: 'resume-hidden',
|
|
89
|
-
deviceId: requiredString(payload.deviceId, 'deviceId'),
|
|
90
|
-
passphraseState: requiredString(payload.passphraseState, 'passphraseState'),
|
|
91
|
-
};
|
|
49
|
+
const normalizeParams = (payload: Record<string, unknown>): OpenWalletSessionParams => {
|
|
50
|
+
if (payload.mode === undefined) {
|
|
51
|
+
throw invalidParameter('Parameter [mode] is required.');
|
|
92
52
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
53
|
+
if (
|
|
54
|
+
payload.mode !== 'standard' &&
|
|
55
|
+
payload.mode !== 'select-hidden' &&
|
|
56
|
+
payload.mode !== 'resume-hidden'
|
|
57
|
+
) {
|
|
58
|
+
throw invalidParameter(
|
|
59
|
+
'Parameter [mode] must be one of standard, select-hidden, or resume-hidden.'
|
|
60
|
+
);
|
|
98
61
|
}
|
|
99
|
-
if (initSession
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
payload.passphraseState === undefined
|
|
104
|
-
? undefined
|
|
105
|
-
: requiredString(payload.passphraseState, 'passphraseState');
|
|
106
|
-
return {
|
|
107
|
-
mode: 'select-hidden',
|
|
108
|
-
...(passphraseState
|
|
109
|
-
? {
|
|
110
|
-
legacySessionToClear: {
|
|
111
|
-
deviceId,
|
|
112
|
-
passphraseState,
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
: {}),
|
|
116
|
-
};
|
|
62
|
+
if (payload.useEmptyPassphrase !== undefined || payload.initSession !== undefined) {
|
|
63
|
+
throw invalidParameter(
|
|
64
|
+
'Legacy parameters [useEmptyPassphrase] and [initSession] are not supported by openWalletSession.'
|
|
65
|
+
);
|
|
117
66
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
67
|
+
if (payload.mode === 'standard' || payload.mode === 'select-hidden') {
|
|
68
|
+
if (payload.deviceId !== undefined || payload.passphraseState !== undefined) {
|
|
69
|
+
throw invalidParameter(
|
|
70
|
+
'Parameters [deviceId] and [passphraseState] are only allowed with mode [resume-hidden].'
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return { mode: payload.mode };
|
|
122
74
|
}
|
|
123
75
|
return {
|
|
124
76
|
mode: 'resume-hidden',
|
|
@@ -127,7 +79,7 @@ const normalizeParams = (payload: Record<string, unknown>): NormalizedOpenWallet
|
|
|
127
79
|
};
|
|
128
80
|
};
|
|
129
81
|
|
|
130
|
-
export default class OpenWalletSession extends BaseMethod<
|
|
82
|
+
export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParams> {
|
|
131
83
|
init() {
|
|
132
84
|
this.useDevicePassphraseState = false;
|
|
133
85
|
this.skipForceUpdateCheck = true;
|
|
@@ -139,33 +91,18 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
139
91
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
140
92
|
const state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
141
93
|
let currentDeviceId = state.identity.deviceId;
|
|
142
|
-
const { legacySessionToClear } = this.params;
|
|
143
94
|
const requireDeviceId = () => {
|
|
144
95
|
if (!currentDeviceId) {
|
|
145
96
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
146
97
|
}
|
|
147
98
|
return currentDeviceId;
|
|
148
99
|
};
|
|
149
|
-
const clearLegacySession = () => {
|
|
150
|
-
const deviceId = requireDeviceId();
|
|
151
|
-
if (
|
|
152
|
-
legacySessionToClear &&
|
|
153
|
-
(!legacySessionToClear.deviceId || legacySessionToClear.deviceId === deviceId)
|
|
154
|
-
) {
|
|
155
|
-
deviceWalletSessionStore.delete(deviceId, legacySessionToClear.passphraseState);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
100
|
const refreshProtocolV2DeviceId = async () => {
|
|
159
101
|
const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
160
102
|
currentDeviceId = refreshedState.identity.deviceId;
|
|
161
|
-
clearLegacySession();
|
|
162
103
|
return requireDeviceId();
|
|
163
104
|
};
|
|
164
105
|
|
|
165
|
-
if (!isProtocolV2) {
|
|
166
|
-
clearLegacySession();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
106
|
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
170
107
|
|
|
171
108
|
if (this.params.mode === 'standard') {
|
|
@@ -5,19 +5,15 @@ import { UI_REQUEST } from '../../constants/ui-request';
|
|
|
5
5
|
import { FirmwareUpdateTipMessage } from '../../events/ui-request';
|
|
6
6
|
import { FirmwareUpdateBaseMethod } from '../firmware/FirmwareUpdateBaseMethod';
|
|
7
7
|
import { getSysResourceBinary } from '../firmware/getBinary';
|
|
8
|
-
import { updateBootloader
|
|
8
|
+
import { updateBootloader } from '../firmware/uploadFirmware';
|
|
9
9
|
import { DeviceModelToTypes } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
-
import { checkBootloaderLength
|
|
12
|
-
import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
13
|
-
import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
|
|
14
|
-
import { assertFirmwareUpdatePreparedPlanBinding } from '../firmware/FirmwareUpdatePreparedPlan';
|
|
11
|
+
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
15
12
|
|
|
16
13
|
import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
17
14
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
18
15
|
import type { Device } from '../../device/Device';
|
|
19
16
|
import type { Features } from '../../types';
|
|
20
|
-
import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
21
17
|
|
|
22
18
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
23
19
|
init() {
|
|
@@ -47,68 +43,17 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
47
43
|
return true;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
|
|
51
|
-
const filePath = '0:boot/bootloader.bin';
|
|
52
|
-
|
|
53
|
-
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
54
|
-
await this.emmcCommonUpdateProcessFromSource({
|
|
55
|
-
source,
|
|
56
|
-
filePath,
|
|
57
|
-
});
|
|
58
|
-
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
59
|
-
await this.reboot(RebootType.Normal);
|
|
60
|
-
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
46
|
async updateTouchBootloader({
|
|
65
47
|
device,
|
|
66
48
|
features,
|
|
67
49
|
firmwareType,
|
|
68
|
-
binary: preparedBinary,
|
|
69
|
-
source: preparedSource,
|
|
70
50
|
}: {
|
|
71
51
|
device: Device;
|
|
72
52
|
features?: Features;
|
|
73
53
|
firmwareType: EFirmwareType;
|
|
74
|
-
binary?: ArrayBuffer;
|
|
75
|
-
source?: FirmwareByteSource;
|
|
76
54
|
}) {
|
|
77
|
-
|
|
78
|
-
if (!(await checkBootloaderSourceLength(preparedSource))) {
|
|
79
|
-
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
80
|
-
}
|
|
81
|
-
if (features && device.isBootloader()) {
|
|
82
|
-
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
83
|
-
const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
|
|
84
|
-
device,
|
|
85
|
-
preparedSource
|
|
86
|
-
);
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
if (features && !device.isBootloader()) {
|
|
90
|
-
await updateBootloaderFromSource(
|
|
91
|
-
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
92
|
-
this.postMessage,
|
|
93
|
-
device,
|
|
94
|
-
preparedSource
|
|
95
|
-
);
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let binary = preparedBinary;
|
|
55
|
+
let { binary } = this.payload;
|
|
101
56
|
if (!binary) {
|
|
102
|
-
if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
|
|
103
|
-
throw ERRORS.TypedError(
|
|
104
|
-
HardwareErrorCode.RuntimeError,
|
|
105
|
-
'Bootloader must be prepared by the external firmware host',
|
|
106
|
-
{
|
|
107
|
-
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
108
|
-
artifactName: 'bootloader',
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
57
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
113
58
|
const resourceUrl = features
|
|
114
59
|
? DataManager.getBootloaderResource(features, firmwareType)
|
|
@@ -123,7 +68,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
123
68
|
}
|
|
124
69
|
}
|
|
125
70
|
|
|
126
|
-
if (!
|
|
71
|
+
if (!checkBootloaderLength(binary)) {
|
|
127
72
|
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
128
73
|
}
|
|
129
74
|
|
|
@@ -131,8 +76,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
131
76
|
if (features && device.isBootloader()) {
|
|
132
77
|
// Use emmcFileWrite + reboot logic for bootloader mode
|
|
133
78
|
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
134
|
-
|
|
135
|
-
return result;
|
|
79
|
+
return this.updateBootloaderWithEmmcFileWrite(device, binary);
|
|
136
80
|
}
|
|
137
81
|
|
|
138
82
|
if (features && !device.isBootloader()) {
|
|
@@ -152,65 +96,13 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
152
96
|
const { features } = device;
|
|
153
97
|
|
|
154
98
|
const payload = this.payload as DeviceUpdateBootloaderParams;
|
|
155
|
-
const hostBinding = payload.artifact
|
|
156
|
-
? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
|
|
157
|
-
: undefined;
|
|
158
|
-
const executionParams = {
|
|
159
|
-
...payload,
|
|
160
|
-
artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
|
|
161
|
-
};
|
|
162
|
-
if (payload.artifact) {
|
|
163
|
-
assertFirmwareUpdatePreparedPlanBinding({
|
|
164
|
-
preparedPlan: payload.preparedPlan,
|
|
165
|
-
executor: 'v2',
|
|
166
|
-
scopeTargets: ['bootloader'],
|
|
167
|
-
bindings: [
|
|
168
|
-
{
|
|
169
|
-
target: 'bootloader',
|
|
170
|
-
artifact: payload.artifact,
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
});
|
|
174
|
-
const source = await openFirmwareByteSource({
|
|
175
|
-
artifact: payload.artifact,
|
|
176
|
-
reader: executionParams.artifactReader,
|
|
177
|
-
});
|
|
178
|
-
if (!source) {
|
|
179
|
-
throw ERRORS.TypedError(
|
|
180
|
-
HardwareErrorCode.RuntimeError,
|
|
181
|
-
'Bootloader artifact is not prepared'
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const deviceType = device.getCurrentDeviceType();
|
|
186
|
-
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
187
|
-
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
188
|
-
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
189
|
-
return await this.updateTouchBootloader({
|
|
190
|
-
device,
|
|
191
|
-
features,
|
|
192
|
-
firmwareType,
|
|
193
|
-
source,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
} finally {
|
|
198
|
-
await source.close();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
99
|
|
|
202
|
-
const { binary } = payload;
|
|
203
100
|
const deviceType = device.getCurrentDeviceType();
|
|
204
101
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
205
102
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
206
103
|
|
|
207
104
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
208
|
-
return this.updateTouchBootloader({
|
|
209
|
-
device,
|
|
210
|
-
features,
|
|
211
|
-
firmwareType,
|
|
212
|
-
binary,
|
|
213
|
-
});
|
|
105
|
+
return this.updateTouchBootloader({ device, features, firmwareType });
|
|
214
106
|
}
|
|
215
107
|
|
|
216
108
|
return Promise.resolve(true);
|
|
@@ -24,10 +24,12 @@ export default class DeviceWipe extends BaseMethod<WipeDevice> {
|
|
|
24
24
|
const res = await this.device.commands.typedCall('DeviceSettingsPageShow', 'Success', {
|
|
25
25
|
page: DeviceSettingsPage.DeviceReset,
|
|
26
26
|
});
|
|
27
|
+
this.device.invalidateAfterWipe();
|
|
27
28
|
return Promise.resolve(res.message);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
const res = await this.device.commands.typedCall('WipeDevice', 'Success');
|
|
32
|
+
this.device.invalidateAfterWipe();
|
|
31
33
|
|
|
32
34
|
return Promise.resolve(res.message);
|
|
33
35
|
}
|
|
@@ -14,7 +14,6 @@ import { DataManager } from '../../data-manager';
|
|
|
14
14
|
import { BaseMethod } from '../BaseMethod';
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
16
|
import { createFirmwareProgressThrottle } from './progressThrottle';
|
|
17
|
-
import { writeFirmwareByteSource } from './FirmwareArtifactSource';
|
|
18
17
|
|
|
19
18
|
import type {
|
|
20
19
|
IFirmwareUpdateProgressType,
|
|
@@ -25,7 +24,6 @@ import type { RebootType } from '@onekeyfe/hd-transport';
|
|
|
25
24
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
26
25
|
import type { KnownDevice } from '../../types';
|
|
27
26
|
import type { TypedResponseMessage } from '../../device/DeviceCommands';
|
|
28
|
-
import type { FirmwareByteSource } from './FirmwareArtifactSource';
|
|
29
27
|
|
|
30
28
|
const Log = getLogger(LoggerNames.Method);
|
|
31
29
|
const SESSION_ERROR = 'session not found';
|
|
@@ -389,54 +387,6 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
389
387
|
return totalSize !== undefined ? (processedSize ?? 0) + payload.byteLength : 0;
|
|
390
388
|
}
|
|
391
389
|
|
|
392
|
-
async emmcCommonUpdateProcessFromSource({
|
|
393
|
-
source,
|
|
394
|
-
filePath,
|
|
395
|
-
processedSize,
|
|
396
|
-
totalSize,
|
|
397
|
-
}: {
|
|
398
|
-
source: FirmwareByteSource;
|
|
399
|
-
filePath: string;
|
|
400
|
-
processedSize?: number;
|
|
401
|
-
totalSize?: number;
|
|
402
|
-
}) {
|
|
403
|
-
if (!filePath.startsWith('0:')) {
|
|
404
|
-
throw new Error('filePath must start with 0:');
|
|
405
|
-
}
|
|
406
|
-
const env = DataManager.getSettings('env');
|
|
407
|
-
const chunkSize = 1024 * (DataManager.isBleConnect(env) ? 16 : 128);
|
|
408
|
-
|
|
409
|
-
await writeFirmwareByteSource({
|
|
410
|
-
source,
|
|
411
|
-
chunkSize,
|
|
412
|
-
write: async ({ data, sourceOffset, length, first }) => {
|
|
413
|
-
const progress =
|
|
414
|
-
totalSize !== undefined && processedSize !== undefined
|
|
415
|
-
? Math.min(Math.ceil(((processedSize + sourceOffset + length) / totalSize) * 100), 99)
|
|
416
|
-
: Math.min(Math.ceil(((sourceOffset + length) / source.size) * 100), 99);
|
|
417
|
-
const writeRes = await this.emmcFileWriteWithRetry(
|
|
418
|
-
filePath,
|
|
419
|
-
length,
|
|
420
|
-
sourceOffset,
|
|
421
|
-
data,
|
|
422
|
-
first,
|
|
423
|
-
progress
|
|
424
|
-
);
|
|
425
|
-
if (!writeRes) {
|
|
426
|
-
throw ERRORS.TypedError(
|
|
427
|
-
HardwareErrorCode.EmmcFileWriteFirmwareError,
|
|
428
|
-
'transfer data error'
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
const processedBytes = Number(writeRes.message.processed_byte);
|
|
432
|
-
this.postProgressMessage(progress, 'transferData');
|
|
433
|
-
return Number.isFinite(processedBytes) ? processedBytes : length;
|
|
434
|
-
},
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
return totalSize !== undefined ? (processedSize ?? 0) + source.size : 0;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
390
|
async emmcFileWriteWithRetry(
|
|
441
391
|
filePath: string,
|
|
442
392
|
chunkLength: number,
|
|
@@ -8,7 +8,6 @@ import { shouldUpdateBootloaderForClassicAndMini } from './bootloaderHelper';
|
|
|
8
8
|
|
|
9
9
|
import type { Features } from '../../types';
|
|
10
10
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
11
|
-
import type { FirmwareByteSource } from './FirmwareArtifactSource';
|
|
12
11
|
|
|
13
12
|
export function checkNeedUpdateBootForTouch(features: Features, firmwareType: EFirmwareType) {
|
|
14
13
|
const deviceType = getDeviceType(features);
|
|
@@ -63,7 +62,8 @@ export function checkNeedUpdateBootForClassicAndMini({
|
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
const INIT_DATA_CHUNK_SIZE = 16 * 1024;
|
|
66
|
-
|
|
65
|
+
export function checkBootloaderLength(data: ArrayBuffer) {
|
|
66
|
+
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
|
|
67
67
|
const buffer = ByteBuffer.wrap(chunk, undefined, undefined, true);
|
|
68
68
|
buffer.LE();
|
|
69
69
|
// byte 'O', 'K', 'T', 'B'
|
|
@@ -77,21 +77,6 @@ const readBootloaderLength = (chunk: Uint8Array) => {
|
|
|
77
77
|
buffer.readUint32();
|
|
78
78
|
// codelen
|
|
79
79
|
const codelen = buffer.readUint32();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
export function checkBootloaderLength(data: ArrayBuffer) {
|
|
84
|
-
if (data.byteLength < 16) {
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
|
|
88
|
-
return readBootloaderLength(chunk) === data.byteLength;
|
|
80
|
+
const bootloaderLength = hdrlen + codelen;
|
|
81
|
+
return bootloaderLength === data.byteLength;
|
|
89
82
|
}
|
|
90
|
-
|
|
91
|
-
export const checkBootloaderSourceLength = async (source: FirmwareByteSource) => {
|
|
92
|
-
if (source.size < 16) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
const chunk = new Uint8Array(await source.readAt(0, Math.min(INIT_DATA_CHUNK_SIZE, source.size)));
|
|
96
|
-
return readBootloaderLength(chunk) === source.size;
|
|
97
|
-
};
|