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.

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 lightningdevkit#563 to
expose the invoice via the event rather than storing it in the
payment store.

Signed-off-by: Vincenzo Palazzo <[email protected]>
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Dec 29, 2025

I've assigned @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
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.

2 participants