@@ -77,9 +77,8 @@ import Simplex.Messaging.Server.Web (EmbeddedWebParams (..), WebHttpsParams (..)
7777import Simplex.Messaging.Server.MsgStore.Journal (JournalMsgStore (.. ), QStoreCfg (.. ), stmQueueStore )
7878import Simplex.Messaging.Server.MsgStore.Types (MsgStoreClass (.. ), SQSType (.. ), SMSType (.. ), newMsgStore )
7979import Network.URI (URI (.. ), URIAuth (.. ), parseAbsoluteURI )
80- import Simplex.Messaging.Protocol (mkNameOwner , NameOwner )
80+ import Simplex.Messaging.Protocol (mkNameOwner )
8181import Simplex.Messaging.Server.Names (NamesConfig (.. ), RpcAuth (.. ), TldRegistries (.. ))
82- import Simplex.Messaging.Server.Names.Eth.RPC (fromHex )
8382import Simplex.Messaging.Server.QueueStore.Postgres.Config
8483import Simplex.Messaging.Server.StoreLog.ReadWrite (readQueueStore )
8584import Simplex.Messaging.Transport (supportedProxyClientSMPRelayVRange , alpnSupportedSMPHandshakes , supportedServerSMPRelayVRange )
@@ -807,11 +806,10 @@ readNamesConfig ini
807806 | otherwise =
808807 let rpcAuth_ = either (error . (" [NAMES] rpc_auth: " <> )) Just . parseRpcAuth =<< eitherToMaybe (lookupValue " NAMES" " rpc_auth" ini)
809808 endpoint = requiredText " ethereum_endpoint"
810- registries = readTldRegistries
811809 in Just
812810 NamesConfig
813811 { ethereumEndpoint = either (error . (" [NAMES] ethereum_endpoint: " <> )) id (validateUrl endpoint rpcAuth_),
814- tldRegistries = registries ,
812+ tldRegistries = hardcodedTldRegistries ,
815813 rpcAuth = rpcAuth_,
816814 rpcTimeoutMs = boundedIniInt 3000 100 60000 " rpc_timeout_ms" ,
817815 rpcMaxResponseBytes = boundedIniInt 262144 1024 16777216 " rpc_max_response_bytes" ,
@@ -833,18 +831,22 @@ readNamesConfig ini
833831 n | n >= floor_ && n <= ceiling_ -> n
834832 | otherwise ->
835833 error $ " [NAMES] " <> T. unpack key <> " must be in [" <> show floor_ <> " .." <> show ceiling_ <> " ] (got " <> show n <> " )"
836- readTldRegistries =
837- let regs = TldRegistries
838- { tldSimplex = optionalAddr " registry_tld_simplex" ,
839- tldTesting = optionalAddr " registry_tld_testing" ,
840- tldAll = optionalAddr " registry_tld_all"
841- }
842- in case (tldSimplex regs, tldTesting regs, tldAll regs) of
843- (Nothing , Nothing , Nothing ) ->
844- error " [NAMES] at least one of registry_tld_simplex, registry_tld_testing, registry_tld_all is required"
845- _ -> regs
846- optionalAddr key =
847- either (error . ((" [NAMES] " <> T. unpack key <> " : " ) <> )) Just . parseEthAddr =<< eitherToMaybe (lookupValue " NAMES" key ini)
834+
835+ -- | Hardcoded SNRC contract whitelist. Placeholder addresses until the
836+ -- launch contracts are deployed; replaced in code rather than INI so
837+ -- operators can't accidentally point a names router at the wrong contract
838+ -- during the bootstrap phase. The TldRegistries shape + lookup precedence
839+ -- (TLD-specific then `tldAll` catch-all) is unchanged from the previous
840+ -- INI-driven form.
841+ hardcodedTldRegistries :: TldRegistries
842+ hardcodedTldRegistries =
843+ TldRegistries
844+ { tldSimplex = Just (placeholderAddr ' \x11 ' ),
845+ tldTesting = Just (placeholderAddr ' \x22 ' ),
846+ tldAll = Nothing
847+ }
848+ where
849+ placeholderAddr c = either error id $ mkNameOwner (B. replicate 20 c)
848850
849851-- | Validate the ethereum_endpoint URL:
850852-- * scheme must be http: or https:
@@ -913,15 +915,6 @@ validateUrl url auth_ = do
913915 ' 0' : ' x' : rest -> all isHexDigit rest
914916 lh -> not (null lh) && all isDigit lh
915917
916- -- | Parse a 20-byte Ethereum address as text "0x[hex40]" or "[hex40]".
917- -- EIP-55 mixed-case checksum verification is a follow-up.
918- parseEthAddr :: Text -> Either String NameOwner
919- parseEthAddr t = do
920- bs <- fromHex (encodeUtf8 t)
921- if B. length bs == 20
922- then mkNameOwner bs
923- else Left " expected a 20-byte address (40 hex characters, optionally 0x-prefixed)"
924-
925918-- | Parse an rpc_auth INI value. Scheme keyword is case-insensitive so
926919-- "Bearer <token>" / "BEARER <token>" (Caddy / RFC 7235 convention) work
927920-- as well as the lowercase form.
0 commit comments