dostr_relay_url 0.1.0
dostr_relay_url: ^0.1.0 copied to clipboard
Normalization of Nostr relay urls, so two spellings of one relay compare equal, and a type for the normalized ones, in pure Dart.
0.1.0 #
- Initial release. The relay url normalization of
ndkmoved here: the deep importpackage:ndk/shared/helpers/relay_helper.dartis nowpackage:dostr_relay_url/dostr_relay_url.dart, anddostr_coreexports it too. cleanRelayUrl(url)is nowRelayUrl.tryParse(url), as inUri.tryParse, andcleanRelayUrls(urls)is gone:urls.map(RelayUrl.tryParse).nonNullsreplaces it.RelayUrl.tryParsereturns aRelayUrl, an extension type onStringthat only it,RelayUrl.parseandRelayUrl.fromUserInputmake, short of a cast. Code that read the urls asStrings keeps working.RelayUrl.parsedoes whatRelayUrl.tryParsedoes, but throws aFormatExceptionwhere it returns null.RelayUrl.fromUserInputnormalizes a relay url a person typed: it reads a url without a scheme as awssurl, and anhttporhttpsurl as awsorwssone. Without a scheme, the host must belocalhost, an IP address or a name holding a dot.relayUrlRegexand the url normalizer behindcleanRelayUrlare gone:RelayUrl.tryParsebuilds onUri.parse.RelayUrl.tryParseaccepts IPv6 addresses, a query without a path and a host name holding_, whichcleanRelayUrlrejected. It drops the fragment, which RFC 6455 forbids in WebSocket urls, wherecleanRelayUrlkept it after a path and rejected the url otherwise. It also rejects port 0 and a port above 65535. It drops the trailing dot of a fully qualified host, wherecleanRelayUrlrejected the url. It merges repeated slashes in the path, wherecleanRelayUrlkept them.