From 4ef47bb25e47470026badfc92eef3f00ca23d93a Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Sun, 22 Nov 2026 13:05:23 +0000 Subject: [PATCH 01/10] agent: parse simplex: links without the slash after the scheme --- src/Simplex/Messaging/Agent/Protocol.hs | 11 ++++++----- src/Simplex/Messaging/SimplexName.hs | 2 +- tests/AgentTests/ConnectionRequestTests.hs | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 1d28db006..4056ddc2b 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1288,8 +1288,8 @@ instance StrEncoding AConnectionRequestUri where connReqUriP :: Maybe ServiceScheme -> Parser AConnectionRequestUri connReqUriP overrideScheme = do - crScheme <- (`fromMaybe` overrideScheme) <$> strP -- always parse, but use the passed one if any - crMode <- A.char '/' *> crModeP <* optional (A.char '/') <* "#/?" + crScheme <- (`fromMaybe` overrideScheme) <$> schemeP -- always parse, but use the passed one if any + crMode <- crModeP <* optional (A.char '/') <* "#/?" query <- strP aVRange <- queryParam "v" query crSmpQueues <- queryParamParser queuesP "smp" query @@ -1306,6 +1306,7 @@ connReqUriP overrideScheme = do rk_ <- queryParam_ "rk" query pure . ACR SCMContact $ CRContactUri crData {crAgentVRange = adjustAgentVRange aVRange} ((,) <$> rk_ <*> e2e_) where + schemeP = "simplex:" *> optional (A.char '/') $> SSSimplex <|> strP <* A.char '/' crModeP = "invitation" $> CMInvitation <|> "contact" $> CMContact -- semicolon is used to separate SMP queues because comma is used to separate server address hostnames queuesP = L.fromList <$> (strDecode <$?> A.takeTill (== ';')) `A.sepBy1'` A.char ';' @@ -1756,7 +1757,7 @@ instance StrEncoding AConnShortLink where strEncode (ACSL _ l) = strEncode l {-# INLINE strEncode #-} strP = do - (sch, h_) <- authorityP <* A.char '/' + (sch, h_) <- authorityP ct_ <- contactTypeP <* optional (A.char '/') <* A.char '#' case ct_ of Nothing -> do @@ -1770,8 +1771,8 @@ instance StrEncoding AConnShortLink where pure $ ACSL SCMContact $ CSLContact sch ct srv (LinkKey k) where authorityP = - "simplex:" $> (SLSSimplex, Nothing) - <|> "https://" *> ((SLSServer,) . Just <$> strP) + "simplex:" *> optional (A.char '/') $> (SLSSimplex, Nothing) + <|> "https://" *> ((SLSServer,) . Just <$> strP) <* A.char '/' <|> fail "bad short link scheme" contactTypeP = do Just <$> (A.anyChar >>= ctTypeP . toUpper) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index 690781196..c6d0d33c4 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -110,7 +110,7 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional "simplex:/name" *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional ("simplex:" *> optional (A.char '/') *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) where infoP NTPublicGroup = SimplexNameInfo NTPublicGroup <$> (strP <|> bareName) infoP NTContact = SimplexNameInfo NTContact <$> strP diff --git a/tests/AgentTests/ConnectionRequestTests.hs b/tests/AgentTests/ConnectionRequestTests.hs index 40ca12cf9..e4ca36eb5 100644 --- a/tests/AgentTests/ConnectionRequestTests.hs +++ b/tests/AgentTests/ConnectionRequestTests.hs @@ -327,6 +327,15 @@ connectionRequestTests = CSLContact SLSSimplex CCTContact shortSrv (LinkKey "0123456789abcdef0123456789abcdef") #==# "simplex:/a#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im" CSLInvitation SLSSimplex srv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "simplex:/i#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im%2Cjjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&p=5223&c=1234-w" CSLInvitation SLSSimplex shortSrv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "simplex:/i#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im" + it "should parse simplex: links without the slash after the scheme" $ do + let channel = CSLContact SLSSimplex CCTChannel shortSrv (LinkKey "0123456789abcdef0123456789abcdef") + name = SimplexNameInfo NTPublicGroup (SimplexDomain TLDSimplex "alice" []) + contactAddress #== ("simplex:contact#/?v=6-8&smp=" <> url queueStr) + connectionRequest #== ("simplex:invitation#/?v=6-8&smp=" <> url queueStr <> "&e2e=" <> testE2ERatchetParamsStrUri) + channel #==# "simplex:/c#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im" + channel #== "simplex:c#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im" + name #== "simplex:/name#alice.simplex" + name #== "simplex:name#alice.simplex" it "should shorten / restore short links" $ do let contact = CSLContact SLSServer CCTContact shortenShortLink [srv] (contact srv (LinkKey "0123456789abcdef0123456789abcdef")) From 6289dc21fac35169be4147c2add35124b29d1b2d Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:39:06 +0000 Subject: [PATCH 02/10] xftp: parse simplex: file links without the slash after the scheme --- src/Simplex/FileTransfer/Description.hs | 7 ++++--- tests/FileDescriptionTests.hs | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Simplex/FileTransfer/Description.hs b/src/Simplex/FileTransfer/Description.hs index bfc1896fd..2e581c6bb 100644 --- a/src/Simplex/FileTransfer/Description.hs +++ b/src/Simplex/FileTransfer/Description.hs @@ -46,7 +46,7 @@ module Simplex.FileTransfer.Description ) where -import Control.Applicative (optional) +import Control.Applicative (optional, (<|>)) import Control.Monad ((<=<)) import Data.Aeson (FromJSON, ToJSON) import qualified Data.Aeson as J @@ -57,6 +57,7 @@ import Data.Bifunctor (first) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isHexDigit) +import Data.Functor (($>)) import Data.Int (Int64) import Data.List (foldl', sortOn) import Data.List.NonEmpty (NonEmpty (..)) @@ -285,8 +286,8 @@ instance StrEncoding FileDescriptionURI where queryStr = strEncode $ QSP QEscape qs qs = ("desc", strEncode description) : maybe [] (\cd -> [("data", encodeUtf8 cd)]) clientData strP = do - scheme <- strP - _ <- "/file" <* optional (A.char '/') <* "#/?" + scheme <- "simplex:" *> optional (A.char '/') $> SSSimplex <|> strP <* A.char '/' + _ <- "file" <* optional (A.char '/') <* "#/?" query <- strP description <- queryParam "desc" query let clientData = safeDecodeUtf8 <$> queryParamStr "data" query diff --git a/tests/FileDescriptionTests.hs b/tests/FileDescriptionTests.hs index 21c62c476..10cfa3020 100644 --- a/tests/FileDescriptionTests.hs +++ b/tests/FileDescriptionTests.hs @@ -47,6 +47,7 @@ fileDescriptionTests = do describe "file description URIs" $ do it "round trip file description URI" testFileDescriptionURI it "round trip file description URI with extra JSON" testFileDescriptionURIExtras + it "parse file description URI without the slash after the scheme" testFileDescriptionURIWithoutSlash fileDescPath :: FilePath fileDescPath = "tests/fixtures/file_description.yaml" @@ -250,6 +251,14 @@ testFileDescriptionURIExtras = do let descr = FileDescriptionURI SSSimplex vfd $ Just "{\"something\":\"extra\",\"more\":true}" strDecode (strEncode descr) `shouldBe` Right descr +testFileDescriptionURIWithoutSlash :: IO () +testFileDescriptionURIWithoutSlash = do + vfd <- either fail pure $ validateFileDescription fileDesc + let descr = FileDescriptionURI SSSimplex vfd mempty + (prefix, rest) = B.splitAt 9 $ strEncode descr + prefix `shouldBe` "simplex:/" + strDecode ("simplex:" <> rest) `shouldBe` Right descr + testHashChunks :: HasTestEnv => IO () testHashChunks = do let sizes = [0, 65535, 65536, 100000, 200000] From 1bc4f1647de7149b5b5a0f2ddf21a31672c4b3b3 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 05:32:50 +0000 Subject: [PATCH 03/10] agent, xftp: parse simplex: and the optional slash in one parser --- src/Simplex/FileTransfer/Description.hs | 5 ++--- src/Simplex/Messaging/Agent/Protocol.hs | 5 ++--- src/Simplex/Messaging/ServiceScheme.hs | 6 +++++- src/Simplex/Messaging/SimplexName.hs | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Simplex/FileTransfer/Description.hs b/src/Simplex/FileTransfer/Description.hs index 2e581c6bb..275b79fb8 100644 --- a/src/Simplex/FileTransfer/Description.hs +++ b/src/Simplex/FileTransfer/Description.hs @@ -57,7 +57,6 @@ import Data.Bifunctor (first) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isHexDigit) -import Data.Functor (($>)) import Data.Int (Int64) import Data.List (foldl', sortOn) import Data.List.NonEmpty (NonEmpty (..)) @@ -79,7 +78,7 @@ import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, parseAll) import Simplex.Messaging.Protocol (XFTPServer) -import Simplex.Messaging.ServiceScheme (ServiceScheme (..)) +import Simplex.Messaging.ServiceScheme (ServiceScheme (..), simplexSchemeP) import Simplex.Messaging.Util (bshow, safeDecodeUtf8, (<$?>)) data FileDescription (p :: FileParty) = FileDescription @@ -286,7 +285,7 @@ instance StrEncoding FileDescriptionURI where queryStr = strEncode $ QSP QEscape qs qs = ("desc", strEncode description) : maybe [] (\cd -> [("data", encodeUtf8 cd)]) clientData strP = do - scheme <- "simplex:" *> optional (A.char '/') $> SSSimplex <|> strP <* A.char '/' + scheme <- simplexSchemeP <|> strP <* A.char '/' _ <- "file" <* optional (A.char '/') <* "#/?" query <- strP description <- queryParam "desc" query diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 4056ddc2b..a3811fcc2 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1288,7 +1288,7 @@ instance StrEncoding AConnectionRequestUri where connReqUriP :: Maybe ServiceScheme -> Parser AConnectionRequestUri connReqUriP overrideScheme = do - crScheme <- (`fromMaybe` overrideScheme) <$> schemeP -- always parse, but use the passed one if any + crScheme <- (`fromMaybe` overrideScheme) <$> (simplexSchemeP <|> strP <* A.char '/') -- always parse, but use the passed one if any crMode <- crModeP <* optional (A.char '/') <* "#/?" query <- strP aVRange <- queryParam "v" query @@ -1306,7 +1306,6 @@ connReqUriP overrideScheme = do rk_ <- queryParam_ "rk" query pure . ACR SCMContact $ CRContactUri crData {crAgentVRange = adjustAgentVRange aVRange} ((,) <$> rk_ <*> e2e_) where - schemeP = "simplex:" *> optional (A.char '/') $> SSSimplex <|> strP <* A.char '/' crModeP = "invitation" $> CMInvitation <|> "contact" $> CMContact -- semicolon is used to separate SMP queues because comma is used to separate server address hostnames queuesP = L.fromList <$> (strDecode <$?> A.takeTill (== ';')) `A.sepBy1'` A.char ';' @@ -1771,7 +1770,7 @@ instance StrEncoding AConnShortLink where pure $ ACSL SCMContact $ CSLContact sch ct srv (LinkKey k) where authorityP = - "simplex:" *> optional (A.char '/') $> (SLSSimplex, Nothing) + simplexSchemeP $> (SLSSimplex, Nothing) <|> "https://" *> ((SLSServer,) . Just <$> strP) <* A.char '/' <|> fail "bad short link scheme" contactTypeP = do diff --git a/src/Simplex/Messaging/ServiceScheme.hs b/src/Simplex/Messaging/ServiceScheme.hs index 904ab971e..825fc7b82 100644 --- a/src/Simplex/Messaging/ServiceScheme.hs +++ b/src/Simplex/Messaging/ServiceScheme.hs @@ -5,9 +5,10 @@ module Simplex.Messaging.ServiceScheme ( ServiceScheme (..), SrvLoc (..), simplexChat, + simplexSchemeP, ) where -import Control.Applicative ((<|>)) +import Control.Applicative (optional, (<|>)) import qualified Data.Attoparsec.ByteString.Char8 as A import qualified Data.ByteString.Char8 as B import Data.Functor (($>)) @@ -26,6 +27,9 @@ instance StrEncoding ServiceScheme where "simplex:" $> SSSimplex <|> "https://" *> (SSAppServer <$> strP) +simplexSchemeP :: A.Parser ServiceScheme +simplexSchemeP = "simplex:" *> optional (A.char '/') $> SSSimplex + data SrvLoc = SrvLoc TransportHost ServiceName deriving (Eq, Ord, Show) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index c6d0d33c4..72036bcca 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -36,6 +36,7 @@ import Simplex.Messaging.Agent.Store.DB (Binary (..), FromField (..), ToField (. import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON) +import Simplex.Messaging.ServiceScheme (simplexSchemeP) import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>)) data SimplexNameInfo = SimplexNameInfo @@ -110,7 +111,7 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional ("simplex:" *> optional (A.char '/') *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional (simplexSchemeP *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) where infoP NTPublicGroup = SimplexNameInfo NTPublicGroup <$> (strP <|> bareName) infoP NTContact = SimplexNameInfo NTContact <$> strP From 73e891f4c6ddda5d781bcf93ff2ebe3d2fe0f3eb Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:21:35 +0000 Subject: [PATCH 04/10] agent, xftp: the service scheme parses and encodes its separator --- src/Simplex/FileTransfer/Description.hs | 8 ++++---- src/Simplex/Messaging/Agent/Protocol.hs | 22 +++++++++++----------- src/Simplex/Messaging/ServiceScheme.hs | 12 ++++-------- src/Simplex/Messaging/SimplexName.hs | 7 +++++-- tests/CoreTests/EncodingTests.hs | 6 +++--- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Simplex/FileTransfer/Description.hs b/src/Simplex/FileTransfer/Description.hs index 275b79fb8..db2423a33 100644 --- a/src/Simplex/FileTransfer/Description.hs +++ b/src/Simplex/FileTransfer/Description.hs @@ -46,7 +46,7 @@ module Simplex.FileTransfer.Description ) where -import Control.Applicative (optional, (<|>)) +import Control.Applicative (optional) import Control.Monad ((<=<)) import Data.Aeson (FromJSON, ToJSON) import qualified Data.Aeson as J @@ -78,7 +78,7 @@ import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, parseAll) import Simplex.Messaging.Protocol (XFTPServer) -import Simplex.Messaging.ServiceScheme (ServiceScheme (..), simplexSchemeP) +import Simplex.Messaging.ServiceScheme (ServiceScheme (..)) import Simplex.Messaging.Util (bshow, safeDecodeUtf8, (<$?>)) data FileDescription (p :: FileParty) = FileDescription @@ -280,12 +280,12 @@ fileDescriptionURI :: ValidFileDescription 'FRecipient -> FileDescriptionURI fileDescriptionURI vfd = FileDescriptionURI SSSimplex vfd mempty instance StrEncoding FileDescriptionURI where - strEncode FileDescriptionURI {scheme, description, clientData} = mconcat [strEncode scheme, "/file", "#/?", queryStr] + strEncode FileDescriptionURI {scheme, description, clientData} = mconcat [strEncode scheme, "file", "#/?", queryStr] where queryStr = strEncode $ QSP QEscape qs qs = ("desc", strEncode description) : maybe [] (\cd -> [("data", encodeUtf8 cd)]) clientData strP = do - scheme <- simplexSchemeP <|> strP <* A.char '/' + scheme <- strP _ <- "file" <* optional (A.char '/') <* "#/?" query <- strP description <- queryParam "desc" query diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index a3811fcc2..e29200a44 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1234,7 +1234,7 @@ instance ConnectionModeI m => StrEncoding (ConnectionRequestUri m) where where crEncode :: ByteString -> ConnReqUriData -> (Maybe (RcvE2ERatchetParamsUri 'C.X448), Maybe RatchetKeyId) -> ByteString crEncode crMode ConnReqUriData {crScheme, crAgentVRange, crSmpQueues, crClientData} (e2eParams, rk) = - strEncode crScheme <> "/" <> crMode <> "#/?" <> queryStr + strEncode crScheme <> crMode <> "#/?" <> queryStr where queryStr = strEncode . QSP QEscape $ @@ -1288,7 +1288,7 @@ instance StrEncoding AConnectionRequestUri where connReqUriP :: Maybe ServiceScheme -> Parser AConnectionRequestUri connReqUriP overrideScheme = do - crScheme <- (`fromMaybe` overrideScheme) <$> (simplexSchemeP <|> strP <* A.char '/') -- always parse, but use the passed one if any + crScheme <- (`fromMaybe` overrideScheme) <$> strP -- always parse, but use the passed one if any crMode <- crModeP <* optional (A.char '/') <* "#/?" query <- strP aVRange <- queryParam "v" query @@ -1737,11 +1737,11 @@ instance ConnectionModeI m => StrEncoding (ConnShortLink m) where CSLContact sch ct srv (LinkKey k) -> slEncode sch srv (toLower $ ctTypeChar ct) "" k where slEncode sch (SMPServer (h :| hs) port (C.KeyHash kh)) linkType lnkId k = - B.concat [authority, "/", B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] + B.concat [strEncode scheme, B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] where - (authority, paramHosts) = case sch of - SLSSimplex -> ("simplex:", h : hs) - SLSServer -> ("https://" <> strEncode h, hs) + (scheme, paramHosts) = case sch of + SLSSimplex -> (SSSimplex, h : hs) + SLSServer -> (SSAppServer (SrvLoc h ""), hs) lnkIdStr = if B.null lnkId then "" else B64.encodeUnpadded lnkId <> "/" queryStr = if B.null query then "" else "?" <> query query = @@ -1756,7 +1756,11 @@ instance StrEncoding AConnShortLink where strEncode (ACSL _ l) = strEncode l {-# INLINE strEncode #-} strP = do - (sch, h_) <- authorityP + (sch, h_) <- + strP >>= \case + SSSimplex -> pure (SLSSimplex, Nothing) + SSAppServer (SrvLoc h "") -> pure (SLSServer, Just h) + SSAppServer _ -> fail "bad short link scheme" ct_ <- contactTypeP <* optional (A.char '/') <* A.char '#' case ct_ of Nothing -> do @@ -1769,10 +1773,6 @@ instance StrEncoding AConnShortLink where srv <- serverQueryP h_ pure $ ACSL SCMContact $ CSLContact sch ct srv (LinkKey k) where - authorityP = - simplexSchemeP $> (SLSSimplex, Nothing) - <|> "https://" *> ((SLSServer,) . Just <$> strP) <* A.char '/' - <|> fail "bad short link scheme" contactTypeP = do Just <$> (A.anyChar >>= ctTypeP . toUpper) <|> A.char 'i' $> Nothing diff --git a/src/Simplex/Messaging/ServiceScheme.hs b/src/Simplex/Messaging/ServiceScheme.hs index 825fc7b82..8a7af7b69 100644 --- a/src/Simplex/Messaging/ServiceScheme.hs +++ b/src/Simplex/Messaging/ServiceScheme.hs @@ -5,7 +5,6 @@ module Simplex.Messaging.ServiceScheme ( ServiceScheme (..), SrvLoc (..), simplexChat, - simplexSchemeP, ) where import Control.Applicative (optional, (<|>)) @@ -21,14 +20,11 @@ data ServiceScheme = SSSimplex | SSAppServer SrvLoc instance StrEncoding ServiceScheme where strEncode = \case - SSSimplex -> "simplex:" - SSAppServer srv -> "https://" <> strEncode srv + SSSimplex -> "simplex:/" + SSAppServer srv -> "https://" <> strEncode srv <> "/" strP = - "simplex:" $> SSSimplex - <|> "https://" *> (SSAppServer <$> strP) - -simplexSchemeP :: A.Parser ServiceScheme -simplexSchemeP = "simplex:" *> optional (A.char '/') $> SSSimplex + "simplex:" *> optional (A.char '/') $> SSSimplex + <|> "https://" *> (SSAppServer <$> strP) <* A.char '/' data SrvLoc = SrvLoc TransportHost ServiceName deriving (Eq, Ord, Show) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index 72036bcca..ca9529df2 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -36,7 +36,7 @@ import Simplex.Messaging.Agent.Store.DB (Binary (..), FromField (..), ToField (. import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON) -import Simplex.Messaging.ServiceScheme (simplexSchemeP) +import Simplex.Messaging.ServiceScheme (ServiceScheme (..)) import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>)) data SimplexNameInfo = SimplexNameInfo @@ -111,8 +111,11 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional (simplexSchemeP *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional nameSchemeP *> ((strP >>= infoP) <|> infoP NTPublicGroup) where + nameSchemeP = strP >>= \case + SSSimplex -> "name" + SSAppServer _ -> fail "bad name scheme" infoP NTPublicGroup = SimplexNameInfo NTPublicGroup <$> (strP <|> bareName) infoP NTContact = SimplexNameInfo NTContact <$> strP bareName = parseBare . safeDecodeUtf8 <$?> boundedNonSpace diff --git a/tests/CoreTests/EncodingTests.hs b/tests/CoreTests/EncodingTests.hs index 4108bef2a..2e489bc30 100644 --- a/tests/CoreTests/EncodingTests.hs +++ b/tests/CoreTests/EncodingTests.hs @@ -82,12 +82,12 @@ encodingTests = modifyMaxSuccess (const 1000) $ do shouldReject @TransportHost "[smp.simplex.im]" describe "Encoding service locations" $ do it "should parse bracketed IPv6 host with port" $ do - strDecode @ServiceScheme "https://[2001:db8::1]:8443" + strDecode @ServiceScheme "https://[2001:db8::1]:8443/" `shouldBe` Right (SSAppServer $ SrvLoc "2001:db8::1" "8443") strEncode (SSAppServer $ SrvLoc "2001:db8::1" "8443") - `shouldBe` "https://[2001:db8::1]:8443" + `shouldBe` "https://[2001:db8::1]:8443/" it "should reject bracketed non-IPv6 host" $ - shouldReject @ServiceScheme "https://[simplex.chat]:8443" + shouldReject @ServiceScheme "https://[simplex.chat]:8443/" describe "Encoding protocol servers" $ do it "should parse bracketed IPv6 server host with port" $ case strDecode @XFTPServer "xftp://1234-w==@[2001:db8::1]:443" of From 02537c34f0e138f4dbef6afc3fd1d60ec2bade9a Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:24:28 +0000 Subject: [PATCH 05/10] core: names take the service scheme of other links --- src/Simplex/Messaging/SimplexName.hs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index ca9529df2..ba7515afe 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -36,7 +36,7 @@ import Simplex.Messaging.Agent.Store.DB (Binary (..), FromField (..), ToField (. import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON) -import Simplex.Messaging.ServiceScheme (ServiceScheme (..)) +import Simplex.Messaging.ServiceScheme (ServiceScheme) import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>)) data SimplexNameInfo = SimplexNameInfo @@ -111,11 +111,8 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional nameSchemeP *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional ((strP :: A.Parser ServiceScheme) *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) where - nameSchemeP = strP >>= \case - SSSimplex -> "name" - SSAppServer _ -> fail "bad name scheme" infoP NTPublicGroup = SimplexNameInfo NTPublicGroup <$> (strP <|> bareName) infoP NTContact = SimplexNameInfo NTContact <$> strP bareName = parseBare . safeDecodeUtf8 <$?> boundedNonSpace From 2a1f8d110a93e38a50979b08eb7c79d3b2002c9a Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:30:58 +0000 Subject: [PATCH 06/10] agent: short link authority parser uses the service scheme --- src/Simplex/Messaging/Agent/Protocol.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index e29200a44..5286c944c 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1756,11 +1756,7 @@ instance StrEncoding AConnShortLink where strEncode (ACSL _ l) = strEncode l {-# INLINE strEncode #-} strP = do - (sch, h_) <- - strP >>= \case - SSSimplex -> pure (SLSSimplex, Nothing) - SSAppServer (SrvLoc h "") -> pure (SLSServer, Just h) - SSAppServer _ -> fail "bad short link scheme" + (sch, h_) <- authorityP ct_ <- contactTypeP <* optional (A.char '/') <* A.char '#' case ct_ of Nothing -> do @@ -1773,6 +1769,11 @@ instance StrEncoding AConnShortLink where srv <- serverQueryP h_ pure $ ACSL SCMContact $ CSLContact sch ct srv (LinkKey k) where + authorityP = + strP >>= \case + SSSimplex -> pure (SLSSimplex, Nothing) + SSAppServer (SrvLoc h "") -> pure (SLSServer, Just h) + SSAppServer _ -> fail "bad short link scheme" contactTypeP = do Just <$> (A.anyChar >>= ctTypeP . toUpper) <|> A.char 'i' $> Nothing From ed38d8ffbc4fde54954f28add557f05be4956ea6 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:33:05 +0000 Subject: [PATCH 07/10] agent: short link encoder keeps the name authority --- src/Simplex/Messaging/Agent/Protocol.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 5286c944c..07a323712 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1737,9 +1737,9 @@ instance ConnectionModeI m => StrEncoding (ConnShortLink m) where CSLContact sch ct srv (LinkKey k) -> slEncode sch srv (toLower $ ctTypeChar ct) "" k where slEncode sch (SMPServer (h :| hs) port (C.KeyHash kh)) linkType lnkId k = - B.concat [strEncode scheme, B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] + B.concat [strEncode authority, B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] where - (scheme, paramHosts) = case sch of + (authority, paramHosts) = case sch of SLSSimplex -> (SSSimplex, h : hs) SLSServer -> (SSAppServer (SrvLoc h ""), hs) lnkIdStr = if B.null lnkId then "" else B64.encodeUnpadded lnkId <> "/" From 7b2fd9ba6ee15660a4d4533b35174b0a1f4307ed Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:39:05 +0000 Subject: [PATCH 08/10] agent: short link base URI names --- src/Simplex/Messaging/Agent/Protocol.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 07a323712..2c1dccca3 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -1737,9 +1737,9 @@ instance ConnectionModeI m => StrEncoding (ConnShortLink m) where CSLContact sch ct srv (LinkKey k) -> slEncode sch srv (toLower $ ctTypeChar ct) "" k where slEncode sch (SMPServer (h :| hs) port (C.KeyHash kh)) linkType lnkId k = - B.concat [strEncode authority, B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] + B.concat [strEncode baseUri, B.singleton linkType, "#", lnkIdStr, B64.encodeUnpadded k, queryStr] where - (authority, paramHosts) = case sch of + (baseUri, paramHosts) = case sch of SLSSimplex -> (SSSimplex, h : hs) SLSServer -> (SSAppServer (SrvLoc h ""), hs) lnkIdStr = if B.null lnkId then "" else B64.encodeUnpadded lnkId <> "/" @@ -1756,7 +1756,7 @@ instance StrEncoding AConnShortLink where strEncode (ACSL _ l) = strEncode l {-# INLINE strEncode #-} strP = do - (sch, h_) <- authorityP + (sch, h_) <- baseUriP ct_ <- contactTypeP <* optional (A.char '/') <* A.char '#' case ct_ of Nothing -> do @@ -1769,7 +1769,7 @@ instance StrEncoding AConnShortLink where srv <- serverQueryP h_ pure $ ACSL SCMContact $ CSLContact sch ct srv (LinkKey k) where - authorityP = + baseUriP = strP >>= \case SSSimplex -> pure (SLSSimplex, Nothing) SSAppServer (SrvLoc h "") -> pure (SLSServer, Just h) From 87d164b2c65752443ceeb5c80d622852649ee8ff Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:36:27 +0000 Subject: [PATCH 09/10] agent: name links only with the simplex: scheme --- src/Simplex/Messaging/SimplexName.hs | 8 ++++++-- tests/AgentTests/ConnectionRequestTests.hs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index ba7515afe..3cba340c3 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -36,7 +36,7 @@ import Simplex.Messaging.Agent.Store.DB (Binary (..), FromField (..), ToField (. import Simplex.Messaging.Encoding (Encoding (..)) import Simplex.Messaging.Encoding.String import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, enumJSON) -import Simplex.Messaging.ServiceScheme (ServiceScheme) +import Simplex.Messaging.ServiceScheme (ServiceScheme (..)) import Simplex.Messaging.Util (eitherToMaybe, safeDecodeUtf8, (<$?>)) data SimplexNameInfo = SimplexNameInfo @@ -111,8 +111,12 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional ((strP :: A.Parser ServiceScheme) *> "name") *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional nameSchemeP *> ((strP >>= infoP) <|> infoP NTPublicGroup) where + nameSchemeP = + strP >>= \case + SSSimplex -> "name" + SSAppServer _ -> fail "bad name scheme" infoP NTPublicGroup = SimplexNameInfo NTPublicGroup <$> (strP <|> bareName) infoP NTContact = SimplexNameInfo NTContact <$> strP bareName = parseBare . safeDecodeUtf8 <$?> boundedNonSpace diff --git a/tests/AgentTests/ConnectionRequestTests.hs b/tests/AgentTests/ConnectionRequestTests.hs index e4ca36eb5..c421a7e9a 100644 --- a/tests/AgentTests/ConnectionRequestTests.hs +++ b/tests/AgentTests/ConnectionRequestTests.hs @@ -336,6 +336,7 @@ connectionRequestTests = channel #== "simplex:c#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY?h=smp.simplex.im" name #== "simplex:/name#alice.simplex" name #== "simplex:name#alice.simplex" + (strDecode "https://simplex.chat/name#alice.simplex" :: Either String SimplexNameInfo) `shouldSatisfy` isLeft it "should shorten / restore short links" $ do let contact = CSLContact SLSServer CCTContact shortenShortLink [srv] (contact srv (LinkKey "0123456789abcdef0123456789abcdef")) From 70042fb655bd1474363c8955204217c7a916b78c Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:12:16 +0000 Subject: [PATCH 10/10] agent: name links only with # or @ after the name scheme --- src/Simplex/Messaging/SimplexName.hs | 2 +- tests/AgentTests/ConnectionRequestTests.hs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Simplex/Messaging/SimplexName.hs b/src/Simplex/Messaging/SimplexName.hs index 3cba340c3..5eb7b84dd 100644 --- a/src/Simplex/Messaging/SimplexName.hs +++ b/src/Simplex/Messaging/SimplexName.hs @@ -111,7 +111,7 @@ boundedNonSpace = do instance StrEncoding SimplexNameInfo where strEncode SimplexNameInfo {nameType, nameDomain} = strEncode nameType <> strEncode nameDomain - strP = optional nameSchemeP *> ((strP >>= infoP) <|> infoP NTPublicGroup) + strP = optional nameSchemeP *> (strP >>= infoP) where nameSchemeP = strP >>= \case diff --git a/tests/AgentTests/ConnectionRequestTests.hs b/tests/AgentTests/ConnectionRequestTests.hs index c421a7e9a..98b1a7aa3 100644 --- a/tests/AgentTests/ConnectionRequestTests.hs +++ b/tests/AgentTests/ConnectionRequestTests.hs @@ -337,6 +337,7 @@ connectionRequestTests = name #== "simplex:/name#alice.simplex" name #== "simplex:name#alice.simplex" (strDecode "https://simplex.chat/name#alice.simplex" :: Either String SimplexNameInfo) `shouldSatisfy` isLeft + (strDecode "simplex:namealice" :: Either String SimplexNameInfo) `shouldSatisfy` isLeft it "should shorten / restore short links" $ do let contact = CSLContact SLSServer CCTContact shortenShortLink [srv] (contact srv (LinkKey "0123456789abcdef0123456789abcdef"))