Home

Awesome

<h1 align="center">rx-nostr</h1> <p align="center"> rx-nostr is a library that supports high quality and flexible communication with multiple Nostr relays. </p> <p align="center"> <a href="https://penpenpng.github.io/rx-nostr/">documentation</a> / <a href="https://github.com/penpenpng/rx-nostr/releases">release notes</a> </p>

Description

rx-nostr provides transparent interface to read/write events on Nostr relays. You can exchange data in a very familiar way (as you see NIP-01) with that interface, but it allows for far more robust and flexible communication than you can do by touching WebSocket directly. For example:

Under the hood, rx-nostr makes use of RxJS, but you don't need to touch it directly. Of course, if you are familiar with RxJS, you can integrate with it for easier and more declarative writing.

Quickstart

npm install rx-nostr rx-nostr-crypto
import { createRxNostr, createRxForwardReq } from "rx-nostr";
import { verifier, seckeySigner } from "rx-nostr-crypto";

import WebSocket from "ws";

const rxNostr = createRxNostr({
  signer: seckeySigner("nsec1..."), // If omitted, rx-nostr uses NIP-07.
  verifier,
  websocketCtor: WebSocket, // You need this if `globalThis.WebSocket` doesn't exist (e.g. Node.js runtime).
});

rxNostr.setDefaultRelays(["wss://nostr.example.com"]);

const rxReq = createRxForwardReq();

// Define a listener.
rxNostr.use(rxReq).subscribe(({ event }) => {
  console.log(event);
});

// Emit a filter to start subscription.
rxReq.emit({ kinds: [1] });

For more information

License

MIT