aboutsummaryrefslogtreecommitdiff
path: root/src/Ssb/Pub.hs
diff options
context:
space:
mode:
authorHaskell Guy <haskell.guy@localhost>2020-05-26 13:07:50 +0200
committerHaskell Guy <haskell.guy@localhost>2020-05-26 13:37:29 +0200
commit41cde99ec6189dbecca6803a5aa4f6f18142e8ba (patch)
tree7a0ceab0d516b8c3b7b49313100ae50c97e875c3 /src/Ssb/Pub.hs
downloadssb-haskell-41cde99ec6189dbecca6803a5aa4f6f18142e8ba.tar.xz
initial commit
Diffstat (limited to 'src/Ssb/Pub.hs')
-rw-r--r--src/Ssb/Pub.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Ssb/Pub.hs b/src/Ssb/Pub.hs
new file mode 100644
index 0000000..9ed5410
--- /dev/null
+++ b/src/Ssb/Pub.hs
@@ -0,0 +1,47 @@
+-- | This module defines SSB pubs used as a gathering point for peers not sharing a local
+-- network.
+--
+-- https://ssbc.github.io/scuttlebutt-protocol-guide/#pubs
+module Ssb.Pub where
+
+import Protolude
+import Control.Arrow ((***))
+import qualified Data.Text as Text
+import qualified Data.ByteString.Base64 as Base64
+
+import Ssb.Identity
+import Ssb.Network
+
+data Invite = Invite
+ {
+ } deriving (Eq)
+
+data PubAddress = PubAddress
+ { host :: Host
+ , port :: Port
+ , key :: PublicKey
+ } deriving (Eq, Show)
+
+-- | Create a Pub Address from the given text.
+-- Example string "net:some.ho.st:8008~shs:SomeActuallyValidPubKey="
+parsePub :: Text -> Either Text PubAddress
+parsePub txt = do
+ let (protocol, postProtocol) = split ":" txt
+ let (addressPort, postAddress) = split "~" postProtocol
+ let (address, port) = splitOnEnd ":" addressPort
+ let (hashType, key) = split ":" postAddress
+ return PubAddress
+ { host = address
+ , port = port
+ , key = PublicKey $ Base64.decodeLenient $ toS key
+ }
+ where
+ split c arg = (identity *** Text.drop 1) $ Text.breakOn c arg
+ splitOnEnd c arg = (Text.dropEnd 1 *** identity) $ Text.breakOnEnd c arg
+
+-- TODO: Complete formatPub
+formatPub :: PubAddress -> Text
+formatPub pub = undefined
+
+newtype PubMessage = PubMessage PubAddress
+ deriving (Eq, Show)