Skip to content

Commit 773ad5c

Browse files
authored
Merge pull request #1091 from IntersectMBO/add-pool-operator-extended-key-support
Add pool operator extended key support
2 parents 8b8d15a + 3f9e62b commit 773ad5c

File tree

62 files changed

+661
-140
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+661
-140
lines changed

cabal.project

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ repository cardano-haskell-packages
1414
-- you need to run if you change them
1515
index-state:
1616
, hackage.haskell.org 2025-04-16T18:30:40Z
17-
, cardano-haskell-packages 2025-04-18T06:38:47Z
17+
, cardano-haskell-packages 2025-04-25T15:50:18Z
18+
1819

1920
packages:
2021
cardano-cli

cardano-cli/cardano-cli.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ library
238238
binary,
239239
bytestring,
240240
canonical-json,
241-
cardano-api ^>=10.14,
241+
cardano-api ^>=10.15,
242242
cardano-binary,
243243
cardano-crypto,
244244
cardano-crypto-class ^>=2.2,

cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data CompatibleStakeAddressCmds era
2626
| CompatibleStakeAddressStakeDelegationCertificateCmd
2727
(ShelleyBasedEra era)
2828
StakeIdentifier
29-
(VerificationKeyOrHashOrFile StakePoolKey)
29+
StakePoolKeyHashSource
3030
(File () Out)
3131
deriving Show
3232

cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Run.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,40 +84,45 @@ runStakeAddressStakeDelegationCertificateCmd
8484
=> ShelleyBasedEra era
8585
-> StakeIdentifier
8686
-- ^ Delegator stake verification key, verification key file or script file.
87-
-> VerificationKeyOrHashOrFile StakePoolKey
87+
-> StakePoolKeyHashSource
8888
-- ^ Delegatee stake pool verification key or verification key file or
8989
-- verification key hash.
9090
-> File () Out
9191
-> CIO e ()
9292
runStakeAddressStakeDelegationCertificateCmd sbe stakeVerifier poolVKeyOrHashOrFile outFp =
9393
shelleyBasedEraConstraints sbe $ do
94-
poolStakeVKeyHash <-
95-
fromExceptTCli $
96-
readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile
94+
poolStakeVKeyHash <- getHashFromStakePoolKeyHashSource poolVKeyOrHashOrFile
9795

9896
stakeCred <-
9997
fromExceptTCli $ getStakeCredentialFromIdentifier stakeVerifier
10098

101-
let certificate = createStakeDelegationCertificate stakeCred poolStakeVKeyHash sbe
99+
let certificate =
100+
createStakeDelegationCertificate sbe stakeCred poolStakeVKeyHash
102101

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

107106
createStakeDelegationCertificate
108-
:: StakeCredential
107+
:: ShelleyBasedEra era
108+
-> StakeCredential
109109
-> Hash StakePoolKey
110-
-> ShelleyBasedEra era
111110
-> Certificate era
112-
createStakeDelegationCertificate stakeCredential (StakePoolKeyHash poolStakeVKeyHash) = do
111+
createStakeDelegationCertificate sbe stakeCredential stakePoolHash = do
113112
caseShelleyToBabbageOrConwayEraOnwards
114113
( \w ->
115114
shelleyToBabbageEraConstraints w $
116115
ShelleyRelatedCertificate w $
117-
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) poolStakeVKeyHash
116+
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) (toLedgerHash stakePoolHash)
118117
)
119118
( \w ->
120119
conwayEraOnwardsConstraints w $
121120
ConwayCertificate w $
122-
L.mkDelegTxCert (toShelleyStakeCredential stakeCredential) (L.DelegStake poolStakeVKeyHash)
121+
L.mkDelegTxCert
122+
(toShelleyStakeCredential stakeCredential)
123+
(L.DelegStake (toLedgerHash stakePoolHash))
123124
)
125+
sbe
126+
where
127+
toLedgerHash :: Hash StakePoolKey -> L.KeyHash L.StakePool
128+
toLedgerHash (StakePoolKeyHash poolStakeVKeyHash) = poolStakeVKeyHash

cardano-cli/src/Cardano/CLI/Compatible/StakePool/Command.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import Prelude
1919

2020
import Data.Text (Text)
2121

22-
data CompatibleStakePoolCmds era
22+
newtype CompatibleStakePoolCmds era
2323
= CompatibleStakePoolRegistrationCertificateCmd
24-
!(CompatibleStakePoolRegistrationCertificateCmdArgs era)
24+
(CompatibleStakePoolRegistrationCertificateCmdArgs era)
2525
deriving Show
2626

2727
data CompatibleStakePoolRegistrationCertificateCmdArgs era
2828
= CompatibleStakePoolRegistrationCertificateCmdArgs
2929
{ sbe :: !(ShelleyBasedEra era)
3030
-- ^ Era in which to register the stake pool.
31-
, poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
31+
, poolVerificationKeyOrFile :: !StakePoolVerificationKeySource
3232
-- ^ Stake pool verification key.
3333
, vrfVerificationKeyOrFile :: !(VerificationKeyOrFile VrfKey)
3434
-- ^ VRF Verification key.

cardano-cli/src/Cardano/CLI/Compatible/StakePool/Run.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import Cardano.Api.Shelley
1414
import Cardano.CLI.Compatible.Exception
1515
import Cardano.CLI.Compatible.StakePool.Command
1616
import Cardano.CLI.EraBased.StakePool.Internal.Metadata
17+
import Cardano.CLI.Read
18+
( getVerificationKeyFromStakePoolVerificationKeySource
19+
)
1720
import Cardano.CLI.Type.Common
1821
import Cardano.CLI.Type.Error.StakePoolCmdError
1922
import Cardano.CLI.Type.Key (readVerificationKeyOrFile)
@@ -48,11 +51,8 @@ runStakePoolRegistrationCertificateCmd
4851
} =
4952
shelleyBasedEraConstraints sbe $ do
5053
-- Pool verification key
51-
stakePoolVerKey <-
52-
fromExceptTCli $
53-
firstExceptT StakePoolCmdReadKeyFileError $
54-
readVerificationKeyOrFile AsStakePoolKey poolVerificationKeyOrFile
55-
let stakePoolId' = verificationKeyHash stakePoolVerKey
54+
stakePoolVerKey <- getVerificationKeyFromStakePoolVerificationKeySource poolVerificationKeyOrFile
55+
let stakePoolId' = anyStakePoolVerificationKeyHash stakePoolVerKey
5656

5757
-- VRF verification key
5858
vrfVerKey <-

cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,23 +445,40 @@ parseLovelace = do
445445
else return $ L.Coin i
446446

447447
-- | The first argument is the optional prefix.
448-
pStakePoolVerificationKeyOrFile :: Maybe String -> Parser (VerificationKeyOrFile StakePoolKey)
448+
pStakePoolVerificationKeyOrFile
449+
:: Maybe String
450+
-> Parser StakePoolVerificationKeySource
449451
pStakePoolVerificationKeyOrFile prefix =
450452
asum
451-
[ VerificationKeyValue <$> pStakePoolVerificationKey prefix
452-
, VerificationKeyFilePath <$> pStakePoolVerificationKeyFile prefix
453+
[ StakePoolVerificationKeyFromLiteral . AnyStakePoolNormalVerificationKey
454+
<$> pStakePoolVerificationNormalKey prefix
455+
, StakePoolVerificationKeyFromLiteral . AnyStakePoolExtendedVerificationKey
456+
<$> pStakePoolVerificationExtendedKey prefix
457+
, StakePoolVerificationKeyFromFile <$> pStakePoolVerificationKeyFile prefix
453458
]
454459

455460
-- | The first argument is the optional prefix.
456-
pStakePoolVerificationKey :: Maybe String -> Parser (VerificationKey StakePoolKey)
457-
pStakePoolVerificationKey prefix =
461+
pStakePoolVerificationNormalKey
462+
:: Maybe String -> Parser (VerificationKey StakePoolKey)
463+
pStakePoolVerificationNormalKey prefix =
458464
Opt.option (readVerificationKey AsStakePoolKey) $
459465
mconcat
460466
[ Opt.long $ prefixFlag prefix "stake-pool-verification-key"
461467
, Opt.metavar "STRING"
462468
, Opt.help "Stake pool verification key (Bech32 or hex-encoded)."
463469
]
464470

471+
-- | The first argument is the optional prefix.
472+
pStakePoolVerificationExtendedKey
473+
:: Maybe String -> Parser (VerificationKey StakePoolExtendedKey)
474+
pStakePoolVerificationExtendedKey prefix =
475+
Opt.option (readVerificationKey AsStakePoolExtendedKey) $
476+
mconcat
477+
[ Opt.long $ prefixFlag prefix "stake-pool-verification-extended-key"
478+
, Opt.metavar "STRING"
479+
, Opt.help "Stake pool verification extended key (Bech32 or hex-encoded)."
480+
]
481+
465482
-- | The first argument is the optional prefix.
466483
pStakePoolVerificationKeyFile :: Maybe String -> Parser (VerificationKeyFile In)
467484
pStakePoolVerificationKeyFile prefix =
@@ -581,7 +598,10 @@ rVerificationKey a mErrPrefix =
581598
pColdVerificationKeyOrFile :: Maybe String -> Parser ColdVerificationKeyOrFile
582599
pColdVerificationKeyOrFile prefix =
583600
asum
584-
[ ColdStakePoolVerificationKey <$> pStakePoolVerificationKey prefix
601+
[ ColdStakePoolVerificationKey . AnyStakePoolNormalVerificationKey
602+
<$> pStakePoolVerificationNormalKey prefix
603+
, ColdStakePoolVerificationKey . AnyStakePoolExtendedVerificationKey
604+
<$> pStakePoolVerificationExtendedKey prefix
585605
, ColdGenesisDelegateVerificationKey <$> pGenesisDelegateVerificationKey
586606
, ColdVerificationKeyFile <$> pColdVerificationKeyFile
587607
]
@@ -961,11 +981,11 @@ pStakeVerificationKeyHash prefix =
961981

962982
-- | The first argument is the optional prefix.
963983
pStakePoolVerificationKeyOrHashOrFile
964-
:: Maybe String -> Parser (VerificationKeyOrHashOrFile StakePoolKey)
984+
:: Maybe String -> Parser StakePoolKeyHashSource
965985
pStakePoolVerificationKeyOrHashOrFile prefix =
966986
asum
967-
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile prefix
968-
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix
987+
[ StakePoolKeyHashSource <$> pStakePoolVerificationKeyOrFile prefix
988+
, StakePoolKeyHashLiteral <$> pStakePoolVerificationKeyHash prefix
969989
]
970990

971991
--------------------------------------------------------------------------------
@@ -3424,7 +3444,7 @@ pVoterType =
34243444
]
34253445

34263446
-- TODO: Conway era include "normal" stake keys
3427-
pVotingCredential :: Parser (VerificationKeyOrFile StakePoolKey)
3447+
pVotingCredential :: Parser StakePoolVerificationKeySource
34283448
pVotingCredential = pStakePoolVerificationKeyOrFile Nothing
34293449

34303450
pVoteDelegationTarget :: Parser VoteDelegationTarget

cardano-cli/src/Cardano/CLI/EraBased/Genesis/Option.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ pGenesisCreateTestNetData era envCli =
247247
<*> pNumGenesisKeys
248248
<*> pNumPools
249249
<*> pNumStakeDelegs
250-
<*> (case era of Exp.BabbageEra -> pure 0; Exp.ConwayEra -> pNumCommittee) -- Committee doesn't exist in babbage
251-
<*> (case era of Exp.BabbageEra -> pure $ DRepCredentials OnDisk 0; Exp.ConwayEra -> pNumDReps) -- DReps don't exist in babbage
250+
<*> (case era of Exp.ConwayEra -> pNumCommittee) -- Committee doesn't exist in babbage
251+
<*> (case era of Exp.ConwayEra -> pNumDReps) -- DReps don't exist in babbage
252252
<*> pNumStuffedUtxoCount
253253
<*> pNumUtxoKeys
254254
<*> pSupply

cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys = do
341341
createOpCert (kesKey, delegateKey) = either (error . show) id eResult
342342
where
343343
eResult = issueOperationalCertificate kesKey (Right delegateKey) (KESPeriod 0) counter
344-
counter = OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
344+
counter =
345+
OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
345346
convertFun
346347
:: VerificationKey GenesisDelegateExtendedKey
347348
-> VerificationKey StakePoolKey

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Run.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Cardano.Api.Shelley
2121
import Cardano.CLI.EraBased.Governance.Vote.Command qualified as Cmd
2222
import Cardano.CLI.EraBased.Script.Vote.Read
2323
import Cardano.CLI.EraIndependent.Hash.Internal.Common (carryHashChecks)
24+
import Cardano.CLI.Read (getHashFromStakePoolKeyHashSource)
2425
import Cardano.CLI.Type.Common
2526
import Cardano.CLI.Type.Error.CmdError
2627
import Cardano.CLI.Type.Error.GovernanceVoteCmdError
@@ -85,7 +86,8 @@ runGovernanceVoteCreateCmd
8586
drepCred <- readVerificationKeyOrHashOrFileOrScriptHash AsDRepKey unDRepKeyHash stake
8687
pure $ L.DRepVoter drepCred
8788
AnyStakePoolVerificationKeyOrHashOrFile stake -> do
88-
StakePoolKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake
89+
StakePoolKeyHash h <-
90+
liftIO $ getHashFromStakePoolKeyHashSource stake
8991
pure $ L.StakePoolVoter h
9092
AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash stake -> do
9193
hotCred <- readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeHotKey unCommitteeHotKeyHash stake

cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ data QueryCommons = QueryCommons
9292
data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
9393
{ commons :: !QueryCommons
9494
, genesisFp :: !GenesisFile
95-
, poolColdVerKeyFile :: !(VerificationKeyOrHashOrFile StakePoolKey)
95+
, poolColdVerKeyFile :: !StakePoolKeyHashSource
9696
, vrkSkeyFp :: !(SigningKeyFile In)
9797
, whichSchedule :: !EpochLeadershipSchedule
9898
, format :: !(Vary [FormatJson, FormatText])

cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ import Cardano.Binary qualified as CBOR
5252
import Cardano.CLI.EraBased.Genesis.Internal.Common
5353
import Cardano.CLI.EraBased.Query.Command qualified as Cmd
5454
import Cardano.CLI.Helper
55+
import Cardano.CLI.Read
56+
( getHashFromStakePoolKeyHashSource
57+
)
5558
import Cardano.CLI.Type.Common
5659
import Cardano.CLI.Type.Error.NodeEraMismatchError
5760
import Cardano.CLI.Type.Error.QueryCmdError
@@ -556,7 +559,8 @@ runQueryKesPeriodInfoCmd
556559
-- We need the stake pool id to determine what the counter of our SPO
557560
-- should be.
558561
let opCertCounterMap = Consensus.getOpCertCounters (Proxy @(ConsensusProtocol era)) chainDepState
559-
StakePoolKeyHash blockIssuerHash = verificationKeyHash stakePoolVKey
562+
StakePoolKeyHash blockIssuerHash =
563+
verificationKeyHash stakePoolVKey
560564

561565
case Map.lookup (coerce blockIssuerHash) opCertCounterMap of
562566
-- Operational certificate exists in the protocol state
@@ -1431,9 +1435,7 @@ runQueryLeadershipScheduleCmd
14311435
, Cmd.format
14321436
, Cmd.mOutFile
14331437
} = do
1434-
poolid <-
1435-
modifyError QueryCmdTextReadError $
1436-
readVerificationKeyOrHashOrFile AsStakePoolKey poolColdVerKeyFile
1438+
poolid <- getHashFromStakePoolKeyHashSource poolColdVerKeyFile
14371439

14381440
vrkSkey <-
14391441
modifyError QueryCmdTextEnvelopeReadError . hoistIOEither $
@@ -1464,7 +1466,8 @@ runQueryLeadershipScheduleCmd
14641466
CurrentEpoch -> do
14651467
beo <- requireEon BabbageEra era
14661468

1467-
serCurrentEpochState <- easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))
1469+
serCurrentEpochState <-
1470+
easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))
14681471

14691472
pure $ do
14701473
schedule <-

cardano-cli/src/Cardano/CLI/EraBased/StakeAddress/Command.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ data StakeAddressCmds era
3838
| StakeAddressStakeDelegationCertificateCmd
3939
(ShelleyBasedEra era)
4040
StakeIdentifier
41-
(VerificationKeyOrHashOrFile StakePoolKey)
41+
StakePoolKeyHashSource
4242
(File () Out)
4343
| StakeAddressStakeAndVoteDelegationCertificateCmd
4444
(ConwayEraOnwards era)
4545
StakeIdentifier
46-
(VerificationKeyOrHashOrFile StakePoolKey)
46+
StakePoolKeyHashSource
4747
VoteDelegationTarget
4848
(File () Out)
4949
| StakeAddressVoteDelegationCertificateCmd
@@ -59,7 +59,7 @@ data StakeAddressCmds era
5959
| StakeAddressRegistrationAndDelegationCertificateCmd
6060
(ConwayEraOnwards era)
6161
StakeIdentifier
62-
(VerificationKeyOrHashOrFile StakePoolKey)
62+
StakePoolKeyHashSource
6363
Coin
6464
(File () Out)
6565
| StakeAddressRegistrationAndVoteDelegationCertificateCmd
@@ -71,7 +71,7 @@ data StakeAddressCmds era
7171
| StakeAddressRegistrationStakeAndVoteDelegationCertificateCmd
7272
(ConwayEraOnwards era)
7373
StakeIdentifier
74-
(VerificationKeyOrHashOrFile StakePoolKey)
74+
StakePoolKeyHashSource
7575
VoteDelegationTarget
7676
Coin
7777
(File () Out)

0 commit comments

Comments
 (0)