From 789e9fdcc4b8ba6199c1100a88d90d49cb56c7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Mon, 30 Oct 2023 18:01:03 +0100 Subject: [PATCH] drep verification key: extended->non extended: specify description --- .../Cardano/CLI/EraBased/Run/Governance.hs | 5 ++--- .../src/Cardano/CLI/EraBased/Run/Key.hs | 20 ++++++++++++------- .../non-extended-keys/non-extended-drep.vkey | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs index 78bc8d45ab..a0306836a9 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs @@ -16,6 +16,7 @@ import Cardano.Api import qualified Cardano.Api.Ledger as Ledger import Cardano.Api.Shelley +import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.GovernanceCmdError import qualified Cardano.Ledger.Shelley.TxBody as Shelley @@ -90,10 +91,8 @@ runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFi skey <- liftIO $ generateSigningKey AsDRepKey let vkey = getVerificationKey skey newExceptT $ writeLazyByteStringFile skeyPath (textEnvelopeToJSON (Just skeyDesc) skey) - newExceptT $ writeLazyByteStringFile vkeyPath (textEnvelopeToJSON (Just vkeyDesc) vkey) + newExceptT $ writeLazyByteStringFile vkeyPath (textEnvelopeToJSON (Just Key.drepKeyEnvelopeDescr) vkey) where skeyDesc :: TextEnvelopeDescr skeyDesc = "Delegate Representative Signing Key" - vkeyDesc :: TextEnvelopeDescr - vkeyDesc = "Delegate Representative Verification Key" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs index 8117df8221..f9c77ae11b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs @@ -18,6 +18,8 @@ module Cardano.CLI.EraBased.Run.Key , runNonExtendedKeyCmd , runVerificationKeyCmd + , drepKeyEnvelopeDescr + -- * Exports for testing , decodeBech32 ) where @@ -54,6 +56,9 @@ import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import System.Exit (exitFailure) +drepKeyEnvelopeDescr :: TextEnvelopeDescr +drepKeyEnvelopeDescr = "Delegate Representative Verification Key" + runKeyCmds :: () => Cmd.KeyCmds era -> ExceptT KeyCmdError IO () @@ -110,26 +115,27 @@ runNonExtendedKeyCmd writeVerificationKey ssk = case ssk of APaymentExtendedVerificationKey vk -> - writeToDisk vkf (castVerificationKey vk :: VerificationKey PaymentKey) + writeToDisk vkf Nothing (castVerificationKey vk :: VerificationKey PaymentKey) ADRepExtendedVerificationKey vk -> - writeToDisk vkf (castVerificationKey vk :: VerificationKey DRepKey) + writeToDisk vkf (Just drepKeyEnvelopeDescr) (castVerificationKey vk :: VerificationKey DRepKey) AStakeExtendedVerificationKey vk -> - writeToDisk vkf (castVerificationKey vk :: VerificationKey StakeKey) + writeToDisk vkf Nothing (castVerificationKey vk :: VerificationKey StakeKey) AGenesisExtendedVerificationKey vk -> - writeToDisk vkf (castVerificationKey vk :: VerificationKey GenesisKey) + writeToDisk vkf Nothing (castVerificationKey vk :: VerificationKey GenesisKey) AGenesisDelegateExtendedVerificationKey vk -> - writeToDisk vkf (castVerificationKey vk :: VerificationKey GenesisDelegateKey) + writeToDisk vkf Nothing (castVerificationKey vk :: VerificationKey GenesisDelegateKey) nonExtendedKey -> left $ KeyCmdExpectedExtendedVerificationKey nonExtendedKey writeToDisk :: Key keyrole => File content Out + -> Maybe TextEnvelopeDescr -> VerificationKey keyrole -> ExceptT KeyCmdError IO () - writeToDisk vkf' vk = + writeToDisk vkf' descr vk = firstExceptT KeyCmdWriteFileError . newExceptT - $ writeLazyByteStringFile vkf' $ textEnvelopeToJSON Nothing vk + $ writeLazyByteStringFile vkf' $ textEnvelopeToJSON descr vk readExtendedVerificationKeyFile diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey b/cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey index a839fc1f70..e47dbe6dd5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey +++ b/cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey @@ -1,5 +1,5 @@ { "type": "DRepVerificationKey_ed25519", - "description": "", + "description": "Delegate Representative Verification Key", "cborHex": "5820b0cd9e6e3e274f4f38f55ef274af123cf4600ac0c58294399b7e076175262553" }