62b5ca60f92c49f9636fd153303ee17b71518bc7
[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_PaymentSecretZ 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_PaymentSecretZ ret_hu_conv = org.ldk.structs.Option_PaymentSecretZ.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_PaymentSecretZ val) {
57                 bindings.RecipientOnionFields_set_payment_secret(this.ptr, val.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(val);
60                 if (this != null) { this.ptrs_to.AddLast(val); };
61         }
62
63         /**
64          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
65          * arbitrary length. This gives recipients substantially more flexibility to receive
66          * additional data.
67          * 
68          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
69          * scheme to authenticate received payments against expected payments and invoices, this field
70          * is not used in LDK for received payments, and can be used to store arbitrary data in
71          * invoices which will be received with the payment.
72          * 
73          * Note that this field was added to the lightning specification more recently than
74          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
75          * may not be supported as universally.
76          * 
77          * Returns a copy of the field.
78          */
79         public Option_CVec_u8ZZ get_payment_metadata() {
80                 long ret = bindings.RecipientOnionFields_get_payment_metadata(this.ptr);
81                 GC.KeepAlive(this);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
85                 return ret_hu_conv;
86         }
87
88         /**
89          * The payment metadata serves a similar purpose as [`Self::payment_secret`] but is of
90          * arbitrary length. This gives recipients substantially more flexibility to receive
91          * additional data.
92          * 
93          * In LDK, while the [`Self::payment_secret`] is fixed based on an internal authentication
94          * scheme to authenticate received payments against expected payments and invoices, this field
95          * is not used in LDK for received payments, and can be used to store arbitrary data in
96          * invoices which will be received with the payment.
97          * 
98          * Note that this field was added to the lightning specification more recently than
99          * [`Self::payment_secret`] and while nearly all lightning senders support secrets, metadata
100          * may not be supported as universally.
101          */
102         public void set_payment_metadata(org.ldk.structs.Option_CVec_u8ZZ val) {
103                 bindings.RecipientOnionFields_set_payment_metadata(this.ptr, val.ptr);
104                 GC.KeepAlive(this);
105                 GC.KeepAlive(val);
106                 if (this != null) { this.ptrs_to.AddLast(val); };
107         }
108
109         /**
110          * Constructs a new RecipientOnionFields given each field
111          */
112         public static RecipientOnionFields of(org.ldk.structs.Option_PaymentSecretZ payment_secret_arg, org.ldk.structs.Option_CVec_u8ZZ payment_metadata_arg) {
113                 long ret = bindings.RecipientOnionFields_new(payment_secret_arg.ptr, payment_metadata_arg.ptr);
114                 GC.KeepAlive(payment_secret_arg);
115                 GC.KeepAlive(payment_metadata_arg);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
119                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_secret_arg); };
120                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_metadata_arg); };
121                 return ret_hu_conv;
122         }
123
124         internal long clone_ptr() {
125                 long ret = bindings.RecipientOnionFields_clone_ptr(this.ptr);
126                 GC.KeepAlive(this);
127                 return ret;
128         }
129
130         /**
131          * Creates a copy of the RecipientOnionFields
132          */
133         public RecipientOnionFields clone() {
134                 long ret = bindings.RecipientOnionFields_clone(this.ptr);
135                 GC.KeepAlive(this);
136                 if (ret >= 0 && ret <= 4096) { return null; }
137                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
138                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
139                 return ret_hu_conv;
140         }
141
142         /**
143          * Checks if two RecipientOnionFieldss contain equal inner contents.
144          * This ignores pointers and is_owned flags and looks at the values in fields.
145          * Two objects with NULL inner values will be considered "equal" here.
146          */
147         public bool eq(org.ldk.structs.RecipientOnionFields b) {
148                 bool ret = bindings.RecipientOnionFields_eq(this.ptr, b == null ? 0 : b.ptr);
149                 GC.KeepAlive(this);
150                 GC.KeepAlive(b);
151                 if (this != null) { this.ptrs_to.AddLast(b); };
152                 return ret;
153         }
154
155         public override bool Equals(object o) {
156                 if (!(o is RecipientOnionFields)) return false;
157                 return this.eq((RecipientOnionFields)o);
158         }
159         /**
160          * Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
161          */
162         public byte[] write() {
163                 byte[] ret = bindings.RecipientOnionFields_write(this.ptr);
164                 GC.KeepAlive(this);
165                 return ret;
166         }
167
168         /**
169          * Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
170          */
171         public static Result_RecipientOnionFieldsDecodeErrorZ read(byte[] ser) {
172                 long ret = bindings.RecipientOnionFields_read(ser);
173                 GC.KeepAlive(ser);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 Result_RecipientOnionFieldsDecodeErrorZ ret_hu_conv = Result_RecipientOnionFieldsDecodeErrorZ.constr_from_ptr(ret);
176                 return ret_hu_conv;
177         }
178
179         /**
180          * Creates a [`RecipientOnionFields`] from only a [`PaymentSecret`]. This is the most common
181          * set of onion fields for today's BOLT11 invoices - most nodes require a [`PaymentSecret`]
182          * but do not require or provide any further data.
183          */
184         public static RecipientOnionFields secret_only(byte[] payment_secret) {
185                 long ret = bindings.RecipientOnionFields_secret_only(InternalUtils.check_arr_len(payment_secret, 32));
186                 GC.KeepAlive(payment_secret);
187                 if (ret >= 0 && ret <= 4096) { return null; }
188                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
189                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
190                 return ret_hu_conv;
191         }
192
193         /**
194          * Creates a new [`RecipientOnionFields`] with no fields. This generally does not create
195          * payable HTLCs except for single-path spontaneous payments, i.e. this should generally
196          * only be used for calls to [`ChannelManager::send_spontaneous_payment`]. If you are sending
197          * a spontaneous MPP this will not work as all MPP require payment secrets; you may
198          * instead want to use [`RecipientOnionFields::secret_only`].
199          * 
200          * [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
201          * [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
202          */
203         public static RecipientOnionFields spontaneous_empty() {
204                 long ret = bindings.RecipientOnionFields_spontaneous_empty();
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 org.ldk.structs.RecipientOnionFields ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RecipientOnionFields(null, ret); }
207                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
208                 return ret_hu_conv;
209         }
210
211 }
212 } } }