part of 'relay_session.dart'; String buildNip98AuthHeader({ required String method, required String url, required List bodyBytes, required String? nsec, }) { if (nsec == null || nsec.isEmpty) { throw Exception('Cannot query relay: no signing key available'); } final privkeyHex = nostr.Nip19.decode(payload: nsec).data; if (privkeyHex.isEmpty) { throw Exception('Invalid nsec'); } final payloadHash = SHA256Digest() .process(Uint8List.fromList(bodyBytes)) .map((byte) => byte.toRadixString(16).padLeft(2, '0')) .join(); final event = nostr.Event.from( kind: 27235, content: '', tags: [ ['u', url], ['method', method.toUpperCase()], ['payload', payloadHash], ['nonce', const Uuid().v4()], ], secretKey: privkeyHex, verify: false, ); return 'Nostr ${base64.encode(utf8.encode(event.toJson()))}'; }