Skip to content

Conversation

@tcheeric
Copy link
Collaborator

@tcheeric tcheeric commented Nov 2, 2025

No description provided.

automation added 2 commits November 2, 2025 14:13
- 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.
@tcheeric tcheeric requested a review from Copilot November 2, 2025 21:27
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

Comment on lines 54 to 80
/**
* 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;

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@github-actions
Copy link

github-actions bot commented Nov 2, 2025

Qodana Community for JVM

2 new problems were found

Inspection name Severity Problems
AutoCloseable used without 'try'-with-resources 🔶 Warning 1
Simplifiable conditional expression 🔶 Warning 1

☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

Copy link

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

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();
Copy link

Copilot AI Nov 2, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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";
Copy link

Copilot AI Nov 2, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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};
Copy link

Copilot AI Nov 2, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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

Copy link

Copilot AI commented Nov 2, 2025

@tcheeric I've opened a new pull request, #58, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI commented Nov 2, 2025

@tcheeric I've opened a new pull request, #59, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI commented Nov 2, 2025

@tcheeric I've opened a new pull request, #60, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 10 commits November 2, 2025 21:34
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
@tcheeric tcheeric merged commit e33d8b6 into develop Nov 2, 2025
2 of 4 checks passed
@tcheeric tcheeric deleted the release/0.1.4 branch November 2, 2025 21:41
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.

2 participants