875 Commits

Author SHA1 Message Date
fiatjaf
bd02fc3287 pass the relay URL to verifyEvent() so trusted-relay policies can be implemented. 2026-07-20 13:01:28 -03:00
fiatjaf
c66469dc75 declare a missing type. 2026-07-17 20:55:14 -03:00
fiatjaf
05c2836218 add favorite follow sets kind. 2026-07-16 21:08:11 -03:00
fiatjaf
fa21fd6671 replace ad-hoc regexes with isHex32(). 2026-07-16 20:24:50 -03:00
fiatjaf
585258516b blossom: optimize hash extraction from url. 2026-07-16 20:24:50 -03:00
fiatjaf
cbb1b9688d subscribeMap's onClose is now called with {url, reason}[] instead of reason[]. 2026-07-14 13:17:35 -03:00
fiatjaf
b1406da48e blossom: send content-type header when uploading. v2.23.12 2026-07-13 22:28:19 -03:00
fiatjaf
514678b102 automatically closed unused relay connections after a while. v2.23.11 2026-07-13 11:24:56 -03:00
fiatjaf
21d11f1496 export new modules to jsr. 2026-07-01 00:49:15 -03:00
fiatjaf
08b676a8a4 nip45 helpers and pool.countMany() with HLL. 2026-07-01 00:17:27 -03:00
fiatjaf
e07ed919c5 relay.countWithHLL() 2026-06-30 23:43:51 -03:00
fiatjaf
cf1c218bfc add a nipb0.ts with blossom helpers. 2026-06-26 19:00:17 -03:00
fiatjaf
73ff3660ac add a bunch of kind numbers. 2026-06-26 18:59:47 -03:00
fiatjaf
c5f7f3cbe1 catch EVENT/COUNT sending errors. 2026-06-25 22:20:47 -03:00
fiatjaf
e9b40dca7c nip46: support client metadata for the bunker:// flow. 2026-06-23 09:16:02 -03:00
fiatjaf
dab630de34 nip10/nip22: guard against malformed tags. 2026-06-22 21:20:09 -03:00
hoppe
455124eecd fix(reconnect): don't permanently kill subscriptions on a single failed reconnect attempt
A single failed reconnect attempt (`ws.onerror` or connect timeout)
set `skipReconnection = true`, which made `handleHardClose` close
every subscription on the relay and remove it from the pool. The
intent of fb7de7f was to give up on the *initial* connect failure
(a relay that's dead from the start) — but the same code path also
fires for retries, so any outage longer than the first 10s backoff
slot turned a transient drop into permanent silence on every
long-running client.

Symptom in the wild: a long-running daemon goes silently deaf on a
subscription after the relay operator restarts the relay, with no
error from the SDK because the pool still considers the relay
connected after a later `ensureRelay`. Only `skipReconnection` on
the first attempt (`reconnectAttempts === 0`), so retries fall
through to `handleHardClose` and schedule another attempt as the
`resubscribeBackoff` array clearly intended.
2026-06-20 13:40:04 -03:00
fiatjaf
3575368176 nip19: TLV infinite loop again.
probably fixes https://github.com/nbd-wtf/nostr-tools/issues/223
2026-06-15 18:22:50 -03:00
fiatjaf
e17366cd2e add AUTH recommendations to README.
fixes https://github.com/nbd-wtf/nostr-tools/issues/537
2026-06-10 22:09:28 -03:00
hzrd149
7b1574d45c Fix linting 2026-06-10 21:47:21 -03:00
hzrd149
3defeeb796 nip46: add logout method 2026-06-10 21:47:21 -03:00
fiatjaf
5de4f4549b fix jsr export. 2026-05-18 21:11:05 -03:00
fiatjaf
ed47ef8ef7 bump version. v2.23.5 2026-05-18 20:52:28 -03:00
fiatjaf
a9e89e16e3 nip22: like nip10, but for kind:1111 and adjacent kinds. 2026-05-18 20:52:05 -03:00
fiatjaf
3cd26d7d76 nip44: fix test sha256. 2026-05-18 20:52:05 -03:00
Kai
e1f3ffdece fix: format pool.test.ts and relay.test.ts (pre-existing) 2026-04-25 13:41:06 -03:00
Kai
1f2c967b04 feat(nip47): support multiple relays in parseConnectionString
NIP-47 connection strings can specify multiple relay params, but
parseConnectionString only returned the first one.

Adds a 'relays' field (string[]) to NWCConnection while keeping the
existing 'relay' field (deprecated) for backward compatibility.

Fixes #494
2026-04-25 13:41:06 -03:00
Kai
6b8c242282 fix(nip42): catch SendingOnClosedConnection during automatic AUTH
Fixes #531. When automaticallyAuth is configured and a relay closes the
connection between sending the AUTH challenge and the client sending
the signed response, the SendingOnClosedConnection error was propagating
as an unhandled promise rejection.

This is a race condition that commonly occurs with relays that enforce
WoT or whitelists - they accept the WebSocket, send an AUTH challenge,
but close the connection before the client can respond.

The fix catches the SendingOnClosedConnection error specifically in the
AUTH case handler, preventing unhandled rejections while still propagating
other errors.
2026-04-14 08:24:47 -03:00
Alex Gleason
8260e6245d nip44: support encryption of payloads larger than 65535 bytes (#527)
* nip44: support encryption of payloads larger than 65535 bytes

Implement the extended prefix format from nostr-protocol/nips#1907
with bug fixes:

- When plaintext length >= 65536, pad with a 6-byte prefix (2 zero
  sentinel bytes + 4-byte u32 BE length) instead of the 2-byte u16
- Detect the sentinel in unpad() and use dynamic prefix_len (2 or 6)
  for both data extraction and padding validation
- Remove upper-bound size limits in decodePayload() (was rejecting
  payloads > 87472 chars / 65603 bytes)
- Raise maxPlaintextSize from 0xffff to 0xffffffff (2^32-1)
- Add writeU32BE() helper for encoding large lengths
- Fix unpad() to use padded.byteOffset for correct DataView on
  subarrays (was using padded.buffer directly which could be wrong
  if padded is a subarray of a larger buffer)

Tests: add boundary tests at 65535/65536/65537 bytes and full
encrypt/decrypt round-trips at 65536 and 100000 bytes.
All 10 tests pass (5 existing + 5 new).

* nip44: fix calcPaddedLen overflow, enforce canonical prefix, add thorough tests

Fix three bugs found during security audit:

- calcPaddedLen: use 2** instead of 1<< to avoid signed 32-bit
  overflow in JS for plaintext lengths above 2^30
- unpad: reject extended 6-byte prefix when decoded length is below
  65536 (enforce canonical encoding, prevent ambiguous padding)
- decodePayload: document that callers should validate payload size
  before calling to prevent DoS from oversized inputs
- Fix stale size-range comments to match corrected spec arithmetic

Add 10 new tests covering:
- Non-canonical extended prefix rejection (len=1, 1000, 65535)
- Truncated extended prefix buffer
- calcPaddedLen at 2^30+1, 2^31, and 2^32-1
- Multi-byte UTF-8 at the 65536 byte boundary (pad/unpad + e2e)
- Spec test vectors with SHA-256 checksums for 65535/65536/65537
2026-04-10 23:21:52 -03:00
Kai
007e0b41d0 feat(nip46): add skipSwitchRelays option to BunkerSignerParams
Adds a skipSwitchRelays option that prevents automatic switchRelays()
call in fromURI. This is useful when users want to call switchRelays
manually at their own pace, avoiding race conditions when making
immediate RPC calls after connection.

Fixes #526
2026-03-28 10:14:35 -03:00
Kai
8be6d08a43 fix(nip47): support multiple relays in parseConnectionString
Addresses #494. The NIP-47 spec allows multiple relay parameters in
connection strings, but parseConnectionString only returned the first one.

Changes:
- Add 'relays' field to NWCConnection interface (string array)
- Use searchParams.getAll('relay') to capture all relays
- Keep 'relay' field for backwards compatibility (returns first relay)

This is backwards compatible - existing code using connection.relay
will continue to work, while new code can use connection.relays to
access all specified relays.
2026-03-27 07:02:47 -03:00
d3vv3
1b955bdbcb fix: window.printer is undefined in AbstractRelay._onmessage 2026-02-28 01:01:07 -03:00
fiatjaf
1c1e2cc51a verify event should catch exceptions from basic validation. v2.23.2 2026-02-26 18:10:39 -03:00
arthurfranca
54199504a7 oninvalidevent 2026-02-26 18:08:17 -03:00
fiatjaf
e45a9987e2 pool: prevent edge case with undefined subcloser. v2.23.1 2026-02-12 15:08:13 -03:00
fiatjaf
0c2c2cd4d8 nip13: improve mining by skipping hex. 2026-02-08 01:06:01 -03:00
fiatjaf
28f7553187 fix a type so jsr is happy. v2.23.0 2026-02-02 18:49:17 -03:00
fiatjaf
ca29d9b515 ok, we need the prepareSubscription method. 2026-02-02 18:46:50 -03:00
fiatjaf
ab802c8dbe automatic prune broken relay objects and keep track of relay idleness so they can be pruned. 2026-02-02 18:44:52 -03:00
fiatjaf
9db705d86c delete queue test since we don't have queues anymore. 2026-02-02 17:01:59 -03:00
fiatjaf
be9b91318f relay: get rid of the message queue, because js is single-threaded. 2026-02-02 09:06:56 -03:00
fiatjaf
c2423f7f31 nip27: fix hashtag parsing after newline or other characters. 2026-02-02 08:56:18 -03:00
fiatjaf
05b1fba511 export source files so they can be imported by other ts apps and libraries better. 2026-02-02 00:38:15 -03:00
fiatjaf
2d1345096b subscribeMany and subscribeManyEose are the same as subscribe/subscribeEose. 2026-02-01 17:19:58 -03:00
fiatjaf
6fc7788a4f utils: merging two (reverse) sorted lists of events. 2026-02-01 08:44:49 -03:00
fiatjaf
2180c7a1fe add onRelayConnectionSuccess to pair with onRelayConnectionFailure. 2026-01-31 19:27:45 -03:00
fiatjaf
b4bec2097d finally stop reconnecting when the first connection fails once and for all. 2026-01-31 19:27:45 -03:00
fiatjaf
fb7de7f1aa prevent reconnections when initial connection fails. 2026-01-31 13:57:33 -03:00
fiatjaf
ccb9641fb9 pool: maxWaitForConnection parameter.
this was so obvious.
2026-01-31 00:27:55 -03:00
fiatjaf
b624ad4059 pool: hooks to notify when a relay fails to connect, then ask whether a connection should be attempted. v2.22.1 2026-01-30 17:35:46 -03:00