mirror of https://github.com/voidlizard/hbs2
minor-fix: extracted SignedBox and code sweeped
This commit is contained in:
parent
ed279f1d34
commit
93137d8f4c
|
@ -81,6 +81,7 @@ library
|
||||||
, HBS2.Data.Types.Crypto
|
, HBS2.Data.Types.Crypto
|
||||||
, HBS2.Data.Types.Peer
|
, HBS2.Data.Types.Peer
|
||||||
, HBS2.Data.Types.Refs
|
, HBS2.Data.Types.Refs
|
||||||
|
, HBS2.Data.Types.SignedBox
|
||||||
, HBS2.Data.Bundle
|
, HBS2.Data.Bundle
|
||||||
, HBS2.Defaults
|
, HBS2.Defaults
|
||||||
, HBS2.Events
|
, HBS2.Events
|
||||||
|
|
|
@ -26,6 +26,7 @@ import Streaming()
|
||||||
|
|
||||||
{- HLINT ignore "Use newtype instead of data" -}
|
{- HLINT ignore "Use newtype instead of data" -}
|
||||||
|
|
||||||
|
|
||||||
-- у нас может быть много способов хранить данные:
|
-- у нас может быть много способов хранить данные:
|
||||||
-- сжимать целиком (эффективно, но медленно)
|
-- сжимать целиком (эффективно, но медленно)
|
||||||
-- сжимать по секциям (быстрее, но менее эффективно)
|
-- сжимать по секциям (быстрее, но менее эффективно)
|
||||||
|
|
|
@ -38,10 +38,6 @@ newtype HashRefMetadata =
|
||||||
deriving newtype (Eq,Ord,Pretty)
|
deriving newtype (Eq,Ord,Pretty)
|
||||||
deriving stock (Data,Show,Generic)
|
deriving stock (Data,Show,Generic)
|
||||||
|
|
||||||
newtype HashRefPrevState = HashRefPrevState HashRef
|
|
||||||
deriving newtype (Eq,Ord,Pretty,IsString)
|
|
||||||
deriving stock (Data,Show,Generic)
|
|
||||||
|
|
||||||
data HashRefType =
|
data HashRefType =
|
||||||
HashRefMerkle HashRefObject
|
HashRefMerkle HashRefObject
|
||||||
| HashRefBlob HashRefObject
|
| HashRefBlob HashRefObject
|
||||||
|
@ -58,81 +54,7 @@ data SequentialRef =
|
||||||
instance Serialise AnnotatedHashRef
|
instance Serialise AnnotatedHashRef
|
||||||
instance Serialise SequentialRef
|
instance Serialise SequentialRef
|
||||||
instance Serialise HashRef
|
instance Serialise HashRef
|
||||||
instance Serialise HashRefMetadata
|
|
||||||
instance Serialise HashRefObject
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
data RefGenesis s = RefGenesis
|
|
||||||
{ refOwner :: !(PubKey 'Sign s)
|
|
||||||
, refName :: !Text
|
|
||||||
, refMeta :: !AnnMetaData
|
|
||||||
}
|
|
||||||
deriving stock (Generic)
|
|
||||||
|
|
||||||
instance Serialise (PubKey 'Sign s) => Serialise (RefGenesis s)
|
|
||||||
|
|
||||||
data RefForm
|
|
||||||
= LinearRef
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
data family Refs e ( f :: RefForm )
|
|
||||||
|
|
||||||
newtype instance Refs e 'LinearRef
|
|
||||||
-- List of hashes of stored RefGenesis
|
|
||||||
= LinearRefs { unLinearRefs :: [Hash HbSync] }
|
|
||||||
deriving stock (Generic)
|
|
||||||
|
|
||||||
instance Serialise (Refs e 'LinearRef)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
data family MutableRef e ( f :: RefForm )
|
|
||||||
|
|
||||||
data instance MutableRef s 'LinearRef
|
|
||||||
= LinearMutableRef
|
|
||||||
{ lrefId :: !(Hash HbSync)
|
|
||||||
, lrefHeight :: !Int
|
|
||||||
-- , lrefMTree :: !(MTreeAnn [Hash HbSync])
|
|
||||||
, lrefVal :: !(Hash HbSync)
|
|
||||||
}
|
|
||||||
deriving stock (Generic, Show)
|
|
||||||
|
|
||||||
instance Serialise (MutableRef s 'LinearRef)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
data SignPhase = SignaturePresent | SignatureVerified
|
|
||||||
|
|
||||||
data family Signed ( p :: SignPhase ) a
|
|
||||||
|
|
||||||
data instance Signed SignaturePresent (MutableRef s 'LinearRef)
|
|
||||||
= LinearMutableRefSigned
|
|
||||||
{ signature :: Signature s
|
|
||||||
, signedRef :: MutableRef s 'LinearRef
|
|
||||||
}
|
|
||||||
deriving stock (Generic)
|
|
||||||
|
|
||||||
instance Serialise (Signature s) =>
|
|
||||||
Serialise (Signed 'SignaturePresent (MutableRef s 'LinearRef))
|
|
||||||
|
|
||||||
data instance Signed 'SignatureVerified (MutableRef s 'LinearRef)
|
|
||||||
= LinearMutableRefSignatureVerified
|
|
||||||
{ signature :: Signature s
|
|
||||||
, signedRef :: MutableRef s 'LinearRef
|
|
||||||
, signer :: PubKey 'Sign s
|
|
||||||
}
|
|
||||||
deriving stock (Generic)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
nodeLinearRefsRef :: PubKey 'Sign s -> RefGenesis s
|
|
||||||
nodeLinearRefsRef pk = RefGenesis
|
|
||||||
{ refOwner = pk
|
|
||||||
, refName = "List of node linear refs"
|
|
||||||
, refMeta = NoMetaData
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
type IsRefPubKey s = ( Eq (PubKey 'Sign s)
|
type IsRefPubKey s = ( Eq (PubKey 'Sign s)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
|
module HBS2.Data.Types.SignedBox where
|
||||||
|
|
||||||
|
import HBS2.Prelude.Plated
|
||||||
|
import HBS2.Net.Proto.Types
|
||||||
|
import HBS2.Net.Auth.Credentials
|
||||||
|
|
||||||
|
import Codec.Serialise
|
||||||
|
import Data.Hashable
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
|
||||||
|
data SignedBox p e =
|
||||||
|
SignedBox (PubKey 'Sign (Encryption e)) ByteString (Signature (Encryption e))
|
||||||
|
deriving stock (Generic)
|
||||||
|
|
||||||
|
deriving stock instance
|
||||||
|
( Eq (PubKey 'Sign (Encryption e))
|
||||||
|
, Eq (Signature (Encryption e))
|
||||||
|
) => Eq (SignedBox p e)
|
||||||
|
|
||||||
|
instance ( Eq (PubKey 'Sign (Encryption e))
|
||||||
|
, Eq (Signature (Encryption e))
|
||||||
|
, Serialise (SignedBox p e)
|
||||||
|
) => Hashable (SignedBox p e) where
|
||||||
|
hashWithSalt salt box = hashWithSalt salt (serialise box)
|
||||||
|
|
||||||
|
|
||||||
|
type ForSignedBox e = ( Serialise ( PubKey 'Sign (Encryption e))
|
||||||
|
, FromStringMaybe (PubKey 'Sign (Encryption e))
|
||||||
|
, Serialise (Signature (Encryption e))
|
||||||
|
, Hashable (PubKey 'Sign (Encryption e))
|
||||||
|
)
|
||||||
|
|
||||||
|
instance ForSignedBox e => Serialise (SignedBox p e)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import HBS2.Net.Proto.Peer
|
||||||
import HBS2.Net.Proto.BlockAnnounce
|
import HBS2.Net.Proto.BlockAnnounce
|
||||||
import HBS2.Net.Proto.Sessions
|
import HBS2.Net.Proto.Sessions
|
||||||
import HBS2.Data.Types.Refs
|
import HBS2.Data.Types.Refs
|
||||||
|
import HBS2.Data.Types.SignedBox
|
||||||
import HBS2.Actors.Peer.Types
|
import HBS2.Actors.Peer.Types
|
||||||
import HBS2.Data.Types.Peer
|
import HBS2.Data.Types.Peer
|
||||||
import HBS2.Storage
|
import HBS2.Storage
|
||||||
|
@ -51,10 +52,6 @@ type RefChanId e = PubKey 'Sign (Encryption e)
|
||||||
type RefChanOwner e = PubKey 'Sign (Encryption e)
|
type RefChanOwner e = PubKey 'Sign (Encryption e)
|
||||||
type RefChanAuthor e = PubKey 'Sign (Encryption e)
|
type RefChanAuthor e = PubKey 'Sign (Encryption e)
|
||||||
|
|
||||||
data SignedBox p e =
|
|
||||||
SignedBox (PubKey 'Sign (Encryption e)) ByteString (Signature (Encryption e))
|
|
||||||
deriving stock (Generic)
|
|
||||||
|
|
||||||
type Weight = Integer
|
type Weight = Integer
|
||||||
|
|
||||||
data RefChanHeadBlock e =
|
data RefChanHeadBlock e =
|
||||||
|
@ -77,7 +74,6 @@ type ForRefChans e = ( Serialise ( PubKey 'Sign (Encryption e))
|
||||||
)
|
)
|
||||||
|
|
||||||
instance ForRefChans e => Serialise (RefChanHeadBlock e)
|
instance ForRefChans e => Serialise (RefChanHeadBlock e)
|
||||||
instance ForRefChans e => Serialise (SignedBox p e)
|
|
||||||
|
|
||||||
type instance SessionData e (RefChanHeadBlock e) = RefChanHeadBlock e
|
type instance SessionData e (RefChanHeadBlock e) = RefChanHeadBlock e
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import HBS2.Defaults
|
||||||
import HBS2.Events
|
import HBS2.Events
|
||||||
import HBS2.Hash
|
import HBS2.Hash
|
||||||
import HBS2.Data.Types.Refs
|
import HBS2.Data.Types.Refs
|
||||||
|
import HBS2.Data.Types.SignedBox
|
||||||
import HBS2.Data.Types
|
import HBS2.Data.Types
|
||||||
import HBS2.Net.Auth.Credentials
|
import HBS2.Net.Auth.Credentials
|
||||||
import HBS2.Net.IP.Addr
|
import HBS2.Net.IP.Addr
|
||||||
|
|
|
@ -19,6 +19,7 @@ import HBS2.Base58
|
||||||
import HBS2.Clock
|
import HBS2.Clock
|
||||||
import HBS2.Data.Detect
|
import HBS2.Data.Detect
|
||||||
import HBS2.Data.Types.Refs
|
import HBS2.Data.Types.Refs
|
||||||
|
import HBS2.Data.Types.SignedBox
|
||||||
import HBS2.Events
|
import HBS2.Events
|
||||||
import HBS2.Merkle
|
import HBS2.Merkle
|
||||||
import HBS2.Net.Auth.Credentials
|
import HBS2.Net.Auth.Credentials
|
||||||
|
|
Loading…
Reference in New Issue