Skip to content

Add pool operator extended key support #1091

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

Merged
merged 4 commits into from
Apr 25, 2025
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
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2025-04-16T18:30:40Z
, cardano-haskell-packages 2025-04-18T06:38:47Z
, cardano-haskell-packages 2025-04-25T15:50:18Z


packages:
cardano-cli
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ library
binary,
bytestring,
canonical-json,
cardano-api ^>=10.14,
cardano-api ^>=10.15,
cardano-binary,
cardano-crypto,
cardano-crypto-class ^>=2.2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data CompatibleStakeAddressCmds era
| CompatibleStakeAddressStakeDelegationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
StakePoolKeyHashSource
(File () Out)
deriving Show

Expand Down
25 changes: 15 additions & 10 deletions cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,45 @@ runStakeAddressStakeDelegationCertificateCmd
=> ShelleyBasedEra era
-> StakeIdentifier
-- ^ Delegator stake verification key, verification key file or script file.
-> VerificationKeyOrHashOrFile StakePoolKey
-> StakePoolKeyHashSource
-- ^ Delegatee stake pool verification key or verification key file or
-- verification key hash.
-> File () Out
-> CIO e ()
runStakeAddressStakeDelegationCertificateCmd sbe stakeVerifier poolVKeyOrHashOrFile outFp =
shelleyBasedEraConstraints sbe $ do
poolStakeVKeyHash <-
fromExceptTCli $
readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile
poolStakeVKeyHash <- getHashFromStakePoolKeyHashSource poolVKeyOrHashOrFile

stakeCred <-
fromExceptTCli $ getStakeCredentialFromIdentifier stakeVerifier

let certificate = createStakeDelegationCertificate stakeCred poolStakeVKeyHash sbe
let certificate =
createStakeDelegationCertificate sbe stakeCred poolStakeVKeyHash

fromEitherIOCli @(FileError ()) $
writeLazyByteStringFile outFp $
textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Delegation Certificate") certificate

createStakeDelegationCertificate
:: StakeCredential
:: ShelleyBasedEra era
-> StakeCredential
-> Hash StakePoolKey
-> ShelleyBasedEra era
-> Certificate era
createStakeDelegationCertificate stakeCredential (StakePoolKeyHash poolStakeVKeyHash) = do
createStakeDelegationCertificate sbe stakeCredential stakePoolHash = do
caseShelleyToBabbageOrConwayEraOnwards
( \w ->
shelleyToBabbageEraConstraints w $
ShelleyRelatedCertificate w $
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) poolStakeVKeyHash
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) (toLedgerHash stakePoolHash)
)
( \w ->
conwayEraOnwardsConstraints w $
ConwayCertificate w $
L.mkDelegTxCert (toShelleyStakeCredential stakeCredential) (L.DelegStake poolStakeVKeyHash)
L.mkDelegTxCert
(toShelleyStakeCredential stakeCredential)
(L.DelegStake (toLedgerHash stakePoolHash))
)
sbe
where
toLedgerHash :: Hash StakePoolKey -> L.KeyHash L.StakePool
toLedgerHash (StakePoolKeyHash poolStakeVKeyHash) = poolStakeVKeyHash
6 changes: 3 additions & 3 deletions cardano-cli/src/Cardano/CLI/Compatible/StakePool/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import Prelude

import Data.Text (Text)

data CompatibleStakePoolCmds era
newtype CompatibleStakePoolCmds era
= CompatibleStakePoolRegistrationCertificateCmd
!(CompatibleStakePoolRegistrationCertificateCmdArgs era)
(CompatibleStakePoolRegistrationCertificateCmdArgs era)
deriving Show

data CompatibleStakePoolRegistrationCertificateCmdArgs era
= CompatibleStakePoolRegistrationCertificateCmdArgs
{ sbe :: !(ShelleyBasedEra era)
-- ^ Era in which to register the stake pool.
, poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
, poolVerificationKeyOrFile :: !StakePoolVerificationKeySource
-- ^ Stake pool verification key.
, vrfVerificationKeyOrFile :: !(VerificationKeyOrFile VrfKey)
-- ^ VRF Verification key.
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/Compatible/StakePool/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import Cardano.Api.Shelley
import Cardano.CLI.Compatible.Exception
import Cardano.CLI.Compatible.StakePool.Command
import Cardano.CLI.EraBased.StakePool.Internal.Metadata
import Cardano.CLI.Read
( getVerificationKeyFromStakePoolVerificationKeySource
)
import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Error.StakePoolCmdError
import Cardano.CLI.Type.Key (readVerificationKeyOrFile)
Expand Down Expand Up @@ -48,11 +51,8 @@ runStakePoolRegistrationCertificateCmd
} =
shelleyBasedEraConstraints sbe $ do
-- Pool verification key
stakePoolVerKey <-
fromExceptTCli $
firstExceptT StakePoolCmdReadKeyFileError $
readVerificationKeyOrFile AsStakePoolKey poolVerificationKeyOrFile
let stakePoolId' = verificationKeyHash stakePoolVerKey
stakePoolVerKey <- getVerificationKeyFromStakePoolVerificationKeySource poolVerificationKeyOrFile
let stakePoolId' = anyStakePoolVerificationKeyHash stakePoolVerKey

-- VRF verification key
vrfVerKey <-
Expand Down
40 changes: 30 additions & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -445,23 +445,40 @@ parseLovelace = do
else return $ L.Coin i

-- | The first argument is the optional prefix.
pStakePoolVerificationKeyOrFile :: Maybe String -> Parser (VerificationKeyOrFile StakePoolKey)
pStakePoolVerificationKeyOrFile
:: Maybe String
-> Parser StakePoolVerificationKeySource
pStakePoolVerificationKeyOrFile prefix =
asum
[ VerificationKeyValue <$> pStakePoolVerificationKey prefix
, VerificationKeyFilePath <$> pStakePoolVerificationKeyFile prefix
[ StakePoolVerificationKeyFromLiteral . AnyStakePoolNormalVerificationKey
<$> pStakePoolVerificationNormalKey prefix
, StakePoolVerificationKeyFromLiteral . AnyStakePoolExtendedVerificationKey
<$> pStakePoolVerificationExtendedKey prefix
, StakePoolVerificationKeyFromFile <$> pStakePoolVerificationKeyFile prefix
]

-- | The first argument is the optional prefix.
pStakePoolVerificationKey :: Maybe String -> Parser (VerificationKey StakePoolKey)
pStakePoolVerificationKey prefix =
pStakePoolVerificationNormalKey
:: Maybe String -> Parser (VerificationKey StakePoolKey)
pStakePoolVerificationNormalKey prefix =
Opt.option (readVerificationKey AsStakePoolKey) $
mconcat
[ Opt.long $ prefixFlag prefix "stake-pool-verification-key"
, Opt.metavar "STRING"
, Opt.help "Stake pool verification key (Bech32 or hex-encoded)."
]

-- | The first argument is the optional prefix.
pStakePoolVerificationExtendedKey
:: Maybe String -> Parser (VerificationKey StakePoolExtendedKey)
pStakePoolVerificationExtendedKey prefix =
Opt.option (readVerificationKey AsStakePoolExtendedKey) $
mconcat
[ Opt.long $ prefixFlag prefix "stake-pool-verification-extended-key"
, Opt.metavar "STRING"
, Opt.help "Stake pool verification extended key (Bech32 or hex-encoded)."
]

-- | The first argument is the optional prefix.
pStakePoolVerificationKeyFile :: Maybe String -> Parser (VerificationKeyFile In)
pStakePoolVerificationKeyFile prefix =
Expand Down Expand Up @@ -581,7 +598,10 @@ rVerificationKey a mErrPrefix =
pColdVerificationKeyOrFile :: Maybe String -> Parser ColdVerificationKeyOrFile
pColdVerificationKeyOrFile prefix =
asum
[ ColdStakePoolVerificationKey <$> pStakePoolVerificationKey prefix
[ ColdStakePoolVerificationKey . AnyStakePoolNormalVerificationKey
<$> pStakePoolVerificationNormalKey prefix
, ColdStakePoolVerificationKey . AnyStakePoolExtendedVerificationKey
<$> pStakePoolVerificationExtendedKey prefix
, ColdGenesisDelegateVerificationKey <$> pGenesisDelegateVerificationKey
, ColdVerificationKeyFile <$> pColdVerificationKeyFile
]
Expand Down Expand Up @@ -961,11 +981,11 @@ pStakeVerificationKeyHash prefix =

-- | The first argument is the optional prefix.
pStakePoolVerificationKeyOrHashOrFile
:: Maybe String -> Parser (VerificationKeyOrHashOrFile StakePoolKey)
:: Maybe String -> Parser StakePoolKeyHashSource
pStakePoolVerificationKeyOrHashOrFile prefix =
asum
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile prefix
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix
[ StakePoolKeyHashSource <$> pStakePoolVerificationKeyOrFile prefix
, StakePoolKeyHashLiteral <$> pStakePoolVerificationKeyHash prefix
]

--------------------------------------------------------------------------------
Expand Down Expand Up @@ -3424,7 +3444,7 @@ pVoterType =
]

-- TODO: Conway era include "normal" stake keys
pVotingCredential :: Parser (VerificationKeyOrFile StakePoolKey)
pVotingCredential :: Parser StakePoolVerificationKeySource
pVotingCredential = pStakePoolVerificationKeyOrFile Nothing

pVoteDelegationTarget :: Parser VoteDelegationTarget
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Genesis/Option.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ pGenesisCreateTestNetData era envCli =
<*> pNumGenesisKeys
<*> pNumPools
<*> pNumStakeDelegs
<*> (case era of Exp.BabbageEra -> pure 0; Exp.ConwayEra -> pNumCommittee) -- Committee doesn't exist in babbage
<*> (case era of Exp.BabbageEra -> pure $ DRepCredentials OnDisk 0; Exp.ConwayEra -> pNumDReps) -- DReps don't exist in babbage
<*> (case era of Exp.ConwayEra -> pNumCommittee) -- Committee doesn't exist in babbage
<*> (case era of Exp.ConwayEra -> pNumDReps) -- DReps don't exist in babbage
<*> pNumStuffedUtxoCount
<*> pNumUtxoKeys
<*> pSupply
Expand Down
3 changes: 2 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys = do
createOpCert (kesKey, delegateKey) = either (error . show) id eResult
where
eResult = issueOperationalCertificate kesKey (Right delegateKey) (KESPeriod 0) counter
counter = OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
counter =
OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
convertFun
:: VerificationKey GenesisDelegateExtendedKey
-> VerificationKey StakePoolKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Cardano.Api.Shelley
import Cardano.CLI.EraBased.Governance.Vote.Command qualified as Cmd
import Cardano.CLI.EraBased.Script.Vote.Read
import Cardano.CLI.EraIndependent.Hash.Internal.Common (carryHashChecks)
import Cardano.CLI.Read (getHashFromStakePoolKeyHashSource)
import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Error.CmdError
import Cardano.CLI.Type.Error.GovernanceVoteCmdError
Expand Down Expand Up @@ -85,7 +86,8 @@ runGovernanceVoteCreateCmd
drepCred <- readVerificationKeyOrHashOrFileOrScriptHash AsDRepKey unDRepKeyHash stake
pure $ L.DRepVoter drepCred
AnyStakePoolVerificationKeyOrHashOrFile stake -> do
StakePoolKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake
StakePoolKeyHash h <-
liftIO $ getHashFromStakePoolKeyHashSource stake
pure $ L.StakePoolVoter h
AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash stake -> do
hotCred <- readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeHotKey unCommitteeHotKeyHash stake
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ data QueryCommons = QueryCommons
data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
{ commons :: !QueryCommons
, genesisFp :: !GenesisFile
, poolColdVerKeyFile :: !(VerificationKeyOrHashOrFile StakePoolKey)
, poolColdVerKeyFile :: !StakePoolKeyHashSource
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR but @newhoggy we should use Vary here too.

, vrkSkeyFp :: !(SigningKeyFile In)
, whichSchedule :: !EpochLeadershipSchedule
, format :: !(Vary [FormatJson, FormatText])
Expand Down
13 changes: 8 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import Cardano.Binary qualified as CBOR
import Cardano.CLI.EraBased.Genesis.Internal.Common
import Cardano.CLI.EraBased.Query.Command qualified as Cmd
import Cardano.CLI.Helper
import Cardano.CLI.Read
( getHashFromStakePoolKeyHashSource
)
import Cardano.CLI.Type.Common
import Cardano.CLI.Type.Error.NodeEraMismatchError
import Cardano.CLI.Type.Error.QueryCmdError
Expand Down Expand Up @@ -556,7 +559,8 @@ runQueryKesPeriodInfoCmd
-- We need the stake pool id to determine what the counter of our SPO
-- should be.
let opCertCounterMap = Consensus.getOpCertCounters (Proxy @(ConsensusProtocol era)) chainDepState
StakePoolKeyHash blockIssuerHash = verificationKeyHash stakePoolVKey
StakePoolKeyHash blockIssuerHash =
verificationKeyHash stakePoolVKey

case Map.lookup (coerce blockIssuerHash) opCertCounterMap of
-- Operational certificate exists in the protocol state
Expand Down Expand Up @@ -1431,9 +1435,7 @@ runQueryLeadershipScheduleCmd
, Cmd.format
, Cmd.mOutFile
} = do
poolid <-
modifyError QueryCmdTextReadError $
readVerificationKeyOrHashOrFile AsStakePoolKey poolColdVerKeyFile
poolid <- getHashFromStakePoolKeyHashSource poolColdVerKeyFile

vrkSkey <-
modifyError QueryCmdTextEnvelopeReadError . hoistIOEither $
Expand Down Expand Up @@ -1464,7 +1466,8 @@ runQueryLeadershipScheduleCmd
CurrentEpoch -> do
beo <- requireEon BabbageEra era

serCurrentEpochState <- easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))
serCurrentEpochState <-
easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))

pure $ do
schedule <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ data StakeAddressCmds era
| StakeAddressStakeDelegationCertificateCmd
(ShelleyBasedEra era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
StakePoolKeyHashSource
(File () Out)
| StakeAddressStakeAndVoteDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
StakePoolKeyHashSource
VoteDelegationTarget
(File () Out)
| StakeAddressVoteDelegationCertificateCmd
Expand All @@ -59,7 +59,7 @@ data StakeAddressCmds era
| StakeAddressRegistrationAndDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
StakePoolKeyHashSource
Coin
(File () Out)
| StakeAddressRegistrationAndVoteDelegationCertificateCmd
Expand All @@ -71,7 +71,7 @@ data StakeAddressCmds era
| StakeAddressRegistrationStakeAndVoteDelegationCertificateCmd
(ConwayEraOnwards era)
StakeIdentifier
(VerificationKeyOrHashOrFile StakePoolKey)
StakePoolKeyHashSource
VoteDelegationTarget
Coin
(File () Out)
Expand Down
Loading
Loading