diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 1e6bd31539..532d5fbf12 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -62,6 +62,7 @@ library Cardano.CLI.Commands.Debug.LogEpochState Cardano.CLI.Commands.Debug.TransactionView Cardano.CLI.Commands.Hash + Cardano.CLI.Commands.Key Cardano.CLI.Commands.Node Cardano.CLI.Commands.Ping Cardano.CLI.Environment @@ -74,7 +75,6 @@ library Cardano.CLI.EraBased.Commands.Governance.DRep Cardano.CLI.EraBased.Commands.Governance.Poll Cardano.CLI.EraBased.Commands.Governance.Vote - Cardano.CLI.EraBased.Commands.Key Cardano.CLI.EraBased.Commands.Query Cardano.CLI.EraBased.Commands.StakeAddress Cardano.CLI.EraBased.Commands.StakePool @@ -89,7 +89,6 @@ library Cardano.CLI.EraBased.Options.Governance.DRep Cardano.CLI.EraBased.Options.Governance.Poll Cardano.CLI.EraBased.Options.Governance.Vote - Cardano.CLI.EraBased.Options.Key Cardano.CLI.EraBased.Options.Query Cardano.CLI.EraBased.Options.StakeAddress Cardano.CLI.EraBased.Options.StakePool @@ -108,7 +107,6 @@ library Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate Cardano.CLI.EraBased.Run.Governance.Poll Cardano.CLI.EraBased.Run.Governance.Vote - Cardano.CLI.EraBased.Run.Key Cardano.CLI.EraBased.Run.Query Cardano.CLI.EraBased.Run.StakeAddress Cardano.CLI.EraBased.Run.StakePool @@ -129,6 +127,7 @@ library Cardano.CLI.Options Cardano.CLI.Options.Debug Cardano.CLI.Options.Hash + Cardano.CLI.Options.Key Cardano.CLI.Options.Node Cardano.CLI.Options.Ping Cardano.CLI.Orphans @@ -141,6 +140,7 @@ library Cardano.CLI.Run.Debug.LogEpochState Cardano.CLI.Run.Debug.TransactionView Cardano.CLI.Run.Hash + Cardano.CLI.Run.Key Cardano.CLI.Run.Node Cardano.CLI.Run.Ping Cardano.CLI.TopHandler diff --git a/cardano-cli/src/Cardano/CLI/Commands.hs b/cardano-cli/src/Cardano/CLI/Commands.hs index 20c4f4b9cd..eda4ed836c 100644 --- a/cardano-cli/src/Cardano/CLI/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/Commands.hs @@ -8,6 +8,7 @@ where import Cardano.CLI.Byron.Commands (ByronCommand) import Cardano.CLI.Commands.Debug import Cardano.CLI.Commands.Hash (HashCmds) +import Cardano.CLI.Commands.Key import Cardano.CLI.Commands.Node import Cardano.CLI.Commands.Ping (PingCmd (..)) import Cardano.CLI.EraBased.Commands @@ -20,8 +21,10 @@ data ClientCommand = AnyEraCommand AnyEraCommand | -- | Byron Related Commands ByronCommand ByronCommand - | -- | Era-agnostic hashing commands + | -- | Era agnostic hashing commands HashCmds HashCmds + | -- | Era agnostic key commands + KeyCommands KeyCmds | -- | Era agnostic node commands NodeCommands NodeCmds | -- | Legacy shelley-based Commands diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs similarity index 98% rename from cardano-cli/src/Cardano/CLI/EraBased/Commands/Key.hs rename to cardano-cli/src/Cardano/CLI/Commands/Key.hs index 713eb685d3..413cc24ab5 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -2,7 +2,7 @@ {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} -module Cardano.CLI.EraBased.Commands.Key +module Cardano.CLI.Commands.Key ( KeyCmds (..) , KeyVerificationKeyCmdArgs (..) , KeyNonExtendedKeyCmdArgs (..) @@ -22,7 +22,7 @@ import Cardano.CLI.Types.Common import Data.Text (Text) -data KeyCmds era +data KeyCmds = KeyVerificationKeyCmd !KeyVerificationKeyCmdArgs | KeyNonExtendedKeyCmd !KeyNonExtendedKeyCmdArgs | KeyConvertByronKeyCmd !KeyConvertByronKeyCmdArgs @@ -118,7 +118,7 @@ data KeyConvertCardanoAddressKeyCmdArgs = KeyConvertCardanoAddressKeyCmdArgs } deriving Show -renderKeyCmds :: KeyCmds era -> Text +renderKeyCmds :: KeyCmds -> Text renderKeyCmds = \case KeyVerificationKeyCmd{} -> "key verification-key" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands.hs index 58b58dd4a9..5dcbb1e078 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands.hs @@ -13,11 +13,11 @@ where import Cardano.Api (ShelleyBasedEra (..), toCardanoEra) +import Cardano.CLI.Commands.Key import Cardano.CLI.Commands.Node import Cardano.CLI.Environment import Cardano.CLI.EraBased.Commands.Address import Cardano.CLI.EraBased.Commands.Genesis -import Cardano.CLI.EraBased.Commands.Key import Cardano.CLI.EraBased.Commands.Query import Cardano.CLI.EraBased.Commands.StakeAddress import Cardano.CLI.EraBased.Commands.StakePool hiding (sbe) @@ -27,12 +27,12 @@ import Cardano.CLI.EraBased.Options.Address import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.EraBased.Options.Genesis import Cardano.CLI.EraBased.Options.Governance -import Cardano.CLI.EraBased.Options.Key import Cardano.CLI.EraBased.Options.Query import Cardano.CLI.EraBased.Options.StakeAddress import Cardano.CLI.EraBased.Options.StakePool import Cardano.CLI.EraBased.Options.TextView import Cardano.CLI.EraBased.Options.Transaction +import Cardano.CLI.Options.Key import Cardano.CLI.Options.Node import Data.Foldable @@ -51,7 +51,7 @@ renderAnyEraCommand = \case data Cmds era = AddressCmds (AddressCmds era) - | KeyCmds (KeyCmds era) + | KeyCmds KeyCmds | GenesisCmds (GenesisCmds era) | GovernanceCmds (GovernanceCmds era) | NodeCmds NodeCmds @@ -118,7 +118,7 @@ pCmds sbe' envCli = do asum $ catMaybes [ fmap AddressCmds <$> pAddressCmds cEra envCli - , fmap KeyCmds <$> pKeyCmds + , Just (KeyCmds <$> pKeyCmds) , fmap GenesisCmds <$> pGenesisCmds cEra envCli , fmap GovernanceCmds <$> pGovernanceCmds cEra , Just (NodeCmds <$> pNodeCmds) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs index bbe26a8614..ad7e9f4970 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs @@ -14,13 +14,13 @@ import Cardano.CLI.EraBased.Commands import Cardano.CLI.EraBased.Run.Address import Cardano.CLI.EraBased.Run.Genesis import Cardano.CLI.EraBased.Run.Governance -import Cardano.CLI.EraBased.Run.Key import Cardano.CLI.EraBased.Run.Query import Cardano.CLI.EraBased.Run.StakeAddress import Cardano.CLI.EraBased.Run.StakePool import Cardano.CLI.EraBased.Run.TextView import Cardano.CLI.EraBased.Run.Transaction import Cardano.CLI.Helpers (printEraDeprecationWarning) +import Cardano.CLI.Run.Key import Cardano.CLI.Run.Node import Cardano.CLI.Types.Errors.CmdError diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs index 6850d92e21..97e32bae74 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs @@ -20,8 +20,8 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Address import Cardano.CLI.EraBased.Run.Address.Info -import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.Read +import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.AddressCmdError import Cardano.CLI.Types.Key (PaymentVerifier (..), StakeIdentifier (..), diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs index f3340a0113..46c6cffd36 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/CreateTestnetData.hs @@ -39,9 +39,9 @@ import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep import Cardano.CLI.EraBased.Run.Address (generateAndWriteKeyFiles) import Cardano.CLI.EraBased.Run.Genesis.Common import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep -import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.EraBased.Run.StakeAddress (runStakeAddressKeyGenCmd) import qualified Cardano.CLI.IO.Lazy as Lazy +import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd, runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd) import Cardano.CLI.Types.Common diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index 3f862d9602..f3f2e018df 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -14,8 +14,8 @@ import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Governance.Committee import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as Cmd -import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.Read (readVerificationKeySource) +import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Types.Errors.GovernanceCommitteeError import Cardano.CLI.Types.Key.VerificationKey diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs index 84499fc860..0a055a4b30 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -20,8 +20,8 @@ import qualified Cardano.Api.Ledger as L import Cardano.CLI.EraBased.Commands.Governance.DRep (DRepHashGoal (..)) import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as Cmd -import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.Run.Hash (allSchemas, getByteStringFromURL, httpsAndIpfsSchemas) +import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.CmdError import Cardano.CLI.Types.Errors.GovernanceCmdError diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs index 40173e210e..6676dcf67a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/StakeAddress.hs @@ -25,8 +25,8 @@ import qualified Cardano.Api.Ledger as L import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.StakeAddress -import qualified Cardano.CLI.EraBased.Run.Key as Key import Cardano.CLI.Read +import qualified Cardano.CLI.Run.Key as Key import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.StakeAddressCmdError import Cardano.CLI.Types.Errors.StakeAddressRegistrationError diff --git a/cardano-cli/src/Cardano/CLI/Options.hs b/cardano-cli/src/Cardano/CLI/Options.hs index da4426017b..6b8a7f43c4 100644 --- a/cardano-cli/src/Cardano/CLI/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Options.hs @@ -16,6 +16,7 @@ import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.Legacy.Options (parseLegacyCmds) import Cardano.CLI.Options.Debug import Cardano.CLI.Options.Hash +import Cardano.CLI.Options.Key import Cardano.CLI.Options.Node import Cardano.CLI.Options.Ping (parsePingCmd) import Cardano.CLI.Render (customRenderHelp) @@ -53,13 +54,17 @@ pref = nodeCmdsTopLevel :: Parser ClientCommand nodeCmdsTopLevel = NodeCommands <$> pNodeCmds +keyCmdsTopLevel :: Parser ClientCommand +keyCmdsTopLevel = KeyCommands <$> pKeyCmds + parseClientCommand :: EnvCli -> Parser ClientCommand parseClientCommand envCli = asum -- There are name clashes between Shelley commands and the Byron backwards -- compat commands (e.g. "genesis"), and we need to prefer the Shelley ones -- so we list it first. - [ nodeCmdsTopLevel + [ keyCmdsTopLevel + , nodeCmdsTopLevel , parseLegacy envCli , parseByron envCli , parseAnyEra envCli diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs similarity index 64% rename from cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs rename to cardano-cli/src/Cardano/CLI/Options/Key.hs index 58520058db..2b93c6f7b0 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -3,14 +3,14 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE ScopedTypeVariables #-} -module Cardano.CLI.EraBased.Options.Key +module Cardano.CLI.Options.Key ( pKeyCmds ) where import Cardano.Api hiding (QueryInShelleyBasedEra (..), parseFilePath) -import Cardano.CLI.EraBased.Commands.Key +import Cardano.CLI.Commands.Key import Cardano.CLI.EraBased.Options.Common import Cardano.CLI.Types.Common @@ -22,102 +22,98 @@ import qualified Options.Applicative as Opt {- HLINT ignore "Use <$>" -} {- HLINT ignore "Move brackets to avoid $" -} -pKeyCmds :: Maybe (Parser (KeyCmds era)) +pKeyCmds :: Parser KeyCmds pKeyCmds = - subInfoParser - "key" - ( Opt.progDesc $ - mconcat - [ "Key utility commands." + let keyCmdParsers = + asum + [ subParser "verification-key" $ + Opt.info pKeyVerificationKeyCmd $ + Opt.progDesc $ + mconcat + [ "Get a verification key from a signing key. This " + , " supports all key types." + ] + , subParser "non-extended-key" $ + Opt.info pKeyNonExtendedKeyCmd $ + Opt.progDesc $ + mconcat + [ "Get a non-extended verification key from an " + , "extended verification key. This supports all " + , "extended key types." + ] + , subParser "convert-byron-key" $ + Opt.info pKeyConvertByronKeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert a Byron payment, genesis or genesis " + , "delegate key (signing or verification) to a " + , "corresponding Shelley-format key." + ] + , subParser "convert-byron-genesis-vkey" $ + Opt.info pKeyConvertByronGenesisKeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert a Base64-encoded Byron genesis " + , "verification key to a Shelley genesis " + , "verification key" + ] + , subParser "convert-itn-key" $ + Opt.info pKeyConvertITNKeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert an Incentivized Testnet (ITN) non-extended " + , "(Ed25519) signing or verification key to a " + , "corresponding Shelley stake key" + ] + , subParser "convert-itn-extended-key" $ + Opt.info pKeyConvertITNExtendedKeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert an Incentivized Testnet (ITN) extended " + , "(Ed25519Extended) signing key to a corresponding " + , "Shelley stake signing key" + ] + , subParser "convert-itn-bip32-key" $ + Opt.info pKeyConvertITNBip32KeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert an Incentivized Testnet (ITN) BIP32 " + , "(Ed25519Bip32) signing key to a corresponding " + , "Shelley stake signing key" + ] + , subParser "convert-cardano-address-key" $ + Opt.info pKeyConvertCardanoAddressKeyCmd $ + Opt.progDesc $ + mconcat + [ "Convert a cardano-address extended signing key " + , "to a corresponding Shelley-format key." + ] ] - ) - [ Just $ - subParser "verification-key" $ - Opt.info pKeyVerificationKeyCmd $ - Opt.progDesc $ - mconcat - [ "Get a verification key from a signing key. This " - , " supports all key types." - ] - , Just $ - subParser "non-extended-key" $ - Opt.info pKeyNonExtendedKeyCmd $ - Opt.progDesc $ - mconcat - [ "Get a non-extended verification key from an " - , "extended verification key. This supports all " - , "extended key types." - ] - , Just $ - subParser "convert-byron-key" $ - Opt.info pKeyConvertByronKeyCmd $ - Opt.progDesc $ - mconcat - [ "Convert a Byron payment, genesis or genesis " - , "delegate key (signing or verification) to a " - , "corresponding Shelley-format key." - ] - , Just $ - subParser "convert-byron-genesis-vkey" $ - Opt.info pKeyConvertByronGenesisKeyCmd $ - Opt.progDesc $ - mconcat - [ "Convert a Base64-encoded Byron genesis " - , "verification key to a Shelley genesis " - , "verification key" - ] - , Just $ - subParser "convert-itn-key" $ - Opt.info pKeyConvertITNKeyCmd $ - Opt.progDesc $ - mconcat - [ "Convert an Incentivized Testnet (ITN) non-extended " - , "(Ed25519) signing or verification key to a " - , "corresponding Shelley stake key" - ] - , Just $ - subParser "convert-itn-extended-key" $ - Opt.info pKeyConvertITNExtendedKeyCmd $ - Opt.progDesc $ - mconcat - [ "Convert an Incentivized Testnet (ITN) extended " - , "(Ed25519Extended) signing key to a corresponding " - , "Shelley stake signing key" - ] - , Just $ - subParser "convert-itn-bip32-key" $ - Opt.info pKeyConvertITNBip32KeyCmd $ - Opt.progDesc $ - mconcat - [ "Convert an Incentivized Testnet (ITN) BIP32 " - , "(Ed25519Bip32) signing key to a corresponding " - , "Shelley stake signing key" - ] - , Just $ - subParser "convert-cardano-address-key" $ - Opt.info pKeyConvertCardanoAddressKeyCmd $ - Opt.progDesc $ + in subParser + "key" + $ Opt.info + keyCmdParsers + ( Opt.progDesc $ mconcat - [ "Convert a cardano-address extended signing key " - , "to a corresponding Shelley-format key." + [ "Key utility commands." ] - ] + ) -pKeyVerificationKeyCmd :: Parser (KeyCmds era) +pKeyVerificationKeyCmd :: Parser KeyCmds pKeyVerificationKeyCmd = fmap KeyVerificationKeyCmd $ KeyVerificationKeyCmdArgs <$> pSigningKeyFileIn <*> pVerificationKeyFileOut -pKeyNonExtendedKeyCmd :: Parser (KeyCmds era) +pKeyNonExtendedKeyCmd :: Parser KeyCmds pKeyNonExtendedKeyCmd = fmap KeyNonExtendedKeyCmd $ KeyNonExtendedKeyCmdArgs <$> pExtendedVerificationKeyFileIn <*> pVerificationKeyFileOut -pKeyConvertByronKeyCmd :: Parser (KeyCmds era) +pKeyConvertByronKeyCmd :: Parser KeyCmds pKeyConvertByronKeyCmd = fmap KeyConvertByronKeyCmd $ KeyConvertByronKeyCmdArgs @@ -186,7 +182,7 @@ pByronVerificationKeyFile = File <$> parseFilePath "byron-verification-key-file" "Input filepath of the Byron-format verification key." -pKeyConvertByronGenesisKeyCmd :: Parser (KeyCmds era) +pKeyConvertByronGenesisKeyCmd :: Parser KeyCmds pKeyConvertByronGenesisKeyCmd = fmap KeyConvertByronGenesisVKeyCmd $ KeyConvertByronGenesisVKeyCmdArgs @@ -203,21 +199,21 @@ pByronGenesisVKeyBase64 = , Opt.help "Base64 string for the Byron genesis verification key." ] -pKeyConvertITNKeyCmd :: Parser (KeyCmds era) +pKeyConvertITNKeyCmd :: Parser KeyCmds pKeyConvertITNKeyCmd = fmap KeyConvertITNKeyCmd $ KeyConvertITNKeyCmdArgs <$> pITNKeyFIle <*> pOutputFile -pKeyConvertITNExtendedKeyCmd :: Parser (KeyCmds era) +pKeyConvertITNExtendedKeyCmd :: Parser KeyCmds pKeyConvertITNExtendedKeyCmd = fmap KeyConvertITNExtendedKeyCmd $ KeyConvertITNExtendedKeyCmdArgs <$> pITNSigningKeyFile <*> pOutputFile -pKeyConvertITNBip32KeyCmd :: Parser (KeyCmds era) +pKeyConvertITNBip32KeyCmd :: Parser KeyCmds pKeyConvertITNBip32KeyCmd = fmap KeyConvertITNBip32KeyCmd $ KeyConvertITNBip32KeyCmdArgs @@ -240,7 +236,7 @@ pITNVerificationKeyFile = AVerificationKeyFile . File <$> parseFilePath "itn-verification-key-file" "Filepath of the ITN verification key." -pKeyConvertCardanoAddressKeyCmd :: Parser (KeyCmds era) +pKeyConvertCardanoAddressKeyCmd :: Parser KeyCmds pKeyConvertCardanoAddressKeyCmd = fmap KeyConvertCardanoAddressKeyCmd $ KeyConvertCardanoAddressKeyCmdArgs diff --git a/cardano-cli/src/Cardano/CLI/Run.hs b/cardano-cli/src/Cardano/CLI/Run.hs index 8fb988925c..1e9dd469e6 100644 --- a/cardano-cli/src/Cardano/CLI/Run.hs +++ b/cardano-cli/src/Cardano/CLI/Run.hs @@ -23,11 +23,13 @@ import Cardano.CLI.Legacy.Run (runLegacyCmds) import Cardano.CLI.Render (customRenderHelp) import Cardano.CLI.Run.Debug import Cardano.CLI.Run.Hash (runHashCmds) +import Cardano.CLI.Run.Key import Cardano.CLI.Run.Node import Cardano.CLI.Run.Ping (PingClientCmdError (..), renderPingClientCmdError, runPingCmd) import Cardano.CLI.Types.Errors.CmdError import Cardano.CLI.Types.Errors.HashCmdError +import Cardano.CLI.Types.Errors.KeyCmdError import Cardano.CLI.Types.Errors.NodeCmdError import Cardano.Git.Rev (gitRev) @@ -50,6 +52,7 @@ data ClientCommandErrors = ByronClientError ByronClientCmdError | CmdError Text CmdError | HashCmdError HashCmdError + | KeyCmdError KeyCmdError | NodeCmdError NodeCmdError | PingClientError PingClientCmdError | DebugCmdError DebugCmdError @@ -65,6 +68,8 @@ runClientCommand = \case firstExceptT ByronClientError $ runByronClientCommand cmds HashCmds cmds -> firstExceptT HashCmdError $ runHashCmds cmds + KeyCommands cmds -> + firstExceptT KeyCmdError $ runKeyCmds cmds LegacyCmds cmds -> firstExceptT (CmdError (renderLegacyCommand cmds)) $ runLegacyCmds cmds CliPingCommand cmds -> @@ -86,6 +91,8 @@ renderClientCommandError = \case prettyError err NodeCmdError err -> renderNodeCmdError err + KeyCmdError err -> + renderKeyCmdError err PingClientError err -> renderPingClientCmdError err DebugCmdError err -> diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs similarity index 99% rename from cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs rename to cardano-cli/src/Cardano/CLI/Run/Key.hs index fca88e3f32..5fe8336002 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -6,7 +6,7 @@ {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} -module Cardano.CLI.EraBased.Run.Key +module Cardano.CLI.Run.Key ( runKeyCmds , runConvertByronGenesisVKeyCmd , runConvertByronKeyCmd @@ -38,7 +38,7 @@ import Cardano.Api.Crypto.Ed25519Bip32 (xPrvFromBytes) import qualified Cardano.Api.Ledger as L import qualified Cardano.CLI.Byron.Key as Byron -import qualified Cardano.CLI.EraBased.Commands.Key as Cmd +import qualified Cardano.CLI.Commands.Key as Cmd import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.CardanoAddressSigningKeyConversionError import Cardano.CLI.Types.Errors.ItnKeyConversionError @@ -105,7 +105,7 @@ stakeVkeyDesc = "Stake Verification Key" runKeyCmds :: () - => Cmd.KeyCmds era + => Cmd.KeyCmds -> ExceptT KeyCmdError IO () runKeyCmds = \case Cmd.KeyVerificationKeyCmd cmd -> diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index ff8632d071..92a25f98bc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -1,5 +1,6 @@ Usage: cardano-cli - ( node + ( key + | node | legacy | byron | shelley @@ -15,6 +16,88 @@ Usage: cardano-cli | version ) +Usage: cardano-cli key + ( verification-key + | non-extended-key + | convert-byron-key + | convert-byron-genesis-vkey + | convert-itn-key + | convert-itn-extended-key + | convert-itn-bip32-key + | convert-cardano-address-key + ) + + Key utility commands. + +Usage: cardano-cli key verification-key --signing-key-file FILEPATH + --verification-key-file FILEPATH + + Get a verification key from a signing key. This supports all key types. + +Usage: cardano-cli key non-extended-key --extended-verification-key-file FILEPATH + --verification-key-file FILEPATH + + Get a non-extended verification key from an extended verification key. This + supports all extended key types. + +Usage: cardano-cli key convert-byron-key [--password TEXT] + ( --byron-payment-key-type + | --legacy-byron-payment-key-type + | --byron-genesis-key-type + | --legacy-byron-genesis-key-type + | --byron-genesis-delegate-key-type + | --legacy-byron-genesis-delegate-key-type + ) + ( --byron-signing-key-file FILEPATH + | --byron-verification-key-file FILEPATH + ) + --out-file FILEPATH + + Convert a Byron payment, genesis or genesis delegate key (signing or + verification) to a corresponding Shelley-format key. + +Usage: cardano-cli key convert-byron-genesis-vkey --byron-genesis-verification-key BASE64 + --out-file FILEPATH + + Convert a Base64-encoded Byron genesis verification key to a Shelley genesis + verification key + +Usage: cardano-cli key convert-itn-key + ( --itn-signing-key-file FILEPATH + | --itn-verification-key-file FILEPATH + ) + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) non-extended (Ed25519) signing or + verification key to a corresponding Shelley stake key + +Usage: cardano-cli key convert-itn-extended-key --itn-signing-key-file FILEPATH + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) extended (Ed25519Extended) signing key + to a corresponding Shelley stake signing key + +Usage: cardano-cli key convert-itn-bip32-key --itn-signing-key-file FILEPATH + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) BIP32 (Ed25519Bip32) signing key to a + corresponding Shelley stake signing key + +Usage: cardano-cli key convert-cardano-address-key + ( --cc-cold-key + | --cc-hot-key + | --drep-key + | --shelley-payment-key + | --shelley-stake-key + | --icarus-payment-key + | --byron-payment-key + ) + --signing-key-file FILEPATH + --out-file FILEPATH + + Convert a cardano-address extended signing key to a corresponding + Shelley-format key. + Usage: cardano-cli node ( key-gen | key-gen-KES diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli new file mode 100644 index 0000000000..c47902f063 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli @@ -0,0 +1,40 @@ +Usage: cardano-cli key + ( verification-key + | non-extended-key + | convert-byron-key + | convert-byron-genesis-vkey + | convert-itn-key + | convert-itn-extended-key + | convert-itn-bip32-key + | convert-cardano-address-key + ) + + Key utility commands. + +Available options: + -h,--help Show this help text + +Available commands: + verification-key Get a verification key from a signing key. This + supports all key types. + non-extended-key Get a non-extended verification key from an extended + verification key. This supports all extended key + types. + convert-byron-key Convert a Byron payment, genesis or genesis delegate + key (signing or verification) to a corresponding + Shelley-format key. + convert-byron-genesis-vkey + Convert a Base64-encoded Byron genesis verification + key to a Shelley genesis verification key + convert-itn-key Convert an Incentivized Testnet (ITN) non-extended + (Ed25519) signing or verification key to a + corresponding Shelley stake key + convert-itn-extended-key Convert an Incentivized Testnet (ITN) extended + (Ed25519Extended) signing key to a corresponding + Shelley stake signing key + convert-itn-bip32-key Convert an Incentivized Testnet (ITN) BIP32 + (Ed25519Bip32) signing key to a corresponding Shelley + stake signing key + convert-cardano-address-key + Convert a cardano-address extended signing key to a + corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-genesis-vkey.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-genesis-vkey.cli new file mode 100644 index 0000000000..dc80c4e3e9 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-genesis-vkey.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli key convert-byron-genesis-vkey --byron-genesis-verification-key BASE64 + --out-file FILEPATH + + Convert a Base64-encoded Byron genesis verification key to a Shelley genesis + verification key + +Available options: + --byron-genesis-verification-key BASE64 + Base64 string for the Byron genesis verification key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-key.cli new file mode 100644 index 0000000000..5103818e2b --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-byron-key.cli @@ -0,0 +1,35 @@ +Usage: cardano-cli key convert-byron-key [--password TEXT] + ( --byron-payment-key-type + | --legacy-byron-payment-key-type + | --byron-genesis-key-type + | --legacy-byron-genesis-key-type + | --byron-genesis-delegate-key-type + | --legacy-byron-genesis-delegate-key-type + ) + ( --byron-signing-key-file FILEPATH + | --byron-verification-key-file FILEPATH + ) + --out-file FILEPATH + + Convert a Byron payment, genesis or genesis delegate key (signing or + verification) to a corresponding Shelley-format key. + +Available options: + --password TEXT Password for signing key (if applicable). + --byron-payment-key-type Use a Byron-era payment key. + --legacy-byron-payment-key-type + Use a Byron-era payment key, in legacy SL format. + --byron-genesis-key-type Use a Byron-era genesis key. + --legacy-byron-genesis-key-type + Use a Byron-era genesis key, in legacy SL format. + --byron-genesis-delegate-key-type + Use a Byron-era genesis delegate key. + --legacy-byron-genesis-delegate-key-type + Use a Byron-era genesis delegate key, in legacy SL + format. + --byron-signing-key-file FILEPATH + Input filepath of the Byron-format signing key. + --byron-verification-key-file FILEPATH + Input filepath of the Byron-format verification key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-cardano-address-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-cardano-address-key.cli new file mode 100644 index 0000000000..20829714ec --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-cardano-address-key.cli @@ -0,0 +1,29 @@ +Usage: cardano-cli key convert-cardano-address-key + ( --cc-cold-key + | --cc-hot-key + | --drep-key + | --shelley-payment-key + | --shelley-stake-key + | --icarus-payment-key + | --byron-payment-key + ) + --signing-key-file FILEPATH + --out-file FILEPATH + + Convert a cardano-address extended signing key to a corresponding + Shelley-format key. + +Available options: + --cc-cold-key Use a committee cold key. + --cc-hot-key Use a committee hot key. + --drep-key Use a DRep key. + --shelley-payment-key Use a Shelley-era extended payment key. + --shelley-stake-key Use a Shelley-era extended stake key. + --icarus-payment-key Use a Byron-era extended payment key formatted in the + Icarus style. + --byron-payment-key Use a Byron-era extended payment key formatted in the + deprecated Byron style. + --signing-key-file FILEPATH + Input filepath of the signing key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-bip32-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-bip32-key.cli new file mode 100644 index 0000000000..cc2fb482b7 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-bip32-key.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli key convert-itn-bip32-key --itn-signing-key-file FILEPATH + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) BIP32 (Ed25519Bip32) signing key to a + corresponding Shelley stake signing key + +Available options: + --itn-signing-key-file FILEPATH + Filepath of the ITN signing key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-extended-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-extended-key.cli new file mode 100644 index 0000000000..bc21c345c1 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-extended-key.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli key convert-itn-extended-key --itn-signing-key-file FILEPATH + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) extended (Ed25519Extended) signing key + to a corresponding Shelley stake signing key + +Available options: + --itn-signing-key-file FILEPATH + Filepath of the ITN signing key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-key.cli new file mode 100644 index 0000000000..fa5d03634d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_convert-itn-key.cli @@ -0,0 +1,16 @@ +Usage: cardano-cli key convert-itn-key + ( --itn-signing-key-file FILEPATH + | --itn-verification-key-file FILEPATH + ) + --out-file FILEPATH + + Convert an Incentivized Testnet (ITN) non-extended (Ed25519) signing or + verification key to a corresponding Shelley stake key + +Available options: + --itn-signing-key-file FILEPATH + Filepath of the ITN signing key. + --itn-verification-key-file FILEPATH + Filepath of the ITN verification key. + --out-file FILEPATH The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_non-extended-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_non-extended-key.cli new file mode 100644 index 0000000000..d30e9aa908 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_non-extended-key.cli @@ -0,0 +1,12 @@ +Usage: cardano-cli key non-extended-key --extended-verification-key-file FILEPATH + --verification-key-file FILEPATH + + Get a non-extended verification key from an extended verification key. This + supports all extended key types. + +Available options: + --extended-verification-key-file FILEPATH + Input filepath of the ed25519-bip32 verification key. + --verification-key-file FILEPATH + Output filepath of the verification key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_verification-key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_verification-key.cli new file mode 100644 index 0000000000..69e7ff42ed --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_verification-key.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli key verification-key --signing-key-file FILEPATH + --verification-key-file FILEPATH + + Get a verification key from a signing key. This supports all key types. + +Available options: + --signing-key-file FILEPATH + Input filepath of the signing key. + --verification-key-file FILEPATH + Output filepath of the verification key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-test/Test/Cli/ITN.hs b/cardano-cli/test/cardano-cli-test/Test/Cli/ITN.hs index 9d953b33f3..2c4c3868a0 100644 --- a/cardano-cli/test/cardano-cli-test/Test/Cli/ITN.hs +++ b/cardano-cli/test/cardano-cli-test/Test/Cli/ITN.hs @@ -8,7 +8,7 @@ module Test.Cli.ITN ) where -import Cardano.CLI.EraBased.Run.Key (decodeBech32) +import Cardano.CLI.Run.Key (decodeBech32) import qualified Codec.Binary.Bech32 as Bech32 import Control.Monad (void)