Skip to content

Commit

Permalink
#128 DRep key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 10, 2023
1 parent 2f80fa6 commit e2fba65
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 2 deletions.
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

1 change: 1 addition & 0 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ test-suite cardano-cli-golden
Test.Golden.Byron.Witness
Test.Golden.ErrorsSpec
Test.Golden.Governance.Committee
Test.Golden.Governance.DRep
Test.Golden.Help
Test.Golden.Key.NonExtendedKey
Test.Golden.Shelley.Address.Build
Expand Down
5 changes: 5 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ data EraBasedGovernanceCmds era
(GovernanceCommitteeCmds era)
| EraBasedGovernanceActionCmds
(GovernanceActionCmds era)
| EraBasedGovernanceDRepGenerateKey
(ConwayEraOnwards era)
(File (VerificationKey ()) Out)
(File (SigningKey ()) Out)

renderEraBasedGovernanceCmds :: EraBasedGovernanceCmds era -> Text
renderEraBasedGovernanceCmds = \case
Expand All @@ -69,3 +73,4 @@ renderEraBasedGovernanceCmds = \case
renderGovernanceCommitteeCmds cmds
EraBasedGovernanceActionCmds cmds ->
renderGovernanceActionCmds cmds
EraBasedGovernanceDRepGenerateKey{} -> "governance drep key-gen"
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ pCreateConstitution envCli =
<*> pVotingCredential
<*> pConstitution
<*> pFileOutDirection "out-file" "Output filepath of the governance action."

15 changes: 15 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pEraBasedGovernanceCmds envCli era =
, pCreateMirCertificatesCmds era
, pGovernanceCommitteeCmds era <&> fmap EraBasedGovernanceCommitteeCmds
, fmap EraBasedGovernanceActionCmds <$> pGovernanceActionCmds era
, pDRepCommands era
]


Expand Down Expand Up @@ -301,3 +302,17 @@ pMIRTransferToReserves w =

--------------------------------------------------------------------------------

pDRepCommands :: ()
=> CardanoEra era
-> Maybe (Parser (EraBasedGovernanceCmds era))
pDRepCommands era = do
w <- maybeFeatureInEra era
pure $
subParser "drep"
$ Opt.info (pKeyGen w)
$ Opt.progDesc "Delegate Representative commands."
where
pKeyGen w =
subParser "key-gen"
$ Opt.info (EraBasedGovernanceDRepGenerateKey w <$> pVerificationKeyFileOut <*> pSigningKeyFileOut)
$ Opt.progDesc "Generate Delegate Representative verification and signing keys."
5 changes: 5 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ runEraBasedGovernanceCmds = \case
EraBasedGovernanceActionCmds cmds ->
firstExceptT (const ()) -- TODO: Conway era - fix error handling
$ runGovernanceActionCmds cmds

EraBasedGovernanceDRepGenerateKey w vrf sgn ->
firstExceptT (const ()) -- TODO: Conway era - fix error handling
$ runGovernanceDRepKeyGen w vrf sgn

runEraBasedGovernancePreConwayCmd
:: ShelleyToBabbageEra era
-> ExceptT () IO ()
Expand Down
17 changes: 17 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.CLI.EraBased.Run.Governance
( runGovernanceCmds
, runGovernanceMIRCertificatePayStakeAddrs
, runGovernanceMIRCertificateTransfer
, runGovernanceDRepKeyGen
) where


Expand Down Expand Up @@ -334,3 +335,19 @@ runGovernanceVerifyPoll pollFile txFile mOutFile = do

lift (writeByteStringOutput mOutFile (prettyPrintJSON signatories))
& onLeft (left . GovernanceCmdWriteFileError)

runGovernanceDRepKeyGen
:: ConwayEraOnwards era
-> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT GovernanceCmdError IO ()
runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFileError $ do
skey <- liftIO $ generateSigningKey AsDRepKey
let vkey = getVerificationKey skey
newExceptT $ writeLazyByteStringFile skeyPath (textEnvelopeToJSON (Just skeyDesc) skey)
newExceptT $ writeLazyByteStringFile vkeyPath (textEnvelopeToJSON (Just vkeyDesc) vkey)
where
skeyDesc :: TextEnvelopeDescr
skeyDesc = "Delegate Representative Signing Key"
vkeyDesc :: TextEnvelopeDescr
vkeyDesc = "Delegate Representative Verification Key"
30 changes: 30 additions & 0 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{- HLINT ignore "Use camelCase" -}

module Test.Golden.Governance.DRep where

import Control.Monad (void)

import Test.Cardano.CLI.Util

import Hedgehog (Property)
import qualified Hedgehog.Extras.Test.Base as H
import qualified Hedgehog.Extras.Test.File as H

hprop_golden_governanceDRepKeyGen :: Property
hprop_golden_governanceDRepKeyGen =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
verificationKeyFile <- noteTempFile tempDir "key-gen.vkey"
signingKeyFile <- noteTempFile tempDir "key-gen.skey"

void $ execCardanoCLI
[ "conway", "governance", "drep", "key-gen"
, "--verification-key-file", verificationKeyFile
, "--signing-key-file", signingKeyFile
]

H.assertFileOccurences 1 "DRepVerificationKey_ed25519" verificationKeyFile
H.assertFileOccurences 1 "DRepSigningKey_ed25519" signingKeyFile

H.assertFileOccurences 1 "Delegate Representative Verification Key" verificationKeyFile
H.assertFileOccurences 1 "Delegate Representative Signing Key" signingKeyFile

20 changes: 20 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ Usage: cardano-cli conway governance
| vote
| committee
| action
| drep
)

Era-based governance commands
Expand Down Expand Up @@ -649,6 +650,15 @@ Usage: cardano-cli conway governance action create-constitution --governance-act

Create a constitution.

Usage: cardano-cli conway governance drep key-gen

Delegate Representative commands.

Usage: cardano-cli conway governance drep key-gen --verification-key-file FILE
--signing-key-file FILE

Generate Delegate Representative verification and signing keys.

Usage: cardano-cli latest governance

Latest era commands (Babbage)
Expand Down Expand Up @@ -758,6 +768,7 @@ Usage: cardano-cli experimental governance
| vote
| committee
| action
| drep
)

Era-based governance commands
Expand Down Expand Up @@ -888,6 +899,15 @@ Usage: cardano-cli experimental governance action create-constitution --governan

Create a constitution.

Usage: cardano-cli experimental governance drep key-gen

Delegate Representative commands.

Usage: cardano-cli experimental governance drep key-gen --verification-key-file FILE
--signing-key-file FILE

Generate Delegate Representative verification and signing keys.

Usage: cardano-cli legacy Legacy commands

Legacy commands
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Usage: cardano-cli conway governance drep key-gen --verification-key-file FILE
--signing-key-file FILE

Generate Delegate Representative verification and signing keys.

Available options:
--verification-key-file FILE
Output filepath of the verification key.
--signing-key-file FILE Output filepath of the signing key.
-h,--help Show this help text
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Usage: cardano-cli experimental governance drep key-gen --verification-key-file FILE
--signing-key-file FILE

Generate Delegate Representative verification and signing keys.

Available options:
--verification-key-file FILE
Output filepath of the verification key.
--signing-key-file FILE Output filepath of the signing key.
-h,--help Show this help text

0 comments on commit e2fba65

Please sign in to comment.