Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add signable representations #1666

Merged
merged 5 commits into from
Jul 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ where
import Cardano.Binary (FromCBOR (..), ToCBOR (..), toCBOR)
import qualified Cardano.Crypto.DSIGN as DSIGN
import qualified Cardano.Crypto.KES as KES
import Cardano.Crypto.Util
( SignableRepresentation (..),
writeBinaryWord64,
)
import Cardano.Crypto.Util (SignableRepresentation (..))
import Cardano.Prelude (NoUnexpectedThunks (..))
import Control.Monad.Trans.Reader (asks)
import qualified Data.Binary as Binary (encode)
import qualified Data.Binary as Binary
import qualified Data.Binary.Put as Binary
import qualified Data.ByteString.Lazy as BSL
import Data.Functor ((<&>))
import Data.Map.Strict (Map)
Expand Down Expand Up @@ -145,9 +143,10 @@ data OCertSignable crypto

instance Crypto crypto => SignableRepresentation (OCertSignable crypto) where
getSignableRepresentation (OCertSignable vk counter period) =
KES.rawSerialiseVerKeyKES vk
<> BSL.toStrict (Binary.encode counter)
<> writeBinaryWord64 (fromIntegral $ unKESPeriod period)
BSL.toStrict . Binary.runPut $ do
Binary.putByteString (KES.rawSerialiseVerKeyKES vk)
Binary.put counter
Binary.putWord64be (fromIntegral $ unKESPeriod period)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bytestring builder will be faster

Suggested change
BSL.toStrict . Binary.runPut $ do
Binary.putByteString (KES.rawSerialiseVerKeyKES vk)
Binary.put counter
Binary.putWord64be (fromIntegral $ unKESPeriod period)
runByteBuilder (32+8+8) $ do
BS.byteStringCopy (KES.rawSerialiseVerKeyKES vk)
BS.word64BE counter
BS.word64BE (fromIntegral $ unKESPeriod period)

Needs

import Shelley.Spec.Ledger.Serialization (runByteBuilder)
import qualified Data.ByteString.Builder as BS
import qualified Data.ByteString.Builder.Extra as BS


-- | Extract the signable part of an operational certificate (for verification)
ocertToSignable :: OCert crypto -> OCertSignable crypto
Expand Down