part of 'relay_session.dart'; /// Pass the signer's hex [pubkey] when it is already known: deriving it from /// the key costs about a third of a signature, on the UI isolate. String buildNip98AuthHeader({ required String method, required String url, required List bodyBytes, required String? nsec, String? pubkey, }) { 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 = crypto.sha256.convert(bodyBytes).toString(); final event = signNostrEvent( kind: 27235, content: '', tags: [ ['u', url], ['method', method.toUpperCase()], ['payload', payloadHash], ['nonce', const Uuid().v4()], ], secretKey: privkeyHex, pubkey: pubkey, ); return 'Nostr ${base64.encode(utf8.encode(event.toJson()))}'; }