@onekeyfe/hd-core 1.2.0-alpha.21 → 1.2.0-alpha.23
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 +85 -0
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-identity.test.ts +24 -2
- package/__tests__/device-settings.test.ts +2 -2
- package/__tests__/device-wallet-session-store.test.ts +152 -7
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +86 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +326 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +39 -30
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/logBlockEvent.test.ts +17 -0
- package/__tests__/open-wallet-session.test.ts +311 -12
- package/__tests__/pro2Wallpaper.test.ts +7 -18
- package/__tests__/protocol-v2-unlock-policy.test.ts +45 -0
- package/__tests__/protocol-v2.test.ts +685 -177
- package/__tests__/public-device-state-api.test.ts +69 -62
- package/__tests__/public-pro2-api-boundary.test.ts +8 -34
- package/dist/api/BaseMethod.d.ts +2 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +11 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +29 -10
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxGetAddress.d.ts +1 -0
- package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessage.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts +1 -0
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +7 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +23 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +30 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -17
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +1 -0
- package/dist/api/nexa/NexaSignTransaction.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 +1 -0
- 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/device/DeviceStateMapper.d.ts.map +1 -1
- package/dist/device/DeviceStateProjector.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 +273 -230
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3060 -1676
- 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/unlockPolicy.d.ts +4 -0
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -1
- 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 +3 -0
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +69 -0
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +27 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +10 -19
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +1 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -76
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +4 -1
- package/dist/types/api/sessionCache.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -0
- package/dist/types/settings.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/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -3
- package/src/api/CheckAllFirmwareRelease.ts +23 -3
- package/src/api/ClearSessionCache.ts +4 -0
- package/src/api/FirmwareUpdate.ts +8 -1
- package/src/api/FirmwareUpdateV2.ts +292 -120
- package/src/api/FirmwareUpdateV3.ts +256 -55
- package/src/api/FirmwareUpdateV4.ts +821 -331
- package/src/api/GetPassphraseState.ts +11 -5
- package/src/api/OpenWalletSession.ts +74 -25
- package/src/api/UploadPortfolio.ts +1 -1
- package/src/api/conflux/ConfluxGetAddress.ts +2 -0
- package/src/api/conflux/ConfluxSignMessage.ts +2 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +2 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +2 -0
- package/src/api/device/DeviceChangePin.ts +1 -1
- package/src/api/device/DeviceUnlock.ts +1 -2
- package/src/api/device/DeviceUpdateBootloader.ts +122 -6
- package/src/api/device/DeviceWipe.ts +3 -1
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +50 -0
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +621 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +392 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +140 -22
- package/src/api/helpers/protocolV2FileWrite.ts +6 -0
- package/src/api/index.ts +0 -18
- package/src/api/nexa/NexaSignTransaction.ts +2 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +1 -1
- package/src/core/index.ts +1 -0
- package/src/data/messages/messages-protocol-v2.json +35 -1
- package/src/data-manager/DataManager.ts +33 -33
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +80 -67
- package/src/device/DeviceCommands.ts +76 -159
- package/src/device/DeviceStateMapper.ts +18 -1
- package/src/device/DeviceStateProjector.ts +7 -1
- package/src/events/device.ts +1 -0
- package/src/events/logBlockEvent.ts +1 -14
- package/src/events/ui-request.ts +1 -0
- package/src/index.ts +5 -0
- package/src/inject.ts +22 -25
- package/src/lowLevelInject.ts +5 -1
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +2 -3
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +1 -3
- package/src/protocols/protocol-v2/walletSession.ts +86 -9
- package/src/topLevelInject.ts +5 -1
- package/src/types/api/checkAllFirmwareRelease.ts +3 -0
- package/src/types/api/deviceUnlock.ts +2 -5
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -0
- package/src/types/api/firmwareUpdate.ts +76 -0
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +36 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/getPassphraseState.ts +4 -3
- package/src/types/api/index.ts +14 -34
- package/src/types/api/openWalletSession.ts +2 -0
- package/src/types/api/protocolV2.ts +3 -156
- package/src/types/api/sessionCache.ts +9 -4
- package/src/types/settings.ts +13 -0
- package/src/utils/deviceFeaturesUtils.ts +5 -1
- package/src/utils/deviceInfoUtils.ts +3 -16
|
@@ -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
|
|
|
@@ -34,6 +34,25 @@ const wasResumed = (session: unknown) =>
|
|
|
34
34
|
'resumed' in session &&
|
|
35
35
|
(session as { resumed?: unknown }).resumed === true;
|
|
36
36
|
|
|
37
|
+
const forwardSessionId = (session: { newSession?: string }) =>
|
|
38
|
+
session.newSession ? { sessionId: session.newSession } : {};
|
|
39
|
+
|
|
40
|
+
const requireHiddenWalletResponse = (session: {
|
|
41
|
+
passphraseState?: string;
|
|
42
|
+
newSession?: string;
|
|
43
|
+
}) => {
|
|
44
|
+
if (!session.passphraseState) {
|
|
45
|
+
throw ERRORS.TypedError(
|
|
46
|
+
HardwareErrorCode.DeviceInitializeFailed,
|
|
47
|
+
'Hidden wallet response is missing passphraseState'
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
passphraseState: session.passphraseState,
|
|
52
|
+
...forwardSessionId(session),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
37
56
|
type NormalizedOpenWalletSessionParams = OpenWalletSessionParams & {
|
|
38
57
|
legacySessionToClear?: {
|
|
39
58
|
deviceId?: string;
|
|
@@ -117,30 +136,47 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
117
136
|
}
|
|
118
137
|
|
|
119
138
|
async run(): Promise<OpenWalletSessionPayload> {
|
|
139
|
+
const isProtocolV2 = this.device.isProtocolV2();
|
|
120
140
|
const state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
121
|
-
|
|
122
|
-
if (!currentDeviceId) {
|
|
123
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
124
|
-
}
|
|
125
|
-
|
|
141
|
+
let currentDeviceId = state.identity.deviceId;
|
|
126
142
|
const { legacySessionToClear } = this.params;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
const requireDeviceId = () => {
|
|
144
|
+
if (!currentDeviceId) {
|
|
145
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
146
|
+
}
|
|
147
|
+
return currentDeviceId;
|
|
148
|
+
};
|
|
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
|
+
const refreshProtocolV2DeviceId = async () => {
|
|
159
|
+
const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
160
|
+
currentDeviceId = refreshedState.identity.deviceId;
|
|
161
|
+
clearLegacySession();
|
|
162
|
+
return requireDeviceId();
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (!isProtocolV2) {
|
|
166
|
+
clearLegacySession();
|
|
132
167
|
}
|
|
133
168
|
|
|
134
|
-
const protocol =
|
|
169
|
+
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
135
170
|
|
|
136
171
|
if (this.params.mode === 'standard') {
|
|
137
172
|
this.device.passphraseState = undefined;
|
|
138
|
-
const session =
|
|
173
|
+
const session = isProtocolV2
|
|
139
174
|
? await getProtocolV2WalletSession(this.device, { onlyMainPin: true })
|
|
140
175
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
141
176
|
onlyMainPin: true,
|
|
142
177
|
initSession: this.payload.initSession,
|
|
143
178
|
});
|
|
179
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
144
180
|
if (session.unlockedAttachPin) {
|
|
145
181
|
try {
|
|
146
182
|
await this.device.lockDevice();
|
|
@@ -153,14 +189,24 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
153
189
|
return {
|
|
154
190
|
protocol,
|
|
155
191
|
walletType: 'standard',
|
|
156
|
-
deviceId
|
|
192
|
+
deviceId,
|
|
157
193
|
passphraseState: null,
|
|
194
|
+
...forwardSessionId(session),
|
|
158
195
|
resumed: wasResumed(session),
|
|
159
196
|
};
|
|
160
197
|
}
|
|
161
198
|
|
|
162
199
|
if (this.params.mode === 'resume-hidden') {
|
|
163
|
-
if (
|
|
200
|
+
if (isProtocolV2) {
|
|
201
|
+
if (this.device.features?.unlocked === false) {
|
|
202
|
+
await this.device.unlockDevice();
|
|
203
|
+
}
|
|
204
|
+
const refreshedDeviceId = await refreshProtocolV2DeviceId();
|
|
205
|
+
if (refreshedDeviceId !== this.params.deviceId) {
|
|
206
|
+
deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
|
|
207
|
+
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
208
|
+
}
|
|
209
|
+
} else if (requireDeviceId() !== this.params.deviceId) {
|
|
164
210
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
165
211
|
}
|
|
166
212
|
this.device.passphraseState = this.params.passphraseState;
|
|
@@ -171,19 +217,20 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
171
217
|
if (!cachedSessionId) {
|
|
172
218
|
throw ERRORS.TypedError(HardwareErrorCode.WalletSessionInvalid);
|
|
173
219
|
}
|
|
174
|
-
if (!
|
|
220
|
+
if (!isProtocolV2) {
|
|
175
221
|
await this.device.initialize({
|
|
176
222
|
deviceId: this.params.deviceId,
|
|
177
223
|
passphraseState: this.params.passphraseState,
|
|
178
224
|
});
|
|
179
225
|
}
|
|
180
|
-
const session =
|
|
226
|
+
const session = isProtocolV2
|
|
181
227
|
? await getProtocolV2WalletSession(this.device, {
|
|
182
228
|
expectedPassphraseState: this.params.passphraseState,
|
|
183
229
|
})
|
|
184
230
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
185
231
|
expectPassphraseState: this.params.passphraseState,
|
|
186
232
|
});
|
|
233
|
+
const deviceId = requireDeviceId();
|
|
187
234
|
if (!session.passphraseState) {
|
|
188
235
|
this.device.clearInternalState();
|
|
189
236
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
@@ -191,31 +238,33 @@ export default class OpenWalletSession extends BaseMethod<NormalizedOpenWalletSe
|
|
|
191
238
|
return {
|
|
192
239
|
protocol,
|
|
193
240
|
walletType: 'hidden',
|
|
194
|
-
deviceId
|
|
195
|
-
|
|
241
|
+
deviceId,
|
|
242
|
+
...requireHiddenWalletResponse(session),
|
|
196
243
|
resumed: wasResumed(session) || session.newSession === cachedSessionId,
|
|
197
244
|
};
|
|
198
245
|
}
|
|
199
246
|
|
|
200
247
|
this.device.passphraseState = undefined;
|
|
201
|
-
const session =
|
|
248
|
+
const session = isProtocolV2
|
|
202
249
|
? await getProtocolV2WalletSession(this.device, { initSession: true })
|
|
203
250
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
|
|
251
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
204
252
|
const responseBase = {
|
|
205
253
|
protocol,
|
|
206
|
-
deviceId
|
|
254
|
+
deviceId,
|
|
207
255
|
resumed: wasResumed(session),
|
|
208
256
|
} as const;
|
|
209
|
-
return
|
|
257
|
+
return this.device.getCurrentPassphraseProtection() === false
|
|
210
258
|
? {
|
|
211
259
|
...responseBase,
|
|
212
|
-
walletType: '
|
|
213
|
-
passphraseState:
|
|
260
|
+
walletType: 'standard',
|
|
261
|
+
passphraseState: null,
|
|
262
|
+
...forwardSessionId(session),
|
|
214
263
|
}
|
|
215
264
|
: {
|
|
216
265
|
...responseBase,
|
|
217
|
-
walletType: '
|
|
218
|
-
|
|
266
|
+
walletType: 'hidden',
|
|
267
|
+
...requireHiddenWalletResponse(session),
|
|
219
268
|
};
|
|
220
269
|
}
|
|
221
270
|
}
|
|
@@ -23,7 +23,7 @@ export default class UploadPortfolio extends FileWrite {
|
|
|
23
23
|
timeoutMs,
|
|
24
24
|
};
|
|
25
25
|
super.init();
|
|
26
|
-
this.unlockPolicy = '
|
|
26
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
27
27
|
// Portfolio is a background write/apply flow and never synthesizes UI events.
|
|
28
28
|
this.protocolV2UiMode = 'none';
|
|
29
29
|
}
|
|
@@ -7,6 +7,8 @@ import type { ConfluxGetAddress as HardwareConfluxGetAddress } from '@onekeyfe/h
|
|
|
7
7
|
import type { ConfluxAddress, ConfluxGetAddressParams } from '../../types/api/confluxGetAddress';
|
|
8
8
|
|
|
9
9
|
export default class ConfluxGetAddress extends BaseMethod<HardwareConfluxGetAddress[]> {
|
|
10
|
+
checkDeviceId = true;
|
|
11
|
+
|
|
10
12
|
hasBundle = false;
|
|
11
13
|
|
|
12
14
|
init() {
|
|
@@ -7,6 +7,8 @@ import { formatAnyHex } from '../helpers/hexUtils';
|
|
|
7
7
|
import type { ConfluxSignMessage as HardwareConfluxSignMessage } from '@onekeyfe/hd-transport';
|
|
8
8
|
|
|
9
9
|
export default class ConfluxSignMessage extends BaseMethod<HardwareConfluxSignMessage> {
|
|
10
|
+
checkDeviceId = true;
|
|
11
|
+
|
|
10
12
|
init() {
|
|
11
13
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
12
14
|
this.allowUsePreInitialize = true;
|
|
@@ -7,6 +7,8 @@ import { formatAnyHex } from '../helpers/hexUtils';
|
|
|
7
7
|
import type { ConfluxSignMessageCIP23 as HardwareConfluxSignMessageCIP23 } from '@onekeyfe/hd-transport';
|
|
8
8
|
|
|
9
9
|
export default class ConfluxSignMessageCIP23 extends BaseMethod<HardwareConfluxSignMessageCIP23> {
|
|
10
|
+
checkDeviceId = true;
|
|
11
|
+
|
|
10
12
|
init() {
|
|
11
13
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
12
14
|
this.allowUsePreInitialize = true;
|
|
@@ -16,6 +16,8 @@ import type {
|
|
|
16
16
|
import type { ConfluxSignTx, ConfluxTxRequest } from '@onekeyfe/hd-transport';
|
|
17
17
|
|
|
18
18
|
export default class ConfluxSignTransaction extends BaseMethod {
|
|
19
|
+
checkDeviceId = true;
|
|
20
|
+
|
|
19
21
|
addressN: number[] = [];
|
|
20
22
|
|
|
21
23
|
formattedTx: ConfluxTransaction | undefined;
|
|
@@ -8,7 +8,7 @@ import type { ChangePin } from '@onekeyfe/hd-transport';
|
|
|
8
8
|
|
|
9
9
|
export default class DeviceChangePin extends BaseMethod<ChangePin> {
|
|
10
10
|
init() {
|
|
11
|
-
this.unlockPolicy = '
|
|
11
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
12
12
|
this.useDevicePassphraseState = false;
|
|
13
13
|
|
|
14
14
|
// check payload
|
|
@@ -5,15 +5,23 @@ 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 } from '../firmware/uploadFirmware';
|
|
8
|
+
import { updateBootloader, updateBootloaderFromSource } from '../firmware/uploadFirmware';
|
|
9
9
|
import { DeviceModelToTypes } from '../../types';
|
|
10
10
|
import { DataManager } from '../../data-manager';
|
|
11
|
-
import { checkBootloaderLength } from '../firmware/updateBootloader';
|
|
11
|
+
import { checkBootloaderLength, checkBootloaderSourceLength } from '../firmware/updateBootloader';
|
|
12
|
+
import { openFirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
13
|
+
import { resolveFirmwareUpdateHostBinding } from '../firmware/FirmwareHostBinding';
|
|
14
|
+
import {
|
|
15
|
+
assertFirmwareUpdatePreparedPlanBinding,
|
|
16
|
+
assertFirmwareUpdatePreparedPlanDeviceIdentity,
|
|
17
|
+
} from '../firmware/FirmwareUpdatePreparedPlan';
|
|
18
|
+
import { getDeviceUUID } from '../../utils';
|
|
12
19
|
|
|
13
20
|
import type { DeviceUpdateBootloaderParams } from '../../types/api/deviceUpdateBootloader';
|
|
14
21
|
import type { EFirmwareType } from '@onekeyfe/hd-shared';
|
|
15
22
|
import type { Device } from '../../device/Device';
|
|
16
23
|
import type { Features } from '../../types';
|
|
24
|
+
import type { FirmwareByteSource } from '../firmware/FirmwareArtifactSource';
|
|
17
25
|
|
|
18
26
|
export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any> {
|
|
19
27
|
init() {
|
|
@@ -43,17 +51,68 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
43
51
|
return true;
|
|
44
52
|
}
|
|
45
53
|
|
|
54
|
+
async updateBootloaderWithEmmcFileWriteFromSource(_device: Device, source: FirmwareByteSource) {
|
|
55
|
+
const filePath = '0:boot/bootloader.bin';
|
|
56
|
+
|
|
57
|
+
this.postTipMessage(FirmwareUpdateTipMessage.StartTransferData);
|
|
58
|
+
await this.emmcCommonUpdateProcessFromSource({
|
|
59
|
+
source,
|
|
60
|
+
filePath,
|
|
61
|
+
});
|
|
62
|
+
this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
|
|
63
|
+
await this.reboot(RebootType.Normal);
|
|
64
|
+
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloaderSuccess);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
46
68
|
async updateTouchBootloader({
|
|
47
69
|
device,
|
|
48
70
|
features,
|
|
49
71
|
firmwareType,
|
|
72
|
+
binary: preparedBinary,
|
|
73
|
+
source: preparedSource,
|
|
50
74
|
}: {
|
|
51
75
|
device: Device;
|
|
52
76
|
features?: Features;
|
|
53
77
|
firmwareType: EFirmwareType;
|
|
78
|
+
binary?: ArrayBuffer;
|
|
79
|
+
source?: FirmwareByteSource;
|
|
54
80
|
}) {
|
|
55
|
-
|
|
81
|
+
if (preparedSource) {
|
|
82
|
+
if (!(await checkBootloaderSourceLength(preparedSource))) {
|
|
83
|
+
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
84
|
+
}
|
|
85
|
+
if (features && device.isBootloader()) {
|
|
86
|
+
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
87
|
+
const result = await this.updateBootloaderWithEmmcFileWriteFromSource(
|
|
88
|
+
device,
|
|
89
|
+
preparedSource
|
|
90
|
+
);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
if (features && !device.isBootloader()) {
|
|
94
|
+
await updateBootloaderFromSource(
|
|
95
|
+
this.device.getCommands().typedCall.bind(this.device.getCommands()),
|
|
96
|
+
this.postMessage,
|
|
97
|
+
device,
|
|
98
|
+
preparedSource
|
|
99
|
+
);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let binary = preparedBinary;
|
|
56
105
|
if (!binary) {
|
|
106
|
+
if (DataManager.getSettings('firmwareManifestMode') === 'external-only') {
|
|
107
|
+
throw ERRORS.TypedError(
|
|
108
|
+
HardwareErrorCode.RuntimeError,
|
|
109
|
+
'Bootloader must be prepared by the external firmware host',
|
|
110
|
+
{
|
|
111
|
+
firmwareUpdateCode: 'FirmwareArtifactsNotPrepared',
|
|
112
|
+
artifactName: 'bootloader',
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
}
|
|
57
116
|
this.postTipMessage(FirmwareUpdateTipMessage.CheckLatestUiResource);
|
|
58
117
|
const resourceUrl = features
|
|
59
118
|
? DataManager.getBootloaderResource(features, firmwareType)
|
|
@@ -68,7 +127,7 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
68
127
|
}
|
|
69
128
|
}
|
|
70
129
|
|
|
71
|
-
if (!checkBootloaderLength(binary)) {
|
|
130
|
+
if (!binary || !checkBootloaderLength(binary)) {
|
|
72
131
|
throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
|
|
73
132
|
}
|
|
74
133
|
|
|
@@ -76,7 +135,8 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
76
135
|
if (features && device.isBootloader()) {
|
|
77
136
|
// Use emmcFileWrite + reboot logic for bootloader mode
|
|
78
137
|
this.postTipMessage(FirmwareUpdateTipMessage.UpdateBootloader);
|
|
79
|
-
|
|
138
|
+
const result = await this.updateBootloaderWithEmmcFileWrite(device, binary);
|
|
139
|
+
return result;
|
|
80
140
|
}
|
|
81
141
|
|
|
82
142
|
if (features && !device.isBootloader()) {
|
|
@@ -96,13 +156,69 @@ export default class DeviceUpdateBootloader extends FirmwareUpdateBaseMethod<any
|
|
|
96
156
|
const { features } = device;
|
|
97
157
|
|
|
98
158
|
const payload = this.payload as DeviceUpdateBootloaderParams;
|
|
159
|
+
const hostBinding = payload.artifact
|
|
160
|
+
? resolveFirmwareUpdateHostBinding(payload.hostBindingGeneration)
|
|
161
|
+
: undefined;
|
|
162
|
+
const executionParams = {
|
|
163
|
+
...payload,
|
|
164
|
+
artifactReader: hostBinding?.artifactReader ?? payload.artifactReader,
|
|
165
|
+
};
|
|
166
|
+
if (payload.artifact) {
|
|
167
|
+
assertFirmwareUpdatePreparedPlanDeviceIdentity({
|
|
168
|
+
preparedPlan: payload.preparedPlan,
|
|
169
|
+
deviceIdentity: getDeviceUUID(features) || undefined,
|
|
170
|
+
});
|
|
171
|
+
assertFirmwareUpdatePreparedPlanBinding({
|
|
172
|
+
preparedPlan: payload.preparedPlan,
|
|
173
|
+
executor: 'v2',
|
|
174
|
+
scopeTargets: ['bootloader'],
|
|
175
|
+
bindings: [
|
|
176
|
+
{
|
|
177
|
+
target: 'bootloader',
|
|
178
|
+
artifact: payload.artifact,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
const source = await openFirmwareByteSource({
|
|
183
|
+
artifact: payload.artifact,
|
|
184
|
+
reader: executionParams.artifactReader,
|
|
185
|
+
});
|
|
186
|
+
if (!source) {
|
|
187
|
+
throw ERRORS.TypedError(
|
|
188
|
+
HardwareErrorCode.RuntimeError,
|
|
189
|
+
'Bootloader artifact is not prepared'
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const deviceType = device.getCurrentDeviceType();
|
|
194
|
+
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
195
|
+
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
196
|
+
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
197
|
+
return await this.updateTouchBootloader({
|
|
198
|
+
device,
|
|
199
|
+
features,
|
|
200
|
+
firmwareType,
|
|
201
|
+
source,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
} finally {
|
|
206
|
+
await source.close();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
99
209
|
|
|
210
|
+
const { binary } = payload;
|
|
100
211
|
const deviceType = device.getCurrentDeviceType();
|
|
101
212
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
102
213
|
const firmwareType = payload.firmwareType ?? deviceFirmwareType;
|
|
103
214
|
|
|
104
215
|
if (DeviceModelToTypes.model_touch.includes(deviceType)) {
|
|
105
|
-
return this.updateTouchBootloader({
|
|
216
|
+
return this.updateTouchBootloader({
|
|
217
|
+
device,
|
|
218
|
+
features,
|
|
219
|
+
firmwareType,
|
|
220
|
+
binary,
|
|
221
|
+
});
|
|
106
222
|
}
|
|
107
223
|
|
|
108
224
|
return Promise.resolve(true);
|
|
@@ -6,7 +6,7 @@ import type { WipeDevice } from '@onekeyfe/hd-transport';
|
|
|
6
6
|
|
|
7
7
|
export default class DeviceWipe extends BaseMethod<WipeDevice> {
|
|
8
8
|
init() {
|
|
9
|
-
this.unlockPolicy = '
|
|
9
|
+
this.unlockPolicy = 'unlock-before-run';
|
|
10
10
|
this.useDevicePassphraseState = false;
|
|
11
11
|
this.protocolV2UiInteraction = {
|
|
12
12
|
request: 'button',
|
|
@@ -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
|
}
|