55{-# LANGUAGE FlexibleInstances #-}
66{-# LANGUAGE GeneralizedNewtypeDeriving #-}
77{-# LANGUAGE OverloadedStrings #-}
8- {-# LANGUAGE PatternSynonyms #-}
98{-# LANGUAGE PolyKinds #-}
109{-# LANGUAGE RecordWildCards #-}
1110{-# LANGUAGE ScopedTypeVariables #-}
12- {-# LANGUAGE StandaloneDeriving #-}
1311{-# LANGUAGE TypeApplications #-}
1412{-# LANGUAGE TypeFamilies #-}
1513{-# LANGUAGE UndecidableInstances #-}
16- {-# LANGUAGE ViewPatterns #-}
1714
1815module Cardano.Ledger.Keys.Bootstrap (
19- BootstrapWitness (
20- BootstrapWitness ,
21- bwKey ,
22- bwSig ,
23- bwChainCode ,
24- bwAttributes
25- ),
26- BootstrapWitnessRaw ,
16+ BootstrapWitness (.. ),
2717 ChainCode (.. ),
2818 bootstrapWitKeyHash ,
2919 unpackByronVKey ,
3020 makeBootstrapWitness ,
3121 verifyBootstrapWit ,
32- eqBootstrapWitnessRaw ,
3322)
3423where
3524
3625import qualified Cardano.Chain.Common as Byron
3726import Cardano.Crypto.DSIGN (SignedDSIGN (.. ))
3827import qualified Cardano.Crypto.DSIGN as DSIGN
28+ import qualified Cardano.Crypto.DSIGN.Class as C
3929import qualified Cardano.Crypto.Hash as Hash
4030import qualified Cardano.Crypto.Signing as Byron
4131import qualified Cardano.Crypto.Wallet as WC
4232import Cardano.Ledger.Binary (
4333 Annotator ,
4434 DecCBOR (.. ),
4535 EncCBOR (.. ),
46- byronProtVer ,
36+ )
37+ import Cardano.Ledger.Binary.Plain (
38+ FromCBOR (.. ),
39+ ToCBOR (.. ),
4740 decodeRecordNamed ,
4841 encodeListLen ,
4942 serialize' ,
5043 )
51- import Cardano.Ledger.Binary.Crypto (
52- decodeSignedDSIGN ,
53- encodeSignedDSIGN ,
54- )
55- import qualified Cardano.Ledger.Binary.Plain as Plain
5644import Cardano.Ledger.Hashes (ADDRHASH , EraIndependentTxBody , HASH , Hash , KeyHash (.. ))
5745import Cardano.Ledger.Keys.Internal (
5846 DSIGN ,
5947 KeyRole (.. ),
6048 VKey (.. ),
6149 verifySignedDSIGN ,
6250 )
63- import Cardano.Ledger.MemoBytes (
64- EqRaw (.. ),
65- Mem ,
66- MemoBytes ,
67- Memoized (.. ),
68- getMemoRawType ,
69- mkMemoized ,
70- )
71- import Control.DeepSeq (NFData )
51+ import Control.DeepSeq (NFData (.. ), rwhnf )
7252import Data.ByteString (ByteString )
7353import Data.Coerce (coerce )
7454import Data.Maybe (fromMaybe )
@@ -81,65 +61,40 @@ import Quiet
8161newtype ChainCode = ChainCode { unChainCode :: ByteString }
8262 deriving (Eq , Generic )
8363 deriving (Show ) via Quiet ChainCode
84- deriving newtype (NoThunks , EncCBOR , DecCBOR , NFData )
64+ deriving newtype (NoThunks , ToCBOR , FromCBOR , EncCBOR , DecCBOR , NFData )
8565
86- data BootstrapWitnessRaw = BootstrapWitnessRaw
87- { bwrKey :: ! (VKey 'Witness)
88- , bwrSignature :: ! (SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody ))
89- , bwrChainCode :: ! ChainCode
90- , bwrAttributes :: ! ByteString
66+ data BootstrapWitness = BootstrapWitness
67+ { bwKey :: ! (VKey 'Witness)
68+ , bwSignature :: ! (SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody ))
69+ , bwChainCode :: ! ChainCode
70+ , bwAttributes :: ! ByteString
9171 }
9272 deriving (Generic , Show , Eq )
9373
94- instance NFData BootstrapWitnessRaw
95- instance NoThunks BootstrapWitnessRaw
74+ instance NFData BootstrapWitness where
75+ rnf = rwhnf
76+
77+ instance NoThunks BootstrapWitness
9678
97- instance EncCBOR BootstrapWitnessRaw where
98- encCBOR cwr@ (BootstrapWitnessRaw _ _ _ _) =
99- let BootstrapWitnessRaw {.. } = cwr
79+ instance ToCBOR BootstrapWitness where
80+ toCBOR cwr@ (BootstrapWitness _ _ _ _) =
81+ let BootstrapWitness {.. } = cwr
10082 in encodeListLen 4
101- <> encCBOR bwrKey
102- <> encodeSignedDSIGN bwrSignature
103- <> encCBOR bwrChainCode
104- <> encCBOR bwrAttributes
83+ <> toCBOR bwKey
84+ <> C. encodeSignedDSIGN bwSignature
85+ <> toCBOR bwChainCode
86+ <> toCBOR bwAttributes
87+ instance EncCBOR BootstrapWitness
10588
106- instance DecCBOR BootstrapWitnessRaw where
107- decCBOR =
89+ instance FromCBOR BootstrapWitness where
90+ fromCBOR =
10891 decodeRecordNamed " BootstrapWitnessRaw" (const 4 ) $
109- BootstrapWitnessRaw <$> decCBOR <*> decodeSignedDSIGN <*> decCBOR <*> decCBOR
92+ BootstrapWitness <$> fromCBOR <*> C. decodeSignedDSIGN <*> fromCBOR <*> fromCBOR
93+ instance DecCBOR BootstrapWitness
11094
111- instance DecCBOR (Annotator BootstrapWitnessRaw ) where
95+ instance DecCBOR (Annotator BootstrapWitness ) where
11296 decCBOR = pure <$> decCBOR
11397
114- newtype BootstrapWitness = BootstrapWitnessConstr (MemoBytes BootstrapWitnessRaw )
115- deriving (Generic )
116- deriving newtype (Show , Eq , NFData , NoThunks , Plain.ToCBOR , DecCBOR )
117-
118- instance Memoized BootstrapWitness where
119- type RawType BootstrapWitness = BootstrapWitnessRaw
120-
121- instance EncCBOR BootstrapWitness
122-
123- deriving via
124- Mem BootstrapWitnessRaw
125- instance
126- DecCBOR (Annotator BootstrapWitness )
127-
128- pattern BootstrapWitness ::
129- VKey 'Witness ->
130- SignedDSIGN DSIGN (Hash HASH EraIndependentTxBody ) ->
131- ChainCode ->
132- ByteString ->
133- BootstrapWitness
134- pattern BootstrapWitness {bwKey, bwSig, bwChainCode, bwAttributes} <-
135- ( getMemoRawType ->
136- BootstrapWitnessRaw bwKey bwSig bwChainCode bwAttributes
137- )
138- where
139- BootstrapWitness bwKey bwSig bwChainCode bwAttributes =
140- mkMemoized minBound $ BootstrapWitnessRaw bwKey bwSig bwChainCode bwAttributes
141- {-# COMPLETE BootstrapWitness #-}
142-
14398instance Ord BootstrapWitness where
14499 compare = comparing bootstrapWitKeyHash
145100
@@ -195,7 +150,7 @@ verifyBootstrapWit txbodyHash witness =
195150 verifySignedDSIGN
196151 (bwKey witness)
197152 txbodyHash
198- (coerce . bwSig $ witness)
153+ (coerce $ bwSignature witness)
199154
200155coerceSignature :: WC. XSignature -> DSIGN. SigDSIGN DSIGN. Ed25519DSIGN
201156coerceSignature sig =
@@ -208,7 +163,7 @@ makeBootstrapWitness ::
208163 Byron. Attributes Byron. AddrAttributes ->
209164 BootstrapWitness
210165makeBootstrapWitness txBodyHash byronSigningKey addrAttributes =
211- BootstrapWitness vk signature cc (serialize' byronProtVer addrAttributes)
166+ BootstrapWitness vk signature cc (serialize' addrAttributes)
212167 where
213168 (vk, cc) = unpackByronVKey $ Byron. toVerification byronSigningKey
214169 signature =
@@ -217,13 +172,3 @@ makeBootstrapWitness txBodyHash byronSigningKey addrAttributes =
217172 (mempty :: ByteString )
218173 (Byron. unSigningKey byronSigningKey)
219174 (Hash. hashToBytes txBodyHash)
220-
221- eqBootstrapWitnessRaw :: BootstrapWitness -> BootstrapWitness -> Bool
222- eqBootstrapWitnessRaw bw1 bw2 =
223- bwKey bw1 == bwKey bw2
224- && bwSig bw1 == bwSig bw2
225- && bwChainCode bw1 == bwChainCode bw2
226- && bwAttributes bw1 == bwAttributes bw2
227-
228- instance EqRaw BootstrapWitness where
229- eqRaw = eqBootstrapWitnessRaw
0 commit comments