JSPM

applesauce-relay

2.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 277
    • Score
      100M100P100Q92957F
    • License MIT

    nostr relay communication framework built on rxjs

    Package Exports

    • applesauce-relay
    • applesauce-relay/negentropy
    • applesauce-relay/operators
    • applesauce-relay/operators/complete-on-eose
    • applesauce-relay/operators/index
    • applesauce-relay/operators/mark-from-relay
    • applesauce-relay/operators/only-events
    • applesauce-relay/operators/store-events
    • applesauce-relay/operators/to-event-store
    • applesauce-relay/pool
    • applesauce-relay/relay
    • applesauce-relay/types

    Readme

    Applesauce Relay

    applesauce-relay is a nostr relay communication framework built on top of RxJS

    Installation

    npm install applesauce-relay

    Features

    • NIP-01
    • Relay pool and groups
    • Fetch NIP-11 information before connecting
    • NIP-11 auth_required limitation
    • NIP-11 max_subscriptions limitation
    • Client negentropy sync
    • Reconnection backoff logic
    • republish event on reconnect and auth-required
    • Resubscribe on reconnect and auth-required
    • NIP-45 COUNT

    Examples

    Read the documentation for more detailed explanation of all methods

    Single Relay

    import { Relay } from "./relay";
    
    // Connect to a single relay
    const relay = new Relay("wss://relay.example.com");
    
    // Subscribe to events
    relay
      .req({
        kinds: [1],
        limit: 10,
      })
      .subscribe((response) => {
        if (response === "EOSE") {
          console.log("End of stored events");
        } else {
          console.log("Received event:", response);
        }
      });
    
    // Publish an event
    const event = {
      kind: 1,
      content: "Hello Nostr!",
      created_at: Math.floor(Date.now() / 1000),
      tags: [],
      // ... other required fields
    };
    
    relay.event(event).subscribe((response) => {
      console.log(`Published:`, response.ok);
    });

    Relay Pool

    import { RelayPool } from "./pool";
    
    // Create a pool and connect to multiple relays
    const pool = new RelayPool();
    const relays = ["wss://relay1.example.com", "wss://relay2.example.com"];
    
    // Subscribe to events from multiple relays
    pool
      .req(relays, {
        kinds: [1],
        limit: 10,
      })
      .subscribe((response) => {
        if (response === "EOSE") {
          console.log("End of stored events");
        } else {
          console.log("Received event:", response);
        }
      });
    
    // Publish to multiple relays
    pool.event(relays, event).subscribe((response) => {
      console.log(`Published to ${response.from}:`, response.ok);
    });

    Relay Group

    import { RelayPool } from "./pool";
    
    const pool = new RelayPool();
    const relays = ["wss://relay1.example.com", "wss://relay2.example.com"];
    
    // Create a group (automatically deduplicates events)
    const group = pool.group(relays);
    
    // Subscribe to events
    group
      .req({
        kinds: [1],
        limit: 10,
      })
      .subscribe((response) => {
        console.log("Received:", response);
      });
    
    // Publish to all relays in group
    group.event(event).subscribe((response) => {
      console.log(`Published to ${response.from}:`, response.ok);
    });