6 namespace org { namespace ldk { namespace structs {
10 * An `Offer` is a potentially long-lived proposal for payment of a good or service.
12 * An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
13 * customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
14 * to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
16 * Offers may be denominated in currency other than bitcoin but are ultimately paid using the
19 * Through the use of [`BlindedPath`]s, offers provide recipient privacy.
21 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
22 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
24 public class Offer : CommonBase {
25 internal Offer(object _dummy, long ptr) : base(ptr) { }
27 if (ptr != 0) { bindings.Offer_free(ptr); }
30 internal long clone_ptr() {
31 long ret = bindings.Offer_clone_ptr(this.ptr);
37 * Creates a copy of the Offer
39 public Offer clone() {
40 long ret = bindings.Offer_clone(this.ptr);
42 if (ret >= 0 && ret <= 4096) { return null; }
43 org.ldk.structs.Offer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Offer(null, ret); }
44 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
49 * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
50 * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
51 * for the selected chain.
53 public byte[][] chains() {
54 long ret = bindings.Offer_chains(this.ptr);
56 if (ret >= 0 && ret <= 4096) { return null; }
57 int ret_conv_8_len = InternalUtils.getArrayLength(ret);
58 byte[][] ret_conv_8_arr = new byte[ret_conv_8_len][];
59 for (int i = 0; i < ret_conv_8_len; i++) {
60 long ret_conv_8 = InternalUtils.getU64ArrayElem(ret, i);
61 byte[] ret_conv_8_conv = InternalUtils.decodeUint8Array(ret_conv_8);
62 ret_conv_8_arr[i] = ret_conv_8_conv;
64 bindings.free_buffer(ret);
65 return ret_conv_8_arr;
69 * Opaque bytes set by the originator. Useful for authentication and validating fields since it
70 * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
72 public Option_CVec_u8ZZ metadata() {
73 long ret = bindings.Offer_metadata(this.ptr);
75 if (ret >= 0 && ret <= 4096) { return null; }
76 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
77 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
82 * The minimum amount required for a successful payment of a single item.
84 public Option_AmountZ amount() {
85 long ret = bindings.Offer_amount(this.ptr);
87 if (ret >= 0 && ret <= 4096) { return null; }
88 org.ldk.structs.Option_AmountZ ret_hu_conv = org.ldk.structs.Option_AmountZ.constr_from_ptr(ret);
89 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
94 * A complete description of the purpose of the payment. Intended to be displayed to the user
95 * but with the caveat that it has not been verified in any way.
97 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
99 public PrintableString description() {
100 long ret = bindings.Offer_description(this.ptr);
102 if (ret >= 0 && ret <= 4096) { return null; }
103 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
104 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
109 * Features pertaining to the offer.
111 public OfferFeatures offer_features() {
112 long ret = bindings.Offer_offer_features(this.ptr);
114 if (ret >= 0 && ret <= 4096) { return null; }
115 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
116 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
121 * Duration since the Unix epoch when an invoice should no longer be requested.
123 * If `None`, the offer does not expire.
125 public Option_u64Z absolute_expiry() {
126 long ret = bindings.Offer_absolute_expiry(this.ptr);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
130 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
135 * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
136 * displayed to the user but with the caveat that it has not been verified in any way.
138 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
140 public PrintableString issuer() {
141 long ret = bindings.Offer_issuer(this.ptr);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
145 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
150 * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
151 * recipient privacy by obfuscating its node id.
153 public BlindedPath[] paths() {
154 long ret = bindings.Offer_paths(this.ptr);
156 if (ret >= 0 && ret <= 4096) { return null; }
157 int ret_conv_13_len = InternalUtils.getArrayLength(ret);
158 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
159 for (int n = 0; n < ret_conv_13_len; n++) {
160 long ret_conv_13 = InternalUtils.getU64ArrayElem(ret, n);
161 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); }
162 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.AddLast(this); };
163 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
165 bindings.free_buffer(ret);
166 return ret_conv_13_arr;
170 * The quantity of items supported.
172 public Quantity supported_quantity() {
173 long ret = bindings.Offer_supported_quantity(this.ptr);
175 if (ret >= 0 && ret <= 4096) { return null; }
176 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
177 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
182 * The public key used by the recipient to sign invoices.
184 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
186 public byte[] signing_pubkey() {
187 long ret = bindings.Offer_signing_pubkey(this.ptr);
189 if (ret >= 0 && ret <= 4096) { return null; }
190 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
195 * Returns the id of the offer.
197 public OfferId id() {
198 long ret = bindings.Offer_id(this.ptr);
200 if (ret >= 0 && ret <= 4096) { return null; }
201 org.ldk.structs.OfferId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferId(null, ret); }
202 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
207 * Returns whether the given chain is supported by the offer.
209 public bool supports_chain(byte[] chain) {
210 bool ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(chain, 32)));
217 * Whether the offer has expired.
219 public bool is_expired() {
220 bool ret = bindings.Offer_is_expired(this.ptr);
226 * Whether the offer has expired given the duration since the Unix epoch.
228 public bool is_expired_no_std(long duration_since_epoch) {
229 bool ret = bindings.Offer_is_expired_no_std(this.ptr, duration_since_epoch);
231 GC.KeepAlive(duration_since_epoch);
236 * Returns whether the given quantity is valid for the offer.
238 public bool is_valid_quantity(long quantity) {
239 bool ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
241 GC.KeepAlive(quantity);
246 * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
248 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
250 public bool expects_quantity() {
251 bool ret = bindings.Offer_expects_quantity(this.ptr);
257 * Similar to [`Offer::request_invoice`] except it:
258 * - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
260 * - sets [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is called
261 * such that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was
262 * requested using a base [`ExpandedKey`] from which the payer id was derived, and
263 * - includes the [`PaymentId`] encrypted in [`InvoiceRequest::payer_metadata`] so that it can
264 * be used when sending the payment for the requested invoice.
266 * Useful to protect the sender's privacy.
268 * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
269 * [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
270 * [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
271 * [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
273 public Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ request_invoice_deriving_payer_id(org.ldk.structs.ExpandedKey expanded_key, org.ldk.structs.EntropySource entropy_source, byte[] payment_id) {
274 long ret = bindings.Offer_request_invoice_deriving_payer_id(this.ptr, expanded_key.ptr, entropy_source.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_id, 32)));
276 GC.KeepAlive(expanded_key);
277 GC.KeepAlive(entropy_source);
278 GC.KeepAlive(payment_id);
279 if (ret >= 0 && ret <= 4096) { return null; }
280 Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
281 if (this != null) { this.ptrs_to.AddLast(expanded_key); };
282 if (this != null) { this.ptrs_to.AddLast(entropy_source); };
287 * Similar to [`Offer::request_invoice_deriving_payer_id`] except uses `payer_id` for the
288 * [`InvoiceRequest::payer_id`] instead of deriving a different key for each request.
290 * Useful for recurring payments using the same `payer_id` with different invoices.
292 * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
294 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) {
295 long ret = bindings.Offer_request_invoice_deriving_metadata(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer_id, 33)), expanded_key.ptr, entropy_source.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_id, 32)));
297 GC.KeepAlive(payer_id);
298 GC.KeepAlive(expanded_key);
299 GC.KeepAlive(entropy_source);
300 GC.KeepAlive(payment_id);
301 if (ret >= 0 && ret <= 4096) { return null; }
302 Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
303 if (this != null) { this.ptrs_to.AddLast(expanded_key); };
304 if (this != null) { this.ptrs_to.AddLast(entropy_source); };
309 * Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
310 * which will be reflected in the `Bolt12Invoice` response.
312 * The `metadata` is useful for including information about the derivation of `payer_id` such
313 * that invoice response handling can be stateless. Also serves as payer-provided entropy while
314 * hashing in the signature calculation.
316 * This should not leak any information such as by using a simple BIP-32 derivation path.
317 * Otherwise, payments may be correlated.
319 * Errors if the offer contains unknown required features.
321 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
323 public Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ request_invoice(byte[] metadata, byte[] payer_id) {
324 long ret = bindings.Offer_request_invoice(this.ptr, InternalUtils.encodeUint8Array(metadata), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer_id, 33)));
326 GC.KeepAlive(metadata);
327 GC.KeepAlive(payer_id);
328 if (ret >= 0 && ret <= 4096) { return null; }
329 Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
334 * Generates a non-cryptographic 64-bit hash of the Offer.
337 long ret = bindings.Offer_hash(this.ptr);
342 public override int GetHashCode() {
343 return (int)this.hash();
346 * Serialize the Offer object into a byte array which can be read by Offer_read
348 public byte[] write() {
349 long ret = bindings.Offer_write(this.ptr);
351 if (ret >= 0 && ret <= 4096) { return null; }
352 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
357 * Read a Offer object from a string
359 public static Result_OfferBolt12ParseErrorZ from_str(string s) {
360 long ret = bindings.Offer_from_str(InternalUtils.encodeString(s));
362 if (ret >= 0 && ret <= 4096) { return null; }
363 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);