fetchNip05 method

  1. @override
Future<Nip05?> fetchNip05(
  1. String nip05
)
override

fetches NIP-05 data without validation returns pubkey and relays for the given nip05 identifier

Implementation

@override
Future<Nip05?> fetchNip05(String nip05) async {
  final identifier = _parseIdentifier(nip05);
  if (identifier == null) {
    return null;
  }

  final Map<String, dynamic> json;
  try {
    json = await httpDS.jsonRequest(
      identifier.url,
      followRedirects: false,
      timeout: timeout,
    );
  } on HttpRequestException catch (e) {
    if (e.statusCode == 404) {
      return null;
    }
    rethrow;
  }

  Map names = json["names"];
  Map relays = json["relays"] ?? {};

  String? pubkey = names[identifier.name];

  if (pubkey == null) {
    return null;
  }

  List<String> pRelays = [];
  if (relays[pubkey] != null) {
    pRelays = List<String>.from(relays[pubkey]);
  }

  return Nip05Model(
    pubKey: pubkey,
    nip05: nip05,
    valid: true,
    networkFetchTime: DateTime.now().millisecondsSinceEpoch ~/ 1000,
    relays: pRelays,
  );
}