This commit is contained in:
Shusui MOYATANI
2023-02-25 23:35:58 +09:00
parent 717c264c2f
commit 57bc321436
27 changed files with 563 additions and 157 deletions

View File

@@ -4,6 +4,8 @@ import type { Pub } from 'nostr-tools/relay';
import usePool from '@/clients/usePool';
const currentDate = (): number => Math.floor(Date.now() / 1000);
// NIP-20: Command Result
const waitCommandResult = (pub: Pub): Promise<void> => {
return new Promise((resolve, reject) => {
@@ -48,11 +50,10 @@ const useCommands = () => {
const preSignedEvent: NostrEvent = {
kind: 1,
pubkey,
created_at: Math.floor(Date.now() / 1000),
created_at: currentDate(),
tags: [],
content,
};
// TODO define window.nostr
return publishEvent(relayUrls, preSignedEvent);
},
// NIP-25
@@ -73,14 +74,40 @@ const useCommands = () => {
const preSignedEvent: NostrEvent = {
kind: 7,
pubkey,
created_at: Math.floor(Date.now() / 1000),
created_at: currentDate(),
tags: [
['e', eventId],
['p', notifyPubkey],
],
content,
};
// TODO define window.nostr
return publishEvent(relayUrls, preSignedEvent);
},
// NIP-18
publishDeprecatedRepost({
relayUrls,
pubkey,
eventId,
notifyPubkey,
}: {
relayUrls: string[];
pubkey: string;
eventId: string;
notifyPubkey: string;
}): Promise<Promise<void>[]> {
const preSignedEvent: NostrEvent = {
kind: 6,
pubkey,
created_at: currentDate(),
tags: [
['e', eventId],
['p', notifyPubkey],
],
// Some clients includes some contents here.
// Damus includes an original event. Iris includes #[0] as a mention.
// We just follow the specification.
content: '',
};
return publishEvent(relayUrls, preSignedEvent);
},
};