-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
6cb3d44
to
1458a99
Compare
c221f32
to
d3a2e42
Compare
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.
LGTM
d3a2e42
to
1510a1b
Compare
libs/sdk-core/src/invoice.rs
Outdated
/// 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> { |
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.
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?
4459c20
to
0a20576
Compare
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.
Looks good and simple! Dropped one simplification suggestion.
libs/sdk-core/src/invoice.rs
Outdated
@@ -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() { |
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.
We duplicate the parse_invoice code here. Perhaps we should just use it and compare the network with the LNInvoice object?
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.
LGTM
This PR adds the invoice network to the LNInvoice response of
parse_input
andparse_invoice
. It also validates the bolt11 invoice network against the config network when callingsend_payment
orlnurl_pay
.Fixes #462