-
Notifications
You must be signed in to change notification settings - Fork 216
feat(webln): support Lightning Addresses in sendPayment #3477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(webln): support Lightning Addresses in sendPayment #3477
Conversation
📝 WalkthroughWalkthroughThe change adds LNURL Lightning address support to payment request handling, enabling resolution of Lightning addresses alongside existing Bolt11 decoding, with comprehensive error handling and conditional payment routing based on decoded payment details. Changes
Sequence DiagramsequenceDiagram
participant User as Payment Request<br/>Input
participant Handler as sendPaymentOrPrompt<br/>Handler
participant LNURL as LNURL<br/>Resolver
participant Decoder as Bolt11<br/>Decoder
participant Router as Payment<br/>Router
User->>Handler: Payment Request (address/bolt11)
alt Is Lightning Address
Handler->>LNURL: Resolve LNURL
alt Resolution Success
LNURL-->>Handler: Payment Details
Handler->>Handler: Check Detail Tag
alt Tag is "payRequest"
Handler->>Router: Route to lnurlPayWithPrompt
else Other Tag
Handler-->>User: Error Response
end
else Resolution Failure
LNURL-->>Handler: Error
Handler-->>User: "Failed to resolve<br/>Lightning Address"
end
else Is Bolt11
Handler->>Decoder: Decode Bolt11
alt Decode Success
Decoder-->>Handler: Payment Details
Handler->>Handler: Check Allowance
alt Allowance OK
Handler->>Router: Route to sendPaymentWithAllowance
else No Allowance
Handler->>Router: Route to payWithPrompt
end
else Decode Failure
Decoder-->>Handler: Error
Handler-->>User: Error Message
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
|
@rolznz Whenever you have time, could you please take a look and let me know: if the approach looks okay, and if there are any changes or adjustments you’d like me to make. Thanks a lot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/extension/background-script/actions/webln/sendPaymentOrPrompt.ts`:
- Around line 44-51: The try/catch around lightningPayReq.decode in
sendPaymentOrPrompt currently only handles Error instances and leaves non-Error
throws to be swallowed, so change the catch to always return an error when
decode fails (e.g., return { error: String(e) } for any thrown value) and
optionally add a guard that paymentRequestDetails is defined before calling
payWithPrompt; locate lightningPayReq.decode, the paymentRequestDetails variable
and the later call to payWithPrompt in sendPaymentOrPrompt to implement this
consistent error-return behavior.
- Around line 29-41: The code currently returns a generic "Failed to resolve
Lightning Address" when lnurlDetails resolves but has a tag other than
"payRequest", which is misleading; update the logic in sendPaymentOrPrompt so
that after resolving lnurlDetails you explicitly handle unsupported tags by
returning a clear error (e.g., return { error: `Unsupported LNURL type:
${lnurlDetails.tag}` }) when lnurlDetails.tag exists but !== "payRequest", keep
the existing path that calls lnurlPayWithPrompt for "payRequest", and also
ensure the catch block handles non-Error throws by returning a safe generic
error if e is not an instance of Error.
Describe the changes you have made in this PR
This PR extends
window.webln.sendPayment()to support Lightning Addresses (e.g.alice@getalby.com) in addition to BOLT11 invoices.When a Lightning Address is detected, it is resolved via LNURL-pay to obtain an invoice, after which the existing payment flow continues unchanged. Invoice-based payments behave exactly as before.
This improves WebLN developer experience and enables simpler Value-for-Value integrations (e.g. RSS readers, blogs, tipping flows) without requiring developers to manually resolve Lightning Addresses.
A clear and concise description of what you want to happen
Allow websites to call
webln.sendPayment()with either:and have both work seamlessly and consistently.
Link this PR to an issue / bounty [optional]
Related bounty:
https://guides.getalby.com/developer-guide/bounties/alby-browser-extension-bounties#add-value-4-value-to-a-rss-reader
Type of change
Screenshots of the changes [optional]
N/A (no UI changes)
How has this been tested?
Manual testing with the Alby browser extension:
Tested
webln.sendPayment(<bolt11_invoice>)Tested
webln.sendPayment(<lightning_address>)Tested invalid Lightning Address input
Checklist
For UI-related changes
N/A
Screen.Recording.2026-01-26.at.10.41.25.PM.mov
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.