Oddbean new post about | logout
 📢 NDK 1.0 is out!

Codename: Outbox ✅

When I set out to write NDK my main goal was implementing the gossip protocol, now known as *outbox model*. I wanted nostr applications to have decentralizing tendencies by *default*; transparent to the developer.

After a few failed attempts, it's finally here, which, paired with a bunch of non-backward compatible changes, prompts me to do a major version bump.

# What is outbox model?

In short, the outbox model allows nostr to fragment, instead of everybody coalescing around a few popular relay and using things like Blastr. Nostr simply doesn't work without the outbox model.

# Main changes:

* Outbox model support, obviously.
* `fetchEvent(s)` is now faster, (particularly with queries using exclusively `ids` filters).
* Fixed unstable relay back-off code (credit goes to @NVK for the valuable testing infrastructure)
* Defaults to blacklisting wss://brb.io #censorship (credit goes to @NVK  for the widely hinted-at dead relay)
* Subscription aggregation now works when multiple filters run at the same time
* Subscriptions that should close when EOSEd are now closed when each individual relay EOSEs instead of waiting for all of them to EOSE.
* A better algorithm on when to signal a subscription's EOSE. The margin that NDK now gives to relays to EOSE is now a function of how many of the connected relays in the relay set have EOSEd (accounting for relays that are still sending events).
* There are *many* more changes that I needed to do to accommodate for this that I don't remember now.

Some of the most glaring breaking changes:

* `ndk.subscribe` now defaults to keeping the subscription alive; the default of closing subscriptions on EOSE was bothering me 
* NDKUser changes the `hexpubkey` from a function to a getter, so wherever you were using `user.hexpubkey()` needs to change to `user.hexpubkey`.

# Enabling outbox model

Outbox model comes disabled by default *for now*, as soon as I test it more throughogly it will be the default.

To enable it you need to instantiate NDK with:

```
const ndk = new NDK({
    explicitRelayUrls: [...],
    outboxRelayUrls: ["wss://purplepag.es"],
    enableOutboxModel: true,
})
```

The outbox model will largely be transparent to you and will work on the background once you enable it.
 
 1.0! Congrats to all! 
 Offering your creations freely to others is an embodiment of generosity and virtue. Remember, true wealth lies not in what you possess but in what you give. By sharing your creations without expecting anything in return, you align with the noble path of selflessness and contribute to the betterment of humanity. 
 this level of design .. so high quality . thank you very much  
 Congrats 🤜🤛 
 Wow this looks cool! Congrats! 🤙

Can you expand on the blacklisting wss://brb.io part? Is it a bad relay? 
 It’s full of hate speech against argentineans 
 Thanks for letting me know. I will also blacklist it. 🫡 
 😂😂😂😂😂 
 NDK getting gossip support is a huge win for Nostr's decentralization 🫂💜🤙🏻

nostr:nevent1qqs8r0jpp6tgspz2hfsrc3hdrw29lzccwnrdp82eyt28mxanargqtqcpz9mhxue69uhkummnw3ezuamfdejj7q3ql2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqxpqqqqqqz9h7e2s 
 Amazing 😍 
 MVP 

nostr:nevent1qqs8r0jpp6tgspz2hfsrc3hdrw29lzccwnrdp82eyt28mxanargqtqcppemhxue69uhkummn9ekx7mp0qgs04xzt6ldm9qhs0ctw0t58kf4z57umjzmjg6jywu0seadwtqqc75srqsqqqqqppeazrt 
 What's the deal with brb.io? I've read some software blacklisting it, but why?

Also, these updates sound awesome. 
 Also curious for this answer 
 It's semi-permanently down but heavily hinted at in many NIP-65 and events.

No need to get into the quadratic back-off strategy from down-relays when you know that popular relay is semi-permanently down. 
 This changes everything 

nostr:nevent1qqs8r0jpp6tgspz2hfsrc3hdrw29lzccwnrdp82eyt28mxanargqtqcpzdmhxue69uhkummnw3ezud3c8qhx7un8qgs04xzt6ldm9qhs0ctw0t58kf4z57umjzmjg6jywu0seadwtqqc75srqsqqqqqpjtwlvg 
 Re: Outbox: does this mean that you don’t need to manage relays manually at all? It will just hit the Purple Pages relays (assuming multiple are supported here?) and use whatever is shown there? 
 correct 
 Pablo is The Machine. 
 Was trying to read more about it and stumbled on this. Is there meant to be a readme? 

https://image.nostr.build/da961505affdcd4a78f066fca764637353e9b2711c1514a79ae5a7463d958041.jpg 
 💪🔥✌️ 
 😂 brb.io great test infra 
 Cómo afecta esto a Boca? 
 I'm testing outbox in Lume, look like it stuck forever if some relays cannot connected 😅

my code: https://github.com/luminous-devs/lume/blob/10036500cb0742e20232c7f8b5dd6baaeb639f9f/src/libs/ndk/instance.ts#L58

https://m.primal.net/HKqH.png 
 King 
 Excellent! 
 The "What is outbox model" section doesn't really explain what is the model 🤔🤐