Skip to content

Add basic NWC fixes and lud16 support#4005

Open
advorzhak wants to merge 65 commits intoZeusLN:masterfrom
advorzhak:nwc-m1-basic
Open

Add basic NWC fixes and lud16 support#4005
advorzhak wants to merge 65 commits intoZeusLN:masterfrom
advorzhak:nwc-m1-basic

Conversation

@advorzhak
Copy link
Copy Markdown

Description

Relates to issue: ZEUS-4003

This PR implements the first NWC milestone:

  • fixes a few core NIP-47 response/service compatibility issues
  • adds lud16 support to generated NWC URIs when Zeus has an active Lightning Address
  • adds a create-time toggle so users can choose whether to include lud16

This pull request is categorized as a:

  • New feature
  • Bug fix
  • Code refactor
  • Configuration change
  • Locales update
  • Quality assurance
  • Other

Checklist

  • I’ve run yarn run tsc and made sure my code compiles correctly
  • I’ve run yarn run lint and made sure my code didn’t contain any problematic patterns
  • I’ve run yarn run prettier and made sure my code is formatted correctly
  • I’ve run yarn run test and made sure all of the tests pass

Testing

If you modified or added a utility file, did you add new unit tests?

  • No, I’m a fool
  • Yes
  • N/A

I have tested this PR on the following platforms (please specify OS version and phone model/VM):

  • Android
  • iOS

I have tested this PR with the following types of nodes (please specify node version and API version where appropriate):

On-device

  • LDK Node
  • Embedded LND

Remote

  • LND (REST)
  • LND (Lightning Node Connect)
  • Core Lightning (CLNRest)
  • Nostr Wallet Connect
  • LndHub

Locales

  • I’ve added new locale text that requires translations
  • I’m aware that new translations should be made on the ZEUS Transfix page and not directly to this repo

Third Party Dependencies and Packages

  • Contributors will need to run yarn after this PR is merged in
  • 3rd party dependencies have been modified:
    • verify that package.json and yarn.lock have been properly updated
    • verify that dependencies are installed for both iOS and Android platforms

Other:

  • Changes were made that require an update to the README
  • Changes were made that require an update to onboarding

Testing Notes

Commands run locally:

  • ./node_modules/.bin/tsc --noEmit
  • ./node_modules/.bin/jest utils/NostrWalletConnectUrlUtils.test.ts --runInBand
  • ./node_modules/.bin/jest utils --runInBand --testPathIgnorePatterns=check-styles.test.ts

Notes:

  • Utility coverage passed, including the new NWC URL helper tests.
  • Mobile/manual device validation has not been completed yet.

@advorzhak
Copy link
Copy Markdown
Author

Tracking issue: #4003

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs and expands support for several NIP-47 methods, including get_info, get_balance, make_invoice, lookup_invoice, list_transactions, and sign_message. Key changes include updates to the NWC connection model, the addition of a URL builder utility with associated tests, and UI enhancements to toggle the inclusion of the Lightning Address. Feedback focuses on improving error handling and permission enforcement within NostrWalletConnectStore.ts. Specifically, it is noted that throwing errors during event validation may lead to silent failures, and several newly added methods lack consistent permission checks or use misleading error messages when access is restricted.

Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
@advorzhak
Copy link
Copy Markdown
Author

advorzhak commented Apr 20, 2026

Addressed all open review comments in this PR.

  1. validateAndParsePendingEvent permission check / silent failure concern
  • Removed the early permission check from validateAndParsePendingEvent so requests are no longer rejected there.
  • Permission enforcement is now handled in handleEventRequest, which always builds/publishes an NWC error response (instead of dropping events during pending validation).
  1. Missing permission checks for get_info and get_balance
  • Added explicit permission checks for both methods in handleEventRequest.
  • Unauthorized calls now return RESTRICTED + permissionDenied.
  1. Misleading methodNotImplemented message for authorization failures
  • Replaced methodNotImplemented with backends.NWC.permissionDenied for authorization failures in:
    • pay_invoice
    • make_invoice
    • lookup_invoice
    • list_transactions
    • sign_message
  • These now consistently return RESTRICTED for denied permissions.

Validation done:

  • TypeScript check passes: npm run -s tsc -- --noEmit (exit 0).

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs. Key changes include adding a UI toggle in the connection settings, updating the NWC connection models and stores to persist this preference, and implementing a utility for constructing the connection string. Furthermore, the NWC request handling logic was refactored to improve permission validation across multiple methods and standardize error reporting with a new RESTRICTED error code. Unit tests for the URL construction utility were also included. I have no feedback to provide as there were no review comments to evaluate.

@advorzhak advorzhak marked this pull request as ready for review April 20, 2026 21:27
Copilot AI review requested due to automatic review settings April 20, 2026 21:27
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the option to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs. Key changes include the addition of a new utility for building NWC URLs, updates to the NWC connection model and store to support the includeLightningAddress flag, and UI enhancements in the connection settings to toggle this feature. Furthermore, the NostrWalletConnectStore has been expanded to support additional NIP-47 methods—such as get_info, get_balance, make_invoice, lookup_invoice, list_transactions, and sign_message—complete with permission checks and a new RESTRICTED error code. I have no feedback to provide.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the first Nostr Wallet Connect (NWC) milestone by improving NIP-47 compatibility and adding optional lud16 (Lightning Address) support to generated NWC connection URLs.

Changes:

  • Add includeLightningAddress toggle to NWC connection creation UI and persist it on connections.
  • Introduce a shared NWC URL builder utility that conditionally appends lud16, with unit tests.
  • Improve NWC request handling by returning standardized permission-denied errors and adjusting response event tags.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Adds create-time UI toggle and persists includeLightningAddress into connection params/state.
utils/NostrWalletConnectUrlUtils.ts New helper to build nostr+walletconnect:// URLs with optional lud16.
utils/NostrWalletConnectUrlUtils.test.ts Unit tests for the URL builder (with/without/blank lud16).
utils/NostrConnectUtils.ts Updates advertised NWC notifications list (now empty).
stores/NostrWalletConnectStore.ts Uses URL builder, persists includeLightningAddress, and standardizes permission-denied errors/tags.
models/NWCConnection.ts Adds includeLightningAddress field to the connection model/data interface.
locales/en.json Adds strings for the new “Include Lightning Address” setting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.ts
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread models/NWCConnection.ts Outdated
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Comment thread stores/NostrWalletConnectStore.ts
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs. It adds a toggle in the connection creation/edit view, updates the connection data models and storage logic to persist this preference, and implements a utility for building the connection URL with the optional lud16 parameter. Additionally, the NWC request handling logic was refactored to include permission checks for several methods (get_info, get_balance, etc.) and return a specific RESTRICTED error code when access is denied. I have no feedback to provide.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for including Lightning Addresses (lud16) in Nostr Wallet Connect (NWC) connection URLs. It updates the NWC connection model, introduces a dedicated URL builder utility with unit tests, and refactors the NostrWalletConnectStore to handle new NWC methods and permission checks. The UI now features a toggle for users to include their Lightning Address when creating connections. Review feedback suggests returning a failure status when a connection URL cannot be regenerated due to missing keys, ensuring the pay_invoice handler supports zero-amount invoices as per NIP-47, and refactoring duplicated logic used to check for active lightning addresses.

Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.ts
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Comment thread stores/NostrWalletConnectStore.ts
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for including Lightning Addresses (lud16) in Nostr Wallet Connect (NWC) connection URLs and expands the supported NWC methods to include get_info, get_balance, and make_invoice, among others. The changes include updates to the NWC connection model, a new URL builder utility, and UI enhancements for managing connection settings. Feedback identifies a potential precision loss when converting millisatoshis to satoshis for zero-amount invoices and recommends exposing the Lightning Address toggle in the edit view to improve user flexibility.

Comment thread stores/NostrWalletConnectStore.ts
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs. It adds a new setting in the connection creation and edit views, updates the data models and stores to persist this preference, and implements a utility for building the connection URL. Furthermore, the PR expands NWC functionality by supporting several new methods, including get_info, get_balance, and make_invoice, while refining error handling and permission checks. Review feedback suggests refactoring duplicated lud16 derivation logic, improving type safety by replacing 'any' with specific interfaces, and consolidating repeated permission checks within the request processing logic.

Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.ts
Comment thread stores/NostrWalletConnectStore.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the option to include a Lightning Address (lud16) in Nostr Wallet Connect (NWC) connection URLs. Key changes include updates to the NWC connection model, store, and UI to support this feature, along with a new utility for URL construction. The PR also improves NIP-47 method handling by implementing permission checks for several methods and refining event tagging. Feedback was provided to address indentation inconsistencies in a switch block and to simplify the logic for initializing the Lightning Address toggle state.

Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread views/Settings/NostrWalletConnect/AddOrEditNWCConnection.tsx Outdated
advorzhak and others added 9 commits April 22, 2026 23:52
…essages

- Replace .includes() with exact match: tag[1] === 'nip44_v2'
- Add validation that encryptionTag[1] is a string
- Add schema validation with validSchemes array
- Improve error detection: log which scheme was attempted
- Add diagnostic info to decryption error messages
- Include test cases for encryption scheme detection

The changes address the following test scenarios:
  • Event with encryption='nip44_v2' → uses nip44_v2
  • Event with encryption='nip04' → uses nip04
  • Event with encryption='invalid' → fallback to nip04 (with warning)
  • Event with missing encryption tag → fallback to nip04
  • Event with encryption='NIP44_V2' (uppercase) → normalize and match
  • Non-string encryption values → reject with warning

Reference: FINAL_REVIEW_SYNTHESIS.md HIGH-PRIORITY MEDIUM-1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add MAX_ACTIVITY_ITEMS constant (1000) to prevent memory growth
- Implement addActivity() method with rotation logic using shift()
- Remove oldest item when reaching capacity, preventing unbounded arrays
- Update all activity.push() calls in NostrWalletConnectStore to use new method
- Add comprehensive test coverage for rotation behavior
- Limit rationale: ~100 payments at current velocity (~10/day) before rotation

This ensures that activity history remains bounded and prevents potential OOM
issues while maintaining recent transaction visibility.

Reference: FINAL_REVIEW_SYNTHESIS.md medium-priority ACTIVITY-OVERFLOW

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ment ID

- Add generatePaymentHashFallback() method with millisecond precision
- Format: timestamp-paymentIdPrefix-randomSuffix (or timestamp-randomSuffix if no ID)
- Includes payment ID prefix (first 8 chars) for correlation with wallet tracking
- Ensures unique hashes with millisecond-level precision
- Applied to make_invoice and lookup_invoice handlers
- Includes fallback in finalizePayment() for activity tracking
- Backwards compatible with existing payment hash flows

Resolves FINAL_REVIEW_SYNTHESIS.md: PAYMENT-HASH-UNIQUENESS medium-priority issue
Reference: Fallback hash collision detection and millisecond precision improvements

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tion list

Add clarifying comment explaining why 'hold_invoice_accepted' was removed from the
notification types supported by NIP-47 M1. The removal is intentional as the M1 spec
focuses only on core payment operations.

Reference: FINAL_REVIEW_SYNTHESIS.md - low-priority documentation improvement

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Auto-enable includeLightningAddress for existing connections that have lud16 set
- Smoother UX: users don't need to manually re-toggle the flag
- Respects explicit false values (doesn't override user preference)
- Helps migrate existing connections to new Lightning Address feature

Reference: FINAL_REVIEW_SYNTHESIS.md low-priority ZeusLN#10
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Removed: CLAUDE_REVIEW_FINDINGS.txt, CODE_REVIEW_INDEX.md, CODE_REVIEW.md
- Removed: FINAL_REVIEW_SYNTHESIS.md, FLEET_MODE_COMPLETION_SUMMARY.txt
- Removed: GPT_REVIEW_MANIFEST.txt, REVIEW_FINDINGS_STRUCTURED.txt
- Removed: REVIEW_OUTPUT_FILES.txt, REVIEW_SUMMARY.txt

Keep only actual code fixes and implementation changes in repository.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eftover

- Restored: CODE_REVIEW.md from commit 290d1b4 (original repo file)
- Removed: READ_ME_FIRST.txt (leftover file)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@advorzhak
Copy link
Copy Markdown
Author

@gemini-code-assist review

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.encryption.test.ts Outdated
Comment thread stores/SubSatoshiRounding.test.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread stores/NostrWalletConnectStore.ts Outdated
Comment thread utils/NostrWalletConnectUrlUtils.ts
Comment thread models/NWCConnection.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the Nostr Wallet Connect (NWC) implementation by adding NIP-44 encryption support, LUD-16 lightning address integration, and improved budget enforcement. Significant changes include refactoring the CLN backend for better fee and amount handling, implementing activity history limits to prevent memory growth, and ensuring NIP-47 specification compliance for method permissions and error codes. Review feedback identified critical type mismatches in the NIP-44 encryption logic where hex strings were passed instead of the required byte arrays for conversation key generation, which would result in runtime errors.

Comment thread stores/NostrWalletConnectStore.ts
Comment thread stores/NostrWalletConnectStore.ts
advorzhak and others added 4 commits April 23, 2026 00:34
Ensures toNip47ErrorCode() can properly map error types that were already
being thrown at runtime (line 3655) but missing from the enum definition.
This fixes NWC clients receiving raw Error strings instead of proper
NIP-47 error responses.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Rejects leading/trailing hyphens in domain segments (DNS compliance)
- Ensures each domain label starts and ends with alphanumeric characters
- Hyphens only allowed in middle of labels
- Rejects: user@-example.com, user@example.-com, user@example-.com
- Accepts: user@example.com, alice@sub.example.org, test@my-domain.co.uk
- Added comprehensive test cases for DNS-compliant validation

Reference: Multi-review blocker ZeusLN#2

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Change condition from '!normalizedData.includeLightningAddress' to '=== undefined'
- Prevents overwriting explicit false values when lud16 metadata is present
- Allows explicit user preference to persist
- Fixes failing test: NWCConnection.test.ts line 84

Reference: Multi-review critical findings
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ix comments, update JSDoc

- Add localized error key 'stores.NostrWalletConnectStore.error.invalidRelayUrl' for relay validation failures
- Replace hard-coded relay URL error messages with localized key in both createConnection() and updateConnection()
- Fix MAX_ACTIVITY_ITEMS comment to accurately reflect 1000-item limit with FIFO rotation (not ~100 archived)
- Fix fee_limit_msat comment to correctly document Math.floor behavior (not Math.ceil)
- Remove incorrect @throws from validateRelayUrl JSDoc (returns false, doesn't throw)
- Ensure error messages are translatable across all 27 locale files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stores/NostrWalletConnectStore.encryption.test.ts Outdated
Comment thread models/NWCConnection.ts Outdated
Comment thread utils/NostrWalletConnectUrlUtils.ts
advorzhak and others added 8 commits April 23, 2026 07:56
The normalizeNWCConnectionData function had a logic error where:
1. Line 89 set includeLightningAddress to false using ?? operator
2. Line 95 then checked if it was === undefined (never true)
3. Result: auto-migration from lud16 metadata never occurred

Fix:
- Check includeLightningAddress from source BEFORE spreading
- Apply defaults and fallback logic in correct order
- Ensures lud16 values in metadata properly enable includeLightningAddress

All 25 NWCConnection tests now pass:
✅ Auto-migration tests fixed (were failing)
✅ Budget tracking tests pass
✅ Activity rotation tests pass
✅ Race condition handling tests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GPT-5.4 code review identified blocker: msat→sat conversion was using
Math.ceil which OVERCHARGES users on non-whole-sat amounts.

Spec & tests require Math.floor:
- 1500 msat should become 1 sat (not 2 sat)
- 1001 msat should become 1 sat (not 2 sat)
- Fee limit is hard ceiling (must not exceed) ✅ uses floor
- Payment amount must not overcharge (must not exceed) ✅ now uses floor

Changes:
- pay_invoice: Math.ceil → Math.floor
- getInvoiceAmount: Math.ceil → Math.floor
- Updated comments from 'rounded UP' to 'truncated DOWN'
- Updated warning logs to show truncation, not overpayment

All 11 SubSatoshiRounding tests pass ✅
All 25 NWCConnection tests pass ✅

This is a critical user-facing fix preventing unauthorized overcharges.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Removed PR_4005_COMPREHENSIVE_REVIEW.md
- Removed PR_4005_REVIEW_INDEX.md
- Removed PR_4005_REVIEW_SUMMARY.md
- Removed PR_4005_TECHNICAL_DEEP_DIVE.md
- Removed other analysis docs and review artifacts

Keep PR clean with only code changes and spec-compliant implementation.
Review documentation stored in session checkpoints for internal reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review threads 3127253368 and 3127010174 by rewriting the encryption tests to call NostrWalletConnectStore's real helper methods instead of duplicating their logic.
Address review thread 3127010219 by rewriting the rounding tests to exercise getInvoiceAmount and handleLightningPayInvoice, including fee_limit_msat precedence and sub-satoshi truncation behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ssues

BLOCKERS (Fixed):
- Sub-satoshi payments (1-999 msat) now properly handled as 0 sats instead of rejected
  (stores/NostrWalletConnectStore.ts:2104-2118)
- LUD-16 validation now accepts valid +tag aliases (user+tag@domain format)
  (utils/NostrWalletConnectUrlUtils.ts:15-22)

HIGH Priority (Fixed):
- Replaced unsafe error casting with proper Error type normalization
  (stores/NostrWalletConnectStore.ts:556-565)

MEDIUM Priority (Fixed):
- Added regression tests for <1000 msat boundary cases
  (stores/SubSatoshiRounding.test.ts:253-271)
- Added regression tests for LUD-16 +tag acceptance
  (utils/NostrWalletConnectUrlUtils.test.ts:173-193)

LOW Priority (Fixed):
- Updated stale comments describing Math.ceil behavior to reflect Math.floor
  (stores/NostrWalletConnectStore.ts:2204-2213, 2641-2664)

Test Results:
- 807/807 tests passing ✅
- TypeScript clean ✅
- All regression tests passing ✅

Fixes address findings from Claude Opus 4.7 + GPT-5.4 multi-review synthesis.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CRITICAL Issues Fixed:
1. Sub-satoshi budget bypass (GPT-5.4 finding)
   - Sub-satoshi amounts (1-999 msat) were flooring to 0 sats and bypassing budget checks
   - Now charge at least 1 sat to budget for any positive msat request
   - Budget enforcement: min(amountSats, 1) when flooring reduces to 0
   - Locations: stores/NostrWalletConnectStore.ts:2149-2158, 2743-2745

2. LUD-16 validation allows invalid formats (GPT-5.4 finding)
   - Was accepting consecutive dots (e.g., user..name@domain)
   - Now rejects: consecutive dots, leading dots, trailing dots
   - Validation tightened with explicit checks
   - Location: utils/NostrWalletConnectUrlUtils.ts:15-29

Changes:
- calculatebudgetChargeAmountSats in handleLightningPayInvoice to ensure budget enforcement
- Tightened LUD-16 regex to prevent malformed local parts
- Added validation checks for dot positions
- Updated finalizePayment to accept budgetChargeAmountSats parameter
- Added 3 new LUD-16 edge case tests (consecutive dots, leading/trailing dots)

Tests:
- 810/810 passing (3 new tests)
- LUD-16 validation: 18 test cases
- Sub-satoshi rounding: 7 test cases
- TypeScript: clean

This addresses critical findings from multi-review synthesis (GPT-5.4 was correct about the budget bypass vulnerability).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.

3 participants