nostr-dev-kit / ndk

Nostr Development Kit with outbox-model support
MIT License
357 stars 96 forks source link

create a config to include readonly relay (caching relay) #132

Open antonioconselheiro opened 11 months ago

antonioconselheiro commented 11 months ago

this will allow to integrate with cache relays like https://github.com/PrimalHQ/primal-caching-service, they don't receive publish, it just cache data from other relays.

Suggestion:


const ndk = new NDK({
    explicitRelayUrls: ["wss://a.relay", "wss://another.relay"],
    explicitReadonlyRelayUrls: [ "wss://caching.relay" ]
});```

or

```typescript
const ndk = new NDK({
    explicitRelayUrls: ["wss://a.relay", "wss://another.relay"],
    explicitCachingRelayUrls: [ "wss://caching.relay" ]
});```
WilhelmFreiheitsberg commented 11 months ago

This makes a lot of sense, I would also need it!

pablof7z commented 11 months ago

It does make sense, but I think this is a hack because relays are not able to communicate these things in the protocol; not sure what to do here because I really want to fix the spec but that's going to take some time.

pablof7z commented 11 months ago

I'm inclined to think it's worth adding something like this; I'll think about it some more and how to structure it properly

antonioconselheiro commented 11 months ago

This configuration should create a relay pool that does not write events, read only, where is the hack?

With this, you can allow your user to configure cache services or home cache service actively persisting relay events of interest to us to don't need to connect to anything when I wanna read my timeline.

The protocol is guaranteed by the signature in the event, not by the relay's structure. I can save a signed nostr event in a QR code or in a file, the nsec signature guarantees guarantees the authorship of the event.

The fact that events are shared with event type 6 already allows us to pass events from relay to relay and having these caching services will increase resilience against censorship, which is the fundamental proposal of nostr.

Check primal, it uses cache services: image

This configuration significantly affects the user experience in a positive way, check https://primal.net/.