verifyNip05 method

  1. @override
Future<bool> verifyNip05({
  1. required String internetIdentifier,
  2. required String pubKey,
})
override

This method will verify the internetIdentifier with a pubKey using the NIP05 implementation, and simply will return a Future with a bool that indicates if the verification was successful or not.

example:

final verified = await Nostr.instance.relays.verifyNip05(
 internetIdentifier: "localPart@domainPart",
 pubKey: "pub key in hex format",
);

Implementation

@override
Future<bool> verifyNip05({
  required String internetIdentifier,
  required String pubKey,
}) async {
  assert(
    pubKey.length == 64 || !pubKey.startsWith('npub'),
    'pub key is invalid, it must be in hex format and not a npub(nip19) key!',
  );
  assert(
    internetIdentifier.contains('@') &&
        internetIdentifier.split('@').length == 2,
    'invalid internet identifier',
  );

  try {
    final localPart = internetIdentifier.split('@')[0];
    final domainPart = internetIdentifier.split('@')[1];
    final res = await http.get(
      Uri.parse('https://$domainPart/.well-known/nostr.json?name=$localPart'),
    );

    final decoded = jsonDecode(res.body) as Map<String, dynamic>;
    assert(decoded['names'] != null, 'invalid nip05 response, no names key!');
    final pubKeyFromResponse = decoded['names'][localPart];
    assert(pubKeyFromResponse != null, 'invalid nip05 response, no pub key!');

    return pubKey == pubKeyFromResponse;
  } catch (e) {
    utils.log(
      'error while verifying nip05 for internet identifier: $internetIdentifier',
      e,
    );
    rethrow;
  }
}