{-# LANGUAGE DeriveGeneric, FlexibleInstances #-} module Types ( module Types, Val(..) ) where import Val import GHC.Generics (Generic) import Data.Aeson -- | Things that the developer sees. data Seen = Seen { seenData :: Val } deriving (Show, Generic) instance ToJSON Seen instance FromJSON Seen -- | Things that the developer enters. data Entered = Entered { enteredData :: Val , echoData :: Val -- ^ Data that is expected to be Seen, but has not been received -- at the time this was entered. } deriving (Show, Generic) instance ToJSON Entered instance FromJSON Entered -- | An activity (either Entered or Seen) with a pointer -- to the Activity before this one. -- -- The Signature is over both the data in the activity, and its pointer. data Activity a = Activity { activity :: a , prevActivity :: (Maybe HashPointer) , signature :: Signature } deriving (Show, Generic) instance ToJSON (Activity Seen) instance FromJSON (Activity Seen) instance ToJSON (Activity Entered) instance FromJSON (Activity Entered) newtype Signature = Signature Val deriving (Show, Generic) instance ToJSON Signature instance FromJSON Signature -- | A hash pointer to something that hashes to this value. data HashPointer = HashPointer { hashMethod :: HashMethod , hashValue :: Val } deriving (Show, Generic, Eq) instance ToJSON HashPointer instance FromJSON HashPointer -- | We use SHA256. (SHA3 is included to future proof, and because it -- improves the generated JSON.) data HashMethod = SHA256 | SHA3 deriving (Show, Generic, Eq) instance ToJSON HashMethod instance FromJSON HashMethod