Skip to content

Expose remaining invoice details in UniFFI bindings - #1266

Open
tankyleo wants to merge 7 commits into
lightningdevkit:mainfrom
tankyleo:2026-11-expand-invoice-bindings
Open

tankyleo wants to merge 7 commits into
lightningdevkit:mainfrom
tankyleo:2026-11-expand-invoice-bindings

Conversation

@tankyleo

Copy link
Copy Markdown
Contributor

Bindings users could not inspect several offer and invoice properties already available to Rust users.

`Bolt12Invoice::offer_id`, `Bolt12Invoice::payer_metadata`, and
`Bolt11Invoice::payment_metadata` were only available to Rust users,
so bindings users had to decode invoices themselves to associate them
with offers or inspect their metadata.

Expose these values through the existing invoice objects.

Co-Authored-By: Codex
The bindings' `StaticInvoice` only exposed the amount, so bindings
users receiving one with a successful payment could not inspect its
offer identity, description, expiry, chain, or fallback addresses.

Expose these fields along with the issuer, metadata, creation time,
and signing keys, following the existing invoice getters.

Co-Authored-By: Codex
Offer, refund, and invoice feature sets were only available to Rust
users, so bindings users could not inspect their protocol capabilities
or distinguish required features from optional ones.

Expose the four feature contexts through UniFFI objects, using the
same byte helpers and feature checks as the existing feature wrappers.

Co-Authored-By: Codex
Bindings users could check whether an offer expects a quantity but
could not discover its upper bound or distinguish an unbounded offer
from one with a limit.

Expose supported quantities on offers, BOLT12 invoices, and static
invoices via an `OfferQuantity` enum. Preserve the distinction between
an offer for one item and an explicit quantity limit of one.

Co-Authored-By: Codex
@ldk-reviews-bot

ldk-reviews-bot commented Nov 26, 2026 •

Copy link
Copy Markdown

👋 Thanks for assigning @ajaysehwal 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.

@tankyleo
tankyleo force-pushed the 2026-11-expand-invoice-bindings branch from e13a9cc to 1fe9efe Compare November 26, 2026 17:45
@tankyleo
tankyleo requested a review from tnull November 26, 2026 17:46
`Bolt12Invoice::is_for_offer`, `is_for_refund`, and `signature` were
only available to Rust users, so bindings users could not directly
classify an invoice or verify its signature despite having access to
the signable hash and signing public key.

Bindings users also lacked access to `StaticInvoice::signature`,
despite being able to inspect its signing public key.

Expose the origin checks and both invoice signatures through the
existing invoice objects.

Co-Authored-By: Codex
@tankyleo
tankyleo force-pushed the 2026-11-expand-invoice-bindings branch from 1fe9efe to 488e5be Compare November 26, 2026 18:13
Comment thread src/ffi/types.rs
}

/// The chain that must be used when paying the invoice, as a chain hash.
pub fn chain(&self) -> Vec<u8> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

StaticInvoice::chain returns the raw chain hash bytes (like the existing Bolt12Invoice::chain), while Offer::chains/Refund::chain return Network. Would it be worth returning Option (or adding a network() helper) on the invoice types so that binding users get a typed value everywhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you see the commits below, I added fn network() -> Option<Network> to both invoice types, and made further cleanups to the bindings API

The same chain terminology means network enums on some bindings
objects and raw hashes on others. Callers must learn each object's
conventions just to identify its network.

Typed network access should be predictable, without hiding chain
identifiers the library does not recognize.

Co-Authored-By: Codex
BOLT11 uses the same currency for Testnet and Testnet4, so its network
getter cannot distinguish them. Without this limitation in the wrapper's
documentation, callers may mistake the result for an exact network
identification.

Co-Authored-By: Codex
@tankyleo
tankyleo requested a review from ajaysehwal November 30, 2026 05:49
Comment thread src/ffi/types.rs
}

/// The chains that may be used when paying a requested invoice, as chain hashes.
pub fn chains(&self) -> Vec<Vec<u8>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In v0.7.x, Offer::chains() returned sequence<Network> and Refund::chain() returned Network?. Here, the same methods now return raw chain hashes, with the old behavior moved to networks() and network().

For Swift/Kotlin, this causes a compile error, but in Python the change is silent. For example, Network.BITCOIN in offer.chains() or refund.chain() == Network.BITCOIN will now evaluate to false, so existing code could start rejecting valid offers or refunds without any obvious error.

I think chain = hash and network = Network is a good naming convention, but could we avoid reusing the old method names for a different return type? For example, use chain_hashes() and chain_hash() for the raw hash values, while keeping chains() and chain() backward-compatible. Was this rename intentional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it was intentional, I prefer to break users in favor of a clean and predictable API across all types shipped in bindings. We can document the break clearly in the release notes.

Comment thread src/ffi/types.rs
#[uniffi::export]
impl Refund {
/// Features pertaining to requesting an invoice for the refund.
pub fn features(&self) -> Arc<InvoiceRequestFeatures> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed that the other BOLT12 feature getters are named after what they return (offer_features, invoice_request_features, invoice_features). Since this also returns InvoiceRequestFeatures, would invoice_request_features() be clearer for users of the bindings than a generic features()? Happy to keep features() if matching LDK's naming is preferred.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I prefer to have the bindings closely follow the upstream code.

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