Skip to content

Conversation

@vincenzopalazzo
Copy link
Contributor

This patch adds the bolt12_invoice field to the PaymentSuccessful event, enabling users to obtain proof of payment for BOLT12 transactions.

Problem:
Previously, after a successful BOLT12 payment, users had no way to access the paid invoice data. This made it impossible to provide proof of payment to third parties, who need both the payment preimage and the original invoice to verify that sha256(preimage) matches the invoice's payment_hash.

Solution:
Add a bolt12_invoice: Option<Vec<u8>> field to PaymentSuccessful that contains the serialized BOLT12 invoice bytes. The invoice is serialized using LDK's standard encoding, which can be parsed back using Bolt12Invoice::try_from(bytes) in native Rust, or by hex-encoding the bytes and using Bolt12Invoice.from_str() in FFI bindings.

Design decisions:

  • Store as Vec<u8> rather than the complex PaidBolt12Invoice type to avoid UniFFI limitations with objects in enum variants
  • Return None for StaticInvoice (async payments) since proof of payment is not possible for those payment types anyway
  • Use TLV tag 7 for serialization, maintaining backward compatibility with existing persisted events

This implementation follows the maintainer guidance from PR #563 to expose the invoice via the event rather than storing it in the payment store.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 29, 2025

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@vincenzopalazzo
Copy link
Contributor Author

@tnull IDK if this is a good design to have with the ffi, but I had to work around some unify ffi limitation with the enum type that is used inside the PaymentSend in rust-lightning

@vincenzopalazzo vincenzopalazzo marked this pull request as ready for review December 29, 2025 13:53
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @tnull! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Exposing the BOLT12 invoice makes sense to me, though we should do it properly instead of just exposing the bytes.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

The changes are getting closer, but please make sure to avoid unnecessary boilerplate and stick to the approach we took for the other types (like Offer, Refund, etc).

This also needs a rebase by now, sorry!

Btw, please re-request review when you made updates, otherwise I might not always see it immediately.

"StaticInvoice",
};

dictionary PaidBolt12Invoice {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we make this an

[Enum]
interface PaidBolt12Invoice {

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mh I was hacking round this this afternoon and this is what I got

  error: failed to run custom build command for `ldk-node v0.8.0+git`

  Caused by:
    process didn't exit successfully (exit status: 101)
    --- stdout
    cargo:rerun-if-changed=bindings/ldk_node.udl
    cargo:rerun-if-env-changed=UNIFFI_TESTS_DISABLE_EXTENSIONS

    --- stderr
    thread 'main' panicked at build.rs:10:59:
    called `Result::unwrap()` on an `Err` value: Objects cannot currently be used in enum variant data

The key part is:

Objects cannot currently be used in enum variant data

  This occurs when trying to use:
  [Enum]
  interface PaidBolt12Invoice {
      Bolt12Invoice(Bolt12Invoice invoice);
      StaticInvoice(StaticInvoice invoice);
  };

It looks like that it is happening because Bolt12Invoice and StaticInvoice are defined as interface (Objects) in UniFFI, they cannot be used as parameters in enum variants.

Am I missing something?

src/types.rs Outdated
/// Unlike [`Bolt12Invoice`], a `StaticInvoice` does not support proof of payment
/// because the payment hash is not derived from a preimage known only to the recipient.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StaticInvoice {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to wrap StaticInvoice in the non-uniffi case. Please follow the same approach as we did for Offer, Refund, etc. and reuse the existing maybe_wrap macros etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok let me know if now this is solving your concern, thanks!

@vincenzopalazzo vincenzopalazzo force-pushed the macros/bolt12-pop branch 3 times, most recently from 05838f1 to 22abd3b Compare January 10, 2026 11:42
After a successful BOLT12 payment, users need access to the paid invoice
to provide proof of payment to third parties. The invoice contains the
payment_hash that can be verified against sha256(preimage).

This adds a `bolt12_invoice` field to `PaymentSuccessful` containing
the `PaidBolt12Invoice` which wraps either a regular `Bolt12Invoice` or
a `StaticInvoice` for async payments.

For UniFFI bindings, `PaidBolt12Invoice` is exposed as a dictionary
struct that delegates serialization to LDK's native type. For non-UniFFI
builds, we simply re-export LDK's `PaidBolt12Invoice` enum directly.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
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.

3 participants