relayInformationsDocumentNip11 method

  1. @override
Future<RelayInformations?> relayInformationsDocumentNip11({
  1. required String relayUrl,
  2. bool throwExceptionIfExists = true,
})
override

Ths method will get you RelayInformations that contains the given relayUrl using the NIP11 implementation.

example:

final relayInformations = await Nostr.instance.relays.relayInformationsDocumentNip11(
relayUrl: "ws://relay.nostr.dev",
);

Implementation

@override
Future<RelayInformations?> relayInformationsDocumentNip11({
  required String relayUrl,
  bool throwExceptionIfExists = true,
}) async {
  try {
    final relayHttpUri =
        webSocketsService.getHttpUrlFromWebSocketUrl(relayUrl);

    final res = await http.get(
      relayHttpUri,
      headers: {
        'Accept': 'application/nostr+json',
      },
    );
    final decoded = jsonDecode(res.body) as Map<String, dynamic>;

    return RelayInformations.fromNip11Response(decoded);
  } catch (e) {
    utils.log(
      'error while getting relay informations from nip11 for relay url: $relayUrl',
      e,
    );

    if (throwExceptionIfExists) {
      rethrow;
    }
  }
  return null;
}