From e0c630283a5c84d065c024cbe011ea69dcb5c55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 17 Oct 2023 08:26:45 +0200 Subject: [PATCH 1/3] key non-extended-key: support drep extended keys --- cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs index 3ef15246a3..8117df8221 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs @@ -111,6 +111,8 @@ runNonExtendedKeyCmd case ssk of APaymentExtendedVerificationKey vk -> writeToDisk vkf (castVerificationKey vk :: VerificationKey PaymentKey) + ADRepExtendedVerificationKey vk -> + writeToDisk vkf (castVerificationKey vk :: VerificationKey DRepKey) AStakeExtendedVerificationKey vk -> writeToDisk vkf (castVerificationKey vk :: VerificationKey StakeKey) AGenesisExtendedVerificationKey vk -> @@ -139,6 +141,7 @@ readExtendedVerificationKeyFile evkfile = do $ VktofVerificationKeyFile evkfile case vKey of k@APaymentExtendedVerificationKey{} -> return k + k@ADRepExtendedVerificationKey{} -> return k k@AStakeExtendedVerificationKey{} -> return k k@AGenesisExtendedVerificationKey{} -> return k k@AGenesisDelegateExtendedVerificationKey{} -> return k From eab272fee8a9f8284091ac7dddb1214eae338133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 17 Oct 2023 14:58:18 +0200 Subject: [PATCH 2/3] Add golden test --- .../Test/Golden/Key/NonExtendedKey.hs | 22 +++++++++++++++++++ .../non-extended-keys/non-extended-drep.vkey | 5 +++++ .../key/non-extended-keys/extended-drep.vkey | 5 +++++ 3 files changed, 32 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey create mode 100644 cardano-cli/test/cardano-cli-golden/files/input/key/non-extended-keys/extended-drep.vkey diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Key/NonExtendedKey.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Key/NonExtendedKey.hs index 05b30767f8..12609f7ad0 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Key/NonExtendedKey.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Key/NonExtendedKey.hs @@ -60,3 +60,25 @@ hprop_golden_KeyNonExtendedKey_StakeExtendedVerificationKeyShelley = H.assertFilesExist [outFp] H.diffFileVsGoldenFile outFp nonExtendedFp + +-- | Test that converting a drep extended verification key yields the +-- expected result. +hprop_golden_KeyNonExtendedKey_DRepExtendedVerificationKey :: Property +hprop_golden_KeyNonExtendedKey_DRepExtendedVerificationKey = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + extendedKeyFile <- H.noteInputFile "test/cardano-cli-golden/files/input/key/non-extended-keys/extended-drep.vkey" + goldenFile <- H.note "test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey" + outFp <- H.note $ tempDir "non-extended-drep.vkey" + + H.assertFilesExist [extendedKeyFile] + + void $ execCardanoCLI + [ "conway", "key", "non-extended-key" + , "--extended-verification-key-file", extendedKeyFile + , "--verification-key-file", outFp + ] + + -- Check for existence of the converted signing key file + H.assertFilesExist [outFp] + + H.diffFileVsGoldenFile outFp goldenFile 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 new file mode 100644 index 0000000000..a839fc1f70 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/key/non-extended-keys/non-extended-drep.vkey @@ -0,0 +1,5 @@ +{ + "type": "DRepVerificationKey_ed25519", + "description": "", + "cborHex": "5820b0cd9e6e3e274f4f38f55ef274af123cf4600ac0c58294399b7e076175262553" +} diff --git a/cardano-cli/test/cardano-cli-golden/files/input/key/non-extended-keys/extended-drep.vkey b/cardano-cli/test/cardano-cli-golden/files/input/key/non-extended-keys/extended-drep.vkey new file mode 100644 index 0000000000..a2c4d4327b --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/input/key/non-extended-keys/extended-drep.vkey @@ -0,0 +1,5 @@ +{ + "type": "DRepExtendedVerificationKey_ed25519_bip32", + "description": "Delegate Representative Verification Key", + "cborHex": "5840b0cd9e6e3e274f4f38f55ef274af123cf4600ac0c58294399b7e076175262553dde8b75f847f2b7e61a8748627292a06d739c8ba8e78ac83e666030d1093fb3e" +} 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 3/3] 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" }