]> git.bitcoin.ninja Git - ldk-java/blob - c_sharp/src/org/ldk/structs/Offer.cs
Update CI references to LDK 0.0.124 drop stale memchr pins
[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 [`BlindedMessagePath`]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 BlindedMessagePath[] 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_20_len = InternalUtils.getArrayLength(ret);
158                 BlindedMessagePath[] ret_conv_20_arr = new BlindedMessagePath[ret_conv_20_len];
159                 for (int u = 0; u < ret_conv_20_len; u++) {
160                         long ret_conv_20 = InternalUtils.getU64ArrayElem(ret, u);
161                         org.ldk.structs.BlindedMessagePath ret_conv_20_hu_conv = null; if (ret_conv_20 < 0 || ret_conv_20 > 4096) { ret_conv_20_hu_conv = new org.ldk.structs.BlindedMessagePath(null, ret_conv_20); }
162                         if (ret_conv_20_hu_conv != null) { ret_conv_20_hu_conv.ptrs_to.AddLast(this); };
163                         ret_conv_20_arr[u] = ret_conv_20_hu_conv;
164                 }
165                 bindings.free_buffer(ret);
166                 return ret_conv_20_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_using_metadata`] to determine if the
262          * invoice was requested using a base [`ExpandedKey`] from which the payer id was derived,
263          * and
264          * - includes the [`PaymentId`] encrypted in [`InvoiceRequest::payer_metadata`] so that it can
265          * be used when sending the payment for the requested invoice.
266          * 
267          * Useful to protect the sender's privacy.
268          * 
269          * [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
270          * [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
271          * [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata
272          * [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
273          */
274         public Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ request_invoice_deriving_payer_id(org.ldk.structs.ExpandedKey expanded_key, org.ldk.structs.Nonce nonce, byte[] payment_id) {
275                 long ret = bindings.Offer_request_invoice_deriving_payer_id(this.ptr, expanded_key.ptr, nonce.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_id, 32)));
276                 GC.KeepAlive(this);
277                 GC.KeepAlive(expanded_key);
278                 GC.KeepAlive(nonce);
279                 GC.KeepAlive(payment_id);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithDerivedPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
282                 if (this != null) { this.ptrs_to.AddLast(expanded_key); };
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.Nonce nonce, 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, nonce.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(nonce);
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                 return ret_hu_conv;
305         }
306
307         /**
308          * Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
309          * which will be reflected in the `Bolt12Invoice` response.
310          * 
311          * The `metadata` is useful for including information about the derivation of `payer_id` such
312          * that invoice response handling can be stateless. Also serves as payer-provided entropy while
313          * hashing in the signature calculation.
314          * 
315          * This should not leak any information such as by using a simple BIP-32 derivation path.
316          * Otherwise, payments may be correlated.
317          * 
318          * Errors if the offer contains unknown required features.
319          * 
320          * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
321          */
322         public Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ request_invoice(byte[] metadata, byte[] payer_id) {
323                 long ret = bindings.Offer_request_invoice(this.ptr, InternalUtils.encodeUint8Array(metadata), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payer_id, 33)));
324                 GC.KeepAlive(this);
325                 GC.KeepAlive(metadata);
326                 GC.KeepAlive(payer_id);
327                 if (ret >= 0 && ret <= 4096) { return null; }
328                 Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceRequestWithExplicitPayerIdBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
329                 return ret_hu_conv;
330         }
331
332         /**
333          * Generates a non-cryptographic 64-bit hash of the Offer.
334          */
335         public long hash() {
336                 long ret = bindings.Offer_hash(this.ptr);
337                 GC.KeepAlive(this);
338                 return ret;
339         }
340
341         public override int GetHashCode() {
342                 return (int)this.hash();
343         }
344         /**
345          * Read a Offer from a byte array, created by Offer_write
346          */
347         public static Result_OfferDecodeErrorZ read(byte[] ser) {
348                 long ret = bindings.Offer_read(InternalUtils.encodeUint8Array(ser));
349                 GC.KeepAlive(ser);
350                 if (ret >= 0 && ret <= 4096) { return null; }
351                 Result_OfferDecodeErrorZ ret_hu_conv = Result_OfferDecodeErrorZ.constr_from_ptr(ret);
352                 return ret_hu_conv;
353         }
354
355         /**
356          * Serialize the Offer object into a byte array which can be read by Offer_read
357          */
358         public byte[] write() {
359                 long ret = bindings.Offer_write(this.ptr);
360                 GC.KeepAlive(this);
361                 if (ret >= 0 && ret <= 4096) { return null; }
362                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
363                 return ret_conv;
364         }
365
366         /**
367          * Read a Offer object from a string
368          */
369         public static Result_OfferBolt12ParseErrorZ from_str(string s) {
370                 long ret = bindings.Offer_from_str(InternalUtils.encodeString(s));
371                 GC.KeepAlive(s);
372                 if (ret >= 0 && ret <= 4096) { return null; }
373                 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);
374                 return ret_hu_conv;
375         }
376
377         /**
378          * Get the string representation of a Offer object
379          */
380         public string to_str() {
381                 long ret = bindings.Offer_to_str(this.ptr);
382                 GC.KeepAlive(this);
383                 if (ret >= 0 && ret <= 4096) { return null; }
384                 string ret_conv = InternalUtils.decodeString(ret);
385                 return ret_conv;
386         }
387
388 }
389 } } }