@onetokenfe/hd-core 1.1.23
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/.eslintrc +6 -0
- package/README.md +32 -0
- package/__tests__/benfen.test.ts +68 -0
- package/__tests__/checkBootloaderReleast.test.ts +115 -0
- package/__tests__/evmSignTransaction.test.ts +419 -0
- package/jest.config.js +6 -0
- package/package.json +48 -0
- package/src/api/BaseMethod.ts +275 -0
- package/src/api/CheckAllFirmwareRelease.ts +73 -0
- package/src/api/CheckBLEFirmwareRelease.ts +23 -0
- package/src/api/CheckBootloaderRelease.ts +32 -0
- package/src/api/CheckBridgeRelease.ts +28 -0
- package/src/api/CheckBridgeStatus.ts +32 -0
- package/src/api/CheckFirmwareRelease.ts +31 -0
- package/src/api/CheckFirmwareTypeAvailable.tsx +30 -0
- package/src/api/CipherKeyValue.ts +68 -0
- package/src/api/FirmwareUpdate.ts +219 -0
- package/src/api/FirmwareUpdateV2.ts +408 -0
- package/src/api/FirmwareUpdateV3.ts +560 -0
- package/src/api/GetFeatures.ts +23 -0
- package/src/api/GetLogs.ts +40 -0
- package/src/api/GetOnetokenFeatures.ts +25 -0
- package/src/api/GetPassphraseState.ts +28 -0
- package/src/api/PromptWebDeviceAccess.ts +77 -0
- package/src/api/SearchDevices.ts +50 -0
- package/src/api/alephium/AlephiumGetAddress.ts +84 -0
- package/src/api/alephium/AlephiumSignMessage.ts +51 -0
- package/src/api/alephium/AlephiumSignTransaction.ts +135 -0
- package/src/api/algo/AlgoGetAddress.ts +73 -0
- package/src/api/algo/AlgoSignTransaction.ts +52 -0
- package/src/api/allnetwork/AllNetworkGetAddress.ts +88 -0
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +529 -0
- package/src/api/allnetwork/AllNetworkGetAddressByLoop.ts +162 -0
- package/src/api/aptos/AptosGetAddress.ts +129 -0
- package/src/api/aptos/AptosGetPublicKey.ts +64 -0
- package/src/api/aptos/AptosSignInMessage.ts +55 -0
- package/src/api/aptos/AptosSignMessage.ts +79 -0
- package/src/api/aptos/AptosSignTransaction.ts +72 -0
- package/src/api/benfen/BenfenGetAddress.ts +122 -0
- package/src/api/benfen/BenfenGetPublicKey.ts +68 -0
- package/src/api/benfen/BenfenSignMessage.ts +50 -0
- package/src/api/benfen/BenfenSignTransaction.ts +105 -0
- package/src/api/benfen/normalize.ts +51 -0
- package/src/api/btc/BTCGetAddress.ts +91 -0
- package/src/api/btc/BTCGetPublicKey.ts +174 -0
- package/src/api/btc/BTCSignMessage.ts +73 -0
- package/src/api/btc/BTCSignPsbt.ts +65 -0
- package/src/api/btc/BTCSignTransaction.ts +148 -0
- package/src/api/btc/BTCVerifyMessage.ts +46 -0
- package/src/api/btc/helpers/btcParamsUtils.ts +64 -0
- package/src/api/btc/helpers/signtx.ts +251 -0
- package/src/api/btc/helpers/signtxLegacy.ts +227 -0
- package/src/api/btc/helpers/versionLimit.ts +25 -0
- package/src/api/btc/helpers/xpubUtils.ts +132 -0
- package/src/api/cardano/CardanoGetAddress.ts +139 -0
- package/src/api/cardano/CardanoGetPublicKey.ts +72 -0
- package/src/api/cardano/CardanoSignMessage.ts +73 -0
- package/src/api/cardano/CardanoSignTransaction.ts +404 -0
- package/src/api/cardano/helper/addressParameters.ts +120 -0
- package/src/api/cardano/helper/auxiliaryData.ts +133 -0
- package/src/api/cardano/helper/cardanoInputs.ts +55 -0
- package/src/api/cardano/helper/cardanoOutputs.ts +89 -0
- package/src/api/cardano/helper/certificate.ts +246 -0
- package/src/api/cardano/helper/token.ts +44 -0
- package/src/api/cardano/helper/utils.ts +17 -0
- package/src/api/cardano/helper/witnesses.ts +62 -0
- package/src/api/conflux/ConfluxGetAddress.ts +78 -0
- package/src/api/conflux/ConfluxSignMessage.ts +49 -0
- package/src/api/conflux/ConfluxSignMessageCIP23.ts +49 -0
- package/src/api/conflux/ConfluxSignTransaction.ts +135 -0
- package/src/api/cosmos/CosmosGetAddress.ts +80 -0
- package/src/api/cosmos/CosmosGetPublicKey.ts +77 -0
- package/src/api/cosmos/CosmosSignTransaction.ts +68 -0
- package/src/api/device/DeviceBackup.ts +15 -0
- package/src/api/device/DeviceCancel.ts +15 -0
- package/src/api/device/DeviceChangePin.ts +25 -0
- package/src/api/device/DeviceFlags.ts +26 -0
- package/src/api/device/DeviceFullyUploadResource.ts +80 -0
- package/src/api/device/DeviceLock.ts +15 -0
- package/src/api/device/DeviceRebootToBoardloader.ts +30 -0
- package/src/api/device/DeviceRebootToBootloader.ts +28 -0
- package/src/api/device/DeviceRecovery.ts +44 -0
- package/src/api/device/DeviceReset.ts +46 -0
- package/src/api/device/DeviceSettings.ts +96 -0
- package/src/api/device/DeviceSupportFeatures.ts +29 -0
- package/src/api/device/DeviceUnlock.ts +13 -0
- package/src/api/device/DeviceUpdateBootloader.ts +111 -0
- package/src/api/device/DeviceUpdateReboot.ts +17 -0
- package/src/api/device/DeviceUploadResource.ts +204 -0
- package/src/api/device/DeviceVerify.ts +65 -0
- package/src/api/device/DeviceWipe.ts +15 -0
- package/src/api/dynex/DnxGetAddress.ts +75 -0
- package/src/api/dynex/DnxSignTransaction.ts +126 -0
- package/src/api/evm/EVMGetAddress.ts +88 -0
- package/src/api/evm/EVMGetPublicKey.ts +116 -0
- package/src/api/evm/EVMSignMessage.ts +49 -0
- package/src/api/evm/EVMSignMessageEIP712.ts +56 -0
- package/src/api/evm/EVMSignTransaction.ts +141 -0
- package/src/api/evm/EVMSignTypedData.ts +477 -0
- package/src/api/evm/EVMVerifyMessage.ts +46 -0
- package/src/api/evm/latest/getAddress.ts +13 -0
- package/src/api/evm/latest/getPublicKey.ts +17 -0
- package/src/api/evm/latest/signMessage.ts +19 -0
- package/src/api/evm/latest/signTransaction.ts +303 -0
- package/src/api/evm/latest/signTypedData.ts +34 -0
- package/src/api/evm/latest/signTypedHash.ts +46 -0
- package/src/api/evm/latest/verifyMessage.ts +15 -0
- package/src/api/evm/legacyV1/getAddress.ts +16 -0
- package/src/api/evm/legacyV1/getPublicKey.ts +20 -0
- package/src/api/evm/legacyV1/signMessage.ts +22 -0
- package/src/api/evm/legacyV1/signTransaction.ts +37 -0
- package/src/api/evm/legacyV1/signTypedData.ts +37 -0
- package/src/api/evm/legacyV1/signTypedHash.ts +50 -0
- package/src/api/evm/legacyV1/verifyMessage.ts +19 -0
- package/src/api/filecoin/FilecoinGetAddress.ts +80 -0
- package/src/api/filecoin/FilecoinSignTransaction.ts +57 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +476 -0
- package/src/api/firmware/bootloaderHelper.ts +46 -0
- package/src/api/firmware/getBinary.ts +99 -0
- package/src/api/firmware/releaseHelper.ts +78 -0
- package/src/api/firmware/updateBootloader.ts +82 -0
- package/src/api/firmware/uploadFirmware.ts +541 -0
- package/src/api/helpers/batchGetPublickeys.ts +84 -0
- package/src/api/helpers/bigNumberUtils.ts +58 -0
- package/src/api/helpers/hexUtils.ts +111 -0
- package/src/api/helpers/paramsValidator.ts +165 -0
- package/src/api/helpers/pathUtils.ts +145 -0
- package/src/api/helpers/stringUtils.ts +11 -0
- package/src/api/helpers/typeNameUtils.ts +137 -0
- package/src/api/index.ts +161 -0
- package/src/api/kaspa/KaspaGetAddress.ts +103 -0
- package/src/api/kaspa/KaspaSignTransaction.ts +182 -0
- package/src/api/kaspa/helpers/BufferWriter.ts +177 -0
- package/src/api/kaspa/helpers/HashWriter.ts +74 -0
- package/src/api/kaspa/helpers/SignatureType.ts +7 -0
- package/src/api/kaspa/helpers/TransferSerialize.ts +144 -0
- package/src/api/lightning/LnurlAuth.ts +52 -0
- package/src/api/near/NearGetAddress.ts +75 -0
- package/src/api/near/NearSignTransaction.ts +46 -0
- package/src/api/nem/NEMGetAddress.ts +72 -0
- package/src/api/nem/NEMSignTransaction.ts +251 -0
- package/src/api/neo/NeoGetAddress.ts +80 -0
- package/src/api/neo/NeoSignTransaction.ts +59 -0
- package/src/api/nervos/NervosGetAddress.ts +80 -0
- package/src/api/nervos/NervosSignTransaction.ts +116 -0
- package/src/api/nexa/NexaGetAddress.ts +88 -0
- package/src/api/nexa/NexaSignTransaction.ts +107 -0
- package/src/api/nostr/NostrDecryptMessage.ts +57 -0
- package/src/api/nostr/NostrEncryptMessage.ts +57 -0
- package/src/api/nostr/NostrGetPublicKey.ts +74 -0
- package/src/api/nostr/NostrSignEvent.ts +65 -0
- package/src/api/nostr/NostrSignSchnorr.ts +52 -0
- package/src/api/nostr/helper/index.ts +28 -0
- package/src/api/polkadot/PolkadotGetAddress.ts +83 -0
- package/src/api/polkadot/PolkadotSignTransaction.ts +53 -0
- package/src/api/polkadot/networks.ts +72 -0
- package/src/api/scdo/ScdoGetAddress.ts +76 -0
- package/src/api/scdo/ScdoSignMessage.ts +45 -0
- package/src/api/scdo/ScdoSignTransaction.ts +106 -0
- package/src/api/solana/SolGetAddress.ts +68 -0
- package/src/api/solana/SolSignMessage.ts +61 -0
- package/src/api/solana/SolSignOffchainMessage.ts +61 -0
- package/src/api/solana/SolSignTransaction.ts +108 -0
- package/src/api/starcoin/StarcoinGetAddress.ts +69 -0
- package/src/api/starcoin/StarcoinGetPublicKey.ts +70 -0
- package/src/api/starcoin/StarcoinSignMessage.ts +42 -0
- package/src/api/starcoin/StarcoinSignTransaction.ts +38 -0
- package/src/api/starcoin/StarcoinVerifyMessage.ts +35 -0
- package/src/api/stellar/StellarGetAddress.ts +68 -0
- package/src/api/stellar/StellarSignTransaction.ts +220 -0
- package/src/api/sui/SuiGetAddress.ts +117 -0
- package/src/api/sui/SuiGetPublicKey.ts +66 -0
- package/src/api/sui/SuiSignMessage.ts +48 -0
- package/src/api/sui/SuiSignTransaction.ts +126 -0
- package/src/api/sui/normalize.ts +28 -0
- package/src/api/test/TestInitializeDeviceDuration.ts +22 -0
- package/src/api/ton/TonGetAddress.ts +96 -0
- package/src/api/ton/TonSignMessage.ts +217 -0
- package/src/api/ton/TonSignProof.ts +62 -0
- package/src/api/tron/TronGetAddress.ts +75 -0
- package/src/api/tron/TronSignMessage.ts +89 -0
- package/src/api/tron/TronSignTransaction.ts +214 -0
- package/src/api/u2f/GetNextU2FCounter.ts +15 -0
- package/src/api/u2f/SetU2FCounter.ts +19 -0
- package/src/api/utils.ts +23 -0
- package/src/api/xrp/XrpGetAddress.ts +96 -0
- package/src/api/xrp/XrpSignTransaction.ts +71 -0
- package/src/constants/errors.ts +15 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/ui-request.ts +3 -0
- package/src/core/RequestQueue.ts +134 -0
- package/src/core/index.ts +1320 -0
- package/src/data/coins/bitcoin.json +44 -0
- package/src/data/config.ts +25 -0
- package/src/data/messages/messages.json +13167 -0
- package/src/data/messages/messages_legacy_v1.json +10282 -0
- package/src/data-manager/CoinManager.ts +31 -0
- package/src/data-manager/DataManager.ts +499 -0
- package/src/data-manager/MessagesConfig.ts +28 -0
- package/src/data-manager/TransportManager.ts +140 -0
- package/src/data-manager/connectSettings.ts +121 -0
- package/src/data-manager/index.ts +3 -0
- package/src/device/Device.ts +884 -0
- package/src/device/DeviceCommands.ts +631 -0
- package/src/device/DeviceConnector.ts +124 -0
- package/src/device/DeviceList.ts +39 -0
- package/src/device/DevicePool.ts +266 -0
- package/src/events/call.ts +95 -0
- package/src/events/core.ts +65 -0
- package/src/events/device.ts +92 -0
- package/src/events/firmware.ts +43 -0
- package/src/events/iframe.ts +55 -0
- package/src/events/index.ts +10 -0
- package/src/events/log.ts +23 -0
- package/src/events/logBlockEvent.ts +6 -0
- package/src/events/ui-promise.ts +14 -0
- package/src/events/ui-request.ts +216 -0
- package/src/events/ui-response.ts +59 -0
- package/src/events/utils.ts +19 -0
- package/src/index.ts +70 -0
- package/src/inject.ts +408 -0
- package/src/lowLevelInject.ts +61 -0
- package/src/topLevelInject.ts +62 -0
- package/src/types/api/alephiumGetAddress.ts +31 -0
- package/src/types/api/alephiumSignMessage.ts +14 -0
- package/src/types/api/alephiumSignTransaction.ts +18 -0
- package/src/types/api/algoGetAddress.ts +23 -0
- package/src/types/api/algoSignTransaction.ts +17 -0
- package/src/types/api/allNetworkGetAddress.ts +130 -0
- package/src/types/api/aptosGetAddress.ts +28 -0
- package/src/types/api/aptosGetPublicKey.ts +27 -0
- package/src/types/api/aptosSignInMessage.ts +17 -0
- package/src/types/api/aptosSignMessage.ts +26 -0
- package/src/types/api/aptosSignTransaction.ts +18 -0
- package/src/types/api/benfenGetAddress.ts +24 -0
- package/src/types/api/benfenGetPublicKey.ts +23 -0
- package/src/types/api/benfenSignMessage.ts +13 -0
- package/src/types/api/benfenSignTransaction.ts +19 -0
- package/src/types/api/btcGetAddress.ts +26 -0
- package/src/types/api/btcGetPublicKey.ts +26 -0
- package/src/types/api/btcSignMessage.ts +16 -0
- package/src/types/api/btcSignPsbt.ts +13 -0
- package/src/types/api/btcSignTransaction.ts +98 -0
- package/src/types/api/btcVerifyMessage.ts +15 -0
- package/src/types/api/cardano.ts +212 -0
- package/src/types/api/cardanoGetAddress.ts +49 -0
- package/src/types/api/cardanoGetPublicKey.ts +33 -0
- package/src/types/api/cardanoSignMessage.ts +31 -0
- package/src/types/api/cardanoSignTransaction.ts +8 -0
- package/src/types/api/checkAllFirmwareRelease.ts +34 -0
- package/src/types/api/checkBLEFirmwareRelease.ts +15 -0
- package/src/types/api/checkBootloaderRelease.ts +19 -0
- package/src/types/api/checkBridgeRelease.ts +14 -0
- package/src/types/api/checkBridgeStatus.ts +3 -0
- package/src/types/api/checkFirmwareRelease.ts +23 -0
- package/src/types/api/checkFirmwareTypeAvailable.ts +12 -0
- package/src/types/api/cipherKeyValue.ts +28 -0
- package/src/types/api/confluxGetAddress.ts +24 -0
- package/src/types/api/confluxSignMessage.ts +13 -0
- package/src/types/api/confluxSignMessageCIP23.ts +14 -0
- package/src/types/api/confluxSignTransaction.ts +32 -0
- package/src/types/api/cosmosGetAddress.ts +24 -0
- package/src/types/api/cosmosGetPublicKey.ts +28 -0
- package/src/types/api/cosmosSignTransaction.ts +17 -0
- package/src/types/api/deviceBackup.ts +4 -0
- package/src/types/api/deviceCancel.ts +4 -0
- package/src/types/api/deviceChangePin.ts +11 -0
- package/src/types/api/deviceFlags.ts +11 -0
- package/src/types/api/deviceFullyUploadResource.ts +15 -0
- package/src/types/api/deviceLock.ts +4 -0
- package/src/types/api/deviceRebootToBoardloader.ts +6 -0
- package/src/types/api/deviceRebootToBootloader.ts +4 -0
- package/src/types/api/deviceRecovery.ts +19 -0
- package/src/types/api/deviceReset.ts +20 -0
- package/src/types/api/deviceSettings.ts +23 -0
- package/src/types/api/deviceSupportFeatures.ts +6 -0
- package/src/types/api/deviceUnlock.ts +4 -0
- package/src/types/api/deviceUpdateBootloader.ts +13 -0
- package/src/types/api/deviceUpdateReboot.ts +3 -0
- package/src/types/api/deviceUploadResource.ts +21 -0
- package/src/types/api/deviceVerify.ts +15 -0
- package/src/types/api/deviceWipe.ts +4 -0
- package/src/types/api/dnxGetAddress.ts +23 -0
- package/src/types/api/dnxSignTransaction.ts +36 -0
- package/src/types/api/event.ts +8 -0
- package/src/types/api/evmGetAddress.ts +24 -0
- package/src/types/api/evmGetPublicKey.ts +36 -0
- package/src/types/api/evmSignMessage.ts +14 -0
- package/src/types/api/evmSignMessageEIP712.ts +14 -0
- package/src/types/api/evmSignTransaction.ts +80 -0
- package/src/types/api/evmSignTypedData.ts +42 -0
- package/src/types/api/evmVerifyMessage.ts +15 -0
- package/src/types/api/export.ts +194 -0
- package/src/types/api/filecoinGetAddress.ts +24 -0
- package/src/types/api/filecoinSignTransaction.ts +24 -0
- package/src/types/api/firmwareUpdate.ts +66 -0
- package/src/types/api/getFeatures.ts +4 -0
- package/src/types/api/getLogs.ts +3 -0
- package/src/types/api/getNextU2FCounter.ts +7 -0
- package/src/types/api/getOnetokenFeatures.ts +7 -0
- package/src/types/api/getPassphraseState.ts +6 -0
- package/src/types/api/index.ts +404 -0
- package/src/types/api/init.ts +11 -0
- package/src/types/api/kaspaGetAddress.ts +26 -0
- package/src/types/api/kaspaSignTransaction.ts +44 -0
- package/src/types/api/lnurlAuth.ts +22 -0
- package/src/types/api/nearGetAddress.ts +23 -0
- package/src/types/api/nearSignTransaction.ts +13 -0
- package/src/types/api/nemGetAddress.ts +24 -0
- package/src/types/api/nemSignTransaction.ts +118 -0
- package/src/types/api/neoGetAddress.ts +24 -0
- package/src/types/api/neoSignTransaction.ts +18 -0
- package/src/types/api/nervosGetAddress.ts +24 -0
- package/src/types/api/nervosSignTransaction.ts +19 -0
- package/src/types/api/nexaGetAddress.ts +26 -0
- package/src/types/api/nexaSignTransaction.ts +28 -0
- package/src/types/api/nostrDecryptMessage.ts +25 -0
- package/src/types/api/nostrEncryptMessage.ts +25 -0
- package/src/types/api/nostrGetPublicKey.ts +28 -0
- package/src/types/api/nostrSignEvent.ts +52 -0
- package/src/types/api/nostrSignSchnorr.ts +22 -0
- package/src/types/api/polkadotGetAddress.ts +30 -0
- package/src/types/api/polkadotSignTransaction.ts +19 -0
- package/src/types/api/promptWebDeviceAccess.ts +6 -0
- package/src/types/api/scdoGetAddress.ts +23 -0
- package/src/types/api/scdoSignMessage.ts +13 -0
- package/src/types/api/scdoSignTransaction.ts +24 -0
- package/src/types/api/searchDevices.ts +4 -0
- package/src/types/api/setU2FCounter.ts +7 -0
- package/src/types/api/solGetAddress.ts +23 -0
- package/src/types/api/solSignMessage.ts +17 -0
- package/src/types/api/solSignOffchainMessage.ts +24 -0
- package/src/types/api/solSignTransaction.ts +27 -0
- package/src/types/api/starcoinGetAddress.ts +23 -0
- package/src/types/api/starcoinGetPublicKey.ts +23 -0
- package/src/types/api/starcoinSignMessage.ts +13 -0
- package/src/types/api/starcoinSignTransaction.ts +13 -0
- package/src/types/api/starcoinVerifyMessage.ts +14 -0
- package/src/types/api/stellarGetAddress.ts +23 -0
- package/src/types/api/stellarSignTransaction.ts +154 -0
- package/src/types/api/suiGetAddress.ts +28 -0
- package/src/types/api/suiGetPublicKey.ts +27 -0
- package/src/types/api/suiSignMessage.ts +13 -0
- package/src/types/api/suiSignTransaction.ts +17 -0
- package/src/types/api/testInitializeDeviceDuration.ts +6 -0
- package/src/types/api/tonGetAddress.ts +34 -0
- package/src/types/api/tonSignMessage.ts +42 -0
- package/src/types/api/tonSignProof.ts +25 -0
- package/src/types/api/tronGetAddress.ts +23 -0
- package/src/types/api/tronSignMessage.ts +14 -0
- package/src/types/api/tronSignTransaction.ts +89 -0
- package/src/types/api/uiResponse.ts +3 -0
- package/src/types/api/xrpGetAddress.ts +28 -0
- package/src/types/api/xrpSignTransaction.ts +29 -0
- package/src/types/device.ts +194 -0
- package/src/types/firmware.ts +41 -0
- package/src/types/global.d.ts +3 -0
- package/src/types/index.ts +5 -0
- package/src/types/params.ts +64 -0
- package/src/types/settings.ts +144 -0
- package/src/utils/arrayUtils.ts +7 -0
- package/src/utils/assets.ts +5 -0
- package/src/utils/bridgeUpdate.ts +80 -0
- package/src/utils/capabilitieUtils.ts +12 -0
- package/src/utils/deviceFeaturesUtils.ts +352 -0
- package/src/utils/deviceInfoUtils.ts +167 -0
- package/src/utils/deviceSettings.ts +109 -0
- package/src/utils/deviceVersionUtils.ts +79 -0
- package/src/utils/findDefectiveBatchDevice.ts +39 -0
- package/src/utils/getMutex.ts +41 -0
- package/src/utils/getSynchronize.ts +25 -0
- package/src/utils/homescreen.ts +345 -0
- package/src/utils/index.ts +44 -0
- package/src/utils/logger.ts +190 -0
- package/src/utils/networkUtils.ts +25 -0
- package/src/utils/patch.ts +14 -0
- package/src/utils/promiseUtils.ts +4 -0
- package/src/utils/release.ts +42 -0
- package/src/utils/semver.test.js +53 -0
- package/src/utils/tracing.ts +238 -0
- package/src/utils/versionUtils.ts +120 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
3
|
+
|
|
4
|
+
import { BaseMethod } from '../BaseMethod';
|
|
5
|
+
import { PROTO } from '../../constants';
|
|
6
|
+
import { UI_REQUEST } from '../../constants/ui-request';
|
|
7
|
+
import { validateParams } from '../helpers/paramsValidator';
|
|
8
|
+
import {
|
|
9
|
+
transformCollateralInput,
|
|
10
|
+
transformInput,
|
|
11
|
+
transformReferenceInput,
|
|
12
|
+
} from './helper/cardanoInputs';
|
|
13
|
+
import { sendOutput, transformOutput } from './helper/cardanoOutputs';
|
|
14
|
+
import { transformCertificate } from './helper/certificate';
|
|
15
|
+
import { tokenBundleToProto } from './helper/token';
|
|
16
|
+
import {
|
|
17
|
+
modifyAuxiliaryDataForBackwardsCompatibility,
|
|
18
|
+
transformAuxiliaryData,
|
|
19
|
+
} from './helper/auxiliaryData';
|
|
20
|
+
import { gatherWitnessPaths } from './helper/witnesses';
|
|
21
|
+
import { validatePath } from '../helpers/pathUtils';
|
|
22
|
+
import { getDeviceFirmwareVersion, getMethodVersionRange } from '../../utils';
|
|
23
|
+
|
|
24
|
+
import type { DeviceFirmwareRange } from '../../types';
|
|
25
|
+
import type { CollateralInputWithPath, Path } from './helper/cardanoInputs';
|
|
26
|
+
import type {
|
|
27
|
+
AssetGroupWithTokens,
|
|
28
|
+
CardanoAuxiliaryDataSupplement,
|
|
29
|
+
CardanoSignTransaction as CardanoSignTransactionType,
|
|
30
|
+
CardanoSignedTxData,
|
|
31
|
+
CardanoSignedTxWitness,
|
|
32
|
+
CertificateWithPoolOwnersAndRelays,
|
|
33
|
+
} from '../../types/api/cardano';
|
|
34
|
+
|
|
35
|
+
export default class CardanoSignTransaction extends BaseMethod<any> {
|
|
36
|
+
hasBundle?: boolean;
|
|
37
|
+
|
|
38
|
+
getVersionRange() {
|
|
39
|
+
return {
|
|
40
|
+
model_mini: {
|
|
41
|
+
min: '3.0.0',
|
|
42
|
+
},
|
|
43
|
+
model_touch: {
|
|
44
|
+
min: '4.1.0',
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
init() {
|
|
50
|
+
this.checkDeviceId = true;
|
|
51
|
+
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
52
|
+
|
|
53
|
+
this.hasBundle = !!this.payload?.bundle;
|
|
54
|
+
|
|
55
|
+
const { payload } = this;
|
|
56
|
+
|
|
57
|
+
// convert legacy parameters to new parameter
|
|
58
|
+
// payload.auxiliaryData.governanceRegistrationParameters are legacy params kept for backward compatibility (for now)
|
|
59
|
+
if (payload.auxiliaryData && payload.auxiliaryData.governanceRegistrationParameters) {
|
|
60
|
+
console.warn(
|
|
61
|
+
'Please use cVoteRegistrationParameters instead of governanceRegistrationParameters.'
|
|
62
|
+
);
|
|
63
|
+
payload.auxiliaryData.cVoteRegistrationParameters =
|
|
64
|
+
payload.auxiliaryData.governanceRegistrationParameters;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// validate incoming parameters
|
|
68
|
+
validateParams(payload, [
|
|
69
|
+
{ name: 'signingMode', type: 'number', required: true },
|
|
70
|
+
{ name: 'inputs', type: 'array', required: true },
|
|
71
|
+
{ name: 'outputs', type: 'array', required: true, allowEmpty: true },
|
|
72
|
+
{ name: 'fee', type: 'uint', required: true },
|
|
73
|
+
{ name: 'ttl', type: 'uint' },
|
|
74
|
+
{ name: 'certificates', type: 'array', allowEmpty: true },
|
|
75
|
+
{ name: 'withdrawals', type: 'array', allowEmpty: true },
|
|
76
|
+
{ name: 'mint', type: 'array', allowEmpty: true },
|
|
77
|
+
{ name: 'validityIntervalStart', type: 'uint' },
|
|
78
|
+
{ name: 'scriptDataHash', type: 'string' },
|
|
79
|
+
{ name: 'collateralInputs', type: 'array', allowEmpty: true },
|
|
80
|
+
{ name: 'requiredSigners', type: 'array', allowEmpty: true },
|
|
81
|
+
{ name: 'totalCollateral', type: 'uint' },
|
|
82
|
+
{ name: 'referenceInputs', type: 'array', allowEmpty: true },
|
|
83
|
+
{ name: 'protocolMagic', type: 'number', required: true },
|
|
84
|
+
{ name: 'networkId', type: 'number', required: true },
|
|
85
|
+
{ name: 'additionalWitnessRequests', type: 'array', allowEmpty: true },
|
|
86
|
+
{ name: 'derivationType', type: 'number' },
|
|
87
|
+
{ name: 'includeNetworkId', type: 'boolean' },
|
|
88
|
+
{ name: 'chunkify', type: 'boolean' },
|
|
89
|
+
{ name: 'tagCborSets', type: 'boolean' },
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
const inputsWithPath = payload.inputs.map(transformInput);
|
|
93
|
+
const outputsWithData = payload.outputs.map(transformOutput);
|
|
94
|
+
|
|
95
|
+
let certificatesWithPoolOwnersAndRelays: CertificateWithPoolOwnersAndRelays[] = [];
|
|
96
|
+
if (payload.certificates) {
|
|
97
|
+
certificatesWithPoolOwnersAndRelays = payload.certificates.map(transformCertificate);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let withdrawals: PROTO.CardanoTxWithdrawal[] = [];
|
|
101
|
+
if (payload.withdrawals) {
|
|
102
|
+
withdrawals = payload.withdrawals.map((withdrawal: any) => {
|
|
103
|
+
validateParams(withdrawal, [
|
|
104
|
+
{ name: 'amount', type: 'uint', required: true },
|
|
105
|
+
{ name: 'scriptHash', type: 'string' },
|
|
106
|
+
{ name: 'keyHash', type: 'string' },
|
|
107
|
+
]);
|
|
108
|
+
return {
|
|
109
|
+
path: withdrawal.path ? validatePath(withdrawal.path, 5) : undefined,
|
|
110
|
+
amount: withdrawal.amount,
|
|
111
|
+
script_hash: withdrawal.scriptHash,
|
|
112
|
+
key_hash: withdrawal.keyHash,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let mint: AssetGroupWithTokens[] = [];
|
|
118
|
+
if (payload.mint) {
|
|
119
|
+
mint = tokenBundleToProto(payload.mint);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let auxiliaryData;
|
|
123
|
+
if (payload.auxiliaryData) {
|
|
124
|
+
auxiliaryData = transformAuxiliaryData(payload.auxiliaryData);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let additionalWitnessRequests: Path[] = [];
|
|
128
|
+
if (payload.additionalWitnessRequests) {
|
|
129
|
+
additionalWitnessRequests = payload.additionalWitnessRequests.map((witnessRequest: any) =>
|
|
130
|
+
validatePath(witnessRequest, 3)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let collateralInputsWithPath: CollateralInputWithPath[] = [];
|
|
135
|
+
if (payload.collateralInputs) {
|
|
136
|
+
collateralInputsWithPath = payload.collateralInputs.map(transformCollateralInput);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let requiredSigners: PROTO.CardanoTxRequiredSigner[] = [];
|
|
140
|
+
if (payload.requiredSigners) {
|
|
141
|
+
requiredSigners = payload.requiredSigners.map((requiredSigner: any) => {
|
|
142
|
+
validateParams(requiredSigner, [{ name: 'keyHash', type: 'string' }]);
|
|
143
|
+
return {
|
|
144
|
+
key_path: requiredSigner.keyPath ? validatePath(requiredSigner.keyPath, 3) : undefined,
|
|
145
|
+
key_hash: requiredSigner.keyHash,
|
|
146
|
+
} as PROTO.CardanoTxRequiredSigner;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const collateralReturnWithData = payload.collateralReturn
|
|
151
|
+
? transformOutput(payload.collateralReturn)
|
|
152
|
+
: undefined;
|
|
153
|
+
|
|
154
|
+
let referenceInputs: PROTO.CardanoTxReferenceInput[] = [];
|
|
155
|
+
if (payload.referenceInputs) {
|
|
156
|
+
referenceInputs = payload.referenceInputs.map(transformReferenceInput);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.params = {
|
|
160
|
+
signingMode: payload.signingMode,
|
|
161
|
+
inputsWithPath,
|
|
162
|
+
outputsWithData,
|
|
163
|
+
fee: payload.fee,
|
|
164
|
+
ttl: payload.ttl,
|
|
165
|
+
certificatesWithPoolOwnersAndRelays,
|
|
166
|
+
withdrawals,
|
|
167
|
+
mint,
|
|
168
|
+
auxiliaryData,
|
|
169
|
+
validityIntervalStart: payload.validityIntervalStart,
|
|
170
|
+
scriptDataHash: payload.scriptDataHash,
|
|
171
|
+
collateralInputsWithPath,
|
|
172
|
+
requiredSigners,
|
|
173
|
+
collateralReturnWithData,
|
|
174
|
+
totalCollateral: payload.totalCollateral,
|
|
175
|
+
referenceInputs,
|
|
176
|
+
protocolMagic: payload.protocolMagic,
|
|
177
|
+
networkId: payload.networkId,
|
|
178
|
+
witnessPaths: gatherWitnessPaths(
|
|
179
|
+
inputsWithPath,
|
|
180
|
+
certificatesWithPoolOwnersAndRelays,
|
|
181
|
+
withdrawals,
|
|
182
|
+
collateralInputsWithPath,
|
|
183
|
+
requiredSigners,
|
|
184
|
+
additionalWitnessRequests,
|
|
185
|
+
payload.signingMode
|
|
186
|
+
),
|
|
187
|
+
additionalWitnessRequests,
|
|
188
|
+
derivationType:
|
|
189
|
+
typeof payload.derivationType !== 'undefined'
|
|
190
|
+
? payload.derivationType
|
|
191
|
+
: PROTO.CardanoDerivationType.ICARUS,
|
|
192
|
+
includeNetworkId: payload.includeNetworkId,
|
|
193
|
+
chunkify: payload.chunkify,
|
|
194
|
+
tagCborSets: payload.tagCborSets,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
hasConway = () => {
|
|
199
|
+
const payload = this.payload as CardanoSignTransactionType;
|
|
200
|
+
if (payload.tagCborSets === true) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
if (payload.auxiliaryData?.cVoteRegistrationParameters != null) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
for (const certificate of payload.certificates ?? []) {
|
|
207
|
+
if (certificate.dRep != null) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
if (certificate.deposit != null) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
if (
|
|
214
|
+
certificate.type === PROTO.CardanoCertificateType.STAKE_REGISTRATION_CONWAY ||
|
|
215
|
+
certificate.type === PROTO.CardanoCertificateType.STAKE_DEREGISTRATION_CONWAY ||
|
|
216
|
+
certificate.type === PROTO.CardanoCertificateType.VOTE_DELEGATION
|
|
217
|
+
) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return false;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
supportConwayVersionRange = (): DeviceFirmwareRange => ({
|
|
226
|
+
pro: {
|
|
227
|
+
min: '4.12.0',
|
|
228
|
+
},
|
|
229
|
+
touch: {
|
|
230
|
+
min: '4.10.0',
|
|
231
|
+
},
|
|
232
|
+
classic: {
|
|
233
|
+
min: '3.10.0',
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
checkSupportConway = () => {
|
|
238
|
+
if (!this.hasConway()) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const firmwareVersion = getDeviceFirmwareVersion(this.device.features)?.join('.');
|
|
243
|
+
|
|
244
|
+
const versionRange = getMethodVersionRange(
|
|
245
|
+
this.device.features,
|
|
246
|
+
type => this.supportConwayVersionRange()[type]
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
if (!versionRange) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (!semver.valid(firmwareVersion) || semver.lt(firmwareVersion, versionRange.min)) {
|
|
254
|
+
throw ERRORS.TypedError(
|
|
255
|
+
HardwareErrorCode.CallMethodNeedUpgradeFirmware,
|
|
256
|
+
`Device firmware version is too low, please update to ${versionRange.min}`,
|
|
257
|
+
{ current: firmwareVersion, require: versionRange.min }
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
async signTx(): Promise<CardanoSignedTxData> {
|
|
263
|
+
const typedCall = this.device.getCommands().typedCall.bind(this.device.getCommands());
|
|
264
|
+
|
|
265
|
+
const hasAuxiliaryData = !!this.params.auxiliaryData;
|
|
266
|
+
|
|
267
|
+
const signTxInitMessage = {
|
|
268
|
+
signing_mode: this.params.signingMode,
|
|
269
|
+
protocol_magic: this.params.protocolMagic,
|
|
270
|
+
network_id: this.params.networkId,
|
|
271
|
+
inputs_count: this.params.inputsWithPath.length,
|
|
272
|
+
outputs_count: this.params.outputsWithData.length,
|
|
273
|
+
fee: this.params.fee,
|
|
274
|
+
ttl: this.params.ttl,
|
|
275
|
+
certificates_count: this.params.certificatesWithPoolOwnersAndRelays.length,
|
|
276
|
+
withdrawals_count: this.params.withdrawals.length,
|
|
277
|
+
has_auxiliary_data: hasAuxiliaryData,
|
|
278
|
+
validity_interval_start: this.params.validityIntervalStart,
|
|
279
|
+
witness_requests_count: this.params.witnessPaths.length,
|
|
280
|
+
minting_asset_groups_count: this.params.mint.length,
|
|
281
|
+
script_data_hash: this.params.scriptDataHash,
|
|
282
|
+
collateral_inputs_count: this.params.collateralInputsWithPath.length,
|
|
283
|
+
required_signers_count: this.params.requiredSigners.length,
|
|
284
|
+
has_collateral_return: this.params.collateralReturnWithData != null,
|
|
285
|
+
total_collateral: this.params.totalCollateral,
|
|
286
|
+
reference_inputs_count: this.params.referenceInputs.length,
|
|
287
|
+
derivation_type: this.params.derivationType,
|
|
288
|
+
include_network_id: this.params.includeNetworkId,
|
|
289
|
+
chunkify: this.params.chunkify,
|
|
290
|
+
tag_cbor_sets: this.params.tagCborSets,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// init
|
|
294
|
+
await typedCall('CardanoSignTxInit', 'CardanoTxItemAck', signTxInitMessage);
|
|
295
|
+
// inputs
|
|
296
|
+
for (const { input } of this.params.inputsWithPath) {
|
|
297
|
+
await typedCall('CardanoTxInput', 'CardanoTxItemAck', input);
|
|
298
|
+
}
|
|
299
|
+
// outputs and tokens
|
|
300
|
+
for (const outputWithData of this.params.outputsWithData) {
|
|
301
|
+
await sendOutput(typedCall, outputWithData);
|
|
302
|
+
}
|
|
303
|
+
// certificates, owners and relays
|
|
304
|
+
for (const { certificate, poolOwners, poolRelays } of this.params
|
|
305
|
+
.certificatesWithPoolOwnersAndRelays) {
|
|
306
|
+
await typedCall('CardanoTxCertificate', 'CardanoTxItemAck', certificate);
|
|
307
|
+
for (const poolOwner of poolOwners) {
|
|
308
|
+
await typedCall('CardanoPoolOwner', 'CardanoTxItemAck', poolOwner);
|
|
309
|
+
}
|
|
310
|
+
for (const poolRelay of poolRelays) {
|
|
311
|
+
await typedCall('CardanoPoolRelayParameters', 'CardanoTxItemAck', poolRelay);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
// withdrawals
|
|
315
|
+
for (const withdrawal of this.params.withdrawals) {
|
|
316
|
+
await typedCall('CardanoTxWithdrawal', 'CardanoTxItemAck', withdrawal);
|
|
317
|
+
}
|
|
318
|
+
// auxiliary data
|
|
319
|
+
let auxiliaryDataSupplement: CardanoAuxiliaryDataSupplement | undefined;
|
|
320
|
+
if (this.params.auxiliaryData) {
|
|
321
|
+
const { catalyst_registration_parameters } = this.params.auxiliaryData;
|
|
322
|
+
if (catalyst_registration_parameters) {
|
|
323
|
+
this.params.auxiliaryData = modifyAuxiliaryDataForBackwardsCompatibility(
|
|
324
|
+
this.params.auxiliaryData
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const { message } = await typedCall(
|
|
329
|
+
'CardanoTxAuxiliaryData',
|
|
330
|
+
'CardanoTxAuxiliaryDataSupplement',
|
|
331
|
+
this.params.auxiliaryData
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const auxiliaryDataType: any = PROTO.CardanoTxAuxiliaryDataSupplementType[message.type];
|
|
335
|
+
if (auxiliaryDataType !== PROTO.CardanoTxAuxiliaryDataSupplementType.NONE) {
|
|
336
|
+
auxiliaryDataSupplement = {
|
|
337
|
+
type: auxiliaryDataType,
|
|
338
|
+
auxiliaryDataHash: message.auxiliary_data_hash as unknown as string,
|
|
339
|
+
cVoteRegistrationSignature: message.cvote_registration_signature,
|
|
340
|
+
// @ts-expect-error
|
|
341
|
+
catalystSignature: message.cvote_registration_signature,
|
|
342
|
+
governanceSignature: message.cvote_registration_signature,
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
await typedCall('CardanoTxHostAck', 'CardanoTxItemAck');
|
|
346
|
+
}
|
|
347
|
+
// mint
|
|
348
|
+
if (this.params.mint.length > 0) {
|
|
349
|
+
await typedCall('CardanoTxMint', 'CardanoTxItemAck', {
|
|
350
|
+
asset_groups_count: this.params.mint.length,
|
|
351
|
+
});
|
|
352
|
+
for (const assetGroup of this.params.mint) {
|
|
353
|
+
await typedCall('CardanoAssetGroup', 'CardanoTxItemAck', {
|
|
354
|
+
policy_id: assetGroup.policyId,
|
|
355
|
+
tokens_count: assetGroup.tokens.length,
|
|
356
|
+
});
|
|
357
|
+
for (const token of assetGroup.tokens) {
|
|
358
|
+
await typedCall('CardanoToken', 'CardanoTxItemAck', token);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// collateral inputs
|
|
363
|
+
for (const { collateralInput } of this.params.collateralInputsWithPath) {
|
|
364
|
+
await typedCall('CardanoTxCollateralInput', 'CardanoTxItemAck', collateralInput);
|
|
365
|
+
}
|
|
366
|
+
// required signers
|
|
367
|
+
for (const requiredSigner of this.params.requiredSigners) {
|
|
368
|
+
await typedCall('CardanoTxRequiredSigner', 'CardanoTxItemAck', requiredSigner);
|
|
369
|
+
}
|
|
370
|
+
// collateral return
|
|
371
|
+
if (this.params.collateralReturnWithData) {
|
|
372
|
+
await sendOutput(typedCall, this.params.collateralReturnWithData);
|
|
373
|
+
}
|
|
374
|
+
// reference inputs
|
|
375
|
+
for (const referenceInput of this.params.referenceInputs) {
|
|
376
|
+
await typedCall('CardanoTxReferenceInput', 'CardanoTxItemAck', referenceInput);
|
|
377
|
+
}
|
|
378
|
+
// witnesses
|
|
379
|
+
const witnesses: CardanoSignedTxWitness[] = [];
|
|
380
|
+
for (const path of this.params.witnessPaths) {
|
|
381
|
+
const { message } = await typedCall('CardanoTxWitnessRequest', 'CardanoTxWitnessResponse', {
|
|
382
|
+
path,
|
|
383
|
+
});
|
|
384
|
+
witnesses.push({
|
|
385
|
+
type: PROTO.CardanoTxWitnessType[message.type] as any,
|
|
386
|
+
pubKey: message.pub_key,
|
|
387
|
+
signature: message.signature,
|
|
388
|
+
chainCode: message.chain_code,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
// tx hash
|
|
392
|
+
const { message: txBodyHashMessage } = await typedCall('CardanoTxHostAck', 'CardanoTxBodyHash');
|
|
393
|
+
// finish
|
|
394
|
+
await typedCall('CardanoTxHostAck', 'CardanoSignTxFinished');
|
|
395
|
+
|
|
396
|
+
return { hash: txBodyHashMessage.tx_hash, witnesses, auxiliaryDataSupplement };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
run() {
|
|
400
|
+
this.checkSupportConway();
|
|
401
|
+
|
|
402
|
+
return this.signTx();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import { validatePath } from '../../helpers/pathUtils';
|
|
4
|
+
import { validateParams } from '../../helpers/paramsValidator';
|
|
5
|
+
import { PROTO } from '../../../constants';
|
|
6
|
+
|
|
7
|
+
import type { CardanoAddressParameters } from '../../../types/api/cardano';
|
|
8
|
+
|
|
9
|
+
export const validateAddressParameters = (addressParameters: CardanoAddressParameters) => {
|
|
10
|
+
validateParams(addressParameters, [
|
|
11
|
+
{ name: 'addressType', type: 'number', required: true },
|
|
12
|
+
{ name: 'stakingKeyHash', type: 'string' },
|
|
13
|
+
{ name: 'paymentScriptHash', type: 'string' },
|
|
14
|
+
{ name: 'stakingScriptHash', type: 'string' },
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
if (addressParameters.path) {
|
|
18
|
+
validatePath(addressParameters.path);
|
|
19
|
+
}
|
|
20
|
+
if (addressParameters.stakingPath) {
|
|
21
|
+
validatePath(addressParameters.stakingPath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (addressParameters.certificatePointer) {
|
|
25
|
+
validateParams(addressParameters.certificatePointer, [
|
|
26
|
+
{ name: 'blockIndex', type: 'number', required: true },
|
|
27
|
+
{ name: 'txIndex', type: 'number', required: true },
|
|
28
|
+
{ name: 'certificateIndex', type: 'number', required: true },
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const addressParametersToProto = (
|
|
34
|
+
addressParameters: CardanoAddressParameters
|
|
35
|
+
): PROTO.CardanoAddressParametersType => {
|
|
36
|
+
let path: number[] = [];
|
|
37
|
+
if (addressParameters.path) {
|
|
38
|
+
path = validatePath(addressParameters.path, 3);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let stakingPath: number[] = [];
|
|
42
|
+
if (addressParameters.stakingPath) {
|
|
43
|
+
stakingPath = validatePath(addressParameters.stakingPath, 3);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let certificatePointer;
|
|
47
|
+
if (addressParameters.certificatePointer) {
|
|
48
|
+
certificatePointer = {
|
|
49
|
+
block_index: addressParameters.certificatePointer.blockIndex,
|
|
50
|
+
tx_index: addressParameters.certificatePointer.txIndex,
|
|
51
|
+
certificate_index: addressParameters.certificatePointer.certificateIndex,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
address_type: addressParameters.addressType,
|
|
57
|
+
address_n: path,
|
|
58
|
+
address_n_staking: stakingPath,
|
|
59
|
+
staking_key_hash: addressParameters.stakingKeyHash,
|
|
60
|
+
certificate_pointer: certificatePointer,
|
|
61
|
+
script_payment_hash: addressParameters.paymentScriptHash,
|
|
62
|
+
script_staking_hash: addressParameters.stakingScriptHash,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const addressParametersFromProto = (
|
|
67
|
+
addressParameters: PROTO.CardanoAddressParametersType
|
|
68
|
+
): CardanoAddressParameters => {
|
|
69
|
+
let certificatePointer;
|
|
70
|
+
if (addressParameters.certificate_pointer) {
|
|
71
|
+
certificatePointer = {
|
|
72
|
+
blockIndex: addressParameters.certificate_pointer.block_index,
|
|
73
|
+
txIndex: addressParameters.certificate_pointer.tx_index,
|
|
74
|
+
certificateIndex: addressParameters.certificate_pointer.certificate_index,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
addressType: addressParameters.address_type,
|
|
80
|
+
path: addressParameters.address_n,
|
|
81
|
+
stakingPath: addressParameters.address_n_staking,
|
|
82
|
+
stakingKeyHash: addressParameters.staking_key_hash,
|
|
83
|
+
certificatePointer,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const modifyAddressParametersForBackwardsCompatibility = (
|
|
88
|
+
address_parameters: PROTO.CardanoAddressParametersType
|
|
89
|
+
): PROTO.CardanoAddressParametersType => {
|
|
90
|
+
if (address_parameters.address_type === PROTO.CardanoAddressType.REWARD) {
|
|
91
|
+
// older firmware expects reward address path in path field instead of staking path
|
|
92
|
+
let { address_n, address_n_staking } = address_parameters;
|
|
93
|
+
|
|
94
|
+
if (address_n.length > 0 && address_n_staking.length > 0) {
|
|
95
|
+
throw ERRORS.TypedError(
|
|
96
|
+
HardwareErrorCode.CallMethodInvalidParameter,
|
|
97
|
+
`Only stakingPath is allowed for CardanoAddressType.REWARD`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (address_n.length > 0) {
|
|
102
|
+
address_n_staking = address_n;
|
|
103
|
+
address_n = [];
|
|
104
|
+
}
|
|
105
|
+
// TODO: version check
|
|
106
|
+
// if (device.atLeast(['0', '2.4.3'])) {
|
|
107
|
+
// } else if (address_n_staking.length > 0) {
|
|
108
|
+
// address_n = address_n_staking;
|
|
109
|
+
// address_n_staking = [];
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
...address_parameters,
|
|
114
|
+
address_n,
|
|
115
|
+
address_n_staking,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return address_parameters;
|
|
120
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ERRORS, HardwareErrorCode } from '@onetokenfe/hd-shared';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
addressParametersToProto,
|
|
5
|
+
modifyAddressParametersForBackwardsCompatibility,
|
|
6
|
+
validateAddressParameters,
|
|
7
|
+
} from './addressParameters';
|
|
8
|
+
import { validateParams } from '../../helpers/paramsValidator';
|
|
9
|
+
import { validatePath } from '../../helpers/pathUtils';
|
|
10
|
+
|
|
11
|
+
import type { PROTO } from '../../../constants';
|
|
12
|
+
import type {
|
|
13
|
+
CardanoAuxiliaryData,
|
|
14
|
+
CardanoCVoteRegistrationDelegation,
|
|
15
|
+
CardanoCVoteRegistrationParameters,
|
|
16
|
+
} from '../../../types/api/cardano';
|
|
17
|
+
|
|
18
|
+
const MAX_DELEGATION_COUNT = 32;
|
|
19
|
+
|
|
20
|
+
const transformDelegation = (
|
|
21
|
+
delegation: CardanoCVoteRegistrationDelegation
|
|
22
|
+
): PROTO.CardanoCVoteRegistrationDelegation => {
|
|
23
|
+
// @ts-expect-error votingPublicKey is a legacy param kept for backward compatibility (for now)
|
|
24
|
+
if (delegation.votingPublicKey) {
|
|
25
|
+
console.warn('Please use votePublicKey instead of votingPublicKey.');
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
delegation.votePublicKey = delegation.votingPublicKey;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
validateParams(delegation, [
|
|
31
|
+
{ name: 'votingPublicKey', type: 'string', required: true },
|
|
32
|
+
{ name: 'weight', type: 'uint', required: true },
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
vote_public_key: delegation.votePublicKey,
|
|
37
|
+
weight: delegation.weight,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const transformCvoteRegistrationParameters = (
|
|
42
|
+
cVoteRegistrationParameters: CardanoCVoteRegistrationParameters
|
|
43
|
+
): PROTO.CardanoCVoteRegistrationParametersType => {
|
|
44
|
+
// votingPublicKey and rewardAddressParameters are legacy params kept for backward compatibility (for now)
|
|
45
|
+
// @ts-expect-error
|
|
46
|
+
if (cVoteRegistrationParameters.votingPublicKey) {
|
|
47
|
+
console.warn('Please use votePublicKey instead of votingPublicKey.');
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
cVoteRegistrationParameters.votePublicKey = cVoteRegistrationParameters.votingPublicKey;
|
|
50
|
+
}
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
if (cVoteRegistrationParameters.rewardAddressParameters) {
|
|
53
|
+
console.warn('Please use paymentAddressParameters instead of rewardAddressParameters.');
|
|
54
|
+
cVoteRegistrationParameters.paymentAddressParameters =
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
cVoteRegistrationParameters.rewardAddressParameters;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
validateParams(cVoteRegistrationParameters, [
|
|
60
|
+
{ name: 'votePublicKey', type: 'string' },
|
|
61
|
+
{ name: 'stakingPath', required: true },
|
|
62
|
+
{ name: 'nonce', type: 'uint', required: true },
|
|
63
|
+
{ name: 'format', type: 'number' },
|
|
64
|
+
{ name: 'delegations', type: 'array', allowEmpty: true },
|
|
65
|
+
{ name: 'votingPurpose', type: 'uint' },
|
|
66
|
+
{ name: 'paymentAddress', type: 'string' },
|
|
67
|
+
]);
|
|
68
|
+
const { paymentAddressParameters } = cVoteRegistrationParameters;
|
|
69
|
+
validateAddressParameters(paymentAddressParameters);
|
|
70
|
+
|
|
71
|
+
const { delegations } = cVoteRegistrationParameters;
|
|
72
|
+
if (delegations && delegations.length > MAX_DELEGATION_COUNT) {
|
|
73
|
+
throw ERRORS.TypedError(
|
|
74
|
+
HardwareErrorCode.CallMethodInvalidParameter,
|
|
75
|
+
`At most ${MAX_DELEGATION_COUNT} delegations are allowed in a governance registration`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
vote_public_key: cVoteRegistrationParameters.votePublicKey,
|
|
81
|
+
staking_path: validatePath(cVoteRegistrationParameters.stakingPath, 3),
|
|
82
|
+
payment_address_parameters: paymentAddressParameters
|
|
83
|
+
? addressParametersToProto(paymentAddressParameters)
|
|
84
|
+
: undefined,
|
|
85
|
+
nonce: cVoteRegistrationParameters.nonce as unknown as number,
|
|
86
|
+
format: cVoteRegistrationParameters.format,
|
|
87
|
+
delegations: delegations?.map(transformDelegation) ?? [],
|
|
88
|
+
voting_purpose: cVoteRegistrationParameters.votingPurpose,
|
|
89
|
+
payment_address: cVoteRegistrationParameters.paymentAddress,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const transformAuxiliaryData = (
|
|
94
|
+
auxiliaryData: CardanoAuxiliaryData
|
|
95
|
+
): PROTO.CardanoTxAuxiliaryData => {
|
|
96
|
+
validateParams(auxiliaryData, [
|
|
97
|
+
{
|
|
98
|
+
name: 'hash',
|
|
99
|
+
type: 'string',
|
|
100
|
+
},
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
let cVoteRegistrationParameters;
|
|
104
|
+
if (auxiliaryData.cVoteRegistrationParameters) {
|
|
105
|
+
cVoteRegistrationParameters = transformCvoteRegistrationParameters(
|
|
106
|
+
auxiliaryData.cVoteRegistrationParameters
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
hash: auxiliaryData.hash,
|
|
112
|
+
cvote_registration_parameters: cVoteRegistrationParameters,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const modifyAuxiliaryDataForBackwardsCompatibility = (
|
|
117
|
+
auxiliary_data: PROTO.CardanoTxAuxiliaryData
|
|
118
|
+
): PROTO.CardanoTxAuxiliaryData => {
|
|
119
|
+
const { cvote_registration_parameters } = auxiliary_data;
|
|
120
|
+
if (cvote_registration_parameters?.payment_address_parameters) {
|
|
121
|
+
cvote_registration_parameters.payment_address_parameters =
|
|
122
|
+
modifyAddressParametersForBackwardsCompatibility(
|
|
123
|
+
cvote_registration_parameters.payment_address_parameters
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
...auxiliary_data,
|
|
128
|
+
cvote_registration_parameters,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return auxiliary_data;
|
|
133
|
+
};
|