Skip to content

Commit

Permalink
Add support for Bech32 serialisation of keys in Shelley node CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate authored and newhoggy committed Mar 16, 2023
1 parent 8d62858 commit 1137e03
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
8 changes: 6 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,15 @@ pNodeCmd =

pKeyGenKES :: Parser NodeCmd
pKeyGenKES =
NodeKeyGenKES <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
NodeKeyGenKES
<$> pVerificationKeyFile Output
<*> pSigningKeyFile Output

pKeyGenVRF :: Parser NodeCmd
pKeyGenVRF =
NodeKeyGenVRF <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
NodeKeyGenVRF
<$> pVerificationKeyFile Output
<*> pSigningKeyFile Output

pKeyHashVRF :: Parser NodeCmd
pKeyHashVRF =
Expand Down
69 changes: 37 additions & 32 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, readVerificationKeyOrFile)
import Cardano.CLI.Shelley.Key (OutputDirection (..), VerificationKeyOrFile,
readVerificationKeyOrFile, writeOutputBech32)
import Cardano.CLI.Types (SigningKeyFile (..), VerificationKeyFile (..))

{- HLINT ignore "Reduce duplication" -}
Expand Down Expand Up @@ -75,24 +76,27 @@ runNodeKeyGenCold :: VerificationKeyFile
-> SigningKeyFile
-> OpCertCounterFile
-> ExceptT ShelleyNodeCmdError IO ()
runNodeKeyGenCold (VerificationKeyFile vkeyPath) (SigningKeyFile skeyPath)
runNodeKeyGenCold (VerificationKeyFile vkeyPath)
(SigningKeyFile skeyPath)
(OpCertCounterFile ocertCtrPath) = do
skey <- liftIO $ generateSigningKey AsStakePoolKey
let vkey = getVerificationKey skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope skeyPath (Just skeyDesc) skey
$ writeOutputBech32
(OutputDirectionFile skeyPath)
skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope vkeyPath (Just vkeyDesc) vkey
$ writeOutputBech32
(OutputDirectionFile vkeyPath)
vkey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope ocertCtrPath (Just ocertCtrDesc)
$ OperationalCertificateIssueCounter initialCounter vkey
where
skeyDesc, vkeyDesc, ocertCtrDesc :: TextEnvelopeDescr
skeyDesc = "Stake Pool Operator Signing Key"
vkeyDesc = "Stake Pool Operator Verification Key"
ocertCtrDesc :: TextEnvelopeDescr
ocertCtrDesc = "Next certificate issue number: "
<> fromString (show initialCounter)

Expand All @@ -104,34 +108,36 @@ runNodeKeyGenKES :: VerificationKeyFile
-> SigningKeyFile
-> ExceptT ShelleyNodeCmdError IO ()
runNodeKeyGenKES (VerificationKeyFile vkeyPath) (SigningKeyFile skeyPath) = do
skey <- liftIO $ generateSigningKey AsKesKey
let vkey = getVerificationKey skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope skeyPath (Just skeyDesc) skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope vkeyPath (Just vkeyDesc) vkey
where
skeyDesc, vkeyDesc :: TextEnvelopeDescr
skeyDesc = "KES Signing Key"
vkeyDesc = "KES Verification Key"
skey <- liftIO $ generateSigningKey AsKesKey
let vkey = getVerificationKey skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeOutputBech32
(OutputDirectionFile skeyPath)
skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeOutputBech32
(OutputDirectionFile vkeyPath)
vkey


runNodeKeyGenVRF :: VerificationKeyFile -> SigningKeyFile
-> ExceptT ShelleyNodeCmdError IO ()
runNodeKeyGenVRF (VerificationKeyFile vkeyPath) (SigningKeyFile skeyPath) = do
skey <- liftIO $ generateSigningKey AsVrfKey
let vkey = getVerificationKey skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelopeWithOwnerPermissions skeyPath (Just skeyDesc) skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeFileTextEnvelope vkeyPath (Just vkeyDesc) vkey
where
skeyDesc, vkeyDesc :: TextEnvelopeDescr
skeyDesc = "VRF Signing Key"
vkeyDesc = "VRF Verification Key"
skey <- liftIO $ generateSigningKey AsVrfKey
let vkey = getVerificationKey skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeOutputBech32
(OutputDirectionFile skeyPath)
skey
firstExceptT ShelleyNodeCmdWriteFileError
. newExceptT
$ writeOutputBech32
(OutputDirectionFile vkeyPath)
vkey


runNodeKeyHashVRF :: VerificationKeyOrFile VrfKey
-> Maybe OutputFile
Expand Down Expand Up @@ -260,4 +266,3 @@ readColdVerificationKeyOrFile coldVerKeyOrFile =
, FromSomeType (AsVerificationKey AsGenesisDelegateKey) castVerificationKey
]
fp

0 comments on commit 1137e03

Please sign in to comment.