nsite-ts/src/ndk.ts

18 lines
497 B
TypeScript
Raw Normal View History

2024-09-01 13:26:37 -05:00
import NDK from "@nostr-dev-kit/ndk";
2024-09-25 15:28:28 -05:00
import { LOOKUP_RELAYS, NOSTR_RELAYS } from "./env.js";
2024-09-01 13:26:37 -05:00
const ndk = new NDK({
2024-09-25 15:28:28 -05:00
explicitRelayUrls: [...LOOKUP_RELAYS, ...NOSTR_RELAYS],
2024-09-01 13:26:37 -05:00
});
ndk.connect();
2024-09-25 15:28:28 -05:00
export async function getUserOutboxes(pubkey: string) {
const mailboxes = await ndk.fetchEvent({ kinds: [10002], authors: [pubkey] });
if (!mailboxes) return;
return mailboxes.tags.filter((t) => t[0] === "r" && (t[2] === undefined || t[2] === "write")).map((t) => t[1]);
}
2024-09-01 13:26:37 -05:00
export default ndk;