6 namespace org { namespace ldk { namespace structs {
10 * Information which is provided, encrypted, to the payment recipient when sending HTLCs.
12 * This should generally be constructed with data communicated to us from the recipient (via a
13 * BOLT11 or BOLT12 invoice).
15 public class RecipientOnionFields : CommonBase {
16 internal RecipientOnionFields(object _dummy, long ptr) : base(ptr) { }
17 ~RecipientOnionFields() {
18 if (ptr != 0) { bindings.RecipientOnionFields_free(ptr); }
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)
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.
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.
34 public Option_ThirtyTwoBytesZ get_payment_secret() {
35 long ret = bindings.RecipientOnionFields_get_payment_secret(this.ptr);
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); };
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)
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.
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.
56 public void set_payment_secret(org.ldk.structs.Option_ThirtyTwoBytesZ val) {
57 bindings.RecipientOnionFields_set_payment_secret(this.ptr, val.ptr);
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
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.
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.
76 * Returns a copy of the field.
78 public Option_CVec_u8ZZ get_payment_metadata() {
79 long ret = bindings.RecipientOnionFields_get_payment_metadata(this.ptr);
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); };
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
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.
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.
101 public void set_payment_metadata(org.ldk.structs.Option_CVec_u8ZZ val) {
102 bindings.RecipientOnionFields_set_payment_metadata(this.ptr, val.ptr);
107 internal long clone_ptr() {
108 long ret = bindings.RecipientOnionFields_clone_ptr(this.ptr);
114 * Creates a copy of the RecipientOnionFields
116 public RecipientOnionFields clone() {
117 long ret = bindings.RecipientOnionFields_clone(this.ptr);
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); };
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.
130 public bool eq(org.ldk.structs.RecipientOnionFields b) {
131 bool ret = bindings.RecipientOnionFields_eq(this.ptr, b.ptr);
134 if (this != null) { this.ptrs_to.AddLast(b); };
138 public override bool Equals(object o) {
139 if (!(o is RecipientOnionFields)) return false;
140 return this.eq((RecipientOnionFields)o);
143 * Serialize the RecipientOnionFields object into a byte array which can be read by RecipientOnionFields_read
145 public byte[] write() {
146 long ret = bindings.RecipientOnionFields_write(this.ptr);
148 if (ret >= 0 && ret <= 4096) { return null; }
149 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
154 * Read a RecipientOnionFields from a byte array, created by RecipientOnionFields_write
156 public static Result_RecipientOnionFieldsDecodeErrorZ read(byte[] ser) {
157 long ret = bindings.RecipientOnionFields_read(InternalUtils.encodeUint8Array(ser));
159 if (ret >= 0 && ret <= 4096) { return null; }
160 Result_RecipientOnionFieldsDecodeErrorZ ret_hu_conv = Result_RecipientOnionFieldsDecodeErrorZ.constr_from_ptr(ret);
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.
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); };
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`].
185 * [`ChannelManager::send_spontaneous_payment`]: super::channelmanager::ChannelManager::send_spontaneous_payment
186 * [`RecipientOnionFields::secret_only`]: RecipientOnionFields::secret_only
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); };
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(())`.
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.
205 * See [`Self::custom_tlvs`] for more info.
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)));
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);
218 * Gets the custom TLVs that will be sent or have been received.
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.
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`].
229 public TwoTuple_u64CVec_u8ZZ[] custom_tlvs() {
230 long ret = bindings.RecipientOnionFields_custom_tlvs(this.ptr);
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;
241 bindings.free_buffer(ret);
242 return ret_conv_23_arr;