Add NIP-47 (Nostr Wallet Connect) support #8

Open
padreug wants to merge 1 commit from feature/nip47-nwc-support into dev
Owner

Summary

  • Adds NIP-47 (Nostr Wallet Connect) protocol support alongside the existing CLINK/Ndebit system
  • Enables any NWC-compatible wallet (Alby, Amethyst, Damus, etc.) to connect to a Lightning Pub node
  • Implements 6 NIP-47 methods: pay_invoice, make_invoice, get_balance, get_info, lookup_invoice, list_transactions
  • Publishes kind 13194 info events advertising supported NWC methods

Architecture

NWC fits into the existing event routing architecture. NWC clients send kind 23194 requests addressed to the app's existing Nostr pubkey via #p tag, so no new relay subscriptions are needed. The connection URI uses the app's pubkey and a random secret that becomes the client's private key. The wallet identifies connections by the client's derived pubkey stored in a new NwcConnection table.

Key design decisions:

  • Reuses app's existing Nostr keypair — no separate NWC keypairs needed
  • NIP-44 v2 encryption only (already supported in codebase)
  • All amounts converted at boundary: NIP-47 uses msats, internal system uses sats
  • Budget enforcement via max_amount and total_spent per connection

New files

  • src/services/storage/entity/NwcConnection.ts — TypeORM entity
  • src/services/storage/migrations/1770000000000-nwc_connection.ts — DB migration
  • src/services/storage/nwcStorage.ts — Storage layer for connection CRUD
  • src/services/main/nwcManager.ts — Core NIP-47 handler

Modified files

  • src/services/nostr/nostrPool.ts — Subscribe to kind 23194 events
  • src/nostrMiddleware.ts — Route kind 23194 to NwcManager
  • src/services/main/index.ts — Wire NwcManager, publish kind 13194 info
  • src/services/storage/db/db.ts — Register NwcConnection entity
  • src/services/storage/index.ts — Wire NwcStorage
  • src/services/storage/migrations/runner.ts — Register migration

Test plan

  • tsc compiles with zero errors
  • App startup auto-runs the migration and creates nwc_connection table
  • Create an NWC connection via nwcManager.createConnection()
  • Copy nostr+walletconnect://... URI into NWC-compatible wallet (e.g., Alby)
  • Send get_balance request → returns user balance in msats
  • Send pay_invoice request → pays from user balance, returns preimage
  • Send make_invoice request → creates invoice for user
  • Verify kind 13194 event published on relay
  • Existing CLINK/Ndebit flows still work (no regressions)

🤖 Generated with Claude Code

## Summary - Adds NIP-47 (Nostr Wallet Connect) protocol support alongside the existing CLINK/Ndebit system - Enables any NWC-compatible wallet (Alby, Amethyst, Damus, etc.) to connect to a Lightning Pub node - Implements 6 NIP-47 methods: `pay_invoice`, `make_invoice`, `get_balance`, `get_info`, `lookup_invoice`, `list_transactions` - Publishes kind 13194 info events advertising supported NWC methods ## Architecture NWC fits into the existing event routing architecture. NWC clients send kind 23194 requests addressed to the app's existing Nostr pubkey via `#p` tag, so no new relay subscriptions are needed. The connection URI uses the app's pubkey and a random `secret` that becomes the client's private key. The wallet identifies connections by the client's derived pubkey stored in a new `NwcConnection` table. **Key design decisions:** - Reuses app's existing Nostr keypair — no separate NWC keypairs needed - NIP-44 v2 encryption only (already supported in codebase) - All amounts converted at boundary: NIP-47 uses msats, internal system uses sats - Budget enforcement via `max_amount` and `total_spent` per connection ## New files - `src/services/storage/entity/NwcConnection.ts` — TypeORM entity - `src/services/storage/migrations/1770000000000-nwc_connection.ts` — DB migration - `src/services/storage/nwcStorage.ts` — Storage layer for connection CRUD - `src/services/main/nwcManager.ts` — Core NIP-47 handler ## Modified files - `src/services/nostr/nostrPool.ts` — Subscribe to kind 23194 events - `src/nostrMiddleware.ts` — Route kind 23194 to NwcManager - `src/services/main/index.ts` — Wire NwcManager, publish kind 13194 info - `src/services/storage/db/db.ts` — Register NwcConnection entity - `src/services/storage/index.ts` — Wire NwcStorage - `src/services/storage/migrations/runner.ts` — Register migration ## Test plan - [ ] `tsc` compiles with zero errors - [ ] App startup auto-runs the migration and creates `nwc_connection` table - [ ] Create an NWC connection via `nwcManager.createConnection()` - [ ] Copy `nostr+walletconnect://...` URI into NWC-compatible wallet (e.g., Alby) - [ ] Send `get_balance` request → returns user balance in msats - [ ] Send `pay_invoice` request → pays from user balance, returns preimage - [ ] Send `make_invoice` request → creates invoice for user - [ ] Verify kind 13194 event published on relay - [ ] Existing CLINK/Ndebit flows still work (no regressions) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
padreug added 1 commit 2026-02-25 16:30:42 +00:00
Add NIP-47 (Nostr Wallet Connect) support
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
f1d0c521b8
Implements NWC protocol alongside the existing CLINK/Ndebit system,
allowing any NWC-compatible wallet (Alby, Amethyst, Damus, etc.) to
connect to a Lightning Pub node.

Supported NIP-47 methods: pay_invoice, make_invoice, get_balance,
get_info, lookup_invoice, list_transactions.

New files:
- NwcConnection entity with per-connection spending limits
- NwcStorage for connection CRUD operations
- NwcManager for NIP-47 request handling and connection management
- Database migration for nwc_connection table

Modified files:
- nostrPool: subscribe to kind 23194 events
- nostrMiddleware: route kind 23194 to NwcManager
- main/index: wire NwcManager, publish kind 13194 info events
- storage: register NwcConnection entity and NwcStorage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
padreug force-pushed feature/nip47-nwc-support from f1d0c521b8 to 52d727e6c5 2026-03-04 20:23:13 +00:00 Compare
padreug force-pushed feature/nip47-nwc-support from 52d727e6c5 to 6037dbe600 2026-03-26 22:46:08 +00:00 Compare
padreug force-pushed feature/nip47-nwc-support from 6037dbe600 to 5a26676a24 2026-04-02 19:10:35 +00:00 Compare
padreug changed target branch from master to dev 2026-04-02 19:10:43 +00:00
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/nip47-nwc-support:feature/nip47-nwc-support
git checkout feature/nip47-nwc-support

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feature/nip47-nwc-support
git checkout feature/nip47-nwc-support
git rebase dev
git checkout dev
git merge --ff-only feature/nip47-nwc-support
git checkout feature/nip47-nwc-support
git rebase dev
git checkout dev
git merge --no-ff feature/nip47-nwc-support
git checkout dev
git merge --squash feature/nip47-nwc-support
git checkout dev
git merge --ff-only feature/nip47-nwc-support
git checkout dev
git merge feature/nip47-nwc-support
git push origin dev
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: aiolabs/lightning-pub#8
No description provided.