Skip to content

Commit

Permalink
Add SignKeyWithPeriodKES wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
tdammers committed Nov 12, 2022
1 parent ac4bc21 commit bbebbe5
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 @@ -21,6 +21,10 @@ module Cardano.Crypto.KES.Class
, OptimizedKESAlgorithm (..)
, verifyOptimizedKES

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

-- * 'SignedKES' wrapper
, SignedKES (..)
, signedKES
Expand Down Expand Up @@ -63,6 +67,7 @@ import GHC.Generics (Generic)
import GHC.Stack
import GHC.TypeLits (Nat, KnownNat, natVal, TypeError, ErrorMessage (..))
import NoThunks.Class (NoThunks)
import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT)

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

Expand Down Expand Up @@ -389,6 +394,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
:: (HasCallStack, KESSignAlgorithm m v)
=> 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 bbebbe5

Please sign in to comment.