Created
April 19, 2023 03:53
-
-
Save mattn/3d1735cd9d660b20a9aaf59e0394d1f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "websocket-polyfill" | |
import { | |
nip19, | |
relayInit, | |
generatePrivateKey, | |
getPublicKey, | |
getEventHash, | |
signEvent | |
} from 'nostr-tools' | |
function formatDate(date: Date) { | |
return ("00" + date.getHours()).slice(-2) | |
+ ":" + ("00" + date.getMinutes()).slice(-2) | |
+ ":" + ("00" + date.getSeconds()).slice(-2) | |
} | |
const relay = relayInit('wss://nostr.wine') | |
relay.connect() | |
const decoded = nip19.decode(process.env.JIHOBOT_NSEC) | |
const sk = decoded.data as string | |
const pk = getPublicKey(sk) | |
let event = { | |
id: '', | |
kind: 1, | |
pubkey: pk, | |
created_at: Math.floor(Date.now() / 1000), | |
tags: [], | |
content: formatDate(new Date()), | |
sig: '', | |
} | |
event.id = getEventHash(event) | |
event.sig = signEvent(event, sk) | |
console.log(relay.publish(event)) | |
relay.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment