pull down to refresh

What is WASM?

All web browser today are almost like a virtual machine, inside which program code can run. In the olden days it would just be JavaScript or VBScript or, via a plug-in, Java code running in an JVM inside the browser. (Or Flash, in the FlashPlayer, but let's not talk about that).
Nowadays, all modern browsers support WASM aka WebAssembly[1]. This allows us to create programs that run “close to the metal”. This means that games or video/audio editing [5] or other very demanding tasks can run without the hindrance of one extra conversion step.
Other techniques [2], [3] allow us to save and later retrieve data inside the browser.

Can I install and run a BTC/LN node inside a browser?

You can see where this is going. A BTC node needs to download, process, and store large amounts of data to run (less storage if it's running in “pruned” mode). A LN node, however, needs only to connect to a full BTC node to function. It should be relatively simple to program a LN node that runs entirely inside a browser. [4]

Why would you want a NOSTR client (or a relay) in wasm inside a browser?

One weak point of Nostr is that there is a distinction between participating clients and those with more technical skills that support the network by running a relay. This is different from P2P models like BitTorrent uses, where to download you also need to upload [6].
Now, imagine a world in which every Nostr web client doesn't need a server that collects all messages and forwards those to your browser. Rather, the Nostr client fully runs inside the browser. There would be no more choke points, and all users would (even unknowingly) be full participants in this decentralized network.
A man's gotta dream...
[1] https://medium.com/commencis/what-is-the-webassembly-wasm-c19bfcfb34ad [2] https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB [3] https://html.spec.whatwg.org/multipage/webstorage.html#webstorage [4] one wonko even ported parts of a BTC node to WASM, see: https://github.com/donpdonp/bitcoin-wasm [5] https://github.com/ffmpegwasm/ffmpeg.wasm [6] Although you can set your upload and download bandwidths independently and thereby be more of a leecher than a seeder.
LDK targets wasm as a compile target. mutiny wallet uses that today to run a lightning node in wasm in the browser. you can try it on testnet today!
On the "every nostr client should be a relay" point: Nostr was explicitly designed not that way. You need relays to aggregate events and for search/discovery. decentralized, p2p, and distributed are all different things. nostr is decentralized, not p2p, and that's why it has a chance at working.
reply
I did not know about LDK's target of compiling to wasm. Thanks for telling us 👍
I remember reading about Mutiny Wallet. I searched for it but could not find it again, and plainly forgot about the name Mutiny wallet 🙈 Thanks for mentioning the name here. https://mutinywallet.com/
I was thinking of a future where running a NOSTR relay becomes burdensome because of the popularity. It's better to have a system with users that also relay, then having some centralized entities doing all the storing and relaying.
reply
One of the devs of mutiny! I think @rijndael nails it by comparing it to p2p. Lightning is designed to be p2p, nostr isn't. That's why I think a LN in a web browser is more capable than a nostr relay. Though it's not without hurdles to solve even then.
reply
Agreed on nostr wasm client. Would love to see it. Probably one of the existing rust libraries need to target wasm and build the special sauce for it.
As a relay itself, still an advocate for wasm but not in the browser itself. I'm not a nostr expert but the need to be always online for other people to post to is pretty burdensome. Maybe you could do it if there's in depth support for specifying your personal relays when people are specifically trying to communicate with just you. Further, there's listening support that's required so a server needs to be running somewhere regardless.
Again, not a nostr expert but I'm sure there would be significant protocol work required to get to that point. Just because people can run their own relays doesn't mean the system can support it if everyone did. I have my own opinions about nostr but it's more of a distributed system than a decentralized one.
reply
Fantastic article. This seems very promising for both nostr and the LN
reply