Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#128 DRep key generation #163

Merged
merged 1 commit into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2023-07-28"
CABAL_CACHE_VERSION: "2023-08-14"

concurrency:
group: >
Expand Down
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 @@ -298,6 +298,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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about having a single key generation command that generates all the different keys? cc: @newhoggy @disassembler

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a really good idea!

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


Expand Down Expand Up @@ -297,3 +298,18 @@ pMIRTransferToReserves w =
<*> pure TransferToReserves

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

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
19 changes: 19 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Cardano.CLI.EraBased.Run.Governance
( runGovernanceMIRCertificatePayStakeAddrs
, runGovernanceMIRCertificateTransfer
, runGovernanceDRepKeyGen
) where

import Cardano.Api
Expand All @@ -14,6 +15,8 @@ import Cardano.CLI.Types.Common
import qualified Cardano.Ledger.Shelley.TxBody as Shelley

import Control.Monad

import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -72,3 +75,19 @@ runGovernanceMIRCertificateTransfer w ll oFp direction = do
mirCertDesc :: TransferDirection -> TextEnvelopeDescr
mirCertDesc TransferToTreasury = "MIR Certificate Send To Treasury"
mirCertDesc TransferToReserves = "MIR Certificate Send To Reserves"

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"
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,4 @@ pCreateConstitution envCli =
<*> pVotingCredential
<*> pConstitution
<*> pFileOutDirection "out-file" "Output filepath of the governance action."

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
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli conway governance
| vote
| committee
| action
| drep
)

Era-based governance commands
Expand All @@ -17,3 +18,4 @@ Available commands:
vote Vote creation.
committee Committee member commands.
action Governance action commands.
drep Delegate Representative commands.
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
Expand Up @@ -4,6 +4,7 @@ Usage: cardano-cli experimental governance
| vote
| committee
| action
| drep
)

Era-based governance commands
Expand All @@ -17,3 +18,4 @@ Available commands:
vote Vote creation.
committee Committee member commands.
action Governance action commands.
drep Delegate Representative commands.
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