[C#] Run tests against release library in determinism CI run
[ldk-java] / c_sharp / src / org / ldk / structs / Offer.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * An `Offer` is a potentially long-lived proposal for payment of a good or service.
11  * 
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`].
15  * 
16  * Offers may be denominated in currency other than bitcoin but are ultimately paid using the
17  * latter.
18  * 
19  * Through the use of [`BlindedPath`]s, offers provide recipient privacy.
20  * 
21  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
22  * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
23  */
24 public class Offer : CommonBase {
25         internal Offer(object _dummy, long ptr) : base(ptr) { }
26         ~Offer() {
27                 if (ptr != 0) { bindings.Offer_free(ptr); }
28         }
29
30         internal long clone_ptr() {
31                 long ret = bindings.Offer_clone_ptr(this.ptr);
32                 GC.KeepAlive(this);
33                 return ret;
34         }
35
36         /**
37          * Creates a copy of the Offer
38          */
39         public Offer clone() {
40                 long ret = bindings.Offer_clone(this.ptr);
41                 GC.KeepAlive(this);
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); };
45                 return ret_hu_conv;
46         }
47
48         /**
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.
52          */
53         public byte[][] chains() {
54                 long ret = bindings.Offer_chains(this.ptr);
55                 GC.KeepAlive(this);
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;
63                 }
64                 bindings.free_buffer(ret);
65                 return ret_conv_8_arr;
66         }
67
68         /**
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`.
71          */
72         public Option_CVec_u8ZZ metadata() {
73                 long ret = bindings.Offer_metadata(this.ptr);
74                 GC.KeepAlive(this);
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); };
78                 return ret_hu_conv;
79         }
80
81         /**
82          * The minimum amount required for a successful payment of a single item.
83          */
84         public Option_AmountZ amount() {
85                 long ret = bindings.Offer_amount(this.ptr);
86                 GC.KeepAlive(this);
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); };
90                 return ret_hu_conv;
91         }
92
93         /**
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.
96          * 
97          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
98          */
99         public PrintableString description() {
100                 long ret = bindings.Offer_description(this.ptr);
101                 GC.KeepAlive(this);
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); };
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Features pertaining to the offer.
110          */
111         public OfferFeatures offer_features() {
112                 long ret = bindings.Offer_offer_features(this.ptr);
113                 GC.KeepAlive(this);
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); };
117                 return ret_hu_conv;
118         }
119
120         /**
121          * Duration since the Unix epoch when an invoice should no longer be requested.
122          * 
123          * If `None`, the offer does not expire.
124          */
125         public Option_u64Z absolute_expiry() {
126                 long ret = bindings.Offer_absolute_expiry(this.ptr);
127                 GC.KeepAlive(this);
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); };
131                 return ret_hu_conv;
132         }
133
134         /**
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.
137          * 
138          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
139          */
140         public PrintableString issuer() {
141                 long ret = bindings.Offer_issuer(this.ptr);
142                 GC.KeepAlive(this);
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); };
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
151          * recipient privacy by obfuscating its node id.
152          */
153         public BlindedPath[] paths() {
154                 long ret = bindings.Offer_paths(this.ptr);
155                 GC.KeepAlive(this);
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;
164                 }
165                 bindings.free_buffer(ret);
166                 return ret_conv_13_arr;
167         }
168
169         /**
170          * The quantity of items supported.
171          */
172         public Quantity supported_quantity() {
173                 long ret = bindings.Offer_supported_quantity(this.ptr);
174                 GC.KeepAlive(this);
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); };
178                 return ret_hu_conv;
179         }
180
181         /**
182          * The public key used by the recipient to sign invoices.
183          * 
184          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
185          */
186         public byte[] signing_pubkey() {
187                 long ret = bindings.Offer_signing_pubkey(this.ptr);
188                 GC.KeepAlive(this);
189                 if (ret >= 0 && ret <= 4096) { return null; }
190                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
191                 return ret_conv;
192         }
193
194         /**
195          * Returns the id of the offer.
196          */
197         public OfferId id() {
198                 long ret = bindings.Offer_id(this.ptr);
199                 GC.KeepAlive(this);
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); };
203                 return ret_hu_conv;
204         }
205
206         /**
207          * Returns whether the given chain is supported by the offer.
208          */
209         public bool supports_chain(byte[] chain) {
210                 bool ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(chain, 32)));
211                 GC.KeepAlive(this);
212                 GC.KeepAlive(chain);
213                 return ret;
214         }
215
216         /**
217          * Whether the offer has expired.
218          */
219         public bool is_expired() {
220                 bool ret = bindings.Offer_is_expired(this.ptr);
221                 GC.KeepAlive(this);
222                 return ret;
223         }
224
225         /**
226          * Whether the offer has expired given the duration since the Unix epoch.
227          */
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);
230                 GC.KeepAlive(this);
231                 GC.KeepAlive(duration_since_epoch);
232                 return ret;
233         }
234
235         /**
236          * Returns whether the given quantity is valid for the offer.
237          */
238         public bool is_valid_quantity(long quantity) {
239                 bool ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
240                 GC.KeepAlive(this);
241                 GC.KeepAlive(quantity);
242                 return ret;
243         }
244
245         /**
246          * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
247          * 
248          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
249          */
250         public bool expects_quantity() {
251                 bool ret = bindings.Offer_expects_quantity(this.ptr);
252                 GC.KeepAlive(this);
253                 return ret;
254         }
255
256         /**
257          * Similar to [`Offer::request_invoice`] except it:
258          * - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
259          * request,
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.
265          * 
266          * Useful to protect the sender's privacy.
267          * 
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
272          */
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)));
275                 GC.KeepAlive(this);
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); };
283                 return ret_hu_conv;
284         }
285
286         /**
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.
289          * 
290          * Useful for recurring payments using the same `payer_id` with different invoices.
291          * 
292          * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
293          */
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)));
296                 GC.KeepAlive(this);
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); };
305                 return ret_hu_conv;
306         }
307
308         /**
309          * Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
310          * which will be reflected in the `Bolt12Invoice` response.
311          * 
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.
315          * 
316          * This should not leak any information such as by using a simple BIP-32 derivation path.
317          * Otherwise, payments may be correlated.
318          * 
319          * Errors if the offer contains unknown required features.
320          * 
321          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
322          */
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)));
325                 GC.KeepAlive(this);
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);
330                 return ret_hu_conv;
331         }
332
333         /**
334          * Generates a non-cryptographic 64-bit hash of the Offer.
335          */
336         public long hash() {
337                 long ret = bindings.Offer_hash(this.ptr);
338                 GC.KeepAlive(this);
339                 return ret;
340         }
341
342         public override int GetHashCode() {
343                 return (int)this.hash();
344         }
345         /**
346          * Serialize the Offer object into a byte array which can be read by Offer_read
347          */
348         public byte[] write() {
349                 long ret = bindings.Offer_write(this.ptr);
350                 GC.KeepAlive(this);
351                 if (ret >= 0 && ret <= 4096) { return null; }
352                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
353                 return ret_conv;
354         }
355
356         /**
357          * Read a Offer object from a string
358          */
359         public static Result_OfferBolt12ParseErrorZ from_str(string s) {
360                 long ret = bindings.Offer_from_str(InternalUtils.encodeString(s));
361                 GC.KeepAlive(s);
362                 if (ret >= 0 && ret <= 4096) { return null; }
363                 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);
364                 return ret_hu_conv;
365         }
366
367 }
368 } } }