Skip to content

Commit 6b13e0b

Browse files
committed
Remove CBOR encoding from AnyStakePoolVerificationKey and fix OperationalCertificate types
1 parent 7ee73d5 commit 6b13e0b

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

cardano-api/src/Cardano/Api/Internal/Keys/Shelley.hs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
{-# LANGUAGE GADTs #-}
77
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
88
{-# LANGUAGE InstanceSigs #-}
9-
{-# LANGUAGE LambdaCase #-}
109
{-# LANGUAGE MultiParamTypeClasses #-}
1110
{-# LANGUAGE RankNTypes #-}
1211
{-# LANGUAGE ScopedTypeVariables #-}
@@ -61,7 +60,6 @@ import Cardano.Api.Internal.SerialiseRaw
6160
import Cardano.Api.Internal.SerialiseTextEnvelope
6261
import Cardano.Api.Internal.SerialiseUsing
6362

64-
import Cardano.Binary (DecoderError (DecoderErrorUnknownTag), cborError)
6563
import Cardano.Crypto.DSIGN.Class qualified as Crypto
6664
import Cardano.Crypto.Hash.Class qualified as Crypto
6765
import Cardano.Crypto.Seed qualified as Crypto
@@ -70,8 +68,6 @@ import Cardano.Ledger.Crypto (StandardCrypto)
7068
import Cardano.Ledger.Crypto qualified as Shelley (DSIGN)
7169
import Cardano.Ledger.Keys qualified as Shelley
7270

73-
import Codec.CBOR.Decoding (Decoder, TokenType (TypeListLen), decodeListLenOf, peekTokenType)
74-
import Codec.CBOR.Encoding (Encoding, encodeListLen)
7571
import Data.Aeson.Types
7672
( ToJSONKey (..)
7773
, toJSONKeyText
@@ -83,7 +79,6 @@ import Data.ByteString qualified as BS
8379
import Data.Either.Combinators (maybeToRight)
8480
import Data.Maybe
8581
import Data.String (IsString (..))
86-
import Data.Word (Word8)
8782

8883
--
8984
-- Shelley payment keys
@@ -1681,27 +1676,6 @@ data AnyStakePoolVerificationKey
16811676
| AnyStakePoolExtendedVerificationKey (VerificationKey StakePoolExtendedKey)
16821677
deriving (Show, Eq)
16831678

1684-
instance ToCBOR AnyStakePoolVerificationKey where
1685-
toCBOR :: AnyStakePoolVerificationKey -> Encoding
1686-
toCBOR (AnyStakePoolNormalVerificationKey vk) =
1687-
encodeListLen 2 <> toCBOR (0 :: Word8) <> toCBOR vk
1688-
toCBOR (AnyStakePoolExtendedVerificationKey vk) =
1689-
encodeListLen 2 <> toCBOR (1 :: Word8) <> toCBOR vk
1690-
1691-
instance FromCBOR AnyStakePoolVerificationKey where
1692-
fromCBOR :: Decoder s AnyStakePoolVerificationKey
1693-
fromCBOR =
1694-
peekTokenType >>= \case
1695-
TypeListLen ->
1696-
decodeListLenOf 2 >> do
1697-
tag <- fromCBOR
1698-
case tag of
1699-
0 -> AnyStakePoolNormalVerificationKey <$> fromCBOR
1700-
1 -> AnyStakePoolExtendedVerificationKey <$> fromCBOR
1701-
_ -> cborError $ DecoderErrorUnknownTag "AnyStakePoolVerificationKey" tag
1702-
-- This case is for backwards compatibility (with CBOR encoding that doesn't support extended keys)
1703-
_ -> AnyStakePoolNormalVerificationKey <$> fromCBOR
1704-
17051679
anyStakePoolVerificationKeyHash :: AnyStakePoolVerificationKey -> Hash StakePoolKey
17061680
anyStakePoolVerificationKeyHash (AnyStakePoolNormalVerificationKey vk) = verificationKeyHash vk
17071681
anyStakePoolVerificationKeyHash (AnyStakePoolExtendedVerificationKey vk) =

cardano-api/src/Cardano/Api/Internal/OperationalCertificate.hs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ import Data.Word
4444
data OperationalCertificate
4545
= OperationalCertificate
4646
!(Shelley.OCert StandardCrypto)
47-
!AnyStakePoolVerificationKey
47+
!(VerificationKey StakePoolKey)
4848
deriving (Eq, Show)
4949
deriving anyclass SerialiseAsCBOR
5050

5151
data OperationalCertificateIssueCounter
5252
= OperationalCertificateIssueCounter
5353
{ opCertIssueCount :: !Word64
54-
, opCertIssueColdKey :: !AnyStakePoolVerificationKey -- For consistency checking
54+
, opCertIssueColdKey :: !(VerificationKey StakePoolKey) -- For consistency checking
5555
}
5656
deriving (Eq, Show)
5757
deriving anyclass SerialiseAsCBOR
@@ -95,8 +95,8 @@ data OperationalCertIssueError
9595
--
9696
-- Order: pool vkey expected, pool skey supplied
9797
OperationalCertKeyMismatch
98-
AnyStakePoolVerificationKey
99-
AnyStakePoolVerificationKey
98+
(VerificationKey StakePoolKey)
99+
(VerificationKey StakePoolKey)
100100
deriving Show
101101

102102
instance Error OperationalCertIssueError where
@@ -133,11 +133,20 @@ issueOperationalCertificate
133133
, OperationalCertificateIssueCounter (succ counter) poolVKey
134134
)
135135
where
136-
poolVKey' :: AnyStakePoolVerificationKey
136+
castAnyStakePoolSigningKeyToNormalVerificationKey
137+
:: AnyStakePoolSigningKey
138+
-> VerificationKey StakePoolKey
139+
castAnyStakePoolSigningKeyToNormalVerificationKey anyStakePoolSKey =
140+
case anyStakePoolSigningKeyToVerificationKey anyStakePoolSKey of
141+
AnyStakePoolNormalVerificationKey normalStakePoolVKey -> normalStakePoolVKey
142+
AnyStakePoolExtendedVerificationKey extendedStakePoolVKey ->
143+
castVerificationKey extendedStakePoolVKey
144+
145+
poolVKey' :: VerificationKey StakePoolKey
137146
poolVKey' =
138147
either
139-
anyStakePoolSigningKeyToVerificationKey
140-
(AnyStakePoolNormalVerificationKey . convert . getVerificationKey)
148+
castAnyStakePoolSigningKeyToNormalVerificationKey
149+
(convert . getVerificationKey)
141150
skey
142151
where
143152
convert

0 commit comments

Comments
 (0)