diff --git a/cardano-cli/CHANGELOG.md b/cardano-cli/CHANGELOG.md index ee66aa8657f..7a293bb8007 100644 --- a/cardano-cli/CHANGELOG.md +++ b/cardano-cli/CHANGELOG.md @@ -56,6 +56,18 @@ ([PR5119](https://github.com/input-output-hk/cardano-node/pull/5119)) ([PR5119](https://github.com/input-output-hk/cardano-node/pull/5119)) +- Add `--out-file` argument to the shelley stake-pool id command. + Add `--key-format-output` argument to the following commands: + - `address key-gen` + - `stake-address key-gen` + - `node key-gen` + - `node key-gen-KES` + - `node key-gen-VRF` + - `genesis create-staked` + - `genesis create` + [PR5058](https://github.com/input-output-hk/cardano-node/pull/5058) + + ### Features - The `--socket-path` option is now a required CLI argument for relevant commands if `CARDANO_NODE_SOCKET_PATH` is not supplied. diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 17fa632bf70..1497a9bc87b 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -252,6 +252,7 @@ test-suite cardano-cli-golden , hedgehog ^>= 1.2 , hedgehog-extras ^>= 0.4.5.1 , regex-compat + , regex-tdfa , text , time , transformers diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs index 5f035720464..2d9ba65dd59 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE UndecidableInstances #-} @@ -38,6 +39,7 @@ module Cardano.CLI.Shelley.Commands , VerificationKeyBase64 (..) , GenesisKeyFile (..) , MetadataFile (..) + , StakePoolMetadataFile , PrivKeyFile (..) , BlockId (..) , WitnessSigningData (..) @@ -91,7 +93,7 @@ renderShelleyCommand sc = TextViewCmd cmd -> renderTextViewCmd cmd data AddressCmd - = AddressKeyGen AddressKeyType (VerificationKeyFile Out) (SigningKeyFile Out) + = AddressKeyGen KeyOutputFormat AddressKeyType (VerificationKeyFile Out) (SigningKeyFile Out) | AddressKeyHash VerificationKeyTextOrFile (Maybe (File () Out)) | AddressBuild PaymentVerifier @@ -111,7 +113,7 @@ renderAddressCmd cmd = AddressInfo {} -> "address info" data StakeAddressCmd - = StakeAddressKeyGen (VerificationKeyFile Out) (SigningKeyFile Out) + = StakeAddressKeyGen KeyOutputFormat (VerificationKeyFile Out) (SigningKeyFile Out) | StakeAddressKeyHash (VerificationKeyOrFile StakeKey) (Maybe (File () Out)) | StakeAddressBuild StakeVerifier NetworkId (Maybe (File () Out)) | StakeRegistrationCert StakeIdentifier (File () Out) @@ -275,9 +277,9 @@ renderTransactionCmd cmd = TxView {} -> "transaction view" data NodeCmd - = NodeKeyGenCold (VerificationKeyFile Out) (SigningKeyFile Out) (OpCertCounterFile Out) - | NodeKeyGenKES (VerificationKeyFile Out) (SigningKeyFile Out) - | NodeKeyGenVRF (VerificationKeyFile Out) (SigningKeyFile Out) + = NodeKeyGenCold KeyOutputFormat (VerificationKeyFile Out) (SigningKeyFile Out) (OpCertCounterFile Out) + | NodeKeyGenKES KeyOutputFormat (VerificationKeyFile Out) (SigningKeyFile Out) + | NodeKeyGenVRF KeyOutputFormat (VerificationKeyFile Out) (SigningKeyFile Out) | NodeKeyHashVRF (VerificationKeyOrFile VrfKey) (Maybe (File () Out)) | NodeNewCounter ColdVerificationKeyOrFile Word (OpCertCounterFile InOut) | NodeIssueOpCert (VerificationKeyOrFile KesKey) (SigningKeyFile In) (OpCertCounterFile InOut) @@ -323,8 +325,8 @@ data PoolCmd EpochNo -- ^ Epoch in which to retire the stake pool. (File Certificate Out) - | PoolGetId (VerificationKeyOrFile StakePoolKey) OutputFormat - | PoolMetadataHash (File StakePoolMetadata In) (Maybe (File () Out)) + | PoolGetId (VerificationKeyOrFile StakePoolKey) PoolIdOutputFormat (Maybe (File () Out)) + | PoolMetadataHash (StakePoolMetadataFile In) (Maybe (File () Out)) deriving Show renderPoolCmd :: PoolCmd -> Text @@ -448,9 +450,17 @@ renderTextViewCmd :: TextViewCmd -> Text renderTextViewCmd (TextViewInfo _ _) = "text-view decode-cbor" data GenesisCmd - = GenesisCreate GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) NetworkId + = GenesisCreate + KeyOutputFormat + GenesisDir + Word + Word + (Maybe SystemStart) + (Maybe Lovelace) + NetworkId | GenesisCreateCardano GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) BlockCount Word Rational NetworkId FilePath FilePath FilePath FilePath (Maybe FilePath) | GenesisCreateStaked + KeyOutputFormat GenesisDir Word Word @@ -526,6 +536,8 @@ data MetadataFile = MetadataFileJSON (File () In) deriving Show +type StakePoolMetadataFile = File StakePoolMetadata + newtype GenesisDir = GenesisDir FilePath deriving Show diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index 5741a2b9978..07b31ff4310 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -144,10 +144,12 @@ pAddressCmd envCli = ] where pAddressKeyGen :: Parser AddressCmd - pAddressKeyGen = AddressKeyGen - <$> pAddressKeyType - <*> pVerificationKeyFileOut - <*> pSigningKeyFileOut + pAddressKeyGen = + AddressKeyGen + <$> pKeyOutputFormat + <*> pAddressKeyType + <*> pVerificationKeyFileOut + <*> pSigningKeyFileOut pAddressKeyHash :: Parser AddressCmd pAddressKeyHash = @@ -382,7 +384,8 @@ pStakeAddressCmd envCli = pStakeAddressKeyGen :: Parser StakeAddressCmd pStakeAddressKeyGen = StakeAddressKeyGen - <$> pVerificationKeyFileOut + <$> pKeyOutputFormat + <*> pVerificationKeyFileOut <*> pSigningKeyFileOut pStakeAddressKeyHash :: Parser StakeAddressCmd @@ -863,17 +866,24 @@ pNodeCmd = pKeyGenOperator :: Parser NodeCmd pKeyGenOperator = NodeKeyGenCold - <$> pColdVerificationKeyFile + <$> pKeyOutputFormat + <*> pColdVerificationKeyFile <*> pColdSigningKeyFile <*> pOperatorCertIssueCounterFile pKeyGenKES :: Parser NodeCmd pKeyGenKES = - NodeKeyGenKES <$> pVerificationKeyFileOut <*> pSigningKeyFileOut + NodeKeyGenKES + <$> pKeyOutputFormat + <*> pVerificationKeyFileOut + <*> pSigningKeyFileOut pKeyGenVRF :: Parser NodeCmd pKeyGenVRF = - NodeKeyGenVRF <$> pVerificationKeyFileOut <*> pSigningKeyFileOut + NodeKeyGenVRF + <$> pKeyOutputFormat + <*> pVerificationKeyFileOut + <*> pSigningKeyFileOut pKeyHashVRF :: Parser NodeCmd pKeyHashVRF = @@ -916,7 +926,7 @@ pPoolCmd envCli = ] where pId :: Parser PoolCmd - pId = PoolGetId <$> pStakePoolVerificationKeyOrFile <*> pOutputFormat + pId = PoolGetId <$> pStakePoolVerificationKeyOrFile <*> pPoolIdOutputFormat <*> pMaybeOutputFile pPoolMetadataHashSubCmd :: Parser PoolCmd pPoolMetadataHashSubCmd = PoolMetadataHash <$> pPoolMetadataFile <*> pMaybeOutputFile @@ -1387,7 +1397,8 @@ pGenesisCmd envCli = pGenesisCreate :: Parser GenesisCmd pGenesisCreate = GenesisCreate - <$> pGenesisDir + <$> pKeyOutputFormat + <*> pGenesisDir <*> pGenesisNumGenesisKeys <*> pGenesisNumUTxOKeys <*> pMaybeSystemStart @@ -1397,7 +1408,8 @@ pGenesisCmd envCli = pGenesisCreateStaked :: Parser GenesisCmd pGenesisCreateStaked = GenesisCreateStaked - <$> pGenesisDir + <$> pKeyOutputFormat + <*> pGenesisDir <*> pGenesisNumGenesisKeys <*> pGenesisNumUTxOKeys <*> pGenesisNumPools @@ -1638,7 +1650,7 @@ pCertificateFile balanceExecUnits = , "stake key certificates etc). Optionally specify a script witness." ] -pPoolMetadataFile :: Parser (File StakePoolMetadata In) +pPoolMetadataFile :: Parser (StakePoolMetadataFile In) pPoolMetadataFile = fmap File $ Opt.strOption $ mconcat [ Opt.long "pool-metadata-file" @@ -1923,15 +1935,29 @@ pOperationalCertificateFile = <> Opt.completer (Opt.bashCompleter "file") ) -pOutputFormat :: Parser OutputFormat -pOutputFormat = - Opt.option readOutputFormat - ( Opt.long "output-format" - <> Opt.metavar "STRING" - <> Opt.help "Optional output format. Accepted output formats are \"hex\" \ - \and \"bech32\" (default is \"bech32\")." - <> Opt.value OutputFormatBech32 - ) +pKeyOutputFormat :: Parser KeyOutputFormat +pKeyOutputFormat = + Opt.option readKeyOutputFormat $ mconcat + [ Opt.long "key-output-format" + , Opt.metavar "STRING" + , Opt.help $ mconcat + [ "Optional key output format. Accepted output formats are \"text-envelope\" " + , "and \"bech32\" (default is \"bech32\")." + ] + , Opt.value KeyOutputFormatTextEnvelope + ] + +pPoolIdOutputFormat :: Parser PoolIdOutputFormat +pPoolIdOutputFormat = + Opt.option readPoolIdOutputFormat $ mconcat + [ Opt.long "output-format" + , Opt.metavar "STRING" + , Opt.help $ mconcat + [ "Optional pool id output format. Accepted output formats are \"hex\" " + , "and \"bech32\" (default is \"bech32\")." + ] + , Opt.value PoolIdOutputFormatBech32 + ] pMaybeOutputFile :: Parser (Maybe (File content Out)) pMaybeOutputFile = @@ -3380,16 +3406,29 @@ readVerificationKey asType = first (Text.unpack . renderInputDecodeError) $ deserialiseInput (AsVerificationKey asType) keyFormats (BSC.pack str) -readOutputFormat :: Opt.ReadM OutputFormat -readOutputFormat = do - s <- Opt.str +readPoolIdOutputFormat :: Opt.ReadM PoolIdOutputFormat +readPoolIdOutputFormat = do + s <- Opt.str @String + case s of + "hex" -> pure PoolIdOutputFormatHex + "bech32" -> pure PoolIdOutputFormatBech32 + _ -> + fail $ mconcat + [ "Invalid output format: " <> show s + , ". Accepted output formats are \"hex\" and \"bech32\"." + ] + +readKeyOutputFormat :: Opt.ReadM KeyOutputFormat +readKeyOutputFormat = do + s <- Opt.str @String case s of - "hex" -> pure OutputFormatHex - "bech32" -> pure OutputFormatBech32 + "text-envelope" -> pure KeyOutputFormatTextEnvelope + "bech32" -> pure KeyOutputFormatBech32 _ -> - fail $ "Invalid output format: \"" - <> s - <> "\". Accepted output formats are \"hex\" and \"bech32\"." + fail $ mconcat + [ "Invalid key output format: " <> show s + , ". Accepted output formats are \"text-envelope\" and \"bech32\"." + ] readURIOfMaxLength :: Int -> Opt.ReadM Text readURIOfMaxLength maxLen = diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs index 406e1975d70..f339660d15e 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Address.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} @@ -59,39 +60,90 @@ renderShelleyAddressCmdError err = runAddressCmd :: AddressCmd -> ExceptT ShelleyAddressCmdError IO () runAddressCmd cmd = case cmd of - AddressKeyGen kt vkf skf -> runAddressKeyGenToFile kt vkf skf + AddressKeyGen fmt kt vkf skf -> runAddressKeyGenToFile fmt kt vkf skf AddressKeyHash vkf mOFp -> runAddressKeyHash vkf mOFp AddressBuild paymentVerifier mbStakeVerifier nw mOutFp -> runAddressBuild paymentVerifier mbStakeVerifier nw mOutFp AddressInfo txt mOFp -> firstExceptT ShelleyAddressCmdAddressInfoError $ runAddressInfo txt mOFp runAddressKeyGenToFile - :: AddressKeyType + :: KeyOutputFormat + -> AddressKeyType -> VerificationKeyFile Out -> SigningKeyFile Out -> ExceptT ShelleyAddressCmdError IO () -runAddressKeyGenToFile kt vkf skf = case kt of - AddressKeyShelley -> generateAndWriteKeyFiles AsPaymentKey vkf skf - AddressKeyShelleyExtended -> generateAndWriteKeyFiles AsPaymentExtendedKey vkf skf - AddressKeyByron -> generateAndWriteKeyFiles AsByronKey vkf skf +runAddressKeyGenToFile fmt kt vkf skf = case kt of + AddressKeyShelley -> generateAndWriteKeyFiles fmt AsPaymentKey vkf skf + AddressKeyShelleyExtended -> generateAndWriteKeyFiles fmt AsPaymentExtendedKey vkf skf + AddressKeyByron -> generateAndWriteByronKeyFiles AsByronKey vkf skf -generateAndWriteKeyFiles +generateAndWriteByronKeyFiles :: Key keyrole => AsType keyrole -> VerificationKeyFile Out -> SigningKeyFile Out -> ExceptT ShelleyAddressCmdError IO () -generateAndWriteKeyFiles asType vkf skf = do - uncurry (writePaymentKeyFiles vkf skf) =<< liftIO (generateKeyPair asType) +generateAndWriteByronKeyFiles asType vkf skf = do + uncurry (writeByronPaymentKeyFiles vkf skf) =<< liftIO (generateKeyPair asType) + +generateAndWriteKeyFiles + :: Key keyrole + => SerialiseAsBech32 (SigningKey keyrole) + => SerialiseAsBech32 (VerificationKey keyrole) + => KeyOutputFormat + -> AsType keyrole + -> VerificationKeyFile Out + -> SigningKeyFile Out + -> ExceptT ShelleyAddressCmdError IO () +generateAndWriteKeyFiles fmt asType vkf skf = do + uncurry (writePaymentKeyFiles fmt vkf skf) =<< liftIO (generateKeyPair asType) writePaymentKeyFiles :: Key keyrole - => VerificationKeyFile Out + => SerialiseAsBech32 (SigningKey keyrole) + => SerialiseAsBech32 (VerificationKey keyrole) + => KeyOutputFormat + -> VerificationKeyFile Out -> SigningKeyFile Out -> VerificationKey keyrole -> SigningKey keyrole -> ExceptT ShelleyAddressCmdError IO () -writePaymentKeyFiles vkeyPath skeyPath vkey skey = do +writePaymentKeyFiles fmt vkeyPath skeyPath vkey skey = do + firstExceptT ShelleyAddressCmdWriteFileError $ do + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT + $ writeLazyByteStringFile skeyPath + $ textEnvelopeToJSON (Just skeyDesc) skey + KeyOutputFormatBech32 -> + newExceptT + $ writeTextFile skeyPath + $ serialiseToBech32 skey + + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT + $ writeLazyByteStringFile vkeyPath + $ textEnvelopeToJSON (Just vkeyDesc) vkey + KeyOutputFormatBech32 -> + newExceptT + $ writeTextFile vkeyPath + $ serialiseToBech32 vkey + + where + skeyDesc, vkeyDesc :: TextEnvelopeDescr + skeyDesc = "Payment Signing Key" + vkeyDesc = "Payment Verification Key" + +writeByronPaymentKeyFiles + :: Key keyrole + => VerificationKeyFile Out + -> SigningKeyFile Out + -> VerificationKey keyrole + -> SigningKey keyrole + -> ExceptT ShelleyAddressCmdError IO () +writeByronPaymentKeyFiles vkeyPath skeyPath vkey skey = do firstExceptT ShelleyAddressCmdWriteFileError $ do + -- No bech32 encoding for Byron keys newExceptT $ writeLazyByteStringFile skeyPath $ textEnvelopeToJSON (Just skeyDesc) skey newExceptT $ writeLazyByteStringFile vkeyPath $ textEnvelopeToJSON (Just vkeyDesc) vkey where diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs index 2006caf14c1..a947119acad 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Genesis.hs @@ -218,10 +218,10 @@ runGenesisCmd (GenesisCmdKeyHash vk) = runGenesisKeyHash vk runGenesisCmd (GenesisVerKey vk sk) = runGenesisVerKey vk sk runGenesisCmd (GenesisTxIn vk nw mOutFile) = runGenesisTxIn vk nw mOutFile runGenesisCmd (GenesisAddr vk nw mOutFile) = runGenesisAddr vk nw mOutFile -runGenesisCmd (GenesisCreate gd gn un ms am nw) = runGenesisCreate gd gn un ms am nw +runGenesisCmd (GenesisCreate fmt gd gn un ms am nw) = runGenesisCreate fmt gd gn un ms am nw runGenesisCmd (GenesisCreateCardano gd gn un ms am k slotLength sc nw bg sg ag cg mNodeCfg) = runGenesisCreateCardano gd gn un ms am k slotLength sc nw bg sg ag cg mNodeCfg -runGenesisCmd (GenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su relayJsonFp) = - runGenesisCreateStaked gd gn gp gl un ms am ds nw bf bp su relayJsonFp +runGenesisCmd (GenesisCreateStaked fmt gd gn gp gl un ms am ds nw bf bp su relayJsonFp) = + runGenesisCreateStaked fmt gd gn gp gl un ms am ds nw bf bp su relayJsonFp runGenesisCmd (GenesisHashFile gf) = runGenesisHashFile gf -- @@ -417,16 +417,20 @@ writeOutput Nothing = Text.putStrLn -- Create Genesis command implementation -- -runGenesisCreate :: GenesisDir - -> Word -- ^ num genesis & delegate keys to make - -> Word -- ^ num utxo keys to make - -> Maybe SystemStart - -> Maybe Lovelace - -> NetworkId - -> ExceptT ShelleyGenesisCmdError IO () -runGenesisCreate (GenesisDir rootdir) - genNumGenesisKeys genNumUTxOKeys - mStart mAmount network = do +runGenesisCreate + :: KeyOutputFormat + -> GenesisDir + -> Word -- ^ num genesis & delegate keys to make + -> Word -- ^ num utxo keys to make + -> Maybe SystemStart + -> Maybe Lovelace + -> NetworkId + -> ExceptT ShelleyGenesisCmdError IO () +runGenesisCreate + fmt (GenesisDir rootdir) + genNumGenesisKeys genNumUTxOKeys + mStart mAmount network = do + liftIO $ do createDirectoryIfMissing False rootdir createDirectoryIfMissing False gendir @@ -439,7 +443,7 @@ runGenesisCreate (GenesisDir rootdir) forM_ [ 1 .. genNumGenesisKeys ] $ \index -> do createGenesisKeys gendir index - createDelegateKeys deldir index + createDelegateKeys fmt deldir index forM_ [ 1 .. genNumUTxOKeys ] $ \index -> createUtxoKeys utxodir index @@ -690,25 +694,27 @@ runGenesisCreateCardano (GenesisDir rootdir) dlgCertMap byronGenesis = Genesis.unGenesisDelegation $ Genesis.gdHeavyDelegation byronGenesis runGenesisCreateStaked - :: GenesisDir - -> Word -- ^ num genesis & delegate keys to make - -> Word -- ^ num utxo keys to make - -> Word -- ^ num pools to make - -> Word -- ^ num delegators to make + :: KeyOutputFormat -- ^ key output format + -> GenesisDir + -> Word -- ^ num genesis & delegate keys to make + -> Word -- ^ num utxo keys to make + -> Word -- ^ num pools to make + -> Word -- ^ num delegators to make -> Maybe SystemStart - -> Maybe Lovelace -- ^ supply going to non-delegators - -> Lovelace -- ^ supply going to delegators + -> Maybe Lovelace -- ^ supply going to non-delegators + -> Lovelace -- ^ supply going to delegators -> NetworkId - -> Word -- ^ bulk credential files to write - -> Word -- ^ pool credentials per bulk file - -> Word -- ^ num stuffed UTxO entries - -> Maybe FilePath -- ^ Specified stake pool relays + -> Word -- ^ bulk credential files to write + -> Word -- ^ pool credentials per bulk file + -> Word -- ^ num stuffed UTxO entries + -> Maybe FilePath -- ^ Specified stake pool relays -> ExceptT ShelleyGenesisCmdError IO () -runGenesisCreateStaked (GenesisDir rootdir) - genNumGenesisKeys genNumUTxOKeys genNumPools genNumStDelegs - mStart mNonDlgAmount stDlgAmount network - numBulkPoolCredFiles bulkPoolsPerFile numStuffedUtxo - sPoolRelayFp = do +runGenesisCreateStaked + fmt (GenesisDir rootdir) + genNumGenesisKeys genNumUTxOKeys genNumPools genNumStDelegs + mStart mNonDlgAmount stDlgAmount network + numBulkPoolCredFiles bulkPoolsPerFile numStuffedUtxo + sPoolRelayFp = do liftIO $ do createDirectoryIfMissing False rootdir createDirectoryIfMissing False gendir @@ -723,7 +729,7 @@ runGenesisCreateStaked (GenesisDir rootdir) forM_ [ 1 .. genNumGenesisKeys ] $ \index -> do createGenesisKeys gendir index - createDelegateKeys deldir index + createDelegateKeys fmt deldir index forM_ [ 1 .. genNumUTxOKeys ] $ \index -> createUtxoKeys utxodir index @@ -737,7 +743,7 @@ runGenesisCreateStaked (GenesisDir rootdir) . hoistEither $ Aeson.eitherDecode relaySpecJsonBs poolParams <- forM [ 1 .. genNumPools ] $ \index -> do - createPoolCredentials pooldir index + createPoolCredentials fmt pooldir index buildPoolParams network pooldir index (fromMaybe mempty mayStakePoolRelays) when (numBulkPoolCredFiles * bulkPoolsPerFile > genNumPools) $ @@ -834,8 +840,8 @@ runGenesisCreateStaked (GenesisDir rootdir) -- ------------------------------------------------------------------------------------------------- -createDelegateKeys :: FilePath -> Word -> ExceptT ShelleyGenesisCmdError IO () -createDelegateKeys dir index = do +createDelegateKeys :: KeyOutputFormat -> FilePath -> Word -> ExceptT ShelleyGenesisCmdError IO () +createDelegateKeys fmt dir index = do liftIO $ createDirectoryIfMissing False dir runGenesisKeyGenDelegate (File @(VerificationKey ()) $ dir "delegate" ++ strIndex ++ ".vkey") @@ -846,6 +852,7 @@ createDelegateKeys dir index = do (File @(SigningKey ()) $ dir "delegate" ++ strIndex ++ ".vrf.skey") firstExceptT ShelleyGenesisCmdNodeCmdError $ do runNodeKeyGenKES + fmt (onlyOut kesVK) (File @(SigningKey ()) $ dir "delegate" ++ strIndex ++ ".kes.skey") runNodeIssueOpCert @@ -877,17 +884,20 @@ createUtxoKeys dir index = do (File @(VerificationKey ()) $ dir "utxo" ++ strIndex ++ ".vkey") (File @(SigningKey ()) $ dir "utxo" ++ strIndex ++ ".skey") -createPoolCredentials :: FilePath -> Word -> ExceptT ShelleyGenesisCmdError IO () -createPoolCredentials dir index = do +createPoolCredentials :: KeyOutputFormat -> FilePath -> Word -> ExceptT ShelleyGenesisCmdError IO () +createPoolCredentials fmt dir index = do liftIO $ createDirectoryIfMissing False dir firstExceptT ShelleyGenesisCmdNodeCmdError $ do runNodeKeyGenKES + fmt (onlyOut kesVK) (File @(SigningKey ()) $ dir "kes" ++ strIndex ++ ".skey") runNodeKeyGenVRF + fmt (File @(VerificationKey ()) $ dir "vrf" ++ strIndex ++ ".vkey") (File @(SigningKey ()) $ dir "vrf" ++ strIndex ++ ".skey") runNodeKeyGenCold + fmt (File @(VerificationKey ()) $ dir "cold" ++ strIndex ++ ".vkey") (onlyOut coldSK) (onlyOut opCertCtr) @@ -899,6 +909,7 @@ createPoolCredentials dir index = do (File $ dir "opcert" ++ strIndex ++ ".cert") firstExceptT ShelleyGenesisCmdStakeAddressCmdError $ runStakeAddressKeyGenToFile + fmt (File @(VerificationKey ()) $ dir "staking-reward" ++ strIndex ++ ".vkey") (File @(SigningKey ()) $ dir "staking-reward" ++ strIndex ++ ".skey") where diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs index 7da5900320b..e8a2ac71036 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs @@ -25,7 +25,7 @@ import Cardano.Api.Shelley import Cardano.CLI.Shelley.Commands import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile) -import Cardano.CLI.Types (SigningKeyFile, VerificationKeyFile) +import Cardano.CLI.Types (KeyOutputFormat (..), SigningKeyFile, VerificationKeyFile) {- HLINT ignore "Reduce duplication" -} @@ -59,9 +59,9 @@ renderShelleyNodeCmdError err = runNodeCmd :: NodeCmd -> ExceptT ShelleyNodeCmdError IO () -runNodeCmd (NodeKeyGenCold vk sk ctr) = runNodeKeyGenCold vk sk ctr -runNodeCmd (NodeKeyGenKES vk sk) = runNodeKeyGenKES vk sk -runNodeCmd (NodeKeyGenVRF vk sk) = runNodeKeyGenVRF vk sk +runNodeCmd (NodeKeyGenCold fmt vk sk ctr) = runNodeKeyGenCold fmt vk sk ctr +runNodeCmd (NodeKeyGenKES fmt vk sk) = runNodeKeyGenKES fmt vk sk +runNodeCmd (NodeKeyGenVRF fmt vk sk) = runNodeKeyGenVRF fmt vk sk runNodeCmd (NodeKeyHashVRF vk mOutFp) = runNodeKeyHashVRF vk mOutFp runNodeCmd (NodeNewCounter vk ctr out) = runNodeNewCounter vk ctr out runNodeCmd (NodeIssueOpCert vk sk ctr p out) = @@ -73,30 +73,53 @@ runNodeCmd (NodeIssueOpCert vk sk ctr p out) = -- Node command implementations -- -runNodeKeyGenCold :: VerificationKeyFile Out - -> SigningKeyFile Out - -> OpCertCounterFile Out - -> ExceptT ShelleyNodeCmdError IO () -runNodeKeyGenCold vkeyPath skeyPath ocertCtrPath = do +runNodeKeyGenCold + :: KeyOutputFormat + -> VerificationKeyFile Out + -> SigningKeyFile Out + -> OpCertCounterFile Out + -> ExceptT ShelleyNodeCmdError IO () +runNodeKeyGenCold fmt vkeyPath skeyPath ocertCtrPath = do skey <- liftIO $ generateSigningKey AsStakePoolKey let vkey = getVerificationKey skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFile skeyPath - $ textEnvelopeToJSON (Just skeyDesc) skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFile vkeyPath - $ textEnvelopeToJSON (Just vkeyDesc) vkey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFile skeyPath + $ textEnvelopeToJSON (Just skeyDesc) skey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile skeyPath + $ serialiseToBech32 skey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFile vkeyPath + $ textEnvelopeToJSON (Just vkeyDesc) vkey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile vkeyPath + $ serialiseToBech32 vkey + firstExceptT ShelleyNodeCmdWriteFileError . newExceptT $ writeLazyByteStringFile ocertCtrPath $ textEnvelopeToJSON (Just ocertCtrDesc) $ OperationalCertificateIssueCounter initialCounter vkey where - skeyDesc, vkeyDesc, ocertCtrDesc :: TextEnvelopeDescr + skeyDesc :: TextEnvelopeDescr skeyDesc = "Stake Pool Operator Signing Key" + + vkeyDesc :: TextEnvelopeDescr vkeyDesc = "Stake Pool Operator Verification Key" + + ocertCtrDesc :: TextEnvelopeDescr ocertCtrDesc = "Next certificate issue number: " <> fromString (show initialCounter) @@ -104,40 +127,80 @@ runNodeKeyGenCold vkeyPath skeyPath ocertCtrPath = do initialCounter = 0 -runNodeKeyGenKES :: VerificationKeyFile Out - -> SigningKeyFile Out - -> ExceptT ShelleyNodeCmdError IO () -runNodeKeyGenKES vkeyPath skeyPath = do - skey <- liftIO $ generateSigningKey AsKesKey - let vkey = getVerificationKey skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFile skeyPath - $ textEnvelopeToJSON (Just skeyDesc) skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFile vkeyPath - $ textEnvelopeToJSON (Just vkeyDesc) vkey +runNodeKeyGenKES + :: KeyOutputFormat + -> VerificationKeyFile Out + -> SigningKeyFile Out + -> ExceptT ShelleyNodeCmdError IO () +runNodeKeyGenKES fmt vkeyPath skeyPath = do + skey <- liftIO $ generateSigningKey AsKesKey + + let vkey = getVerificationKey skey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFileWithOwnerPermissions skeyPath + $ textEnvelopeToJSON (Just skeyDesc) skey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile skeyPath + $ serialiseToBech32 skey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFile vkeyPath + $ textEnvelopeToJSON (Just vkeyDesc) vkey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile vkeyPath + $ serialiseToBech32 vkey + where - skeyDesc, vkeyDesc :: TextEnvelopeDescr + skeyDesc :: TextEnvelopeDescr skeyDesc = "KES Signing Key" + + vkeyDesc :: TextEnvelopeDescr vkeyDesc = "KES Verification Key" -runNodeKeyGenVRF :: - VerificationKeyFile Out +runNodeKeyGenVRF + :: KeyOutputFormat + -> VerificationKeyFile Out -> SigningKeyFile Out -> ExceptT ShelleyNodeCmdError IO () -runNodeKeyGenVRF vkeyPath skeyPath = do - skey <- liftIO $ generateSigningKey AsVrfKey - let vkey = getVerificationKey skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFileWithOwnerPermissions skeyPath - $ textEnvelopeToJSON (Just skeyDesc) skey - firstExceptT ShelleyNodeCmdWriteFileError - . newExceptT - $ writeLazyByteStringFile vkeyPath - $ textEnvelopeToJSON (Just vkeyDesc) vkey +runNodeKeyGenVRF fmt vkeyPath skeyPath = do + skey <- liftIO $ generateSigningKey AsVrfKey + + let vkey = getVerificationKey skey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFileWithOwnerPermissions skeyPath + $ textEnvelopeToJSON (Just skeyDesc) skey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile skeyPath + $ serialiseToBech32 skey + + case fmt of + KeyOutputFormatTextEnvelope -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeLazyByteStringFile vkeyPath + $ textEnvelopeToJSON (Just vkeyDesc) vkey + KeyOutputFormatBech32 -> + firstExceptT ShelleyNodeCmdWriteFileError + . newExceptT + $ writeTextFile vkeyPath + $ serialiseToBech32 vkey where skeyDesc, vkeyDesc :: TextEnvelopeDescr skeyDesc = "VRF Signing Key" @@ -265,4 +328,3 @@ readColdVerificationKeyOrFile coldVerKeyOrFile = , FromSomeType (AsVerificationKey AsGenesisDelegateKey) castVerificationKey ] fp - diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs index 75b3256a3de..762f8df8a2e 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Pool.hs @@ -15,13 +15,12 @@ import qualified Data.ByteString.Char8 as BS import Data.Function ((&)) import Data.Text (Text) import qualified Data.Text as Text -import qualified Data.Text.IO as Text import Cardano.Api import Cardano.Api.Shelley import Cardano.CLI.Shelley.Commands import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile) -import Cardano.CLI.Types (OutputFormat (..)) +import Cardano.CLI.Types (PoolIdOutputFormat (..)) import qualified Cardano.Ledger.Slot as Shelley @@ -48,7 +47,7 @@ runPoolCmd (PoolRegistrationCert sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerV runStakePoolRegistrationCert sPvkey vrfVkey pldg pCost pMrgn rwdVerFp ownerVerFps relays mbMetadata network outfp runPoolCmd (PoolRetirementCert sPvkeyFp retireEpoch outfp) = runStakePoolRetirementCert sPvkeyFp retireEpoch outfp -runPoolCmd (PoolGetId sPvkey outputFormat) = runPoolId sPvkey outputFormat +runPoolCmd (PoolGetId sPvkey outputFormat mOutFile) = runPoolId sPvkey outputFormat mOutFile runPoolCmd (PoolMetadataHash poolMdFile mOutFile) = runPoolMetadataHash poolMdFile mOutFile @@ -169,20 +168,27 @@ runStakePoolRetirementCert stakePoolVerKeyOrFile retireEpoch outfp = do runPoolId :: VerificationKeyOrFile StakePoolKey - -> OutputFormat + -> PoolIdOutputFormat + -> Maybe (File () Out) -> ExceptT ShelleyPoolCmdError IO () -runPoolId verKeyOrFile outputFormat = do - stakePoolVerKey <- firstExceptT ShelleyPoolCmdReadKeyFileError - . newExceptT - $ readVerificationKeyOrFile AsStakePoolKey verKeyOrFile - liftIO $ - case outputFormat of - OutputFormatHex -> - BS.putStrLn $ serialiseToRawBytesHex (verificationKeyHash stakePoolVerKey) - OutputFormatBech32 -> - Text.putStrLn $ serialiseToBech32 (verificationKeyHash stakePoolVerKey) - -runPoolMetadataHash :: File StakePoolMetadata In -> Maybe (File () Out) -> ExceptT ShelleyPoolCmdError IO () +runPoolId verKeyOrFile outputFormat mOutFile = do + stakePoolVerKey <- firstExceptT ShelleyPoolCmdReadKeyFileError + . newExceptT + $ readVerificationKeyOrFile AsStakePoolKey verKeyOrFile + + case outputFormat of + PoolIdOutputFormatHex -> + firstExceptT ShelleyPoolCmdWriteFileError + . newExceptT + $ writeByteStringOutput mOutFile + $ serialiseToRawBytesHex (verificationKeyHash stakePoolVerKey) + PoolIdOutputFormatBech32 -> + firstExceptT ShelleyPoolCmdWriteFileError + . newExceptT + $ writeTextOutput mOutFile + $ serialiseToBech32 (verificationKeyHash stakePoolVerKey) + +runPoolMetadataHash :: StakePoolMetadataFile In -> Maybe (File () Out) -> ExceptT ShelleyPoolCmdError IO () runPoolMetadataHash poolMDPath mOutFile = do metadataBytes <- lift (readByteStringFile poolMDPath) & onLeft (left . ShelleyPoolCmdReadFileError) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs index 9aaefff3fac..b7d7e9fdcdc 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/StakeAddress.hs @@ -43,7 +43,7 @@ renderShelleyStakeAddressCmdError err = ShelleyStakeAddressCmdReadScriptFileError fileErr -> Text.pack (displayError fileErr) runStakeAddressCmd :: StakeAddressCmd -> ExceptT ShelleyStakeAddressCmdError IO () -runStakeAddressCmd (StakeAddressKeyGen vk sk) = runStakeAddressKeyGenToFile vk sk +runStakeAddressCmd (StakeAddressKeyGen fmt vk sk) = runStakeAddressKeyGenToFile fmt vk sk runStakeAddressCmd (StakeAddressKeyHash vk mOutputFp) = runStakeAddressKeyHash vk mOutputFp runStakeAddressCmd (StakeAddressBuild stakeVerifier nw mOutputFp) = runStakeAddressBuild stakeVerifier nw mOutputFp @@ -60,10 +60,11 @@ runStakeAddressCmd (StakeCredentialDeRegistrationCert stakeIdentifier outputFp) -- runStakeAddressKeyGenToFile - :: VerificationKeyFile Out + :: KeyOutputFormat + -> VerificationKeyFile Out -> SigningKeyFile Out -> ExceptT ShelleyStakeAddressCmdError IO () -runStakeAddressKeyGenToFile vkFp skFp = do +runStakeAddressKeyGenToFile fmt vkFp skFp = do let skeyDesc = "Stake Signing Key" let vkeyDesc = "Stake Verification Key" @@ -72,8 +73,17 @@ runStakeAddressKeyGenToFile vkFp skFp = do let vkey = getVerificationKey skey firstExceptT ShelleyStakeAddressCmdWriteFileError $ do - newExceptT $ writeLazyByteStringFile skFp $ textEnvelopeToJSON (Just skeyDesc) skey - newExceptT $ writeLazyByteStringFile vkFp $ textEnvelopeToJSON (Just vkeyDesc) vkey + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT $ writeLazyByteStringFile skFp $ textEnvelopeToJSON (Just skeyDesc) skey + KeyOutputFormatBech32 -> + newExceptT $ writeTextFile skFp $ serialiseToBech32 skey + + case fmt of + KeyOutputFormatTextEnvelope -> + newExceptT $ writeLazyByteStringFile vkFp $ textEnvelopeToJSON (Just vkeyDesc) vkey + KeyOutputFormatBech32 -> + newExceptT $ writeTextFile vkFp $ serialiseToBech32 vkey runStakeAddressKeyHash :: VerificationKeyOrFile StakeKey diff --git a/cardano-cli/src/Cardano/CLI/Types.hs b/cardano-cli/src/Cardano/CLI/Types.hs index 78c2dd06096..9acdcb93fd2 100644 --- a/cardano-cli/src/Cardano/CLI/Types.hs +++ b/cardano-cli/src/Cardano/CLI/Types.hs @@ -12,13 +12,14 @@ module Cardano.CLI.Types , CurrentKesPeriod (..) , EpochLeadershipSchedule (..) , GenesisFile (..) + , KeyOutputFormat(..) , OpCertEndingKesPeriod (..) , OpCertIntervalInformation (..) , OpCertOnDiskCounter (..) , OpCertNodeAndOnDiskCounterInformation (..) , OpCertNodeStateCounter (..) , OpCertStartingKesPeriod (..) - , OutputFormat (..) + , PoolIdOutputFormat (..) , TxBuildOutputOptions(..) , ReferenceScriptAnyEra (..) , SigningKeyFile @@ -194,9 +195,14 @@ instance FromJSON GenesisFile where <> "Encountered: " <> show invalid -- | The desired output format. -data OutputFormat - = OutputFormatHex - | OutputFormatBech32 +data PoolIdOutputFormat + = PoolIdOutputFormatHex + | PoolIdOutputFormatBech32 + deriving (Eq, Show) + +data KeyOutputFormat + = KeyOutputFormatTextEnvelope + | KeyOutputFormatBech32 deriving (Eq, Show) data AllOrOnly a = All | Only a deriving (Eq, Show) diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley.hs index d639746d8e1..c310b9cb576 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley.hs @@ -12,7 +12,8 @@ module Test.Golden.Shelley import Test.Golden.Shelley.Address.Build (golden_shelleyAddressBuild) import Test.Golden.Shelley.Address.Info (golden_shelleyAddressInfo) -import Test.Golden.Shelley.Address.KeyGen (golden_shelleyAddressKeyGen) +import Test.Golden.Shelley.Address.KeyGen (golden_shelleyAddressExtendedKeyGen, + golden_shelleyAddressKeyGen) import Test.Golden.Shelley.Genesis.Create (golden_shelleyGenesisCreate) import Test.Golden.Shelley.Genesis.InitialTxIn (golden_shelleyGenesisInitialTxIn) import Test.Golden.Shelley.Genesis.KeyGenDelegate (golden_shelleyGenesisKeyGenDelegate) @@ -38,9 +39,12 @@ import Test.Golden.Shelley.Key.ConvertCardanoAddressKey golden_convertCardanoAddressShelleyPaymentSigningKey, golden_convertCardanoAddressShelleyStakeSigningKey) import Test.Golden.Shelley.Node.IssueOpCert (golden_shelleyNodeIssueOpCert) -import Test.Golden.Shelley.Node.KeyGen (golden_shelleyNodeKeyGen) -import Test.Golden.Shelley.Node.KeyGenKes (golden_shelleyNodeKeyGenKes) -import Test.Golden.Shelley.Node.KeyGenVrf (golden_shelleyNodeKeyGenVrf) +import Test.Golden.Shelley.Node.KeyGen (golden_shelleyNodeKeyGen, + golden_shelleyNodeKeyGen_bech32, golden_shelleyNodeKeyGen_te) +import Test.Golden.Shelley.Node.KeyGenKes (golden_shelleyNodeKeyGenKes, + golden_shelleyNodeKeyGenKes_bech32, golden_shelleyNodeKeyGenKes_te) +import Test.Golden.Shelley.Node.KeyGenVrf (golden_shelleyNodeKeyGenVrf, + golden_shelleyNodeKeyGenVrf_bech32, golden_shelleyNodeKeyGenVrf_te) import Test.Golden.Shelley.StakeAddress.Build (golden_shelleyStakeAddressBuild) import Test.Golden.Shelley.StakeAddress.DeregistrationCertificate (golden_shelleyStakeAddressDeregistrationCertificate) @@ -64,16 +68,20 @@ import Test.Golden.Shelley.Metadata.StakePoolMetadata (golden_stakePoo import Test.Golden.Shelley.MultiSig.Address (golden_shelleyAllMultiSigAddressBuild, golden_shelleyAnyMultiSigAddressBuild, golden_shelleyAtLeastMultiSigAddressBuild) import Test.Golden.Shelley.TextEnvelope.Keys.ExtendedPaymentKeys - (golden_shelleyExtendedPaymentKeys) + (golden_shelleyExtendedPaymentKeys, golden_shelleyExtendedPaymentKeys_bech32, + golden_shelleyExtendedPaymentKeys_te) import Test.Golden.Shelley.TextEnvelope.Keys.GenesisDelegateKeys (golden_shelleyGenesisDelegateKeys) import Test.Golden.Shelley.TextEnvelope.Keys.GenesisKeys (golden_shelleyGenesisKeys) import Test.Golden.Shelley.TextEnvelope.Keys.GenesisUTxOKeys (golden_shelleyGenesisUTxOKeys) import Test.Golden.Shelley.TextEnvelope.Keys.KESKeys (golden_shelleyKESKeys) -import Test.Golden.Shelley.TextEnvelope.Keys.PaymentKeys (golden_shelleyPaymentKeys) -import Test.Golden.Shelley.TextEnvelope.Keys.StakeKeys (golden_shelleyStakeKeys) -import Test.Golden.Shelley.TextEnvelope.Keys.VRFKeys (golden_shelleyVRFKeys) +import Test.Golden.Shelley.TextEnvelope.Keys.PaymentKeys (golden_shelleyPaymentKeys, + golden_shelleyPaymentKeys_bech32, golden_shelleyPaymentKeys_te) +import Test.Golden.Shelley.TextEnvelope.Keys.StakeKeys (golden_shelleyStakeKeys, + golden_shelleyStakeKeys_bech32, golden_shelleyStakeKeys_te) +import Test.Golden.Shelley.TextEnvelope.Keys.VRFKeys (golden_shelleyVRFKeys, + golden_shelleyVRFKeys_bech32, golden_shelleyVRFKeys_te) import Test.Golden.Shelley.TextView.DecodeCbor (golden_shelleyTextViewDecodeCbor) import Test.Golden.Shelley.Transaction.Assemble (golden_shelleyTransactionAssembleWitness_SigningKey) @@ -101,8 +109,11 @@ keyTests = $ H.Group "TextEnvelope Key Goldens" [ ("golden_shelleyAddressInfo", golden_shelleyAddressInfo) , ("golden_shelleyAddressKeyGen", golden_shelleyAddressKeyGen) + , ("golden_shelleyAddressExtendedKeyGen", golden_shelleyAddressExtendedKeyGen) , ("golden_shelleyAddressBuild", golden_shelleyAddressBuild) , ("golden_shelleyExtendedPaymentKeys", golden_shelleyExtendedPaymentKeys) + , ("golden_shelleyExtendedPaymentKeys_bech32", golden_shelleyExtendedPaymentKeys_bech32) + , ("golden_shelleyExtendedPaymentKeys_te", golden_shelleyExtendedPaymentKeys_te) , ("golden_shelleyGenesisCreate", golden_shelleyGenesisCreate) , ("golden_shelleyGenesisDelegateKeys", golden_shelleyGenesisDelegateKeys) , ("golden_shelleyGenesisInitialTxIn", golden_shelleyGenesisInitialTxIn) @@ -115,14 +126,24 @@ keyTests = , ("golden_shelleyKESKeys", golden_shelleyKESKeys) , ("golden_shelleyNodeIssueOpCert", golden_shelleyNodeIssueOpCert) , ("golden_shelleyNodeKeyGen", golden_shelleyNodeKeyGen) + , ("golden_shelleyNodeKeyGen_bech32", golden_shelleyNodeKeyGen_bech32) + , ("golden_shelleyNodeKeyGen_te", golden_shelleyNodeKeyGen_te) , ("golden_shelleyNodeKeyGenKes", golden_shelleyNodeKeyGenKes) + , ("golden_shelleyNodeKeyGenKes_bech32", golden_shelleyNodeKeyGenKes_bech32) + , ("golden_shelleyNodeKeyGenKes_te", golden_shelleyNodeKeyGenKes_te) , ("golden_shelleyNodeKeyGenVrf", golden_shelleyNodeKeyGenVrf) + , ("golden_shelleyNodeKeyGenVrf_bech32", golden_shelleyNodeKeyGenVrf_bech32) + , ("golden_shelleyNodeKeyGenVrf_te", golden_shelleyNodeKeyGenVrf_te) , ("golden_shelleyPaymentKeys", golden_shelleyPaymentKeys) + , ("golden_shelleyPaymentKeys_bech32", golden_shelleyPaymentKeys_bech32) + , ("golden_shelleyPaymentKeys_te", golden_shelleyPaymentKeys_te) , ("golden_shelleyStakeAddressBuild", golden_shelleyStakeAddressBuild) , ("golden_shelleyStakeAddressDeregistrationCertificate", golden_shelleyStakeAddressDeregistrationCertificate) , ("golden_shelleyStakeAddressKeyGen", golden_shelleyStakeAddressKeyGen) , ("golden_shelleyStakeAddressRegistrationCertificate", golden_shelleyStakeAddressRegistrationCertificate) , ("golden_shelleyStakeKeys", golden_shelleyStakeKeys) + , ("golden_shelleyStakeKeys_bech32", golden_shelleyStakeKeys_bech32) + , ("golden_shelleyStakeKeys_te", golden_shelleyStakeKeys_te) , ("golden_shelleyStakePoolRegistrationCertificate", golden_shelleyStakePoolRegistrationCertificate) , ("golden_shelleyTextViewDecodeCbor", golden_shelleyTextViewDecodeCbor) , ("golden_shelleyTransactionBuild", golden_shelleyTransactionBuild) @@ -133,6 +154,8 @@ keyTests = , ("golden_shelleyTransactionCalculateMinFee", golden_shelleyTransactionCalculateMinFee) , ("golden_shelleyTransactionSign", golden_shelleyTransactionSign) , ("golden_shelleyVRFKeys", golden_shelleyVRFKeys) + , ("golden_shelleyVRFKeys_bech32", golden_shelleyVRFKeys_bech32) + , ("golden_shelleyVRFKeys_te", golden_shelleyVRFKeys_te) , ("golden_version", golden_version) ] diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Address/KeyGen.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Address/KeyGen.hs index 6d42b5ab409..9543f8c3a5a 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Address/KeyGen.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Address/KeyGen.hs @@ -2,6 +2,7 @@ module Test.Golden.Shelley.Address.KeyGen ( golden_shelleyAddressKeyGen + , golden_shelleyAddressExtendedKeyGen ) where import Control.Monad (void) @@ -27,8 +28,23 @@ golden_shelleyAddressKeyGen = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir void $ H.readFile addressVKeyFile void $ H.readFile addressSKeyFile - H.assertFileOccurences 1 "PaymentVerificationKeyShelley" addressVKeyFile + H.assertFileOccurences 1 "PaymentVerificationKeyShelley_ed25519" addressVKeyFile H.assertFileOccurences 1 "PaymentSigningKeyShelley_ed25519" addressSKeyFile - H.assertEndsWithSingleNewline addressVKeyFile - H.assertEndsWithSingleNewline addressSKeyFile +golden_shelleyAddressExtendedKeyGen :: Property +golden_shelleyAddressExtendedKeyGen = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + addressVKeyFile <- noteTempFile tempDir "address.vkey" + addressSKeyFile <- noteTempFile tempDir "address.skey" + + void $ execCardanoCLI + [ "shelley","address","key-gen" + , "--extended-key" + , "--verification-key-file", addressVKeyFile + , "--signing-key-file", addressSKeyFile + ] + + void $ H.readFile addressVKeyFile + void $ H.readFile addressSKeyFile + + H.assertFileOccurences 1 "PaymentExtendedVerificationKeyShelley_ed25519_bip32" addressVKeyFile + H.assertFileOccurences 1 "PaymentExtendedSigningKeyShelley_ed25519_bip32" addressSKeyFile diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGen.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGen.hs index 424e6ce112b..fd90f0af2f4 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGen.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGen.hs @@ -2,6 +2,8 @@ module Test.Golden.Shelley.Node.KeyGen ( golden_shelleyNodeKeyGen + , golden_shelleyNodeKeyGen_bech32 + , golden_shelleyNodeKeyGen_te ) where import Control.Monad (void) @@ -33,3 +35,44 @@ golden_shelleyNodeKeyGen = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> H.assertEndsWithSingleNewline verificationKeyFile H.assertEndsWithSingleNewline signingKeyFile H.assertEndsWithSingleNewline opCertCounterFile + +golden_shelleyNodeKeyGen_te :: Property +golden_shelleyNodeKeyGen_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKeyFile <- noteTempFile tempDir "key-gen.vkey" + signingKeyFile <- noteTempFile tempDir "key-gen.skey" + opCertCounterFile <- noteTempFile tempDir "op-cert.counter" + + void $ execCardanoCLI + [ "node","key-gen" + , "--verification-key-file", verificationKeyFile + , "--signing-key-file", signingKeyFile + , "--operational-certificate-issue-counter", opCertCounterFile + ] + + H.assertFileOccurences 1 "StakePoolVerificationKey_ed25519" verificationKeyFile + H.assertFileOccurences 1 "StakePoolSigningKey_ed25519" signingKeyFile + H.assertFileOccurences 1 "NodeOperationalCertificateIssueCounter" opCertCounterFile + + H.assertEndsWithSingleNewline verificationKeyFile + H.assertEndsWithSingleNewline signingKeyFile + H.assertEndsWithSingleNewline opCertCounterFile + +golden_shelleyNodeKeyGen_bech32 :: Property +golden_shelleyNodeKeyGen_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKeyFile <- noteTempFile tempDir "key-gen.vkey" + signingKeyFile <- noteTempFile tempDir "key-gen.skey" + opCertCounterFile <- noteTempFile tempDir "op-cert.counter" + + void $ execCardanoCLI + [ "node","key-gen" + , "--key-output-format", "bech32" + , "--verification-key-file", verificationKeyFile + , "--signing-key-file", signingKeyFile + , "--operational-certificate-issue-counter", opCertCounterFile + ] + + H.assertFileOccurences 1 "pool_vk" verificationKeyFile + H.assertFileOccurences 1 "pool_sk" signingKeyFile + H.assertFileOccurences 1 "NodeOperationalCertificateIssueCounter" opCertCounterFile + + H.assertEndsWithSingleNewline opCertCounterFile diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenKes.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenKes.hs index c426bb344dd..1445c02040d 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenKes.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenKes.hs @@ -2,6 +2,8 @@ module Test.Golden.Shelley.Node.KeyGenKes ( golden_shelleyNodeKeyGenKes + , golden_shelleyNodeKeyGenKes_bech32 + , golden_shelleyNodeKeyGenKes_te ) where import Control.Monad (void) @@ -29,3 +31,36 @@ golden_shelleyNodeKeyGenKes = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir H.assertEndsWithSingleNewline verificationKey H.assertEndsWithSingleNewline signingKey + +golden_shelleyNodeKeyGenKes_te :: Property +golden_shelleyNodeKeyGenKes_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKey <- noteTempFile tempDir "kes.vkey" + signingKey <- noteTempFile tempDir "kes.skey" + + void $ execCardanoCLI + [ "node","key-gen-KES" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verificationKey + , "--signing-key-file", signingKey + ] + + H.assertFileOccurences 1 "KesVerificationKey_ed25519_kes_2^6" verificationKey + H.assertFileOccurences 1 "KesSigningKey_ed25519_kes_2^6" signingKey + + H.assertEndsWithSingleNewline verificationKey + H.assertEndsWithSingleNewline signingKey + +golden_shelleyNodeKeyGenKes_bech32 :: Property +golden_shelleyNodeKeyGenKes_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKey <- noteTempFile tempDir "kes.vkey" + signingKey <- noteTempFile tempDir "kes.skey" + + void $ execCardanoCLI + [ "node","key-gen-KES" + , "--key-output-format", "bech32" + , "--verification-key-file", verificationKey + , "--signing-key-file", signingKey + ] + + H.assertFileOccurences 1 "kes_vk" verificationKey + H.assertFileOccurences 1 "kes_sk" signingKey diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenVrf.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenVrf.hs index e43f011c746..ccad67f5df6 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenVrf.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/Node/KeyGenVrf.hs @@ -2,6 +2,8 @@ module Test.Golden.Shelley.Node.KeyGenVrf ( golden_shelleyNodeKeyGenVrf + , golden_shelleyNodeKeyGenVrf_bech32 + , golden_shelleyNodeKeyGenVrf_te ) where import Control.Monad (void) @@ -29,3 +31,36 @@ golden_shelleyNodeKeyGenVrf = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir H.assertEndsWithSingleNewline verificationKey H.assertEndsWithSingleNewline signingKey + +golden_shelleyNodeKeyGenVrf_te :: Property +golden_shelleyNodeKeyGenVrf_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKey <- noteTempFile tempDir "kes.vkey" + signingKey <- noteTempFile tempDir "kes.skey" + + void $ execCardanoCLI + [ "node","key-gen-VRF" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verificationKey + , "--signing-key-file", signingKey + ] + + H.assertFileOccurences 1 "VRF Verification Key" verificationKey + H.assertFileOccurences 1 "VRF Signing Key" signingKey + + H.assertEndsWithSingleNewline verificationKey + H.assertEndsWithSingleNewline signingKey + +golden_shelleyNodeKeyGenVrf_bech32 :: Property +golden_shelleyNodeKeyGenVrf_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKey <- noteTempFile tempDir "kes.vkey" + signingKey <- noteTempFile tempDir "kes.skey" + + void $ execCardanoCLI + [ "node","key-gen-VRF" + , "--key-output-format", "bech32" + , "--verification-key-file", verificationKey + , "--signing-key-file", signingKey + ] + + H.assertFileOccurences 1 "vrf_vk" verificationKey + H.assertFileOccurences 1 "vrf_sk" signingKey diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/KeyGen.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/KeyGen.hs index 07062f36a83..b0553b42d83 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/KeyGen.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/StakeAddress/KeyGen.hs @@ -26,6 +26,3 @@ golden_shelleyStakeAddressKeyGen = propertyOnce . H.moduleWorkspace "tmp" $ \tem H.assertFileOccurences 1 "StakeVerificationKeyShelley_ed25519" verificationKeyFile H.assertFileOccurences 1 "StakeSigningKeyShelley_ed25519" signingKeyFile - - H.assertEndsWithSingleNewline verificationKeyFile - H.assertEndsWithSingleNewline signingKeyFile diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/ExtendedPaymentKeys.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/ExtendedPaymentKeys.hs index 2a2b56a0293..d7f7a489b5e 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/ExtendedPaymentKeys.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/ExtendedPaymentKeys.hs @@ -1,15 +1,22 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} module Test.Golden.Shelley.TextEnvelope.Keys.ExtendedPaymentKeys ( golden_shelleyExtendedPaymentKeys + , golden_shelleyExtendedPaymentKeys_bech32 + , golden_shelleyExtendedPaymentKeys_te ) where import Cardano.Api (AsType (..), HasTextEnvelope (..)) + import Control.Monad (void) import Hedgehog (Property) import Test.Cardano.CLI.Util +import Text.Regex.TDFA ((=~)) +import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H {- HLINT ignore "Use camelCase" -} @@ -41,3 +48,59 @@ golden_shelleyExtendedPaymentKeys = propertyOnce . H.moduleWorkspace "tmp" $ \te -- golden files checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyExtendedPaymentKeys_te :: Property +golden_shelleyExtendedPaymentKeys_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + -- Reference keys + referenceVerKey <- noteInputFile "test/data/golden/shelley/keys/extended_payment_keys/verification_key" + referenceSignKey <- noteInputFile "test/data/golden/shelley/keys/extended_payment_keys/signing_key" + + -- Key filepaths + verKey <- noteTempFile tempDir "extended-payment-verification-key-file" + signKey <- noteTempFile tempDir "extended-payment-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "address","key-gen" + , "--key-output-format", "text-envelope" + , "--extended-key" + , "--verification-key-file", verKey + , "--signing-key-file", signKey + ] + + let signingKeyType = textEnvelopeType (AsSigningKey AsPaymentExtendedKey) + verificationKeyType = textEnvelopeType (AsVerificationKey AsPaymentExtendedKey) + + -- Check the newly created files have not deviated from the + -- golden files + checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey + checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the bech32 serialization format has not changed. +golden_shelleyExtendedPaymentKeys_bech32 :: Property +golden_shelleyExtendedPaymentKeys_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + + -- Key filepaths + verKeyFile <- noteTempFile tempDir "payment-verification-key-file" + signKeyFile <- noteTempFile tempDir "payment-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "address","key-gen" + , "--key-output-format", "bech32" + , "--extended-key" + , "--verification-key-file", verKeyFile + , "--signing-key-file", signKeyFile + ] + + verKey <- H.readFile verKeyFile + H.assert $ verKey =~ id @String "^addr_xvk[a-z0-9]{110}$" + + signKey <- H.readFile signKeyFile + H.assert $ signKey =~ id @String "^addr_xsk[a-z0-9]{212}$" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/KESKeys.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/KESKeys.hs index 06e7d22837b..e459544f12c 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/KESKeys.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/KESKeys.hs @@ -1,15 +1,22 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} module Test.Golden.Shelley.TextEnvelope.Keys.KESKeys ( golden_shelleyKESKeys + , golden_shelleyKESKeys_bech32 + , golden_shelleyKESKeys_te ) where import Cardano.Api (AsType (..), HasTextEnvelope (..)) + import Control.Monad (void) import Hedgehog (Property) import Test.Cardano.CLI.Util +import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H +import Text.Regex.TDFA ((=~)) {- HLINT ignore "Use camelCase" -} @@ -40,3 +47,57 @@ golden_shelleyKESKeys = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do -- golden files checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyKESKeys_te :: Property +golden_shelleyKESKeys_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + -- Reference keys + referenceVerKey <- noteInputFile "test/data/golden/shelley/keys/kes_keys/verification_key" + referenceSignKey <- noteInputFile "test/data/golden/shelley/keys/kes_keys/signing_key" + + -- Key filepaths + verKey <- noteTempFile tempDir "kes-verification-key-file" + signKey <- noteTempFile tempDir "kes-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "node","key-gen-KES" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verKey + , "--signing-key-file", signKey + ] + + let signingKeyType = textEnvelopeType (AsSigningKey AsKesKey) + verificationKeyType = textEnvelopeType (AsVerificationKey AsKesKey) + + -- Check the newly created files have not deviated from the + -- golden files + checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey + checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyKESKeys_bech32 :: Property +golden_shelleyKESKeys_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + -- Key filepaths + verKeyFile <- noteTempFile tempDir "kes-verification-key-file" + signKeyFile <- noteTempFile tempDir "kes-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "node","key-gen-KES" + , "--key-output-format", "bech32" + , "--verification-key-file", verKeyFile + , "--signing-key-file", signKeyFile + ] + + -- Check the newly created files have not deviated from the + -- golden files + verKey <- H.readFile verKeyFile + H.assert $ verKey =~ id @String "kes_vk[a-z0-9]{59}" + + signKey <- H.readFile signKeyFile + H.assert $ signKey =~ id @String "kes_sk[a-z0-9]{980}" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/PaymentKeys.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/PaymentKeys.hs index 47d832376e2..b74212db3b8 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/PaymentKeys.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/PaymentKeys.hs @@ -1,7 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} module Test.Golden.Shelley.TextEnvelope.Keys.PaymentKeys ( golden_shelleyPaymentKeys + , golden_shelleyPaymentKeys_te + , golden_shelleyPaymentKeys_bech32 ) where import Cardano.Api (AsType (..), HasTextEnvelope (..)) @@ -9,7 +12,10 @@ import Control.Monad (void) import Hedgehog (Property) import Test.Cardano.CLI.Util +import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H +import Text.Regex.TDFA ((=~)) {- HLINT ignore "Use camelCase" -} @@ -40,3 +46,57 @@ golden_shelleyPaymentKeys = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> -- golden files checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyPaymentKeys_te :: Property +golden_shelleyPaymentKeys_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + -- Reference keys + referenceVerKey <- noteInputFile "test/data/golden/shelley/keys/payment_keys/verification_key" + referenceSignKey <- noteInputFile "test/data/golden/shelley/keys/payment_keys/signing_key" + + -- Key filepaths + verKey <- noteTempFile tempDir "payment-verification-key-file" + signKey <- noteTempFile tempDir "payment-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "address","key-gen" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verKey + , "--signing-key-file", signKey + ] + + let signingKeyType = textEnvelopeType (AsSigningKey AsPaymentKey) + verificationKeyType = textEnvelopeType (AsVerificationKey AsPaymentKey) + + -- Check the newly created files have not deviated from the + -- golden files + checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey + checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the bech32 serialization format has not changed. +golden_shelleyPaymentKeys_bech32 :: Property +golden_shelleyPaymentKeys_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + + -- Key filepaths + verKeyFile <- noteTempFile tempDir "payment-verification-key-file" + signKeyFile <- noteTempFile tempDir "payment-signing-key-file" + + -- Generate payment verification key + void $ execCardanoCLI + [ "address","key-gen" + , "--key-output-format", "bech32" + , "--verification-key-file", verKeyFile + , "--signing-key-file", signKeyFile + ] + + verKey <- H.readFile verKeyFile + H.assert $ verKey =~ id @String "^addr_vk[a-z0-9]{59}$" + + signKey <- H.readFile signKeyFile + H.assert $ signKey =~ id @String "^addr_sk[a-z0-9]{59}$" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/StakeKeys.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/StakeKeys.hs index d2ee06f2052..2a049cbfef6 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/StakeKeys.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/StakeKeys.hs @@ -1,7 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} module Test.Golden.Shelley.TextEnvelope.Keys.StakeKeys ( golden_shelleyStakeKeys + , golden_shelleyStakeKeys_bech32 + , golden_shelleyStakeKeys_te ) where import Cardano.Api (AsType (..), HasTextEnvelope (..)) @@ -9,7 +12,10 @@ import Control.Monad (void) import Hedgehog (Property) import Test.Cardano.CLI.Util +import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H +import Text.Regex.TDFA ((=~)) {- HLINT ignore "Use camelCase" -} @@ -40,3 +46,57 @@ golden_shelleyStakeKeys = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> d -- golden files checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyStakeKeys_te :: Property +golden_shelleyStakeKeys_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + -- Reference keys + referenceVerKey <- noteInputFile "test/data/golden/shelley/keys/stake_keys/verification_key" + referenceSignKey <- noteInputFile "test/data/golden/shelley/keys/stake_keys/signing_key" + + -- Key filepaths + verKey <- noteTempFile tempDir "stake-verification-key-file" + signKey <- noteTempFile tempDir "stake-signing-key-file" + + -- Generate stake key pair + void $ execCardanoCLI + [ "stake-address","key-gen" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verKey + , "--signing-key-file", signKey + ] + + let signingKeyType = textEnvelopeType (AsSigningKey AsStakeKey) + verificationKeyType = textEnvelopeType (AsVerificationKey AsStakeKey) + + -- Check the newly created files have not deviated from the + -- golden files + checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey + checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the bech32 serialization format has not changed. +golden_shelleyStakeKeys_bech32 :: Property +golden_shelleyStakeKeys_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + + -- Key filepaths + verKeyFile <- noteTempFile tempDir "stake-verification-key-file" + signKeyFile <- noteTempFile tempDir "stake-signing-key-file" + + -- Generate stake key pair + void $ execCardanoCLI + [ "stake-address","key-gen" + , "--key-output-format", "bech32" + , "--verification-key-file", verKeyFile + , "--signing-key-file", signKeyFile + ] + + verKey <- H.readFile verKeyFile + H.assert $ verKey =~ id @String "stake_vk[a-z0-9]{59}" + + signKey <- H.readFile signKeyFile + H.assert $ signKey =~ id @String "stake_sk[a-z0-9]{59}" diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/VRFKeys.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/VRFKeys.hs index 399e109561a..e65d7443ee1 100644 --- a/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/VRFKeys.hs +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Shelley/TextEnvelope/Keys/VRFKeys.hs @@ -1,15 +1,22 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} module Test.Golden.Shelley.TextEnvelope.Keys.VRFKeys ( golden_shelleyVRFKeys + , golden_shelleyVRFKeys_bech32 + , golden_shelleyVRFKeys_te ) where import Cardano.Api (AsType (..), HasTextEnvelope (..)) + import Control.Monad (void) import Hedgehog (Property) import Test.Cardano.CLI.Util +import qualified Hedgehog as H import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H +import Text.Regex.TDFA ((=~)) {- HLINT ignore "Use camelCase" -} @@ -18,6 +25,8 @@ import qualified Hedgehog.Extras.Test.Base as H -- 3. Check the TextEnvelope serialization format has not changed. golden_shelleyVRFKeys :: Property golden_shelleyVRFKeys = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + -- Reference keys referenceVerKey <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/keys/vrf_keys/verification_key" referenceSignKey <- noteInputFile "test/cardano-cli-golden/files/golden/shelley/keys/vrf_keys/signing_key" @@ -40,3 +49,59 @@ golden_shelleyVRFKeys = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do -- golden files checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the TextEnvelope serialization format has not changed. +golden_shelleyVRFKeys_te :: Property +golden_shelleyVRFKeys_te = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + + -- Reference keys + referenceVerKey <- noteInputFile "test/data/golden/shelley/keys/vrf_keys/verification_key" + referenceSignKey <- noteInputFile "test/data/golden/shelley/keys/vrf_keys/signing_key" + + -- Key filepaths + verKey <- noteTempFile tempDir "vrf-verification-key-file" + signKey <- noteTempFile tempDir "vrf-signing-key-file" + + -- Generate vrf verification key + void $ execCardanoCLI + [ "node","key-gen-VRF" + , "--key-output-format", "text-envelope" + , "--verification-key-file", verKey + , "--signing-key-file", signKey + ] + + let signingKeyType = textEnvelopeType (AsSigningKey AsVrfKey) + verificationKeyType = textEnvelopeType (AsVerificationKey AsVrfKey) + + -- Check the newly created files have not deviated from the + -- golden files + checkTextEnvelopeFormat verificationKeyType referenceVerKey verKey + checkTextEnvelopeFormat signingKeyType referenceSignKey signKey + +-- | 1. Generate a key pair +-- 2. Check for the existence of the key pair +-- 3. Check the bech32 serialization format has not changed. +golden_shelleyVRFKeys_bech32 :: Property +golden_shelleyVRFKeys_bech32 = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + H.note_ tempDir + + -- Key filepaths + verKeyFile <- noteTempFile tempDir "vrf-verification-key-file" + signKeyFile <- noteTempFile tempDir "vrf-signing-key-file" + + -- Generate vrf verification key + void $ execCardanoCLI + [ "node","key-gen-VRF" + , "--key-output-format", "bech32" + , "--verification-key-file", verKeyFile + , "--signing-key-file", signKeyFile + ] + + verKey <- H.readFile verKeyFile + H.assert $ verKey =~ id @String "vrf_vk[a-z0-9]{59}" + + signKey <- H.readFile signKeyFile + H.assert $ signKey =~ id @String "vrf_sk[a-z0-9]{110}"