@onekeyfe/hd-core 1.1.34-alpha.1 → 1.1.34-alpha.3
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 +75 -0
- package/__tests__/DeviceCommands.test.ts +217 -0
- package/__tests__/RequestQueue.test.ts +140 -0
- package/__tests__/UploadPortfolio.test.ts +46 -0
- package/__tests__/connectSettings.test.ts +61 -0
- package/__tests__/device-lifecycle-events.test.ts +117 -0
- package/__tests__/device-pool-state.test.ts +132 -0
- package/__tests__/device-settings.test.ts +286 -0
- package/__tests__/device-state-mapper.test.ts +229 -0
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +191 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +15 -4
- package/__tests__/evmSignTransaction.test.ts +1 -1
- package/__tests__/evmSignTypedData.test.ts +1 -1
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-checkpoint.test.ts +105 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +73 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +17 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +358 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-recovery.test.ts +81 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +48 -31
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +403 -0
- package/__tests__/logBlockEvent.test.ts +61 -0
- package/__tests__/logger.test.ts +34 -0
- package/__tests__/open-wallet-session.test.ts +565 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +39 -0
- package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
- package/__tests__/protocol-v2-firmware-targets.test.ts +19 -0
- package/__tests__/protocol-v2.test.ts +6008 -0
- package/__tests__/protocolV2FileWrite.test.ts +67 -0
- package/__tests__/public-pro2-api-boundary.test.ts +66 -0
- package/__tests__/search-devices.test.ts +136 -0
- package/dist/api/BaseMethod.d.ts +12 -0
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckBootloaderRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/api/ClearSessionCache.d.ts +9 -0
- package/dist/api/ClearSessionCache.d.ts.map +1 -0
- package/dist/api/DirList.d.ts +10 -0
- package/dist/api/DirList.d.ts.map +1 -0
- package/dist/api/DirMake.d.ts +9 -0
- package/dist/api/DirMake.d.ts.map +1 -0
- package/dist/api/DirRemove.d.ts +9 -0
- package/dist/api/DirRemove.d.ts.map +1 -0
- package/dist/api/FileDelete.d.ts +9 -0
- package/dist/api/FileDelete.d.ts.map +1 -0
- package/dist/api/FileRead.d.ts +19 -0
- package/dist/api/FileRead.d.ts.map +1 -0
- package/dist/api/FileWrite.d.ts +25 -0
- package/dist/api/FileWrite.d.ts.map +1 -0
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +14 -3
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +10 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +75 -0
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -0
- package/dist/api/GetDeviceState.d.ts +7 -0
- package/dist/api/GetDeviceState.d.ts.map +1 -0
- package/dist/api/GetFeatures.d.ts +1 -1
- package/dist/api/GetFeatures.d.ts.map +1 -1
- package/dist/api/GetOnekeyFeatures.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts +14 -0
- package/dist/api/OpenWalletSession.d.ts.map +1 -0
- package/dist/api/PathInfo.d.ts +10 -0
- package/dist/api/PathInfo.d.ts.map +1 -0
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +5 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +18 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- package/dist/api/alephium/AlephiumGetAddress.d.ts +2 -6
- package/dist/api/alephium/AlephiumGetAddress.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignMessage.d.ts +2 -5
- package/dist/api/alephium/AlephiumSignMessage.d.ts.map +1 -1
- package/dist/api/alephium/AlephiumSignTransaction.d.ts +5 -8
- package/dist/api/alephium/AlephiumSignTransaction.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetAddress.d.ts +2 -9
- package/dist/api/benfen/BenfenGetAddress.d.ts.map +1 -1
- package/dist/api/benfen/BenfenGetPublicKey.d.ts +2 -9
- package/dist/api/benfen/BenfenGetPublicKey.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignMessage.d.ts +2 -8
- package/dist/api/benfen/BenfenSignMessage.d.ts.map +1 -1
- package/dist/api/benfen/BenfenSignTransaction.d.ts +2 -8
- package/dist/api/benfen/BenfenSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCGetAddress.d.ts +1 -11
- package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -11
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/btc/BTCSignMessage.d.ts +1 -15
- package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
- package/dist/api/btc/BTCSignPsbt.d.ts.map +1 -1
- package/dist/api/btc/BTCSignTransaction.d.ts +1 -11
- package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
- package/dist/api/btc/BTCVerifyMessage.d.ts +1 -11
- package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
- package/dist/api/btc/helpers/versionLimit.d.ts +2 -11
- package/dist/api/btc/helpers/versionLimit.d.ts.map +1 -1
- package/dist/api/cardano/CardanoSignTransaction.d.ts.map +1 -1
- package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -1
- package/dist/api/device/DeviceCancel.d.ts.map +1 -1
- package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
- package/dist/api/device/DeviceFullyUploadResource.d.ts +1 -2
- package/dist/api/device/DeviceFullyUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceLock.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts +1 -1
- package/dist/api/device/DeviceRebootToBoardloader.d.ts.map +1 -1
- package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceSupportFeatures.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 +7 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceUploadResource.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/dynex/DnxGetAddress.d.ts.map +1 -1
- package/dist/api/dynex/DnxSignTransaction.d.ts.map +1 -1
- package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
- package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -8
- package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts +1 -1
- package/dist/api/evm/latest/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/latest/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getAddress.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/getPublicKey.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signMessage.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts +1 -1
- package/dist/api/evm/legacyV1/signTypedData.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/signTypedHash.d.ts.map +1 -1
- package/dist/api/evm/legacyV1/verifyMessage.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +26 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareCheckpoint.d.ts +15 -0
- package/dist/api/firmware/FirmwareCheckpoint.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 +10 -1
- 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 +29 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/bootloaderHelper.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +11 -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/batchGetPublickeys.d.ts +3 -0
- package/dist/api/helpers/batchGetPublickeys.d.ts.map +1 -1
- package/dist/api/helpers/filesystemValidation.d.ts +10 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts +33 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -0
- package/dist/api/index.d.ts +29 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/lightning/LnurlAuth.d.ts +4 -0
- package/dist/api/lightning/LnurlAuth.d.ts.map +1 -1
- package/dist/api/neo/NeoGetAddress.d.ts +2 -8
- package/dist/api/neo/NeoGetAddress.d.ts.map +1 -1
- package/dist/api/neo/NeoSignTransaction.d.ts +2 -8
- package/dist/api/neo/NeoSignTransaction.d.ts.map +1 -1
- package/dist/api/nervos/NervosGetAddress.d.ts +2 -9
- package/dist/api/nervos/NervosGetAddress.d.ts.map +1 -1
- package/dist/api/nervos/NervosSignTransaction.d.ts +9 -12
- package/dist/api/nervos/NervosSignTransaction.d.ts.map +1 -1
- package/dist/api/nexa/NexaGetAddress.d.ts +2 -8
- package/dist/api/nexa/NexaGetAddress.d.ts.map +1 -1
- package/dist/api/nexa/NexaSignTransaction.d.ts +2 -9
- package/dist/api/nexa/NexaSignTransaction.d.ts.map +1 -1
- package/dist/api/polkadot/PolkadotGetAddress.d.ts +3 -0
- package/dist/api/polkadot/PolkadotGetAddress.d.ts.map +1 -1
- package/dist/api/polkadot/networks.d.ts +3 -0
- package/dist/api/polkadot/networks.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceInfoGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts +7 -0
- package/dist/api/protocol-v2/DeviceReboot.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts +28 -0
- package/dist/api/protocol-v2/DeviceSessionOpen.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +16 -0
- package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +12 -0
- package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts +6 -0
- package/dist/api/protocol-v2/DeviceStatusGet.d.ts.map +1 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts +26 -0
- package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemFormat.d.ts.map +1 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts +6 -0
- package/dist/api/protocol-v2/FilesystemPermissionFix.d.ts.map +1 -0
- package/dist/api/protocol-v2/Ping.d.ts +8 -0
- package/dist/api/protocol-v2/Ping.d.ts.map +1 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts +6 -0
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -0
- package/dist/api/protocol-v2/helpers.d.ts +42 -0
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -0
- package/dist/api/scdo/ScdoGetAddress.d.ts +2 -6
- package/dist/api/scdo/ScdoGetAddress.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignMessage.d.ts +2 -5
- package/dist/api/scdo/ScdoSignMessage.d.ts.map +1 -1
- package/dist/api/scdo/ScdoSignTransaction.d.ts +2 -5
- package/dist/api/scdo/ScdoSignTransaction.d.ts.map +1 -1
- package/dist/api/solana/SolGetAddress.d.ts +1 -0
- package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
- package/dist/api/solana/SolSignMessage.d.ts +3 -0
- package/dist/api/solana/SolSignMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignOffchainMessage.d.ts +3 -0
- package/dist/api/solana/SolSignOffchainMessage.d.ts.map +1 -1
- package/dist/api/solana/SolSignTransaction.d.ts +6 -0
- package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
- package/dist/api/stellar/StellarGetAddress.d.ts +2 -1
- package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +3 -2
- package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
- package/dist/api/sui/SuiGetAddress.d.ts +3 -0
- package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
- package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
- package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
- package/dist/api/sui/SuiSignMessage.d.ts +3 -0
- package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
- package/dist/api/sui/SuiSignTransaction.d.ts +5 -2
- package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
- package/dist/api/ton/TonGetAddress.d.ts +3 -0
- package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -0
- package/dist/api/ton/TonSignData.d.ts.map +1 -1
- package/dist/api/ton/TonSignMessage.d.ts +3 -0
- package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
- package/dist/api/ton/TonSignProof.d.ts +3 -0
- package/dist/api/ton/TonSignProof.d.ts.map +1 -1
- package/dist/api/tron/TronSignMessage.d.ts +3 -0
- package/dist/api/tron/TronSignMessage.d.ts.map +1 -1
- package/dist/api/tron/TronSignTransaction.d.ts +3 -0
- package/dist/api/tron/TronSignTransaction.d.ts.map +1 -1
- package/dist/api/utils.d.ts +2 -1
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/constants/index.d.ts +2 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/core/RequestQueue.d.ts +19 -1
- package/dist/core/RequestQueue.d.ts.map +1 -1
- package/dist/core/deviceEventRegistration.d.ts +11 -0
- package/dist/core/deviceEventRegistration.d.ts.map +1 -0
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +9 -5
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/MessagesConfig.d.ts +2 -2
- package/dist/data-manager/MessagesConfig.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts +5 -4
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +60 -16
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +16 -14
- 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/DeviceFeaturesState.d.ts +4 -0
- package/dist/device/DeviceFeaturesState.d.ts.map +1 -0
- package/dist/device/DevicePool.d.ts +4 -2
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/device/DeviceStateMapper.d.ts +13 -0
- package/dist/device/DeviceStateMapper.d.ts.map +1 -0
- package/dist/device/DeviceStateProjector.d.ts +7 -0
- package/dist/device/DeviceStateProjector.d.ts.map +1 -0
- package/dist/device/DeviceStateStore.d.ts +21 -0
- package/dist/device/DeviceStateStore.d.ts.map +1 -0
- package/dist/device/DeviceWalletSessionStore.d.ts +15 -0
- package/dist/device/DeviceWalletSessionStore.d.ts.map +1 -0
- package/dist/device/cloneDeviceState.d.ts +2 -0
- package/dist/device/cloneDeviceState.d.ts.map +1 -0
- package/dist/device/deviceIdentity.d.ts +5 -0
- package/dist/device/deviceIdentity.d.ts.map +1 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts +12 -0
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -0
- package/dist/deviceProfile/index.d.ts +2 -0
- package/dist/deviceProfile/index.d.ts.map +1 -0
- package/dist/events/call.d.ts +7 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/device.d.ts +11 -2
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +1 -0
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts +1 -0
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +26 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +1797 -451
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26905 -5606
- package/dist/inject.d.ts +3 -2
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts +2 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/deviceSession.d.ts +7 -0
- package/dist/protocols/protocol-v2/deviceSession.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/features.d.ts +88 -0
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/firmware.d.ts +15 -0
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/index.d.ts +5 -0
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -0
- 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/settingsUnlockPolicy.d.ts +16 -0
- package/dist/protocols/protocol-v2/settingsUnlockPolicy.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +39 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +11 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +21 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- 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/deviceSettings.d.ts +9 -0
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +1 -1
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -1
- 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 +114 -1
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +13 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +35 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +43 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/getDeviceState.d.ts +12 -0
- package/dist/types/api/getDeviceState.d.ts.map +1 -0
- package/dist/types/api/getFeatures.d.ts.map +1 -1
- package/dist/types/api/getOnekeyFeatures.d.ts.map +1 -1
- package/dist/types/api/getPassphraseState.d.ts +2 -1
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +48 -2
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +35 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +113 -0
- package/dist/types/api/protocolV2.d.ts.map +1 -0
- package/dist/types/api/searchDevices.d.ts +2 -2
- package/dist/types/api/searchDevices.d.ts.map +1 -1
- package/dist/types/api/sessionCache.d.ts +10 -0
- package/dist/types/api/sessionCache.d.ts.map +1 -0
- package/dist/types/device.d.ts +207 -5
- package/dist/types/device.d.ts.map +1 -1
- package/dist/types/params.d.ts +3 -0
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +33 -0
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/capabilitieUtils.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +13 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -0
- package/dist/utils/deviceFeaturesUtils.d.ts +17 -9
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +10 -8
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +2 -0
- package/dist/utils/deviceSettings.d.ts.map +1 -1
- package/dist/utils/deviceVersionUtils.d.ts +6 -5
- package/dist/utils/deviceVersionUtils.d.ts.map +1 -1
- package/dist/utils/findDefectiveBatchDevice.d.ts +1 -1
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +3 -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 +12 -0
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -0
- package/dist/utils/tracing.d.ts.map +1 -1
- package/dist/utils/versionUtils.d.ts +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +60 -23
- package/src/api/CheckAllFirmwareRelease.ts +16 -3
- package/src/api/CheckBootloaderRelease.ts +1 -2
- package/src/api/CheckFirmwareRelease.ts +1 -2
- package/src/api/ClearSessionCache.ts +28 -0
- package/src/api/DirList.ts +33 -0
- package/src/api/DirMake.ts +23 -0
- package/src/api/DirRemove.ts +23 -0
- package/src/api/FileDelete.ts +23 -0
- package/src/api/FileRead.ts +183 -0
- package/src/api/FileWrite.ts +71 -0
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +354 -148
- package/src/api/FirmwareUpdateV3.ts +376 -62
- package/src/api/FirmwareUpdateV4.ts +2279 -0
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +12 -4
- package/src/api/GetOnekeyFeatures.ts +15 -3
- package/src/api/GetPassphraseState.ts +9 -10
- package/src/api/OpenWalletSession.ts +211 -0
- package/src/api/PathInfo.ts +41 -0
- package/src/api/PromptWebDeviceAccess.ts +10 -1
- package/src/api/SearchDevices.ts +33 -3
- package/src/api/UploadPortfolio.ts +50 -0
- package/src/api/alephium/AlephiumGetAddress.ts +6 -2
- package/src/api/alephium/AlephiumSignMessage.ts +6 -1
- package/src/api/alephium/AlephiumSignTransaction.ts +15 -4
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +25 -21
- package/src/api/aptos/AptosGetAddress.ts +2 -3
- package/src/api/benfen/BenfenGetAddress.ts +11 -7
- package/src/api/benfen/BenfenGetPublicKey.ts +6 -2
- package/src/api/benfen/BenfenSignMessage.ts +6 -1
- package/src/api/benfen/BenfenSignTransaction.ts +6 -1
- package/src/api/btc/BTCGetPublicKey.ts +3 -2
- package/src/api/btc/BTCSignPsbt.ts +1 -2
- package/src/api/btc/helpers/versionLimit.ts +7 -1
- package/src/api/cardano/CardanoSignTransaction.ts +2 -4
- package/src/api/conflux/ConfluxSignTransaction.ts +5 -2
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +24 -0
- package/src/api/device/DeviceFullyUploadResource.ts +6 -7
- package/src/api/device/DeviceLock.ts +2 -3
- package/src/api/device/DeviceRebootToBoardloader.ts +11 -1
- package/src/api/device/DeviceRebootToBootloader.ts +11 -1
- package/src/api/device/DeviceSettings.ts +121 -0
- package/src/api/device/DeviceSupportFeatures.ts +2 -13
- package/src/api/device/DeviceUnlock.ts +9 -0
- package/src/api/device/DeviceUpdateBootloader.ts +175 -11
- package/src/api/device/DeviceUploadResource.ts +4 -5
- package/src/api/device/DeviceVerify.ts +1 -2
- package/src/api/device/DeviceWipe.ts +19 -0
- package/src/api/dynex/DnxGetAddress.ts +6 -0
- package/src/api/dynex/DnxSignTransaction.ts +6 -0
- package/src/api/evm/EVMGetAddress.ts +1 -1
- package/src/api/evm/EVMGetPublicKey.ts +3 -4
- package/src/api/evm/EVMSignMessage.ts +1 -1
- package/src/api/evm/EVMSignMessageEIP712.ts +14 -1
- package/src/api/evm/EVMSignTransaction.ts +1 -1
- package/src/api/evm/EVMSignTypedData.ts +30 -18
- package/src/api/evm/EVMVerifyMessage.ts +1 -1
- package/src/api/evm/latest/signTypedHash.ts +2 -4
- package/src/api/evm/legacyV1/getAddress.ts +5 -3
- package/src/api/evm/legacyV1/getPublicKey.ts +5 -3
- package/src/api/evm/legacyV1/signMessage.ts +5 -3
- package/src/api/evm/legacyV1/signTypedData.ts +9 -8
- package/src/api/evm/legacyV1/signTypedHash.ts +7 -7
- package/src/api/evm/legacyV1/verifyMessage.ts +5 -3
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareCheckpoint.ts +188 -0
- package/src/api/firmware/FirmwareHostBinding.ts +108 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -15
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +13 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +729 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +403 -0
- package/src/api/firmware/bootloaderHelper.ts +3 -2
- package/src/api/firmware/getBinary.ts +1 -1
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/releaseHelper.ts +3 -3
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +148 -34
- package/src/api/helpers/batchGetPublickeys.ts +51 -6
- package/src/api/helpers/filesystemValidation.ts +112 -0
- package/src/api/helpers/protocolV2FileWrite.ts +193 -0
- package/src/api/index.ts +32 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +2 -3
- package/src/api/lightning/LnurlAuth.ts +4 -0
- package/src/api/neo/NeoGetAddress.ts +6 -1
- package/src/api/neo/NeoSignTransaction.ts +6 -1
- package/src/api/nervos/NervosGetAddress.ts +6 -2
- package/src/api/nervos/NervosSignTransaction.ts +14 -4
- package/src/api/nexa/NexaGetAddress.ts +6 -2
- package/src/api/nexa/NexaSignTransaction.ts +11 -12
- package/src/api/polkadot/networks.ts +9 -0
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +20 -0
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +61 -0
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +55 -0
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +18 -0
- package/src/api/protocol-v2/DeviceInfoGet.ts +145 -0
- package/src/api/protocol-v2/DeviceReboot.ts +26 -0
- package/src/api/protocol-v2/DeviceSessionOpen.ts +102 -0
- package/src/api/protocol-v2/DeviceSettingsGet.ts +18 -0
- package/src/api/protocol-v2/DeviceSettingsPageShow.ts +70 -0
- package/src/api/protocol-v2/DeviceSettingsSet.ts +44 -0
- package/src/api/protocol-v2/DeviceStatusGet.ts +16 -0
- package/src/api/protocol-v2/DeviceUploadWallpaper.ts +131 -0
- package/src/api/protocol-v2/FilesystemFormat.ts +19 -0
- package/src/api/protocol-v2/FilesystemPermissionFix.ts +16 -0
- package/src/api/protocol-v2/Ping.ts +18 -0
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +16 -0
- package/src/api/protocol-v2/helpers.ts +203 -0
- package/src/api/scdo/ScdoGetAddress.ts +6 -2
- package/src/api/scdo/ScdoSignMessage.ts +6 -1
- package/src/api/scdo/ScdoSignTransaction.ts +6 -2
- package/src/api/solana/SolGetAddress.ts +4 -0
- package/src/api/solana/SolSignMessage.ts +3 -0
- package/src/api/solana/SolSignOffchainMessage.ts +3 -0
- package/src/api/solana/SolSignTransaction.ts +6 -0
- package/src/api/stellar/StellarGetAddress.ts +10 -1
- package/src/api/stellar/StellarSignTransaction.ts +14 -1
- package/src/api/sui/SuiGetAddress.ts +5 -3
- package/src/api/sui/SuiGetPublicKey.ts +3 -0
- package/src/api/sui/SuiSignMessage.ts +3 -0
- package/src/api/sui/SuiSignTransaction.ts +14 -12
- package/src/api/ton/TonGetAddress.ts +3 -0
- package/src/api/ton/TonSignData.ts +6 -3
- package/src/api/ton/TonSignMessage.ts +6 -5
- package/src/api/ton/TonSignProof.ts +3 -0
- package/src/api/tron/TronSignMessage.ts +4 -1
- package/src/api/tron/TronSignTransaction.ts +3 -0
- package/src/api/utils.ts +7 -3
- package/src/api/xrp/XrpSignTransaction.ts +1 -1
- package/src/constants/index.ts +7 -1
- package/src/core/RequestQueue.ts +124 -4
- package/src/core/deviceEventRegistration.ts +23 -0
- package/src/core/index.ts +255 -116
- package/src/data/messages/messages-protocol-v2.json +13544 -0
- package/src/data-manager/DataManager.ts +61 -49
- package/src/data-manager/MessagesConfig.ts +14 -14
- package/src/data-manager/TransportManager.ts +38 -12
- package/src/data-manager/connectSettings.ts +15 -0
- package/src/device/Device.ts +759 -164
- package/src/device/DeviceCommands.ts +245 -36
- package/src/device/DeviceConnector.ts +29 -4
- package/src/device/DeviceFeaturesState.ts +34 -0
- package/src/device/DevicePool.ts +69 -21
- package/src/device/DeviceStateMapper.ts +348 -0
- package/src/device/DeviceStateProjector.ts +95 -0
- package/src/device/DeviceStateStore.ts +201 -0
- package/src/device/DeviceWalletSessionStore.ts +78 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +391 -0
- package/src/deviceProfile/index.ts +4 -0
- package/src/events/call.ts +6 -0
- package/src/events/core.ts +2 -0
- package/src/events/device.ts +17 -1
- package/src/events/iframe.ts +1 -0
- package/src/events/logBlockEvent.ts +30 -0
- package/src/events/ui-request.ts +32 -2
- package/src/index.ts +9 -0
- package/src/inject.ts +75 -3
- package/src/lowLevelInject.ts +8 -1
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +163 -0
- package/src/protocols/protocol-v2/firmware.ts +21 -0
- package/src/protocols/protocol-v2/index.ts +18 -0
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/settingsUnlockPolicy.ts +61 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +210 -0
- package/src/protocols/protocol-v2/unlockRetry.ts +76 -0
- package/src/protocols/protocol-v2/walletSession.ts +202 -0
- package/src/topLevelInject.ts +7 -1
- package/src/types/api/checkAllFirmwareRelease.ts +4 -2
- package/src/types/api/deviceSettings.ts +9 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- package/src/types/api/deviceUpdateBootloader.ts +10 -1
- package/src/types/api/export.ts +25 -0
- package/src/types/api/firmwareUpdate.ts +163 -1
- package/src/types/api/firmwareUpdateCapabilities.ts +13 -0
- package/src/types/api/firmwareUpdatePlan.ts +52 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +55 -0
- package/src/types/api/getDeviceState.ts +19 -0
- package/src/types/api/getFeatures.ts +3 -0
- package/src/types/api/getOnekeyFeatures.ts +3 -0
- package/src/types/api/getPassphraseState.ts +10 -2
- package/src/types/api/index.ts +89 -2
- package/src/types/api/openWalletSession.ts +54 -0
- package/src/types/api/protocolV2.ts +244 -0
- package/src/types/api/searchDevices.ts +2 -2
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +266 -5
- package/src/types/params.ts +11 -0
- package/src/types/settings.ts +54 -29
- package/src/utils/capabilitieUtils.ts +1 -2
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +122 -84
- package/src/utils/deviceInfoUtils.ts +38 -87
- package/src/utils/deviceSettings.ts +48 -0
- package/src/utils/deviceVersionUtils.ts +25 -62
- package/src/utils/findDefectiveBatchDevice.ts +8 -8
- package/src/utils/homescreen.ts +10 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/pro2Wallpaper.ts +109 -0
- package/src/utils/tracing.ts +3 -1
package/src/core/index.ts
CHANGED
|
@@ -17,11 +17,8 @@ import {
|
|
|
17
17
|
import {
|
|
18
18
|
LoggerNames,
|
|
19
19
|
enableLog,
|
|
20
|
-
getDeviceBLEFirmwareVersion,
|
|
21
|
-
getDeviceFirmwareVersion,
|
|
22
|
-
getFirmwareType,
|
|
23
20
|
getLogger,
|
|
24
|
-
|
|
21
|
+
isMethodVersionRangeUnsupported,
|
|
25
22
|
setLoggerPostMessage,
|
|
26
23
|
wait,
|
|
27
24
|
} from '../utils';
|
|
@@ -29,7 +26,6 @@ import {
|
|
|
29
26
|
findDefectiveBatchDevice,
|
|
30
27
|
getDefectiveDeviceInfo,
|
|
31
28
|
} from '../utils/findDefectiveBatchDevice';
|
|
32
|
-
import { supportNewPassphrase } from '../utils/deviceFeaturesUtils';
|
|
33
29
|
import {
|
|
34
30
|
cleanupSdkInstance,
|
|
35
31
|
completeRequestContext,
|
|
@@ -40,6 +36,7 @@ import {
|
|
|
40
36
|
updateRequestContext,
|
|
41
37
|
} from '../utils/tracing';
|
|
42
38
|
import { Device } from '../device/Device';
|
|
39
|
+
import { checkLiveDeviceId } from '../device/deviceIdentity';
|
|
43
40
|
import { DeviceList } from '../device/DeviceList';
|
|
44
41
|
import { DevicePool } from '../device/DevicePool';
|
|
45
42
|
import { PollingStateManager } from './PollingStateManager';
|
|
@@ -55,22 +52,25 @@ import {
|
|
|
55
52
|
createDeviceMessage,
|
|
56
53
|
createResponseMessage,
|
|
57
54
|
createUiMessage,
|
|
55
|
+
getLogBlockLabel,
|
|
58
56
|
} from '../events';
|
|
59
57
|
import TransportManager from '../data-manager/TransportManager';
|
|
60
58
|
import DeviceConnector from '../device/DeviceConnector';
|
|
61
59
|
import RequestQueue from './RequestQueue';
|
|
60
|
+
import { registerHardwareUiEventListeners } from './deviceEventRegistration';
|
|
62
61
|
import { getSynchronize } from '../utils/getSynchronize';
|
|
62
|
+
import { runMethodWithUnlockRetry } from '../protocols/protocol-v2/unlockRetry';
|
|
63
|
+
import {
|
|
64
|
+
ProtocolV2UiInteractionCoordinator,
|
|
65
|
+
isProtocolV2UiEnabled,
|
|
66
|
+
} from '../protocols/protocol-v2/uiInteraction';
|
|
63
67
|
|
|
64
|
-
import type { ConnectSettings, KnownDevice } from '../types';
|
|
68
|
+
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
65
69
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
66
70
|
import type { DeviceEvents, InitOptions, RunOptions } from '../device/Device';
|
|
67
71
|
import type { SdkTracingContext } from '../utils/tracing';
|
|
68
72
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
69
|
-
import type {
|
|
70
|
-
Features,
|
|
71
|
-
LowlevelTransportSharedPlugin,
|
|
72
|
-
OneKeyDeviceInfo,
|
|
73
|
-
} from '@onekeyfe/hd-transport';
|
|
73
|
+
import type { LowlevelTransportSharedPlugin, OneKeyDeviceInfo } from '@onekeyfe/hd-transport';
|
|
74
74
|
import type { BaseMethod } from '../api/BaseMethod';
|
|
75
75
|
|
|
76
76
|
const Log = getLogger(LoggerNames.Core);
|
|
@@ -99,12 +99,14 @@ function hasDeriveCardano(method: BaseMethod): boolean {
|
|
|
99
99
|
|
|
100
100
|
const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
101
101
|
initSession: method?.payload.initSession,
|
|
102
|
-
passphraseState: method?.payload.passphraseState,
|
|
102
|
+
passphraseState: method?.payload.useEmptyPassphrase ? undefined : method?.payload.passphraseState,
|
|
103
103
|
deviceId: method?.payload.deviceId,
|
|
104
104
|
deriveCardano: method && hasDeriveCardano(method),
|
|
105
|
+
connectProtocol: method?.payload.connectProtocol,
|
|
106
|
+
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
105
107
|
});
|
|
106
108
|
|
|
107
|
-
let _core: Core;
|
|
109
|
+
let _core: Core | undefined;
|
|
108
110
|
let _deviceList: DeviceList | undefined;
|
|
109
111
|
let _connector: DeviceConnector | undefined;
|
|
110
112
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
@@ -148,7 +150,7 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
// find api method
|
|
151
|
-
let method
|
|
153
|
+
let method!: BaseMethod;
|
|
152
154
|
try {
|
|
153
155
|
method = findMethod(message as IFrameCallMessage);
|
|
154
156
|
method.connector = _connector;
|
|
@@ -164,6 +166,10 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
164
166
|
|
|
165
167
|
method.init();
|
|
166
168
|
} catch (error) {
|
|
169
|
+
if (method) {
|
|
170
|
+
completeMethodRequestContext(method, error);
|
|
171
|
+
method.dispose();
|
|
172
|
+
}
|
|
167
173
|
return Promise.reject(error);
|
|
168
174
|
}
|
|
169
175
|
|
|
@@ -190,34 +196,25 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
190
196
|
// );
|
|
191
197
|
// }
|
|
192
198
|
|
|
193
|
-
const { requestQueue, methodSynchronize } = context;
|
|
194
|
-
const error = await methodSynchronize(() => {
|
|
195
|
-
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
196
|
-
const task = requestQueue.getTask(requestId);
|
|
197
|
-
Log.debug(
|
|
198
|
-
'pre request task: ',
|
|
199
|
-
`task?.id: ${task?.id},
|
|
200
|
-
task?.method.connectId: ${task?.method.connectId},
|
|
201
|
-
task?.method.deviceId: ${task?.method.deviceId},
|
|
202
|
-
task?.method.name: ${task?.method.name}`
|
|
203
|
-
);
|
|
204
|
-
// if (task) {
|
|
205
|
-
// return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceBusy));
|
|
206
|
-
// }
|
|
207
|
-
}
|
|
208
|
-
return null;
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
if (error) {
|
|
212
|
-
return createResponseMessage(method.responseID, false, { error });
|
|
213
|
-
}
|
|
214
|
-
|
|
215
199
|
// only the pre-warm signal (PreInitialize) forks here; normal methods fall
|
|
216
200
|
// through to onCallDevice below, so the pre-warm dedup/guards never touch them
|
|
217
201
|
if (method.isPreWarmSignal) {
|
|
218
202
|
return handlePreWarmSignal(context, message, method);
|
|
219
203
|
}
|
|
220
204
|
|
|
205
|
+
const { requestQueue, methodSynchronize } = context;
|
|
206
|
+
const admission = await methodSynchronize(
|
|
207
|
+
() => requestQueue.admitTask(method),
|
|
208
|
+
method.connectId ?? method.deviceId ?? 'unknown-device'
|
|
209
|
+
);
|
|
210
|
+
if (admission.status === 'busy') {
|
|
211
|
+
const error = ERRORS.TypedError(HardwareErrorCode.DeviceBusy);
|
|
212
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
213
|
+
completeMethodRequestContext(method, error);
|
|
214
|
+
method.dispose();
|
|
215
|
+
return createResponseMessage(method.responseID, false, { error });
|
|
216
|
+
}
|
|
217
|
+
|
|
221
218
|
return onCallDevice(context, message, method);
|
|
222
219
|
};
|
|
223
220
|
|
|
@@ -229,9 +226,16 @@ const handlePreWarmSignal = async (
|
|
|
229
226
|
message: CoreMessage,
|
|
230
227
|
method: BaseMethod
|
|
231
228
|
): Promise<any> => {
|
|
229
|
+
const createAckResponse = () => {
|
|
230
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
231
|
+
completeMethodRequestContext(method);
|
|
232
|
+
method.dispose();
|
|
233
|
+
return createResponseMessage(method.responseID, true, true);
|
|
234
|
+
};
|
|
235
|
+
|
|
232
236
|
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
233
237
|
if (!method.connectId) {
|
|
234
|
-
return
|
|
238
|
+
return createAckResponse();
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
const key = method.getPreWarmKey();
|
|
@@ -244,12 +248,12 @@ const handlePreWarmSignal = async (
|
|
|
244
248
|
} catch {
|
|
245
249
|
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
246
250
|
}
|
|
247
|
-
return
|
|
251
|
+
return createAckResponse();
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
const doneAt = preWarmDoneAt.get(key);
|
|
251
255
|
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
252
|
-
return
|
|
256
|
+
return createAckResponse();
|
|
253
257
|
}
|
|
254
258
|
|
|
255
259
|
const run = onCallDevice(context, message, method);
|
|
@@ -330,7 +334,7 @@ const onCallDevice = async (
|
|
|
330
334
|
|
|
331
335
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
332
336
|
|
|
333
|
-
const task = requestQueue.createTask(method);
|
|
337
|
+
const task = requestQueue.getTask(method.responseID) ?? requestQueue.createTask(method);
|
|
334
338
|
|
|
335
339
|
// Pre-warm holds the device as a per-connectId callback task so a concurrent
|
|
336
340
|
// real call waits (before ensureConnected) instead of racing its Initialize.
|
|
@@ -357,7 +361,7 @@ const onCallDevice = async (
|
|
|
357
361
|
);
|
|
358
362
|
} catch (e) {
|
|
359
363
|
preWarmCallbackTask?.resolve();
|
|
360
|
-
|
|
364
|
+
Log.debug('ensureConnected error: ', e);
|
|
361
365
|
|
|
362
366
|
completeMethodRequestContext(method, e);
|
|
363
367
|
|
|
@@ -374,6 +378,10 @@ const onCallDevice = async (
|
|
|
374
378
|
if (method.payload?.onlyConnectBleDevice) {
|
|
375
379
|
preWarmCallbackTask?.resolve();
|
|
376
380
|
Log.debug('Call API - only connect ble device: ', device?.mainId);
|
|
381
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
382
|
+
requestQueue.releaseTask(method.responseID);
|
|
383
|
+
completeMethodRequestContext(method);
|
|
384
|
+
method.dispose();
|
|
377
385
|
return createResponseMessage(method.responseID, true, null);
|
|
378
386
|
}
|
|
379
387
|
|
|
@@ -394,18 +402,23 @@ const onCallDevice = async (
|
|
|
394
402
|
);
|
|
395
403
|
}
|
|
396
404
|
|
|
397
|
-
device
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
405
|
+
registerHardwareUiEventListeners(device, {
|
|
406
|
+
pin: onDevicePinHandler,
|
|
407
|
+
button: onDeviceButtonHandler,
|
|
408
|
+
passphrase: message.payload.useEmptyPassphrase
|
|
409
|
+
? onEmptyPassphraseHandler
|
|
410
|
+
: onDevicePassphraseHandler,
|
|
411
|
+
passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
|
|
412
|
+
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
413
|
+
});
|
|
404
414
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
415
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
405
416
|
device.on(
|
|
406
417
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
407
418
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
408
419
|
);
|
|
420
|
+
|
|
421
|
+
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
409
422
|
device.on(
|
|
410
423
|
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
411
424
|
onSelectDeviceForSwitchFirmwareWebDeviceHandler
|
|
@@ -420,13 +433,24 @@ const onCallDevice = async (
|
|
|
420
433
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
421
434
|
|
|
422
435
|
const inner = async (): Promise<void> => {
|
|
436
|
+
// The protocol is established after acquire/initialize. Reject Protocol V2-only
|
|
437
|
+
// methods on other devices through BaseMethod.requireProtocolV2.
|
|
438
|
+
if (method.requireProtocolV2 && !device.isProtocolV2()) {
|
|
439
|
+
throw createDeviceNotSupportMethodError(method.name, device.getCurrentFirmwareType());
|
|
440
|
+
}
|
|
441
|
+
|
|
423
442
|
// check firmware version
|
|
424
|
-
const versionRange =
|
|
425
|
-
device.features,
|
|
443
|
+
const versionRange = device.getCurrentMethodVersionRange(
|
|
426
444
|
type => method.getVersionRange()[type]
|
|
427
445
|
);
|
|
428
|
-
|
|
429
|
-
|
|
446
|
+
const currentFirmwareVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
447
|
+
const currentBleVersion = device.getCurrentBLEFirmwareVersionString() ?? '0.0.0';
|
|
448
|
+
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
449
|
+
let newVersionStatus: ReturnType<typeof DataManager.getFirmwareStatus> | undefined;
|
|
450
|
+
|
|
451
|
+
// Defective-batch and forced-update gates depend on V1 features/remote config.
|
|
452
|
+
// Pro2 joins after DataManager supports its profile firmwareStatus.
|
|
453
|
+
if (device.features && !device.isProtocolV2()) {
|
|
430
454
|
await DataManager.checkAndReloadData();
|
|
431
455
|
|
|
432
456
|
// 检测故障固件设备
|
|
@@ -443,12 +467,9 @@ const onCallDevice = async (
|
|
|
443
467
|
}
|
|
444
468
|
}
|
|
445
469
|
|
|
446
|
-
|
|
447
|
-
const newVersionStatus = DataManager.getFirmwareStatus(device.features, deviceFirmwareType);
|
|
470
|
+
newVersionStatus = DataManager.getFirmwareStatus(device.features, deviceFirmwareType);
|
|
448
471
|
const bleVersionStatus = DataManager.getBLEFirmwareStatus(device.features);
|
|
449
472
|
|
|
450
|
-
const currentFirmwareVersion = getDeviceFirmwareVersion(device.features).join('.');
|
|
451
|
-
const currentBleVersion = getDeviceBLEFirmwareVersion(device.features).join('.');
|
|
452
473
|
if (
|
|
453
474
|
(newVersionStatus === 'required' || bleVersionStatus === 'required') &&
|
|
454
475
|
method.skipForceUpdateCheck === false
|
|
@@ -474,42 +495,43 @@ const onCallDevice = async (
|
|
|
474
495
|
currentVersions
|
|
475
496
|
);
|
|
476
497
|
}
|
|
498
|
+
}
|
|
477
499
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
semver.lt(currentFirmwareVersion, versionRange.min)
|
|
482
|
-
) {
|
|
483
|
-
if (newVersionStatus === 'none' || newVersionStatus === 'valid') {
|
|
484
|
-
throw createNewFirmwareUnReleaseHardwareError({
|
|
485
|
-
currentVersion: currentFirmwareVersion,
|
|
486
|
-
requireVersion: versionRange.min,
|
|
487
|
-
methodName: method.name,
|
|
488
|
-
firmwareType: getFirmwareType(device.features),
|
|
489
|
-
});
|
|
490
|
-
}
|
|
500
|
+
if (isMethodVersionRangeUnsupported(versionRange)) {
|
|
501
|
+
throw createDeviceNotSupportMethodError(method.name, deviceFirmwareType);
|
|
502
|
+
}
|
|
491
503
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
if (
|
|
502
|
-
versionRange.max &&
|
|
503
|
-
semver.valid(versionRange.max) &&
|
|
504
|
-
semver.gte(currentFirmwareVersion, versionRange.max)
|
|
505
|
-
) {
|
|
506
|
-
return Promise.reject(
|
|
507
|
-
createDeprecatedHardwareError(currentFirmwareVersion, versionRange.max, method.name)
|
|
508
|
-
);
|
|
504
|
+
if (versionRange) {
|
|
505
|
+
if (semver.valid(versionRange.min) && semver.lt(currentFirmwareVersion, versionRange.min)) {
|
|
506
|
+
if (newVersionStatus === 'none' || newVersionStatus === 'valid') {
|
|
507
|
+
throw createNewFirmwareUnReleaseHardwareError({
|
|
508
|
+
currentVersion: currentFirmwareVersion,
|
|
509
|
+
requireVersion: versionRange.min,
|
|
510
|
+
methodName: method.name,
|
|
511
|
+
firmwareType: deviceFirmwareType,
|
|
512
|
+
});
|
|
509
513
|
}
|
|
510
|
-
|
|
511
|
-
|
|
514
|
+
|
|
515
|
+
return Promise.reject(
|
|
516
|
+
createNeedUpgradeFirmwareHardwareError({
|
|
517
|
+
currentVersion: currentFirmwareVersion,
|
|
518
|
+
requireVersion: versionRange.min,
|
|
519
|
+
methodName: method.name,
|
|
520
|
+
firmwareType: deviceFirmwareType,
|
|
521
|
+
})
|
|
522
|
+
);
|
|
512
523
|
}
|
|
524
|
+
if (
|
|
525
|
+
versionRange.max &&
|
|
526
|
+
semver.valid(versionRange.max) &&
|
|
527
|
+
semver.gte(currentFirmwareVersion, versionRange.max)
|
|
528
|
+
) {
|
|
529
|
+
return Promise.reject(
|
|
530
|
+
createDeprecatedHardwareError(currentFirmwareVersion, versionRange.max, method.name)
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
} else if (method.strictCheckDeviceSupport) {
|
|
534
|
+
throw createDeviceNotSupportMethodError(method.name, deviceFirmwareType);
|
|
513
535
|
}
|
|
514
536
|
|
|
515
537
|
// check call method mode
|
|
@@ -530,7 +552,7 @@ const onCallDevice = async (
|
|
|
530
552
|
}
|
|
531
553
|
|
|
532
554
|
if (method.deviceId && method.checkDeviceId) {
|
|
533
|
-
const isSameDeviceID = device
|
|
555
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
534
556
|
if (!isSameDeviceID) {
|
|
535
557
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
536
558
|
}
|
|
@@ -547,16 +569,16 @@ const onCallDevice = async (
|
|
|
547
569
|
method.checkDeviceSupportFeature();
|
|
548
570
|
|
|
549
571
|
// reconfigure messages
|
|
550
|
-
if (_deviceList) {
|
|
572
|
+
if (_deviceList && device.features && !device.isProtocolV2()) {
|
|
551
573
|
await TransportManager.reconfigure(device.features);
|
|
552
574
|
}
|
|
553
575
|
|
|
554
576
|
// Check to see if it is safe to use Passphrase
|
|
555
577
|
checkPassphraseEnableState(method, device.features);
|
|
556
578
|
|
|
557
|
-
if (
|
|
579
|
+
if (shouldCheckPassphraseState(method, device)) {
|
|
558
580
|
// check version
|
|
559
|
-
const support = supportNewPassphrase(
|
|
581
|
+
const support = device.supportNewPassphrase();
|
|
560
582
|
if (!support.support) {
|
|
561
583
|
return Promise.reject(
|
|
562
584
|
ERRORS.TypedError(
|
|
@@ -607,7 +629,11 @@ const onCallDevice = async (
|
|
|
607
629
|
method.device?.commands?.checkDisposed();
|
|
608
630
|
|
|
609
631
|
try {
|
|
610
|
-
const response: object = await
|
|
632
|
+
const response: object = await runMethodWithUnlockRetry(
|
|
633
|
+
method,
|
|
634
|
+
device,
|
|
635
|
+
protocolV2UiCoordinator
|
|
636
|
+
);
|
|
611
637
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
612
638
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
613
639
|
completeMethodRequestContext(method);
|
|
@@ -624,6 +650,8 @@ const onCallDevice = async (
|
|
|
624
650
|
) {
|
|
625
651
|
throw error;
|
|
626
652
|
}
|
|
653
|
+
} finally {
|
|
654
|
+
protocolV2UiCoordinator.close();
|
|
627
655
|
}
|
|
628
656
|
};
|
|
629
657
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -633,8 +661,9 @@ const onCallDevice = async (
|
|
|
633
661
|
skipInitialize: canSkipInitialize(method, device),
|
|
634
662
|
...parseInitOptions(method),
|
|
635
663
|
};
|
|
636
|
-
const
|
|
637
|
-
task.callPromise = createDeferred<any>(
|
|
664
|
+
const deviceRunPromise = device.run(inner, runOptions);
|
|
665
|
+
task.callPromise = createDeferred<any>();
|
|
666
|
+
deviceRunPromise.catch(error => task.callPromise?.reject(error));
|
|
638
667
|
|
|
639
668
|
try {
|
|
640
669
|
return await task.callPromise.promise;
|
|
@@ -642,6 +671,8 @@ const onCallDevice = async (
|
|
|
642
671
|
Log.debug('Device Run Error: ', e);
|
|
643
672
|
completeMethodRequestContext(method, e);
|
|
644
673
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
674
|
+
} finally {
|
|
675
|
+
await deviceRunPromise.catch(() => undefined);
|
|
645
676
|
}
|
|
646
677
|
} catch (error) {
|
|
647
678
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
@@ -677,7 +708,9 @@ const onCallDevice = async (
|
|
|
677
708
|
|
|
678
709
|
requestQueue.releaseTask(method.responseID);
|
|
679
710
|
|
|
680
|
-
|
|
711
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
712
|
+
closePopup();
|
|
713
|
+
}
|
|
681
714
|
|
|
682
715
|
cleanup();
|
|
683
716
|
|
|
@@ -723,17 +756,27 @@ function initDevice(method: BaseMethod) {
|
|
|
723
756
|
let device: Device | typeof undefined;
|
|
724
757
|
const allDevices = _deviceList.allDevices();
|
|
725
758
|
|
|
726
|
-
if (method.payload?.detectBootloaderDevice && allDevices.some(d => d.
|
|
759
|
+
if (method.payload?.detectBootloaderDevice && allDevices.some(d => d.isBootloader())) {
|
|
727
760
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceDetectInBootloaderMode);
|
|
728
761
|
}
|
|
729
762
|
|
|
730
763
|
if (method.connectId) {
|
|
731
764
|
device = _deviceList.getDevice(method.connectId);
|
|
765
|
+
if (!device && method.name === 'firmwareUpdateV4' && allDevices.length === 1) {
|
|
766
|
+
const [singleDevice] = allDevices;
|
|
767
|
+
if (singleDevice.isBootloader()) {
|
|
768
|
+
Log.debug(
|
|
769
|
+
'firmwareUpdateV4 uses the only bootloader device when connectId changed after reboot'
|
|
770
|
+
);
|
|
771
|
+
device = singleDevice;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
732
774
|
} else if (allDevices.length === 1) {
|
|
733
775
|
[device] = allDevices;
|
|
734
776
|
} else if (allDevices.length > 1) {
|
|
735
777
|
throw ERRORS.TypedError(
|
|
736
778
|
[
|
|
779
|
+
'firmwareUpdateV4',
|
|
737
780
|
'firmwareUpdateV3',
|
|
738
781
|
'firmwareUpdateV2',
|
|
739
782
|
'checkFirmwareRelease',
|
|
@@ -796,8 +839,8 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
|
796
839
|
if (!method.connectId) reasons.push('connectId.missing');
|
|
797
840
|
// passphrase state must match the pre-initialize
|
|
798
841
|
if (!device.isPreInitializeMetaMatch(method.payload)) reasons.push('meta.mismatch');
|
|
799
|
-
// device must have been initialized before
|
|
800
|
-
if (
|
|
842
|
+
// device must have been initialized before.
|
|
843
|
+
if (device.isUnacquired()) reasons.push('deviceInfo.missing');
|
|
801
844
|
// within pre-initialize TTL
|
|
802
845
|
if (!device.isPreInitializedValid(PRE_INITIALIZE_TTL_MS)) reasons.push('ttl.expired');
|
|
803
846
|
|
|
@@ -813,13 +856,23 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
|
|
|
813
856
|
return true;
|
|
814
857
|
}
|
|
815
858
|
|
|
859
|
+
function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
|
|
860
|
+
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
861
|
+
return (
|
|
862
|
+
method.payload.connectProtocol === 'V2' &&
|
|
863
|
+
message.includes('Device protocol mismatch') &&
|
|
864
|
+
message.includes('expected V2') &&
|
|
865
|
+
message.includes('did not respond to expected protocol')
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
|
|
816
869
|
/**
|
|
817
870
|
* If the Bluetooth connection times out, retry up to 6 times
|
|
818
871
|
* @param retryCount - Current retry count (default 0)
|
|
819
872
|
*/
|
|
820
873
|
async function connectDeviceForBle(method: BaseMethod, device: Device, retryCount = 0) {
|
|
821
874
|
try {
|
|
822
|
-
await device.acquire();
|
|
875
|
+
await device.acquire(method.payload.connectProtocol);
|
|
823
876
|
if (method.payload?.onlyConnectBleDevice) {
|
|
824
877
|
return;
|
|
825
878
|
}
|
|
@@ -832,7 +885,12 @@ async function connectDeviceForBle(method: BaseMethod, device: Device, retryCoun
|
|
|
832
885
|
});
|
|
833
886
|
}
|
|
834
887
|
} catch (err) {
|
|
835
|
-
if (
|
|
888
|
+
if (
|
|
889
|
+
(err.errorCode === HardwareErrorCode.BleTimeoutError ||
|
|
890
|
+
err.errorCode === HardwareErrorCode.BleConnectedError ||
|
|
891
|
+
isRetryableBleProtocolV2ProbeError(method, err)) &&
|
|
892
|
+
retryCount < 6
|
|
893
|
+
) {
|
|
836
894
|
const nextRetry = retryCount + 1;
|
|
837
895
|
Log.debug(`Bluetooth connect timeout and will retry, retry count: ${nextRetry}`);
|
|
838
896
|
await wait(3000);
|
|
@@ -1091,7 +1149,11 @@ export const cancel = (context: CoreContext, connectId?: string) => {
|
|
|
1091
1149
|
const checkPassphraseEnableState = (method: BaseMethod, features?: Features) => {
|
|
1092
1150
|
if (!method.useDevicePassphraseState) return;
|
|
1093
1151
|
|
|
1094
|
-
|
|
1152
|
+
const passphraseProtection = method.device
|
|
1153
|
+
? method.device.getCurrentPassphraseProtection()
|
|
1154
|
+
: features?.passphraseProtection;
|
|
1155
|
+
|
|
1156
|
+
if (passphraseProtection === true) {
|
|
1095
1157
|
const hasNoPassphraseState =
|
|
1096
1158
|
method.payload.passphraseState == null || method.payload.passphraseState === '';
|
|
1097
1159
|
const shouldRequirePassphrase =
|
|
@@ -1103,12 +1165,18 @@ const checkPassphraseEnableState = (method: BaseMethod, features?: Features) =>
|
|
|
1103
1165
|
}
|
|
1104
1166
|
}
|
|
1105
1167
|
|
|
1106
|
-
if (
|
|
1168
|
+
if (passphraseProtection === false && method.payload.passphraseState) {
|
|
1107
1169
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
1108
1170
|
throw ERRORS.TypedError(HardwareErrorCode.DeviceNotOpenedPassphrase);
|
|
1109
1171
|
}
|
|
1110
1172
|
};
|
|
1111
1173
|
|
|
1174
|
+
const shouldCheckPassphraseState = (method: BaseMethod, device: Device) => {
|
|
1175
|
+
if (!method.useDevicePassphraseState) return false;
|
|
1176
|
+
|
|
1177
|
+
return device.hasUsePassphrase();
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1112
1180
|
const cleanup = () => {
|
|
1113
1181
|
_uiPromises = [];
|
|
1114
1182
|
Log.debug('Cleanup...');
|
|
@@ -1128,16 +1196,16 @@ const closePopup = () => {
|
|
|
1128
1196
|
};
|
|
1129
1197
|
|
|
1130
1198
|
const onDeviceConnectHandler = (device: Device) => {
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject
|
|
1199
|
+
const deviceObject = device.toMessageObject();
|
|
1200
|
+
if (!deviceObject) return;
|
|
1201
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
1134
1202
|
};
|
|
1135
1203
|
|
|
1136
1204
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1137
1205
|
device.clearPreInitialized();
|
|
1138
|
-
const
|
|
1139
|
-
|
|
1140
|
-
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject
|
|
1206
|
+
const deviceObject = device.toMessageObject();
|
|
1207
|
+
if (!deviceObject) return;
|
|
1208
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
1141
1209
|
};
|
|
1142
1210
|
|
|
1143
1211
|
const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
@@ -1178,6 +1246,10 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1178
1246
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1179
1247
|
};
|
|
1180
1248
|
|
|
1249
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1250
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1181
1253
|
const onDevicePassphraseHandler = async (
|
|
1182
1254
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1183
1255
|
) => {
|
|
@@ -1188,6 +1260,9 @@ const onDevicePassphraseHandler = async (
|
|
|
1188
1260
|
device: device.toMessageObject() as KnownDevice,
|
|
1189
1261
|
passphraseState: device.passphraseState,
|
|
1190
1262
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
1263
|
+
source: requestPayload.source,
|
|
1264
|
+
reason: requestPayload.reason,
|
|
1265
|
+
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
1191
1266
|
})
|
|
1192
1267
|
);
|
|
1193
1268
|
// wait for passphrase
|
|
@@ -1209,12 +1284,27 @@ const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']
|
|
|
1209
1284
|
};
|
|
1210
1285
|
|
|
1211
1286
|
const onEnterPassphraseOnDeviceHandler = (
|
|
1212
|
-
...[device]: [...DeviceEvents['passphrase_on_device']]
|
|
1287
|
+
...[device, requestPayload]: [...DeviceEvents['passphrase_on_device']]
|
|
1213
1288
|
) => {
|
|
1214
1289
|
postMessage(
|
|
1215
1290
|
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
1216
1291
|
device: device.toMessageObject() as KnownDevice,
|
|
1217
1292
|
passphraseState: device.passphraseState,
|
|
1293
|
+
source: requestPayload?.source,
|
|
1294
|
+
reason: requestPayload?.reason,
|
|
1295
|
+
})
|
|
1296
|
+
);
|
|
1297
|
+
};
|
|
1298
|
+
|
|
1299
|
+
const onEnterAttachPinOnDeviceHandler = (
|
|
1300
|
+
...[device, requestPayload]: [...DeviceEvents['attach_pin_on_device']]
|
|
1301
|
+
) => {
|
|
1302
|
+
postMessage(
|
|
1303
|
+
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1304
|
+
device: device.toMessageObject() as KnownDevice,
|
|
1305
|
+
type: 'ButtonRequest_AttachPin',
|
|
1306
|
+
source: requestPayload?.source,
|
|
1307
|
+
reason: requestPayload?.reason,
|
|
1218
1308
|
})
|
|
1219
1309
|
);
|
|
1220
1310
|
};
|
|
@@ -1285,6 +1375,8 @@ export default class Core extends EventEmitter {
|
|
|
1285
1375
|
|
|
1286
1376
|
private requestQueue = new RequestQueue();
|
|
1287
1377
|
|
|
1378
|
+
private disposePromise?: Promise<void>;
|
|
1379
|
+
|
|
1288
1380
|
// background task
|
|
1289
1381
|
private prePendingCallPromise: Promise<void> | undefined;
|
|
1290
1382
|
|
|
@@ -1297,6 +1389,10 @@ export default class Core extends EventEmitter {
|
|
|
1297
1389
|
Log.debug(`[Core] Created SDK instance: ${this.sdkInstanceId}`);
|
|
1298
1390
|
}
|
|
1299
1391
|
|
|
1392
|
+
cancelOperation(operationId: string) {
|
|
1393
|
+
this.requestQueue.abortOperation(operationId);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1300
1396
|
private getCoreContext() {
|
|
1301
1397
|
return {
|
|
1302
1398
|
sdkInstanceId: this.sdkInstanceId,
|
|
@@ -1343,10 +1439,17 @@ export default class Core extends EventEmitter {
|
|
|
1343
1439
|
}
|
|
1344
1440
|
|
|
1345
1441
|
case IFRAME.CALL: {
|
|
1346
|
-
|
|
1442
|
+
const logBlockLabel = getLogBlockLabel(message);
|
|
1443
|
+
Log.log(
|
|
1444
|
+
`[${Date.now()}][CALL_API]`,
|
|
1445
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : message
|
|
1446
|
+
);
|
|
1347
1447
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1348
1448
|
const { success, payload } = response;
|
|
1349
|
-
Log.log(
|
|
1449
|
+
Log.log(
|
|
1450
|
+
`[${Date.now()}][CALL_API_RESPONSE]`,
|
|
1451
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response
|
|
1452
|
+
);
|
|
1350
1453
|
if (success) {
|
|
1351
1454
|
return response;
|
|
1352
1455
|
}
|
|
@@ -1365,6 +1468,10 @@ export default class Core extends EventEmitter {
|
|
|
1365
1468
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
1366
1469
|
break;
|
|
1367
1470
|
}
|
|
1471
|
+
case IFRAME.CANCEL_OPERATION: {
|
|
1472
|
+
this.cancelOperation(message.payload.operationId);
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1368
1475
|
case IFRAME.CALLBACK: {
|
|
1369
1476
|
Log.log('callback message: ', message);
|
|
1370
1477
|
postMessage(message);
|
|
@@ -1376,20 +1483,52 @@ export default class Core extends EventEmitter {
|
|
|
1376
1483
|
return Promise.resolve(message);
|
|
1377
1484
|
}
|
|
1378
1485
|
|
|
1379
|
-
dispose() {
|
|
1486
|
+
dispose(): Promise<void> {
|
|
1487
|
+
if (!this.disposePromise) {
|
|
1488
|
+
this.disposePromise = this.disposeResources();
|
|
1489
|
+
}
|
|
1490
|
+
return this.disposePromise;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
private async disposeResources(): Promise<void> {
|
|
1494
|
+
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1495
|
+
pollingManager.stopAll();
|
|
1496
|
+
this.requestQueue.abortAllRequests();
|
|
1497
|
+
cleanup();
|
|
1498
|
+
|
|
1499
|
+
_connector?.stop();
|
|
1500
|
+
let transportCleanup: Promise<void>;
|
|
1501
|
+
try {
|
|
1502
|
+
transportCleanup = Promise.resolve(TransportManager.getTransport()?.stop?.()).catch(error => {
|
|
1503
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1504
|
+
});
|
|
1505
|
+
} catch (error) {
|
|
1506
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1507
|
+
transportCleanup = Promise.resolve();
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// Preserve synchronous dispose semantics for in-memory state and listeners.
|
|
1380
1511
|
_deviceList = undefined;
|
|
1381
1512
|
_connector = undefined;
|
|
1513
|
+
DevicePool.resetState();
|
|
1382
1514
|
deviceCacheMap.clear();
|
|
1383
1515
|
preWarmInflight.clear();
|
|
1384
1516
|
preWarmDoneAt.clear();
|
|
1385
|
-
|
|
1517
|
+
preConnectCache = { passphraseState: undefined };
|
|
1518
|
+
this.prePendingCallPromise = undefined;
|
|
1519
|
+
this.removeAllListeners();
|
|
1386
1520
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1521
|
+
if (_core === this) _core = undefined;
|
|
1522
|
+
|
|
1523
|
+
// Transports, especially Node USB, may release native handles asynchronously.
|
|
1524
|
+
await transportCleanup;
|
|
1387
1525
|
}
|
|
1388
1526
|
}
|
|
1389
1527
|
|
|
1390
1528
|
export const initCore = () => {
|
|
1391
|
-
|
|
1392
|
-
|
|
1529
|
+
const core = new Core();
|
|
1530
|
+
_core = core;
|
|
1531
|
+
return core;
|
|
1393
1532
|
};
|
|
1394
1533
|
|
|
1395
1534
|
export const initConnector = () => {
|