Skip to content
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

Validate bolt11 network #586

Merged
merged 2 commits into from
Nov 15, 2023
Merged

Validate bolt11 network #586

merged 2 commits into from
Nov 15, 2023

Conversation

dangeross
Copy link
Collaborator

@dangeross dangeross commented Nov 6, 2023

This PR adds the invoice network to the LNInvoice response of parse_input and parse_invoice. It also validates the bolt11 invoice network against the config network when calling send_payment or lnurl_pay.

  • Validate send_payment
  • Validate lnurl_pay

Fixes #462

@dangeross dangeross marked this pull request as ready for review November 6, 2023 21:22
@dangeross dangeross force-pushed the savage-invalid-network branch from 6cb3d44 to 1458a99 Compare November 6, 2023 21:29
@dangeross dangeross requested review from roeierez and ok300 November 6, 2023 21:30
@dangeross dangeross force-pushed the savage-invalid-network branch 5 times, most recently from c221f32 to d3a2e42 Compare November 9, 2023 13:51
Copy link
Contributor

@JssDWt JssDWt left a comment

Choose a reason for hiding this comment

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

LGTM

@dangeross dangeross force-pushed the savage-invalid-network branch from d3a2e42 to 1510a1b Compare November 13, 2023 11:40
/// Parse a BOLT11 payment request and return a structure contains the parsed fields.
pub fn parse_invoice(bolt11: &str) -> InvoiceResult<LNInvoice> {
pub fn parse_invoice(bolt11: &str, network: Option<Network>) -> InvoiceResult<LNInvoice> {
Copy link
Member

Choose a reason for hiding this comment

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

This change makes the binding interface different than the rust interface (we added one parameter only to the rust layer).
I am not sure we should overload the upper layer validation down to this function. Perhaps we should validate on the caller instead?

@dangeross dangeross force-pushed the savage-invalid-network branch from 4459c20 to 0a20576 Compare November 15, 2023 12:14
Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

Looks good and simple! Dropped one simplification suggestion.

@@ -189,6 +195,25 @@ pub fn add_lsp_routing_hints(
Ok(invoice_builder.build_raw()?)
}

// Validate that the BOLT11 payment request matches the network
pub fn validate_network(bolt11: &str, network: Network) -> InvoiceResult<()> {
if bolt11.trim().is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

We duplicate the parse_invoice code here. Perhaps we should just use it and compare the network with the LNInvoice object?

Copy link
Member

@roeierez roeierez left a comment

Choose a reason for hiding this comment

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

LGTM

@dangeross dangeross merged commit 3a7fd3e into main Nov 15, 2023
6 of 7 checks passed
@dangeross dangeross deleted the savage-invalid-network branch November 15, 2023 20:15
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.

Feature request: add Network field to LNInvoice
4 participants