1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * An `Offer` is a potentially long-lived proposal for payment of a good or service.
14 * An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
15 * customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
16 * to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
18 * Offers may be denominated in currency other than bitcoin but are ultimately paid using the
21 * Through the use of [`BlindedPath`]s, offers provide recipient privacy.
23 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
24 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class Offer extends CommonBase {
28 Offer(Object _dummy, long ptr) { super(ptr); }
29 @Override @SuppressWarnings("deprecation")
30 protected void finalize() throws Throwable {
32 if (ptr != 0) { bindings.Offer_free(ptr); }
36 long ret = bindings.Offer_clone_ptr(this.ptr);
37 Reference.reachabilityFence(this);
42 * Creates a copy of the Offer
44 public Offer clone() {
45 long ret = bindings.Offer_clone(this.ptr);
46 Reference.reachabilityFence(this);
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.Offer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Offer(null, ret); }
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
54 * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
55 * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
56 * for the selected chain.
58 public byte[][] chains() {
59 byte[][] ret = bindings.Offer_chains(this.ptr);
60 Reference.reachabilityFence(this);
65 * Opaque bytes set by the originator. Useful for authentication and validating fields since it
66 * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
68 public Option_CVec_u8ZZ metadata() {
69 long ret = bindings.Offer_metadata(this.ptr);
70 Reference.reachabilityFence(this);
71 if (ret >= 0 && ret <= 4096) { return null; }
72 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
73 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
78 * The minimum amount required for a successful payment of a single item.
80 public Option_AmountZ amount() {
81 long ret = bindings.Offer_amount(this.ptr);
82 Reference.reachabilityFence(this);
83 if (ret >= 0 && ret <= 4096) { return null; }
84 org.ldk.structs.Option_AmountZ ret_hu_conv = org.ldk.structs.Option_AmountZ.constr_from_ptr(ret);
85 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
90 * A complete description of the purpose of the payment. Intended to be displayed to the user
91 * but with the caveat that it has not been verified in any way.
93 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
96 public PrintableString description() {
97 long ret = bindings.Offer_description(this.ptr);
98 Reference.reachabilityFence(this);
99 if (ret >= 0 && ret <= 4096) { return null; }
100 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
101 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
106 * Features pertaining to the offer.
108 public OfferFeatures offer_features() {
109 long ret = bindings.Offer_offer_features(this.ptr);
110 Reference.reachabilityFence(this);
111 if (ret >= 0 && ret <= 4096) { return null; }
112 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
118 * Duration since the Unix epoch when an invoice should no longer be requested.
120 * If `None`, the offer does not expire.
122 public Option_u64Z absolute_expiry() {
123 long ret = bindings.Offer_absolute_expiry(this.ptr);
124 Reference.reachabilityFence(this);
125 if (ret >= 0 && ret <= 4096) { return null; }
126 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
127 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
132 * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
133 * displayed to the user but with the caveat that it has not been verified in any way.
135 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
138 public PrintableString issuer() {
139 long ret = bindings.Offer_issuer(this.ptr);
140 Reference.reachabilityFence(this);
141 if (ret >= 0 && ret <= 4096) { return null; }
142 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
143 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
148 * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
149 * recipient privacy by obfuscating its node id.
151 public BlindedPath[] paths() {
152 long[] ret = bindings.Offer_paths(this.ptr);
153 Reference.reachabilityFence(this);
154 int ret_conv_13_len = ret.length;
155 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
156 for (int n = 0; n < ret_conv_13_len; n++) {
157 long ret_conv_13 = ret[n];
158 org.ldk.structs.BlindedPath ret_conv_13_hu_conv = null; if (ret_conv_13 < 0 || ret_conv_13 > 4096) { ret_conv_13_hu_conv = new org.ldk.structs.BlindedPath(null, ret_conv_13); }
159 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
160 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
162 return ret_conv_13_arr;
166 * The quantity of items supported.
168 public Quantity supported_quantity() {
169 long ret = bindings.Offer_supported_quantity(this.ptr);
170 Reference.reachabilityFence(this);
171 if (ret >= 0 && ret <= 4096) { return null; }
172 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
173 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
178 * The public key used by the recipient to sign invoices.
180 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
183 public byte[] signing_pubkey() {
184 byte[] ret = bindings.Offer_signing_pubkey(this.ptr);
185 Reference.reachabilityFence(this);
190 * Returns the id of the offer.
192 public OfferId id() {
193 long ret = bindings.Offer_id(this.ptr);
194 Reference.reachabilityFence(this);
195 if (ret >= 0 && ret <= 4096) { return null; }
196 org.ldk.structs.OfferId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferId(null, ret); }
197 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
202 * Returns whether the given chain is supported by the offer.
204 public boolean supports_chain(byte[] chain) {
205 boolean ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.check_arr_len(chain, 32));
206 Reference.reachabilityFence(this);
207 Reference.reachabilityFence(chain);
212 * Whether the offer has expired.
214 public boolean is_expired() {
215 boolean ret = bindings.Offer_is_expired(this.ptr);
216 Reference.reachabilityFence(this);
221 * Whether the offer has expired given the duration since the Unix epoch.
223 public boolean is_expired_no_std(long duration_since_epoch) {
224 boolean ret = bindings.Offer_is_expired_no_std(this.ptr, duration_since_epoch);
225 Reference.reachabilityFence(this);
226 Reference.reachabilityFence(duration_since_epoch);
231 * Returns whether the given quantity is valid for the offer.
233 public boolean is_valid_quantity(long quantity) {
234 boolean ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
235 Reference.reachabilityFence(this);
236 Reference.reachabilityFence(quantity);
241 * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
243 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
245 public boolean expects_quantity() {
246 boolean ret = bindings.Offer_expects_quantity(this.ptr);
247 Reference.reachabilityFence(this);
252 * Similar to [`Offer::request_invoice`] except it:
253 * - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
255 * - sets [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is called
256 * such that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was
257 * requested using a base [`ExpandedKey`] from which the payer id was derived, and
258 * - includes the [`PaymentId`] encrypted in [`InvoiceRequest::payer_metadata`] so that it can
259 * be used when sending the payment for the requested invoice.
261 * Useful to protect the sender's privacy.
263 * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
264 * [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
265 * [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
266 * [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
268 public Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ request_invoice_deriving_payer_id(org.ldk.structs.ExpandedKey expanded_key, org.ldk.structs.EntropySource entropy_source, byte[] payment_id) {
269 long ret = bindings.Offer_request_invoice_deriving_payer_id(this.ptr, expanded_key.ptr, entropy_source.ptr, InternalUtils.check_arr_len(payment_id, 32));
270 Reference.reachabilityFence(this);
271 Reference.reachabilityFence(expanded_key);
272 Reference.reachabilityFence(entropy_source);
273 Reference.reachabilityFence(payment_id);
274 if (ret >= 0 && ret <= 4096) { return null; }
275 Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
276 if (this != null) { this.ptrs_to.add(expanded_key); };
277 if (this != null) { this.ptrs_to.add(entropy_source); };
282 * Similar to [`Offer::request_invoice_deriving_payer_id`] except uses `payer_id` for the
283 * [`InvoiceRequest::payer_id`] instead of deriving a different key for each request.
285 * Useful for recurring payments using the same `payer_id` with different invoices.
287 * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
289 public Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ request_invoice_deriving_metadata(byte[] payer_id, org.ldk.structs.ExpandedKey expanded_key, org.ldk.structs.EntropySource entropy_source, byte[] payment_id) {
290 long ret = bindings.Offer_request_invoice_deriving_metadata(this.ptr, InternalUtils.check_arr_len(payer_id, 33), expanded_key.ptr, entropy_source.ptr, InternalUtils.check_arr_len(payment_id, 32));
291 Reference.reachabilityFence(this);
292 Reference.reachabilityFence(payer_id);
293 Reference.reachabilityFence(expanded_key);
294 Reference.reachabilityFence(entropy_source);
295 Reference.reachabilityFence(payment_id);
296 if (ret >= 0 && ret <= 4096) { return null; }
297 Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
298 if (this != null) { this.ptrs_to.add(expanded_key); };
299 if (this != null) { this.ptrs_to.add(entropy_source); };
304 * Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
305 * which will be reflected in the `Bolt12Invoice` response.
307 * The `metadata` is useful for including information about the derivation of `payer_id` such
308 * that invoice response handling can be stateless. Also serves as payer-provided entropy while
309 * hashing in the signature calculation.
311 * This should not leak any information such as by using a simple BIP-32 derivation path.
312 * Otherwise, payments may be correlated.
314 * Errors if the offer contains unknown required features.
316 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
318 public Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ request_invoice(byte[] metadata, byte[] payer_id) {
319 long ret = bindings.Offer_request_invoice(this.ptr, metadata, InternalUtils.check_arr_len(payer_id, 33));
320 Reference.reachabilityFence(this);
321 Reference.reachabilityFence(metadata);
322 Reference.reachabilityFence(payer_id);
323 if (ret >= 0 && ret <= 4096) { return null; }
324 Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
329 * Generates a non-cryptographic 64-bit hash of the Offer.
332 long ret = bindings.Offer_hash(this.ptr);
333 Reference.reachabilityFence(this);
337 @Override public int hashCode() {
338 return (int)this.hash();
341 * Serialize the Offer object into a byte array which can be read by Offer_read
343 public byte[] write() {
344 byte[] ret = bindings.Offer_write(this.ptr);
345 Reference.reachabilityFence(this);
350 * Read a Offer object from a string
352 public static Result_OfferBolt12ParseErrorZ from_str(java.lang.String s) {
353 long ret = bindings.Offer_from_str(s);
354 Reference.reachabilityFence(s);
355 if (ret >= 0 && ret <= 4096) { return null; }
356 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);
361 * Get the string representation of a Offer object
363 public String to_str() {
364 String ret = bindings.Offer_to_str(this.ptr);
365 Reference.reachabilityFence(this);