Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Mar 13, 2024
1 parent 0896afd commit 3e0aeb2
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ data GovernanceCommitteeKeyHashCmdArgs era =
data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era =
GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey)
, vkeyHotKeySource :: !(VerificationKeyOrHashOrFile CommitteeHotKey)
, vkeyColdKeySource :: !(VerificationKeySource CommitteeColdKey)
, vkeyHotKeySource :: !(VerificationKeySource CommitteeHotKey)
, outFile :: !(File () Out)
} deriving Show

Expand All @@ -66,14 +66,14 @@ data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era =
} deriving Show

renderGovernanceCommitteeCmds :: GovernanceCommitteeCmds era -> Text
renderGovernanceCommitteeCmds = \case
renderGovernanceCommitteeCmds = ("governance committee" <>) . \case
GovernanceCommitteeKeyGenColdCmd {} ->
"governance committee key-gen-cold"
"key-gen-cold"
GovernanceCommitteeKeyGenHotCmd {} ->
"governance committee key-gen-hot"
"key-gen-hot"
GovernanceCommitteeKeyHashCmd {} ->
"governance committee key-hash"
"key-hash"
GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd {} ->
"governance committee create-hot-key-authorization-certificate"
"create-hot-key-authorization-certificate"
GovernanceCommitteeCreateColdKeyResignationCertificateCmd {} ->
"governance committee create-cold-key-resignation-certificate"
"create-cold-key-resignation-certificate"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import qualified Cardano.Api.Ledger as L
import Cardano.CLI.EraBased.Commands.Governance.Committee
import Cardano.CLI.EraBased.Options.Common hiding (pAnchorUrl)
import Cardano.CLI.Read
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key.VerificationKey

import Control.Applicative
import Options.Applicative (Parser)
import qualified Options.Applicative as Opt

Expand Down Expand Up @@ -103,14 +106,23 @@ pGovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd era = do
$ Opt.info
( fmap GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd $
GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs w
<$> pCommitteeColdVerificationKeyOrHashOrFile
<*> pCommitteeHotKeyOrHashOrFile
<$> pColdVerificationKeySource
<*> pHotVerificationKeySource
<*> pOutputFile
)
$ Opt.progDesc
$ mconcat
[ "Create hot key authorization certificate for a Constitutional Committee Member"
]
where
pColdVerificationKeySource = asum
[ VksKeyHashFile <$> pCommitteeColdVerificationKeyOrHashOrFile
, VksScript . File . unScriptFile <$> pScriptFor "cold-verification-key-script" Nothing "Cold script"
]
pHotVerificationKeySource = asum
[ VksKeyHashFile <$> pCommitteeHotKeyOrHashOrFile
, VksScript . File . unScriptFile <$> pScriptFor "hot-script" Nothing "Hot script"
]

pGovernanceCommitteeCreateColdKeyResignationCertificateCmd :: ()
=> CardanoEra era
Expand Down
52 changes: 28 additions & 24 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,33 +139,37 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate :: ()
runGovernanceCommitteeCreateHotKeyAuthorizationCertificate
Cmd.GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs
{ Cmd.eon = eon
, Cmd.vkeyColdKeySource = coldVkOrHashOrFp
, Cmd.vkeyHotKeySource = hotVkOrHashOrFp
, Cmd.vkeyColdKeySource
, Cmd.vkeyHotKeySource
, Cmd.outFile = oFp
} =
conwayEraOnwardsConstraints eon $ do
---
let fp = undefined :: FilePath
ScriptInAnyLang _lang hotScript <-
modifyError GovernanceCommitteeCmdScriptReadError $
readFileScriptInAnyLang fp

let hotCred = L.ScriptHashObj . toShelleyScriptHash $ hashScript hotScript

ScriptInAnyLang _lang coldScript <-
modifyError GovernanceCommitteeCmdScriptReadError $
readFileScriptInAnyLang fp

let coldCred = L.ScriptHashObj . toShelleyScriptHash $ hashScript coldScript

---
CommitteeColdKeyHash coldVKHash <-
lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp)
& onLeft (left . GovernanceCommitteeCmdKeyReadError)

CommitteeHotKeyHash hotVkHash <-
lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey hotVkOrHashOrFp)
& onLeft (left . GovernanceCommitteeCmdKeyReadError)
-- FIXME deduplicate
hotCred <-
case vkeyHotKeySource of
VksScript (File fp) -> do
ScriptInAnyLang _lang script <-
modifyError GovernanceCommitteeCmdScriptReadError $
readFileScriptInAnyLang fp
pure . L.ScriptHashObj . toShelleyScriptHash $ hashScript script
VksKeyHashFile vkOrHashOrFp -> do
CommitteeHotKeyHash vkHash <-
modifyError GovernanceCommitteeCmdKeyReadError . hoistIOEither $
readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey vkOrHashOrFp
pure $ L.KeyHashObj vkHash

coldCred <-
case vkeyColdKeySource of
VksScript (File fp) -> do
ScriptInAnyLang _lang script <-
modifyError GovernanceCommitteeCmdScriptReadError $
readFileScriptInAnyLang fp
pure . L.ScriptHashObj . toShelleyScriptHash $ hashScript script
VksKeyHashFile vkOrHashOrFp -> do
CommitteeColdKeyHash vkHash <-
modifyError GovernanceCommitteeCmdKeyReadError . hoistIOEither $
readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey vkOrHashOrFp
pure $ L.KeyHashObj vkHash

makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements eon coldCred hotCred)
& textEnvelopeToJSON (Just genKeyDelegCertDesc)
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ newtype UpdateProposalFile = UpdateProposalFile { unUpdateProposalFile :: FilePa

type VerificationKeyFile = File (VerificationKey ())

-- FIXME: replace with File
newtype ScriptFile = ScriptFile { unScriptFile :: FilePath }
deriving (Eq, Show)

Expand Down
14 changes: 14 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types/Key/VerificationKey.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}

module Cardano.CLI.Types.Key.VerificationKey
( AnyVerificationKeySource(..)
, AnyVerificationKeyText(..)
, VerificationKeySource(..)
) where

import Cardano.Api

import Cardano.CLI.Types.Key (VerificationKeyOrFile, VerificationKeyOrHashOrFile)

import Data.Text (Text)

-- | A bech32 text encoded verification key of an unspecified key role.
Expand All @@ -21,3 +27,11 @@ data AnyVerificationKeySource
= AnyVerificationKeySourceOfText !AnyVerificationKeyText
| AnyVerificationKeySourceOfFile !(File (VerificationKey ()) In)
deriving (Eq, Show)

-- FIXME: not a verification key source
data VerificationKeySource c
= VksKeyHashFile !(VerificationKeyOrHashOrFile c)
| VksScript !(File ScriptInAnyLang In)

deriving instance (Eq (VerificationKeyOrHashOrFile c)) => Eq (VerificationKeySource c)
deriving instance (Show (VerificationKeyOrHashOrFile c)) => Show (VerificationKeySource c)
2 changes: 2 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 @@ -6346,10 +6346,12 @@ Usage: cardano-cli conway governance committee create-hot-key-authorization-cert
( --cold-verification-key STRING
| --cold-verification-key-file FILE
| --cold-verification-key-hash STRING
| --cold-script FILE
)
( --hot-key STRING
| --hot-key-file FILE
| --hot-key-hash STRING
| --hot-script FILE
)
--out-file FILE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ Usage: cardano-cli conway governance committee create-hot-key-authorization-cert
( --cold-verification-key STRING
| --cold-verification-key-file FILE
| --cold-verification-key-hash STRING
| --cold-script FILE
)
( --hot-key STRING
| --hot-key-file FILE
| --hot-key-hash STRING
| --hot-script FILE
)
--out-file FILE

Expand All @@ -18,8 +20,10 @@ Available options:
Filepath of the Consitutional Committee cold key.
--cold-verification-key-hash STRING
Constitutional Committee key hash (hex-encoded).
--cold-script FILE Cold script
--hot-key STRING Constitutional Committee hot key (hex-encoded).
--hot-key-file FILE Filepath of the Consitutional Committee hot key.
--hot-key-hash STRING Constitutional Committee key hash (hex-encoded).
--hot-script FILE Hot script
--out-file FILE The output file.
-h,--help Show this help text

0 comments on commit 3e0aeb2

Please sign in to comment.