Skip to content

Commit

Permalink
ccm key-gen-cold and ccm key-gen-hot
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed May 25, 2023
1 parent 0973434 commit e052eb3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 70 deletions.
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Expand Up @@ -290,10 +290,10 @@ data CcCmd
= CcKeyGenCold
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| CcKeyGenVRF
| CcKeyGenHot
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| CcKeyHashVRF
(VerificationKeyOrFile VrfKey)
(Maybe (File () Out))
Expand Down
16 changes: 8 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Expand Up @@ -841,11 +841,11 @@ pTransaction envCli =
pGovernanceCcCmd :: Parser CcCmd
pGovernanceCcCmd =
asum
[ subParser "key-gen" . Opt.info pKeyGenOperator . Opt.progDesc $ mconcat
[ subParser "key-gen-cold" . Opt.info pCcKeyGenCold . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM's offline "
, "key and a new certificate issue counter"
]
, subParser "key-gen-VRF" . Opt.info pKeyGenVRF . Opt.progDesc $ mconcat
, subParser "key-gen-hot" . Opt.info pKeyGenHot . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM VRF operational key"
]
, subParser "key-hash-VRF". Opt.info pKeyHashVRF . Opt.progDesc $ mconcat
Expand All @@ -859,18 +859,18 @@ pGovernanceCcCmd =
]
]
where
pKeyGenOperator :: Parser CcCmd
pKeyGenOperator =
pCcKeyGenCold :: Parser CcCmd
pCcKeyGenCold =
CcKeyGenCold
<$> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile

pKeyGenVRF :: Parser CcCmd
pKeyGenVRF =
CcKeyGenVRF
pKeyGenHot :: Parser CcCmd
pKeyGenHot =
CcKeyGenHot
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
<*> pOperatorCertIssueCounterFile

pKeyHashVRF :: Parser CcCmd
pKeyHashVRF =
Expand Down
98 changes: 51 additions & 47 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Governance/Cc.hs
Expand Up @@ -6,7 +6,7 @@ module Cardano.CLI.Shelley.Run.Governance.Cc
, renderShelleyGovernanceCcCmdError
, runGovernanceCcCmd
, runCcKeyGenCold
, runCcKeyGenVRF
, runCcKeyGenHot
) where

import Cardano.Api
Expand Down Expand Up @@ -58,66 +58,70 @@ renderShelleyGovernanceCcCmdError err =

runGovernanceCcCmd :: CcCmd -> ExceptT ShelleyGovernanceCcCmdError IO ()
runGovernanceCcCmd = \case
CcKeyGenCold vk sk ctr -> runCcKeyGenCold vk sk ctr
CcKeyGenVRF vk sk -> runCcKeyGenVRF vk sk
CcKeyGenCold vk sk -> runCcKeyGenCold vk sk
CcKeyGenHot vk sk ctr -> runCcKeyGenHot vk sk ctr
CcKeyHashVRF vk mOutFp -> runCcKeyHashVRF vk mOutFp
CcNewCounter vk ctr out -> runCcNewCounter vk ctr out
CcIssueOpCert vk sk ctr p out -> runCcIssueOpCert vk sk ctr p out


--
-- Cc command implementations
-- Constitutional Committee command implementations
--

runCcKeyGenCold :: VerificationKeyFile Out
-> SigningKeyFile Out
-> OpCertCounterFile Out
-> ExceptT ShelleyGovernanceCcCmdError IO ()
runCcKeyGenCold vkeyPath skeyPath ocertCtrPath = do
skey <- liftIO $ generateSigningKey AsStakePoolKey
let vkey = getVerificationKey skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile skeyPath
$ textEnvelopeToJSON (Just skeyDesc) skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile vkeyPath
$ textEnvelopeToJSON (Just vkeyDesc) vkey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile ocertCtrPath
$ textEnvelopeToJSON (Just ocertCtrDesc)
$ OperationalCertificateIssueCounter initialCounter vkey
runCcKeyGenCold ::
VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT ShelleyGovernanceCcCmdError IO ()
runCcKeyGenCold vkeyPath skeyPath = do
skey <- liftIO $ generateSigningKey AsGenesisKey
let vkey = getVerificationKey skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile skeyPath
$ textEnvelopeToJSON (Just skeyDesc) skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile vkeyPath
$ textEnvelopeToJSON (Just vkeyDesc) vkey
where
skeyDesc, vkeyDesc, ocertCtrDesc :: TextEnvelopeDescr
skeyDesc = "Stake Pool Operator Signing Key"
vkeyDesc = "Stake Pool Operator Verification Key"
ocertCtrDesc = "Next certificate issue number: "
<> fromString (show initialCounter)

initialCounter :: Word64
initialCounter = 0
skeyDesc, vkeyDesc :: TextEnvelopeDescr
skeyDesc = "Constitutional Committee Cold Signing Key"
vkeyDesc = "Constitutional Committee Cold Verification Key"

runCcKeyGenVRF ::
runCcKeyGenHot ::
VerificationKeyFile Out
-> SigningKeyFile Out
-> OpCertCounterFile Out
-> ExceptT ShelleyGovernanceCcCmdError IO ()
runCcKeyGenVRF vkeyPath skeyPath = do
skey <- liftIO $ generateSigningKey AsVrfKey
let vkey = getVerificationKey skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFileWithOwnerPermissions skeyPath
$ textEnvelopeToJSON (Just skeyDesc) skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile vkeyPath
$ textEnvelopeToJSON (Just vkeyDesc) vkey
runCcKeyGenHot vkeyPath skeyPath ocertCtrPath = do
skey <- liftIO $ generateSigningKey AsGenesisDelegateKey
let vkey = getVerificationKey skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile skeyPath
$ textEnvelopeToJSON (Just skeyDesc) skey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile vkeyPath
$ textEnvelopeToJSON (Just vkeyDesc) vkey
firstExceptT ShelleyGovernanceCcCmdWriteFileError
. newExceptT
$ writeLazyByteStringFile ocertCtrPath
$ textEnvelopeToJSON (Just certCtrDesc)
$ OperationalCertificateIssueCounter
initialCounter
(castVerificationKey vkey)
where
skeyDesc, vkeyDesc :: TextEnvelopeDescr
skeyDesc = "VRF Signing Key"
vkeyDesc = "VRF Verification Key"
skeyDesc, vkeyDesc, certCtrDesc :: TextEnvelopeDescr
skeyDesc = "Constitutional Committee Hot Signing Key"
vkeyDesc = "Constitutional Committee Hot Verification Key"
certCtrDesc = "Next certificate issue number: "
<> fromString (show initialCounter)

initialCounter :: Word64
initialCounter = 0


runCcKeyHashVRF :: VerificationKeyOrFile VrfKey
-> Maybe (File () Out)
Expand Down
13 changes: 9 additions & 4 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Expand Up @@ -98,18 +98,23 @@ Usage: cardano-cli governance action query --socket-path SOCKET_PATH
Query an on-chain action

Usage: cardano-cli governance cc
(key-gen | key-gen-VRF | key-hash-VRF | new-counter | issue-op-cert)
( key-gen-cold
| key-gen-hot
| key-hash-VRF
| new-counter
| issue-op-cert
)

Constitutional Committee operation commands

Usage: cardano-cli governance cc key-gen --cold-verification-key-file FILE
Usage: cardano-cli governance cc key-gen-cold --cold-verification-key-file FILE
--cold-signing-key-file FILE
--operational-certificate-issue-counter-file FILE

Create a key pair for a CCM's offline key and a new certificate issue counter

Usage: cardano-cli governance cc key-gen-VRF --verification-key-file FILE
Usage: cardano-cli governance cc key-gen-hot --verification-key-file FILE
--signing-key-file FILE
--operational-certificate-issue-counter-file FILE

Create a key pair for a CCM VRF operational key

Expand Down
@@ -1,15 +1,20 @@
Usage: cardano-cli governance cc
(key-gen | key-gen-VRF | key-hash-VRF | new-counter | issue-op-cert)
( key-gen-cold
| key-gen-hot
| key-hash-VRF
| new-counter
| issue-op-cert
)

Constitutional Committee operation commands

Available options:
-h,--help Show this help text

Available commands:
key-gen Create a key pair for a CCM's offline key and a new
key-gen-cold Create a key pair for a CCM's offline key and a new
certificate issue counter
key-gen-VRF Create a key pair for a CCM VRF operational key
key-gen-hot Create a key pair for a CCM VRF operational key
key-hash-VRF Print hash of a CCM's operational VRF key.
new-counter Create a new certificate issue counter
issue-op-cert Issue a CCM operational certificate
@@ -1,6 +1,5 @@
Usage: cardano-cli governance cc key-gen --cold-verification-key-file FILE
Usage: cardano-cli governance cc key-gen-cold --cold-verification-key-file FILE
--cold-signing-key-file FILE
--operational-certificate-issue-counter-file FILE

Create a key pair for a CCM's offline key and a new certificate issue counter

Expand All @@ -9,7 +8,4 @@ Available options:
Filepath of the cold verification key.
--cold-signing-key-file FILE
Filepath of the cold signing key.
--operational-certificate-issue-counter-file FILE
The file with the issue counter for the operational
certificate.
-h,--help Show this help text
@@ -1,10 +1,14 @@
Usage: cardano-cli governance cc key-gen-VRF --verification-key-file FILE
Usage: cardano-cli governance cc key-gen-hot --verification-key-file FILE
--signing-key-file FILE
--operational-certificate-issue-counter-file FILE

Create a key pair for a CCM VRF operational key

Available options:
--verification-key-file FILE
Output filepath of the verification key.
--signing-key-file FILE Output filepath of the signing key.
--operational-certificate-issue-counter-file FILE
The file with the issue counter for the operational
certificate.
-h,--help Show this help text

0 comments on commit e052eb3

Please sign in to comment.