Why Nostr? What is Njump?
2025-04-21 00:53:44

Jimmy Flanagan on Nostr: import { getEventHash, signEvent, relayInit } from 'nostr-tools'; import * as fs from ...

import { getEventHash, signEvent, relayInit } from 'nostr-tools';
import * as fs from 'fs/promises';

// Replace with your actual keys
const sk = 'your_private_key_hex'; // keep this secret
const pk = 'your_public_key_hex'; // can be derived from sk if needed

async function postSignedProof() {
const proof = await fs.readFile('proof.txt.asc', 'utf8');

const event = {
kind: 1,
created_at: Math.floor(Date.now() / 1000),
tags: [],
content: proof,
pubkey: pk,
};

event.id = getEventHash(event);
event.sig = signEvent(event, sk);

const relay = relayInit('wss://relay.nostr.band');

relay.on('connect', () => {
console.log('Connected to relay');
let pub = relay.publish(event);
pub.on('ok', () => {
console.log('Event published successfully');
relay.close();
});
pub.on('failed', reason => {
console.error('Failed to publish:', reason);
relay.close();
});
});

relay.on('error', () => {
console.error('Failed to connect to relay');
});

await relay.connect();
}

postSignedProof();
Author Public Key
npub103m2ctf5ju49ffzmvn7ld7tne8x0t4g2248l26qfwf6khgnmq8pqvft082