@onekeyfe/hd-core 1.2.0-alpha.56 → 1.2.0-alpha.62
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__/AllNetworkGetAddressBase.tracing.test.ts +0 -231
- package/__tests__/DeviceCommands.test.ts +0 -45
- package/__tests__/DeviceEventRegistration.test.ts +0 -6
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -198
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +3 -105
- package/__tests__/device-state-contract.test.ts +0 -1
- package/__tests__/device-state-mapper.test.ts +1 -1
- package/__tests__/deviceSettings.test.ts +1 -1
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -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-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +294 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -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 +59 -31
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +12 -132
- package/__tests__/homescreen.test.ts +1 -41
- package/__tests__/kaspaSignTransaction.test.ts +26 -3
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +37 -568
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -201
- package/__tests__/protocol-v2.test.ts +1046 -1388
- package/__tests__/protocolV2FileWrite.test.ts +0 -39
- package/__tests__/protocolV2UiInteraction.test.ts +0 -63
- package/__tests__/public-pro2-api-boundary.test.ts +0 -1
- package/__tests__/search-devices.test.ts +3 -12
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +1 -2
- package/dist/api/CheckAllFirmwareRelease.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 +25 -11
- 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/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceUnlock.d.ts +2 -2
- 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/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/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +9 -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 +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -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/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- 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 +0 -2
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +2 -4
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -29
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/events/device.d.ts +0 -4
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +2 -4
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -31
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +2 -10
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +231 -214
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3530 -2634
- package/dist/inject.d.ts +1 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +4 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +1 -6
- 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 +4 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -5
- 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 -2
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +70 -2
- 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 +28 -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/index.d.ts +10 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -22
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -4
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +0 -4
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -10
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -8
- package/src/api/CheckAllFirmwareRelease.ts +57 -54
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +316 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +975 -584
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -70
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -34
- package/src/api/device/DeviceUnlock.ts +3 -8
- package/src/api/device/DeviceUpdateBootloader.ts +122 -6
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -16
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +415 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +144 -39
- package/src/api/helpers/protocolV2FileWrite.ts +7 -27
- package/src/api/index.ts +0 -2
- package/src/api/kaspa/KaspaSignTransaction.ts +12 -1
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/api/protocol-v2/helpers.ts +0 -1
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +83 -167
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +39 -71
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +43 -259
- package/src/device/DeviceCommands.ts +1 -7
- package/src/device/DevicePool.ts +2 -7
- package/src/events/device.ts +0 -4
- package/src/events/logBlockEvent.ts +0 -1
- package/src/events/ui-promise.ts +2 -4
- package/src/events/ui-request.ts +2 -36
- package/src/events/ui-response.ts +2 -12
- package/src/index.ts +5 -0
- package/src/inject.ts +24 -60
- package/src/lowLevelInject.ts +8 -7
- package/src/protocols/protocol-v2/features.ts +7 -10
- package/src/protocols/protocol-v2/firmware.ts +0 -2
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
- package/src/protocols/protocol-v2/walletSession.ts +36 -214
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +4 -2
- package/src/types/api/deviceUnlock.ts +1 -12
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -1
- package/src/types/api/firmwareUpdate.ts +76 -3
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -13
- package/src/types/api/protocolV2.ts +0 -13
- package/src/types/device.ts +0 -3
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +13 -42
- package/src/utils/deviceFeaturesCompat.ts +6 -0
- package/src/utils/deviceFeaturesUtils.ts +0 -8
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/deviceUploadNft.test.ts +0 -293
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -286
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -86
- package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
- package/dist/core/uiPromiseRegistry.d.ts +0 -4
- package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/resources.d.ts +0 -30
- package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/utils/pro2Nft.d.ts +0 -31
- package/dist/utils/pro2Nft.d.ts.map +0 -1
- package/dist/utils/uiProgressThrottle.d.ts +0 -3
- package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
- package/src/api/DetectDeviceConnectProtocol.ts +0 -18
- package/src/api/protocol-v2/DeviceUploadNft.ts +0 -189
- package/src/core/uiPromiseRegistry.ts +0 -41
- package/src/protocols/protocol-v2/resources.ts +0 -359
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -118
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -6
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import { UI_REQUEST } from '../constants/ui-request';
|
|
5
4
|
import { refreshProtocolV2DeviceStatus } from '../protocols/protocol-v2/walletSession';
|
|
@@ -25,12 +24,7 @@ export default class GetPassphraseState extends BaseMethod {
|
|
|
25
24
|
if (isProtocolV2 && this.payload.useEmptyPassphrase !== true) {
|
|
26
25
|
const features = await refreshProtocolV2DeviceStatus(this.device);
|
|
27
26
|
if (features.unlocked === false) {
|
|
28
|
-
await this.device.unlockDevice(
|
|
29
|
-
source: 'unlock-coordinator',
|
|
30
|
-
reason: 'device-locked',
|
|
31
|
-
deviceOnly: true,
|
|
32
|
-
method: 'getPassphraseState',
|
|
33
|
-
});
|
|
27
|
+
await this.device.unlockDevice();
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
30
|
const { passphraseState } = await getPassphraseStateWithRefreshDeviceInfo(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
3
2
|
|
|
4
3
|
import { deviceWalletSessionStore } from '../device/DeviceWalletSessionStore';
|
|
5
4
|
import { getProtocolV2WalletSession } from '../protocols/protocol-v2/walletSession';
|
|
@@ -91,40 +90,23 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
91
90
|
|
|
92
91
|
async run(): Promise<OpenWalletSessionPayload> {
|
|
93
92
|
const isProtocolV2 = this.device.isProtocolV2();
|
|
94
|
-
|
|
93
|
+
const state = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
95
94
|
let currentDeviceId = state.identity.deviceId;
|
|
96
|
-
const hasAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) =>
|
|
97
|
-
candidate.status.unlocked === true &&
|
|
98
|
-
typeof candidate.status.passphraseProtection === 'boolean' &&
|
|
99
|
-
typeof candidate.status.unlockedAttachPin === 'boolean';
|
|
100
|
-
const requireAuthoritativeProtocolV2WalletStatus = (candidate: typeof state) => {
|
|
101
|
-
if (!hasAuthoritativeProtocolV2WalletStatus(candidate)) {
|
|
102
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
103
|
-
}
|
|
104
|
-
return candidate;
|
|
105
|
-
};
|
|
106
95
|
const requireDeviceId = () => {
|
|
107
96
|
if (!currentDeviceId) {
|
|
108
97
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceInitializeFailed);
|
|
109
98
|
}
|
|
110
99
|
return currentDeviceId;
|
|
111
100
|
};
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
currentDeviceId =
|
|
115
|
-
return
|
|
101
|
+
const refreshProtocolV2DeviceId = async () => {
|
|
102
|
+
const refreshedState = await this.device.getDeviceState({ refreshSections: ['status'] });
|
|
103
|
+
currentDeviceId = refreshedState.identity.deviceId;
|
|
104
|
+
return requireDeviceId();
|
|
116
105
|
};
|
|
117
|
-
const
|
|
118
|
-
if (isProtocolV2 &&
|
|
119
|
-
await this.device.unlockDevice(
|
|
120
|
-
source: 'unlock-coordinator',
|
|
121
|
-
reason: 'device-locked',
|
|
122
|
-
deviceOnly: true,
|
|
123
|
-
method: 'openWalletSession',
|
|
124
|
-
});
|
|
125
|
-
requireAuthoritativeProtocolV2WalletStatus(await refreshProtocolV2DeviceState());
|
|
106
|
+
const unlockProtocolV2IfLocked = async () => {
|
|
107
|
+
if (isProtocolV2 && state.status.unlocked === false) {
|
|
108
|
+
await this.device.unlockDevice();
|
|
126
109
|
}
|
|
127
|
-
return state;
|
|
128
110
|
};
|
|
129
111
|
|
|
130
112
|
const protocol = isProtocolV2 ? 'V2' : 'V1';
|
|
@@ -132,25 +114,13 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
132
114
|
if (this.params.mode === OpenWalletSessionMode.Standard) {
|
|
133
115
|
this.device.passphraseState = undefined;
|
|
134
116
|
const session = isProtocolV2
|
|
135
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
136
|
-
onlyMainPin: true,
|
|
137
|
-
deriveCardano: this.payload.deriveCardano,
|
|
138
|
-
selectMainWalletBeforeRestore:
|
|
139
|
-
!hasAuthoritativeProtocolV2WalletStatus(state) ||
|
|
140
|
-
state.status.unlockedAttachPin === true,
|
|
141
|
-
})
|
|
117
|
+
? await getProtocolV2WalletSession(this.device, { onlyMainPin: true })
|
|
142
118
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
143
119
|
onlyMainPin: true,
|
|
144
120
|
initSession: this.payload.initSession,
|
|
145
121
|
});
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
: state;
|
|
149
|
-
const deviceId = requireDeviceId();
|
|
150
|
-
if (
|
|
151
|
-
session.unlockedAttachPin ||
|
|
152
|
-
(isProtocolV2 && refreshedState.status.unlockedAttachPin === true)
|
|
153
|
-
) {
|
|
122
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
123
|
+
if (session.unlockedAttachPin) {
|
|
154
124
|
try {
|
|
155
125
|
await this.device.lockDevice();
|
|
156
126
|
} catch {
|
|
@@ -170,8 +140,8 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
170
140
|
|
|
171
141
|
if (this.params.mode === OpenWalletSessionMode.ResumeHidden) {
|
|
172
142
|
if (isProtocolV2) {
|
|
173
|
-
await
|
|
174
|
-
const refreshedDeviceId =
|
|
143
|
+
await unlockProtocolV2IfLocked();
|
|
144
|
+
const refreshedDeviceId = await refreshProtocolV2DeviceId();
|
|
175
145
|
if (refreshedDeviceId !== this.params.deviceId) {
|
|
176
146
|
deviceWalletSessionStore.delete(this.params.deviceId, this.params.passphraseState);
|
|
177
147
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError);
|
|
@@ -196,7 +166,6 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
196
166
|
const session = isProtocolV2
|
|
197
167
|
? await getProtocolV2WalletSession(this.device, {
|
|
198
168
|
expectedPassphraseState: this.params.passphraseState,
|
|
199
|
-
deriveCardano: this.payload.deriveCardano,
|
|
200
169
|
})
|
|
201
170
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, {
|
|
202
171
|
expectPassphraseState: this.params.passphraseState,
|
|
@@ -216,37 +185,15 @@ export default class OpenWalletSession extends BaseMethod<OpenWalletSessionParam
|
|
|
216
185
|
}
|
|
217
186
|
|
|
218
187
|
this.device.passphraseState = undefined;
|
|
219
|
-
|
|
220
|
-
if (isProtocolV2 && walletStatus.status.passphraseProtection !== true) {
|
|
221
|
-
this.device.clearInternalState();
|
|
222
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
223
|
-
}
|
|
224
|
-
const readCurrentAttachPinSession =
|
|
225
|
-
isProtocolV2 && walletStatus.status.unlockedAttachPin === true;
|
|
188
|
+
await unlockProtocolV2IfLocked();
|
|
226
189
|
const session = isProtocolV2
|
|
227
|
-
? await getProtocolV2WalletSession(this.device, {
|
|
228
|
-
...(readCurrentAttachPinSession
|
|
229
|
-
? { readCurrentAttachPinSession: true }
|
|
230
|
-
: { forceWalletSelection: true }),
|
|
231
|
-
deriveCardano: this.payload.deriveCardano,
|
|
232
|
-
})
|
|
190
|
+
? await getProtocolV2WalletSession(this.device, { forceWalletSelection: true })
|
|
233
191
|
: await getPassphraseStateWithRefreshDeviceInfo(this.device, { initSession: true });
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
: state;
|
|
237
|
-
const deviceId = requireDeviceId();
|
|
238
|
-
if (isProtocolV2 && refreshedState.status.passphraseProtection !== true) {
|
|
192
|
+
const deviceId = isProtocolV2 ? await refreshProtocolV2DeviceId() : requireDeviceId();
|
|
193
|
+
if (isProtocolV2 && this.device.getCurrentPassphraseProtection() !== true) {
|
|
239
194
|
this.device.clearInternalState();
|
|
240
195
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
241
196
|
}
|
|
242
|
-
if (
|
|
243
|
-
isProtocolV2 &&
|
|
244
|
-
readCurrentAttachPinSession &&
|
|
245
|
-
refreshedState.status.unlockedAttachPin !== true
|
|
246
|
-
) {
|
|
247
|
-
this.device.clearInternalState();
|
|
248
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError);
|
|
249
|
-
}
|
|
250
197
|
const responseBase = {
|
|
251
198
|
protocol,
|
|
252
199
|
deviceId,
|
package/src/api/SearchDevices.ts
CHANGED
|
@@ -59,9 +59,7 @@ export default class SearchDevices extends BaseMethod {
|
|
|
59
59
|
// Discovery is best effort. Browsers may retain WebUSB grants for devices that
|
|
60
60
|
// are offline, busy, or not ready, so one descriptor must not abort the scan.
|
|
61
61
|
const result = await DevicePool.getDevices([descriptor], descriptor.path, {
|
|
62
|
-
|
|
63
|
-
connectProtocol: undefined,
|
|
64
|
-
forceProtocolDetection: true,
|
|
62
|
+
connectProtocol: this.payload.connectProtocol,
|
|
65
63
|
refreshRuntimeState: true,
|
|
66
64
|
});
|
|
67
65
|
deviceList.push(...result.deviceList);
|
|
@@ -24,28 +24,24 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
24
24
|
const resultMap: Record<string, AllNetworkAddress> = {};
|
|
25
25
|
const { bundle } = this.payload as AllNetworkGetAddressParams;
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
(this.payload.useEmptyPassphrase === true || !!this.payload.passphraseState);
|
|
43
|
-
const methodGroups: [keyof CoreApi, MethodParams[]][] = requiresProtocolV2WalletHandoff
|
|
44
|
-
? methodParams.map(param => [param.methodName, [param]])
|
|
45
|
-
: Array.from(groupedMethodParams.entries());
|
|
27
|
+
const methodGroups = bundle
|
|
28
|
+
.map((param, index) =>
|
|
29
|
+
this.generateMethodName({
|
|
30
|
+
network: param.network,
|
|
31
|
+
payload: param,
|
|
32
|
+
originalIndex: index,
|
|
33
|
+
})
|
|
34
|
+
)
|
|
35
|
+
.reduce((acc, cur) => {
|
|
36
|
+
if (!acc[cur.methodName]) {
|
|
37
|
+
acc[cur.methodName] = [];
|
|
38
|
+
}
|
|
39
|
+
acc[cur.methodName].push(cur);
|
|
40
|
+
return acc;
|
|
41
|
+
}, {} as Record<keyof CoreApi, MethodParams[]>);
|
|
46
42
|
|
|
47
43
|
let i = 0;
|
|
48
|
-
for (const [methodName, params] of methodGroups) {
|
|
44
|
+
for (const [methodName, params] of Object.entries(methodGroups)) {
|
|
49
45
|
const methodParams = {
|
|
50
46
|
bundle: params.map(param => ({
|
|
51
47
|
...param.params,
|
|
@@ -56,7 +52,11 @@ export default class AllNetworkGetAddress extends AllNetworkGetAddressBase {
|
|
|
56
52
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
57
53
|
}
|
|
58
54
|
// call method
|
|
59
|
-
const response = await this.callMethod(
|
|
55
|
+
const response = await this.callMethod(
|
|
56
|
+
methodName as keyof CoreApi,
|
|
57
|
+
methodParams,
|
|
58
|
+
rootFingerprint
|
|
59
|
+
);
|
|
60
60
|
|
|
61
61
|
if (this.abortController?.signal.aborted) {
|
|
62
62
|
throw new Error(HardwareErrorCodeMessage[HardwareErrorCode.RepeatUnlocking]);
|
|
@@ -14,7 +14,6 @@ import { findMethod } from '../utils';
|
|
|
14
14
|
import { DEVICE, IFRAME, createUiMessage } from '../../events';
|
|
15
15
|
import { UI_REQUEST } from '../../constants/ui-request';
|
|
16
16
|
import { onDeviceButtonHandler } from '../../core';
|
|
17
|
-
import { runMethodWithUnlockPolicy } from '../../protocols/protocol-v2/unlockPolicyRunner';
|
|
18
17
|
import {
|
|
19
18
|
completeRequestContext,
|
|
20
19
|
createRequestContext,
|
|
@@ -376,36 +375,16 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
376
375
|
this.device.on(DEVICE.PASSPHRASE, onSignalAbort);
|
|
377
376
|
|
|
378
377
|
preCheckDeviceSupport(this.device, method);
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Protocol V2 hands a wallet session to exactly one blockchain request.
|
|
392
|
-
// The parent all-network call consumes its first handoff while fetching
|
|
393
|
-
// the root fingerprint, so each nested chain method must resume the
|
|
394
|
-
// requested standard or hidden wallet before sending its device command.
|
|
395
|
-
const useEmptyPassphrase = this.payload.useEmptyPassphrase === true;
|
|
396
|
-
const shouldResumeWalletSession = useEmptyPassphrase || !!this.payload.passphraseState;
|
|
397
|
-
if (this.device.isProtocolV2() && shouldResumeWalletSession) {
|
|
398
|
-
const passphraseStateSafety = await this.device.checkPassphraseStateSafety(
|
|
399
|
-
this.payload.passphraseState,
|
|
400
|
-
useEmptyPassphrase,
|
|
401
|
-
this.payload.skipPassphraseCheck
|
|
402
|
-
);
|
|
403
|
-
if (!passphraseStateSafety) {
|
|
404
|
-
throw ERRORS.TypedError(HardwareErrorCode.DeviceCheckPassphraseStateError);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
});
|
|
378
|
+
if (this.temporarySafetyCheckPrompted) {
|
|
379
|
+
method.temporarySafetyCheckPrompted = true;
|
|
380
|
+
} else {
|
|
381
|
+
const appliedTemporarySafetyCheck = await method.checkSafetyLevelOnTestNet();
|
|
382
|
+
if (appliedTemporarySafetyCheck) {
|
|
383
|
+
this.temporarySafetyCheckPrompted = true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const response = await method.run();
|
|
409
388
|
|
|
410
389
|
if (!Array.isArray(response) || response.length === 0) {
|
|
411
390
|
throw new Error('No response');
|
|
@@ -460,9 +439,7 @@ export default abstract class AllNetworkGetAddressBase extends BaseMethod<
|
|
|
460
439
|
show_display: false,
|
|
461
440
|
});
|
|
462
441
|
|
|
463
|
-
|
|
464
|
-
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
465
|
-
}
|
|
442
|
+
this.postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_PIN_WINDOW));
|
|
466
443
|
|
|
467
444
|
if (res.message.root_fingerprint == null) {
|
|
468
445
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { DeviceSessionPinType } from '@onekeyfe/hd-transport';
|
|
2
|
-
|
|
3
1
|
import { BaseMethod } from '../BaseMethod';
|
|
4
2
|
|
|
5
|
-
import type {
|
|
3
|
+
import type { LockDevice } from '@onekeyfe/hd-transport';
|
|
6
4
|
|
|
7
|
-
export default class DeviceUnlock extends BaseMethod<
|
|
5
|
+
export default class DeviceUnlock extends BaseMethod<LockDevice> {
|
|
8
6
|
getSupportedProtocols() {
|
|
9
7
|
return ['V1', 'V2'] as const;
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
init() {
|
|
13
|
-
this.params = {
|
|
14
|
-
pinType: this.payload.pinType ?? DeviceSessionPinType.Main,
|
|
15
|
-
};
|
|
16
11
|
this.useDevicePassphraseState = false;
|
|
17
12
|
this.unlockPolicy = 'none';
|
|
18
13
|
this.protocolV2UiInteraction = {
|
|
@@ -26,6 +21,6 @@ export default class DeviceUnlock extends BaseMethod<DeviceUnlockParams> {
|
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
async run() {
|
|
29
|
-
return this.device.unlockDevice(
|
|
24
|
+
return this.device.unlockDevice();
|
|
30
25
|
}
|
|
31
26
|
}
|
|
@@ -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);
|