#!/usr/bin/env node // Generates a NIP-98 Authorization header value ("Nostr ") for // testing purposes. // // Usage: // node script/nip98-auth-header.mjs [body] // // Example: // export AUTH=$(node script/nip98-auth-header.mjs \ // "$SECRET" "$BASE_URL/subscription/email" PUT '{"email":"a@b.com","frequency":"daily"}') // curl -H "Authorization: $AUTH" ... import { makeHttpAuth, makeHttpAuthHeader } from '@welshman/util' import { Nip01Signer } from '@welshman/signer' const [, , secret, url, method, body] = process.argv if (!secret || !url) { console.error('Usage: node script/nip98-auth-header.mjs [body]') process.exit(1) } const signer = Nip01Signer.fromSecret(secret) // Create the unsigned auth event template const event = await makeHttpAuth(url, method || 'GET', body || undefined) // Stamp (created_at, pubkey, id) and sign const signed = await signer.sign(event) // Encode as "Nostr " const header = makeHttpAuthHeader(signed) console.log(header)