diff --git a/definitions/src/Simplex/Messaging/Protocol.hs b/definitions/src/Simplex/Messaging/Protocol.hs index e8b4f819bc..662ea62821 100644 --- a/definitions/src/Simplex/Messaging/Protocol.hs +++ b/definitions/src/Simplex/Messaging/Protocol.hs @@ -124,6 +124,8 @@ st2 = SPending :<==> SNew :<==| SConfirmed -- stBad = SPending :<==> SConfirmed :<==| SConfirmed +infixl 4 :>>, :>>= + data Command res (from :: Participant) (to :: Participant) state state' :: Type where CreateConn :: Prf HasState 'Sender s => CreateConnRequest @@ -203,8 +205,12 @@ data Command res (from :: Participant) (to :: Participant) state state' :: Type -> Command b from1 to2 s1 s3 +infix 6 ==> +(==>) :: from -> to -> (from, to) +from ==> to = (from, to) + infix 5 &: -(&:) :: Sing from +(&:) :: (Sing from, Sing to) -> Command a from to s1 s2 -> Command a from to s1 s2 (&:) _ c = c diff --git a/definitions/src/Simplex/Messaging/Scenarios.hs b/definitions/src/Simplex/Messaging/Scenarios.hs new file mode 100644 index 0000000000..fea57b4c12 --- /dev/null +++ b/definitions/src/Simplex/Messaging/Scenarios.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE BlockArguments #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} + +module Simplex.Messaging.Scenarios where + +import Simplex.Messaging.Protocol +import Simplex.Messaging.Types + +establishConnection :: Command () + 'Recipient 'Broker + ('None <==> 'None <==| 'None) + ('Secured <==> 'Secured <==| 'Secured) +establishConnection = + SRecipient ==> SBroker &: CreateConn "123" :>>= -- recipient's public key for broker + \CreateConnResponse{..} -> + SRecipient ==> SBroker &: Subscribe :>> -- TODO add subscribed state + SRecipient ==> SSender &: SendInvite "invite" :>> -- TODO invitation object + SSender ==> SBroker &: ConfirmConn "456" :>> -- sender's public key for broker" + SBroker ==> SRecipient &: PushConfirm :>>= + \senderKey -> + SRecipient ==> SBroker &: SecureConn senderKey :>> + SSender ==> SBroker &: SendWelcome :>> + SBroker ==> SRecipient &: PushWelcome :>> + SSender ==> SBroker &: SendMsg "Hello" :>> + SBroker ==> SRecipient &: PushMsg :>> + SRecipient ==> SBroker &: DeleteMsg diff --git a/definitions/src/Simplex/Messaging/Types.hs b/definitions/src/Simplex/Messaging/Types.hs index 43d2e9c9f7..60fc9ab538 100644 --- a/definitions/src/Simplex/Messaging/Types.hs +++ b/definitions/src/Simplex/Messaging/Types.hs @@ -9,7 +9,11 @@ import GHC.Generics() newtype CreateConnRequest = CreateConnRequest { recipientKey :: Key - } deriving (Show, Generic, ToJSON, FromJSON) + } deriving (Eq, Show, Generic, ToJSON, FromJSON) + +instance IsString CreateConnRequest where + fromString = CreateConnRequest . pack + data CreateConnResponse = CreateConnResponse { recipientId :: String @@ -20,6 +24,10 @@ newtype SecureConnRequest = SecureConnRequest { senderKey :: Key } deriving (Show, Generic, ToJSON, FromJSON) +instance IsString SecureConnRequest where + fromString = SecureConnRequest . pack + + data Message = Message { id :: Base64EncodedString , ts :: TimeStamp @@ -35,6 +43,10 @@ newtype SendMessageRequest = SendMessageRequest { msg :: Base64EncodedString } deriving (Show, Generic, ToJSON, FromJSON) +instance IsString SendMessageRequest where + fromString = SendMessageRequest . pack + + type Key = Base64EncodedString type Base64EncodedString = Text type TimeStamp = Text