rx-nostr
Version:
A library based on RxJS, which allows Nostr applications to easily communicate with relays.
21 lines (18 loc) • 508 B
text/typescript
import * as Nostr from "nostr-typedef";
/**
* Fetch relay's information based on [NIP-11](https://github.com/nostr-protocol/nips/blob/master/11.md).
*/
export async function fetchRelayInfo(
url: string,
): Promise<Nostr.Nip11.RelayInfo> {
try {
const u = new URL(url);
u.protocol = u.protocol.replace(/^ws(s?):/, "http$1:");
const res = await fetch(u.toString(), {
headers: { Accept: "application/nostr+json" },
});
return await res.json();
} catch {
return {};
}
}