]> git.bitcoin.ninja Git - ldk-java/blob - c_sharp/src/org/ldk/structs/RecipientOnionFields.cs
Update CI references to LDK 0.0.124 drop stale memchr pins
[ldk-java] / c_sharp / src / org / ldk / structs / RecipientOnionFields.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  * Information which is provided, encrypted, to the payment recipient when sending HTLCs.
11  * 
12  * This should generally be constructed with data communicated to us from the recipient (via a
13  * BOLT11 or BOLT12 invoice).
14  */
15 public class RecipientOnionFields : CommonBase {
16         internal RecipientOnionFields(object _dummy, long ptr) : base(ptr) { }
17         ~RecipientOnionFields() {
18                 if (ptr != 0) { bindings.RecipientOnionFields_free(ptr); }
19         }
20
21         /**
22          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
23          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
24          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
25          * attacks.
26          * 
27          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
28          * multi-path payments require a recipient-provided secret.
29          * 
30          * Some implementations may reject spontaneous payments with payment secrets, so you may only
31          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
32          * recipient will not reject it.
33          */
34         public Option_ThirtyTwoBytesZ get_payment_secret() {
35                 long ret = bindings.RecipientOnionFields_get_payment_secret(this.ptr);
36                 GC.KeepAlive(this);
37                 if (ret >= 0 && ret <= 4096) { return null; }
38                 org.ldk.structs.Option_ThirtyTwoBytesZ ret_hu_conv = org.ldk.structs.Option_ThirtyTwoBytesZ.constr_from_ptr(ret);
39                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
40                 return ret_hu_conv;
41         }
42
43         /**
44          * The [`PaymentSecret`] is an arbitrary 32 bytes provided by the recipient for us to repeat
45          * in the onion. It is unrelated to `payment_hash` (or [`PaymentPreimage`]) and exists to
46          * authenticate the sender to the recipient and prevent payment-probing (deanonymization)
47          * attacks.
48          * 
49          * If you do not have one, the [`Route`] you pay over must not contain multiple paths as
50          * multi-path payments require a recipient-provided secret.
51          * 
52          * Some implementations may reject spontaneous payments with payment secrets, so you may only
53          * want to provide a secret for a spontaneous payment if MPP is needed and you know your
54          * recipient will not reject it.
55          */
56         public void set_payment_secret(org.ldk.structs.Option_ThirtyTwoBytesZ val) {
57                 bindings.RecipientOnionFields_set_payment_secret(this.ptr, val.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(val);
60         }
61
62         /**
63          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
64          * arbitrary length. This gives recipients substantially more flexibility to receive
65          * additional data.
66          * 
67          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
68          * scheme to authenticate received payments against expected payments and invoices, this field
69          * is not used in LDK for received payments, and can be used to store arbitrary data in
70          * invoices which will be received with the payment.
71          * 
72          * Note that this field was added to the lightning specification more recently than
73          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
74          * may not be supported as universally.
75          * 
76          * Returns a copy of the field.
77          */
78         public Option_CVec_u8ZZ get_payment_metadata() {
79                 long ret = bindings.RecipientOnionFields_get_payment_metadata(this.ptr);
80                 GC.KeepAlive(this);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
84                 return ret_hu_conv;
85         }
86
87         /**
88          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
89          * arbitrary length. This gives recipients substantially more flexibility to receive
90          * additional data.
91          * 
92          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
93          * scheme to authenticate received payments against expected payments and invoices, this field
94          * is not used in LDK for received payments, and can be used to store arbitrary data in
95          * invoices which will be received with the payment.
96          * 
97          * Note that this field was added to the lightning specification more recently than
98          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
99          * may not be supported as universally.
100          */
101         public void set_payment_metadata(org.ldk.structs.Option_CVec_u8ZZ val) {
102                 bindings.RecipientOnionFields_set_payment_metadata(this.ptr, val.ptr);
103                 GC.KeepAlive(this);
104                 GC.KeepAlive(val);
105         }
106
107         internal long clone_ptr() {
108                 long ret = bindings.RecipientOnionFields_clone_ptr(this.ptr);
109                 GC.KeepAlive(this);
110                 return ret;
111         }
112
113         /**
114          * Creates a copy of the RecipientOnionFields
115          */
116         public RecipientOnionFields clone() {
117                 long ret = bindings.RecipientOnionFields_clone(this.ptr);
118                 GC.KeepAlive(this);
119                 if (ret >= 0 && ret <= 4096) { return null; }
120                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
121                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
122                 return ret_hu_conv;
123         }
124
125         /**
126          * Checks if two RecipientOnionFieldss contain equal inner contents.
127          * This ignores pointers and is_owned flags and looks at the values in fields.
128          * Two objects with NULL inner values will be considered "equal" here.
129          */
130         public bool eq(org.ldk.structs.RecipientOnionFields b) {
131                 bool ret = bindings.RecipientOnionFields_eq(this.ptr, b.ptr);
132                 GC.KeepAlive(this);
133                 GC.KeepAlive(b);
134                 if (this != null) { this.ptrs_to.AddLast(b); };
135                 return ret;
136         }
137
138         public override bool Equals(object o) {
139                 if (!(o is RecipientOnionFields)) return false;
140                 return this.eq((RecipientOnionFields)o);
141         }
142         /**
143          * Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
144          */
145         public byte[] write() {
146                 long ret = bindings.RecipientOnionFields_write(this.ptr);
147                 GC.KeepAlive(this);
148                 if (ret >= 0 && ret <= 4096) { return null; }
149                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
150                 return ret_conv;
151         }
152
153         /**
154          * Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
155          */
156         public static Result_RecipientOnionFieldsDecodeErrorZ read(byte[] ser) {
157                 long ret = bindings.RecipientOnionFields_read(InternalUtils.encodeUint8Array(ser));
158                 GC.KeepAlive(ser);
159                 if (ret >= 0 && ret <= 4096) { return null; }
160                 Result_RecipientOnionFieldsDecodeErrorZ ret_hu_conv = Result_RecipientOnionFieldsDecodeErrorZ.constr_from_ptr(ret);
161                 return ret_hu_conv;
162         }
163
164         /**
165          * Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
166          * set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
167          * but do not require or provide any further data.
168          */
169         public static RecipientOnionFields secret_only(byte[] payment_secret) {
170                 long ret = bindings.RecipientOnionFields_secret_only(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_secret, 32)));
171                 GC.KeepAlive(payment_secret);
172                 if (ret >= 0 && ret <= 4096) { return null; }
173                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
174                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
175                 return ret_hu_conv;
176         }
177
178         /**
179          * Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
180          * payable HTLCs except for single-path spontaneous payments, i.e. this should generally
181          * only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
182          * a spontaneous MPP this will not work as all MPP require payment secrets; you may
183          * instead want to use [`RecipientOnionFields::secret_only`].
184          * 
185          * [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
186          * [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
187          */
188         public static RecipientOnionFields spontaneous_empty() {
189                 long ret = bindings.RecipientOnionFields_spontaneous_empty();
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
192                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Creates a new [`RecipientOnionFields`] from an existing one, adding custom TLVs. Each
198          * TLV is provided as a `(u64, Vec<u8>)` for the type number and serialized value
199          * respectively. TLV type numbers must be unique and within the range
200          * reserved for custom types, i.e. >= 2^16, otherwise this method will return `Err(())`.
201          * 
202          * This method will also error for types in the experimental range which have been
203          * standardized within the protocol, which only includes 5482373484 (keysend) for now.
204          * 
205          * See [`Self::custom_tlvs`] for more info.
206          */
207         public Result_RecipientOnionFieldsNoneZ with_custom_tlvs(TwoTuple_u64CVec_u8ZZ[] custom_tlvs) {
208                 long ret = bindings.RecipientOnionFields_with_custom_tlvs(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(custom_tlvs, custom_tlvs_conv_23 => custom_tlvs_conv_23.ptr)));
209                 GC.KeepAlive(this);
210                 GC.KeepAlive(custom_tlvs);
211                 if (ret >= 0 && ret <= 4096) { return null; }
212                 Result_RecipientOnionFieldsNoneZ ret_hu_conv = Result_RecipientOnionFieldsNoneZ.constr_from_ptr(ret);
213                 ;
214                 return ret_hu_conv;
215         }
216
217         /**
218          * Gets the custom TLVs that will be sent or have been received.
219          * 
220          * Custom TLVs allow sending extra application-specific data with a payment. They provide
221          * additional flexibility on top of payment metadata, as while other implementations may
222          * require `payment_metadata` to reflect metadata provided in an invoice, custom TLVs
223          * do not have this restriction.
224          * 
225          * Note that if this field is non-empty, it will contain strictly increasing TLVs, each
226          * represented by a `(u64, Vec<u8>)` for its type number and serialized value respectively.
227          * This is validated when setting this field using [`Self::with_custom_tlvs`].
228          */
229         public TwoTuple_u64CVec_u8ZZ[] custom_tlvs() {
230                 long ret = bindings.RecipientOnionFields_custom_tlvs(this.ptr);
231                 GC.KeepAlive(this);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 int ret_conv_23_len = InternalUtils.getArrayLength(ret);
234                 TwoTuple_u64CVec_u8ZZ[] ret_conv_23_arr = new TwoTuple_u64CVec_u8ZZ[ret_conv_23_len];
235                 for (int x = 0; x < ret_conv_23_len; x++) {
236                         long ret_conv_23 = InternalUtils.getU64ArrayElem(ret, x);
237                         TwoTuple_u64CVec_u8ZZ ret_conv_23_hu_conv = new TwoTuple_u64CVec_u8ZZ(null, ret_conv_23);
238                         if (ret_conv_23_hu_conv != null) { ret_conv_23_hu_conv.ptrs_to.AddLast(this); };
239                         ret_conv_23_arr[x] = ret_conv_23_hu_conv;
240                 }
241                 bindings.free_buffer(ret);
242                 return ret_conv_23_arr;
243         }
244
245 }
246 } } }