From f3256140944e52eb10e80608be804a0e43084c35 Mon Sep 17 00:00:00 2001 From: Ross Savage Date: Thu, 9 Jan 2025 12:03:44 +0100 Subject: [PATCH] Expose fn to get invoice pubkey --- libs/sdk-common/src/invoice.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/libs/sdk-common/src/invoice.rs b/libs/sdk-common/src/invoice.rs index a94ed4a96..11b30ed6f 100644 --- a/libs/sdk-common/src/invoice.rs +++ b/libs/sdk-common/src/invoice.rs @@ -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::(), + None => invoice + .recover_payee_pub_key() + .serialize() + .encode_hex::(), + } +} + /// Parse a BOLT11 payment request and return a structure contains the parsed fields. pub fn parse_invoice(bolt11: &str) -> InvoiceResult { if bolt11.trim().is_empty() { @@ -347,13 +358,7 @@ pub fn parse_invoice(bolt11: &str) -> InvoiceResult { 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::(), - None => invoice - .recover_payee_pub_key() - .serialize() - .encode_hex::(), - }; + let payee_pubkey = invoice_pubkey(&invoice); // convert hints to bridge interface let invoice_hints = invoice.route_hints();