-
Notifications
You must be signed in to change notification settings - Fork 0
Release/0.1.4 #57
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
Release/0.1.4 #57
Conversation
- Added a method to generate a minimally valid BOLT11 invoice with proper Bech32 encoding for mock purposes. - This includes a checksum calculation and random data generation to simulate real invoice behavior.
- Introduce CLAUDE.md to provide comprehensive guidance for the phoenixd-java project, including build commands, module architecture, logging configuration, and testing notes.
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ 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".
| /** | ||
| * Generates a minimally valid BOLT11 invoice for testing purposes. | ||
| * Format: ln + currency + amount + separator + data + checksum | ||
| * | ||
| * This generates a mock invoice that passes basic Bech32 validation but is not | ||
| * cryptographically valid for actual Lightning Network payments. | ||
| */ | ||
| private String generateValidBolt11Invoice() { | ||
| // Human-readable part: ln + bc (bitcoin mainnet) + 10n (10 nanosats = ~0 sats for testing) | ||
| String hrp = "lnbc10n"; | ||
|
|
||
| // Generate random payment hash (32 bytes = 52 chars in bech32, roughly) | ||
| // For a minimal valid invoice, we need at least timestamp + payment hash | ||
| // Bech32 charset: qpzry9x8gf2tvdw0s3jn54khce6mua7l | ||
| SecureRandom random = new SecureRandom(); | ||
| StringBuilder data = new StringBuilder(); | ||
| String charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; | ||
|
|
||
| // Generate 52 random bech32 characters (represents ~32 bytes of data) | ||
| for (int i = 0; i < 52; i++) { | ||
| data.append(charset.charAt(random.nextInt(charset.length()))); | ||
| } | ||
|
|
||
| // Calculate and append Bech32 checksum (6 characters) | ||
| String checksum = calculateBech32Checksum(hrp, data.toString()); | ||
|
|
||
| return hrp + "1" + data.toString() + checksum; |
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.
Generate BOLT11 invoice with missing mandatory tags
The new generateValidBolt11Invoice builds a random Bech32 payload and only appends a checksum, but it never encodes the mandatory p (payment hash) tag or any other tagged fields required by BOLT‑11. Consequently the value returned from handleCreateInvoice cannot be parsed by standard invoice decoders and does not match the paymentHash reported in the JSON response. Clients that attempt to decode or validate the mocked invoice will continue to fail, so the mock still cannot be used to test invoice parsing despite the commit’s intent. Consider constructing the payload with a real timestamp and a p tag derived from the paymentHash so the invoice is syntactically valid.
Useful? React with 👍 / 👎.
Qodana Community for JVM2 new problems were found
☁️ View the detailed Qodana report Contact Qodana teamContact us at qodana-support@jetbrains.com
|
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.
Pull Request Overview
This PR enhances the MockLnServer to generate BOLT11 invoices with valid Bech32 encoding instead of simple mock strings. The change improves test fidelity by making the mock server produce invoices that pass basic validation checks, similar to what would be returned by a real phoenixd instance. Additionally, a new CLAUDE.md file is added to provide project documentation for Claude Code.
- Implements proper Bech32 checksum calculation for BOLT11 invoice generation
- Adds comprehensive project documentation in CLAUDE.md
- Replaces simple mock invoice strings with cryptographically structured (but still mock) invoices
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| phoenixd-mock/src/main/java/xyz/tcheeric/phoenixd/mock/MockLnServer.java | Implements Bech32 encoding with checksum validation for generated BOLT11 invoices |
| CLAUDE.md | Adds comprehensive project documentation including Maven commands, architecture, and testing guidance |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Generate random payment hash (32 bytes = 52 chars in bech32, roughly) | ||
| // For a minimal valid invoice, we need at least timestamp + payment hash | ||
| // Bech32 charset: qpzry9x8gf2tvdw0s3jn54khce6mua7l | ||
| SecureRandom random = new SecureRandom(); |
Copilot
AI
Nov 2, 2025
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.
Creating a new SecureRandom instance on every invoice generation is expensive. Consider making it a static final field or instance field to reuse across invocations, as SecureRandom is thread-safe.
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.
@copilot open a new pull request to apply changes based on this feedback
| // Bech32 charset: qpzry9x8gf2tvdw0s3jn54khce6mua7l | ||
| SecureRandom random = new SecureRandom(); | ||
| StringBuilder data = new StringBuilder(); | ||
| String charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; |
Copilot
AI
Nov 2, 2025
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.
The Bech32 charset is duplicated in both generateValidBolt11Invoice() (line 70) and calculateBech32Checksum() (line 88). Extract this as a class-level constant to avoid duplication and potential inconsistency.
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.
@copilot open a new pull request to apply changes based on this feedback
| * Bech32 polymod function for checksum calculation. | ||
| */ | ||
| private int polymod(int[] values) { | ||
| int[] gen = {0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3}; |
Copilot
AI
Nov 2, 2025
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.
The generator values array should be extracted as a class-level constant since these are fixed values defined by the Bech32 specification and don't need to be recreated on every checksum calculation.
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.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: tcheeric <6341500+tcheeric@users.noreply.github.com>
Co-authored-by: tcheeric <6341500+tcheeric@users.noreply.github.com>
Co-authored-by: tcheeric <6341500+tcheeric@users.noreply.github.com>
Co-authored-by: tcheeric <6341500+tcheeric@users.noreply.github.com>
Co-authored-by: tcheeric <6341500+tcheeric@users.noreply.github.com>
[WIP] Update to address feedback from PR #57
refactor: extract Bech32 generator constant to class level
perf: reuse SecureRandom instance in MockLnServer
No description provided.