Skip to content

Add NIP-01 OK and CLOSED responses for client messages#68

Open
BenGWeeks wants to merge 1 commit intolnbits:mainfrom
BenGWeeks:fix/nip20-ok-response
Open

Add NIP-01 OK and CLOSED responses for client messages#68
BenGWeeks wants to merge 1 commit intolnbits:mainfrom
BenGWeeks:fix/nip20-ok-response

Conversation

@BenGWeeks
Copy link
Copy Markdown
Contributor

Summary

The relay proxy was not sending NIP-01 required responses after receiving EVENT and REQ messages from clients.

Changes

  • EVENT → OK response: When a client publishes an EVENT, the relay now responds with:
    • ["OK", event_id, true, ""] when the event is forwarded to upstream relays
    • ["OK", event_id, false, "error: no relay connections"] when no relays are connected
  • REQ → CLOSED response: When a client sends a REQ but no relays are connected, the relay responds with:
    • ["CLOSED", subscription_id, "error: no relay connections"]

Why this matters

NIP-01 states:

OK messages MUST be sent in response to EVENT messages received from clients

Without OK responses, NWC clients using nostr-tools SimplePool.publish() timeout after 4.4s waiting for confirmation, causing Nip47PublishError: failed to publish: AggregateError: All promises were rejected. This makes NWC connections unreliable — payments may succeed on the backend but the client reports failure, risking double payments from user retries.

Testing

Verified by connecting directly via WebSocket:

Before patch:

> ["EVENT", {signed_event}]
(no response - timeout after 4.4s)

After patch:

> ["EVENT", {signed_event}]
< ["OK", "e830dca0...", true, ""]

Tested with the @getalby/sdk NWC client — NWC get_balance, pay_invoice, and list_transactions all work reliably after this fix.

Fixes #52
Related: #40

🤖 Generated with Claude Code

The relay proxy was not sending NIP-01 required responses:

- EVENT messages now receive OK responses:
  - ["OK", event_id, true, ""] when event is forwarded to relays
  - ["OK", event_id, false, "error: no relay connections"] when no
    relays are connected
- REQ messages now receive CLOSED responses when no relays are
  connected: ["CLOSED", subscription_id, "error: no relay connections"]

Without OK responses, NWC clients using nostr-tools SimplePool.publish()
timeout after 4.4s waiting for confirmation, making NWC connections
unreliable or broken.

Fixes lnbits#52
Related: lnbits#40

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BenGWeeks added a commit to BenGWeeks/lightning-piggy-mobile that referenced this pull request Apr 5, 2026
- Add TROUBLESHOOTING entry for re-applying the NIP-20 OK fix after
  LNbits upgrade or container recreate
- Add scripts/apply_nip20_fix.py for patching Nostrclient router.py
- Fix patches the EVENT handler to send NIP-01 OK responses
  (PR lnbits/nostrclient#68, still unmerged upstream)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Return error when publishing with no relay connections

1 participant