Skip to content

Commit b6e3199

Browse files
committed
Incorporate cip-129
1 parent e270070 commit b6e3199

21 files changed

+299
-11
lines changed

cabal.project

+6
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,9 @@ if impl (ghc >= 9.12)
7777
-- https://github.com/fizruk/http-api-data/pull/146
7878
, http-api-data:base
7979

80+
81+
source-repository-package
82+
type: git
83+
location: https://github.com/IntersectMBO/cardano-api.git
84+
tag: cc7535791ee480e7644acc3283c58e4a2f44e85d
85+
subdir: cardano-api

cardano-cli/cardano-cli.cabal

+7
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ library
142142
Cardano.CLI.EraIndependent.Address.Info.Run
143143
Cardano.CLI.EraIndependent.Address.Option
144144
Cardano.CLI.EraIndependent.Address.Run
145+
Cardano.CLI.EraIndependent.Cip.Cip129.Command
146+
Cardano.CLI.EraIndependent.Cip.Cip129.Options
147+
Cardano.CLI.EraIndependent.Cip.Cip129.Run
148+
Cardano.CLI.EraIndependent.Cip.Command
149+
Cardano.CLI.EraIndependent.Cip.Common
150+
Cardano.CLI.EraIndependent.Cip.Options
151+
Cardano.CLI.EraIndependent.Cip.Run
145152
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Command
146153
Cardano.CLI.EraIndependent.Debug.CheckNodeConfiguration.Run
147154
Cardano.CLI.EraIndependent.Debug.Command

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

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Cardano.CLI.Compatible.Command
1010
import Cardano.CLI.EraBased.Command
1111
import Cardano.CLI.EraBased.Query.Command
1212
import Cardano.CLI.EraIndependent.Address.Command
13+
import Cardano.CLI.EraIndependent.Cip.Command (CipFormatCmds)
1314
import Cardano.CLI.EraIndependent.Debug.Command
1415
import Cardano.CLI.EraIndependent.Hash.Command (HashCmds)
1516
import Cardano.CLI.EraIndependent.Key.Command
@@ -37,6 +38,8 @@ data ClientCommand
3738
forall era. QueryCommands (QueryCmds era)
3839
| -- | Legacy shelley-based Commands
3940
LegacyCmds LegacyCmds
41+
| -- | Miscellaneous commands
42+
CipFormatCmds CipFormatCmds
4043
| CliPingCommand PingCmd
4144
| CliDebugCmds DebugCmds
4245
| forall a. Help ParserPrefs (ParserInfo a)

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

+1
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,7 @@ pKesVerificationKey =
19781978
Left err@(Bech32DataPartToBytesError _) -> Left (docToString $ prettyError err)
19791979
Left err@(Bech32DeserialiseFromBytesError _) -> Left (docToString $ prettyError err)
19801980
Left err@(Bech32WrongPrefix _ _) -> Left (docToString $ prettyError err)
1981+
Left err@(Bech32UnexpectedHeader _ _) -> Left (docToString $ prettyError err)
19811982
-- The input was not valid Bech32. Attempt to deserialise it as hex.
19821983
Left (Bech32DecodingError _) ->
19831984
first

cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Command.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Cardano.CLI.EraBased.Governance.DRep.Command
1111
, GovernanceDRepRetirementCertificateCmdArgs (..)
1212
, GovernanceDRepUpdateCertificateCmdArgs (..)
1313
, GovernanceDRepMetadataHashCmdArgs (..)
14+
, DRepIdOutputFormat (..)
1415
, DRepMetadataSource (..)
1516
)
1617
where
@@ -43,7 +44,7 @@ data GovernanceDRepIdCmdArgs era
4344
= GovernanceDRepIdCmdArgs
4445
{ eon :: !(ConwayEraOnwards era)
4546
, vkeySource :: !(VerificationKeyOrHashOrFile DRepKey)
46-
, idOutputFormat :: !IdOutputFormat
47+
, idOutputFormat :: !DRepIdOutputFormat
4748
, mOutFile :: !(Maybe (File () Out))
4849
}
4950

@@ -112,3 +113,8 @@ renderGovernanceDRepCmds = \case
112113
"governance drep update-certificate"
113114
GovernanceDRepMetadataHashCmd{} ->
114115
"governance drep metadata-hash"
116+
117+
data DRepIdOutputFormat
118+
= IdOutputFormat IdOutputFormat
119+
| DRepCIP129OutputFormat
120+
deriving (Eq, Show)

cardano-cli/src/Cardano/CLI/EraBased/Governance/DRep/Option.hs

+8-4
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,16 @@ pGovernanceDRepKeyIdCmd era = do
7676
)
7777
$ Opt.progDesc "Generate a drep id."
7878

79-
pDRepIdOutputFormat :: Parser IdOutputFormat
79+
pDRepIdOutputFormat :: Parser DRepIdOutputFormat
8080
pDRepIdOutputFormat =
81-
asum [make IdOutputFormatHex "hex", make IdOutputFormatBech32 "bech32"]
82-
<|> pure default_
81+
asum
82+
[ make (IdOutputFormat IdOutputFormatHex) "hex"
83+
, make (IdOutputFormat IdOutputFormatBech32) "bech32"
84+
, make DRepCIP129OutputFormat "cip129"
85+
, pure default_
86+
]
8387
where
84-
default_ = IdOutputFormatBech32
88+
default_ = IdOutputFormat IdOutputFormatBech32
8589
make format flag_ =
8690
Opt.flag' format $
8791
mconcat

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ where
1717

1818
import Cardano.Api
1919
import Cardano.Api.Ledger qualified as L
20+
import Cardano.Api.Shelley
2021

2122
import Cardano.CLI.EraBased.Governance.DRep.Command qualified as Cmd
2223
import Cardano.CLI.EraIndependent.Hash.Command qualified as Cmd
@@ -93,8 +94,12 @@ runGovernanceDRepIdCmd
9394

9495
content <-
9596
pure $ case idOutputFormat of
96-
IdOutputFormatHex -> serialiseToRawBytesHex drepVerKeyHash
97-
IdOutputFormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 drepVerKeyHash
97+
Cmd.IdOutputFormat IdOutputFormatHex -> serialiseToRawBytesHex drepVerKeyHash
98+
Cmd.IdOutputFormat IdOutputFormatBech32 -> Text.encodeUtf8 $ serialiseToBech32 drepVerKeyHash
99+
Cmd.DRepCIP129OutputFormat ->
100+
let DRepKeyHash kh = drepVerKeyHash
101+
keyCredential = L.KeyHashObj kh
102+
in Text.encodeUtf8 $ serialiseToBech32CIP129 keyCredential
98103

99104
lift (writeByteStringOutput mOutFile content)
100105
& onLeft (left . WriteFileError)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Cardano.CLI.EraIndependent.Cip.Cip129.Command
2+
( Cip129(..)
3+
)
4+
where
5+
6+
import Cardano.CLI.EraIndependent.Cip.Common
7+
8+
data Cip129
9+
= Cip129DRep Input Output
10+
| Cip129CommitteeHotKey Input Output
11+
| Cip129CommitteeColdKey Input Output
12+
| Cip129GovernanceAction Input Output
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module Cardano.CLI.EraIndependent.Cip.Cip129.Options
2+
( pCip129
3+
)
4+
where
5+
6+
import Options.Applicative qualified as Opt
7+
import Cardano.CLI.EraIndependent.Cip.Command
8+
import Control.Applicative
9+
import Cardano.CLI.EraIndependent.Cip.Common
10+
11+
pCip129 :: Opt.Parser CipFormatCmds
12+
pCip129 = Cip129 <$> asum [ pCip129Drep
13+
, pCip129CommitteeHotKey
14+
, pCip129CommitteeColdKey
15+
, pCip129GovernanceAction
16+
]
17+
18+
pCip129Drep :: Opt.Parser Cip129
19+
pCip129Drep =
20+
Cip129DRep
21+
<$> pInput
22+
<*> pOutput
23+
where
24+
pInput = asum [ pInputFile "drep-file" "Input hex/bech32/text envelope drep file"
25+
, pInputHexText "drep-hex" "HEX" "Input hex encoded drep"
26+
, pInputBech32Text "drep-bech32" "BECH32" "Input bech32 encoded drep"
27+
]
28+
29+
pCip129CommitteeHotKey :: Opt.Parser Cip129
30+
pCip129CommitteeHotKey =
31+
Cip129CommitteeHotKey
32+
<$> pInput
33+
<*> pOutput
34+
where
35+
pInput = asum [ pInputFile "committee-hot-key-file" "Input hex/bech32/text envelope committee hot key file"
36+
, pInputHexText "committee-hot-key-hex" "HEX" "Input hex encoded committee hot key"
37+
, pInputBech32Text "committee-hot-key-bech32" "BECH32" "Input bech32 encoded committee hot key"
38+
]
39+
40+
pCip129CommitteeColdKey :: Opt.Parser Cip129
41+
pCip129CommitteeColdKey =
42+
Cip129CommitteeColdKey
43+
<$> pInput
44+
<*> pOutput
45+
where
46+
pInput = asum [ pInputFile "committee-cold-key-file" "Input hex/bech32/text envelope committee cold key file"
47+
, pInputHexText "committee-cold-key-hex" "HEX" "Input hex encoded committee cold key"
48+
, pInputBech32Text "committee-cold-key-bech32" "BECH32" "Input bech32 encoded committee cold key"
49+
]
50+
51+
pCip129GovernanceAction :: Opt.Parser Cip129
52+
pCip129GovernanceAction =
53+
Cip129GovernanceAction
54+
<$> pInput
55+
<*> pOutput
56+
where
57+
pInput = asum [ pInputFile "governance-action-file" "Input hex/bech32/text envelope governance action file"
58+
, pInputHexText "governance-action-hex" "HEX" "Input hex encoded governance action"
59+
, pInputBech32Text "governance-action-bech32" "BECH32" "Input bech32 encoded governance action"
60+
]
61+
62+
63+
64+
pOutput :: Opt.Parser Output
65+
pOutput = asum [ pOutputFile "output-file" "Output file"
66+
, pOutputText "output-text" "TEXT" "Output text"
67+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Cardano.CLI.EraIndependent.Cip.Cip129.Run
2+
( runCip129
3+
)
4+
where
5+
6+
import Cardano.CLI.EraIndependent.Cip.Cip129.Command
7+
8+
runCip129 :: Cip129 -> IO ()
9+
runCip129 (Cip129DRep inp out) = undefined
10+
runCip129 (Cip129CommitteeHotKey inp out) = undefined
11+
runCip129 (Cip129CommitteeColdKey inp out) = undefined
12+
runCip129 (Cip129GovernanceAction inp out) = undefined
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
module Cardano.CLI.EraIndependent.Cip.Command
3+
( -- * Supported CIPs
4+
Cip129(..)
5+
6+
, CipFormatCmds(..)
7+
8+
)
9+
where
10+
import Cardano.CLI.EraIndependent.Cip.Cip129.Command
11+
12+
newtype CipFormatCmds
13+
= Cip129 Cip129
14+
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{-# LANGUAGE DataKinds #-}
2+
3+
module Cardano.CLI.EraIndependent.Cip.Common
4+
( -- * Input related
5+
Input (..)
6+
7+
, pInputFile
8+
, pInputHexText
9+
, pInputBech32Text
10+
11+
-- * Output related
12+
, Output (..)
13+
, pOutputFile
14+
, pOutputText
15+
)
16+
where
17+
18+
19+
import Options.Applicative qualified as Opt
20+
import Cardano.Api
21+
import Cardano.CLI.EraBased.Common.Option hiding (pOutputFile)
22+
import qualified Data.Text as Text
23+
import Data.Text (Text)
24+
25+
26+
data Input
27+
= InputFile (File () In)
28+
| InputHexText Text
29+
| InputBech32Text Text
30+
31+
pInputFile :: String -> String -> Opt.Parser Input
32+
pInputFile optName desc =
33+
InputFile <$> pFileInDirection optName desc
34+
35+
pInputHexText :: String -> String -> String -> Opt.Parser Input
36+
pInputHexText optName metavar help =
37+
fmap (InputHexText . Text.pack) $
38+
Opt.strOption $
39+
mconcat
40+
[ Opt.long optName
41+
, Opt.metavar metavar
42+
, Opt.help help
43+
]
44+
45+
pInputBech32Text :: String -> String -> String -> Opt.Parser Input
46+
pInputBech32Text optName metavar help =
47+
fmap (InputBech32Text . Text.pack) $
48+
Opt.strOption $
49+
mconcat
50+
[ Opt.long optName
51+
, Opt.metavar metavar
52+
, Opt.help help
53+
]
54+
55+
56+
data Output
57+
= OutputFile (File () Out)
58+
| OutputText Text
59+
60+
pOutputFile :: String -> String -> Opt.Parser Output
61+
pOutputFile optName desc =
62+
OutputFile <$> pFileOutDirection optName desc
63+
64+
65+
pOutputText :: String -> String -> String -> Opt.Parser Output
66+
pOutputText optName metavar help =
67+
fmap (OutputText . Text.pack) $
68+
Opt.strOption $
69+
mconcat
70+
[ Opt.long optName
71+
, Opt.metavar metavar
72+
, Opt.help help
73+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE TypeApplications #-}
2+
3+
module Cardano.CLI.EraIndependent.Cip.Options
4+
( parseCipCmd
5+
)
6+
where
7+
8+
import Cardano.CLI.Command (ClientCommand (CipFormatCmds))
9+
import Options.Applicative qualified as Opt
10+
import Prettyprinter qualified as PP
11+
import Cardano.CLI.EraIndependent.Cip.Command
12+
import Cardano.CLI.EraIndependent.Cip.Cip129.Options
13+
14+
import Cardano.CLI.Parser
15+
16+
parseCipCmd :: Opt.Mod Opt.CommandFields ClientCommand
17+
parseCipCmd =
18+
Opt.command "cip-format" $
19+
Opt.info (CipFormatCmds <$> pCipFormat) $
20+
Opt.progDescDoc $
21+
Just $
22+
mconcat
23+
[ PP.pretty @String "Convert a hex or bech32 ledger cddl encoded thing to a CIP format."
24+
]
25+
26+
pCipFormat :: Opt.Parser CipFormatCmds
27+
pCipFormat =
28+
subParser "cip-129" $
29+
Opt.info pCip129 $
30+
Opt.progDesc $
31+
mconcat
32+
[ "Modified binary encoding of drep keys, constitutional committee cold and hot keys, governance actions."
33+
, "https://github.com/cardano-foundation/CIPs/tree/master/CIP-0129"
34+
]
35+
36+
37+
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
module Cardano.CLI.EraIndependent.Cip.Run
3+
( runCipFormat
4+
)
5+
where
6+
7+
import Cardano.CLI.EraIndependent.Cip.Command
8+
import Cardano.CLI.EraIndependent.Cip.Cip129.Run
9+
10+
runCipFormat :: CipFormatCmds -> IO ()
11+
runCipFormat (Cip129 cip129) = runCip129 cip129

cardano-cli/src/Cardano/CLI/EraIndependent/Key/Run.hs

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import Cardano.Api
3636
import Cardano.Api.Byron qualified as ByronApi
3737
import Cardano.Api.Crypto.Ed25519Bip32 (xPrvFromBytes)
3838
import Cardano.Api.Ledger qualified as L
39+
import Cardano.Api.Shelley
3940

4041
import Cardano.CLI.Byron.Key qualified as Byron
4142
import Cardano.CLI.EraIndependent.Key.Command qualified as Cmd
@@ -178,12 +179,15 @@ runNonExtendedKeyCmd
178179
vkf
179180
(Just genesisVkeyDelegateDesc)
180181
(castVerificationKey vk :: VerificationKey GenesisDelegateKey)
182+
AStakePoolExtendedVerificationKey vk ->
183+
writeToDisk vkf (Just stakeVkeyDesc) (castVerificationKey vk :: VerificationKey StakePoolKey)
181184
-- Non-extended keys are below and cause failure.
182185
vk@AByronVerificationKey{} -> goFail vk
183186
vk@APaymentVerificationKey{} -> goFail vk
184187
vk@AGenesisUTxOVerificationKey{} -> goFail vk
185188
vk@AKesVerificationKey{} -> goFail vk
186189
vk@AVrfVerificationKey{} -> goFail vk
190+
vk@AStakePoolVerificationKey{} -> goFail vk
187191
vk@AStakeVerificationKey{} -> goFail vk
188192
vk@ADRepVerificationKey{} -> goFail vk
189193
vk@ACommitteeColdVerificationKey{} -> goFail vk
@@ -216,6 +220,7 @@ readExtendedVerificationKeyFile evkfile = do
216220
k@ADRepExtendedVerificationKey{} -> return k
217221
k@ACommitteeColdExtendedVerificationKey{} -> return k
218222
k@ACommitteeHotExtendedVerificationKey{} -> return k
223+
k@AStakePoolExtendedVerificationKey{} -> return k
219224
k@AStakeExtendedVerificationKey{} -> return k
220225
k@AGenesisExtendedVerificationKey{} -> return k
221226
k@AGenesisDelegateExtendedVerificationKey{} -> return k
@@ -225,6 +230,7 @@ readExtendedVerificationKeyFile evkfile = do
225230
k@AGenesisUTxOVerificationKey{} -> goFail k
226231
k@AKesVerificationKey{} -> goFail k
227232
k@AVrfVerificationKey{} -> goFail k
233+
k@AStakePoolVerificationKey{} -> goFail k
228234
k@AStakeVerificationKey{} -> goFail k
229235
k@ADRepVerificationKey{} -> goFail k
230236
k@ACommitteeColdVerificationKey{} -> goFail k

0 commit comments

Comments
 (0)