@onekeyfe/hd-core 1.2.0-alpha.67 → 1.2.0-alpha.68
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 +313 -0
- package/__tests__/DeviceCommands.test.ts +59 -13
- package/__tests__/DeviceEventRegistration.test.ts +6 -0
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +198 -3
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-lifecycle-events.test.ts +105 -3
- package/__tests__/device-pool-state.test.ts +22 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/device-state-contract.test.ts +1 -0
- package/__tests__/device-state-mapper.test.ts +13 -1
- package/__tests__/device-utils.test.ts +48 -1
- package/__tests__/deviceSettings.test.ts +11 -1
- package/__tests__/deviceUploadNft.test.ts +316 -0
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +5 -0
- package/__tests__/get-device-state.test.ts +132 -12
- package/__tests__/homescreen.test.ts +41 -1
- package/__tests__/kaspa-use-tweak-pro2.test.ts +2 -2
- package/__tests__/kaspaSignTransaction.test.ts +3 -26
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +19 -0
- package/__tests__/open-wallet-session.test.ts +568 -37
- package/__tests__/pro2Nft.test.ts +108 -0
- package/__tests__/protocol-binding.test.ts +89 -0
- package/__tests__/protocol-v2-resources.test.ts +340 -0
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +91 -0
- package/__tests__/protocol-v2-unlock-policy.test.ts +300 -37
- package/__tests__/protocol-v2.test.ts +1449 -867
- package/__tests__/protocolV2FileWrite.test.ts +152 -0
- package/__tests__/protocolV2UiInteraction.test.ts +63 -0
- package/__tests__/public-pro2-api-boundary.test.ts +1 -0
- package/__tests__/search-devices.test.ts +12 -3
- package/__tests__/tron-sign-message-init.test.ts +2 -2
- package/__tests__/uiProgressThrottle.test.ts +74 -0
- package/__tests__/uiPromiseRegistry.test.ts +115 -0
- package/dist/api/BaseMethod.d.ts +3 -1
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts +2 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/DetectDeviceConnectProtocol.d.ts +7 -0
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +11 -4
- 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/DeviceSettings.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/firmware/FirmwareUpdateBaseMethod.d.ts +4 -3
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +9 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaGetAddress.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +1 -1
- package/dist/api/polkadot/networks.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +31 -0
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +1 -0
- 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/solana/SolSignMessage.d.ts +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +2 -2
- package/dist/api/sui/SuiGetAddress.d.ts +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +1 -1
- package/dist/api/ton/TonSignProof.d.ts +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +2 -2
- package/dist/api/tron/TronSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +2 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/uiPromiseRegistry.d.ts +6 -0
- package/dist/core/uiPromiseRegistry.d.ts.map +1 -0
- package/dist/data-manager/DataManager.d.ts +9 -3
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +29 -5
- 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/DeviceConnector.d.ts +2 -1
- package/dist/device/DeviceConnector.d.ts.map +1 -1
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/deviceProfile/protocolV2DeviceIdentity.d.ts.map +1 -1
- package/dist/events/device.d.ts +4 -0
- 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 +4 -2
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +31 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +10 -2
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +243 -69
- package/dist/index.js +2563 -1217
- package/dist/inject.d.ts +6 -1
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts +0 -4
- 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/resources.d.ts +30 -0
- package/dist/protocols/protocol-v2/resources.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +7 -4
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +1 -3
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +22 -0
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +6 -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 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +4 -0
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +1 -0
- package/dist/types/api/deviceUnlock.d.ts +5 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +1 -0
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +4 -2
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +6 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +3 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/device.d.ts +2 -2
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +38 -8
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +4 -0
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +4 -0
- 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/pro2Nft.d.ts +31 -0
- package/dist/utils/pro2Nft.d.ts.map +1 -0
- package/dist/utils/pro2Wallpaper.d.ts +10 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/dist/utils/uiProgressThrottle.d.ts +3 -0
- package/dist/utils/uiProgressThrottle.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +8 -10
- package/src/api/CheckAllFirmwareRelease.ts +61 -11
- package/src/api/DetectDeviceConnectProtocol.ts +18 -0
- package/src/api/FirmwareUpdate.ts +6 -2
- package/src/api/FirmwareUpdateV2.ts +5 -2
- package/src/api/FirmwareUpdateV3.ts +6 -2
- package/src/api/FirmwareUpdateV4.ts +463 -258
- package/src/api/GetPassphraseState.ts +7 -1
- package/src/api/OpenWalletSession.ts +71 -17
- package/src/api/SearchDevices.ts +3 -1
- package/src/api/allnetwork/AllNetworkGetAddress.ts +21 -21
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +36 -11
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceUnlock.ts +8 -3
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +27 -12
- package/src/api/firmware/uploadFirmware.ts +17 -4
- package/src/api/helpers/protocolV2FileWrite.ts +202 -63
- package/src/api/index.ts +2 -0
- package/src/api/kaspa/KaspaGetAddress.ts +1 -1
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -13
- package/src/api/polkadot/networks.ts +3 -3
- package/src/api/protocol-v2/DeviceUploadNft.ts +197 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +3 -1
- package/src/api/protocol-v2/helpers.ts +1 -1
- package/src/api/solana/SolSignMessage.ts +1 -1
- package/src/api/solana/SolSignOffchainMessage.ts +1 -1
- package/src/api/solana/SolSignTransaction.ts +2 -2
- package/src/api/sui/SuiGetAddress.ts +1 -1
- package/src/api/sui/SuiGetPublicKey.ts +1 -1
- package/src/api/sui/SuiSignMessage.ts +1 -1
- package/src/api/sui/SuiSignTransaction.ts +1 -1
- package/src/api/ton/TonGetAddress.ts +1 -1
- package/src/api/ton/TonSignMessage.ts +1 -1
- package/src/api/ton/TonSignProof.ts +1 -1
- package/src/api/tron/TronSignMessage.ts +2 -2
- package/src/api/tron/TronSignTransaction.ts +1 -1
- package/src/core/deviceEventRegistration.ts +4 -0
- package/src/core/index.ts +213 -111
- package/src/core/uiPromiseRegistry.ts +63 -0
- package/src/data/messages/messages-protocol-v2.json +25 -0
- package/src/data-manager/DataManager.ts +88 -11
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/device/Device.ts +273 -43
- package/src/device/DeviceCommands.ts +31 -4
- package/src/device/DeviceConnector.ts +33 -13
- package/src/device/DevicePool.ts +21 -7
- package/src/deviceProfile/buildDeviceFeatures.ts +2 -2
- package/src/deviceProfile/protocolV2DeviceIdentity.ts +3 -0
- package/src/events/device.ts +4 -0
- package/src/events/logBlockEvent.ts +1 -0
- package/src/events/ui-promise.ts +4 -2
- package/src/events/ui-request.ts +36 -2
- package/src/events/ui-response.ts +12 -2
- package/src/inject.ts +58 -2
- package/src/lowLevelInject.ts +6 -3
- package/src/protocols/protocol-v2/features.ts +10 -7
- package/src/protocols/protocol-v2/firmware.ts +2 -0
- package/src/protocols/protocol-v2/resources.ts +390 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +46 -6
- package/src/protocols/protocol-v2/unlockPolicy.ts +1 -105
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +131 -0
- package/src/protocols/protocol-v2/walletSession.ts +214 -36
- package/src/topLevelInject.ts +6 -3
- package/src/types/api/checkAllFirmwareRelease.ts +3 -1
- package/src/types/api/detectDeviceConnectProtocol.ts +6 -0
- package/src/types/api/deviceUnlock.ts +12 -1
- package/src/types/api/export.ts +1 -0
- package/src/types/api/firmwareUpdate.ts +6 -3
- package/src/types/api/index.ts +13 -0
- package/src/types/api/protocolV2.ts +13 -0
- package/src/types/device.ts +15 -3
- package/src/types/params.ts +7 -1
- package/src/types/settings.ts +60 -9
- package/src/utils/deviceFeaturesCompat.ts +5 -0
- package/src/utils/deviceFeaturesUtils.ts +14 -3
- package/src/utils/deviceInfoUtils.ts +2 -0
- package/src/utils/deviceSettings.ts +3 -0
- package/src/utils/homescreen.ts +32 -6
- package/src/utils/index.ts +6 -1
- package/src/utils/pro2Nft.ts +142 -0
- package/src/utils/pro2Wallpaper.ts +35 -8
- package/src/utils/uiProgressThrottle.ts +63 -0
- package/dist/api/firmware/progressThrottle.d.ts +0 -3
- package/dist/api/firmware/progressThrottle.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +0 -2
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +0 -10
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +0 -1
- package/src/api/firmware/progressThrottle.ts +0 -44
- package/src/protocols/protocol-v2/lockedError.ts +0 -10
- package/src/protocols/protocol-v2/unlockRetry.ts +0 -109
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"pro2Wallpaper.d.ts","sourceRoot":"","sources":["../../src/utils/pro2Wallpaper.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AA8BjE,wBAAgB,eAAe,CAAC,OAAO,EAAE;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;IAC/B,SAAS,CAAC,EAAE,kBAAkB,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CA4E9D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,GAAG,WAAW,CAAC;CAChC,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,wBAAwB,CAAA;CAAE,CAE9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uiProgressThrottle.d.ts","sourceRoot":"","sources":["../../src/utils/uiProgressThrottle.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAiB7C,eAAO,MAAM,6BAA6B,yDAMvB,WAAW,YAqC7B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.2.0-alpha.
|
|
3
|
+
"version": "1.2.0-alpha.68",
|
|
4
4
|
"description": "Core processes and APIs for communicating with OneKey hardware devices.",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@onekeyfe/hd-shared": "1.2.0-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport": "1.2.0-alpha.
|
|
28
|
+
"@onekeyfe/hd-shared": "1.2.0-alpha.68",
|
|
29
|
+
"@onekeyfe/hd-transport": "1.2.0-alpha.68",
|
|
30
30
|
"axios": "1.15.2",
|
|
31
31
|
"bignumber.js": "^9.0.2",
|
|
32
32
|
"bytebuffer": "^5.0.1",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@types/w3c-web-usb": "^1.0.10",
|
|
45
45
|
"@types/web-bluetooth": "^0.0.21"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "6e8a931d08768980cfe7fa918bba447ed73e2724"
|
|
48
48
|
}
|
package/src/api/BaseMethod.ts
CHANGED
|
@@ -16,16 +16,14 @@ import { getBleFirmwareReleaseInfo, getFirmwareReleaseInfo } from './firmware/re
|
|
|
16
16
|
import { LoggerNames, getLogger } from '../utils';
|
|
17
17
|
import { generateInstanceId } from '../utils/tracing';
|
|
18
18
|
import { DeviceModelToTypes } from '../types';
|
|
19
|
-
import {
|
|
20
|
-
type UnlockPolicy,
|
|
21
|
-
getProtocolV2UnlockPolicy,
|
|
22
|
-
} from '../protocols/protocol-v2/unlockPolicy';
|
|
23
19
|
|
|
24
20
|
import type { Device } from '../device/Device';
|
|
25
21
|
import type DeviceConnector from '../device/DeviceConnector';
|
|
26
22
|
import type { DeviceFirmwareRange, KnownDevice } from '../types';
|
|
27
23
|
import type { CoreMessage } from '../events';
|
|
24
|
+
import type { UnlockPolicy } from '../protocols/protocol-v2/unlockPolicy';
|
|
28
25
|
import type { ProtocolV2InteractionDescriptor } from '../protocols/protocol-v2/uiInteraction';
|
|
26
|
+
import type { ProtocolV2UnlockContext } from '../protocols/protocol-v2/unlockPolicyRunner';
|
|
29
27
|
import type { RequestContext } from '../utils/tracing';
|
|
30
28
|
import type { CoreContext } from '../core';
|
|
31
29
|
|
|
@@ -128,9 +126,7 @@ export abstract class BaseMethod<Params = undefined> {
|
|
|
128
126
|
*/
|
|
129
127
|
checkDeviceId = false;
|
|
130
128
|
|
|
131
|
-
/**
|
|
132
|
-
* 该方法是否需要校验 passphrase state
|
|
133
|
-
*/
|
|
129
|
+
/** Whether the method requires wallet-session selection and Protocol V2 pre-unlock. */
|
|
134
130
|
useDevicePassphraseState = true;
|
|
135
131
|
|
|
136
132
|
/**
|
|
@@ -168,9 +164,12 @@ export abstract class BaseMethod<Params = undefined> {
|
|
|
168
164
|
*/
|
|
169
165
|
strictCheckDeviceSupport = false;
|
|
170
166
|
|
|
171
|
-
/**
|
|
167
|
+
/** Non-wallet methods may explicitly require Protocol V2 pre-unlock. */
|
|
172
168
|
unlockPolicy: UnlockPolicy = 'none';
|
|
173
169
|
|
|
170
|
+
/** Shared by composite methods so nested calls do not repeat the root preflight. */
|
|
171
|
+
protocolV2UnlockContext?: ProtocolV2UnlockContext;
|
|
172
|
+
|
|
174
173
|
getSupportedProtocols(): readonly ProtocolType[] {
|
|
175
174
|
return ['V1'];
|
|
176
175
|
}
|
|
@@ -188,7 +187,7 @@ export abstract class BaseMethod<Params = undefined> {
|
|
|
188
187
|
/** Non-blocking Protocol V2 interaction synthesized by the SDK. */
|
|
189
188
|
protocolV2UiInteraction?: ProtocolV2InteractionDescriptor;
|
|
190
189
|
|
|
191
|
-
/** Special background methods may suppress
|
|
190
|
+
/** Special background methods may suppress method-level Protocol V2 UI events. */
|
|
192
191
|
protocolV2UiMode: ProtocolV2UiMode = 'auto';
|
|
193
192
|
|
|
194
193
|
protected throwIfAborted() {
|
|
@@ -217,7 +216,6 @@ export abstract class BaseMethod<Params = undefined> {
|
|
|
217
216
|
this.useDevice = true;
|
|
218
217
|
this.allowDeviceMode = [UI_REQUEST.NOT_INITIALIZE];
|
|
219
218
|
this.requireDeviceMode = [];
|
|
220
|
-
this.unlockPolicy = getProtocolV2UnlockPolicy(this.name);
|
|
221
219
|
}
|
|
222
220
|
|
|
223
221
|
abstract init(): void;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
EDeviceType,
|
|
3
|
+
EFirmwareType,
|
|
4
|
+
ERRORS,
|
|
5
|
+
HardwareError,
|
|
6
|
+
HardwareErrorCode,
|
|
7
|
+
} from '@onekeyfe/hd-shared';
|
|
2
8
|
import semver from 'semver';
|
|
3
9
|
|
|
4
10
|
import { BaseMethod } from './BaseMethod';
|
|
@@ -14,6 +20,10 @@ import {
|
|
|
14
20
|
validateFirmwareUpdatePlanForceTargets,
|
|
15
21
|
} from './firmware/FirmwareUpdatePlan';
|
|
16
22
|
import { getBridgeReleaseInfo } from '../utils/bridgeUpdate';
|
|
23
|
+
import {
|
|
24
|
+
buildProtocolV2ResourceUpdatePlan,
|
|
25
|
+
readProtocolV2ResourceInventory,
|
|
26
|
+
} from '../protocols/protocol-v2/resources';
|
|
17
27
|
import {
|
|
18
28
|
LoggerNames,
|
|
19
29
|
getDeviceFirmwareVersion,
|
|
@@ -101,6 +111,7 @@ function buildComponentRelease({
|
|
|
101
111
|
component,
|
|
102
112
|
currentVersions,
|
|
103
113
|
currentVerification,
|
|
114
|
+
checkFirmwareHash,
|
|
104
115
|
remotePayloadHash,
|
|
105
116
|
releaseRequired,
|
|
106
117
|
}: {
|
|
@@ -108,6 +119,7 @@ function buildComponentRelease({
|
|
|
108
119
|
component: IProtocolV2FirmwareComponent;
|
|
109
120
|
currentVersions: DeviceStateVersions;
|
|
110
121
|
currentVerification: Partial<DeviceFeaturesVerify>;
|
|
122
|
+
checkFirmwareHash: boolean;
|
|
111
123
|
remotePayloadHash: string | null | undefined;
|
|
112
124
|
releaseRequired: boolean;
|
|
113
125
|
}): ProtocolV2FirmwareComponentRelease {
|
|
@@ -136,7 +148,7 @@ function buildComponentRelease({
|
|
|
136
148
|
status = 'valid';
|
|
137
149
|
} else {
|
|
138
150
|
const currentHashKey = CURRENT_HASH_BY_COMPONENT_TARGET[componentTarget];
|
|
139
|
-
if (!currentHashKey) {
|
|
151
|
+
if (!checkFirmwareHash || !currentHashKey) {
|
|
140
152
|
status = 'valid';
|
|
141
153
|
} else {
|
|
142
154
|
const currentHash = normalizeHex(currentVerification[currentHashKey]);
|
|
@@ -175,12 +187,14 @@ type ProtocolV2FirmwareReleasePlan = {
|
|
|
175
187
|
export function buildProtocolV2FirmwareRelease({
|
|
176
188
|
currentVersions,
|
|
177
189
|
currentVerification = {},
|
|
190
|
+
checkFirmwareHash = false,
|
|
178
191
|
remotePayloadHashes = {},
|
|
179
192
|
firmwareType,
|
|
180
193
|
release,
|
|
181
194
|
}: {
|
|
182
195
|
currentVersions: DeviceStateVersions;
|
|
183
196
|
currentVerification?: Partial<DeviceFeaturesVerify>;
|
|
197
|
+
checkFirmwareHash?: boolean;
|
|
184
198
|
remotePayloadHashes?: Readonly<Record<string, string | null>>;
|
|
185
199
|
firmwareType: EFirmwareType;
|
|
186
200
|
release: IFirmwareReleaseInfo | undefined;
|
|
@@ -204,6 +218,7 @@ export function buildProtocolV2FirmwareRelease({
|
|
|
204
218
|
component,
|
|
205
219
|
currentVersions,
|
|
206
220
|
currentVerification,
|
|
221
|
+
checkFirmwareHash,
|
|
207
222
|
remotePayloadHash: Object.prototype.hasOwnProperty.call(remotePayloadHashes, configKey)
|
|
208
223
|
? remotePayloadHashes[configKey]
|
|
209
224
|
: normalizeHex(component.payloadHash),
|
|
@@ -230,9 +245,6 @@ export function buildProtocolV2FirmwareRelease({
|
|
|
230
245
|
const targetsToUpdate = components.flatMap(component =>
|
|
231
246
|
component.status === 'outdated' && component.updateTarget ? [component.updateTarget] : []
|
|
232
247
|
);
|
|
233
|
-
if (targetsToUpdate.length > 0 && release.resourceBundles?.length) {
|
|
234
|
-
targetsToUpdate.push('resource');
|
|
235
|
-
}
|
|
236
248
|
const uniqueTargetsToUpdate = Array.from(new Set(targetsToUpdate));
|
|
237
249
|
const hasUpgrade = uniqueTargetsToUpdate.length > 0;
|
|
238
250
|
const required = release.required && hasUpgrade;
|
|
@@ -358,13 +370,17 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
|
|
|
358
370
|
}
|
|
359
371
|
|
|
360
372
|
private async runProtocolV2(): Promise<AllFirmwareRelease> {
|
|
373
|
+
const { checkFirmwareHash = false, firmwareType: firmwareTypeParam } = this
|
|
374
|
+
.payload as CheckAllFirmwareReleaseParams;
|
|
361
375
|
const state = await this.device.getDeviceState({
|
|
362
|
-
refreshSections:
|
|
376
|
+
refreshSections: checkFirmwareHash
|
|
377
|
+
? ['identity', 'versions', 'verification']
|
|
378
|
+
: ['identity', 'versions'],
|
|
363
379
|
});
|
|
364
|
-
if (state.identity.deviceType !== 'pro2') {
|
|
380
|
+
if (state.identity.deviceType !== 'pro2' && state.identity.deviceType !== 'neo') {
|
|
365
381
|
throw ERRORS.TypedError(
|
|
366
382
|
HardwareErrorCode.DeviceNotSupportMethod,
|
|
367
|
-
'checkAllFirmwareRelease requires a Pro2 device for Protocol V2'
|
|
383
|
+
'checkAllFirmwareRelease requires a Pro2 or Neo device for Protocol V2'
|
|
368
384
|
);
|
|
369
385
|
}
|
|
370
386
|
|
|
@@ -376,16 +392,47 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
|
|
|
376
392
|
);
|
|
377
393
|
}
|
|
378
394
|
|
|
379
|
-
const { firmwareType: firmwareTypeParam } = this.payload as CheckAllFirmwareReleaseParams;
|
|
380
395
|
const firmwareType =
|
|
381
396
|
firmwareTypeParam ?? state.identity.firmwareType ?? EFirmwareType.Universal;
|
|
382
397
|
const release = DataManager.getFirmwareLatestRelease(features, firmwareType);
|
|
383
398
|
const plan = buildProtocolV2FirmwareRelease({
|
|
384
399
|
currentVersions: state.versions,
|
|
385
|
-
currentVerification: state.verification,
|
|
400
|
+
currentVerification: checkFirmwareHash ? state.verification : undefined,
|
|
401
|
+
checkFirmwareHash,
|
|
386
402
|
firmwareType,
|
|
387
403
|
release,
|
|
388
404
|
});
|
|
405
|
+
const resourceDeviceType =
|
|
406
|
+
state.identity.deviceType === 'neo' ? EDeviceType.Neo : EDeviceType.Pro2;
|
|
407
|
+
const resources = DataManager.getProtocolV2Resources(resourceDeviceType);
|
|
408
|
+
let resourceStatus: 'valid' | 'outdated' | 'unknown' = 'unknown';
|
|
409
|
+
if (resources?.length) {
|
|
410
|
+
const loaderMode = state.status.mode === 'bootloader' || state.status.mode === 'romloader';
|
|
411
|
+
// Application mode rejects host access to vol0:/bundles. Resource inventory is
|
|
412
|
+
// resolved after FirmwareUpdateV4 enters a loader instead of probing here.
|
|
413
|
+
if (loaderMode) {
|
|
414
|
+
try {
|
|
415
|
+
const inventory = await readProtocolV2ResourceInventory({
|
|
416
|
+
commands: this.device.getCommands(),
|
|
417
|
+
resources,
|
|
418
|
+
});
|
|
419
|
+
resourceStatus = buildProtocolV2ResourceUpdatePlan({
|
|
420
|
+
resources,
|
|
421
|
+
inventory,
|
|
422
|
+
mode: 'bootloader-recovery',
|
|
423
|
+
}).status;
|
|
424
|
+
} catch {
|
|
425
|
+
resourceStatus = buildProtocolV2ResourceUpdatePlan({
|
|
426
|
+
resources,
|
|
427
|
+
mode: 'bootloader-recovery',
|
|
428
|
+
}).status;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const targetsToUpdate = [
|
|
433
|
+
...plan.targetsToUpdate,
|
|
434
|
+
...(resourceStatus === 'outdated' ? (['resource'] as const) : []),
|
|
435
|
+
];
|
|
389
436
|
const firmwareStatus = plan.status === 'unavailable' ? 'unknown' : plan.status;
|
|
390
437
|
const emptyRelease = 'none' as const;
|
|
391
438
|
|
|
@@ -406,8 +453,11 @@ export default class CheckAllFirmwareRelease extends BaseMethod {
|
|
|
406
453
|
},
|
|
407
454
|
features,
|
|
408
455
|
protocol: 'V2',
|
|
409
|
-
deviceType:
|
|
456
|
+
deviceType: state.identity.deviceType,
|
|
410
457
|
...plan,
|
|
458
|
+
resourceStatus,
|
|
459
|
+
hasUpgrade: plan.hasUpgrade || resourceStatus === 'outdated',
|
|
460
|
+
targetsToUpdate,
|
|
411
461
|
};
|
|
412
462
|
}
|
|
413
463
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseMethod } from './BaseMethod';
|
|
2
|
+
|
|
3
|
+
export default class DetectDeviceConnectProtocol extends BaseMethod {
|
|
4
|
+
init() {
|
|
5
|
+
this.payload.forceProtocolDetection = true;
|
|
6
|
+
this.useDevicePassphraseState = false;
|
|
7
|
+
this.skipForceUpdateCheck = true;
|
|
8
|
+
this.unlockPolicy = 'none';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getSupportedProtocols() {
|
|
12
|
+
return ['V1', 'V2'] as const;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
run() {
|
|
16
|
+
return Promise.resolve(this.device.getProtocol());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -96,7 +96,8 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
|
|
|
96
96
|
await this.device.deviceConnector?.acquire(
|
|
97
97
|
this.device.originalDescriptor.id,
|
|
98
98
|
null,
|
|
99
|
-
true
|
|
99
|
+
true,
|
|
100
|
+
this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
|
|
100
101
|
);
|
|
101
102
|
// Bound each probe so a request the rebooting device never received
|
|
102
103
|
// frees the slot for the next tick instead of hanging into the
|
|
@@ -115,7 +116,10 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
|
|
|
115
116
|
} else {
|
|
116
117
|
const deviceDiff = await this.device.deviceConnector?.enumerate();
|
|
117
118
|
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
118
|
-
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId
|
|
119
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId, {
|
|
120
|
+
connectProtocol:
|
|
121
|
+
this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
|
|
122
|
+
});
|
|
119
123
|
|
|
120
124
|
if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
|
|
121
125
|
// should update current device from cache
|
|
@@ -304,7 +304,8 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
304
304
|
await this.device.deviceConnector?.acquire(
|
|
305
305
|
this.device.originalDescriptor.id,
|
|
306
306
|
null,
|
|
307
|
-
true
|
|
307
|
+
true,
|
|
308
|
+
this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
|
|
308
309
|
);
|
|
309
310
|
// Bound each probe so a request the rebooting device never received
|
|
310
311
|
// frees the slot for the next tick instead of hanging into the
|
|
@@ -343,7 +344,9 @@ export default class FirmwareUpdateV2 extends BaseMethod<Params> {
|
|
|
343
344
|
) {
|
|
344
345
|
const deviceDiff = await this.device.deviceConnector?.enumerate();
|
|
345
346
|
const devicesDescriptor = deviceDiff?.descriptors ?? [];
|
|
346
|
-
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId
|
|
347
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, connectId, {
|
|
348
|
+
connectProtocol: this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
|
|
349
|
+
});
|
|
347
350
|
|
|
348
351
|
if (deviceList.length === 1 && deviceList[0]?.isBootloader()) {
|
|
349
352
|
// should update current device from cache
|
|
@@ -705,7 +705,8 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
705
705
|
await this.device.deviceConnector?.acquire(
|
|
706
706
|
this.device.originalDescriptor.id,
|
|
707
707
|
null,
|
|
708
|
-
true
|
|
708
|
+
true,
|
|
709
|
+
this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType
|
|
709
710
|
);
|
|
710
711
|
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
711
712
|
await Promise.race([
|
|
@@ -742,7 +743,10 @@ export default class FirmwareUpdateV3 extends FirmwareUpdateBaseMethod<FirmwareU
|
|
|
742
743
|
webUsbCheckCount = 0;
|
|
743
744
|
}
|
|
744
745
|
|
|
745
|
-
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, this.connectId
|
|
746
|
+
const { deviceList } = await DevicePool.getDevices(devicesDescriptor, this.connectId, {
|
|
747
|
+
connectProtocol:
|
|
748
|
+
this.payload.connectProtocol ?? this.device.originalDescriptor.protocolType,
|
|
749
|
+
});
|
|
746
750
|
|
|
747
751
|
if (deviceList.length === 1) {
|
|
748
752
|
this.device.updateFromCache(deviceList[0]);
|