Why Nostr? What is Njump?
2025-05-27 10:16:54

Anthony Accioly on Nostr: Morning folks. Quick one, I'm working (well, actually, talking my mouth off and ...

Morning folks. Quick one, I'm working (well, actually, talking my mouth off and getting in the way of their good work 🤣) with Keyoxide folks on their Matrix channel. They are implementing Nostr support and having an interesting issue with nostr-tools.

Apparently

```
import { WebSocket } from 'ws'

useWebSocketImplementation(WebSocket)
```

Is not setting the WS in their environment. Bizarrely, manually setting the variable works.

```
pool._WebSocket = WebSocket
```

See: https://code.jaenis.ch/gists/nostr-tools-websocket-closure-leak/src/branch/main/nostr.js#L28

If you comment line 28 things break.

The code is runnable (`npm i && npm run test`).

I'm a bit clueless when it comes to TypeScript, but it feels like this was meant be somewhat of a "private" global variable. Somehow `useWebSocketImplementation` is not working in this example. After calling `useWebSocketImplementation` WebSocket is still undefined.

Anyone more familiar with TypeScript and Nostr tools can have a look?

#devstr #asknostr #nostrtools #typescript #websockets
Author Public Key
npub1a6we08n7zsv2na689whc9hykpq4q6sj3kaauk9c2dm8vj0adlajq7w0tyc