Skip to content
Melvin Carvalho edited this page May 6, 2023 · 5 revisions

Hyper-Nostr Relay

Hyper-Nostr is a distributed Nostr relay that aims to synchronize your relay storage and real-time events using Hyperswarm, and Hyperbeedee. Read a more detailed introduction here.

Quick Start

npx hyper-nostr 3338 nostr

Where 3338 is the port and nostr is the topic

Output

You will get ED25519 your public key your key is 31e43770940ca86

Testing

echo '["REQ", "hyper", {}]' | websocat -n --ping-interval 20  ws://localhost:3338/nostr

Uses Websocat

Displays a stream of events

Installation

To start using Hyper-Nostr Relay, follow these steps:

  1. Install the package: npm -g hyper-nostr
  2. Run the relay: hyper-nostr [port [...starting topics]] (default port: 3000)
  3. Add your relay to your Nostr client: ws://localhost:[port]/[topic] (replace [port] and [topic] with your desired values)
  4. The setup is complete!

About

Hyper-Nostr Relay is a powerful tool that behaves as a public relay for the Nostr network. It enables users to send and receive notes from their peers through a distributed and synchronized storage system.

The relay utilizes the following technologies:

  • Hyperswarm: A decentralized network for peer discovery and communication.
  • Hyperbeedee: A database loosely based on MongoDB.

Additionally, the project leverages the Hyper SDK to abstract the management of hyperswarm and cores.

NIPs Implemented

Hyper-Nostr Relay supports several Nostr Improvement Proposals (NIPs):

  • NIP-01 (mandatory Nostr implementation)
  • NIP-02 (contact lists)
  • NIP-04 (direct messages)
  • NIP-09 (event deletion)
  • NIP-11 (relay information)
  • NIP-12 (generic tag queries)
  • NIP-16 (event treatment)
  • NIP-20 (command results)
  • NIP-33 (parametrized replaceable events)
  • NIP-45 (event counts)
  • NIP-50 (search)

Code API

To interact with the Hyper-Nostr Relay programmatically, use the following code:

import * as SDK from 'hyper-sdk'
import createSwarm from 'hyper-nostr'
import goodbye from 'graceful-goodbye'

const yourStorageFolder = '.hyper-nostr-relay' // set to false to not persist
const theTopic = 'nostr'

const sdk = SDK.create({
    storage: yourStorageFolder
})
goodbye(_ => sdk.close())

const { 
    subs, // a Map<subscriptionId: string, { filters: Filter[], socket: WebSocket }> object
    sendEvent, // (event: Event, kind: 'regular' | 'replaceable' | 'ephemeral', socket?: WebSocket) => document: Object | Error; to send a Nostr Event to the peers and the local database. Optionally pass in the socket of the sender to filter them out in the broadcast
    queryEvents, // (filters: Filter[]) => Promise<Event[]>; to query the database for the events that match the list of filters 
    update, // () => Promise<void>; to await the database to update, syncing with the connected peers
} = await createSwarm(sdk, theTopic)

Nostr Version of hypercore

https://github.com/blakejakopovic/hypercore-crypto/commit/669cfdfded913f290ce13b87556f484ab58adc46

Clone this wiki locally