summaryrefslogtreecommitdiff
path: root/src/Identity.hs
blob: 07356d8c493a744d4d0192c2849becd26e2ff3e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Identity (
    Identity, IdentityData(..),
    emptyIdentity,
) where

import Data.Text (Text)

import PubKey
import Storage

type Identity = Signed IdentityData

data IdentityData = Identity
    { idName :: Maybe Text
    , idPrev :: Maybe (Stored Identity)
    , idOwner :: Maybe (Stored Identity)
    , idKeyIdentity :: Stored PublicKey
    }
    deriving (Show)

emptyIdentity :: Stored PublicKey -> IdentityData
emptyIdentity key = Identity
    { idName = Nothing
    , idPrev = Nothing
    , idOwner = Nothing
    , idKeyIdentity = key
    }

instance Storable IdentityData where
    store' idt = storeRec $ do
        storeMbText "name" $ idName idt
        storeMbRef "prev" $ idPrev idt
        storeMbRef "owner" $ idOwner idt
        storeRef "key-id" $ idKeyIdentity idt

    load' = loadRec $ Identity
        <$> loadMbText "name"
        <*> loadMbRef "prev"
        <*> loadMbRef "owner"
        <*> loadRef "key-id"