@onekeyfe/hd-core 1.2.0-alpha.2 → 1.2.0-alpha.20
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__/RequestQueue.test.ts +140 -0
- package/__tests__/UploadPortfolio.test.ts +46 -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 +286 -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 +229 -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 +63 -0
- package/__tests__/evmLedgerLegacySafety.test.ts +4 -1
- 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 +403 -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 +4054 -1178
- package/__tests__/protocolV2FileWrite.test.ts +92 -0
- package/__tests__/protocolV2UiInteraction.test.ts +266 -0
- package/__tests__/public-device-state-api.test.ts +253 -0
- package/__tests__/public-pro2-api-boundary.test.ts +91 -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 +11 -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 +18 -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.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 +15 -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/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.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 +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 +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 +34 -10
- 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 +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 +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/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.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 +1351 -603
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5995 -2816
- 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 +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/topLevelInject.d.ts.map +1 -1
- 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 +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/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 +26 -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 +31 -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 +120 -4
- 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 +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/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/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 +40 -7
- 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 +50 -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 +121 -0
- package/src/api/device/DeviceUnlock.ts +9 -0
- 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 +17 -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/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 +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 +124 -4
- package/src/core/deviceEventRegistration.ts +23 -0
- package/src/core/index.ts +171 -60
- 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 +34 -0
- package/src/device/DevicePool.ts +67 -19
- 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 +105 -0
- package/src/device/cloneDeviceState.ts +39 -0
- package/src/device/deviceIdentity.ts +18 -0
- package/src/deviceProfile/buildDeviceFeatures.ts +233 -209
- package/src/deviceProfile/index.ts +0 -1
- 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 +8 -1
- package/src/events/ui-request.ts +24 -2
- package/src/index.ts +4 -0
- package/src/inject.ts +33 -34
- package/src/lowLevelInject.ts +3 -0
- 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/topLevelInject.ts +2 -0
- package/src/types/api/checkAllFirmwareRelease.ts +1 -2
- package/src/types/api/deviceSettings.ts +9 -0
- package/src/types/api/deviceUnlock.ts +1 -1
- 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 +37 -53
- package/src/types/api/kaspaSignTransaction.ts +40 -2
- package/src/types/api/openWalletSession.ts +64 -0
- package/src/types/api/protocolV2.ts +88 -54
- package/src/types/api/sessionCache.ts +14 -0
- package/src/types/device.ts +167 -3
- 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 +48 -0
- 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 +3 -0
- 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
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);
|
|
@@ -183,34 +196,25 @@ export const callAPI = async (context: CoreContext, message: CoreMessage) => {
|
|
|
183
196
|
// );
|
|
184
197
|
// }
|
|
185
198
|
|
|
186
|
-
const { requestQueue, methodSynchronize } = context;
|
|
187
|
-
const error = await methodSynchronize(() => {
|
|
188
|
-
for (const requestId of requestQueue.getRequestTasksId()) {
|
|
189
|
-
const task = requestQueue.getTask(requestId);
|
|
190
|
-
Log.debug(
|
|
191
|
-
'pre request task: ',
|
|
192
|
-
`task?.id: ${task?.id},
|
|
193
|
-
task?.method.connectId: ${task?.method.connectId},
|
|
194
|
-
task?.method.deviceId: ${task?.method.deviceId},
|
|
195
|
-
task?.method.name: ${task?.method.name}`
|
|
196
|
-
);
|
|
197
|
-
// if (task) {
|
|
198
|
-
// return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceBusy));
|
|
199
|
-
// }
|
|
200
|
-
}
|
|
201
|
-
return null;
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
if (error) {
|
|
205
|
-
return createResponseMessage(method.responseID, false, { error });
|
|
206
|
-
}
|
|
207
|
-
|
|
208
199
|
// only the pre-warm signal (PreInitialize) forks here; normal methods fall
|
|
209
200
|
// through to onCallDevice below, so the pre-warm dedup/guards never touch them
|
|
210
201
|
if (method.isPreWarmSignal) {
|
|
211
202
|
return handlePreWarmSignal(context, message, method);
|
|
212
203
|
}
|
|
213
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
|
+
|
|
214
218
|
return onCallDevice(context, message, method);
|
|
215
219
|
};
|
|
216
220
|
|
|
@@ -222,9 +226,16 @@ const handlePreWarmSignal = async (
|
|
|
222
226
|
message: CoreMessage,
|
|
223
227
|
method: BaseMethod
|
|
224
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
|
+
|
|
225
236
|
// no connectId: can't target a device safely, skip pre-warm (ack only)
|
|
226
237
|
if (!method.connectId) {
|
|
227
|
-
return
|
|
238
|
+
return createAckResponse();
|
|
228
239
|
}
|
|
229
240
|
|
|
230
241
|
const key = method.getPreWarmKey();
|
|
@@ -237,12 +248,12 @@ const handlePreWarmSignal = async (
|
|
|
237
248
|
} catch {
|
|
238
249
|
// pre-warm is best-effort; ignore its failure for the coalesced caller
|
|
239
250
|
}
|
|
240
|
-
return
|
|
251
|
+
return createAckResponse();
|
|
241
252
|
}
|
|
242
253
|
|
|
243
254
|
const doneAt = preWarmDoneAt.get(key);
|
|
244
255
|
if (typeof doneAt === 'number' && Date.now() - doneAt <= method.preWarmTtl) {
|
|
245
|
-
return
|
|
256
|
+
return createAckResponse();
|
|
246
257
|
}
|
|
247
258
|
|
|
248
259
|
const run = onCallDevice(context, message, method);
|
|
@@ -323,7 +334,7 @@ const onCallDevice = async (
|
|
|
323
334
|
|
|
324
335
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
325
336
|
|
|
326
|
-
const task = requestQueue.createTask(method);
|
|
337
|
+
const task = requestQueue.getTask(method.responseID) ?? requestQueue.createTask(method);
|
|
327
338
|
|
|
328
339
|
// Pre-warm holds the device as a per-connectId callback task so a concurrent
|
|
329
340
|
// real call waits (before ensureConnected) instead of racing its Initialize.
|
|
@@ -350,7 +361,7 @@ const onCallDevice = async (
|
|
|
350
361
|
);
|
|
351
362
|
} catch (e) {
|
|
352
363
|
preWarmCallbackTask?.resolve();
|
|
353
|
-
|
|
364
|
+
Log.debug('ensureConnected error: ', e);
|
|
354
365
|
|
|
355
366
|
completeMethodRequestContext(method, e);
|
|
356
367
|
|
|
@@ -367,6 +378,10 @@ const onCallDevice = async (
|
|
|
367
378
|
if (method.payload?.onlyConnectBleDevice) {
|
|
368
379
|
preWarmCallbackTask?.resolve();
|
|
369
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();
|
|
370
385
|
return createResponseMessage(method.responseID, true, null);
|
|
371
386
|
}
|
|
372
387
|
|
|
@@ -387,18 +402,23 @@ const onCallDevice = async (
|
|
|
387
402
|
);
|
|
388
403
|
}
|
|
389
404
|
|
|
390
|
-
device
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
+
});
|
|
397
414
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
415
|
+
device.on(DEVICE.STATE, onDeviceStateHandler);
|
|
398
416
|
device.on(
|
|
399
417
|
DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE,
|
|
400
418
|
onSelectDeviceInBootloaderForWebDeviceHandler
|
|
401
419
|
);
|
|
420
|
+
|
|
421
|
+
const protocolV2UiCoordinator = new ProtocolV2UiInteractionCoordinator(device, postMessage);
|
|
402
422
|
device.on(
|
|
403
423
|
DEVICE.SELECT_DEVICE_FOR_SWITCH_FIRMWARE_WEB_DEVICE,
|
|
404
424
|
onSelectDeviceForSwitchFirmwareWebDeviceHandler
|
|
@@ -413,8 +433,8 @@ const onCallDevice = async (
|
|
|
413
433
|
await waitForPendingPromise(getPrePendingCallPromise, setPrePendingCallPromise);
|
|
414
434
|
|
|
415
435
|
const inner = async (): Promise<void> => {
|
|
416
|
-
//
|
|
417
|
-
//
|
|
436
|
+
// The protocol is established after acquire/initialize. Reject Protocol V2-only
|
|
437
|
+
// methods on other devices through BaseMethod.requireProtocolV2.
|
|
418
438
|
if (method.requireProtocolV2 && !device.isProtocolV2()) {
|
|
419
439
|
throw createDeviceNotSupportMethodError(method.name, device.getCurrentFirmwareType());
|
|
420
440
|
}
|
|
@@ -428,8 +448,8 @@ const onCallDevice = async (
|
|
|
428
448
|
const deviceFirmwareType = device.getCurrentFirmwareType();
|
|
429
449
|
let newVersionStatus: ReturnType<typeof DataManager.getFirmwareStatus> | undefined;
|
|
430
450
|
|
|
431
|
-
//
|
|
432
|
-
// Pro2
|
|
451
|
+
// Defective-batch and forced-update gates depend on V1 features/remote config.
|
|
452
|
+
// Pro2 joins after DataManager supports its profile firmwareStatus.
|
|
433
453
|
if (device.features && !device.isProtocolV2()) {
|
|
434
454
|
await DataManager.checkAndReloadData();
|
|
435
455
|
|
|
@@ -532,7 +552,7 @@ const onCallDevice = async (
|
|
|
532
552
|
}
|
|
533
553
|
|
|
534
554
|
if (method.deviceId && method.checkDeviceId) {
|
|
535
|
-
const isSameDeviceID = device
|
|
555
|
+
const isSameDeviceID = await checkLiveDeviceId(device, method.deviceId);
|
|
536
556
|
if (!isSameDeviceID) {
|
|
537
557
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckDeviceIdError));
|
|
538
558
|
}
|
|
@@ -609,7 +629,11 @@ const onCallDevice = async (
|
|
|
609
629
|
method.device?.commands?.checkDisposed();
|
|
610
630
|
|
|
611
631
|
try {
|
|
612
|
-
const response: object = await
|
|
632
|
+
const response: object = await runMethodWithUnlockRetry(
|
|
633
|
+
method,
|
|
634
|
+
device,
|
|
635
|
+
protocolV2UiCoordinator
|
|
636
|
+
);
|
|
613
637
|
messageResponse = createResponseMessage(method.responseID, true, response);
|
|
614
638
|
requestQueue.resolveRequest(method.responseID, messageResponse);
|
|
615
639
|
completeMethodRequestContext(method);
|
|
@@ -626,6 +650,8 @@ const onCallDevice = async (
|
|
|
626
650
|
) {
|
|
627
651
|
throw error;
|
|
628
652
|
}
|
|
653
|
+
} finally {
|
|
654
|
+
protocolV2UiCoordinator.close();
|
|
629
655
|
}
|
|
630
656
|
};
|
|
631
657
|
Log.debug('Call API - Device Run: ', device.mainId);
|
|
@@ -635,8 +661,9 @@ const onCallDevice = async (
|
|
|
635
661
|
skipInitialize: canSkipInitialize(method, device),
|
|
636
662
|
...parseInitOptions(method),
|
|
637
663
|
};
|
|
638
|
-
const
|
|
639
|
-
task.callPromise = createDeferred<any>(
|
|
664
|
+
const deviceRunPromise = device.run(inner, runOptions);
|
|
665
|
+
task.callPromise = createDeferred<any>();
|
|
666
|
+
deviceRunPromise.catch(error => task.callPromise?.reject(error));
|
|
640
667
|
|
|
641
668
|
try {
|
|
642
669
|
return await task.callPromise.promise;
|
|
@@ -644,6 +671,8 @@ const onCallDevice = async (
|
|
|
644
671
|
Log.debug('Device Run Error: ', e);
|
|
645
672
|
completeMethodRequestContext(method, e);
|
|
646
673
|
return createResponseMessage(method.responseID, false, { error: e });
|
|
674
|
+
} finally {
|
|
675
|
+
await deviceRunPromise.catch(() => undefined);
|
|
647
676
|
}
|
|
648
677
|
} catch (error) {
|
|
649
678
|
messageResponse = createResponseMessage(method.responseID, false, { error });
|
|
@@ -679,7 +708,9 @@ const onCallDevice = async (
|
|
|
679
708
|
|
|
680
709
|
requestQueue.releaseTask(method.responseID);
|
|
681
710
|
|
|
682
|
-
|
|
711
|
+
if (isProtocolV2UiEnabled(method)) {
|
|
712
|
+
closePopup();
|
|
713
|
+
}
|
|
683
714
|
|
|
684
715
|
cleanup();
|
|
685
716
|
|
|
@@ -731,6 +762,15 @@ function initDevice(method: BaseMethod) {
|
|
|
731
762
|
|
|
732
763
|
if (method.connectId) {
|
|
733
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
|
+
}
|
|
734
774
|
} else if (allDevices.length === 1) {
|
|
735
775
|
[device] = allDevices;
|
|
736
776
|
} else if (allDevices.length > 1) {
|
|
@@ -1156,16 +1196,16 @@ const closePopup = () => {
|
|
|
1156
1196
|
};
|
|
1157
1197
|
|
|
1158
1198
|
const onDeviceConnectHandler = (device: Device) => {
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject
|
|
1199
|
+
const deviceObject = device.toMessageObject();
|
|
1200
|
+
if (!deviceObject) return;
|
|
1201
|
+
postMessage(createDeviceMessage(DEVICE.CONNECT, { device: deviceObject }));
|
|
1162
1202
|
};
|
|
1163
1203
|
|
|
1164
1204
|
const onDeviceDisconnectHandler = (device: Device) => {
|
|
1165
1205
|
device.clearPreInitialized();
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject
|
|
1206
|
+
const deviceObject = device.toMessageObject();
|
|
1207
|
+
if (!deviceObject) return;
|
|
1208
|
+
postMessage(createDeviceMessage(DEVICE.DISCONNECT, { device: deviceObject }));
|
|
1169
1209
|
};
|
|
1170
1210
|
|
|
1171
1211
|
const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin']) => {
|
|
@@ -1206,6 +1246,10 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
|
|
|
1206
1246
|
postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
|
|
1207
1247
|
};
|
|
1208
1248
|
|
|
1249
|
+
const onDeviceStateHandler = (...[_, stateEvent]: [...DeviceEvents['state']]) => {
|
|
1250
|
+
postMessage(createDeviceMessage(DEVICE.STATE, stateEvent));
|
|
1251
|
+
};
|
|
1252
|
+
|
|
1209
1253
|
const onDevicePassphraseHandler = async (
|
|
1210
1254
|
...[device, requestPayload, callback]: DeviceEvents['passphrase']
|
|
1211
1255
|
) => {
|
|
@@ -1216,6 +1260,9 @@ const onDevicePassphraseHandler = async (
|
|
|
1216
1260
|
device: device.toMessageObject() as KnownDevice,
|
|
1217
1261
|
passphraseState: device.passphraseState,
|
|
1218
1262
|
existsAttachPinUser: requestPayload.existsAttachPinUser,
|
|
1263
|
+
source: requestPayload.source,
|
|
1264
|
+
reason: requestPayload.reason,
|
|
1265
|
+
expectedPassphraseState: requestPayload.expectedPassphraseState,
|
|
1219
1266
|
})
|
|
1220
1267
|
);
|
|
1221
1268
|
// wait for passphrase
|
|
@@ -1237,12 +1284,27 @@ const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']
|
|
|
1237
1284
|
};
|
|
1238
1285
|
|
|
1239
1286
|
const onEnterPassphraseOnDeviceHandler = (
|
|
1240
|
-
...[device]: [...DeviceEvents['passphrase_on_device']]
|
|
1287
|
+
...[device, requestPayload]: [...DeviceEvents['passphrase_on_device']]
|
|
1241
1288
|
) => {
|
|
1242
1289
|
postMessage(
|
|
1243
1290
|
createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
1244
1291
|
device: device.toMessageObject() as KnownDevice,
|
|
1245
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,
|
|
1246
1308
|
})
|
|
1247
1309
|
);
|
|
1248
1310
|
};
|
|
@@ -1313,6 +1375,8 @@ export default class Core extends EventEmitter {
|
|
|
1313
1375
|
|
|
1314
1376
|
private requestQueue = new RequestQueue();
|
|
1315
1377
|
|
|
1378
|
+
private disposePromise?: Promise<void>;
|
|
1379
|
+
|
|
1316
1380
|
// background task
|
|
1317
1381
|
private prePendingCallPromise: Promise<void> | undefined;
|
|
1318
1382
|
|
|
@@ -1325,6 +1389,10 @@ export default class Core extends EventEmitter {
|
|
|
1325
1389
|
Log.debug(`[Core] Created SDK instance: ${this.sdkInstanceId}`);
|
|
1326
1390
|
}
|
|
1327
1391
|
|
|
1392
|
+
cancelOperation(operationId: string) {
|
|
1393
|
+
this.requestQueue.abortOperation(operationId);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1328
1396
|
private getCoreContext() {
|
|
1329
1397
|
return {
|
|
1330
1398
|
sdkInstanceId: this.sdkInstanceId,
|
|
@@ -1371,10 +1439,17 @@ export default class Core extends EventEmitter {
|
|
|
1371
1439
|
}
|
|
1372
1440
|
|
|
1373
1441
|
case IFRAME.CALL: {
|
|
1374
|
-
|
|
1442
|
+
const logBlockLabel = getLogBlockLabel(message);
|
|
1443
|
+
Log.log(
|
|
1444
|
+
`[${Date.now()}][CALL_API]`,
|
|
1445
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : message
|
|
1446
|
+
);
|
|
1375
1447
|
const response = await callAPI(this.getCoreContext(), message);
|
|
1376
1448
|
const { success, payload } = response;
|
|
1377
|
-
Log.log(
|
|
1449
|
+
Log.log(
|
|
1450
|
+
`[${Date.now()}][CALL_API_RESPONSE]`,
|
|
1451
|
+
logBlockLabel ? { method: logBlockLabel, payload: '[REDACTED]' } : response
|
|
1452
|
+
);
|
|
1378
1453
|
if (success) {
|
|
1379
1454
|
return response;
|
|
1380
1455
|
}
|
|
@@ -1393,6 +1468,10 @@ export default class Core extends EventEmitter {
|
|
|
1393
1468
|
cancel(this.getCoreContext(), message.payload.connectId);
|
|
1394
1469
|
break;
|
|
1395
1470
|
}
|
|
1471
|
+
case IFRAME.CANCEL_OPERATION: {
|
|
1472
|
+
this.cancelOperation(message.payload.operationId);
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1396
1475
|
case IFRAME.CALLBACK: {
|
|
1397
1476
|
Log.log('callback message: ', message);
|
|
1398
1477
|
postMessage(message);
|
|
@@ -1404,20 +1483,52 @@ export default class Core extends EventEmitter {
|
|
|
1404
1483
|
return Promise.resolve(message);
|
|
1405
1484
|
}
|
|
1406
1485
|
|
|
1407
|
-
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.
|
|
1408
1511
|
_deviceList = undefined;
|
|
1409
1512
|
_connector = undefined;
|
|
1513
|
+
DevicePool.resetState();
|
|
1410
1514
|
deviceCacheMap.clear();
|
|
1411
1515
|
preWarmInflight.clear();
|
|
1412
1516
|
preWarmDoneAt.clear();
|
|
1413
|
-
|
|
1517
|
+
preConnectCache = { passphraseState: undefined };
|
|
1518
|
+
this.prePendingCallPromise = undefined;
|
|
1519
|
+
this.removeAllListeners();
|
|
1414
1520
|
cleanupSdkInstance(this.sdkInstanceId);
|
|
1521
|
+
if (_core === this) _core = undefined;
|
|
1522
|
+
|
|
1523
|
+
// Transports, especially Node USB, may release native handles asynchronously.
|
|
1524
|
+
await transportCleanup;
|
|
1415
1525
|
}
|
|
1416
1526
|
}
|
|
1417
1527
|
|
|
1418
1528
|
export const initCore = () => {
|
|
1419
|
-
|
|
1420
|
-
|
|
1529
|
+
const core = new Core();
|
|
1530
|
+
_core = core;
|
|
1531
|
+
return core;
|
|
1421
1532
|
};
|
|
1422
1533
|
|
|
1423
1534
|
export const initConnector = () => {
|