@onekeyfe/hd-core 1.2.0-alpha.2 → 1.2.0-alpha.21
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 +285 -0
- package/__tests__/DeviceEventRegistration.test.ts +43 -0
- package/__tests__/connectSettings.test.ts +19 -0
- package/__tests__/core-dispose.test.ts +34 -0
- package/__tests__/core-error-output.test.ts +39 -0
- package/__tests__/device-features-state.test.ts +78 -0
- package/__tests__/device-identity.test.ts +30 -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 +391 -0
- package/__tests__/device-state-contract.test.ts +27 -0
- package/__tests__/device-state-events.test.ts +162 -0
- package/__tests__/device-state-mapper.test.ts +241 -0
- package/__tests__/device-state-projector.test.ts +94 -0
- package/__tests__/device-state-store.test.ts +82 -0
- package/__tests__/device-utils.test.ts +106 -0
- package/__tests__/device-wallet-session-store.test.ts +213 -0
- package/__tests__/deviceFeaturesUtils.test.ts +39 -0
- package/__tests__/deviceSettings.test.ts +103 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +10 -6
- package/__tests__/evmSignTypedData.test.ts +80 -0
- package/__tests__/filesystemValidation.test.ts +53 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +402 -0
- package/__tests__/get-device-state.test.ts +410 -0
- package/__tests__/homescreen.test.ts +24 -0
- package/__tests__/kaspaSignTransaction.test.ts +591 -0
- package/__tests__/logBlockEvent.test.ts +26 -0
- package/__tests__/networkUtils.test.ts +386 -0
- package/__tests__/open-wallet-session-error-response.test.ts +43 -0
- package/__tests__/open-wallet-session.test.ts +559 -0
- package/__tests__/preInitialize.test.ts +33 -0
- package/__tests__/pro2Wallpaper.test.ts +50 -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 +3954 -1191
- package/__tests__/protocolV2FileWrite.test.ts +92 -0
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/__tests__/public-device-state-api.test.ts +257 -0
- package/__tests__/public-pro2-api-boundary.test.ts +110 -0
- package/__tests__/refresh-device-state.test.ts +101 -0
- package/__tests__/request-context-logging.test.ts +16 -0
- package/__tests__/search-devices.test.ts +136 -0
- package/dist/api/BaseMethod.d.ts +8 -0
- package/dist/api/BaseMethod.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.map +1 -1
- package/dist/api/FileRead.d.ts.map +1 -1
- package/dist/api/FileWrite.d.ts +1 -0
- package/dist/api/FileWrite.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +2 -2
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +25 -5
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- 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 +1 -6
- 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.map +1 -1
- package/dist/api/PromptWebDeviceAccess.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts +3 -0
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/UploadPortfolio.d.ts +17 -0
- package/dist/api/UploadPortfolio.d.ts.map +1 -0
- package/dist/api/allnetwork/AllNetworkGetAddressBase.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.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/DeviceUnlock.d.ts +1 -1
- package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/device/DeviceWipe.d.ts.map +1 -1
- package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/getBinary.d.ts +11 -3
- 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/helpers/filesystemValidation.d.ts +3 -0
- package/dist/api/helpers/filesystemValidation.d.ts.map +1 -1
- package/dist/api/helpers/paramsValidator.d.ts +1 -0
- package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
- 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 +12 -19
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/api/kaspa/helpers/TransferSerialize.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 +1 -1
- package/dist/api/protocol-v2/DeviceFirmwareUpdate.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts +3 -2
- package/dist/api/protocol-v2/DeviceGetFirmwareUpdateStatus.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -1
- package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- package/dist/api/protocol-v2/{FilesystemFixPermission.d.ts → FilesystemPermissionFix.d.ts} +2 -2
- package/dist/api/protocol-v2/FilesystemPermissionFix.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 +27 -19
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/ton/TonSignData.d.ts +1 -5
- package/dist/api/ton/TonSignData.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.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 +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -1
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +35 -11
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +8 -6
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceFeaturesState.d.ts +3 -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 +20 -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 +9 -3
- package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
- package/dist/deviceProfile/index.d.ts +0 -1
- package/dist/deviceProfile/index.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/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +18 -2
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/index.d.ts +1361 -609
- package/dist/index.js +5898 -2860
- package/dist/inject.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 +23 -28
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/firmware.d.ts +11 -9
- package/dist/protocols/protocol-v2/firmware.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/index.d.ts +3 -2
- package/dist/protocols/protocol-v2/index.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/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 +19 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -0
- package/dist/types/api/checkAllFirmwareRelease.d.ts +1 -2
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceSettings.d.ts +11 -2
- package/dist/types/api/deviceSettings.d.ts.map +1 -1
- package/dist/types/api/deviceUnlock.d.ts +2 -2
- package/dist/types/api/deviceUnlock.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +6 -6
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- 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 -10
- package/dist/types/api/getPassphraseState.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +22 -25
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/types/api/openWalletSession.d.ts +41 -0
- package/dist/types/api/openWalletSession.d.ts.map +1 -0
- package/dist/types/api/protocolV2.d.ts +23 -28
- package/dist/types/api/protocolV2.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 +121 -5
- 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 +21 -1
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/assets.d.ts +2 -1
- package/dist/utils/assets.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 +13 -3
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/deviceInfoUtils.d.ts +9 -8
- package/dist/utils/deviceInfoUtils.d.ts.map +1 -1
- package/dist/utils/deviceSettings.d.ts +38 -7
- 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/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/networkUtils.d.ts +9 -1
- package/dist/utils/networkUtils.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/package.json +4 -4
- package/src/api/BaseMethod.ts +36 -9
- 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 +5 -3
- package/src/api/DirMake.ts +3 -3
- package/src/api/DirRemove.ts +3 -3
- package/src/api/FileDelete.ts +3 -3
- package/src/api/FileRead.ts +23 -7
- package/src/api/FileWrite.ts +23 -168
- package/src/api/FirmwareUpdate.ts +4 -4
- package/src/api/FirmwareUpdateV2.ts +133 -45
- package/src/api/FirmwareUpdateV3.ts +3 -5
- package/src/api/FirmwareUpdateV4.ts +1138 -357
- package/src/api/GetDeviceState.ts +55 -0
- package/src/api/GetFeatures.ts +8 -3
- package/src/api/GetOnekeyFeatures.ts +3 -72
- package/src/api/GetPassphraseState.ts +11 -18
- package/src/api/OpenWalletSession.ts +221 -0
- package/src/api/PathInfo.ts +5 -3
- package/src/api/PromptWebDeviceAccess.ts +2 -3
- package/src/api/SearchDevices.ts +29 -4
- package/src/api/UploadPortfolio.ts +40 -0
- package/src/api/alephium/AlephiumSignTransaction.ts +2 -2
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +4 -8
- package/src/api/benfen/BenfenGetAddress.ts +1 -1
- package/src/api/btc/BTCGetPublicKey.ts +1 -1
- package/src/api/cardano/CardanoSignMessage.ts +1 -1
- package/src/api/cardano/CardanoSignTransaction.ts +1 -1
- package/src/api/device/DeviceCancel.ts +1 -0
- package/src/api/device/DeviceChangePin.ts +24 -0
- package/src/api/device/DeviceFullyUploadResource.ts +4 -5
- package/src/api/device/DeviceLock.ts +1 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +5 -4
- package/src/api/device/DeviceRebootToBootloader.ts +5 -4
- package/src/api/device/DeviceSettings.ts +183 -1
- package/src/api/device/DeviceUnlock.ts +11 -1
- package/src/api/device/DeviceUpdateBootloader.ts +1 -2
- package/src/api/device/DeviceWipe.ts +19 -0
- package/src/api/evm/EVMSignTypedData.ts +3 -5
- package/src/api/evm/legacyV1/getAddress.ts +2 -2
- package/src/api/evm/legacyV1/getPublicKey.ts +2 -2
- package/src/api/evm/legacyV1/signMessage.ts +2 -2
- package/src/api/evm/legacyV1/signTypedData.ts +2 -2
- package/src/api/evm/legacyV1/signTypedHash.ts +2 -2
- package/src/api/evm/legacyV1/verifyMessage.ts +2 -2
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +21 -7
- package/src/api/firmware/getBinary.ts +8 -3
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/helpers/batchGetPublickeys.ts +2 -2
- package/src/api/helpers/filesystemValidation.ts +61 -0
- package/src/api/helpers/paramsValidator.ts +1 -1
- package/src/api/helpers/protocolV2FileWrite.ts +193 -0
- package/src/api/index.ts +14 -20
- package/src/api/kaspa/KaspaSignTransaction.ts +341 -22
- package/src/api/kaspa/helpers/TransferSerialize.ts +14 -0
- package/src/api/nervos/NervosSignTransaction.ts +2 -2
- package/src/api/nexa/NexaSignTransaction.ts +1 -1
- package/src/api/protocol-v2/{FactoryGetDeviceInfo.ts → DeviceFactoryInfoGet.ts} +4 -4
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +32 -0
- package/src/api/protocol-v2/DeviceFirmwareUpdate.ts +7 -9
- package/src/api/protocol-v2/DeviceGetFirmwareUpdateStatus.ts +41 -6
- package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +6 -4
- package/src/api/protocol-v2/DeviceInfoGet.ts +145 -0
- package/src/api/protocol-v2/DeviceReboot.ts +5 -3
- 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 +5 -2
- package/src/api/protocol-v2/{FilesystemFixPermission.ts → FilesystemPermissionFix.ts} +3 -3
- package/src/api/protocol-v2/Ping.ts +1 -1
- package/src/api/protocol-v2/{GetProtoVersion.ts → ProtocolInfoRequest.ts} +3 -3
- package/src/api/protocol-v2/helpers.ts +58 -62
- package/src/api/ton/TonSignData.ts +1 -5
- package/src/api/utils.ts +7 -3
- package/src/constants/index.ts +7 -1
- package/src/core/RequestQueue.ts +1 -0
- package/src/core/deviceEventRegistration.ts +23 -0
- package/src/core/index.ts +140 -35
- package/src/data/messages/messages-protocol-v2.json +825 -709
- package/src/data/messages/messages.json +286 -1
- package/src/data-manager/DataManager.ts +13 -6
- package/src/data-manager/connectSettings.ts +4 -0
- package/src/device/Device.ts +480 -192
- package/src/device/DeviceCommands.ts +81 -25
- package/src/device/DeviceFeaturesState.ts +25 -0
- package/src/device/DevicePool.ts +67 -19
- package/src/device/DeviceStateMapper.ts +349 -0
- package/src/device/DeviceStateProjector.ts +95 -0
- package/src/device/DeviceStateStore.ts +201 -0
- package/src/device/DeviceWalletSessionStore.ts +105 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +235 -210
- package/src/deviceProfile/index.ts +0 -1
- package/src/events/device.ts +17 -1
- package/src/events/logBlockEvent.ts +8 -1
- package/src/events/ui-request.ts +24 -2
- package/src/inject.ts +23 -34
- package/src/protocols/protocol-v2/deviceSession.ts +24 -0
- package/src/protocols/protocol-v2/features.ts +68 -82
- package/src/protocols/protocol-v2/firmware.ts +12 -36
- package/src/protocols/protocol-v2/index.ts +3 -1
- 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 +107 -0
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +26 -2
- package/src/types/api/deviceUnlock.ts +5 -2
- package/src/types/api/firmwareUpdate.ts +28 -20
- 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 +8 -11
- package/src/types/api/index.ts +30 -53
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +58 -55
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +170 -4
- package/src/types/params.ts +4 -0
- package/src/types/settings.ts +42 -30
- package/src/utils/assets.ts +4 -1
- package/src/utils/deviceFeaturesCompat.ts +173 -0
- package/src/utils/deviceFeaturesUtils.ts +68 -24
- package/src/utils/deviceInfoUtils.ts +26 -64
- package/src/utils/deviceSettings.ts +161 -39
- package/src/utils/deviceVersionUtils.ts +25 -44
- package/src/utils/findDefectiveBatchDevice.ts +3 -3
- package/src/utils/homescreen.ts +10 -0
- package/src/utils/index.ts +21 -1
- package/src/utils/networkUtils.ts +270 -14
- package/src/utils/pro2Wallpaper.ts +109 -0
- package/src/utils/tracing.ts +3 -1
- package/dist/api/GetDeviceInfo.d.ts +0 -9
- package/dist/api/GetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/DevReboot.d.ts +0 -7
- package/dist/api/protocol-v2/DevReboot.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts +0 -29
- package/dist/api/protocol-v2/DeviceGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts +0 -7
- package/dist/api/protocol-v2/FactoryDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts +0 -6
- package/dist/api/protocol-v2/FactoryGetDeviceInfo.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
- package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
- package/dist/api/protocol-v2/FilesystemFixPermission.d.ts.map +0 -1
- package/dist/api/protocol-v2/GetProtoVersion.d.ts +0 -6
- package/dist/api/protocol-v2/GetProtoVersion.d.ts.map +0 -1
- package/dist/deviceProfile/buildDeviceProfile.d.ts +0 -21
- package/dist/deviceProfile/buildDeviceProfile.d.ts.map +0 -1
- package/dist/types/api/getDeviceInfo.d.ts +0 -85
- package/dist/types/api/getDeviceInfo.d.ts.map +0 -1
- package/src/api/GetDeviceInfo.ts +0 -145
- package/src/api/protocol-v2/DevReboot.ts +0 -24
- package/src/api/protocol-v2/DeviceGetDeviceInfo.ts +0 -118
- package/src/api/protocol-v2/FactoryDeviceInfoSettings.ts +0 -29
- package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
- package/src/deviceProfile/buildDeviceProfile.ts +0 -334
- package/src/types/api/getDeviceInfo.ts +0 -99
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DEVICE } from '../events';
|
|
2
|
+
|
|
3
|
+
import type { Device, DeviceEvents } from '../device/Device';
|
|
4
|
+
|
|
5
|
+
export type HardwareUiEventHandlers = {
|
|
6
|
+
pin: (...event: DeviceEvents[typeof DEVICE.PIN]) => void;
|
|
7
|
+
button: (...event: DeviceEvents[typeof DEVICE.BUTTON]) => void;
|
|
8
|
+
passphrase: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE]) => void;
|
|
9
|
+
passphraseOnDevice: (...event: DeviceEvents[typeof DEVICE.PASSPHRASE_ON_DEVICE]) => void;
|
|
10
|
+
attachPinOnDevice: (...event: DeviceEvents[typeof DEVICE.ATTACH_PIN_ON_DEVICE]) => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function registerHardwareUiEventListeners(
|
|
14
|
+
device: Pick<Device, 'on'>,
|
|
15
|
+
handlers: HardwareUiEventHandlers
|
|
16
|
+
) {
|
|
17
|
+
device.on(DEVICE.PIN, handlers.pin);
|
|
18
|
+
device.on(DEVICE.BUTTON, handlers.button);
|
|
19
|
+
device.on(DEVICE.PASSPHRASE, handlers.passphrase);
|
|
20
|
+
device.on(DEVICE.PASSPHRASE_ON_DEVICE, handlers.passphraseOnDevice);
|
|
21
|
+
device.on(DEVICE.ATTACH_PIN_ON_DEVICE, handlers.attachPinOnDevice);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
updateRequestContext,
|
|
37
37
|
} from '../utils/tracing';
|
|
38
38
|
import { Device } from '../device/Device';
|
|
39
|
+
import { checkLiveDeviceId } from '../device/deviceIdentity';
|
|
39
40
|
import { DeviceList } from '../device/DeviceList';
|
|
40
41
|
import { DevicePool } from '../device/DevicePool';
|
|
41
42
|
import { PollingStateManager } from './PollingStateManager';
|
|
@@ -51,11 +52,18 @@ import {
|
|
|
51
52
|
createDeviceMessage,
|
|
52
53
|
createResponseMessage,
|
|
53
54
|
createUiMessage,
|
|
55
|
+
getLogBlockLabel,
|
|
54
56
|
} from '../events';
|
|
55
57
|
import TransportManager from '../data-manager/TransportManager';
|
|
56
58
|
import DeviceConnector from '../device/DeviceConnector';
|
|
57
59
|
import RequestQueue from './RequestQueue';
|
|
60
|
+
import { registerHardwareUiEventListeners } from './deviceEventRegistration';
|
|
58
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';
|
|
59
67
|
|
|
60
68
|
import type { ConnectSettings, Features, KnownDevice } from '../types';
|
|
61
69
|
import type { CoreMessage, IFrameCallMessage, UiPromise, UiPromiseResponse } from '../events';
|
|
@@ -91,13 +99,14 @@ function hasDeriveCardano(method: BaseMethod): boolean {
|
|
|
91
99
|
|
|
92
100
|
const parseInitOptions = (method?: BaseMethod): InitOptions => ({
|
|
93
101
|
initSession: method?.payload.initSession,
|
|
94
|
-
passphraseState: method?.payload.passphraseState,
|
|
102
|
+
passphraseState: method?.payload.useEmptyPassphrase ? undefined : method?.payload.passphraseState,
|
|
95
103
|
deviceId: method?.payload.deviceId,
|
|
96
104
|
deriveCardano: method && hasDeriveCardano(method),
|
|
97
105
|
connectProtocol: method?.payload.connectProtocol,
|
|
106
|
+
protocolV2DeviceInfoTimeoutMs: method?.payload.protocolV2DeviceInfoTimeoutMs,
|
|
98
107
|
});
|
|
99
108
|
|
|
100
|
-
let _core: Core;
|
|
109
|
+
let _core: Core | undefined;
|
|
101
110
|
let _deviceList: DeviceList | undefined;
|
|
102
111
|
let _connector: DeviceConnector | undefined;
|
|
103
112
|
let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
|
|
@@ -141,7 +150,7 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
141
150
|
}
|
|
142
151
|
|
|
143
152
|
// find api method
|
|
144
|
-
let method
|
|
153
|
+
let method!: BaseMethod;
|
|
145
154
|
try {
|
|
146
155
|
method = findMethod(message as IFrameCallMessage);
|
|
147
156
|
method.connector = _connector;
|
|
@@ -157,7 +166,11 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
157
166
|
|
|
158
167
|
method.init();
|
|
159
168
|
} catch (error) {
|
|
160
|
-
|
|
169
|
+
if (method) {
|
|
170
|
+
completeMethodRequestContext(method, error);
|
|
171
|
+
method.dispose();
|
|
172
|
+
}
|
|
173
|
+
return createResponseMessage(method?.responseID ?? message.id, false, { error });
|
|
161
174
|
}
|
|
162
175
|
|
|
163
176
|
DevicePool.emitter.on(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
@@ -222,9 +235,16 @@ const handlePreWarmSignal = async (
|
|
|
222
235
|
message: CoreMessage,
|
|
223
236
|
method: BaseMethod
|
|
224
237
|
): Promise<any> => {
|
|
238
|
+
const createAckResponse = () => {
|
|
239
|
+
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
240
|
+
completeMethodRequestContext(method);
|
|
241
|
+
method.dispose();
|
|
242
|
+
return createResponseMessage(method.responseID, true, true);
|
|
243
|
+
};
|
|
244
|
+
|
|
225
245
|
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
226
246
|
if (!method.connectId) {
|
|
227
|
-
return
|
|
247
|
+
return createAckResponse();
|
|
228
248
|
}
|
|
229
249
|
|
|
230
250
|
const key = method.getPreWarmKey();
|
|
@@ -237,12 +257,12 @@ const handlePreWarmSignal = async (
|
|
|
237
257
|
} catch {
|
|
238
258
|
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
239
259
|
}
|
|
240
|
-
return
|
|
260
|
+
return createAckResponse();
|
|
241
261
|
}
|
|
242
262
|
|
|
243
263
|
const doneAt = preWarmDoneAt.get(key);
|
|
244
264
|
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
245
|
-
return
|
|
265
|
+
return createAckResponse();
|
|
246
266
|
}
|
|
247
267
|
|
|
248
268
|
const run = onCallDevice(context, message, method);
|
|
@@ -350,7 +370,7 @@ const onCallDevice = async (
|
|
|
350
370
|
);
|
|
351
371
|
} catch (e) {
|
|
352
372
|
preWarmCallbackTask?.resolve();
|
|
353
|
-
|
|
373
|
+
Log.debug('ensureConnected error: ', e);
|
|
354
374
|
|
|
355
375
|
completeMethodRequestContext(method, e);
|
|
356
376
|
|
|
@@ -387,18 +407,23 @@ const onCallDevice = async (
|
|
|
387
407
|
);
|
|
388
408
|
}
|
|
389
409
|
|
|
390
|
-
device
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
410
|
+
registerHardwareUiEventListeners(device, {
|
|
411
|
+
pin: onDevicePinHandler,
|
|
412
|
+
button: onDeviceButtonHandler,
|
|
413
|
+
passphrase: message.payload.useEmptyPassphrase
|
|
414
|
+
? onEmptyPassphraseHandler
|
|
415
|
+
: onDevicePassphraseHandler,
|
|
416
|
+
passphraseOnDevice: onEnterPassphraseOnDeviceHandler,
|
|
417
|
+
attachPinOnDevice: onEnterAttachPinOnDeviceHandler,
|
|
418
|
+
});
|
|
397
419
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
420
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
398
421
|
device.on(
|
|
399
422
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
400
423
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
401
424
|
);
|
|
425
|
+
|
|
426
|
+
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
402
427
|
device.on(
|
|
403
428
|
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
404
429
|
onSelectDeviceForSwitchFirmwareWebDeviceHandler
|
|
@@ -413,8 +438,8 @@ const onCallDevice = async (
|
|
|
413
438
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
414
439
|
|
|
415
440
|
const inner = async (): Promise<void> => {
|
|
416
|
-
//
|
|
417
|
-
//
|
|
441
|
+
// The protocol is established after acquire/initialize. Reject Protocol V2-only
|
|
442
|
+
// methods on other devices through BaseMethod.requireProtocolV2.
|
|
418
443
|
if (method.requireProtocolV2 && !device.isProtocolV2()) {
|
|
419
444
|
throw createDeviceNotSupportMethodError(method.name, device.getCurrentFirmwareType());
|
|
420
445
|
}
|
|
@@ -428,8 +453,8 @@ const onCallDevice = async (
|
|
|
428
453
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
429
454
|
let newVersionStatus: ReturnType<typeof DataManager.getFirmwareStatus> | undefined;
|
|
430
455
|
|
|
431
|
-
//
|
|
432
|
-
// Pro2
|
|
456
|
+
// Defective-batch and forced-update gates depend on V1 features/remote config.
|
|
457
|
+
// Pro2 joins after DataManager supports its profile firmwareStatus.
|
|
433
458
|
if (device.features && !device.isProtocolV2()) {
|
|
434
459
|
await DataManager.checkAndReloadData();
|
|
435
460
|
|
|
@@ -532,7 +557,7 @@ const onCallDevice = async (
|
|
|
532
557
|
}
|
|
533
558
|
|
|
534
559
|
if (method.deviceId && method.checkDeviceId) {
|
|
535
|
-
const isSameDeviceID = device
|
|
560
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
536
561
|
if (!isSameDeviceID) {
|
|
537
562
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
538
563
|
}
|
|
@@ -609,7 +634,11 @@ const onCallDevice = async (
|
|
|
609
634
|
method.device?.commands?.checkDisposed();
|
|
610
635
|
|
|
611
636
|
try {
|
|
612
|
-
const response: object = await
|
|
637
|
+
const response: object = await runMethodWithUnlockRetry(
|
|
638
|
+
method,
|
|
639
|
+
device,
|
|
640
|
+
protocolV2UiCoordinator
|
|
641
|
+
);
|
|
613
642
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
614
643
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
615
644
|
completeMethodRequestContext(method);
|
|
@@ -626,6 +655,8 @@ const onCallDevice = async (
|
|
|
626
655
|
) {
|
|
627
656
|
throw error;
|
|
628
657
|
}
|
|
658
|
+
} finally {
|
|
659
|
+
protocolV2UiCoordinator.close();
|
|
629
660
|
}
|
|
630
661
|
};
|
|
631
662
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -679,7 +710,9 @@ const onCallDevice = async (
|
|
|
679
710
|
|
|
680
711
|
requestQueue.releaseTask(method.responseID);
|
|
681
712
|
|
|
682
|
-
|
|
713
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
714
|
+
closePopup();
|
|
715
|
+
}
|
|
683
716
|
|
|
684
717
|
cleanup();
|
|
685
718
|
|
|
@@ -731,6 +764,15 @@ function initDevice(method: BaseMethod) {
|
|
|
731
764
|
|
|
732
765
|
if (method.connectId) {
|
|
733
766
|
device = _deviceList.getDevice(method.connectId);
|
|
767
|
+
if (!device && method.name === 'firmwareUpdateV4' && allDevices.length === 1) {
|
|
768
|
+
const [singleDevice] = allDevices;
|
|
769
|
+
if (singleDevice.isBootloader()) {
|
|
770
|
+
Log.debug(
|
|
771
|
+
'firmwareUpdateV4 uses the only bootloader device when connectId changed after reboot'
|
|
772
|
+
);
|
|
773
|
+
device = singleDevice;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
734
776
|
} else if (allDevices.length === 1) {
|
|
735
777
|
[device] = allDevices;
|
|
736
778
|
} else if (allDevices.length > 1) {
|
|
@@ -1156,16 +1198,16 @@ const closePopup = () => {
|
|
|
1156
1198
|
};
|
|
1157
1199
|
|
|
1158
1200
|
const onDeviceConnectHandler = (device: Device) => {
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject
|
|
1201
|
+
const deviceObject = device.toMessageObject();
|
|
1202
|
+
if (!deviceObject) return;
|
|
1203
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
1162
1204
|
};
|
|
1163
1205
|
|
|
1164
1206
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1165
1207
|
device.clearPreInitialized();
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject
|
|
1208
|
+
const deviceObject = device.toMessageObject();
|
|
1209
|
+
if (!deviceObject) return;
|
|
1210
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
1169
1211
|
};
|
|
1170
1212
|
|
|
1171
1213
|
const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
@@ -1206,6 +1248,10 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1206
1248
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1207
1249
|
};
|
|
1208
1250
|
|
|
1251
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1252
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1209
1255
|
const onDevicePassphraseHandler = async (
|
|
1210
1256
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1211
1257
|
) => {
|
|
@@ -1216,6 +1262,9 @@ const onDevicePassphraseHandler = async (
|
|
|
1216
1262
|
device: device.toMessageObject() as KnownDevice,
|
|
1217
1263
|
passphraseState: device.passphraseState,
|
|
1218
1264
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
1265
|
+
source: requestPayload.source,
|
|
1266
|
+
reason: requestPayload.reason,
|
|
1267
|
+
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
1219
1268
|
})
|
|
1220
1269
|
);
|
|
1221
1270
|
// wait for passphrase
|
|
@@ -1237,12 +1286,27 @@ const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']
|
|
|
1237
1286
|
};
|
|
1238
1287
|
|
|
1239
1288
|
const onEnterPassphraseOnDeviceHandler = (
|
|
1240
|
-
...[device]: [...DeviceEvents['passphrase_on_device']]
|
|
1289
|
+
...[device, requestPayload]: [...DeviceEvents['passphrase_on_device']]
|
|
1241
1290
|
) => {
|
|
1242
1291
|
postMessage(
|
|
1243
1292
|
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
1244
1293
|
device: device.toMessageObject() as KnownDevice,
|
|
1245
1294
|
passphraseState: device.passphraseState,
|
|
1295
|
+
source: requestPayload?.source,
|
|
1296
|
+
reason: requestPayload?.reason,
|
|
1297
|
+
})
|
|
1298
|
+
);
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
const onEnterAttachPinOnDeviceHandler = (
|
|
1302
|
+
...[device, requestPayload]: [...DeviceEvents['attach_pin_on_device']]
|
|
1303
|
+
) => {
|
|
1304
|
+
postMessage(
|
|
1305
|
+
createUiMessage(UI_REQUEST.REQUEST_PIN, {
|
|
1306
|
+
device: device.toMessageObject() as KnownDevice,
|
|
1307
|
+
type: 'ButtonRequest_AttachPin',
|
|
1308
|
+
source: requestPayload?.source,
|
|
1309
|
+
reason: requestPayload?.reason,
|
|
1246
1310
|
})
|
|
1247
1311
|
);
|
|
1248
1312
|
};
|
|
@@ -1313,6 +1377,8 @@ export default class Core extends EventEmitter {
|
|
|
1313
1377
|
|
|
1314
1378
|
private requestQueue = new RequestQueue();
|
|
1315
1379
|
|
|
1380
|
+
private disposePromise?: Promise<void>;
|
|
1381
|
+
|
|
1316
1382
|
// background task
|
|
1317
1383
|
private prePendingCallPromise: Promise<void> | undefined;
|
|
1318
1384
|
|
|
@@ -1371,10 +1437,17 @@ export default class Core extends EventEmitter {
|
|
|
1371
1437
|
}
|
|
1372
1438
|
|
|
1373
1439
|
case IFRAME.CALL: {
|
|
1374
|
-
|
|
1440
|
+
const logBlockLabel = getLogBlockLabel(message);
|
|
1441
|
+
Log.log(
|
|
1442
|
+
`[${Date.now()}][CALL_API]`,
|
|
1443
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : message
|
|
1444
|
+
);
|
|
1375
1445
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1376
1446
|
const { success, payload } = response;
|
|
1377
|
-
Log.log(
|
|
1447
|
+
Log.log(
|
|
1448
|
+
`[${Date.now()}][CALL_API_RESPONSE]`,
|
|
1449
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response
|
|
1450
|
+
);
|
|
1378
1451
|
if (success) {
|
|
1379
1452
|
return response;
|
|
1380
1453
|
}
|
|
@@ -1404,20 +1477,52 @@ export default class Core extends EventEmitter {
|
|
|
1404
1477
|
return Promise.resolve(message);
|
|
1405
1478
|
}
|
|
1406
1479
|
|
|
1407
|
-
dispose() {
|
|
1480
|
+
dispose(): Promise<void> {
|
|
1481
|
+
if (!this.disposePromise) {
|
|
1482
|
+
this.disposePromise = this.disposeResources();
|
|
1483
|
+
}
|
|
1484
|
+
return this.disposePromise;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
private async disposeResources(): Promise<void> {
|
|
1488
|
+
Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
|
|
1489
|
+
pollingManager.stopAll();
|
|
1490
|
+
this.requestQueue.abortAllRequests();
|
|
1491
|
+
cleanup();
|
|
1492
|
+
|
|
1493
|
+
_connector?.stop();
|
|
1494
|
+
let transportCleanup: Promise<void>;
|
|
1495
|
+
try {
|
|
1496
|
+
transportCleanup = Promise.resolve(TransportManager.getTransport()?.stop?.()).catch(error => {
|
|
1497
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1498
|
+
});
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
Log.warn('[Core] Transport cleanup failed:', error);
|
|
1501
|
+
transportCleanup = Promise.resolve();
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// Preserve synchronous dispose semantics for in-memory state and listeners.
|
|
1408
1505
|
_deviceList = undefined;
|
|
1409
1506
|
_connector = undefined;
|
|
1507
|
+
DevicePool.resetState();
|
|
1410
1508
|
deviceCacheMap.clear();
|
|
1411
1509
|
preWarmInflight.clear();
|
|
1412
1510
|
preWarmDoneAt.clear();
|
|
1413
|
-
|
|
1511
|
+
preConnectCache = { passphraseState: undefined };
|
|
1512
|
+
this.prePendingCallPromise = undefined;
|
|
1513
|
+
this.removeAllListeners();
|
|
1414
1514
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1515
|
+
if (_core === this) _core = undefined;
|
|
1516
|
+
|
|
1517
|
+
// Transports, especially Node USB, may release native handles asynchronously.
|
|
1518
|
+
await transportCleanup;
|
|
1415
1519
|
}
|
|
1416
1520
|
}
|
|
1417
1521
|
|
|
1418
1522
|
export const initCore = () => {
|
|
1419
|
-
|
|
1420
|
-
|
|
1523
|
+
const core = new Core();
|
|
1524
|
+
_core = core;
|
|
1525
|
+
return core;
|
|
1421
1526
|
};
|
|
1422
1527
|
|
|
1423
1528
|
export const initConnector = () => {
|