補足2: NIP-07拡張機能(nos2xなど)を使って署名して投稿する
(about:blankでは拡張機能が動かないので、example.comなどで実行)
pubkey = await window.nostr.getPublicKey();
relay = NostrTools.relayInit("wss://nostrja-kari.heguro.com");
await relay.connect();
event = {
"pubkey": pubkey,
"created_at": Math.floor(Date.now() / 1000),
"kind": 1,
"tags": [],
"content": "本文\nだよ〜",
}
event.id = NostrTools.getEventHash(event);
event = await window.nostr.signEvent(event);
pub = relay.publish(event);
pub.on('ok', () => {
console.log('投稿完了');
});
pub.on('failed', (error) => {
console.log('投稿失敗:', error);
});