From 0987f84ea03f394bcbb411ae6394a1a16e0c7754 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Fri, 8 Nov 2024 17:49:16 +0100 Subject: [PATCH 01/14] Preliminary implementation --- cabal.project | 14 ++ cardano-cli/src/Cardano/CLI/Commands/Key.hs | 24 ++++ cardano-cli/src/Cardano/CLI/Options/Key.hs | 85 ++++++++++++ cardano-cli/src/Cardano/CLI/Run/Key.hs | 70 ++++++++++ .../Cardano/CLI/Types/Errors/KeyCmdError.hs | 3 + .../cardano-cli-golden/files/golden/help.cli | 128 ++++++++++++++++++ .../files/golden/help/allegra_key.cli | 2 + .../help/allegra_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/alonzo_key.cli | 2 + .../help/alonzo_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/babbage_key.cli | 2 + .../help/babbage_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/conway_key.cli | 2 + .../help/conway_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/key.cli | 2 + .../golden/help/key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/latest_key.cli | 2 + .../help/latest_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/mary_key.cli | 2 + .../help/mary_key_key-from-mnemonic.cli | 37 +++++ .../files/golden/help/shelley_key.cli | 2 + .../help/shelley_key_key-from-mnemonic.cli | 37 +++++ 22 files changed, 636 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli diff --git a/cabal.project b/cabal.project index 9eb1804dcc..b4fc92178e 100644 --- a/cabal.project +++ b/cabal.project @@ -19,6 +19,20 @@ index-state: packages: cardano-cli +source-repository-package + type: git + location: https://github.com/intersectmbo/cardano-addresses.git + tag: b170724d92549a69fc3074b5f9b3f1871701aaab + subdir: core + --sha256: sha256-ldr7lEdME4XUjtgARPDBMMzeg3i2UojlW03ab3Pv0T0= + +source-repository-package + type: git + location: https://github.com/intersectmbo/cardano-api.git + tag: 29ca290f33c8df3d54e68cd566a762fa4aad2693 + subdir: cardano-api + --sha256: sha256-LuCEwN4nAiAfDelb7slBTkvfvUqQFQK0mMwaOF1kcHo= + program-options ghc-options: -Werror diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index 413cc24ab5..5c18aa5859 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -6,6 +6,8 @@ module Cardano.CLI.Commands.Key ( KeyCmds (..) , KeyVerificationKeyCmdArgs (..) , KeyNonExtendedKeyCmdArgs (..) + , KeyExtendedSigningKeyFromMnemonicArgs (..) + , ExtendedSigningType (..) , KeyConvertByronKeyCmdArgs (..) , KeyConvertByronGenesisVKeyCmdArgs (..) , KeyConvertITNKeyCmdArgs (..) @@ -19,12 +21,14 @@ where import Cardano.Api.Shelley import Cardano.CLI.Types.Common +import Cardano.Prelude (Word32) import Data.Text (Text) data KeyCmds = KeyVerificationKeyCmd !KeyVerificationKeyCmdArgs | KeyNonExtendedKeyCmd !KeyNonExtendedKeyCmdArgs + | KeyExtendedSigningKeyFromMnemonicCmd !KeyExtendedSigningKeyFromMnemonicArgs | KeyConvertByronKeyCmd !KeyConvertByronKeyCmdArgs | KeyConvertByronGenesisVKeyCmd !KeyConvertByronGenesisVKeyCmdArgs | KeyConvertITNKeyCmd !KeyConvertITNKeyCmdArgs @@ -52,6 +56,24 @@ data KeyNonExtendedKeyCmdArgs = KeyNonExtendedKeyCmdArgs } deriving Show +-- | Get a verification key from a mnemonic. This supports all extended key types. +data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicArgs + { keyOutputFormat :: !KeyOutputFormat + , extendedSigningKeyType :: !ExtendedSigningType + , derivationAccountNo :: !Word32 + , mnemonic :: !Text + , signingKeyFileOut :: !(SigningKeyFile Out) + } + deriving Show + +data ExtendedSigningType + = ExtendedSigningPaymentKey !Word32 + | ExtendedSigningStakeKey !Word32 + | ExtendedSigningDRepKey + | ExtendedSigningCCColdKey + | ExtendedSigningCCHotKey + deriving Show + -- | Convert a Byron payment, genesis or genesis delegate key (signing or -- verification) to a corresponding Shelley-format key. data KeyConvertByronKeyCmdArgs = KeyConvertByronKeyCmdArgs @@ -124,6 +146,8 @@ renderKeyCmds = \case "key verification-key" KeyNonExtendedKeyCmd{} -> "key non-extended-key" + KeyExtendedSigningKeyFromMnemonicCmd{} -> + "key from-mnemonic" KeyConvertByronKeyCmd{} -> "key convert-byron-key" KeyConvertByronGenesisVKeyCmd{} -> diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 33d2a0477c..e51c86352a 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -17,6 +17,8 @@ import Cardano.CLI.Types.Common import Data.Foldable import Data.Text (Text) +import qualified Data.Text as Text +import GHC.Word (Word32) import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt @@ -42,6 +44,12 @@ pKeyCmds = , "extended verification key. This supports all " , "extended key types." ] + , subParser "key-from-mnemonic" $ + Opt.info pKeyExtendedSigningKeyFromMnemonicCmd $ + Opt.progDesc $ + mconcat + [ "Derive an extended signing key from a mnemonic." + ] , subParser "convert-byron-key" $ Opt.info pKeyConvertByronKeyCmd $ Opt.progDesc $ @@ -114,6 +122,83 @@ pKeyNonExtendedKeyCmd = <$> pExtendedVerificationKeyFileIn <*> pVerificationKeyFileOut +pKeyExtendedSigningKeyFromMnemonicCmd :: Parser KeyCmds +pKeyExtendedSigningKeyFromMnemonicCmd = + fmap KeyExtendedSigningKeyFromMnemonicCmd $ + KeyExtendedSigningKeyFromMnemonicArgs + <$> pKeyOutputFormat + <*> pExtendedSigningKeyType + <*> pAccountNumber + <*> pMnemonicSentence + <*> pSigningKeyFileOut + +pExtendedSigningKeyType :: Parser ExtendedSigningType +pExtendedSigningKeyType = + asum + [ ( ExtendedSigningPaymentKey + <$ ( Opt.flag' () $ + mconcat + [ Opt.long "payment-key" + , Opt.help "Derive an extended payment key." + ] + ) + ) + <*> pPaymentAddressNumber + , ( ExtendedSigningStakeKey + <$ ( Opt.flag' () $ + mconcat + [ Opt.long "stake-key" + , Opt.help "Derive an extended stake key." + ] + ) + ) + <*> pPaymentAddressNumber + , Opt.flag' ExtendedSigningDRepKey $ + mconcat + [ Opt.long "drep-key" + , Opt.help "Derive an extended DRep key." + ] + , Opt.flag' ExtendedSigningCCColdKey $ + mconcat + [ Opt.long "cc-cold-key" + , Opt.help "Derive an extended committee cold key." + ] + , Opt.flag' ExtendedSigningCCHotKey $ + mconcat + [ Opt.long "cc-hot-key" + , Opt.help "Derive an extended committee hot key." + ] + ] + +pPaymentAddressNumber :: Parser Word32 +pPaymentAddressNumber = + Opt.option integralReader $ + mconcat + [ Opt.long "payment-address-number" + , Opt.metavar "WORD32" + , Opt.help "Payment address number in the derivation path." + ] + +pAccountNumber :: Parser Word32 +pAccountNumber = + Opt.option integralReader $ + mconcat + [ Opt.long "account-number" + , Opt.metavar "WORD32" + , Opt.help "Account number in the derivation path." + ] + +pMnemonicSentence :: Parser Text +pMnemonicSentence = + fmap Text.pack $ + Opt.strOption $ + mconcat + [ Opt.long "mnemonic-phrase" + , Opt.metavar "MNEMONIC" + , Opt.help + "Series of words separated by spaces that represent the mnemonic phrase. The number of words must be one of: 12, 15, 18, 21, or 24." + ] + pKeyConvertByronKeyCmd :: Parser KeyCmds pKeyConvertByronKeyCmd = fmap KeyConvertByronKeyCmd $ diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index 5fe8336002..1aa86663ed 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -57,6 +57,7 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as BS import Data.Function import Data.Text (Text) +import qualified Data.Text as T import qualified Data.Text as Text import qualified Data.Text.Encoding as Text import System.Exit (exitFailure) @@ -112,6 +113,8 @@ runKeyCmds = \case runVerificationKeyCmd cmd Cmd.KeyNonExtendedKeyCmd cmd -> runNonExtendedKeyCmd cmd + Cmd.KeyExtendedSigningKeyFromMnemonicCmd cmd -> + runExtendedSigningKeyFromMnemonicCmd cmd Cmd.KeyConvertByronKeyCmd cmd -> runConvertByronKeyCmd cmd Cmd.KeyConvertByronGenesisVKeyCmd cmd -> @@ -232,6 +235,73 @@ readExtendedVerificationKeyFile evkfile = do where goFail k = left $ KeyCmdExpectedExtendedVerificationKey k +runExtendedSigningKeyFromMnemonicCmd + :: Cmd.KeyExtendedSigningKeyFromMnemonicArgs + -> ExceptT KeyCmdError IO () +runExtendedSigningKeyFromMnemonicCmd + Cmd.KeyExtendedSigningKeyFromMnemonicArgs + { keyOutputFormat + , extendedSigningKeyType + , derivationAccountNo + , mnemonic + , signingKeyFileOut + } = do + let writeKeyToFile + :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) + => SigningKey a -> ExceptT KeyCmdError IO () + writeKeyToFile = writeSigningKeyFile keyOutputFormat signingKeyFileOut + + wrapException :: Either MnemonicToSigningKeyError a -> ExceptT KeyCmdError IO a + wrapException = except . first KeyCmdMnemonicError + + mnemonicWords = map T.pack $ words $ T.unpack mnemonic + + case extendedSigningKeyType of + Cmd.ExtendedSigningPaymentKey paymentKeyNo -> + writeKeyToFile + =<< wrapException + ( signingKeyFromMnemonicWithPaymentKeyIndex + AsPaymentExtendedKey + mnemonicWords + derivationAccountNo + paymentKeyNo + ) + Cmd.ExtendedSigningStakeKey paymentKeyNo -> + writeKeyToFile + =<< wrapException + ( signingKeyFromMnemonicWithPaymentKeyIndex + AsStakeExtendedKey + mnemonicWords + derivationAccountNo + paymentKeyNo + ) + Cmd.ExtendedSigningDRepKey -> + writeKeyToFile + =<< wrapException (signingKeyFromMnemonic AsDRepExtendedKey mnemonicWords derivationAccountNo) + Cmd.ExtendedSigningCCColdKey -> + writeKeyToFile + =<< wrapException + (signingKeyFromMnemonic AsCommitteeColdExtendedKey mnemonicWords derivationAccountNo) + Cmd.ExtendedSigningCCHotKey -> + writeKeyToFile + =<< wrapException + (signingKeyFromMnemonic AsCommitteeHotExtendedKey mnemonicWords derivationAccountNo) + where + writeSigningKeyFile + :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) + => KeyOutputFormat -> SigningKeyFile Out -> SigningKey a -> ExceptT KeyCmdError IO () + writeSigningKeyFile fmt sKeyPath skey = + firstExceptT KeyCmdWriteFileError $ + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT $ + writeLazyByteStringFile sKeyPath $ + textEnvelopeToJSON Nothing skey + KeyOutputFormatBech32 -> + newExceptT $ + writeTextFile sKeyPath $ + serialiseToBech32 skey + runConvertByronKeyCmd :: Cmd.KeyConvertByronKeyCmdArgs -> ExceptT KeyCmdError IO () diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs index a1ac6de59e..ddcf6f9bf3 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs @@ -22,6 +22,7 @@ data KeyCmdError = KeyCmdReadFileError !(FileError TextEnvelopeError) | KeyCmdReadKeyFileError !(FileError InputDecodeError) | KeyCmdWriteFileError !(FileError ()) + | KeyCmdMnemonicError MnemonicToSigningKeyError | KeyCmdByronKeyFailure !Byron.ByronKeyFailure | -- | Text representation of the parse error. Unfortunately, the actual -- error type isn't exported. @@ -45,6 +46,8 @@ renderKeyCmdError err = prettyError fileErr KeyCmdWriteFileError fileErr -> prettyError fileErr + KeyCmdMnemonicError mnemonicErr -> + "Error converting the mnemonic into a key: " <> prettyError mnemonicErr KeyCmdByronKeyFailure e -> Byron.renderByronKeyFailure e KeyCmdByronKeyParseError errTxt -> 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 43b3c0f35a..8e319db7d8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -64,6 +64,7 @@ Usage: cardano-cli address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -85,6 +86,21 @@ Usage: cardano-cli key non-extended-key --extended-verification-key-file FILEPAT Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -1004,6 +1020,7 @@ Usage: cardano-cli shelley address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli shelley key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -1025,6 +1042,21 @@ Usage: cardano-cli shelley key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli shelley key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -2076,6 +2108,7 @@ Usage: cardano-cli allegra address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli allegra key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -2097,6 +2130,21 @@ Usage: cardano-cli allegra key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli allegra key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -3148,6 +3196,7 @@ Usage: cardano-cli mary address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli mary key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -3169,6 +3218,21 @@ Usage: cardano-cli mary key non-extended-key --extended-verification-key-file FI Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli mary key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -4210,6 +4274,7 @@ Usage: cardano-cli alonzo address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli alonzo key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -4231,6 +4296,21 @@ Usage: cardano-cli alonzo key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli alonzo key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -5287,6 +5367,7 @@ Usage: cardano-cli babbage address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli babbage key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -5308,6 +5389,21 @@ Usage: cardano-cli babbage key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli babbage key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -6644,6 +6740,7 @@ Usage: cardano-cli conway address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli conway key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -6665,6 +6762,21 @@ Usage: cardano-cli conway key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli conway key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type @@ -8643,6 +8755,7 @@ Usage: cardano-cli latest address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli latest key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -8664,6 +8777,21 @@ Usage: cardano-cli latest key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + Usage: cardano-cli latest key convert-byron-key [--password TEXT] ( --byron-payment-key-type | --legacy-byron-payment-key-type diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli index 8b423751c7..0a91f8e1dc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli allegra key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..d47304102e --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli index 92dcd0d399..b1a0a10ccf 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli alonzo key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..1ee0a115e2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli index 05984ddb8b..261b30a2ad 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli babbage key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..f19e172db6 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli index 4f277404ee..ace6c5331b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli conway key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..f96ff3a4ef --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text 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 index c47902f063..2a615675b2 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli new file mode 100644 index 0000000000..5d82d7df93 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli index aae3d2309b..e7de1ae2c1 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli latest key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..bdcd2ba066 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli index 8dc24ca138..10e72cfefa 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli mary key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..caee7a400d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli index 1f6999a624..a134b02236 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli shelley key ( verification-key | non-extended-key + | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -20,6 +21,7 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli new file mode 100644 index 0000000000..254746338d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli @@ -0,0 +1,37 @@ +Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + --mnemonic-phrase MNEMONIC + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-phrase MNEMONIC + Series of words separated by spaces that represent + the mnemonic phrase. The number of words must be one + of: 12, 15, 18, 21, or 24. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text From 7782a13e85e78030580a29e52444ff1db60099b9 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 19 Nov 2024 14:20:05 +0100 Subject: [PATCH 02/14] Add command to generate mnemonics --- cardano-cli/src/Cardano/CLI/Commands/Key.hs | 13 +++++ cardano-cli/src/Cardano/CLI/Options/Key.hs | 36 ++++++++++++++ cardano-cli/src/Cardano/CLI/Run/Key.hs | 15 ++++++ .../cardano-cli-golden/files/golden/help.cli | 47 +++++++++++++++++++ .../files/golden/help/allegra_key.cli | 3 ++ .../help/allegra_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/alonzo_key.cli | 3 ++ .../help/alonzo_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/babbage_key.cli | 3 ++ .../help/babbage_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/conway_key.cli | 3 ++ .../help/conway_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/key.cli | 3 ++ .../golden/help/key_generate-mnemonic.cli | 10 ++++ .../files/golden/help/latest_key.cli | 3 ++ .../help/latest_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/mary_key.cli | 3 ++ .../help/mary_key_generate-mnemonic.cli | 11 +++++ .../files/golden/help/shelley_key.cli | 3 ++ .../help/shelley_key_generate-mnemonic.cli | 11 +++++ 20 files changed, 222 insertions(+) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_generate-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_generate-mnemonic.cli diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index 5c18aa5859..40f05bd0f6 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -6,6 +6,7 @@ module Cardano.CLI.Commands.Key ( KeyCmds (..) , KeyVerificationKeyCmdArgs (..) , KeyNonExtendedKeyCmdArgs (..) + , KeyGenerateMnemonicCmdArgs (..) , KeyExtendedSigningKeyFromMnemonicArgs (..) , ExtendedSigningType (..) , KeyConvertByronKeyCmdArgs (..) @@ -28,6 +29,7 @@ import Data.Text (Text) data KeyCmds = KeyVerificationKeyCmd !KeyVerificationKeyCmdArgs | KeyNonExtendedKeyCmd !KeyNonExtendedKeyCmdArgs + | KeyGenerateMnemonicCmd !KeyGenerateMnemonicCmdArgs | KeyExtendedSigningKeyFromMnemonicCmd !KeyExtendedSigningKeyFromMnemonicArgs | KeyConvertByronKeyCmd !KeyConvertByronKeyCmdArgs | KeyConvertByronGenesisVKeyCmd !KeyConvertByronGenesisVKeyCmdArgs @@ -56,6 +58,15 @@ data KeyNonExtendedKeyCmdArgs = KeyNonExtendedKeyCmdArgs } deriving Show +-- | Generate a mnemonic phrase that can be used to derive signing keys. +data KeyGenerateMnemonicCmdArgs = KeyGenerateMnemonicCmdArgs + { mnemonicOutputFormat :: !(Maybe (File () Out)) + -- ^ Output format for the mnemonic phrase + , mnemonicWords :: !MnemonicSize + -- ^ Number of mnemonic words to generate it must be one of: 12, 15, 18, 21, or 24. + } + deriving Show + -- | Get a verification key from a mnemonic. This supports all extended key types. data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicArgs { keyOutputFormat :: !KeyOutputFormat @@ -146,6 +157,8 @@ renderKeyCmds = \case "key verification-key" KeyNonExtendedKeyCmd{} -> "key non-extended-key" + KeyGenerateMnemonicCmd{} -> + "key generate-mnemonic" KeyExtendedSigningKeyFromMnemonicCmd{} -> "key from-mnemonic" KeyConvertByronKeyCmd{} -> diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index e51c86352a..9cfd76afc9 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -44,6 +44,13 @@ pKeyCmds = , "extended verification key. This supports all " , "extended key types." ] + , subParser "generate-mnemonic" $ + Opt.info pKeyGenerateMnemonicCmd $ + Opt.progDesc $ + mconcat + [ "Generate a mnemonic sentence that can be used " + , "for key derivation." + ] , subParser "key-from-mnemonic" $ Opt.info pKeyExtendedSigningKeyFromMnemonicCmd $ Opt.progDesc $ @@ -122,6 +129,35 @@ pKeyNonExtendedKeyCmd = <$> pExtendedVerificationKeyFileIn <*> pVerificationKeyFileOut +pKeyGenerateMnemonicCmd :: Parser KeyCmds +pKeyGenerateMnemonicCmd = + fmap KeyGenerateMnemonicCmd $ + KeyGenerateMnemonicCmdArgs + <$> optional pOutputFile + <*> pMnemonicSize + +pMnemonicSize :: Parser MnemonicSize +pMnemonicSize = do + option + (maybeReader parseSize) + ( long "size" + <> metavar "WORD32" + <> Opt.help + ( mconcat + [ "Specify the desired number of words for the output" + , "mnemonic sentence (valid options are: 12, 15, 18, 21, and 24)" + ] + ) + ) + where + parseSize :: String -> Maybe MnemonicSize + parseSize "12" = Just MS12 + parseSize "15" = Just MS15 + parseSize "18" = Just MS18 + parseSize "21" = Just MS21 + parseSize "24" = Just MS24 + parseSize _ = Nothing + pKeyExtendedSigningKeyFromMnemonicCmd :: Parser KeyCmds pKeyExtendedSigningKeyFromMnemonicCmd = fmap KeyExtendedSigningKeyFromMnemonicCmd $ diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index 1aa86663ed..c3a9186c47 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -113,6 +113,8 @@ runKeyCmds = \case runVerificationKeyCmd cmd Cmd.KeyNonExtendedKeyCmd cmd -> runNonExtendedKeyCmd cmd + Cmd.KeyGenerateMnemonicCmd cmd -> + runGenerateMnemonicCmd cmd Cmd.KeyExtendedSigningKeyFromMnemonicCmd cmd -> runExtendedSigningKeyFromMnemonicCmd cmd Cmd.KeyConvertByronKeyCmd cmd -> @@ -205,6 +207,19 @@ runNonExtendedKeyCmd writeLazyByteStringFile vkf' $ textEnvelopeToJSON descr vk +runGenerateMnemonicCmd :: Cmd.KeyGenerateMnemonicCmdArgs -> ExceptT KeyCmdError IO () +runGenerateMnemonicCmd + Cmd.KeyGenerateMnemonicCmdArgs + { mnemonicOutputFormat + , mnemonicWords + } = do + mnemonic <- firstExceptT KeyCmdMnemonicError $ generateMnemonic mnemonicWords + case mnemonicOutputFormat of + Just outFile -> + firstExceptT KeyCmdWriteFileError . newExceptT $ + writeTextFile outFile (T.unwords mnemonic) + Nothing -> liftIO $ putStrLn $ T.unpack (T.unwords mnemonic) + readExtendedVerificationKeyFile :: VerificationKeyFile In -> ExceptT KeyCmdError IO SomeAddressVerificationKey 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 8e319db7d8..1ec23da1a6 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -64,6 +64,7 @@ Usage: cardano-cli address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -86,6 +87,10 @@ Usage: cardano-cli key non-extended-key --extended-verification-key-file FILEPAT Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli key generate-mnemonic [--out-file FILEPATH] --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -1020,6 +1025,7 @@ Usage: cardano-cli shelley address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli shelley key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -1042,6 +1048,11 @@ Usage: cardano-cli shelley key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli shelley key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -2108,6 +2119,7 @@ Usage: cardano-cli allegra address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli allegra key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -2130,6 +2142,11 @@ Usage: cardano-cli allegra key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli allegra key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -3196,6 +3213,7 @@ Usage: cardano-cli mary address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli mary key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -3218,6 +3236,11 @@ Usage: cardano-cli mary key non-extended-key --extended-verification-key-file FI Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli mary key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -4274,6 +4297,7 @@ Usage: cardano-cli alonzo address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli alonzo key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -4296,6 +4320,11 @@ Usage: cardano-cli alonzo key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli alonzo key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -5367,6 +5396,7 @@ Usage: cardano-cli babbage address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli babbage key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -5389,6 +5419,11 @@ Usage: cardano-cli babbage key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli babbage key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -6740,6 +6775,7 @@ Usage: cardano-cli conway address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli conway key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -6762,6 +6798,11 @@ Usage: cardano-cli conway key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli conway key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 @@ -8755,6 +8796,7 @@ Usage: cardano-cli latest address info --address ADDRESS [--out-file FILEPATH] Usage: cardano-cli latest key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -8777,6 +8819,11 @@ Usage: cardano-cli latest key non-extended-key --extended-verification-key-file Get a non-extended verification key from an extended verification key. This supports all extended key types. +Usage: cardano-cli latest key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] ( --payment-key --payment-address-number WORD32 diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli index 0a91f8e1dc..bf07e26679 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli allegra key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_generate-mnemonic.cli new file mode 100644 index 0000000000..daa7e923c2 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli allegra key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli index b1a0a10ccf..1cdfc7ba79 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli alonzo key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_generate-mnemonic.cli new file mode 100644 index 0000000000..81533e197d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli alonzo key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli index 261b30a2ad..65987624a6 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli babbage key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_generate-mnemonic.cli new file mode 100644 index 0000000000..b250a3ae9e --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli babbage key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli index ace6c5331b..85293a13e2 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli conway key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_generate-mnemonic.cli new file mode 100644 index 0000000000..99b9291670 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli conway key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text 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 index 2a615675b2..5624162ead 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_generate-mnemonic.cli new file mode 100644 index 0000000000..b4c6babe43 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_generate-mnemonic.cli @@ -0,0 +1,10 @@ +Usage: cardano-cli key generate-mnemonic [--out-file FILEPATH] --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli index e7de1ae2c1..f5b4309395 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli latest key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_generate-mnemonic.cli new file mode 100644 index 0000000000..cfc5c02f03 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli latest key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli index 10e72cfefa..9bcacb25d5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli mary key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_generate-mnemonic.cli new file mode 100644 index 0000000000..c0032281cb --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli mary key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli index a134b02236..202b2d8274 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli @@ -1,6 +1,7 @@ Usage: cardano-cli shelley key ( verification-key | non-extended-key + | generate-mnemonic | key-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey @@ -21,6 +22,8 @@ Available commands: non-extended-key Get a non-extended verification key from an extended verification key. This supports all extended key types. + generate-mnemonic Generate a mnemonic sentence that can be used for key + derivation. key-from-mnemonic Derive an extended signing key from a mnemonic. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_generate-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_generate-mnemonic.cli new file mode 100644 index 0000000000..66169a4494 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_generate-mnemonic.cli @@ -0,0 +1,11 @@ +Usage: cardano-cli shelley key generate-mnemonic [--out-file FILEPATH] + --size WORD32 + + Generate a mnemonic sentence that can be used for key derivation. + +Available options: + --out-file FILEPATH The output file. + --size WORD32 Specify the desired number of words for the + outputmnemonic sentence (valid options are: 12, 15, + 18, 21, and 24) + -h,--help Show this help text From 018d9b8f7de7fc93592c23bcfb880e8edbae390d Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 20 Nov 2024 14:04:48 +0100 Subject: [PATCH 03/14] Read mnemonic from file --- cardano-cli/src/Cardano/CLI/Commands/Key.hs | 7 ++- cardano-cli/src/Cardano/CLI/Options/Key.hs | 26 +++++----- cardano-cli/src/Cardano/CLI/Run/Key.hs | 9 +++- .../Cardano/CLI/Types/Errors/KeyCmdError.hs | 3 ++ .../cardano-cli-golden/files/golden/help.cli | 48 ++++++++++++------- .../files/golden/help/allegra_key.cli | 5 +- .../help/allegra_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/alonzo_key.cli | 5 +- .../help/alonzo_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/babbage_key.cli | 5 +- .../help/babbage_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/conway_key.cli | 5 +- .../help/conway_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/key.cli | 5 +- .../golden/help/key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/latest_key.cli | 5 +- .../help/latest_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/mary_key.cli | 5 +- .../help/mary_key_key-from-mnemonic.cli | 12 ++--- .../files/golden/help/shelley_key.cli | 5 +- .../help/shelley_key_key-from-mnemonic.cli | 12 ++--- 21 files changed, 140 insertions(+), 89 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index 40f05bd0f6..e6259e80b8 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -9,6 +9,7 @@ module Cardano.CLI.Commands.Key , KeyGenerateMnemonicCmdArgs (..) , KeyExtendedSigningKeyFromMnemonicArgs (..) , ExtendedSigningType (..) + , MnemonicSource (..) , KeyConvertByronKeyCmdArgs (..) , KeyConvertByronGenesisVKeyCmdArgs (..) , KeyConvertITNKeyCmdArgs (..) @@ -72,11 +73,15 @@ data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicAr { keyOutputFormat :: !KeyOutputFormat , extendedSigningKeyType :: !ExtendedSigningType , derivationAccountNo :: !Word32 - , mnemonic :: !Text + , mnemonicSource :: !MnemonicSource , signingKeyFileOut :: !(SigningKeyFile Out) } deriving Show +newtype MnemonicSource + = MnemonicFromFile (File () In) + deriving Show + data ExtendedSigningType = ExtendedSigningPaymentKey !Word32 | ExtendedSigningStakeKey !Word32 diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 9cfd76afc9..94e9ef022d 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -17,7 +17,6 @@ import Cardano.CLI.Types.Common import Data.Foldable import Data.Text (Text) -import qualified Data.Text as Text import GHC.Word (Word32) import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt @@ -55,7 +54,11 @@ pKeyCmds = Opt.info pKeyExtendedSigningKeyFromMnemonicCmd $ Opt.progDesc $ mconcat - [ "Derive an extended signing key from a mnemonic." + [ "Derive an extended signing key from a mnemonic " + , "sentence. " + , "To ensure the safety of the mnemonic phrase, " + , "we recommend that key derivation is performed " + , "in an air-gapped environment." ] , subParser "convert-byron-key" $ Opt.info pKeyConvertByronKeyCmd $ @@ -165,7 +168,7 @@ pKeyExtendedSigningKeyFromMnemonicCmd = <$> pKeyOutputFormat <*> pExtendedSigningKeyType <*> pAccountNumber - <*> pMnemonicSentence + <*> pMnemonicSource <*> pSigningKeyFileOut pExtendedSigningKeyType :: Parser ExtendedSigningType @@ -206,6 +209,12 @@ pExtendedSigningKeyType = ] ] +pMnemonicSource :: Parser MnemonicSource +pMnemonicSource = + asum + [ MnemonicFromFile . File <$> parseFilePath "mnemonic-from-file" "Input text file with the mnemonic." + ] + pPaymentAddressNumber :: Parser Word32 pPaymentAddressNumber = Opt.option integralReader $ @@ -224,17 +233,6 @@ pAccountNumber = , Opt.help "Account number in the derivation path." ] -pMnemonicSentence :: Parser Text -pMnemonicSentence = - fmap Text.pack $ - Opt.strOption $ - mconcat - [ Opt.long "mnemonic-phrase" - , Opt.metavar "MNEMONIC" - , Opt.help - "Series of words separated by spaces that represent the mnemonic phrase. The number of words must be one of: 12, 15, 18, 21, or 24." - ] - pKeyConvertByronKeyCmd :: Parser KeyCmds pKeyConvertByronKeyCmd = fmap KeyConvertByronKeyCmd $ diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index c3a9186c47..3fadc2dca5 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -258,7 +258,7 @@ runExtendedSigningKeyFromMnemonicCmd { keyOutputFormat , extendedSigningKeyType , derivationAccountNo - , mnemonic + , mnemonicSource , signingKeyFileOut } = do let writeKeyToFile @@ -269,7 +269,7 @@ runExtendedSigningKeyFromMnemonicCmd wrapException :: Either MnemonicToSigningKeyError a -> ExceptT KeyCmdError IO a wrapException = except . first KeyCmdMnemonicError - mnemonicWords = map T.pack $ words $ T.unpack mnemonic + mnemonicWords <- readMnemonic mnemonicSource case extendedSigningKeyType of Cmd.ExtendedSigningPaymentKey paymentKeyNo -> @@ -317,6 +317,11 @@ runExtendedSigningKeyFromMnemonicCmd writeTextFile sKeyPath $ serialiseToBech32 skey +readMnemonic :: Cmd.MnemonicSource -> ExceptT KeyCmdError IO [Text] +readMnemonic (Cmd.MnemonicFromFile filePath) = do + fileText <- firstExceptT KeyCmdReadMnemonicFileError $ except =<< readTextFile filePath + return $ map T.pack $ words $ T.unpack fileText + runConvertByronKeyCmd :: Cmd.KeyConvertByronKeyCmdArgs -> ExceptT KeyCmdError IO () diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs index ddcf6f9bf3..6bc8f1e5cd 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs @@ -21,6 +21,7 @@ import Data.Text (Text) data KeyCmdError = KeyCmdReadFileError !(FileError TextEnvelopeError) | KeyCmdReadKeyFileError !(FileError InputDecodeError) + | KeyCmdReadMnemonicFileError !(FileError ()) | KeyCmdWriteFileError !(FileError ()) | KeyCmdMnemonicError MnemonicToSigningKeyError | KeyCmdByronKeyFailure !Byron.ByronKeyFailure @@ -44,6 +45,8 @@ renderKeyCmdError err = prettyError fileErr KeyCmdReadKeyFileError fileErr -> prettyError fileErr + KeyCmdReadMnemonicFileError fileErr -> + "Error reading mnemonic file: " <> prettyError fileErr KeyCmdWriteFileError fileErr -> prettyError fileErr KeyCmdMnemonicError mnemonicErr -> 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 1ec23da1a6..a51938a3c5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -101,10 +101,12 @@ Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -1063,10 +1065,12 @@ Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli shelley key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -2157,10 +2161,12 @@ Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli allegra key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -3251,10 +3257,12 @@ Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli mary key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -4335,10 +4343,12 @@ Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli alonzo key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -5434,10 +5444,12 @@ Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli babbage key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -6813,10 +6825,12 @@ Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli conway key convert-byron-key [--password TEXT] ( --byron-payment-key-type @@ -8834,10 +8848,12 @@ Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Usage: cardano-cli latest key convert-byron-key [--password TEXT] ( --byron-payment-key-type diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli index bf07e26679..abaf7aa70a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli index d47304102e..fba45487cc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli index 1cdfc7ba79..0964be8c0d 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli index 1ee0a115e2..709fc53d5f 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli index 65987624a6..b816e07d2a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli index f19e172db6..42ab280dab 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli index 85293a13e2..165bab0c1a 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli index f96ff3a4ef..24ef842a2b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text 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 index 5624162ead..bd11f96385 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli index 5d82d7df93..2936d33b76 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli index f5b4309395..aaf865acfd 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli index bdcd2ba066..7fb10802b4 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli index 9bcacb25d5..1b7116795b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli index caee7a400d..c0f93110f6 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli index 202b2d8274..7193f03b66 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli @@ -24,7 +24,10 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic. + key-from-mnemonic Derive an extended signing key from a mnemonic + sentence. To ensure the safety of the mnemonic + phrase, we recommend that key derivation is performed + in an air-gapped environment. convert-byron-key Convert a Byron payment, genesis or genesis delegate key (signing or verification) to a corresponding Shelley-format key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli index 254746338d..6902a8de9f 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli @@ -8,10 +8,12 @@ Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-phrase MNEMONIC + --mnemonic-from-file FILEPATH --signing-key-file FILEPATH - Derive an extended signing key from a mnemonic. + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. Available options: --key-output-format STRING @@ -28,10 +30,8 @@ Available options: --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. --account-number WORD32 Account number in the derivation path. - --mnemonic-phrase MNEMONIC - Series of words separated by spaces that represent - the mnemonic phrase. The number of words must be one - of: 12, 15, 18, 21, or 24. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text From 678f83cbda8861e09895a56e3772283b7d2beeb0 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 20 Nov 2024 16:24:05 +0100 Subject: [PATCH 04/14] Add interactive prompt --- cardano-cli/cardano-cli.cabal | 1 + cardano-cli/src/Cardano/CLI/Commands/Key.hs | 5 +- cardano-cli/src/Cardano/CLI/Options/Key.hs | 5 ++ cardano-cli/src/Cardano/CLI/Run/Key.hs | 61 +++++++++++++++++-- .../cardano-cli-golden/files/golden/help.cli | 32 +++++++--- .../help/allegra_key_key-from-mnemonic.cli | 6 +- .../help/alonzo_key_key-from-mnemonic.cli | 6 +- .../help/babbage_key_key-from-mnemonic.cli | 6 +- .../help/conway_key_key-from-mnemonic.cli | 6 +- .../golden/help/key_key-from-mnemonic.cli | 6 +- .../help/latest_key_key-from-mnemonic.cli | 6 +- .../help/mary_key_key-from-mnemonic.cli | 6 +- .../help/shelley_key_key-from-mnemonic.cli | 6 +- 13 files changed, 130 insertions(+), 22 deletions(-) diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 012438b1cb..7da4bdf71f 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -222,6 +222,7 @@ library exceptions, filepath, formatting, + haskeline, http-client, http-client-tls, http-types, diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index e6259e80b8..0b188bde7a 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -78,8 +78,9 @@ data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicAr } deriving Show -newtype MnemonicSource - = MnemonicFromFile (File () In) +data MnemonicSource + = MnemonicFromFile !(File () In) + | MnemonicFromInteractivePrompt deriving Show data ExtendedSigningType diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 94e9ef022d..27d7fa9c63 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -213,6 +213,11 @@ pMnemonicSource :: Parser MnemonicSource pMnemonicSource = asum [ MnemonicFromFile . File <$> parseFilePath "mnemonic-from-file" "Input text file with the mnemonic." + , Opt.flag' MnemonicFromInteractivePrompt $ + mconcat + [ Opt.long "mnemonic-from-interactive-prompt" + , Opt.help "Input the mnemonic through an interactive prompt." + ] ] pPaymentAddressNumber :: Parser Word32 diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index 3fadc2dca5..f40e60dba6 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -49,6 +49,7 @@ import qualified Cardano.Crypto.Signing as Byron import qualified Cardano.Crypto.Signing as Byron.Crypto import qualified Cardano.Crypto.Signing as Crypto import qualified Cardano.Crypto.Wallet as Crypto +import Cardano.Prelude (isSpace) import qualified Codec.Binary.Bech32 as Bech32 import qualified Control.Exception as Exception @@ -60,6 +61,10 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text as Text import qualified Data.Text.Encoding as Text +import System.Console.Haskeline (Completion, InputT, Settings (..), completeWord', + defaultBehavior, defaultPrefs, getInputLineWithInitial, + runInputTBehaviorWithPrefs, simpleCompletion) +import System.Console.Haskeline.Completion (CompletionFunc) import System.Exit (exitFailure) -- Note on these constants: @@ -317,10 +322,58 @@ runExtendedSigningKeyFromMnemonicCmd writeTextFile sKeyPath $ serialiseToBech32 skey -readMnemonic :: Cmd.MnemonicSource -> ExceptT KeyCmdError IO [Text] -readMnemonic (Cmd.MnemonicFromFile filePath) = do - fileText <- firstExceptT KeyCmdReadMnemonicFileError $ except =<< readTextFile filePath - return $ map T.pack $ words $ T.unpack fileText + readMnemonic :: Cmd.MnemonicSource -> ExceptT KeyCmdError IO [Text] + readMnemonic (Cmd.MnemonicFromFile filePath) = do + fileText <- firstExceptT KeyCmdReadMnemonicFileError $ except =<< readTextFile filePath + return $ map T.pack $ words $ T.unpack fileText + readMnemonic Cmd.MnemonicFromInteractivePrompt = + liftIO $ do + putStrLn "" + putStrLn "Please enter your mnemonic sentence." + putStrLn "" + putStrLn " - It should consist of either: 12, 15, 18, 21, or 24 words." + putStrLn " - To terminate, press enter on an empty line." + putStrLn " - To abort you can press CTRL+C." + putStrLn "" + putStrLn "(If your terminal supports it, you can use the TAB key for word completion.)" + putStrLn "" + runInputTBehaviorWithPrefs defaultBehavior defaultPrefs settings (inputT ("", "") []) + where + settings :: Monad m => Settings m + settings = + Settings + { complete = completionFunc + , historyFile = Nothing + , autoAddHistory = False + } + + completionFunc :: Monad m => CompletionFunc m + completionFunc = completeWord' Nothing isSpace completeMnemonicWord + + completeMnemonicWord :: Monad m => String -> m [Completion] + completeMnemonicWord prefix = return $ map (simpleCompletion . T.unpack . fst) $ findMnemonicWordsWithPrefix (T.pack prefix) + + inputT :: (String, String) -> [Text] -> InputT IO [Text] + inputT prefill mnemonic = do + minput <- getInputLineWithInitial (show (length mnemonic + 1) <> ". ") prefill + case minput of + Nothing -> return $ reverse mnemonic + Just "" -> return $ reverse mnemonic + Just input -> + let newWords = map (T.toLower . T.pack) $ filter (not . null) $ words input + in case span isValidMnemonicWord newWords of + (allWords, []) -> inputT ("", "") (reverse allWords ++ mnemonic) + (validWords, invalidWord : notValidatedWords) -> do + liftIO $ putStrLn $ "The word \"" <> T.unpack invalidWord <> "\" is not in the memonic dictionary" + let textBeforeCursor = unwords (map T.unpack validWords <> [T.unpack invalidWord]) + textAfterCursor = + if null notValidatedWords + then "" + else ' ' : unwords (map T.unpack notValidatedWords) + inputT (textBeforeCursor, textAfterCursor) mnemonic + + isValidMnemonicWord :: Text -> Bool + isValidMnemonicWord word = word `elem` map fst (findMnemonicWordsWithPrefix word) runConvertByronKeyCmd :: Cmd.KeyConvertByronKeyCmdArgs 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 a51938a3c5..a5fb26186c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -101,7 +101,9 @@ Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -1065,7 +1067,9 @@ Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -2161,7 +2165,9 @@ Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -3257,7 +3263,9 @@ Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -4343,7 +4351,9 @@ Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -5444,7 +5454,9 @@ Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -6825,7 +6837,9 @@ Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -8848,7 +8862,9 @@ Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli index fba45487cc..132ec45ca5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli index 709fc53d5f..77d5217ea3 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli index 42ab280dab..aeb281b5c1 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli index 24ef842a2b..8fdb1f8209 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli index 2936d33b76..1d3a5dad08 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli index 7fb10802b4..5446e5a5f5 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli index c0f93110f6..a52bc70385 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli index 6902a8de9f..a5c0996a62 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_key-from-mnemonic.cli @@ -8,7 +8,9 @@ Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] | --cc-hot-key ) --account-number WORD32 - --mnemonic-from-file FILEPATH + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety @@ -32,6 +34,8 @@ Available options: --account-number WORD32 Account number in the derivation path. --mnemonic-from-file FILEPATH Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text From 4bcb2ba14c4c6c441b1aba4659798c9e43560377 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 16:58:11 +0100 Subject: [PATCH 05/14] Fix error in comment --- cardano-cli/src/Cardano/CLI/Commands/Key.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index 0b188bde7a..e8d1bca495 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -68,7 +68,7 @@ data KeyGenerateMnemonicCmdArgs = KeyGenerateMnemonicCmdArgs } deriving Show --- | Get a verification key from a mnemonic. This supports all extended key types. +-- | Get an extended signing key from a mnemonic. data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicArgs { keyOutputFormat :: !KeyOutputFormat , extendedSigningKeyType :: !ExtendedSigningType From d9fdc007d51ba2f49731bd3f7600e6d69ac9acdc Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 16:59:44 +0100 Subject: [PATCH 06/14] Rename `extendedSigningKeyType` to `derivedExtendedSigningKeyType` --- cardano-cli/src/Cardano/CLI/Commands/Key.hs | 2 +- cardano-cli/src/Cardano/CLI/Options/Key.hs | 6 +++--- cardano-cli/src/Cardano/CLI/Run/Key.hs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index e8d1bca495..d36fd360aa 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -71,7 +71,7 @@ data KeyGenerateMnemonicCmdArgs = KeyGenerateMnemonicCmdArgs -- | Get an extended signing key from a mnemonic. data KeyExtendedSigningKeyFromMnemonicArgs = KeyExtendedSigningKeyFromMnemonicArgs { keyOutputFormat :: !KeyOutputFormat - , extendedSigningKeyType :: !ExtendedSigningType + , derivedExtendedSigningKeyType :: !ExtendedSigningType , derivationAccountNo :: !Word32 , mnemonicSource :: !MnemonicSource , signingKeyFileOut :: !(SigningKeyFile Out) diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 27d7fa9c63..ca5cc8653f 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -166,13 +166,13 @@ pKeyExtendedSigningKeyFromMnemonicCmd = fmap KeyExtendedSigningKeyFromMnemonicCmd $ KeyExtendedSigningKeyFromMnemonicArgs <$> pKeyOutputFormat - <*> pExtendedSigningKeyType + <*> pDerivedExtendedSigningKeyType <*> pAccountNumber <*> pMnemonicSource <*> pSigningKeyFileOut -pExtendedSigningKeyType :: Parser ExtendedSigningType -pExtendedSigningKeyType = +pDerivedExtendedSigningKeyType :: Parser ExtendedSigningType +pDerivedExtendedSigningKeyType = asum [ ( ExtendedSigningPaymentKey <$ ( Opt.flag' () $ diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index f40e60dba6..ac97b55b78 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -261,7 +261,7 @@ runExtendedSigningKeyFromMnemonicCmd runExtendedSigningKeyFromMnemonicCmd Cmd.KeyExtendedSigningKeyFromMnemonicArgs { keyOutputFormat - , extendedSigningKeyType + , derivedExtendedSigningKeyType , derivationAccountNo , mnemonicSource , signingKeyFileOut @@ -276,7 +276,7 @@ runExtendedSigningKeyFromMnemonicCmd mnemonicWords <- readMnemonic mnemonicSource - case extendedSigningKeyType of + case derivedExtendedSigningKeyType of Cmd.ExtendedSigningPaymentKey paymentKeyNo -> writeKeyToFile =<< wrapException From c885d131fe67688e82fcd8ee30d2c37cab697a37 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 17:03:35 +0100 Subject: [PATCH 07/14] Add comment to `ExtendedSigningType` type --- cardano-cli/src/Cardano/CLI/Commands/Key.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cardano-cli/src/Cardano/CLI/Commands/Key.hs b/cardano-cli/src/Cardano/CLI/Commands/Key.hs index d36fd360aa..8a27c6f9ed 100644 --- a/cardano-cli/src/Cardano/CLI/Commands/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Commands/Key.hs @@ -83,6 +83,9 @@ data MnemonicSource | MnemonicFromInteractivePrompt deriving Show +-- | Type of the key derived from a mnemonic +-- together with the payment key number in the derivation path +-- for cases where it is applicable. data ExtendedSigningType = ExtendedSigningPaymentKey !Word32 | ExtendedSigningStakeKey !Word32 From be0ec266376bea81664faae8285782126264e39f Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 17:30:23 +0100 Subject: [PATCH 08/14] Rename `key-from-mnemonic` to `--derive-from-mnemonic` --- cardano-cli/src/Cardano/CLI/Options/Key.hs | 2 +- .../cardano-cli-golden/files/golden/help.cli | 240 +++++++++--------- .../files/golden/help/allegra_key.cli | 4 +- .../help/allegra_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/alonzo_key.cli | 4 +- .../help/alonzo_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/babbage_key.cli | 4 +- .../help/babbage_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/conway_key.cli | 4 +- .../help/conway_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/key.cli | 4 +- .../golden/help/key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/latest_key.cli | 4 +- .../help/latest_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/mary_key.cli | 4 +- .../help/mary_key_derive-from-mnemonic.cli | 41 +++ .../files/golden/help/shelley_key.cli | 4 +- .../help/shelley_key_derive-from-mnemonic.cli | 41 +++ 18 files changed, 465 insertions(+), 137 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index ca5cc8653f..956397288a 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -50,7 +50,7 @@ pKeyCmds = [ "Generate a mnemonic sentence that can be used " , "for key derivation." ] - , subParser "key-from-mnemonic" $ + , subParser "derive-from-mnemonic" $ Opt.info pKeyExtendedSigningKeyFromMnemonicCmd $ Opt.progDesc $ mconcat 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 a5fb26186c..a5ba4fff7d 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -65,7 +65,7 @@ Usage: cardano-cli key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -91,20 +91,20 @@ Usage: cardano-cli key generate-mnemonic [--out-file FILEPATH] --size WORD32 Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -1030,7 +1030,7 @@ Usage: cardano-cli shelley key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -1057,20 +1057,20 @@ Usage: cardano-cli shelley key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli shelley key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli shelley key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -2128,7 +2128,7 @@ Usage: cardano-cli allegra key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -2155,20 +2155,20 @@ Usage: cardano-cli allegra key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli allegra key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli allegra key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -3226,7 +3226,7 @@ Usage: cardano-cli mary key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -3253,20 +3253,20 @@ Usage: cardano-cli mary key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli mary key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli mary key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -4314,7 +4314,7 @@ Usage: cardano-cli alonzo key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -4341,20 +4341,20 @@ Usage: cardano-cli alonzo key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli alonzo key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli alonzo key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -5417,7 +5417,7 @@ Usage: cardano-cli babbage key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -5444,20 +5444,20 @@ Usage: cardano-cli babbage key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli babbage key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli babbage key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -6800,7 +6800,7 @@ Usage: cardano-cli conway key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -6827,20 +6827,20 @@ Usage: cardano-cli conway key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli conway key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli conway key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an @@ -8825,7 +8825,7 @@ Usage: cardano-cli latest key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -8852,20 +8852,20 @@ Usage: cardano-cli latest key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. -Usage: cardano-cli latest key key-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 - | --drep-key - | --cc-cold-key - | --cc-hot-key - ) - --account-number WORD32 - ( --mnemonic-from-file FILEPATH - | --mnemonic-from-interactive-prompt - ) - --signing-key-file FILEPATH +Usage: cardano-cli latest key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli index abaf7aa70a..8f6f7d3178 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli allegra key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..71a08a606f --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli allegra key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli index 0964be8c0d..a6bb622a42 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli alonzo key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..0d739e8fc5 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli alonzo key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli index b816e07d2a..ae22fc3ce9 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli babbage key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..8cb6f5e091 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli babbage key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli index 165bab0c1a..68f46d0494 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli conway key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..b64189fe1e --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli conway key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text 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 index bd11f96385..7d110f4c62 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..5ab9215b4d --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli index aaf865acfd..8d035e6029 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli latest key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..ec2d10aee3 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli latest key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli index 1b7116795b..88ef5a27c9 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli mary key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..f1bc7ce724 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli mary key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli index 7193f03b66..ba4b71e50b 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key.cli @@ -2,7 +2,7 @@ Usage: cardano-cli shelley key ( verification-key | non-extended-key | generate-mnemonic - | key-from-mnemonic + | derive-from-mnemonic | convert-byron-key | convert-byron-genesis-vkey | convert-itn-key @@ -24,7 +24,7 @@ Available commands: types. generate-mnemonic Generate a mnemonic sentence that can be used for key derivation. - key-from-mnemonic Derive an extended signing key from a mnemonic + derive-from-mnemonic Derive an extended signing key from a mnemonic sentence. To ensure the safety of the mnemonic phrase, we recommend that key derivation is performed in an air-gapped environment. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli new file mode 100644 index 0000000000..ab7ece9f22 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli @@ -0,0 +1,41 @@ +Usage: cardano-cli shelley key derive-from-mnemonic [--key-output-format STRING] + ( --payment-key + --payment-address-number WORD32 + | --stake-key + --payment-address-number WORD32 + | --drep-key + | --cc-cold-key + | --cc-hot-key + ) + --account-number WORD32 + ( --mnemonic-from-file FILEPATH + | --mnemonic-from-interactive-prompt + ) + --signing-key-file FILEPATH + + Derive an extended signing key from a mnemonic sentence. To ensure the safety + of the mnemonic phrase, we recommend that key derivation is performed in an + air-gapped environment. + +Available options: + --key-output-format STRING + Optional key output format. Accepted output formats + are "text-envelope" and "bech32" (default is + "text-envelope"). + --payment-key Derive an extended payment key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --stake-key Derive an extended stake key. + --payment-address-number WORD32 + Payment address number in the derivation path. + --drep-key Derive an extended DRep key. + --cc-cold-key Derive an extended committee cold key. + --cc-hot-key Derive an extended committee hot key. + --account-number WORD32 Account number in the derivation path. + --mnemonic-from-file FILEPATH + Input text file with the mnemonic. + --mnemonic-from-interactive-prompt + Input the mnemonic through an interactive prompt. + --signing-key-file FILEPATH + Output filepath of the signing key. + -h,--help Show this help text From 82d5200694c466d7bd8ea64a1c2c0ec9ed75ad79 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 17:43:36 +0100 Subject: [PATCH 09/14] Collapse key type and payment key number into one parameter --- cardano-cli/src/Cardano/CLI/Options/Key.hs | 41 ++++++---------- .../cardano-cli-golden/files/golden/help.cli | 48 +++++++------------ .../help/allegra_key_derive-from-mnemonic.cli | 18 ++++--- .../help/alonzo_key_derive-from-mnemonic.cli | 18 ++++--- .../help/babbage_key_derive-from-mnemonic.cli | 18 ++++--- .../help/conway_key_derive-from-mnemonic.cli | 18 ++++--- .../golden/help/key_derive-from-mnemonic.cli | 18 ++++--- .../help/latest_key_derive-from-mnemonic.cli | 18 ++++--- .../help/mary_key_derive-from-mnemonic.cli | 18 ++++--- .../help/shelley_key_derive-from-mnemonic.cli | 18 ++++--- 10 files changed, 94 insertions(+), 139 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 956397288a..50f0433d7d 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -174,24 +174,20 @@ pKeyExtendedSigningKeyFromMnemonicCmd = pDerivedExtendedSigningKeyType :: Parser ExtendedSigningType pDerivedExtendedSigningKeyType = asum - [ ( ExtendedSigningPaymentKey - <$ ( Opt.flag' () $ - mconcat - [ Opt.long "payment-key" - , Opt.help "Derive an extended payment key." - ] - ) - ) - <*> pPaymentAddressNumber - , ( ExtendedSigningStakeKey - <$ ( Opt.flag' () $ - mconcat - [ Opt.long "stake-key" - , Opt.help "Derive an extended stake key." - ] - ) - ) - <*> pPaymentAddressNumber + [ Opt.option (ExtendedSigningPaymentKey <$> integralReader) $ + mconcat + [ Opt.long "payment-key-with-number" + , Opt.metavar "WORD32" + , Opt.help + "Derive an extended payment key with the given payment address number from the derivation path." + ] + , Opt.option (ExtendedSigningStakeKey <$> integralReader) $ + mconcat + [ Opt.long "stake-key-with-number" + , Opt.metavar "WORD32" + , Opt.help + "Derive an extended stake key with the given stake address number from the derivation path." + ] , Opt.flag' ExtendedSigningDRepKey $ mconcat [ Opt.long "drep-key" @@ -220,15 +216,6 @@ pMnemonicSource = ] ] -pPaymentAddressNumber :: Parser Word32 -pPaymentAddressNumber = - Opt.option integralReader $ - mconcat - [ Opt.long "payment-address-number" - , Opt.metavar "WORD32" - , Opt.help "Payment address number in the derivation path." - ] - pAccountNumber :: Parser Word32 pAccountNumber = Opt.option integralReader $ 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 a5ba4fff7d..e1591159be 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -92,10 +92,8 @@ Usage: cardano-cli key generate-mnemonic [--out-file FILEPATH] --size WORD32 Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -1058,10 +1056,8 @@ Usage: cardano-cli shelley key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli shelley key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -2156,10 +2152,8 @@ Usage: cardano-cli allegra key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli allegra key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -3254,10 +3248,8 @@ Usage: cardano-cli mary key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli mary key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -4342,10 +4334,8 @@ Usage: cardano-cli alonzo key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli alonzo key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -5445,10 +5435,8 @@ Usage: cardano-cli babbage key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli babbage key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -6828,10 +6816,8 @@ Usage: cardano-cli conway key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli conway key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -8853,10 +8839,8 @@ Usage: cardano-cli latest key generate-mnemonic [--out-file FILEPATH] Generate a mnemonic sentence that can be used for key derivation. Usage: cardano-cli latest key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli index 71a08a606f..6e2c5ae4de 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli allegra key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli index 0d739e8fc5..2a945cdac0 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli alonzo key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli index 8cb6f5e091..01d5ec7ca4 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli babbage key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli index b64189fe1e..22520f7d05 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli conway key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli index 5ab9215b4d..9cc41bf1f8 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli index ec2d10aee3..d7ad883c76 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli latest key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli index f1bc7ce724..6c163c07bf 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli mary key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli index ab7ece9f22..c9d9a94f33 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli @@ -1,8 +1,6 @@ Usage: cardano-cli shelley key derive-from-mnemonic [--key-output-format STRING] - ( --payment-key - --payment-address-number WORD32 - | --stake-key - --payment-address-number WORD32 + ( --payment-key-with-number WORD32 + | --stake-key-with-number WORD32 | --drep-key | --cc-cold-key | --cc-hot-key @@ -22,12 +20,12 @@ Available options: Optional key output format. Accepted output formats are "text-envelope" and "bech32" (default is "text-envelope"). - --payment-key Derive an extended payment key. - --payment-address-number WORD32 - Payment address number in the derivation path. - --stake-key Derive an extended stake key. - --payment-address-number WORD32 - Payment address number in the derivation path. + --payment-key-with-number WORD32 + Derive an extended payment key with the given payment + address number from the derivation path. + --stake-key-with-number WORD32 + Derive an extended stake key with the given stake + address number from the derivation path. --drep-key Derive an extended DRep key. --cc-cold-key Derive an extended committee cold key. --cc-hot-key Derive an extended committee hot key. From 6a55eca735a82c6f5815dc1c1ca54daf033cf56f Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 17:53:37 +0100 Subject: [PATCH 10/14] Add comment about using pipes with interactive prompt --- cardano-cli/src/Cardano/CLI/Options/Key.hs | 5 ++++- .../files/golden/help/allegra_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/alonzo_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/babbage_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/conway_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/latest_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/mary_key_derive-from-mnemonic.cli | 3 +++ .../files/golden/help/shelley_key_derive-from-mnemonic.cli | 3 +++ 9 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 50f0433d7d..28c8ef60ab 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -212,7 +212,10 @@ pMnemonicSource = , Opt.flag' MnemonicFromInteractivePrompt $ mconcat [ Opt.long "mnemonic-from-interactive-prompt" - , Opt.help "Input the mnemonic through an interactive prompt." + , Opt.help $ + "Input the mnemonic through an interactive prompt. " + <> "This mode also accepts receiving the mnemonic through " + <> "standard input directly, for example, by using a pipe." ] ] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli index 6e2c5ae4de..600bb6e4c6 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli index 2a945cdac0..6756126574 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli index 01d5ec7ca4..b57921d6c7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli index 22520f7d05..324390e473 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli index 9cc41bf1f8..674a8de6c7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli index d7ad883c76..7f52f6005c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli index 6c163c07bf..733f74d363 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/mary_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli index c9d9a94f33..66b3583eeb 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/shelley_key_derive-from-mnemonic.cli @@ -34,6 +34,9 @@ Available options: Input text file with the mnemonic. --mnemonic-from-interactive-prompt Input the mnemonic through an interactive prompt. + This mode also accepts receiving the mnemonic through + standard input directly, for example, by using a + pipe. --signing-key-file FILEPATH Output filepath of the signing key. -h,--help Show this help text From 51c0c94463cadd1551cfce9fd5e0cff8ea9adafe Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 17:55:47 +0100 Subject: [PATCH 11/14] Use `unlines` to print interactive prompt help --- cardano-cli/src/Cardano/CLI/Run/Key.hs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index ac97b55b78..79e363dde8 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -328,15 +328,18 @@ runExtendedSigningKeyFromMnemonicCmd return $ map T.pack $ words $ T.unpack fileText readMnemonic Cmd.MnemonicFromInteractivePrompt = liftIO $ do - putStrLn "" - putStrLn "Please enter your mnemonic sentence." - putStrLn "" - putStrLn " - It should consist of either: 12, 15, 18, 21, or 24 words." - putStrLn " - To terminate, press enter on an empty line." - putStrLn " - To abort you can press CTRL+C." - putStrLn "" - putStrLn "(If your terminal supports it, you can use the TAB key for word completion.)" - putStrLn "" + putStrLn $ + unlines + [ "" + , "Please enter your mnemonic sentence." + , "" + , " - It should consist of either: 12, 15, 18, 21, or 24 words." + , " - To terminate, press enter on an empty line." + , " - To abort you can press CTRL+C." + , "" + , "(If your terminal supports it, you can use the TAB key for word completion.)" + , "" + ] runInputTBehaviorWithPrefs defaultBehavior defaultPrefs settings (inputT ("", "") []) where settings :: Monad m => Settings m From 992e6b929d9afa9a315d0822e896ac97aa641ec2 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 18:19:45 +0100 Subject: [PATCH 12/14] Use `ReadM` in `parseSize` --- cardano-cli/src/Cardano/CLI/Options/Key.hs | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/Options/Key.hs b/cardano-cli/src/Cardano/CLI/Options/Key.hs index 28c8ef60ab..4e70b0a5a0 100644 --- a/cardano-cli/src/Cardano/CLI/Options/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Options/Key.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.CLI.Options.Key @@ -20,6 +21,7 @@ import Data.Text (Text) import GHC.Word (Word32) import Options.Applicative hiding (help, str) import qualified Options.Applicative as Opt +import Options.Applicative.Types (readerAsk) {- HLINT ignore "Use <$>" -} {- HLINT ignore "Move brackets to avoid $" -} @@ -142,7 +144,7 @@ pKeyGenerateMnemonicCmd = pMnemonicSize :: Parser MnemonicSize pMnemonicSize = do option - (maybeReader parseSize) + parseSize ( long "size" <> metavar "WORD32" <> Opt.help @@ -153,13 +155,18 @@ pMnemonicSize = do ) ) where - parseSize :: String -> Maybe MnemonicSize - parseSize "12" = Just MS12 - parseSize "15" = Just MS15 - parseSize "18" = Just MS18 - parseSize "21" = Just MS21 - parseSize "24" = Just MS24 - parseSize _ = Nothing + parseSize :: ReadM MnemonicSize + parseSize = + readerAsk + >>= \case + "12" -> return MS12 + "15" -> return MS15 + "18" -> return MS18 + "21" -> return MS21 + "24" -> return MS24 + invalidSize -> + readerError $ + "Invalid mnemonic size " <> show invalidSize <> "! It must be one of: 12, 15, 18, 21, or 24." pKeyExtendedSigningKeyFromMnemonicCmd :: Parser KeyCmds pKeyExtendedSigningKeyFromMnemonicCmd = From b05b69b37552718d90b0e3a6f139bb8dd70f0bae Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Tue, 26 Nov 2024 18:35:18 +0100 Subject: [PATCH 13/14] Check produced number of mnemonic words is as expected --- cardano-cli/src/Cardano/CLI/Run/Key.hs | 13 +++++++++++++ .../src/Cardano/CLI/Types/Errors/KeyCmdError.hs | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index 79e363dde8..901efcb27f 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -53,6 +53,7 @@ import Cardano.Prelude (isSpace) import qualified Codec.Binary.Bech32 as Bech32 import qualified Control.Exception as Exception +import Control.Monad (when) import Data.Bifunctor (Bifunctor (..)) import Data.ByteString (ByteString) import qualified Data.ByteString as BS @@ -219,11 +220,23 @@ runGenerateMnemonicCmd , mnemonicWords } = do mnemonic <- firstExceptT KeyCmdMnemonicError $ generateMnemonic mnemonicWords + let expectedNumOfMnemonicWords = mnemonicSizeToInt mnemonicWords + obtainedNumOfMnemonicWords = length mnemonic + when (obtainedNumOfMnemonicWords /= expectedNumOfMnemonicWords) $ + left $ + KeyCmdWrongNumOfMnemonics expectedNumOfMnemonicWords obtainedNumOfMnemonicWords case mnemonicOutputFormat of Just outFile -> firstExceptT KeyCmdWriteFileError . newExceptT $ writeTextFile outFile (T.unwords mnemonic) Nothing -> liftIO $ putStrLn $ T.unpack (T.unwords mnemonic) + where + mnemonicSizeToInt :: MnemonicSize -> Int + mnemonicSizeToInt MS12 = 12 + mnemonicSizeToInt MS15 = 15 + mnemonicSizeToInt MS18 = 18 + mnemonicSizeToInt MS21 = 21 + mnemonicSizeToInt MS24 = 24 readExtendedVerificationKeyFile :: VerificationKeyFile In diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs index 6bc8f1e5cd..1a41af1356 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/KeyCmdError.hs @@ -24,6 +24,11 @@ data KeyCmdError | KeyCmdReadMnemonicFileError !(FileError ()) | KeyCmdWriteFileError !(FileError ()) | KeyCmdMnemonicError MnemonicToSigningKeyError + | KeyCmdWrongNumOfMnemonics + !Int + -- ^ Expected number of mnemonics + !Int + -- ^ Actual number of mnemonics | KeyCmdByronKeyFailure !Byron.ByronKeyFailure | -- | Text representation of the parse error. Unfortunately, the actual -- error type isn't exported. @@ -51,6 +56,8 @@ renderKeyCmdError err = prettyError fileErr KeyCmdMnemonicError mnemonicErr -> "Error converting the mnemonic into a key: " <> prettyError mnemonicErr + KeyCmdWrongNumOfMnemonics expected actual -> + "Internal error: expected " <> pretty expected <> " mnemonics, but got " <> pretty actual KeyCmdByronKeyFailure e -> Byron.renderByronKeyFailure e KeyCmdByronKeyParseError errTxt -> From 9dd73013d092008c6abe15950549200a5e2cd776 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Wed, 27 Nov 2024 17:52:18 +0100 Subject: [PATCH 14/14] Move mnemonic-specific functionality to separate module --- cardano-cli/cardano-cli.cabal | 1 + cardano-cli/src/Cardano/CLI/Run/Key.hs | 149 +--------------- cardano-cli/src/Cardano/CLI/Run/Mnemonic.hs | 184 ++++++++++++++++++++ 3 files changed, 194 insertions(+), 140 deletions(-) create mode 100644 cardano-cli/src/Cardano/CLI/Run/Mnemonic.hs diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 7da4bdf71f..8724c7081a 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -147,6 +147,7 @@ library Cardano.CLI.Run.Debug.TransactionView Cardano.CLI.Run.Hash Cardano.CLI.Run.Key + Cardano.CLI.Run.Mnemonic Cardano.CLI.Run.Node Cardano.CLI.Run.Ping Cardano.CLI.TopHandler diff --git a/cardano-cli/src/Cardano/CLI/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Run/Key.hs index 901efcb27f..93aa0218a0 100644 --- a/cardano-cli/src/Cardano/CLI/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Run/Key.hs @@ -1,9 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} -{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.CLI.Run.Key @@ -39,6 +37,7 @@ import qualified Cardano.Api.Ledger as L import qualified Cardano.CLI.Byron.Key as Byron import qualified Cardano.CLI.Commands.Key as Cmd +import Cardano.CLI.Run.Mnemonic (extendedSigningKeyFromMnemonicImpl, generateMnemonicImpl) import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.CardanoAddressSigningKeyConversionError import Cardano.CLI.Types.Errors.ItnKeyConversionError @@ -49,23 +48,16 @@ import qualified Cardano.Crypto.Signing as Byron import qualified Cardano.Crypto.Signing as Byron.Crypto import qualified Cardano.Crypto.Signing as Crypto import qualified Cardano.Crypto.Wallet as Crypto -import Cardano.Prelude (isSpace) import qualified Codec.Binary.Bech32 as Bech32 import qualified Control.Exception as Exception -import Control.Monad (when) import Data.Bifunctor (Bifunctor (..)) import Data.ByteString (ByteString) import qualified Data.ByteString as BS import Data.Function import Data.Text (Text) -import qualified Data.Text as T import qualified Data.Text as Text import qualified Data.Text.Encoding as Text -import System.Console.Haskeline (Completion, InputT, Settings (..), completeWord', - defaultBehavior, defaultPrefs, getInputLineWithInitial, - runInputTBehaviorWithPrefs, simpleCompletion) -import System.Console.Haskeline.Completion (CompletionFunc) import System.Exit (exitFailure) -- Note on these constants: @@ -218,25 +210,7 @@ runGenerateMnemonicCmd Cmd.KeyGenerateMnemonicCmdArgs { mnemonicOutputFormat , mnemonicWords - } = do - mnemonic <- firstExceptT KeyCmdMnemonicError $ generateMnemonic mnemonicWords - let expectedNumOfMnemonicWords = mnemonicSizeToInt mnemonicWords - obtainedNumOfMnemonicWords = length mnemonic - when (obtainedNumOfMnemonicWords /= expectedNumOfMnemonicWords) $ - left $ - KeyCmdWrongNumOfMnemonics expectedNumOfMnemonicWords obtainedNumOfMnemonicWords - case mnemonicOutputFormat of - Just outFile -> - firstExceptT KeyCmdWriteFileError . newExceptT $ - writeTextFile outFile (T.unwords mnemonic) - Nothing -> liftIO $ putStrLn $ T.unpack (T.unwords mnemonic) - where - mnemonicSizeToInt :: MnemonicSize -> Int - mnemonicSizeToInt MS12 = 12 - mnemonicSizeToInt MS15 = 15 - mnemonicSizeToInt MS18 = 18 - mnemonicSizeToInt MS21 = 21 - mnemonicSizeToInt MS24 = 24 + } = generateMnemonicImpl mnemonicWords mnemonicOutputFormat readExtendedVerificationKeyFile :: VerificationKeyFile In @@ -278,118 +252,13 @@ runExtendedSigningKeyFromMnemonicCmd , derivationAccountNo , mnemonicSource , signingKeyFileOut - } = do - let writeKeyToFile - :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) - => SigningKey a -> ExceptT KeyCmdError IO () - writeKeyToFile = writeSigningKeyFile keyOutputFormat signingKeyFileOut - - wrapException :: Either MnemonicToSigningKeyError a -> ExceptT KeyCmdError IO a - wrapException = except . first KeyCmdMnemonicError - - mnemonicWords <- readMnemonic mnemonicSource - - case derivedExtendedSigningKeyType of - Cmd.ExtendedSigningPaymentKey paymentKeyNo -> - writeKeyToFile - =<< wrapException - ( signingKeyFromMnemonicWithPaymentKeyIndex - AsPaymentExtendedKey - mnemonicWords - derivationAccountNo - paymentKeyNo - ) - Cmd.ExtendedSigningStakeKey paymentKeyNo -> - writeKeyToFile - =<< wrapException - ( signingKeyFromMnemonicWithPaymentKeyIndex - AsStakeExtendedKey - mnemonicWords - derivationAccountNo - paymentKeyNo - ) - Cmd.ExtendedSigningDRepKey -> - writeKeyToFile - =<< wrapException (signingKeyFromMnemonic AsDRepExtendedKey mnemonicWords derivationAccountNo) - Cmd.ExtendedSigningCCColdKey -> - writeKeyToFile - =<< wrapException - (signingKeyFromMnemonic AsCommitteeColdExtendedKey mnemonicWords derivationAccountNo) - Cmd.ExtendedSigningCCHotKey -> - writeKeyToFile - =<< wrapException - (signingKeyFromMnemonic AsCommitteeHotExtendedKey mnemonicWords derivationAccountNo) - where - writeSigningKeyFile - :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) - => KeyOutputFormat -> SigningKeyFile Out -> SigningKey a -> ExceptT KeyCmdError IO () - writeSigningKeyFile fmt sKeyPath skey = - firstExceptT KeyCmdWriteFileError $ - case fmt of - KeyOutputFormatTextEnvelope -> - newExceptT $ - writeLazyByteStringFile sKeyPath $ - textEnvelopeToJSON Nothing skey - KeyOutputFormatBech32 -> - newExceptT $ - writeTextFile sKeyPath $ - serialiseToBech32 skey - - readMnemonic :: Cmd.MnemonicSource -> ExceptT KeyCmdError IO [Text] - readMnemonic (Cmd.MnemonicFromFile filePath) = do - fileText <- firstExceptT KeyCmdReadMnemonicFileError $ except =<< readTextFile filePath - return $ map T.pack $ words $ T.unpack fileText - readMnemonic Cmd.MnemonicFromInteractivePrompt = - liftIO $ do - putStrLn $ - unlines - [ "" - , "Please enter your mnemonic sentence." - , "" - , " - It should consist of either: 12, 15, 18, 21, or 24 words." - , " - To terminate, press enter on an empty line." - , " - To abort you can press CTRL+C." - , "" - , "(If your terminal supports it, you can use the TAB key for word completion.)" - , "" - ] - runInputTBehaviorWithPrefs defaultBehavior defaultPrefs settings (inputT ("", "") []) - where - settings :: Monad m => Settings m - settings = - Settings - { complete = completionFunc - , historyFile = Nothing - , autoAddHistory = False - } - - completionFunc :: Monad m => CompletionFunc m - completionFunc = completeWord' Nothing isSpace completeMnemonicWord - - completeMnemonicWord :: Monad m => String -> m [Completion] - completeMnemonicWord prefix = return $ map (simpleCompletion . T.unpack . fst) $ findMnemonicWordsWithPrefix (T.pack prefix) - - inputT :: (String, String) -> [Text] -> InputT IO [Text] - inputT prefill mnemonic = do - minput <- getInputLineWithInitial (show (length mnemonic + 1) <> ". ") prefill - case minput of - Nothing -> return $ reverse mnemonic - Just "" -> return $ reverse mnemonic - Just input -> - let newWords = map (T.toLower . T.pack) $ filter (not . null) $ words input - in case span isValidMnemonicWord newWords of - (allWords, []) -> inputT ("", "") (reverse allWords ++ mnemonic) - (validWords, invalidWord : notValidatedWords) -> do - liftIO $ putStrLn $ "The word \"" <> T.unpack invalidWord <> "\" is not in the memonic dictionary" - let textBeforeCursor = unwords (map T.unpack validWords <> [T.unpack invalidWord]) - textAfterCursor = - if null notValidatedWords - then "" - else ' ' : unwords (map T.unpack notValidatedWords) - inputT (textBeforeCursor, textAfterCursor) mnemonic - - isValidMnemonicWord :: Text -> Bool - isValidMnemonicWord word = word `elem` map fst (findMnemonicWordsWithPrefix word) + } = + extendedSigningKeyFromMnemonicImpl + keyOutputFormat + derivedExtendedSigningKeyType + derivationAccountNo + mnemonicSource + signingKeyFileOut runConvertByronKeyCmd :: Cmd.KeyConvertByronKeyCmdArgs diff --git a/cardano-cli/src/Cardano/CLI/Run/Mnemonic.hs b/cardano-cli/src/Cardano/CLI/Run/Mnemonic.hs new file mode 100644 index 0000000000..50b2ec086e --- /dev/null +++ b/cardano-cli/src/Cardano/CLI/Run/Mnemonic.hs @@ -0,0 +1,184 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} + +module Cardano.CLI.Run.Mnemonic (generateMnemonicImpl, extendedSigningKeyFromMnemonicImpl) where + +import Cardano.Api + (AsType (AsCommitteeColdExtendedKey, AsCommitteeHotExtendedKey, AsDRepExtendedKey, AsPaymentExtendedKey, AsStakeExtendedKey), + ExceptT, File, FileDirection (Out), HasTextEnvelope, Key (SigningKey), + MnemonicSize (..), MnemonicToSigningKeyError, MonadIO (..), SerialiseAsBech32, + except, findMnemonicWordsWithPrefix, firstExceptT, generateMnemonic, left, + newExceptT, readTextFile, serialiseToBech32, signingKeyFromMnemonic, + signingKeyFromMnemonicWithPaymentKeyIndex, textEnvelopeToJSON, + writeLazyByteStringFile, writeTextFile) + +import qualified Cardano.CLI.Commands.Key as Cmd +import Cardano.CLI.Types.Common (KeyOutputFormat (..), SigningKeyFile) +import Cardano.CLI.Types.Errors.KeyCmdError + (KeyCmdError (KeyCmdMnemonicError, KeyCmdReadMnemonicFileError, KeyCmdWriteFileError, KeyCmdWrongNumOfMnemonics)) +import Cardano.Prelude (isSpace) + +import Control.Monad (when) +import Data.Bifunctor (Bifunctor (..)) +import Data.Text (Text) +import qualified Data.Text as T +import Data.Word (Word32) +import System.Console.Haskeline (Completion, InputT, Settings (..), completeWord', + defaultBehavior, defaultPrefs, getInputLineWithInitial, + runInputTBehaviorWithPrefs, simpleCompletion) +import System.Console.Haskeline.Completion (CompletionFunc) + +-- | Generate a mnemonic and write it to a file or stdout. +generateMnemonicImpl + :: MonadIO m + => MnemonicSize + -- ^ The number of words in the mnemonic. + -> Maybe (File () Out) + -- ^ The file to write the mnemonic to. If 'Nothing', write to stdout. + -> ExceptT KeyCmdError m () +generateMnemonicImpl mnemonicWords mnemonicOutputFormat = do + mnemonic <- firstExceptT KeyCmdMnemonicError $ generateMnemonic mnemonicWords + let expectedNumOfMnemonicWords = mnemonicSizeToInt mnemonicWords + obtainedNumOfMnemonicWords = length mnemonic + when (obtainedNumOfMnemonicWords /= expectedNumOfMnemonicWords) $ + left $ + KeyCmdWrongNumOfMnemonics expectedNumOfMnemonicWords obtainedNumOfMnemonicWords + case mnemonicOutputFormat of + Just outFile -> + firstExceptT KeyCmdWriteFileError . newExceptT $ + writeTextFile outFile (T.unwords mnemonic) + Nothing -> liftIO $ putStrLn $ T.unpack (T.unwords mnemonic) + where + mnemonicSizeToInt :: MnemonicSize -> Int + mnemonicSizeToInt MS12 = 12 + mnemonicSizeToInt MS15 = 15 + mnemonicSizeToInt MS18 = 18 + mnemonicSizeToInt MS21 = 21 + mnemonicSizeToInt MS24 = 24 + +-- | Derive an extended signing key from a mnemonic and write it to a file. +extendedSigningKeyFromMnemonicImpl + :: KeyOutputFormat + -- ^ The format in which to write the signing key. + -> Cmd.ExtendedSigningType + -- ^ The type of the extended signing key to derive with an optional payment key index. + -> Word32 + -- ^ The account index. + -> Cmd.MnemonicSource + -- ^ The source of the mnemonic (either file or stdin). + -> SigningKeyFile Out + -- ^ The file to write the signing key to. + -> ExceptT KeyCmdError IO () +extendedSigningKeyFromMnemonicImpl keyOutputFormat derivedExtendedSigningKeyType derivationAccountNo mnemonicSource signingKeyFileOut = + do + let writeKeyToFile + :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) + => SigningKey a -> ExceptT KeyCmdError IO () + writeKeyToFile = writeSigningKeyFile keyOutputFormat signingKeyFileOut + + wrapException :: Either MnemonicToSigningKeyError a -> ExceptT KeyCmdError IO a + wrapException = except . first KeyCmdMnemonicError + + mnemonicWords <- readMnemonic mnemonicSource + + case derivedExtendedSigningKeyType of + Cmd.ExtendedSigningPaymentKey paymentKeyNo -> + writeKeyToFile + =<< wrapException + ( signingKeyFromMnemonicWithPaymentKeyIndex + AsPaymentExtendedKey + mnemonicWords + derivationAccountNo + paymentKeyNo + ) + Cmd.ExtendedSigningStakeKey paymentKeyNo -> + writeKeyToFile + =<< wrapException + ( signingKeyFromMnemonicWithPaymentKeyIndex + AsStakeExtendedKey + mnemonicWords + derivationAccountNo + paymentKeyNo + ) + Cmd.ExtendedSigningDRepKey -> + writeKeyToFile + =<< wrapException (signingKeyFromMnemonic AsDRepExtendedKey mnemonicWords derivationAccountNo) + Cmd.ExtendedSigningCCColdKey -> + writeKeyToFile + =<< wrapException + (signingKeyFromMnemonic AsCommitteeColdExtendedKey mnemonicWords derivationAccountNo) + Cmd.ExtendedSigningCCHotKey -> + writeKeyToFile + =<< wrapException + (signingKeyFromMnemonic AsCommitteeHotExtendedKey mnemonicWords derivationAccountNo) + where + writeSigningKeyFile + :: (HasTextEnvelope (SigningKey a), SerialiseAsBech32 (SigningKey a)) + => KeyOutputFormat -> SigningKeyFile Out -> SigningKey a -> ExceptT KeyCmdError IO () + writeSigningKeyFile fmt sKeyPath skey = + firstExceptT KeyCmdWriteFileError $ + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT $ + writeLazyByteStringFile sKeyPath $ + textEnvelopeToJSON Nothing skey + KeyOutputFormatBech32 -> + newExceptT $ + writeTextFile sKeyPath $ + serialiseToBech32 skey + + readMnemonic :: Cmd.MnemonicSource -> ExceptT KeyCmdError IO [Text] + readMnemonic (Cmd.MnemonicFromFile filePath) = do + fileText <- firstExceptT KeyCmdReadMnemonicFileError $ except =<< readTextFile filePath + return $ map T.pack $ words $ T.unpack fileText + readMnemonic Cmd.MnemonicFromInteractivePrompt = + liftIO $ do + putStrLn $ + unlines + [ "" + , "Please enter your mnemonic sentence." + , "" + , " - It should consist of either: 12, 15, 18, 21, or 24 words." + , " - To terminate, press enter on an empty line." + , " - To abort you can press CTRL+C." + , "" + , "(If your terminal supports it, you can use the TAB key for word completion.)" + , "" + ] + runInputTBehaviorWithPrefs defaultBehavior defaultPrefs settings (inputT ("", "") []) + where + settings :: Monad m => Settings m + settings = + Settings + { complete = completionFunc + , historyFile = Nothing + , autoAddHistory = False + } + + completionFunc :: Monad m => CompletionFunc m + completionFunc = completeWord' Nothing isSpace completeMnemonicWord + + completeMnemonicWord :: Monad m => String -> m [Completion] + completeMnemonicWord prefix = return $ map (simpleCompletion . T.unpack . fst) $ findMnemonicWordsWithPrefix (T.pack prefix) + + inputT :: (String, String) -> [Text] -> InputT IO [Text] + inputT prefill mnemonic = do + minput <- getInputLineWithInitial (show (length mnemonic + 1) <> ". ") prefill + case minput of + Nothing -> return $ reverse mnemonic + Just "" -> return $ reverse mnemonic + Just input -> + let newWords = map (T.toLower . T.pack) $ filter (not . null) $ words input + in case span isValidMnemonicWord newWords of + (allWords, []) -> inputT ("", "") (reverse allWords ++ mnemonic) + (validWords, invalidWord : notValidatedWords) -> do + liftIO $ putStrLn $ "The word \"" <> T.unpack invalidWord <> "\" is not in the memonic dictionary" + let textBeforeCursor = unwords (map T.unpack validWords <> [T.unpack invalidWord]) + textAfterCursor = + if null notValidatedWords + then "" + else ' ' : unwords (map T.unpack notValidatedWords) + inputT (textBeforeCursor, textAfterCursor) mnemonic + + isValidMnemonicWord :: Text -> Bool + isValidMnemonicWord word = word `elem` map fst (findMnemonicWordsWithPrefix word)