Skip to content

Nip47 notifications#30

Open
DoktorShift wants to merge 23 commits into
lnbits:mainfrom
DoktorShift:nip47_notifications
Open

Nip47 notifications#30
DoktorShift wants to merge 23 commits into
lnbits:mainfrom
DoktorShift:nip47_notifications

Conversation

@DoktorShift

Copy link
Copy Markdown

Added support for it.

  • Publishing info event with notifications tag
  • Added notifications to selectable permissions
  • Full support of handeling notification events
  • Backfall for polling if notification event not implemented by client app

Its the part of nwc service provider extension.

nwc funding source needs it in addition to support the spec as well and reduce potential load on server. Requested here:

lnbits/lnbits#3187

DoktorShift and others added 17 commits March 25, 2026 18:30
- Auto-format with black, ruff --fix, prettier
- Fix ruff C901: extract _notify_payment_sent helper to reduce complexity
- Fix ruff RUF059: prefix unused unpacked variable with underscore
- Add noqa: E402 for intentional late imports in standalone test mocks
- Fix pyright: add None guard on payment_status.success
- Fix mock parameter names to match send_notification signature
Standalone notification tests use heavy sys.modules patching to run
without lnbits installed. Exclude them from mypy/pyright since static
type checking cannot follow dynamic module injection.

Also add type ignore for optional lnurlp extension import.
Standalone test files with sys.modules mocking cause mypy "found twice"
errors when in the main package tree. Moving to tests/standalone/
(no __init__.py) prevents mypy from discovering them as package modules.

Also update pyright exclude and fix PROJECT_DIR paths.
- Re-run black/ruff/prettier after rebase
- Move standalone tests to tests/standalone/ (no __init__.py) to prevent
  mypy "found twice" module discovery conflict
- Exclude tests/standalone/ from mypy and pyright
- Fix PROJECT_DIR paths for new location
@DoktorShift DoktorShift force-pushed the nip47_notifications branch from 1324bd0 to c333590 Compare March 25, 2026 17:33
Our lock had mypy 1.19.1 which crashes on pydantic v1 env_settings.
Main uses mypy 1.17.1 which works correctly.
Adding pyrightconfig.json changed pyright's project resolution,
causing it to scan node_modules typeshed stubs. Without the config
file, pyright uses the lnbits shared CI workflow defaults which work.
These files use heavy sys.modules patching that pyright cannot follow.
Inline directives suppress the expected errors without needing a
pyrightconfig.json (which changes pyright's project resolution).
The pairing URL now encodes the relay with quote(), but the test
NWCWallet client was using the encoded value directly to connect,
causing 'scheme isn't ws or wss' errors.
@DoktorShift DoktorShift marked this pull request as ready for review March 25, 2026 23:25
@BenGWeeks

Copy link
Copy Markdown

subbed

@satwise

satwise commented May 3, 2026

Copy link
Copy Markdown

I support this PR to provide the most robust LNbits NIP support possible to keep pace with Nostr's robust growth. This also compliments #38 and lnbits/nostrrelay#44 for LNbits Nostr Relay extension, fixing a patch of NostrClient as current gap within the platform for Nostr for LNBits Paid Relays needed for AI agents to subscribe to a subdomains and charge each agent user (assuming all PRs are implemented)

image

With all PR's implemented, the LNbits platform can finally boast a robust, modern Nostr Relay / NWC Provider pairing for the Agent AI Economy

@talvasconcelos

Copy link
Copy Markdown

I'm not familiar with NWC!

Can you please add some testing steps so i can test it?

@DoktorShift

Copy link
Copy Markdown
Author

Hey @talvasconcelos, one way to test:

  1. Install/enable the extension and configure a relya that supports NWC notifications for sure (and can be observed publicly by u), for example wss://relay.getalby.com/v1. Alternatively, you can also use the LNbits Nostr client extension to observe the emitted events but i am using the alby relay for now.

  2. Create an NWC connection. Keep the new Receive payment notifications permission checked and copy the connection string.

  3. Look up the connection’s service pubkey and confirm that the kind 13194 info event contains this tag:

    ["notifications", "payment_received payment_sent"]
  4. Paste the connection string into a NIP-47-aware client that supports notifications fir sure, for example Alby Wallet.

  5. Receive test: pay the LNbits wallet from anywhere. Alby should show a payment received event.

  6. Send test: create a second connection on the same wallet, then send a payment from Alby Hub using connection 1. Connection 2 should receive a payment sent toast.

  7. Negative test: create a connection with the notifications permission unchecked. No toast should arrive.

You can verify directly on the relay by watching for kind 23196 events from the services pubkey.

@talvasconcelos

Copy link
Copy Markdown

didn't fully tested, but it seems to do what it intends to do

- resolve tasks.py conflict (align with upstream lnbits#43)
- restore poetry.lock
BenGWeeks added a commit to LightningPiggy/lightning-piggy-mobile that referenced this pull request Jun 11, 2026
Closer the gap vs. WoS by polling the SPECIFIC invoice's settled state
via NIP-47 \`lookup_invoice\` rather than polling wallet-wide balance:

- LNbits flips \`settled_at\` the instant LND signals settle — no wait
  for balance aggregation / cache propagation.
- Targeted request (one invoice) vs. balance roll-up (full wallet
  totals) — lighter and less prone to slow responses on busy backends.
- On settle, fall through to a one-shot \`refreshBalanceForWallet\`
  call so the WalletContext diff-detector still fires the overlay —
  single source of truth for "balance went up ⇒ celebrate".
- Poll cadence tightened 1500 ms → 1000 ms (lookup_invoice is a
  lighter request than get_balance on most backends).
- Fallback to balance polling retained for the rare case where the
  bolt11 doesn't yield an extractable payment_hash.

Remaining gap vs. WoS is architectural: WoS talks to its own LN node
directly with push/subscription; we go through LNbits + NWC + a Nostr
relay, so there's always some round-trip floor. The remaining
cure-all is NIP-47 notifications (tracked: lnbits/nwcprovider#30).

Also restrict amount inputs in Send and Receive sheets to digits only
(sats) or digits + single decimal (fiat). Hardware keyboards, paste,
and autocomplete can bypass the soft-keyboard numeric hint and inject
junk characters that caused silent "Invalid amount" rejections.

Co-Authored-By: Claude Opus 4.7 (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.

5 participants