pubKeyFromIdentifierNip05 method

  1. @override
Future<String> pubKeyFromIdentifierNip05({
  1. required String internetIdentifier,
})
override

Return the public key found by the NIP05 implementation via the given for the given internetIdentifier

Example:

 final pubKey = await Nostr.instance.relays.pubKeyFromIdentifierNip05(
  internetIdentifier: "localPart@domainPart",
);

print(pubKey); // ...

Implementation

@override
Future<String> pubKeyFromIdentifierNip05({
  required String internetIdentifier,
}) async {
  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] as String?;

    if (pubKeyFromResponse == null) {
      throw Exception('invalid nip05 response, no pub key!');
    }

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