@onekeyfe/hd-core 1.2.0-alpha.57 → 1.2.0-alpha.58
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 +84 -2
- package/__tests__/DeviceCommands.test.ts +17 -6
- package/__tests__/core-initialization.test.ts +23 -0
- package/__tests__/device-connector-protocol.test.ts +81 -0
- package/__tests__/device-settings.test.ts +39 -18
- package/__tests__/protocol-v2-resources.test.ts +24 -0
- package/__tests__/protocol-v2.test.ts +49 -126
- package/__tests__/protocolV2FileWrite.test.ts +113 -0
- package/__tests__/public-pro2-api-boundary.test.ts +2 -98
- package/dist/api/FirmwareUpdateV4.d.ts +0 -1
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceSettings.d.ts.map +1 -1
- package/dist/api/device/DeviceVerify.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +4 -2
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +7 -0
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -3
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoGet.d.ts.map +1 -1
- package/dist/api/protocol-v2/DeviceFactoryInfoSet.d.ts.map +1 -1
- package/dist/api/protocol-v2/helpers.d.ts +5 -15
- package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/api/utils.d.ts +1 -6
- package/dist/api/utils.d.ts.map +1 -1
- package/dist/core/index.d.ts +4 -10
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +1 -0
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/TransportManager.d.ts.map +1 -1
- 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/index.d.ts +44 -723
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +499 -2953
- package/dist/inject.d.ts +2 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +3 -176
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +2 -8
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/FirmwareUpdateV4.ts +39 -69
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +3 -1
- package/src/api/device/DeviceSettings.ts +5 -4
- package/src/api/device/DeviceVerify.ts +0 -2
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +12 -1
- package/src/api/helpers/protocolV2FileWrite.ts +192 -73
- package/src/api/index.ts +0 -3
- package/src/api/protocol-v2/DeviceFactoryInfoGet.ts +0 -3
- package/src/api/protocol-v2/DeviceFactoryInfoSet.ts +7 -6
- package/src/api/protocol-v2/helpers.ts +5 -152
- package/src/api/utils.ts +1 -46
- package/src/core/index.ts +16 -28
- package/src/data-manager/DataManager.ts +25 -4
- package/src/data-manager/TransportManager.ts +6 -0
- package/src/device/DeviceCommands.ts +20 -2
- package/src/device/DeviceConnector.ts +33 -13
- package/src/index.ts +0 -5
- package/src/inject.ts +7 -209
- package/src/types/api/index.ts +2 -288
- package/src/types/api/protocolV2.ts +2 -43
- package/__tests__/public-test-api-boundary.test.ts +0 -167
- package/dist/api/BixinBackupDevice.d.ts +0 -7
- package/dist/api/BixinBackupDevice.d.ts.map +0 -1
- package/dist/api/BixinLoadDevice.d.ts +0 -7
- package/dist/api/BixinLoadDevice.d.ts.map +0 -1
- package/dist/api/BixinMessageSE.d.ts +0 -8
- package/dist/api/BixinMessageSE.d.ts.map +0 -1
- package/dist/api/BixinVerifyDeviceRequest.d.ts +0 -8
- package/dist/api/BixinVerifyDeviceRequest.d.ts.map +0 -1
- package/dist/api/WebAuthnAddResidentCredential.d.ts +0 -8
- package/dist/api/WebAuthnAddResidentCredential.d.ts.map +0 -1
- package/dist/api/WebAuthnListResidentCredentials.d.ts +0 -8
- package/dist/api/WebAuthnListResidentCredentials.d.ts.map +0 -1
- package/dist/api/WebAuthnRemoveResidentCredential.d.ts +0 -8
- package/dist/api/WebAuthnRemoveResidentCredential.d.ts.map +0 -1
- package/dist/api/binance/BinanceGetAddress.d.ts +0 -8
- package/dist/api/binance/BinanceGetAddress.d.ts.map +0 -1
- package/dist/api/binance/BinanceGetPublicKey.d.ts +0 -8
- package/dist/api/binance/BinanceGetPublicKey.d.ts.map +0 -1
- package/dist/api/binance/BinanceSignTx.d.ts +0 -7
- package/dist/api/binance/BinanceSignTx.d.ts.map +0 -1
- package/dist/api/btc/BTCAuthorizeCoinJoin.d.ts +0 -7
- package/dist/api/btc/BTCAuthorizeCoinJoin.d.ts.map +0 -1
- package/dist/api/btc/BTCGetOwnershipId.d.ts +0 -7
- package/dist/api/btc/BTCGetOwnershipId.d.ts.map +0 -1
- package/dist/api/btc/BTCGetOwnershipProof.d.ts +0 -7
- package/dist/api/btc/BTCGetOwnershipProof.d.ts.map +0 -1
- package/dist/api/crypto/CryptoBatchGetPublickeys.d.ts +0 -8
- package/dist/api/crypto/CryptoBatchGetPublickeys.d.ts.map +0 -1
- package/dist/api/crypto/CryptoCipherKeyValue.d.ts +0 -8
- package/dist/api/crypto/CryptoCipherKeyValue.d.ts.map +0 -1
- package/dist/api/crypto/CryptoCosiCommit.d.ts +0 -8
- package/dist/api/crypto/CryptoCosiCommit.d.ts.map +0 -1
- package/dist/api/crypto/CryptoCosiSign.d.ts +0 -8
- package/dist/api/crypto/CryptoCosiSign.d.ts.map +0 -1
- package/dist/api/crypto/CryptoGetECDHSessionKey.d.ts +0 -8
- package/dist/api/crypto/CryptoGetECDHSessionKey.d.ts.map +0 -1
- package/dist/api/crypto/CryptoSignIdentity.d.ts +0 -8
- package/dist/api/crypto/CryptoSignIdentity.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkDecision.d.ts +0 -7
- package/dist/api/debug/DebugLinkDecision.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkEraseSdCard.d.ts +0 -7
- package/dist/api/debug/DebugLinkEraseSdCard.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkFlashErase.d.ts +0 -7
- package/dist/api/debug/DebugLinkFlashErase.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkGetState.d.ts +0 -7
- package/dist/api/debug/DebugLinkGetState.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkMemoryRead.d.ts +0 -7
- package/dist/api/debug/DebugLinkMemoryRead.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkMemoryWrite.d.ts +0 -7
- package/dist/api/debug/DebugLinkMemoryWrite.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkRecordScreen.d.ts +0 -7
- package/dist/api/debug/DebugLinkRecordScreen.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkReseedRandom.d.ts +0 -7
- package/dist/api/debug/DebugLinkReseedRandom.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkStop.d.ts +0 -7
- package/dist/api/debug/DebugLinkStop.d.ts.map +0 -1
- package/dist/api/debug/DebugLinkWatchLayout.d.ts +0 -7
- package/dist/api/debug/DebugLinkWatchLayout.d.ts.map +0 -1
- package/dist/api/emmc/EmmcDirList.d.ts +0 -7
- package/dist/api/emmc/EmmcDirList.d.ts.map +0 -1
- package/dist/api/emmc/EmmcDirMake.d.ts +0 -7
- package/dist/api/emmc/EmmcDirMake.d.ts.map +0 -1
- package/dist/api/emmc/EmmcDirRemove.d.ts +0 -7
- package/dist/api/emmc/EmmcDirRemove.d.ts.map +0 -1
- package/dist/api/emmc/EmmcFileDelete.d.ts +0 -7
- package/dist/api/emmc/EmmcFileDelete.d.ts.map +0 -1
- package/dist/api/emmc/EmmcFileRead.d.ts +0 -7
- package/dist/api/emmc/EmmcFileRead.d.ts.map +0 -1
- package/dist/api/emmc/EmmcFileWrite.d.ts +0 -7
- package/dist/api/emmc/EmmcFileWrite.d.ts.map +0 -1
- package/dist/api/emmc/EmmcFixPermission.d.ts +0 -7
- package/dist/api/emmc/EmmcFixPermission.d.ts.map +0 -1
- package/dist/api/emmc/EmmcPathInfo.d.ts +0 -7
- package/dist/api/emmc/EmmcPathInfo.d.ts.map +0 -1
- package/dist/api/eos/EosGetPublicKey.d.ts +0 -8
- package/dist/api/eos/EosGetPublicKey.d.ts.map +0 -1
- package/dist/api/eos/EosSignTx.d.ts +0 -12
- package/dist/api/eos/EosSignTx.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMGetAddress.d.ts +0 -10
- package/dist/api/evmTrezor/EVMGetAddress.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMGetPublicKey.d.ts +0 -16
- package/dist/api/evmTrezor/EVMGetPublicKey.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMSignMessage.d.ts +0 -7
- package/dist/api/evmTrezor/EVMSignMessage.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMSignTransaction.d.ts +0 -15
- package/dist/api/evmTrezor/EVMSignTransaction.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMSignTypedData.d.ts +0 -43
- package/dist/api/evmTrezor/EVMSignTypedData.d.ts.map +0 -1
- package/dist/api/evmTrezor/EVMVerifyMessage.d.ts +0 -7
- package/dist/api/evmTrezor/EVMVerifyMessage.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/getAddress.d.ts +0 -6
- package/dist/api/evmTrezor/legacyV1/getAddress.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/getPublicKey.d.ts +0 -6
- package/dist/api/evmTrezor/legacyV1/getPublicKey.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/signMessage.d.ts +0 -6
- package/dist/api/evmTrezor/legacyV1/signMessage.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/signTransaction.d.ts +0 -9
- package/dist/api/evmTrezor/legacyV1/signTransaction.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/signTypedData.d.ts +0 -10
- package/dist/api/evmTrezor/legacyV1/signTypedData.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/signTypedHash.d.ts +0 -11
- package/dist/api/evmTrezor/legacyV1/signTypedHash.d.ts.map +0 -1
- package/dist/api/evmTrezor/legacyV1/verifyMessage.d.ts +0 -6
- package/dist/api/evmTrezor/legacyV1/verifyMessage.d.ts.map +0 -1
- package/dist/api/extensionMethodNames.d.ts +0 -3
- package/dist/api/extensionMethodNames.d.ts.map +0 -1
- package/dist/api/factoryMethods.d.ts +0 -3
- package/dist/api/factoryMethods.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareErase.d.ts +0 -12
- package/dist/api/firmware/FirmwareErase.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareEraseEx.d.ts +0 -12
- package/dist/api/firmware/FirmwareEraseEx.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUpdateEmmcTest.d.ts +0 -7
- package/dist/api/firmware/FirmwareUpdateEmmcTest.d.ts.map +0 -1
- package/dist/api/firmware/FirmwareUploadTest.d.ts +0 -7
- package/dist/api/firmware/FirmwareUploadTest.d.ts.map +0 -1
- package/dist/api/firmware/Reboot.d.ts +0 -7
- package/dist/api/firmware/Reboot.d.ts.map +0 -1
- package/dist/api/firmware/SelfTest.d.ts +0 -7
- package/dist/api/firmware/SelfTest.d.ts.map +0 -1
- package/dist/api/manager/DeviceCancelAuthorization.d.ts +0 -7
- package/dist/api/manager/DeviceCancelAuthorization.d.ts.map +0 -1
- package/dist/api/manager/DeviceChangeWipeCode.d.ts +0 -7
- package/dist/api/manager/DeviceChangeWipeCode.d.ts.map +0 -1
- package/dist/api/manager/DeviceDoPreauthorized.d.ts +0 -7
- package/dist/api/manager/DeviceDoPreauthorized.d.ts.map +0 -1
- package/dist/api/manager/DeviceEndSession.d.ts +0 -7
- package/dist/api/manager/DeviceEndSession.d.ts.map +0 -1
- package/dist/api/manager/DeviceGetEntropy.d.ts +0 -7
- package/dist/api/manager/DeviceGetEntropy.d.ts.map +0 -1
- package/dist/api/manager/DeviceGetFirmwareHash.d.ts +0 -7
- package/dist/api/manager/DeviceGetFirmwareHash.d.ts.map +0 -1
- package/dist/api/manager/DeviceInfoSettings.d.ts +0 -7
- package/dist/api/manager/DeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/manager/DeviceLoad.d.ts +0 -7
- package/dist/api/manager/DeviceLoad.d.ts.map +0 -1
- package/dist/api/manager/DevicePing.d.ts +0 -7
- package/dist/api/manager/DevicePing.d.ts.map +0 -1
- package/dist/api/manager/DeviceReadSEPublicCert.d.ts +0 -7
- package/dist/api/manager/DeviceReadSEPublicCert.d.ts.map +0 -1
- package/dist/api/manager/DeviceSESignMessage.d.ts +0 -7
- package/dist/api/manager/DeviceSESignMessage.d.ts.map +0 -1
- package/dist/api/manager/DeviceSdProtect.d.ts +0 -7
- package/dist/api/manager/DeviceSdProtect.d.ts.map +0 -1
- package/dist/api/manager/DeviceSpiFlashRead.d.ts +0 -7
- package/dist/api/manager/DeviceSpiFlashRead.d.ts.map +0 -1
- package/dist/api/manager/DeviceSpiFlashWrite.d.ts +0 -7
- package/dist/api/manager/DeviceSpiFlashWrite.d.ts.map +0 -1
- package/dist/api/manager/DeviceUnlockPath.d.ts +0 -7
- package/dist/api/manager/DeviceUnlockPath.d.ts.map +0 -1
- package/dist/api/manager/DeviceWriteSEPrivateKey.d.ts +0 -7
- package/dist/api/manager/DeviceWriteSEPrivateKey.d.ts.map +0 -1
- package/dist/api/manager/DeviceWriteSEPublicCert.d.ts +0 -7
- package/dist/api/manager/DeviceWriteSEPublicCert.d.ts.map +0 -1
- package/dist/api/manager/GetDeviceInfoSettings.d.ts +0 -7
- package/dist/api/manager/GetDeviceInfoSettings.d.ts.map +0 -1
- package/dist/api/manager/GetPublicKeyMultiple.d.ts +0 -7
- package/dist/api/manager/GetPublicKeyMultiple.d.ts.map +0 -1
- package/dist/api/manager/ListResDir.d.ts +0 -7
- package/dist/api/manager/ListResDir.d.ts.map +0 -1
- package/dist/api/manager/NFTWriteData.d.ts +0 -7
- package/dist/api/manager/NFTWriteData.d.ts.map +0 -1
- package/dist/api/manager/NFTWriteInfo.d.ts +0 -7
- package/dist/api/manager/NFTWriteInfo.d.ts.map +0 -1
- package/dist/api/manager/ReadSEPublicKey.d.ts +0 -7
- package/dist/api/manager/ReadSEPublicKey.d.ts.map +0 -1
- package/dist/api/manager/ResourceUpdate.d.ts +0 -6
- package/dist/api/manager/ResourceUpdate.d.ts.map +0 -1
- package/dist/api/methodExtension.d.ts +0 -13
- package/dist/api/methodExtension.d.ts.map +0 -1
- package/dist/api/monero/MoneroGetAddress.d.ts +0 -9
- package/dist/api/monero/MoneroGetAddress.d.ts.map +0 -1
- package/dist/api/monero/MoneroGetWatchKey.d.ts +0 -8
- package/dist/api/monero/MoneroGetWatchKey.d.ts.map +0 -1
- package/dist/api/nem/NEMDecryptMessage.d.ts +0 -8
- package/dist/api/nem/NEMDecryptMessage.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFactoryCertificateRead.d.ts +0 -7
- package/dist/api/protocol-v2/DeviceFactoryCertificateRead.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFactoryCertificateWrite.d.ts +0 -8
- package/dist/api/protocol-v2/DeviceFactoryCertificateWrite.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceFactoryChallengeSign.d.ts +0 -8
- package/dist/api/protocol-v2/DeviceFactoryChallengeSign.d.ts.map +0 -1
- package/dist/api/testMethods.d.ts +0 -82
- package/dist/api/testMethods.d.ts.map +0 -1
- package/dist/api/tezos/TezosGetAddress.d.ts +0 -9
- package/dist/api/tezos/TezosGetAddress.d.ts.map +0 -1
- package/dist/api/tezos/TezosGetPublicKey.d.ts +0 -8
- package/dist/api/tezos/TezosGetPublicKey.d.ts.map +0 -1
- package/dist/api/tezos/TezosSignTx.d.ts +0 -12
- package/dist/api/tezos/TezosSignTx.d.ts.map +0 -1
- package/dist/types/api/binanceGetAddress.d.ts +0 -11
- package/dist/types/api/binanceGetAddress.d.ts.map +0 -1
- package/dist/types/api/binanceGetPublicKey.d.ts +0 -11
- package/dist/types/api/binanceGetPublicKey.d.ts.map +0 -1
- package/dist/types/api/binanceSignTx.d.ts +0 -7
- package/dist/types/api/binanceSignTx.d.ts.map +0 -1
- package/dist/types/api/bixinBackupDevice.d.ts +0 -4
- package/dist/types/api/bixinBackupDevice.d.ts.map +0 -1
- package/dist/types/api/bixinLoadDevice.d.ts +0 -4
- package/dist/types/api/bixinLoadDevice.d.ts.map +0 -1
- package/dist/types/api/bixinMessageSE.d.ts +0 -4
- package/dist/types/api/bixinMessageSE.d.ts.map +0 -1
- package/dist/types/api/bixinVerifyDeviceRequest.d.ts +0 -4
- package/dist/types/api/bixinVerifyDeviceRequest.d.ts.map +0 -1
- package/dist/types/api/btcAuthorizeCoinJoin.d.ts +0 -13
- package/dist/types/api/btcAuthorizeCoinJoin.d.ts.map +0 -1
- package/dist/types/api/btcGetOwnershipId.d.ts +0 -10
- package/dist/types/api/btcGetOwnershipId.d.ts.map +0 -1
- package/dist/types/api/btcGetOwnershipProof.d.ts +0 -13
- package/dist/types/api/btcGetOwnershipProof.d.ts.map +0 -1
- package/dist/types/api/cryptoBatchGetPublickeys.d.ts +0 -12
- package/dist/types/api/cryptoBatchGetPublickeys.d.ts.map +0 -1
- package/dist/types/api/cryptoCipherKeyValue.d.ts +0 -13
- package/dist/types/api/cryptoCipherKeyValue.d.ts.map +0 -1
- package/dist/types/api/cryptoCosiCommit.d.ts +0 -8
- package/dist/types/api/cryptoCosiCommit.d.ts.map +0 -1
- package/dist/types/api/cryptoCosiSign.d.ts +0 -10
- package/dist/types/api/cryptoCosiSign.d.ts.map +0 -1
- package/dist/types/api/cryptoGetECDHSessionKey.d.ts +0 -4
- package/dist/types/api/cryptoGetECDHSessionKey.d.ts.map +0 -1
- package/dist/types/api/cryptoSignIdentity.d.ts +0 -4
- package/dist/types/api/cryptoSignIdentity.d.ts.map +0 -1
- package/dist/types/api/debugLinkDecision.d.ts +0 -4
- package/dist/types/api/debugLinkDecision.d.ts.map +0 -1
- package/dist/types/api/debugLinkEraseSdCard.d.ts +0 -4
- package/dist/types/api/debugLinkEraseSdCard.d.ts.map +0 -1
- package/dist/types/api/debugLinkFlashErase.d.ts +0 -4
- package/dist/types/api/debugLinkFlashErase.d.ts.map +0 -1
- package/dist/types/api/debugLinkGetState.d.ts +0 -4
- package/dist/types/api/debugLinkGetState.d.ts.map +0 -1
- package/dist/types/api/debugLinkMemoryRead.d.ts +0 -4
- package/dist/types/api/debugLinkMemoryRead.d.ts.map +0 -1
- package/dist/types/api/debugLinkMemoryWrite.d.ts +0 -4
- package/dist/types/api/debugLinkMemoryWrite.d.ts.map +0 -1
- package/dist/types/api/debugLinkRecordScreen.d.ts +0 -4
- package/dist/types/api/debugLinkRecordScreen.d.ts.map +0 -1
- package/dist/types/api/debugLinkReseedRandom.d.ts +0 -4
- package/dist/types/api/debugLinkReseedRandom.d.ts.map +0 -1
- package/dist/types/api/debugLinkStop.d.ts +0 -4
- package/dist/types/api/debugLinkStop.d.ts.map +0 -1
- package/dist/types/api/debugLinkWatchLayout.d.ts +0 -4
- package/dist/types/api/debugLinkWatchLayout.d.ts.map +0 -1
- package/dist/types/api/deviceCancelAuthorization.d.ts +0 -4
- package/dist/types/api/deviceCancelAuthorization.d.ts.map +0 -1
- package/dist/types/api/deviceChangeWipeCode.d.ts +0 -4
- package/dist/types/api/deviceChangeWipeCode.d.ts.map +0 -1
- package/dist/types/api/deviceDoPreauthorized.d.ts +0 -4
- package/dist/types/api/deviceDoPreauthorized.d.ts.map +0 -1
- package/dist/types/api/deviceEndSession.d.ts +0 -4
- package/dist/types/api/deviceEndSession.d.ts.map +0 -1
- package/dist/types/api/deviceGetEntropy.d.ts +0 -4
- package/dist/types/api/deviceGetEntropy.d.ts.map +0 -1
- package/dist/types/api/deviceGetFirmwareHash.d.ts +0 -4
- package/dist/types/api/deviceGetFirmwareHash.d.ts.map +0 -1
- package/dist/types/api/deviceGetInfo.d.ts +0 -4
- package/dist/types/api/deviceGetInfo.d.ts.map +0 -1
- package/dist/types/api/deviceInfoSettings.d.ts +0 -4
- package/dist/types/api/deviceInfoSettings.d.ts.map +0 -1
- package/dist/types/api/deviceLoad.d.ts +0 -16
- package/dist/types/api/deviceLoad.d.ts.map +0 -1
- package/dist/types/api/devicePing.d.ts +0 -4
- package/dist/types/api/devicePing.d.ts.map +0 -1
- package/dist/types/api/deviceReadSEPublicCert.d.ts +0 -4
- package/dist/types/api/deviceReadSEPublicCert.d.ts.map +0 -1
- package/dist/types/api/deviceSESignMessage.d.ts +0 -4
- package/dist/types/api/deviceSESignMessage.d.ts.map +0 -1
- package/dist/types/api/deviceSdProtect.d.ts +0 -4
- package/dist/types/api/deviceSdProtect.d.ts.map +0 -1
- package/dist/types/api/deviceSpiFlashRead.d.ts +0 -4
- package/dist/types/api/deviceSpiFlashRead.d.ts.map +0 -1
- package/dist/types/api/deviceSpiFlashWrite.d.ts +0 -4
- package/dist/types/api/deviceSpiFlashWrite.d.ts.map +0 -1
- package/dist/types/api/deviceUnlockPath.d.ts +0 -11
- package/dist/types/api/deviceUnlockPath.d.ts.map +0 -1
- package/dist/types/api/deviceWriteSEPrivateKey.d.ts +0 -4
- package/dist/types/api/deviceWriteSEPrivateKey.d.ts.map +0 -1
- package/dist/types/api/deviceWriteSEPublicCert.d.ts +0 -4
- package/dist/types/api/deviceWriteSEPublicCert.d.ts.map +0 -1
- package/dist/types/api/emmcDirList.d.ts +0 -4
- package/dist/types/api/emmcDirList.d.ts.map +0 -1
- package/dist/types/api/emmcDirMake.d.ts +0 -4
- package/dist/types/api/emmcDirMake.d.ts.map +0 -1
- package/dist/types/api/emmcDirRemove.d.ts +0 -4
- package/dist/types/api/emmcDirRemove.d.ts.map +0 -1
- package/dist/types/api/emmcFileDelete.d.ts +0 -4
- package/dist/types/api/emmcFileDelete.d.ts.map +0 -1
- package/dist/types/api/emmcFileRead.d.ts +0 -4
- package/dist/types/api/emmcFileRead.d.ts.map +0 -1
- package/dist/types/api/emmcFileWrite.d.ts +0 -4
- package/dist/types/api/emmcFileWrite.d.ts.map +0 -1
- package/dist/types/api/emmcFixPermission.d.ts +0 -4
- package/dist/types/api/emmcFixPermission.d.ts.map +0 -1
- package/dist/types/api/emmcPathInfo.d.ts +0 -4
- package/dist/types/api/emmcPathInfo.d.ts.map +0 -1
- package/dist/types/api/eosGetPublicKey.d.ts +0 -8
- package/dist/types/api/eosGetPublicKey.d.ts.map +0 -1
- package/dist/types/api/eosSignTx.d.ts +0 -7
- package/dist/types/api/eosSignTx.d.ts.map +0 -1
- package/dist/types/api/evmGetAddressTrezor.d.ts +0 -15
- package/dist/types/api/evmGetAddressTrezor.d.ts.map +0 -1
- package/dist/types/api/evmGetPublicKeyTrezor.d.ts +0 -20
- package/dist/types/api/evmGetPublicKeyTrezor.d.ts.map +0 -1
- package/dist/types/api/evmSignMessageTrezor.d.ts +0 -9
- package/dist/types/api/evmSignMessageTrezor.d.ts.map +0 -1
- package/dist/types/api/evmSignTransactionTrezor.d.ts +0 -40
- package/dist/types/api/evmSignTransactionTrezor.d.ts.map +0 -1
- package/dist/types/api/evmSignTypedDataTrezor.d.ts +0 -34
- package/dist/types/api/evmSignTypedDataTrezor.d.ts.map +0 -1
- package/dist/types/api/evmVerifyMessageTrezor.d.ts +0 -10
- package/dist/types/api/evmVerifyMessageTrezor.d.ts.map +0 -1
- package/dist/types/api/firmwareErase.d.ts +0 -4
- package/dist/types/api/firmwareErase.d.ts.map +0 -1
- package/dist/types/api/firmwareEraseEx.d.ts +0 -4
- package/dist/types/api/firmwareEraseEx.d.ts.map +0 -1
- package/dist/types/api/firmwareUpdateEmmcTest.d.ts +0 -4
- package/dist/types/api/firmwareUpdateEmmcTest.d.ts.map +0 -1
- package/dist/types/api/firmwareUploadTest.d.ts +0 -4
- package/dist/types/api/firmwareUploadTest.d.ts.map +0 -1
- package/dist/types/api/getPublicKeyMultiple.d.ts +0 -4
- package/dist/types/api/getPublicKeyMultiple.d.ts.map +0 -1
- package/dist/types/api/listResDir.d.ts +0 -4
- package/dist/types/api/listResDir.d.ts.map +0 -1
- package/dist/types/api/moneroGetAddress.d.ts +0 -14
- package/dist/types/api/moneroGetAddress.d.ts.map +0 -1
- package/dist/types/api/moneroGetWatchKey.d.ts +0 -14
- package/dist/types/api/moneroGetWatchKey.d.ts.map +0 -1
- package/dist/types/api/nemDecryptMessage.d.ts +0 -10
- package/dist/types/api/nemDecryptMessage.d.ts.map +0 -1
- package/dist/types/api/nftWriteData.d.ts +0 -4
- package/dist/types/api/nftWriteData.d.ts.map +0 -1
- package/dist/types/api/nftWriteInfo.d.ts +0 -4
- package/dist/types/api/nftWriteInfo.d.ts.map +0 -1
- package/dist/types/api/readSEPublicKey.d.ts +0 -4
- package/dist/types/api/readSEPublicKey.d.ts.map +0 -1
- package/dist/types/api/reboot.d.ts +0 -4
- package/dist/types/api/reboot.d.ts.map +0 -1
- package/dist/types/api/resourceUpdate.d.ts +0 -7
- package/dist/types/api/resourceUpdate.d.ts.map +0 -1
- package/dist/types/api/selfTest.d.ts +0 -4
- package/dist/types/api/selfTest.d.ts.map +0 -1
- package/dist/types/api/tezosGetAddress.d.ts +0 -14
- package/dist/types/api/tezosGetAddress.d.ts.map +0 -1
- package/dist/types/api/tezosGetPublicKey.d.ts +0 -14
- package/dist/types/api/tezosGetPublicKey.d.ts.map +0 -1
- package/dist/types/api/tezosSignTx.d.ts +0 -7
- package/dist/types/api/tezosSignTx.d.ts.map +0 -1
- package/dist/types/api/webAuthnAddResidentCredential.d.ts +0 -4
- package/dist/types/api/webAuthnAddResidentCredential.d.ts.map +0 -1
- package/dist/types/api/webAuthnListResidentCredentials.d.ts +0 -4
- package/dist/types/api/webAuthnListResidentCredentials.d.ts.map +0 -1
- package/dist/types/api/webAuthnRemoveResidentCredential.d.ts +0 -4
- package/dist/types/api/webAuthnRemoveResidentCredential.d.ts.map +0 -1
- package/src/api/BixinBackupDevice.ts +0 -15
- package/src/api/BixinLoadDevice.ts +0 -22
- package/src/api/BixinMessageSE.ts +0 -22
- package/src/api/BixinVerifyDeviceRequest.ts +0 -22
- package/src/api/WebAuthnAddResidentCredential.ts +0 -22
- package/src/api/WebAuthnListResidentCredentials.ts +0 -24
- package/src/api/WebAuthnRemoveResidentCredential.ts +0 -22
- package/src/api/binance/BinanceGetAddress.ts +0 -26
- package/src/api/binance/BinanceGetPublicKey.ts +0 -26
- package/src/api/binance/BinanceSignTx.ts +0 -35
- package/src/api/btc/BTCAuthorizeCoinJoin.ts +0 -37
- package/src/api/btc/BTCGetOwnershipId.ts +0 -34
- package/src/api/btc/BTCGetOwnershipProof.ts +0 -37
- package/src/api/crypto/CryptoBatchGetPublickeys.ts +0 -30
- package/src/api/crypto/CryptoCipherKeyValue.ts +0 -29
- package/src/api/crypto/CryptoCosiCommit.ts +0 -24
- package/src/api/crypto/CryptoCosiSign.ts +0 -26
- package/src/api/crypto/CryptoGetECDHSessionKey.ts +0 -24
- package/src/api/crypto/CryptoSignIdentity.ts +0 -25
- package/src/api/debug/DebugLinkDecision.ts +0 -25
- package/src/api/debug/DebugLinkEraseSdCard.ts +0 -23
- package/src/api/debug/DebugLinkFlashErase.ts +0 -23
- package/src/api/debug/DebugLinkGetState.ts +0 -21
- package/src/api/debug/DebugLinkMemoryRead.ts +0 -24
- package/src/api/debug/DebugLinkMemoryWrite.ts +0 -25
- package/src/api/debug/DebugLinkRecordScreen.ts +0 -23
- package/src/api/debug/DebugLinkReseedRandom.ts +0 -23
- package/src/api/debug/DebugLinkStop.ts +0 -25
- package/src/api/debug/DebugLinkWatchLayout.ts +0 -23
- package/src/api/emmc/EmmcDirList.ts +0 -20
- package/src/api/emmc/EmmcDirMake.ts +0 -20
- package/src/api/emmc/EmmcDirRemove.ts +0 -20
- package/src/api/emmc/EmmcFileDelete.ts +0 -20
- package/src/api/emmc/EmmcFileRead.ts +0 -21
- package/src/api/emmc/EmmcFileWrite.ts +0 -23
- package/src/api/emmc/EmmcFixPermission.ts +0 -17
- package/src/api/emmc/EmmcPathInfo.ts +0 -20
- package/src/api/eos/EosGetPublicKey.ts +0 -26
- package/src/api/eos/EosSignTx.ts +0 -40
- package/src/api/evmTrezor/EVMGetAddress.ts +0 -75
- package/src/api/evmTrezor/EVMGetPublicKey.ts +0 -106
- package/src/api/evmTrezor/EVMSignMessage.ts +0 -40
- package/src/api/evmTrezor/EVMSignTransaction.ts +0 -83
- package/src/api/evmTrezor/EVMSignTypedData.ts +0 -366
- package/src/api/evmTrezor/EVMVerifyMessage.ts +0 -37
- package/src/api/evmTrezor/legacyV1/getAddress.ts +0 -16
- package/src/api/evmTrezor/legacyV1/getPublicKey.ts +0 -20
- package/src/api/evmTrezor/legacyV1/signMessage.ts +0 -22
- package/src/api/evmTrezor/legacyV1/signTransaction.ts +0 -24
- package/src/api/evmTrezor/legacyV1/signTypedData.ts +0 -36
- package/src/api/evmTrezor/legacyV1/signTypedHash.ts +0 -48
- package/src/api/evmTrezor/legacyV1/verifyMessage.ts +0 -19
- package/src/api/extensionMethodNames.ts +0 -88
- package/src/api/factoryMethods.ts +0 -2
- package/src/api/firmware/FirmwareErase.ts +0 -18
- package/src/api/firmware/FirmwareEraseEx.ts +0 -18
- package/src/api/firmware/FirmwareUpdateEmmcTest.ts +0 -18
- package/src/api/firmware/FirmwareUploadTest.ts +0 -17
- package/src/api/firmware/Reboot.ts +0 -17
- package/src/api/firmware/SelfTest.ts +0 -17
- package/src/api/manager/DeviceCancelAuthorization.ts +0 -15
- package/src/api/manager/DeviceChangeWipeCode.ts +0 -19
- package/src/api/manager/DeviceDoPreauthorized.ts +0 -15
- package/src/api/manager/DeviceEndSession.ts +0 -19
- package/src/api/manager/DeviceGetEntropy.ts +0 -19
- package/src/api/manager/DeviceGetFirmwareHash.ts +0 -23
- package/src/api/manager/DeviceInfoSettings.ts +0 -23
- package/src/api/manager/DeviceLoad.ts +0 -27
- package/src/api/manager/DevicePing.ts +0 -19
- package/src/api/manager/DeviceReadSEPublicCert.ts +0 -18
- package/src/api/manager/DeviceSESignMessage.ts +0 -23
- package/src/api/manager/DeviceSdProtect.ts +0 -18
- package/src/api/manager/DeviceSpiFlashRead.ts +0 -22
- package/src/api/manager/DeviceSpiFlashWrite.ts +0 -22
- package/src/api/manager/DeviceUnlockPath.ts +0 -26
- package/src/api/manager/DeviceWriteSEPrivateKey.ts +0 -23
- package/src/api/manager/DeviceWriteSEPublicCert.ts +0 -23
- package/src/api/manager/GetDeviceInfoSettings.ts +0 -20
- package/src/api/manager/GetPublicKeyMultiple.ts +0 -24
- package/src/api/manager/ListResDir.ts +0 -19
- package/src/api/manager/NFTWriteData.ts +0 -21
- package/src/api/manager/NFTWriteInfo.ts +0 -23
- package/src/api/manager/ReadSEPublicKey.ts +0 -20
- package/src/api/manager/ResourceUpdate.ts +0 -22
- package/src/api/methodExtension.ts +0 -27
- package/src/api/monero/MoneroGetAddress.ts +0 -64
- package/src/api/monero/MoneroGetWatchKey.ts +0 -59
- package/src/api/nem/NEMDecryptMessage.ts +0 -29
- package/src/api/protocol-v2/DeviceFactoryCertificateRead.ts +0 -25
- package/src/api/protocol-v2/DeviceFactoryCertificateWrite.ts +0 -30
- package/src/api/protocol-v2/DeviceFactoryChallengeSign.ts +0 -28
- package/src/api/testMethods.ts +0 -95
- package/src/api/tezos/TezosGetAddress.ts +0 -64
- package/src/api/tezos/TezosGetPublicKey.ts +0 -63
- package/src/api/tezos/TezosSignTx.ts +0 -44
- package/src/types/api/binanceGetAddress.ts +0 -17
- package/src/types/api/binanceGetPublicKey.ts +0 -17
- package/src/types/api/binanceSignTx.ts +0 -15
- package/src/types/api/bixinBackupDevice.ts +0 -8
- package/src/types/api/bixinLoadDevice.ts +0 -8
- package/src/types/api/bixinMessageSE.ts +0 -8
- package/src/types/api/bixinVerifyDeviceRequest.ts +0 -8
- package/src/types/api/btcAuthorizeCoinJoin.ts +0 -18
- package/src/types/api/btcGetOwnershipId.ts +0 -19
- package/src/types/api/btcGetOwnershipProof.ts +0 -22
- package/src/types/api/cryptoBatchGetPublickeys.ts +0 -18
- package/src/types/api/cryptoCipherKeyValue.ts +0 -18
- package/src/types/api/cryptoCosiCommit.ts +0 -13
- package/src/types/api/cryptoCosiSign.ts +0 -15
- package/src/types/api/cryptoGetECDHSessionKey.ts +0 -8
- package/src/types/api/cryptoSignIdentity.ts +0 -8
- package/src/types/api/debugLinkDecision.ts +0 -7
- package/src/types/api/debugLinkEraseSdCard.ts +0 -7
- package/src/types/api/debugLinkFlashErase.ts +0 -7
- package/src/types/api/debugLinkGetState.ts +0 -7
- package/src/types/api/debugLinkMemoryRead.ts +0 -7
- package/src/types/api/debugLinkMemoryWrite.ts +0 -7
- package/src/types/api/debugLinkRecordScreen.ts +0 -7
- package/src/types/api/debugLinkReseedRandom.ts +0 -7
- package/src/types/api/debugLinkStop.ts +0 -7
- package/src/types/api/debugLinkWatchLayout.ts +0 -7
- package/src/types/api/deviceCancelAuthorization.ts +0 -7
- package/src/types/api/deviceChangeWipeCode.ts +0 -7
- package/src/types/api/deviceDoPreauthorized.ts +0 -7
- package/src/types/api/deviceEndSession.ts +0 -7
- package/src/types/api/deviceGetEntropy.ts +0 -7
- package/src/types/api/deviceGetFirmwareHash.ts +0 -7
- package/src/types/api/deviceGetInfo.ts +0 -7
- package/src/types/api/deviceInfoSettings.ts +0 -7
- package/src/types/api/deviceLoad.ts +0 -19
- package/src/types/api/devicePing.ts +0 -7
- package/src/types/api/deviceReadSEPublicCert.ts +0 -7
- package/src/types/api/deviceSESignMessage.ts +0 -7
- package/src/types/api/deviceSdProtect.ts +0 -7
- package/src/types/api/deviceSpiFlashRead.ts +0 -7
- package/src/types/api/deviceSpiFlashWrite.ts +0 -7
- package/src/types/api/deviceUnlockPath.ts +0 -16
- package/src/types/api/deviceWriteSEPrivateKey.ts +0 -7
- package/src/types/api/deviceWriteSEPublicCert.ts +0 -7
- package/src/types/api/emmcDirList.ts +0 -7
- package/src/types/api/emmcDirMake.ts +0 -7
- package/src/types/api/emmcDirRemove.ts +0 -7
- package/src/types/api/emmcFileDelete.ts +0 -7
- package/src/types/api/emmcFileRead.ts +0 -7
- package/src/types/api/emmcFileWrite.ts +0 -7
- package/src/types/api/emmcFixPermission.ts +0 -7
- package/src/types/api/emmcPathInfo.ts +0 -7
- package/src/types/api/eosGetPublicKey.ts +0 -13
- package/src/types/api/eosSignTx.ts +0 -12
- package/src/types/api/evmGetAddressTrezor.ts +0 -24
- package/src/types/api/evmGetPublicKeyTrezor.ts +0 -31
- package/src/types/api/evmSignMessageTrezor.ts +0 -14
- package/src/types/api/evmSignTransactionTrezor.ts +0 -49
- package/src/types/api/evmSignTypedDataTrezor.ts +0 -42
- package/src/types/api/evmVerifyMessageTrezor.ts +0 -15
- package/src/types/api/firmwareErase.ts +0 -4
- package/src/types/api/firmwareEraseEx.ts +0 -7
- package/src/types/api/firmwareUpdateEmmcTest.ts +0 -7
- package/src/types/api/firmwareUploadTest.ts +0 -7
- package/src/types/api/getPublicKeyMultiple.ts +0 -11
- package/src/types/api/listResDir.ts +0 -8
- package/src/types/api/moneroGetAddress.ts +0 -23
- package/src/types/api/moneroGetWatchKey.ts +0 -26
- package/src/types/api/nemDecryptMessage.ts +0 -15
- package/src/types/api/nftWriteData.ts +0 -8
- package/src/types/api/nftWriteInfo.ts +0 -8
- package/src/types/api/readSEPublicKey.ts +0 -8
- package/src/types/api/reboot.ts +0 -4
- package/src/types/api/resourceUpdate.ts +0 -11
- package/src/types/api/selfTest.ts +0 -7
- package/src/types/api/tezosGetAddress.ts +0 -23
- package/src/types/api/tezosGetPublicKey.ts +0 -23
- package/src/types/api/tezosSignTx.ts +0 -12
- package/src/types/api/webAuthnAddResidentCredential.ts +0 -8
- package/src/types/api/webAuthnListResidentCredentials.ts +0 -8
- package/src/types/api/webAuthnRemoveResidentCredential.ts +0 -8
|
@@ -15,6 +15,7 @@ import { BaseMethod } from '../BaseMethod';
|
|
|
15
15
|
import { DEVICE } from '../../events';
|
|
16
16
|
|
|
17
17
|
import type {
|
|
18
|
+
FirmwareProgress,
|
|
18
19
|
IFirmwareUpdateProgressType,
|
|
19
20
|
IFirmwareUpdateTipMessage,
|
|
20
21
|
} from '../../events/ui-request';
|
|
@@ -28,6 +29,11 @@ const Log = getLogger(LoggerNames.Method);
|
|
|
28
29
|
const SESSION_ERROR = 'session not found';
|
|
29
30
|
const FIRMWARE_UPDATE_CONFIRM = 'Firmware install confirmed';
|
|
30
31
|
|
|
32
|
+
type FirmwareTransferMetrics = Pick<
|
|
33
|
+
FirmwareProgress['payload'],
|
|
34
|
+
'transferredBytes' | 'totalBytes' | 'rateBytesPerSecond' | 'elapsedMs'
|
|
35
|
+
>;
|
|
36
|
+
|
|
31
37
|
const isDeviceDisconnectedError = (error: unknown) => {
|
|
32
38
|
const message = error instanceof Error ? error.message : String(error ?? '');
|
|
33
39
|
return (
|
|
@@ -82,12 +88,17 @@ export class FirmwareUpdateBaseMethod<Params> extends BaseMethod<Params> {
|
|
|
82
88
|
* @description Post the progress message
|
|
83
89
|
* @param progress Post the percentage of the progress
|
|
84
90
|
*/
|
|
85
|
-
postProgressMessage = (
|
|
91
|
+
postProgressMessage = (
|
|
92
|
+
progress: number,
|
|
93
|
+
progressType: IFirmwareUpdateProgressType,
|
|
94
|
+
metrics?: FirmwareTransferMetrics
|
|
95
|
+
) => {
|
|
86
96
|
this.postMessage(
|
|
87
97
|
createUiMessage(UI_REQUEST.FIRMWARE_PROGRESS, {
|
|
88
98
|
device: this.device.toMessageObject() as KnownDevice,
|
|
89
99
|
progress,
|
|
90
100
|
progressType,
|
|
101
|
+
...metrics,
|
|
91
102
|
})
|
|
92
103
|
);
|
|
93
104
|
};
|
|
@@ -5,9 +5,12 @@ import {
|
|
|
5
5
|
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
6
6
|
|
|
7
7
|
import { DataManager } from '../../data-manager';
|
|
8
|
+
import { LoggerNames, getLogger } from '../../utils/logger';
|
|
8
9
|
|
|
9
10
|
import type { DeviceCommands } from '../../device/DeviceCommands';
|
|
10
11
|
|
|
12
|
+
const Log = getLogger(LoggerNames.Method);
|
|
13
|
+
|
|
11
14
|
export type ProtocolV2FileWriteData = ArrayBuffer | Uint8Array | Blob | string;
|
|
12
15
|
|
|
13
16
|
export type ProtocolV2FileWriteProgress = {
|
|
@@ -18,6 +21,12 @@ export type ProtocolV2FileWriteProgress = {
|
|
|
18
21
|
elapsedMs: number;
|
|
19
22
|
};
|
|
20
23
|
|
|
24
|
+
export type ProtocolV2FileWriteChunkContext = {
|
|
25
|
+
offset: number;
|
|
26
|
+
chunkLength: number;
|
|
27
|
+
totalSize: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
21
30
|
export type ProtocolV2FileWriteOptions = {
|
|
22
31
|
commands: Pick<DeviceCommands, 'typedCall'>;
|
|
23
32
|
path: string;
|
|
@@ -30,14 +39,54 @@ export type ProtocolV2FileWriteOptions = {
|
|
|
30
39
|
append?: boolean;
|
|
31
40
|
uiPercentage?: number;
|
|
32
41
|
timeoutMs?: number;
|
|
42
|
+
writeWithResponse?: boolean;
|
|
33
43
|
maxChunkRetries?: number;
|
|
34
44
|
paceMs?: number;
|
|
35
45
|
throwIfAborted?: () => void;
|
|
46
|
+
getUiPercentage?: (context: ProtocolV2FileWriteChunkContext) => number | undefined;
|
|
36
47
|
onProgress?: (progress: ProtocolV2FileWriteProgress) => void;
|
|
37
48
|
};
|
|
38
49
|
|
|
39
50
|
const MIN_FILE_CHUNK_SIZE = 64;
|
|
40
51
|
const FILE_TRANSFER_RATE_WINDOW_MS = 1000;
|
|
52
|
+
const FILE_TRANSFER_LOG_INTERVAL_MS = 10_000;
|
|
53
|
+
const SESSION_ERROR = 'session not found';
|
|
54
|
+
|
|
55
|
+
function formatFileTransferRate(bytesPerSecond: number) {
|
|
56
|
+
return (Math.max(bytesPerSecond, 0) / 1024).toFixed(2);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getAverageFileTransferRate(transferredBytes: number, elapsedMs: number) {
|
|
60
|
+
if (elapsedMs <= 0) return 0;
|
|
61
|
+
return Math.round((Math.max(transferredBytes, 0) / elapsedMs) * 1000);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getFileTransferTransport() {
|
|
65
|
+
const env = DataManager.getSettings('env');
|
|
66
|
+
return env && DataManager.isBleConnect(env) ? 'BLE' : String(env ?? 'unknown');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function logFileTransferMetrics({
|
|
70
|
+
transport,
|
|
71
|
+
status,
|
|
72
|
+
transferredBytes,
|
|
73
|
+
totalBytes,
|
|
74
|
+
elapsedMs,
|
|
75
|
+
rateBytesPerSecond,
|
|
76
|
+
}: {
|
|
77
|
+
transport: string;
|
|
78
|
+
status: 'progress' | 'completed' | 'failed';
|
|
79
|
+
transferredBytes: number;
|
|
80
|
+
totalBytes: number;
|
|
81
|
+
elapsedMs: number;
|
|
82
|
+
rateBytesPerSecond: number;
|
|
83
|
+
}) {
|
|
84
|
+
Log.log(
|
|
85
|
+
`[FileWrite] metrics transport=${transport} status=${status} bytes=${transferredBytes}/${totalBytes} elapsed=${(
|
|
86
|
+
elapsedMs / 1000
|
|
87
|
+
).toFixed(2)}s speed=${formatFileTransferRate(rateBytesPerSecond)} KiB/s`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
41
90
|
|
|
42
91
|
export function isProtocolV2ResponseTimeout(error: unknown) {
|
|
43
92
|
if (!error || typeof error !== 'object') return false;
|
|
@@ -125,89 +174,159 @@ export async function writeProtocolV2File(options: ProtocolV2FileWriteOptions) {
|
|
|
125
174
|
let rateWindowStartedAt = startTime;
|
|
126
175
|
let rateWindowStartedBytes = 0;
|
|
127
176
|
let rateBytesPerSecond: number | undefined;
|
|
177
|
+
let lastConfirmedAt = startTime;
|
|
178
|
+
let logWindowStartedAt = startTime;
|
|
179
|
+
let logWindowStartedBytes = 0;
|
|
180
|
+
const transport = getFileTransferTransport();
|
|
128
181
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
182
|
+
try {
|
|
183
|
+
while (written < dataLength) {
|
|
184
|
+
options.throwIfAborted?.();
|
|
185
|
+
const chunk = data.slice(written, Math.min(written + chunkSize, dataLength));
|
|
186
|
+
const offset = startOffset + written;
|
|
187
|
+
const progress =
|
|
188
|
+
options.uiPercentage ??
|
|
189
|
+
options.getUiPercentage?.({
|
|
190
|
+
offset,
|
|
191
|
+
chunkLength: chunk.byteLength,
|
|
192
|
+
totalSize,
|
|
193
|
+
}) ??
|
|
194
|
+
getDeviceTransferProgress(offset, offset + chunk.byteLength, totalSize);
|
|
195
|
+
const request = {
|
|
196
|
+
file: { path: options.path, offset, total_size: totalSize, data: chunk },
|
|
197
|
+
overwrite: chunks === 0 ? options.overwrite ?? false : false,
|
|
198
|
+
append: options.append ?? false,
|
|
199
|
+
ui_percentage: progress,
|
|
200
|
+
};
|
|
201
|
+
const maxChunkRetries = Math.max(Math.floor(options.maxChunkRetries ?? 0), 0);
|
|
202
|
+
let retryCount = 0;
|
|
203
|
+
let response;
|
|
204
|
+
let isWritePending = true;
|
|
205
|
+
while (isWritePending) {
|
|
206
|
+
try {
|
|
207
|
+
const callOptions =
|
|
208
|
+
options.writeWithResponse === undefined
|
|
209
|
+
? { timeoutMs: options.timeoutMs }
|
|
210
|
+
: {
|
|
211
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
212
|
+
writeWithResponse: options.writeWithResponse,
|
|
213
|
+
};
|
|
214
|
+
response = await options.commands.typedCall(
|
|
215
|
+
'FilesystemFileWrite',
|
|
216
|
+
'FilesystemFile',
|
|
217
|
+
request,
|
|
218
|
+
callOptions
|
|
219
|
+
);
|
|
220
|
+
isWritePending = false;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (retryCount >= maxChunkRetries || !isProtocolV2ResponseTimeout(error)) throw error;
|
|
223
|
+
retryCount += 1;
|
|
224
|
+
options.throwIfAborted?.();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!response) {
|
|
228
|
+
throw ERRORS.TypedError(
|
|
229
|
+
HardwareErrorCode.RuntimeError,
|
|
230
|
+
'FilesystemFileWrite completed without a response'
|
|
153
231
|
);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
232
|
+
}
|
|
233
|
+
const responseType = (response as { type?: string }).type;
|
|
234
|
+
if (responseType && responseType !== 'FilesystemFile') {
|
|
235
|
+
const responseError = (response as { message?: { error?: unknown } }).message?.error;
|
|
236
|
+
if (typeof responseError === 'string' && responseError.includes(SESSION_ERROR)) {
|
|
237
|
+
throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, SESSION_ERROR);
|
|
238
|
+
}
|
|
239
|
+
throw ERRORS.TypedError(
|
|
240
|
+
HardwareErrorCode.RuntimeError,
|
|
241
|
+
`FilesystemFileWrite received unexpected response ${responseType}`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
options.throwIfAborted?.();
|
|
245
|
+
lastMessage = response.message;
|
|
246
|
+
const rawProcessedByte = response.message?.processed_byte;
|
|
247
|
+
const processedByte = Number(rawProcessedByte);
|
|
248
|
+
if (
|
|
249
|
+
rawProcessedByte !== undefined &&
|
|
250
|
+
(!Number.isFinite(processedByte) ||
|
|
251
|
+
processedByte <= offset ||
|
|
252
|
+
processedByte > offset + chunk.byteLength)
|
|
253
|
+
) {
|
|
254
|
+
throw ERRORS.TypedError(
|
|
255
|
+
HardwareErrorCode.RuntimeError,
|
|
256
|
+
`FilesystemFileWrite invalid processed_byte ${processedByte}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
written =
|
|
260
|
+
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
261
|
+
chunks += 1;
|
|
262
|
+
const now = Date.now();
|
|
263
|
+
lastConfirmedAt = now;
|
|
264
|
+
const elapsedMs = now - startTime;
|
|
265
|
+
const transferredBytes = Math.min(written, dataLength);
|
|
266
|
+
const rateWindowElapsedMs = now - rateWindowStartedAt;
|
|
267
|
+
if (rateWindowElapsedMs >= FILE_TRANSFER_RATE_WINDOW_MS) {
|
|
268
|
+
const rateWindowBytes = Math.max(transferredBytes - rateWindowStartedBytes, 0);
|
|
269
|
+
rateBytesPerSecond = Math.round((rateWindowBytes / rateWindowElapsedMs) * 1000);
|
|
270
|
+
rateWindowStartedAt = now;
|
|
271
|
+
rateWindowStartedBytes = transferredBytes;
|
|
272
|
+
} else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
273
|
+
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
274
|
+
}
|
|
275
|
+
options.onProgress?.({
|
|
276
|
+
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
277
|
+
transferredBytes,
|
|
278
|
+
totalBytes: dataLength,
|
|
279
|
+
rateBytesPerSecond,
|
|
280
|
+
elapsedMs,
|
|
281
|
+
});
|
|
282
|
+
const logWindowElapsedMs = now - logWindowStartedAt;
|
|
283
|
+
if (logWindowElapsedMs >= FILE_TRANSFER_LOG_INTERVAL_MS && transferredBytes < dataLength) {
|
|
284
|
+
const logWindowBytes = Math.max(transferredBytes - logWindowStartedBytes, 0);
|
|
285
|
+
logFileTransferMetrics({
|
|
286
|
+
transport,
|
|
287
|
+
status: 'progress',
|
|
288
|
+
transferredBytes,
|
|
289
|
+
totalBytes: dataLength,
|
|
290
|
+
elapsedMs,
|
|
291
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
292
|
+
});
|
|
293
|
+
logWindowStartedAt = now;
|
|
294
|
+
logWindowStartedBytes = transferredBytes;
|
|
295
|
+
}
|
|
296
|
+
if (options.paceMs && options.paceMs > 0) {
|
|
297
|
+
await new Promise(resolve => {
|
|
298
|
+
setTimeout(resolve, options.paceMs);
|
|
299
|
+
});
|
|
159
300
|
}
|
|
160
301
|
}
|
|
161
|
-
|
|
162
|
-
throw ERRORS.TypedError(
|
|
163
|
-
HardwareErrorCode.RuntimeError,
|
|
164
|
-
'FilesystemFileWrite completed without a response'
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
options.throwIfAborted?.();
|
|
168
|
-
lastMessage = response.message;
|
|
169
|
-
const rawProcessedByte = response.message?.processed_byte;
|
|
170
|
-
const processedByte = Number(rawProcessedByte);
|
|
171
|
-
if (
|
|
172
|
-
rawProcessedByte !== undefined &&
|
|
173
|
-
(!Number.isFinite(processedByte) ||
|
|
174
|
-
processedByte <= offset ||
|
|
175
|
-
processedByte > offset + chunk.byteLength)
|
|
176
|
-
) {
|
|
177
|
-
throw ERRORS.TypedError(
|
|
178
|
-
HardwareErrorCode.RuntimeError,
|
|
179
|
-
`FilesystemFileWrite invalid processed_byte ${processedByte}`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
written =
|
|
183
|
-
rawProcessedByte === undefined ? written + chunk.byteLength : processedByte - startOffset;
|
|
184
|
-
chunks += 1;
|
|
302
|
+
} catch (error) {
|
|
185
303
|
const now = Date.now();
|
|
186
|
-
const elapsedMs = now - startTime;
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
rateWindowStartedBytes = transferredBytes;
|
|
194
|
-
} else if (rateBytesPerSecond === undefined && elapsedMs > 0) {
|
|
195
|
-
rateBytesPerSecond = Math.round((transferredBytes / elapsedMs) * 1000);
|
|
196
|
-
}
|
|
197
|
-
options.onProgress?.({
|
|
198
|
-
progress: getConfirmedProgress(startOffset + written, totalSize, written, dataLength),
|
|
199
|
-
transferredBytes,
|
|
304
|
+
const elapsedMs = Math.max(now - startTime, 0);
|
|
305
|
+
const logWindowElapsedMs = Math.max(now - logWindowStartedAt, 0);
|
|
306
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
307
|
+
logFileTransferMetrics({
|
|
308
|
+
transport,
|
|
309
|
+
status: 'failed',
|
|
310
|
+
transferredBytes: written,
|
|
200
311
|
totalBytes: dataLength,
|
|
201
|
-
rateBytesPerSecond,
|
|
202
312
|
elapsedMs,
|
|
313
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
203
314
|
});
|
|
204
|
-
|
|
205
|
-
await new Promise(resolve => {
|
|
206
|
-
setTimeout(resolve, options.paceMs);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
315
|
+
throw error;
|
|
209
316
|
}
|
|
210
317
|
|
|
318
|
+
const elapsedMs = Math.max(lastConfirmedAt - startTime, 0);
|
|
319
|
+
const logWindowElapsedMs = Math.max(lastConfirmedAt - logWindowStartedAt, 0);
|
|
320
|
+
const logWindowBytes = Math.max(written - logWindowStartedBytes, 0);
|
|
321
|
+
logFileTransferMetrics({
|
|
322
|
+
transport,
|
|
323
|
+
status: 'completed',
|
|
324
|
+
transferredBytes: written,
|
|
325
|
+
totalBytes: dataLength,
|
|
326
|
+
elapsedMs,
|
|
327
|
+
rateBytesPerSecond: getAverageFileTransferRate(logWindowBytes, logWindowElapsedMs),
|
|
328
|
+
});
|
|
329
|
+
|
|
211
330
|
return {
|
|
212
331
|
...lastMessage,
|
|
213
332
|
path: options.path,
|
package/src/api/index.ts
CHANGED
|
@@ -49,9 +49,6 @@ export { default as promptWebDeviceAccess } from './PromptWebDeviceAccess';
|
|
|
49
49
|
// Pro2 business API
|
|
50
50
|
export { default as deviceReboot } from './protocol-v2/DeviceReboot';
|
|
51
51
|
export { default as deviceGetOnboardingStatus } from './protocol-v2/DeviceGetOnboardingStatus';
|
|
52
|
-
export { default as deviceReadFactoryInfo } from './protocol-v2/DeviceFactoryInfoGet';
|
|
53
|
-
export { default as deviceReadFactoryCertificate } from './protocol-v2/DeviceFactoryCertificateRead';
|
|
54
|
-
export { default as deviceSignFactoryChallenge } from './protocol-v2/DeviceFactoryChallengeSign';
|
|
55
52
|
export { default as deviceUploadWallpaper } from './protocol-v2/DeviceUploadWallpaper';
|
|
56
53
|
export { default as deviceUploadNft } from './protocol-v2/DeviceUploadNft';
|
|
57
54
|
export { default as uploadPortfolio } from './UploadPortfolio';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
2
|
|
|
4
3
|
export default class DeviceFactoryInfoGet extends BaseMethod {
|
|
5
4
|
getSupportedProtocols() {
|
|
@@ -10,8 +9,6 @@ export default class DeviceFactoryInfoGet extends BaseMethod {
|
|
|
10
9
|
// Protocol V2 (Pro2) only; Core rejects non-V2 devices.
|
|
11
10
|
this.skipForceUpdateCheck = true;
|
|
12
11
|
this.useDevicePassphraseState = false;
|
|
13
|
-
this.unlockPolicy = 'none';
|
|
14
|
-
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.BOOTLOADER];
|
|
15
12
|
this.params = undefined;
|
|
16
13
|
}
|
|
17
14
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { BaseMethod } from '../BaseMethod';
|
|
2
|
-
import { UI_REQUEST } from '../../constants/ui-request';
|
|
3
|
-
import { validateDeviceFactoryInfoSetParams } from './helpers';
|
|
4
2
|
|
|
5
3
|
import type { DeviceFactoryInfoSetParams } from './helpers';
|
|
6
4
|
|
|
@@ -13,10 +11,13 @@ export default class DeviceFactoryInfoSet extends BaseMethod<DeviceFactoryInfoSe
|
|
|
13
11
|
// Protocol V2 (Pro2) only; Core rejects non-V2 devices.
|
|
14
12
|
this.skipForceUpdateCheck = true;
|
|
15
13
|
this.useDevicePassphraseState = false;
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
this.params = {
|
|
15
|
+
version: this.payload.version,
|
|
16
|
+
serial_number: this.payload.serial_number,
|
|
17
|
+
burn_in_completed: this.payload.burn_in_completed,
|
|
18
|
+
factory_test_completed: this.payload.factory_test_completed,
|
|
19
|
+
manufacture_time: this.payload.manufacture_time,
|
|
20
|
+
};
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
async run() {
|
|
@@ -37,11 +37,11 @@ export type DeviceFirmwareUpdateStatusGetParams = {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export type DeviceFactoryInfoSetParams = {
|
|
40
|
-
version
|
|
41
|
-
serial_number
|
|
42
|
-
burn_in_completed
|
|
43
|
-
factory_test_completed
|
|
44
|
-
manufacture_time
|
|
40
|
+
version?: number;
|
|
41
|
+
serial_number?: string;
|
|
42
|
+
burn_in_completed?: boolean;
|
|
43
|
+
factory_test_completed?: boolean;
|
|
44
|
+
manufacture_time?: {
|
|
45
45
|
year: number;
|
|
46
46
|
month: number;
|
|
47
47
|
day: number;
|
|
@@ -51,153 +51,6 @@ export type DeviceFactoryInfoSetParams = {
|
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
export type DeviceFactoryCertificateWriteParams = {
|
|
55
|
-
certificate: string;
|
|
56
|
-
privateKey?: string;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export type DeviceFactoryChallengeSignParams = {
|
|
60
|
-
digest: string;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const FACTORY_SERIAL_MAX_UTF8_BYTES = 24;
|
|
64
|
-
const FACTORY_CERTIFICATE_MAX_BYTES = 512;
|
|
65
|
-
const FACTORY_PRIVATE_KEY_BYTES = 32;
|
|
66
|
-
const FACTORY_CHALLENGE_DIGEST_BYTES = 32;
|
|
67
|
-
|
|
68
|
-
const getUtf8ByteLength = (value: string) =>
|
|
69
|
-
Array.from(value).reduce((length, character) => {
|
|
70
|
-
const codePoint = character.codePointAt(0) ?? 0;
|
|
71
|
-
if (codePoint <= 0x7f) return length + 1;
|
|
72
|
-
if (codePoint <= 0x7ff) return length + 2;
|
|
73
|
-
if (codePoint <= 0xffff) return length + 3;
|
|
74
|
-
return length + 4;
|
|
75
|
-
}, 0);
|
|
76
|
-
|
|
77
|
-
const validateRequiredBoolean = (value: unknown, name: string): boolean => {
|
|
78
|
-
if (typeof value !== 'boolean') {
|
|
79
|
-
throw invalidParameter(`Parameter [${name}] is required and must be a boolean.`);
|
|
80
|
-
}
|
|
81
|
-
return value;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const validateIntegerInRange = (
|
|
85
|
-
value: unknown,
|
|
86
|
-
name: string,
|
|
87
|
-
minimum: number,
|
|
88
|
-
maximum: number
|
|
89
|
-
): number => {
|
|
90
|
-
if (
|
|
91
|
-
typeof value !== 'number' ||
|
|
92
|
-
!Number.isSafeInteger(value) ||
|
|
93
|
-
value < minimum ||
|
|
94
|
-
value > maximum
|
|
95
|
-
) {
|
|
96
|
-
throw invalidParameter(
|
|
97
|
-
`Parameter [${name}] must be an integer between ${minimum} and ${maximum}.`
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
return value;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const validateHexBytes = (
|
|
104
|
-
value: unknown,
|
|
105
|
-
name: string,
|
|
106
|
-
options: { exactBytes?: number; maxBytes?: number }
|
|
107
|
-
): string => {
|
|
108
|
-
const hex = validateNonEmptyString(value, name).trim();
|
|
109
|
-
if (!/^(?:[0-9a-fA-F]{2})+$/.test(hex)) {
|
|
110
|
-
throw invalidParameter(`Parameter [${name}] must be an even-length hexadecimal string.`);
|
|
111
|
-
}
|
|
112
|
-
const byteLength = hex.length / 2;
|
|
113
|
-
if (options.exactBytes !== undefined && byteLength !== options.exactBytes) {
|
|
114
|
-
throw invalidParameter(`Parameter [${name}] must contain exactly ${options.exactBytes} bytes.`);
|
|
115
|
-
}
|
|
116
|
-
if (options.maxBytes !== undefined && byteLength > options.maxBytes) {
|
|
117
|
-
throw invalidParameter(`Parameter [${name}] must not exceed ${options.maxBytes} bytes.`);
|
|
118
|
-
}
|
|
119
|
-
return hex;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export function validateDeviceFactoryInfoSetParams(
|
|
123
|
-
payload: Partial<DeviceFactoryInfoSetParams>
|
|
124
|
-
): DeviceFactoryInfoSetParams {
|
|
125
|
-
const serialNumber = validateNonEmptyString(payload.serial_number, 'serial_number').trim();
|
|
126
|
-
if (getUtf8ByteLength(serialNumber) > FACTORY_SERIAL_MAX_UTF8_BYTES) {
|
|
127
|
-
throw invalidParameter(
|
|
128
|
-
`Parameter [serial_number] must not exceed ${FACTORY_SERIAL_MAX_UTF8_BYTES} UTF-8 bytes.`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const time = payload.manufacture_time;
|
|
133
|
-
if (!time || typeof time !== 'object') {
|
|
134
|
-
throw invalidParameter('Parameter [manufacture_time] is required.');
|
|
135
|
-
}
|
|
136
|
-
const manufactureTime = {
|
|
137
|
-
year: validateIntegerInRange(time.year, 'manufacture_time.year', 2000, 9999),
|
|
138
|
-
month: validateIntegerInRange(time.month, 'manufacture_time.month', 1, 12),
|
|
139
|
-
day: validateIntegerInRange(time.day, 'manufacture_time.day', 1, 31),
|
|
140
|
-
hour: validateIntegerInRange(time.hour, 'manufacture_time.hour', 0, 23),
|
|
141
|
-
minute: validateIntegerInRange(time.minute, 'manufacture_time.minute', 0, 59),
|
|
142
|
-
second: validateIntegerInRange(time.second, 'manufacture_time.second', 0, 59),
|
|
143
|
-
};
|
|
144
|
-
const normalizedDate = new Date(
|
|
145
|
-
Date.UTC(
|
|
146
|
-
manufactureTime.year,
|
|
147
|
-
manufactureTime.month - 1,
|
|
148
|
-
manufactureTime.day,
|
|
149
|
-
manufactureTime.hour,
|
|
150
|
-
manufactureTime.minute,
|
|
151
|
-
manufactureTime.second
|
|
152
|
-
)
|
|
153
|
-
);
|
|
154
|
-
if (
|
|
155
|
-
normalizedDate.getUTCFullYear() !== manufactureTime.year ||
|
|
156
|
-
normalizedDate.getUTCMonth() + 1 !== manufactureTime.month ||
|
|
157
|
-
normalizedDate.getUTCDate() !== manufactureTime.day
|
|
158
|
-
) {
|
|
159
|
-
throw invalidParameter('Parameter [manufacture_time] must be a valid calendar date.');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
version: validateIntegerInRange(payload.version, 'version', 0, 255),
|
|
164
|
-
serial_number: serialNumber,
|
|
165
|
-
burn_in_completed: validateRequiredBoolean(payload.burn_in_completed, 'burn_in_completed'),
|
|
166
|
-
factory_test_completed: validateRequiredBoolean(
|
|
167
|
-
payload.factory_test_completed,
|
|
168
|
-
'factory_test_completed'
|
|
169
|
-
),
|
|
170
|
-
manufacture_time: manufactureTime,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function validateDeviceFactoryCertificateWriteParams(
|
|
175
|
-
payload: Partial<DeviceFactoryCertificateWriteParams>
|
|
176
|
-
): DeviceFactoryCertificateWriteParams {
|
|
177
|
-
return {
|
|
178
|
-
certificate: validateHexBytes(payload.certificate, 'certificate', {
|
|
179
|
-
maxBytes: FACTORY_CERTIFICATE_MAX_BYTES,
|
|
180
|
-
}),
|
|
181
|
-
...(payload.privateKey === undefined
|
|
182
|
-
? {}
|
|
183
|
-
: {
|
|
184
|
-
privateKey: validateHexBytes(payload.privateKey, 'privateKey', {
|
|
185
|
-
exactBytes: FACTORY_PRIVATE_KEY_BYTES,
|
|
186
|
-
}),
|
|
187
|
-
}),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function validateDeviceFactoryChallengeSignParams(
|
|
192
|
-
payload: Partial<DeviceFactoryChallengeSignParams>
|
|
193
|
-
): DeviceFactoryChallengeSignParams {
|
|
194
|
-
return {
|
|
195
|
-
digest: validateHexBytes(payload.digest, 'digest', {
|
|
196
|
-
exactBytes: FACTORY_CHALLENGE_DIGEST_BYTES,
|
|
197
|
-
}),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
54
|
const DEVICE_REBOOT_TYPES: Record<string, DeviceRebootType> = {
|
|
202
55
|
Normal: DeviceRebootType.Normal,
|
|
203
56
|
normal: DeviceRebootType.Normal,
|
package/src/api/utils.ts
CHANGED
|
@@ -3,47 +3,13 @@ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
|
3
3
|
import * as ApiMethods from './index';
|
|
4
4
|
|
|
5
5
|
import type { BaseMethod } from './BaseMethod';
|
|
6
|
-
import type { CoreMethodExtension } from './methodExtension';
|
|
7
6
|
import type { IFrameCallMessage } from '../events';
|
|
8
7
|
|
|
9
8
|
type MethodConstructor = new (message: IFrameCallMessage & { id?: number }) => BaseMethod<any>;
|
|
10
9
|
|
|
11
10
|
const publicMethodRegistry = ApiMethods as unknown as Record<string, MethodConstructor>;
|
|
12
11
|
|
|
13
|
-
export
|
|
14
|
-
extensions?: readonly CoreMethodExtension[];
|
|
15
|
-
allowDestructiveOperations?: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const findExtensionMethod = (
|
|
19
|
-
method: string,
|
|
20
|
-
extensions: readonly CoreMethodExtension[]
|
|
21
|
-
): { constructor: MethodConstructor; destructive: boolean } | undefined => {
|
|
22
|
-
let match: { constructor: MethodConstructor; destructive: boolean } | undefined;
|
|
23
|
-
|
|
24
|
-
for (const extension of extensions) {
|
|
25
|
-
const constructor = extension.methods[method];
|
|
26
|
-
if (constructor) {
|
|
27
|
-
if (match) {
|
|
28
|
-
throw ERRORS.TypedError(
|
|
29
|
-
HardwareErrorCode.CallMethodInvalidParameter,
|
|
30
|
-
`Method ${method} is registered by multiple extensions`
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
match = {
|
|
34
|
-
constructor,
|
|
35
|
-
destructive: extension.destructiveMethods?.includes(method) === true,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return match;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export function findMethod(
|
|
44
|
-
message: IFrameCallMessage & { id?: number },
|
|
45
|
-
options: FindMethodOptions = {}
|
|
46
|
-
): BaseMethod<any> {
|
|
12
|
+
export function findMethod(message: IFrameCallMessage & { id?: number }): BaseMethod<any> {
|
|
47
13
|
const { method } = message.payload;
|
|
48
14
|
if (typeof method !== 'string') {
|
|
49
15
|
throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, 'Method is not set');
|
|
@@ -54,17 +20,6 @@ export function findMethod(
|
|
|
54
20
|
return new MethodConstructor(message);
|
|
55
21
|
}
|
|
56
22
|
|
|
57
|
-
const extensionMethod = findExtensionMethod(method, options.extensions ?? []);
|
|
58
|
-
if (extensionMethod) {
|
|
59
|
-
if (extensionMethod.destructive && options.allowDestructiveOperations !== true) {
|
|
60
|
-
throw ERRORS.TypedError(
|
|
61
|
-
HardwareErrorCode.CallMethodInvalidParameter,
|
|
62
|
-
`Destructive method ${method} requires allowDestructiveOperations`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
return new extensionMethod.constructor(message);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
23
|
throw ERRORS.TypedError(
|
|
69
24
|
HardwareErrorCode.CallMethodInvalidParameter,
|
|
70
25
|
`Method ${method} is not set`
|