Skip to content

Commit

Permalink
SignKeyWithPeriod type
Browse files Browse the repository at this point in the history
  • Loading branch information
tdammers committed May 23, 2023
1 parent 572f2ac commit f525dc5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cardano-crypto-class/src/Cardano/Crypto/KES/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module Cardano.Crypto.KES.Class
, OptimizedKESAlgorithm (..)
, verifyOptimizedKES

-- * 'SignKeyWithPeriodKES' wrapper
, SignKeyWithPeriodKES (..)
, updateKESWithPeriod

-- * 'SignedKES' wrapper
, SignedKES (..)
, signedKES
Expand Down Expand Up @@ -77,6 +81,7 @@ import GHC.TypeLits (Nat, KnownNat, natVal, TypeError, ErrorMessage (..))
import NoThunks.Class (NoThunks)
import Control.Monad.Class.MonadST (MonadST)
import Control.Monad.Class.MonadThrow (MonadThrow)
import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT)

import Cardano.Binary (Decoder, decodeBytes, Encoding, encodeBytes, Size, withWordSize)

Expand Down Expand Up @@ -447,6 +452,30 @@ encodeSignedKES (SignedKES s) = encodeSigKES s
decodeSignedKES :: KESAlgorithm v => Decoder s (SignedKES v a)
decodeSignedKES = SignedKES <$> decodeSigKES

-- | A sign key bundled with its associated period.
data SignKeyWithPeriodKES v =
SignKeyWithPeriodKES
{ skWithoutPeriodKES :: !(SignKeyKES v)
, periodKES :: !Period
}
deriving (Generic)

deriving instance (KESAlgorithm v, Eq (SignKeyKES v)) => Eq (SignKeyWithPeriodKES v)

deriving instance (KESAlgorithm v, Show (SignKeyKES v)) => Show (SignKeyWithPeriodKES v)

instance KESAlgorithm v => NoThunks (SignKeyWithPeriodKES v)
-- use generic instance

updateKESWithPeriod
:: (KESAlgorithm v, MonadST m, MonadThrow m)
=> ContextKES v
-> SignKeyWithPeriodKES v
-> m (Maybe (SignKeyWithPeriodKES v))
updateKESWithPeriod c (SignKeyWithPeriodKES sk t) = runMaybeT $ do
sk' <- MaybeT $ updateKES c sk t
return $ SignKeyWithPeriodKES sk' (succ t)

--
-- 'Size' expressions for 'ToCBOR' instances.
--
Expand Down

0 comments on commit f525dc5

Please sign in to comment.