diff --git a/hbs2-core/hbs2-core.cabal b/hbs2-core/hbs2-core.cabal index e6c2ddaa..1b86abc0 100644 --- a/hbs2-core/hbs2-core.cabal +++ b/hbs2-core/hbs2-core.cabal @@ -81,6 +81,7 @@ library , HBS2.Data.Types.Crypto , HBS2.Data.Types.Peer , HBS2.Data.Types.Refs + , HBS2.Data.Types.SignedBox , HBS2.Data.Bundle , HBS2.Defaults , HBS2.Events diff --git a/hbs2-core/lib/HBS2/Data/Bundle.hs b/hbs2-core/lib/HBS2/Data/Bundle.hs index 74261431..82c7702d 100644 --- a/hbs2-core/lib/HBS2/Data/Bundle.hs +++ b/hbs2-core/lib/HBS2/Data/Bundle.hs @@ -26,6 +26,7 @@ import Streaming() {- HLINT ignore "Use newtype instead of data" -} + -- у нас может быть много способов хранить данные: -- сжимать целиком (эффективно, но медленно) -- сжимать по секциям (быстрее, но менее эффективно) diff --git a/hbs2-core/lib/HBS2/Data/Types/Refs.hs b/hbs2-core/lib/HBS2/Data/Types/Refs.hs index a2df354a..241d4d10 100644 --- a/hbs2-core/lib/HBS2/Data/Types/Refs.hs +++ b/hbs2-core/lib/HBS2/Data/Types/Refs.hs @@ -38,10 +38,6 @@ newtype HashRefMetadata = deriving newtype (Eq,Ord,Pretty) deriving stock (Data,Show,Generic) -newtype HashRefPrevState = HashRefPrevState HashRef - deriving newtype (Eq,Ord,Pretty,IsString) - deriving stock (Data,Show,Generic) - data HashRefType = HashRefMerkle HashRefObject | HashRefBlob HashRefObject @@ -58,81 +54,7 @@ data SequentialRef = instance Serialise AnnotatedHashRef instance Serialise SequentialRef 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) diff --git a/hbs2-core/lib/HBS2/Data/Types/SignedBox.hs b/hbs2-core/lib/HBS2/Data/Types/SignedBox.hs new file mode 100644 index 00000000..d814eb50 --- /dev/null +++ b/hbs2-core/lib/HBS2/Data/Types/SignedBox.hs @@ -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) + diff --git a/hbs2-core/lib/HBS2/Net/Proto/RefChan.hs b/hbs2-core/lib/HBS2/Net/Proto/RefChan.hs index 4c7d8fc2..c777283d 100644 --- a/hbs2-core/lib/HBS2/Net/Proto/RefChan.hs +++ b/hbs2-core/lib/HBS2/Net/Proto/RefChan.hs @@ -18,6 +18,7 @@ import HBS2.Net.Proto.Peer import HBS2.Net.Proto.BlockAnnounce import HBS2.Net.Proto.Sessions import HBS2.Data.Types.Refs +import HBS2.Data.Types.SignedBox import HBS2.Actors.Peer.Types import HBS2.Data.Types.Peer import HBS2.Storage @@ -51,10 +52,6 @@ type RefChanId e = PubKey 'Sign (Encryption e) type RefChanOwner 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 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 (SignedBox p e) type instance SessionData e (RefChanHeadBlock e) = RefChanHeadBlock e diff --git a/hbs2-peer/app/PeerMain.hs b/hbs2-peer/app/PeerMain.hs index ea95eb54..2f3f3588 100644 --- a/hbs2-peer/app/PeerMain.hs +++ b/hbs2-peer/app/PeerMain.hs @@ -14,6 +14,7 @@ import HBS2.Defaults import HBS2.Events import HBS2.Hash import HBS2.Data.Types.Refs +import HBS2.Data.Types.SignedBox import HBS2.Data.Types import HBS2.Net.Auth.Credentials import HBS2.Net.IP.Addr diff --git a/hbs2-peer/app/RefChan.hs b/hbs2-peer/app/RefChan.hs index f996fb49..fc6e4824 100644 --- a/hbs2-peer/app/RefChan.hs +++ b/hbs2-peer/app/RefChan.hs @@ -19,6 +19,7 @@ import HBS2.Base58 import HBS2.Clock import HBS2.Data.Detect import HBS2.Data.Types.Refs +import HBS2.Data.Types.SignedBox import HBS2.Events import HBS2.Merkle import HBS2.Net.Auth.Credentials