66{-# LANGUAGE TypeFamilies #-}
77{-# OPTIONS_GHC -Wno-orphans #-}
88
9- module Cardano.Api.Internal.CIP.CIP129
10- ( CIP129 (.. )
9+ module Cardano.Api.Internal.CIP.Cip129
10+ ( Cip129 (.. )
1111 , deserialiseFromBech32CIP129
12- , serialiseToBech32CIP129
12+ , serialiseToBech32Cip129
1313 , serialiseGovActionIdToBech32CIP129
1414 , deserialiseGovActionIdFromBech32CIP129
1515 )
@@ -38,9 +38,9 @@ import Data.Text (Text)
3838import Data.Text.Encoding qualified as Text
3939import GHC.Exts (IsList (.. ))
4040
41- -- | CIP129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
41+ -- | Cip129 is a typeclass that captures the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
4242-- which pertain to governance credentials and governance action ids.
43- class (SerialiseAsRawBytes a , HasTypeProxy a ) => CIP129 a where
43+ class (SerialiseAsRawBytes a , HasTypeProxy a ) => Cip129 a where
4444 cip129Bech32PrefixFor :: AsType a -> Text
4545
4646 cip129HeaderHexByte :: a -> ByteString
@@ -49,32 +49,35 @@ class (SerialiseAsRawBytes a, HasTypeProxy a) => CIP129 a where
4949 default cip129Bech32PrefixesPermitted :: AsType a -> [Text ]
5050 cip129Bech32PrefixesPermitted = return . cip129Bech32PrefixFor
5151
52- instance CIP129 (Credential L. ColdCommitteeRole ) where
52+ instance Cip129 (Credential L. ColdCommitteeRole ) where
5353 cip129Bech32PrefixFor _ = " cc_cold"
5454 cip129Bech32PrefixesPermitted AsColdCommitteeCredential = [" cc_cold" ]
5555 cip129HeaderHexByte c =
5656 case c of
5757 L. KeyHashObj {} -> BS. singleton 0x12 -- 0001 0010
5858 L. ScriptHashObj {} -> BS. singleton 0x13 -- 0001 0011
5959
60- instance CIP129 (Credential L. HotCommitteeRole ) where
60+ instance Cip129 (Credential L. HotCommitteeRole ) where
6161 cip129Bech32PrefixFor _ = " cc_hot"
6262 cip129Bech32PrefixesPermitted AsHotCommitteeCredential = [" cc_hot" ]
6363 cip129HeaderHexByte c =
6464 case c of
6565 L. KeyHashObj {} -> BS. singleton 0x02 -- 0000 0010
6666 L. ScriptHashObj {} -> BS. singleton 0x03 -- 0000 0011
6767
68- instance CIP129 (Credential L. DRepRole ) where
68+ instance Cip129 (Credential L. DRepRole ) where
6969 cip129Bech32PrefixFor _ = " drep"
7070 cip129Bech32PrefixesPermitted AsDrepCredential = [" drep" ]
7171 cip129HeaderHexByte c =
7272 case c of
7373 L. KeyHashObj {} -> BS. singleton 0x22 -- 0010 0010
7474 L. ScriptHashObj {} -> BS. singleton 0x23 -- 0010 0011
7575
76- serialiseToBech32CIP129 :: forall a . CIP129 a => a -> Text
77- serialiseToBech32CIP129 a =
76+ -- | Serialize a accoding to the serialisation requirements of https://cips.cardano.org/cip/CIP-0129
77+ -- which currently pertain to governance credentials. Governance action ids are dealt separately with
78+ -- via 'serialiseGovActionIdToBech32CIP129'.
79+ serialiseToBech32Cip129 :: forall a . Cip129 a => a -> Text
80+ serialiseToBech32Cip129 a =
7881 Bech32. encodeLenient
7982 humanReadablePart
8083 (Bech32. dataPartFromBytes (cip129HeaderHexByte a <> serialiseToRawBytes a))
@@ -85,13 +88,13 @@ serialiseToBech32CIP129 a =
8588 Right p -> p
8689 Left err ->
8790 error $
88- " serialiseToBech32CIP129 : invalid prefix "
91+ " serialiseToBech32Cip129 : invalid prefix "
8992 ++ show prefix
9093 ++ " , "
9194 ++ show err
9295
9396deserialiseFromBech32CIP129
94- :: CIP129 a
97+ :: Cip129 a
9598 => AsType a -> Text -> Either Bech32DecodeError a
9699deserialiseFromBech32CIP129 asType bech32Str = do
97100 (prefix, dataPart) <-
@@ -130,7 +133,7 @@ deserialiseFromBech32CIP129 asType bech32Str = do
130133 toBase16Text = Text. decodeUtf8 . Base16. encode
131134
132135-- | Governance Action ID
133- -- According to CIP129 there is no header byte for GovActionId.
136+ -- According to Cip129 there is no header byte for GovActionId.
134137-- Instead they append the txid and index to form the payload.
135138serialiseGovActionIdToBech32CIP129 :: Gov. GovActionId -> Text
136139serialiseGovActionIdToBech32CIP129 (Gov. GovActionId txid index) =
0 commit comments