NWC Improvements#42
Conversation
|
Warning Review limit reached
More reviews will be available in 21 minutes and 16 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe PR adds Lightning Address support for NWC nodes, including LNURL-verify checks, structured NWC/NIP-47 error types, and updated request/error handling in both TypeScript and Rust. It also updates tests and package versions. ChangesNWC Lightning Address and Error Handling
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 26b40ebacd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
bindings/typescript/src/__tests__/nwc.test.ts (1)
127-140: 💤 Low valueConsider consolidating duplicate payInvoice calls.
The test makes two separate calls to
makeNode().payInvoice()with different assertions. This could be refactored to capture the rejection once:- await expect(makeNode().payInvoice({ invoice: BOLT11_INVOICE })).rejects.toMatchObject({ - name: 'NwcError', - code: 'NwcError', - nwcCode: 'QUOTA_EXCEEDED', - nwcMessage: 'quota spent', - operation: 'pay_invoice', - message: 'quota spent', - }); - - await expect(makeNode().payInvoice({ invoice: BOLT11_INVOICE })).rejects.toBeInstanceOf(NwcError); + const error = await makeNode().payInvoice({ invoice: BOLT11_INVOICE }).catch(e => e); + + expect(error).toMatchObject({ + name: 'NwcError', + code: 'NwcError', + nwcCode: 'QUOTA_EXCEEDED', + nwcMessage: 'quota spent', + operation: 'pay_invoice', + message: 'quota spent', + }); + expect(error).toBeInstanceOf(NwcError);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bindings/typescript/src/__tests__/nwc.test.ts` around lines 127 - 140, Call makeNode().payInvoice(...) only once and reuse that rejected promise for both assertions: assign the result of makeNode().payInvoice({ invoice: BOLT11_INVOICE }) to a variable (e.g., rejectedPromise) after configuring nwcMocks.payInvoice to throw the Nip47Error, then await expect(rejectedPromise).rejects.toMatchObject({...}) and await expect(rejectedPromise).rejects.toBeInstanceOf(NwcError). Keep references to makeNode, payInvoice, NwcError, nwcMocks.payInvoice, and nwcMocks.Nip47Error to locate the code to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bindings/typescript/src/lnurl.ts`:
- Around line 397-400: The current check treats empty strings for maybeVerify.pr
and maybeVerify.verify as valid because it only tests typeof, leading to
downstream URL parsing errors instead of throwing LnurlVerifyUnsupportedError;
update the validation in the handler that casts callbackResponse to
Partial<LnurlVerifyInvoiceResponse> (the maybeVerify variable) to additionally
ensure both maybeVerify.pr and maybeVerify.verify are non-empty (e.g., check
they are strings with length > 0 or trim() !== '') and throw
LnurlVerifyUnsupportedError() when either is missing/empty so empty values are
normalized as unsupported verify responses.
In `@bindings/typescript/src/nodes/nwc.ts`:
- Around line 169-186: The current getLightningAddress implementation swallows
all errors from verifyLightningAddressPayRequest and returns
lnurlVerifySupported: false; change it to only treat LnurlVerifyUnsupportedError
as "unsupported" while letting genuine failures propagate: call
verifyLightningAddressPayRequest (from bindings/typescript/src/lnurl.ts) and
catch exceptions only of type LnurlVerifyUnsupportedError to set
lnurlVerifySupported = false, but rethrow any other errors (e.g. instances of
LniError or unknown errors) so they surface to the caller; keep the existing
extraction via extractLightningAddressFromNwcUri and preserve passing
this.options.fetch to the verify call.
In `@crates/lni/lnurl/mod.rs`:
- Around line 266-290: The code in verify_lightning_address_pay_request
currently fetches URLs derived from untrusted LNURL data (via
lightning_address_to_url, well_known.callback and verify_response.verify) using
fetch_lnurl_pay and fetch_lnurl_json_value without validating them first; add
strict URL validation before any outbound fetch: parse each URL (the URL
produced by lightning_address_to_url, the callback URL built by
callback_url_with_amount(&well_known.callback, …), and verify_response.verify),
ensure the scheme is https, reject IP-literal hosts or resolve the hostname and
verify the resolved addresses are not loopback/private/RFC1918/cloud metadata
ranges, or apply a safe-host allowlist; perform these checks in
verify_lightning_address_pay_request immediately before calling fetch_lnurl_pay
and before each fetch_lnurl_json_value, returning ApiError::InvalidInput on
failure.
---
Nitpick comments:
In `@bindings/typescript/src/__tests__/nwc.test.ts`:
- Around line 127-140: Call makeNode().payInvoice(...) only once and reuse that
rejected promise for both assertions: assign the result of
makeNode().payInvoice({ invoice: BOLT11_INVOICE }) to a variable (e.g.,
rejectedPromise) after configuring nwcMocks.payInvoice to throw the Nip47Error,
then await expect(rejectedPromise).rejects.toMatchObject({...}) and await
expect(rejectedPromise).rejects.toBeInstanceOf(NwcError). Keep references to
makeNode, payInvoice, NwcError, nwcMocks.payInvoice, and nwcMocks.Nip47Error to
locate the code to change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 633a7b89-7db4-4e44-ae1b-be6f8a9fa097
📒 Files selected for processing (9)
bindings/typescript/src/__tests__/nwc.test.tsbindings/typescript/src/errors.tsbindings/typescript/src/lnurl.tsbindings/typescript/src/nodes/nwc.tsbindings/typescript/src/types.tscrates/lni/lib.rscrates/lni/lnurl/mod.rscrates/lni/nwc/api.rscrates/lni/nwc/lib.rs
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
bindings/typescript/src/nodes/nwc.ts (1)
240-256: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winDo not hide
get_infotimeouts after closing the client.A
get_infotimeout closesthis.clientinwithTimeout, but the broad catch returns fallback node info as if the call succeeded, leaving theNwcNodesilently unusable for later operations.Proposed fix
- } catch { + } catch (error) { + if (error instanceof LniError && error.code === 'NetworkError') { + throwNwcOrApiError(error, 'get_info', 'Failed to get info'); + } + return emptyNodeInfo({ alias: 'NWC Node', pubkey: pubkeyFallback,Also applies to: 503-511
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@bindings/typescript/src/nodes/nwc.ts` around lines 240 - 256, The broad catch in NwcNode’s get info flow is swallowing executeNip47Request/get_info timeout failures and returning emptyNodeInfo, which hides that this.client may have been closed by withTimeout. Update the try/catch around executeNip47Request in the NwcNode method (and the similar fallback block in the other referenced location) to detect timeout/closed-client failures and surface them instead of silently mapping to fallback node info. Keep fallback node info only for non-fatal cases, and preserve the error path so callers know the NwcNode is no longer usable after a timeout.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bindings/typescript/src/nodes/nwc.ts`:
- Around line 55-57: The LniError rewrap in nwc.ts is dropping structured
metadata, so update the error translation path to preserve the original status
and body when `error instanceof LniError` before throwing the new `LniError`.
Keep the existing `code` and `cause` behavior in the `LniError` construction,
and ensure the rethrown error carries through all original HTTP/API context
fields from the incoming `error` object.
---
Outside diff comments:
In `@bindings/typescript/src/nodes/nwc.ts`:
- Around line 240-256: The broad catch in NwcNode’s get info flow is swallowing
executeNip47Request/get_info timeout failures and returning emptyNodeInfo, which
hides that this.client may have been closed by withTimeout. Update the try/catch
around executeNip47Request in the NwcNode method (and the similar fallback block
in the other referenced location) to detect timeout/closed-client failures and
surface them instead of silently mapping to fallback node info. Keep fallback
node info only for non-fatal cases, and preserve the error path so callers know
the NwcNode is no longer usable after a timeout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d005a7a7-2005-4238-874d-21e9dcda0821
⛔ Files ignored due to path filters (4)
bindings/typescript-arkade/package-lock.jsonis excluded by!**/package-lock.jsonbindings/typescript-spark/examples/spark-expo-go/package-lock.jsonis excluded by!**/package-lock.jsonbindings/typescript-spark/package-lock.jsonis excluded by!**/package-lock.jsonbindings/typescript/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (6)
bindings/typescript-arkade/package.jsonbindings/typescript-spark/package.jsonbindings/typescript/package.jsonbindings/typescript/src/__tests__/integration/nwc.real.test.tsbindings/typescript/src/__tests__/nwc.test.tsbindings/typescript/src/nodes/nwc.ts
✅ Files skipped from review due to trivial changes (3)
- bindings/typescript/package.json
- bindings/typescript-arkade/package.json
- bindings/typescript/src/tests/integration/nwc.real.test.ts
Summary by CodeRabbit
getLightningAddress()NwcErrorcodes/messages and operation context