JSPM

applesauce-relay

0.0.0-next-20250404075518
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 277
    • Score
      100M100P100Q92905F
    • 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/pool
    • applesauce-relay/relay
    • applesauce-relay/types

    Readme

    Applesauce Relay

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

    ⚠️ Alpha Software Warning: This package is in early alpha stage. It contains bugs, is not fully tested, and may undergo significant changes. Use with caution in production environments.

    Installation

    npm install applesauce-relay

    Features

    • NIP-01
    • Client negentropy sync
    • Relay pool and groups
    • Handle reconnects
    • Write tests
    • Handle NIP-11 limitations
    • Add documentation to docs

    Examples

    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);
    });