39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import * as nostrTools from '@nostr/tools';
|
|
import { isArray } from './utils/isArray.ts';
|
|
|
|
export const pool = new nostrTools.SimplePool();
|
|
export const relays = [
|
|
'wss://relay.arx-ccn.com/',
|
|
'wss://relay.dannymorabito.com/',
|
|
'wss://nos.lol/',
|
|
'wss://nostr.einundzwanzig.space/',
|
|
'wss://nostr.massmux.com/',
|
|
'wss://nostr.mom/',
|
|
'wss://nostr.wine/',
|
|
'wss://purplerelay.com/',
|
|
'wss://relay.damus.io/',
|
|
'wss://relay.goodmorningbitcoin.com/',
|
|
'wss://relay.lexingtonbitcoin.org/',
|
|
'wss://relay.nostr.band/',
|
|
'wss://relay.primal.net/',
|
|
'wss://relay.snort.social/',
|
|
'wss://strfry.iris.to/',
|
|
'wss://cache2.primal.net/v1',
|
|
];
|
|
|
|
/**
|
|
* FIXME: make sure to somehow tag encryptedEvents and add asserts, so that it's not possible to accidentally call this function with unencrypted events
|
|
*
|
|
* @param encryptedEvent the event to publish to the relay
|
|
*/
|
|
export async function publishToRelays(
|
|
encryptedEvent: nostrTools.Event | nostrTools.Event[],
|
|
): Promise<void> {
|
|
if (isArray(encryptedEvent)) {
|
|
for (const chunk of encryptedEvent) {
|
|
await Promise.any(pool.publish(relays, chunk));
|
|
}
|
|
} else {
|
|
await Promise.any(pool.publish(relays, encryptedEvent));
|
|
}
|
|
}
|