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

Expose fn to get invoice pubkey #1156

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions libs/sdk-common/src/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ pub fn validate_network(invoice: LNInvoice, network: Network) -> InvoiceResult<(
}
}

/// Try to take payee pubkey from the tagged fields, if doesn't exist recover it from the signature
pub fn invoice_pubkey(invoice: &Bolt11Invoice) -> String {
match invoice.payee_pub_key() {
Some(key) => key.serialize().encode_hex::<String>(),
None => invoice
.recover_payee_pub_key()
.serialize()
.encode_hex::<String>(),
}
}

/// Parse a BOLT11 payment request and return a structure contains the parsed fields.
pub fn parse_invoice(bolt11: &str) -> InvoiceResult<LNInvoice> {
if bolt11.trim().is_empty() {
Expand All @@ -347,13 +358,7 @@ pub fn parse_invoice(bolt11: &str) -> InvoiceResult<LNInvoice> {
invoice.check_signature()?;

// Try to take payee pubkey from the tagged fields, if doesn't exist recover it from the signature
let payee_pubkey: String = match invoice.payee_pub_key() {
Some(key) => key.serialize().encode_hex::<String>(),
None => invoice
.recover_payee_pub_key()
.serialize()
.encode_hex::<String>(),
};
let payee_pubkey = invoice_pubkey(&invoice);

// convert hints to bridge interface
let invoice_hints = invoice.route_hints();
Expand Down
Loading