@onekeyfe/hd-core 1.1.34-alpha.2 → 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 -5611
- 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 +253 -125
- 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
|
@@ -9,7 +9,6 @@ import { validatePath } from '../helpers/pathUtils';
|
|
|
9
9
|
import { BaseMethod } from '../BaseMethod';
|
|
10
10
|
import { validateParams } from '../helpers/paramsValidator';
|
|
11
11
|
import { formatAnyHex, parseChainId, stripHexStartZeroes } from '../helpers/hexUtils';
|
|
12
|
-
import { getDeviceFirmwareVersion, getDeviceType } from '../../utils';
|
|
13
12
|
import { existCapability } from '../../utils/capabilitieUtils';
|
|
14
13
|
import {
|
|
15
14
|
DeviceModelToTypes,
|
|
@@ -26,11 +25,19 @@ import { encodeData, getFieldType, parseArrayType } from '../helpers/typeNameUti
|
|
|
26
25
|
import type {
|
|
27
26
|
EthereumTypedDataSignature,
|
|
28
27
|
EthereumTypedDataStructAck,
|
|
28
|
+
EthereumTypedDataStructAckOneKey,
|
|
29
29
|
MessageKey,
|
|
30
30
|
MessageResponse,
|
|
31
31
|
TypedCall,
|
|
32
32
|
} from '@onekeyfe/hd-transport';
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* EthereumTypedDataStructAckOneKey and EthereumTypedDataStructAck have identical
|
|
36
|
+
* fields and enum values. This zero-cost nominal conversion avoids scattered `any`.
|
|
37
|
+
*/
|
|
38
|
+
const toOneKeyStructAck = (ack: EthereumTypedDataStructAck): EthereumTypedDataStructAckOneKey =>
|
|
39
|
+
ack as unknown as EthereumTypedDataStructAckOneKey;
|
|
40
|
+
|
|
34
41
|
export type EVMSignTypedDataParams = {
|
|
35
42
|
addressN: number[];
|
|
36
43
|
metamaskV4Compat: boolean;
|
|
@@ -130,7 +137,6 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
130
137
|
if (supportTrezor) {
|
|
131
138
|
response = await typedCall(
|
|
132
139
|
'EthereumTypedDataStructAck',
|
|
133
|
-
// @ts-ignore
|
|
134
140
|
[
|
|
135
141
|
'EthereumTypedDataStructRequest',
|
|
136
142
|
'EthereumTypedDataValueRequest',
|
|
@@ -141,13 +147,12 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
141
147
|
} else {
|
|
142
148
|
response = await typedCall(
|
|
143
149
|
'EthereumTypedDataStructAckOneKey',
|
|
144
|
-
// @ts-ignore
|
|
145
150
|
[
|
|
146
151
|
'EthereumTypedDataStructRequestOneKey',
|
|
147
152
|
'EthereumTypedDataValueRequestOneKey',
|
|
148
153
|
'EthereumTypedDataSignatureOneKey',
|
|
149
154
|
],
|
|
150
|
-
dataStruckAck
|
|
155
|
+
toOneKeyStructAck(dataStruckAck)
|
|
151
156
|
);
|
|
152
157
|
}
|
|
153
158
|
}
|
|
@@ -183,7 +188,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
183
188
|
} else if (typeof memberData === 'object' && memberData !== null) {
|
|
184
189
|
const memberTypeDefinition = types[memberTypeName][index];
|
|
185
190
|
memberTypeName = memberTypeDefinition.type;
|
|
186
|
-
memberData = memberData[memberTypeDefinition.name];
|
|
191
|
+
memberData = (memberData as Record<string, unknown>)[memberTypeDefinition.name];
|
|
187
192
|
} else {
|
|
188
193
|
// TODO
|
|
189
194
|
}
|
|
@@ -220,6 +225,14 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
220
225
|
|
|
221
226
|
if (response.type === 'EthereumGnosisSafeTxRequest') {
|
|
222
227
|
const { data } = this.params;
|
|
228
|
+
const verifyingContract = data.domain?.verifyingContract;
|
|
229
|
+
// verifyingContract is required by proto and essential to a Gnosis Safe signature.
|
|
230
|
+
if (!verifyingContract) {
|
|
231
|
+
throw ERRORS.TypedError(
|
|
232
|
+
HardwareErrorCode.CallMethodInvalidParameter,
|
|
233
|
+
'EIP712Domain.verifyingContract is required for Gnosis Safe transaction'
|
|
234
|
+
);
|
|
235
|
+
}
|
|
223
236
|
const param = {
|
|
224
237
|
to: data.message.to,
|
|
225
238
|
value: formatAnyHex(new BigNumber(data.message.value).toString(16)),
|
|
@@ -232,11 +245,10 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
232
245
|
refundReceiver: data.message.refundReceiver,
|
|
233
246
|
nonce: formatAnyHex(new BigNumber(data.message.nonce).toString(16)),
|
|
234
247
|
chain_id: parseChainId(data.domain.chainId),
|
|
235
|
-
verifyingContract
|
|
248
|
+
verifyingContract,
|
|
236
249
|
};
|
|
237
250
|
response = await typedCall(
|
|
238
251
|
'EthereumGnosisSafeTxAck',
|
|
239
|
-
// @ts-ignore
|
|
240
252
|
['EthereumTypedDataSignature', 'EthereumTypedDataSignatureOneKey'],
|
|
241
253
|
param
|
|
242
254
|
);
|
|
@@ -262,8 +274,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
262
274
|
|
|
263
275
|
let supportTrezor = false;
|
|
264
276
|
let response: MessageResponse<MessageKey>;
|
|
265
|
-
switch (TransportManager.
|
|
266
|
-
case '
|
|
277
|
+
switch (TransportManager.getProtocolV1MessageSchema()) {
|
|
278
|
+
case 'v1LegacySchema':
|
|
267
279
|
supportTrezor = true;
|
|
268
280
|
response = await signTypedDataLegacyV1({
|
|
269
281
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
@@ -274,7 +286,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
274
286
|
});
|
|
275
287
|
break;
|
|
276
288
|
|
|
277
|
-
case '
|
|
289
|
+
case 'v1CurrentSchema':
|
|
278
290
|
default:
|
|
279
291
|
supportTrezor = false;
|
|
280
292
|
response = await signTypedData({
|
|
@@ -310,8 +322,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
310
322
|
}) {
|
|
311
323
|
if (!domainHash) throw ERRORS.TypedError('Runtime', 'domainHash is required');
|
|
312
324
|
|
|
313
|
-
switch (TransportManager.
|
|
314
|
-
case '
|
|
325
|
+
switch (TransportManager.getProtocolV1MessageSchema()) {
|
|
326
|
+
case 'v1LegacySchema':
|
|
315
327
|
return signTypedHashLegacyV1({
|
|
316
328
|
typedCall,
|
|
317
329
|
addressN,
|
|
@@ -321,7 +333,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
321
333
|
device: this.device,
|
|
322
334
|
});
|
|
323
335
|
|
|
324
|
-
case '
|
|
336
|
+
case 'v1CurrentSchema':
|
|
325
337
|
default:
|
|
326
338
|
return signTypedHash({
|
|
327
339
|
typedCall,
|
|
@@ -348,8 +360,8 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
348
360
|
|
|
349
361
|
let biggerLimit = 1024; // 1k
|
|
350
362
|
|
|
351
|
-
const currentVersion =
|
|
352
|
-
const currentDeviceType =
|
|
363
|
+
const currentVersion = this.device.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
364
|
+
const currentDeviceType = this.device.getCurrentDeviceType();
|
|
353
365
|
const supportBiggerDataVersion = '4.4.0';
|
|
354
366
|
|
|
355
367
|
const supportBiggerData =
|
|
@@ -532,9 +544,9 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
532
544
|
}
|
|
533
545
|
|
|
534
546
|
supportSignTyped() {
|
|
535
|
-
const deviceType =
|
|
547
|
+
const deviceType = this.device.getCurrentDeviceType();
|
|
536
548
|
if (DeviceModelToTypes.model_mini.includes(deviceType)) {
|
|
537
|
-
const currentVersion =
|
|
549
|
+
const currentVersion = this.device.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
538
550
|
const supportSignTypedVersion = '2.2.0';
|
|
539
551
|
|
|
540
552
|
if (semver.lt(currentVersion, supportSignTypedVersion)) {
|
|
@@ -564,7 +576,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
|
|
|
564
576
|
// For Classic / Mini:
|
|
565
577
|
// - If parsed typed-data capability is missing, keep using blind-sign.
|
|
566
578
|
// - For Mini with parsed capability, add extra format checks before parsed signing.
|
|
567
|
-
const deviceType =
|
|
579
|
+
const deviceType = this.device.getCurrentDeviceType();
|
|
568
580
|
if (
|
|
569
581
|
DeviceModelToTypes.model_mini.includes(deviceType) &&
|
|
570
582
|
(!supportEip712OnClassic || this.hasClassicFamilyTypedDataFormatViolations(this.params.data))
|
|
@@ -31,7 +31,7 @@ export default class EVMSignMessage extends BaseMethod<EthereumVerifyMessageOneK
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
async run() {
|
|
34
|
-
if (TransportManager.
|
|
34
|
+
if (TransportManager.getProtocolV1MessageSchema() === 'v1LegacySchema') {
|
|
35
35
|
return verifyMessageLegacyV1({
|
|
36
36
|
typedCall: this.device.commands.typedCall.bind(this.device.commands),
|
|
37
37
|
params: this.params,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
3
|
|
|
4
|
-
import { getDeviceFirmwareVersion, getDeviceType } from '../../../utils';
|
|
5
|
-
|
|
6
4
|
import type { Device } from '../../../device/Device';
|
|
7
5
|
import type { MessageResponse, TypedCall } from '@onekeyfe/hd-transport';
|
|
8
6
|
|
|
@@ -21,10 +19,10 @@ export const signTypedHash = async ({
|
|
|
21
19
|
domainHash: string;
|
|
22
20
|
messageHash: string | undefined;
|
|
23
21
|
}): Promise<MessageResponse<'EthereumTypedDataSignatureOneKey'>> => {
|
|
24
|
-
const deviceType =
|
|
22
|
+
const deviceType = device.getCurrentDeviceType();
|
|
25
23
|
if (deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro) {
|
|
26
24
|
// Touch Pro Sign NestedArrays
|
|
27
|
-
const currentVersion =
|
|
25
|
+
const currentVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
28
26
|
const supportNestedArraysSignVersion = '4.2.0';
|
|
29
27
|
|
|
30
28
|
// 4.2.0 is the first version that supports nested arrays in signTypedData
|
|
@@ -7,10 +7,12 @@ export default async function ({
|
|
|
7
7
|
typedCall: TypedCall;
|
|
8
8
|
param: EthereumGetAddressOneKey;
|
|
9
9
|
}): Promise<MessageResponse<'EthereumAddress'>> {
|
|
10
|
-
|
|
10
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
11
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
12
|
+
const message = {
|
|
11
13
|
address_n: param.address_n,
|
|
12
14
|
show_display: param.show_display,
|
|
13
|
-
// @ts-ignore
|
|
14
15
|
chain_id: param.chain_id,
|
|
15
|
-
}
|
|
16
|
+
};
|
|
17
|
+
return typedCall('EthereumGetAddress', 'EthereumAddress', message);
|
|
16
18
|
}
|
|
@@ -11,10 +11,12 @@ export default async function ({
|
|
|
11
11
|
typedCall: TypedCall;
|
|
12
12
|
param: EthereumGetPublicKeyOneKey;
|
|
13
13
|
}): Promise<MessageResponse<'EthereumPublicKey'>> {
|
|
14
|
-
|
|
14
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
15
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
16
|
+
const message = {
|
|
15
17
|
address_n: param.address_n,
|
|
16
18
|
show_display: param.show_display,
|
|
17
|
-
// @ts-ignore
|
|
18
19
|
chain_id: param.chain_id,
|
|
19
|
-
}
|
|
20
|
+
};
|
|
21
|
+
return typedCall('EthereumGetPublicKey', 'EthereumPublicKey', message);
|
|
20
22
|
}
|
|
@@ -11,12 +11,14 @@ export default async function ({
|
|
|
11
11
|
typedCall: TypedCall;
|
|
12
12
|
params: EthereumSignMessageOneKey;
|
|
13
13
|
}): Promise<EthereumMessageSignature> {
|
|
14
|
-
|
|
14
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
15
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
16
|
+
const message = {
|
|
15
17
|
address_n: params.address_n,
|
|
16
18
|
message: params.message,
|
|
17
|
-
// @ts-ignore
|
|
18
19
|
chain_id: params.chain_id,
|
|
19
|
-
}
|
|
20
|
+
};
|
|
21
|
+
const res = await typedCall('EthereumSignMessage', 'EthereumMessageSignature', message);
|
|
20
22
|
|
|
21
23
|
return Promise.resolve(res.message);
|
|
22
24
|
}
|
|
@@ -16,22 +16,23 @@ export const signTypedData = async ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const { primaryType }: EthereumSignTypedDataMessage<EthereumSignTypedDataTypes> = data;
|
|
18
18
|
|
|
19
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
20
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
21
|
+
const message = {
|
|
22
|
+
address_n: addressN,
|
|
23
|
+
primary_type: primaryType as string,
|
|
24
|
+
metamask_v4_compat: metamaskV4Compat,
|
|
25
|
+
chain_id: chainId,
|
|
26
|
+
};
|
|
19
27
|
const response = await typedCall(
|
|
20
28
|
'EthereumSignTypedData',
|
|
21
|
-
// @ts-ignore
|
|
22
29
|
[
|
|
23
30
|
'EthereumTypedDataStructRequest',
|
|
24
31
|
'EthereumTypedDataValueRequest',
|
|
25
32
|
'EthereumTypedDataSignature',
|
|
26
33
|
'EthereumGnosisSafeTxRequest',
|
|
27
34
|
],
|
|
28
|
-
|
|
29
|
-
address_n: addressN,
|
|
30
|
-
primary_type: primaryType as string,
|
|
31
|
-
metamask_v4_compat: metamaskV4Compat,
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
chain_id: chainId,
|
|
34
|
-
}
|
|
35
|
+
message
|
|
35
36
|
);
|
|
36
37
|
return response;
|
|
37
38
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
2
|
import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
3
3
|
|
|
4
|
-
import { getDeviceFirmwareVersion, getDeviceType } from '../../../utils';
|
|
5
|
-
|
|
6
4
|
import type { Device } from '../../../device/Device';
|
|
7
5
|
import type { MessageResponse, TypedCall } from '@onekeyfe/hd-transport';
|
|
8
6
|
|
|
@@ -24,10 +22,10 @@ export const signTypedHash = async ({
|
|
|
24
22
|
| MessageResponse<'EthereumTypedDataSignature'>
|
|
25
23
|
| MessageResponse<'EthereumTypedDataSignatureOneKey'>
|
|
26
24
|
> => {
|
|
27
|
-
const deviceType =
|
|
25
|
+
const deviceType = device.getCurrentDeviceType();
|
|
28
26
|
if (deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro) {
|
|
29
27
|
// Touch Pro Sign NestedArrays
|
|
30
|
-
const currentVersion =
|
|
28
|
+
const currentVersion = device.getCurrentFirmwareVersionString() ?? '0.0.0';
|
|
31
29
|
const supportNestedArraysSignVersion = '4.2.0';
|
|
32
30
|
|
|
33
31
|
// 4.2.0 is the first version that supports nested arrays in signTypedData
|
|
@@ -40,11 +38,13 @@ export const signTypedHash = async ({
|
|
|
40
38
|
}
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
42
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
43
|
+
const message = {
|
|
44
44
|
address_n: addressN,
|
|
45
45
|
domain_separator_hash: domainHash ?? '',
|
|
46
46
|
message_hash: messageHash,
|
|
47
|
-
// @ts-ignore
|
|
48
47
|
chain_id: chainId,
|
|
49
|
-
}
|
|
48
|
+
};
|
|
49
|
+
return typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', message);
|
|
50
50
|
};
|
|
@@ -7,13 +7,15 @@ export default async function ({
|
|
|
7
7
|
typedCall: TypedCall;
|
|
8
8
|
params: EthereumVerifyMessageOneKey;
|
|
9
9
|
}): Promise<Success> {
|
|
10
|
-
|
|
10
|
+
// The generated legacy type omits chain_id, but old firmware accepts the OneKey
|
|
11
|
+
// extension. A non-fresh object preserves that runtime field without a type cast.
|
|
12
|
+
const message = {
|
|
11
13
|
signature: params.signature,
|
|
12
14
|
message: params.message,
|
|
13
15
|
address: params.address,
|
|
14
|
-
// @ts-ignore
|
|
15
16
|
chain_id: params.chain_id,
|
|
16
|
-
}
|
|
17
|
+
};
|
|
18
|
+
const res = await typedCall('EthereumVerifyMessage', 'Success', message);
|
|
17
19
|
|
|
18
20
|
return Promise.resolve(res.message);
|
|
19
21
|
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
FirmwareArtifactReader,
|
|
5
|
+
FirmwareArtifactReference,
|
|
6
|
+
} from '../../types/api/firmwareUpdate';
|
|
7
|
+
|
|
8
|
+
export const MAX_FIRMWARE_ARTIFACT_READ_BYTES = 256 * 1024;
|
|
9
|
+
|
|
10
|
+
export interface FirmwareByteSource {
|
|
11
|
+
readonly size: number;
|
|
12
|
+
readAt(offset: number, length: number): Promise<ArrayBuffer>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const artifactError = (
|
|
17
|
+
code:
|
|
18
|
+
| 'FirmwareArtifactReceiptMismatch'
|
|
19
|
+
| 'FirmwareArtifactReaderInvalid'
|
|
20
|
+
| 'FirmwareArtifactReadOutOfBounds'
|
|
21
|
+
| 'FirmwareArtifactReadTooLarge',
|
|
22
|
+
message: string
|
|
23
|
+
): never => {
|
|
24
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, message, {
|
|
25
|
+
firmwareUpdateCode: code,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const assertSafeSize = (value: number, name: string) => {
|
|
30
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
31
|
+
artifactError('FirmwareArtifactReceiptMismatch', `${name} must be a positive safe integer`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const assertFirmwareArtifactReference = (
|
|
36
|
+
artifact: FirmwareArtifactReference
|
|
37
|
+
): FirmwareArtifactReference => {
|
|
38
|
+
if (
|
|
39
|
+
!artifact ||
|
|
40
|
+
typeof artifact.artifactRef !== 'string' ||
|
|
41
|
+
artifact.artifactRef.length === 0 ||
|
|
42
|
+
artifact.artifactRef.length > 160 ||
|
|
43
|
+
artifact.artifactRef.includes('/') ||
|
|
44
|
+
artifact.artifactRef.includes('\\')
|
|
45
|
+
) {
|
|
46
|
+
artifactError(
|
|
47
|
+
'FirmwareArtifactReceiptMismatch',
|
|
48
|
+
'Firmware artifactRef must be an opaque identifier'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
assertSafeSize(artifact.size, 'Firmware artifact size');
|
|
52
|
+
if (typeof artifact.sha256 !== 'string' || !/^[a-f0-9]{64}$/i.test(artifact.sha256)) {
|
|
53
|
+
artifactError(
|
|
54
|
+
'FirmwareArtifactReceiptMismatch',
|
|
55
|
+
'Firmware artifact sha256 must be a 32-byte hexadecimal digest'
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return artifact;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const assertFirmwareArtifactRead = (size: number, offset: number, length: number) => {
|
|
62
|
+
if (
|
|
63
|
+
!Number.isSafeInteger(offset) ||
|
|
64
|
+
offset < 0 ||
|
|
65
|
+
offset >= size ||
|
|
66
|
+
!Number.isSafeInteger(length) ||
|
|
67
|
+
length <= 0 ||
|
|
68
|
+
offset + length > size
|
|
69
|
+
) {
|
|
70
|
+
artifactError(
|
|
71
|
+
'FirmwareArtifactReadOutOfBounds',
|
|
72
|
+
`Firmware artifact read is outside size ${size}: offset=${offset}, length=${length}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (length > MAX_FIRMWARE_ARTIFACT_READ_BYTES) {
|
|
76
|
+
artifactError(
|
|
77
|
+
'FirmwareArtifactReadTooLarge',
|
|
78
|
+
`Firmware artifact read length ${length} exceeds ${MAX_FIRMWARE_ARTIFACT_READ_BYTES}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const createMemoryFirmwareByteSource = (binary: ArrayBuffer): FirmwareByteSource => {
|
|
84
|
+
let bytes: Uint8Array | null = new Uint8Array(binary);
|
|
85
|
+
const { byteLength: size } = binary;
|
|
86
|
+
assertSafeSize(size, 'Firmware binary size');
|
|
87
|
+
return {
|
|
88
|
+
size,
|
|
89
|
+
readAt: (offset, length) => {
|
|
90
|
+
if (!bytes) {
|
|
91
|
+
return Promise.reject(
|
|
92
|
+
ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Firmware byte source is closed', {
|
|
93
|
+
firmwareUpdateCode: 'FirmwareArtifactReaderInvalid',
|
|
94
|
+
})
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
assertFirmwareArtifactRead(size, offset, length);
|
|
98
|
+
return Promise.resolve(bytes.slice(offset, offset + length).buffer);
|
|
99
|
+
},
|
|
100
|
+
close: () => {
|
|
101
|
+
bytes = null;
|
|
102
|
+
return Promise.resolve();
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
class ReaderFirmwareByteSource implements FirmwareByteSource {
|
|
108
|
+
readonly size: number;
|
|
109
|
+
|
|
110
|
+
private closed = false;
|
|
111
|
+
|
|
112
|
+
private reading = false;
|
|
113
|
+
|
|
114
|
+
private constructor(
|
|
115
|
+
private readonly reader: FirmwareArtifactReader,
|
|
116
|
+
private readonly readerId: string,
|
|
117
|
+
size: number
|
|
118
|
+
) {
|
|
119
|
+
this.size = size;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static async open(
|
|
123
|
+
artifact: FirmwareArtifactReference,
|
|
124
|
+
reader: FirmwareArtifactReader
|
|
125
|
+
): Promise<ReaderFirmwareByteSource> {
|
|
126
|
+
const opened = await reader.open({ artifactRef: artifact.artifactRef });
|
|
127
|
+
if (
|
|
128
|
+
!opened ||
|
|
129
|
+
typeof opened.readerId !== 'string' ||
|
|
130
|
+
opened.readerId.length === 0 ||
|
|
131
|
+
!Number.isSafeInteger(opened.size) ||
|
|
132
|
+
opened.size !== artifact.size
|
|
133
|
+
) {
|
|
134
|
+
if (opened?.readerId) {
|
|
135
|
+
await reader.close({ readerId: opened.readerId }).catch(() => undefined);
|
|
136
|
+
}
|
|
137
|
+
return artifactError(
|
|
138
|
+
'FirmwareArtifactReceiptMismatch',
|
|
139
|
+
`Firmware artifact opened with size ${opened?.size ?? 'unknown'}, expected ${artifact.size}`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return new ReaderFirmwareByteSource(reader, opened.readerId, opened.size);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async readAt(offset: number, length: number): Promise<ArrayBuffer> {
|
|
146
|
+
if (this.closed) {
|
|
147
|
+
return artifactError('FirmwareArtifactReaderInvalid', 'Firmware artifact reader is closed');
|
|
148
|
+
}
|
|
149
|
+
if (this.reading) {
|
|
150
|
+
return artifactError(
|
|
151
|
+
'FirmwareArtifactReaderInvalid',
|
|
152
|
+
'Firmware artifact reader only permits one in-flight read'
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
assertFirmwareArtifactRead(this.size, offset, length);
|
|
156
|
+
this.reading = true;
|
|
157
|
+
try {
|
|
158
|
+
const result = await this.reader.read({
|
|
159
|
+
readerId: this.readerId,
|
|
160
|
+
offset,
|
|
161
|
+
length,
|
|
162
|
+
});
|
|
163
|
+
const expectedEof = offset + length === this.size;
|
|
164
|
+
if (
|
|
165
|
+
!result ||
|
|
166
|
+
!(result.data instanceof ArrayBuffer) ||
|
|
167
|
+
result.data.byteLength !== length ||
|
|
168
|
+
result.bytesRead !== length ||
|
|
169
|
+
result.eof !== expectedEof
|
|
170
|
+
) {
|
|
171
|
+
return artifactError(
|
|
172
|
+
'FirmwareArtifactReaderInvalid',
|
|
173
|
+
'Firmware artifact reader returned an invalid read result'
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return result.data;
|
|
177
|
+
} finally {
|
|
178
|
+
this.reading = false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async close(): Promise<void> {
|
|
183
|
+
if (this.closed) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.closed = true;
|
|
187
|
+
await this.reader.close({ readerId: this.readerId });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const openFirmwareByteSource = async ({
|
|
192
|
+
binary,
|
|
193
|
+
artifact,
|
|
194
|
+
reader,
|
|
195
|
+
}: {
|
|
196
|
+
binary?: ArrayBuffer;
|
|
197
|
+
artifact?: FirmwareArtifactReference;
|
|
198
|
+
reader?: FirmwareArtifactReader;
|
|
199
|
+
}): Promise<FirmwareByteSource | null> => {
|
|
200
|
+
if (binary && artifact) {
|
|
201
|
+
return artifactError(
|
|
202
|
+
'FirmwareArtifactReceiptMismatch',
|
|
203
|
+
'Firmware input must not contain both binary and artifactRef'
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
if (binary) {
|
|
207
|
+
return createMemoryFirmwareByteSource(binary);
|
|
208
|
+
}
|
|
209
|
+
if (!artifact) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
assertFirmwareArtifactReference(artifact);
|
|
213
|
+
if (!reader) {
|
|
214
|
+
return artifactError(
|
|
215
|
+
'FirmwareArtifactReaderInvalid',
|
|
216
|
+
'Firmware artifact reader is required for artifactRef input'
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return ReaderFirmwareByteSource.open(artifact, reader);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const readFirmwareByteSourceFully = async (
|
|
223
|
+
source: FirmwareByteSource
|
|
224
|
+
): Promise<ArrayBuffer> => {
|
|
225
|
+
const output = new Uint8Array(source.size);
|
|
226
|
+
let offset = 0;
|
|
227
|
+
while (offset < source.size) {
|
|
228
|
+
const length = Math.min(MAX_FIRMWARE_ARTIFACT_READ_BYTES, source.size - offset);
|
|
229
|
+
output.set(new Uint8Array(await source.readAt(offset, length)), offset);
|
|
230
|
+
offset += length;
|
|
231
|
+
}
|
|
232
|
+
return output.buffer;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export const writeFirmwareByteSource = async ({
|
|
236
|
+
source,
|
|
237
|
+
chunkSize,
|
|
238
|
+
write,
|
|
239
|
+
}: {
|
|
240
|
+
source: FirmwareByteSource;
|
|
241
|
+
chunkSize: number;
|
|
242
|
+
write: (input: {
|
|
243
|
+
data: ArrayBuffer;
|
|
244
|
+
sourceOffset: number;
|
|
245
|
+
length: number;
|
|
246
|
+
first: boolean;
|
|
247
|
+
}) => Promise<number>;
|
|
248
|
+
}) => {
|
|
249
|
+
if (
|
|
250
|
+
!Number.isSafeInteger(chunkSize) ||
|
|
251
|
+
chunkSize <= 0 ||
|
|
252
|
+
chunkSize > MAX_FIRMWARE_ARTIFACT_READ_BYTES
|
|
253
|
+
) {
|
|
254
|
+
return artifactError(
|
|
255
|
+
'FirmwareArtifactReadTooLarge',
|
|
256
|
+
`Firmware artifact chunk size must be between 1 and ${MAX_FIRMWARE_ARTIFACT_READ_BYTES}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
let offset = 0;
|
|
260
|
+
while (offset < source.size) {
|
|
261
|
+
const length = Math.min(chunkSize, source.size - offset);
|
|
262
|
+
const data = await source.readAt(offset, length);
|
|
263
|
+
const processed = await write({
|
|
264
|
+
data,
|
|
265
|
+
sourceOffset: offset,
|
|
266
|
+
length,
|
|
267
|
+
first: offset === 0,
|
|
268
|
+
});
|
|
269
|
+
if (processed !== length) {
|
|
270
|
+
return artifactError(
|
|
271
|
+
'FirmwareArtifactReaderInvalid',
|
|
272
|
+
`Firmware artifact writer processed ${processed} bytes, expected ${length}`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
offset += length;
|
|
276
|
+
}
|
|
277
|
+
return offset;
|
|
278
|
+
};
|