check method

Future<Nip05> check({
  1. required String nip05,
  2. required String pubkey,
})

checks the nip05 object for validity it checks the cache first, if not found it fetches from the network if either fails valid is set to false

nip05 the nip05 identifier pubkey the public key returns the Nip05 object

Implementation

Future<Nip05> check({required String nip05, required String pubkey}) async {
  if (nip05.isEmpty || pubkey.isEmpty) {
    throw Exception("nip05 or pubkey empty");
  }

  final databaseResult = await _database.loadNip05(pubkey);

  if (databaseResult != null) {
    int now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
    int lastCheck = databaseResult.networkFetchTime ?? 0;
    if (now - lastCheck < NIP_05_VALID_DURATION) {
      return databaseResult;
    }
  }

  // Check if there's an in-flight request for this nip05
  if (_inFlightRequests.containsKey(nip05)) {
    // Wait for the existing request to complete
    return await _inFlightRequests[nip05]!;
  }

  // Create a new request and add it to the in-flight map
  final request =
      _performCheck(nip05, pubkey, Nip05(pubKey: pubkey, nip05: nip05));
  _inFlightRequests[nip05] = request;

  try {
    return await request;
  } finally {
    // Remove the request from the in-flight map once it's completed
    _inFlightRequests.remove(nip05);
  }
}