diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Key.hs b/cardano-cli/src/Cardano/CLI/Shelley/Key.hs index 3c73065b0f2..e4c35287584 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Key.hs @@ -6,10 +6,7 @@ -- | Shelley CLI option data types and functions for cryptographic keys. module Cardano.CLI.Shelley.Key - ( readSigningKeyFile - , readSigningKeyFileAnyOf - - , VerificationKeyOrFile (..) + ( VerificationKeyOrFile (..) , readVerificationKeyOrFile , readVerificationKeyOrTextEnvFile @@ -38,41 +35,6 @@ import qualified Data.Text.Encoding as Text import Cardano.CLI.Types ------------------------------------------------------------------------------- --- Signing key deserialisation ------------------------------------------------------------------------------- - --- | Read a signing key from a file. --- --- The contents of the file can either be Bech32-encoded, hex-encoded, or in --- the text envelope format. -readSigningKeyFile - :: forall keyrole. - ( HasTextEnvelope (SigningKey keyrole) - , SerialiseAsBech32 (SigningKey keyrole) - ) - => AsType keyrole - -> SigningKeyFile - -> IO (Either (FileError InputDecodeError) (SigningKey keyrole)) -readSigningKeyFile asType (SigningKeyFile fp) = - readKeyFile - (AsSigningKey asType) - (NE.fromList [InputFormatBech32, InputFormatHex, InputFormatTextEnvelope]) - fp - --- | Read a signing key from a file given that it is one of the provided types --- of signing key. --- --- The contents of the file can either be Bech32-encoded or in the text --- envelope format. -readSigningKeyFileAnyOf - :: forall b. - [FromSomeType SerialiseAsBech32 b] - -> [FromSomeType HasTextEnvelope b] - -> SigningKeyFile - -> IO (Either (FileError InputDecodeError) b) -readSigningKeyFileAnyOf bech32Types textEnvTypes (SigningKeyFile fp) = - readKeyFileAnyOf bech32Types textEnvTypes fp ------------------------------------------------------------------------------ -- Verification key deserialisation diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Key.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Key.hs index bebbade205e..7aaa1ea9570 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Key.hs @@ -38,8 +38,8 @@ import Cardano.Api.Shelley import qualified Cardano.CLI.Byron.Key as Byron import Cardano.CLI.Shelley.Commands import Cardano.CLI.Shelley.Key (VerificationKeyTextOrFile (..), - VerificationKeyTextOrFileError, readSigningKeyFileAnyOf, - readVerificationKeyTextOrFileAnyOf, renderVerificationKeyTextOrFileError) + VerificationKeyTextOrFileError, readVerificationKeyTextOrFileAnyOf, + renderVerificationKeyTextOrFileError) import Cardano.CLI.Types (SigningKeyFile (..), VerificationKeyFile (..)) @@ -156,9 +156,9 @@ withSomeSigningKey ssk f = readSigningKeyFile :: SigningKeyFile -> ExceptT (FileError InputDecodeError) IO SomeSigningKey -readSigningKeyFile skFile = +readSigningKeyFile (SigningKeyFile skFile) = newExceptT $ - readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile + readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile where textEnvFileTypes = [ FromSomeType (AsSigningKey AsByronKey) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs index 7f83eb272c7..8681faefb68 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs @@ -22,8 +22,7 @@ import Cardano.Api import Cardano.Api.Shelley import Cardano.CLI.Shelley.Commands -import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readSigningKeyFileAnyOf, - readVerificationKeyOrFile) +import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile) import Cardano.CLI.Types (SigningKeyFile (..), VerificationKeyFile (..)) {- HLINT ignore "Reduce duplication" -} @@ -178,7 +177,7 @@ runNodeIssueOpCert :: VerificationKeyOrFile KesKey -> OutputFile -> ExceptT ShelleyNodeCmdError IO () runNodeIssueOpCert kesVerKeyOrFile - stakePoolSKeyFile + (SigningKeyFile stakePoolSKeyFile) (OpCertCounterFile ocertCtrPath) kesPeriod (OutputFile certFile) = do @@ -193,7 +192,7 @@ runNodeIssueOpCert kesVerKeyOrFile signKey <- firstExceptT ShelleyNodeCmdReadKeyFileError . newExceptT - $ readSigningKeyFileAnyOf + $ readKeyFileAnyOf bech32PossibleBlockIssuers textEnvPossibleBlockIssuers stakePoolSKeyFile diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs index 744b83be55d..e15ab96d171 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Read.hs @@ -74,7 +74,6 @@ import Cardano.Api.Shelley import qualified Cardano.Binary as CBOR import Data.Text (Text) -import Cardano.CLI.Shelley.Key import Cardano.CLI.Shelley.Parsers import Cardano.CLI.Types @@ -640,9 +639,9 @@ renderReadWitnessSigningDataError err = readWitnessSigningData :: WitnessSigningData -> IO (Either ReadWitnessSigningDataError SomeWitness) -readWitnessSigningData (KeyWitnessSigningData skFile mbByronAddr) = do +readWitnessSigningData (KeyWitnessSigningData (SigningKeyFile skFile) mbByronAddr) = do eRes <- first ReadWitnessSigningDataSigningKeyDecodeError - <$> readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile + <$> readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile return $ do res <- eRes case (res, mbByronAddr) of @@ -706,8 +705,8 @@ instance Error RequiredSignerError where readRequiredSigner :: RequiredSigner -> IO (Either RequiredSignerError (Hash PaymentKey)) readRequiredSigner (RequiredSignerHash h) = return $ Right h -readRequiredSigner (RequiredSignerSkeyFile skFile) = do - eKeyWit <- first RequiredSignerErrorFile <$> readSigningKeyFileAnyOf bech32FileTypes textEnvFileTypes skFile +readRequiredSigner (RequiredSignerSkeyFile skFile@(SigningKeyFile skFp)) = do + eKeyWit <- first RequiredSignerErrorFile <$> readKeyFileAnyOf bech32FileTypes textEnvFileTypes skFp return $ do keyWit <- eKeyWit case categoriseSomeWitness keyWit of