ec7aa54a9001dd3062b77c7011b375252e0488ac
[ldk-java] / src / main / java / org / ldk / structs / BaseSign.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10 /**
11  * A trait to sign Lightning channel transactions as described in
12  * [BOLT 3](https://github.com/lightning/bolts/blob/master/03-transactions.md).
13  * 
14  * Signing services could be implemented on a hardware wallet and should implement signing
15  * policies in order to be secure. Please refer to the [VLS Policy
16  * Controls](https://gitlab.com/lightning-signer/validating-lightning-signer/-/blob/main/docs/policy-controls.md)
17  * for an example of such policies.
18  */
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class BaseSign extends CommonBase {
21         final bindings.LDKBaseSign bindings_instance;
22         BaseSign(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
23         private BaseSign(bindings.LDKBaseSign arg, ChannelPublicKeys pubkeys) {
24                 super(bindings.LDKBaseSign_new(arg, pubkeys == null ? 0 : pubkeys.clone_ptr()));
25                 this.ptrs_to.add(arg);
26                 this.bindings_instance = arg;
27         }
28         @Override @SuppressWarnings("deprecation")
29         protected void finalize() throws Throwable {
30                 if (ptr != 0) { bindings.BaseSign_free(ptr); } super.finalize();
31         }
32
33         public static interface BaseSignInterface {
34                 /**
35                  * Gets the per-commitment point for a specific commitment number
36                  * 
37                  * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
38                  */
39                 byte[] get_per_commitment_point(long idx);
40                 /**
41                  * Gets the commitment secret for a specific commitment number as part of the revocation process
42                  * 
43                  * An external signer implementation should error here if the commitment was already signed
44                  * and should refuse to sign it in the future.
45                  * 
46                  * May be called more than once for the same index.
47                  * 
48                  * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
49                  */
50                 byte[] release_commitment_secret(long idx);
51                 /**
52                  * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
53                  * 
54                  * This is required in order for the signer to make sure that releasing a commitment
55                  * secret won't leave us without a broadcastable holder transaction.
56                  * Policy checks should be implemented in this function, including checking the amount
57                  * sent to us and checking the HTLCs.
58                  * 
59                  * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
60                  * A validating signer should ensure that an HTLC output is removed only when the matching
61                  * preimage is provided, or when the value to holder is restored.
62                  * 
63                  * Note that all the relevant preimages will be provided, but there may also be additional
64                  * irrelevant or duplicate preimages.
65                  */
66                 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages);
67                 /**
68                  * Returns an arbitrary identifier describing the set of keys which are provided back to you in
69                  * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
70                  * [`BaseSign`] object uniquely and lookup or re-derive its keys.
71                  */
72                 byte[] channel_keys_id();
73                 /**
74                  * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
75                  * 
76                  * Note that if signing fails or is rejected, the channel will be force-closed.
77                  * 
78                  * Policy checks should be implemented in this function, including checking the amount
79                  * sent to us and checking the HTLCs.
80                  * 
81                  * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
82                  * A validating signer should ensure that an HTLC output is removed only when the matching
83                  * preimage is provided, or when the value to holder is restored.
84                  * 
85                  * Note that all the relevant preimages will be provided, but there may also be additional
86                  * irrelevant or duplicate preimages.
87                  */
88                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages);
89                 /**
90                  * Validate the counterparty's revocation.
91                  * 
92                  * This is required in order for the signer to make sure that the state has moved
93                  * forward and it is safe to sign the next counterparty commitment.
94                  */
95                 Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret);
96                 /**
97                  * Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
98                  * 
99                  * This will be called
100                  * - with a non-revoked `commitment_tx`.
101                  * - with the latest `commitment_tx` when we initiate a force-close.
102                  * - with the previous `commitment_tx`, just to get claiming HTLC
103                  * signatures, if we are reacting to a [`ChannelMonitor`]
104                  * [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
105                  * that decided to broadcast before it had been updated to the latest `commitment_tx`.
106                  * 
107                  * This may be called multiple times for the same transaction.
108                  * 
109                  * An external signer implementation should check that the commitment has not been revoked.
110                  * 
111                  * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
112                  */
113                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx);
114                 /**
115                  * Create a signature for the given input in a transaction spending an HTLC transaction output
116                  * or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
117                  * 
118                  * A justice transaction may claim multiple outputs at the same time if timelocks are
119                  * similar, but only a signature for the input at index `input` should be signed for here.
120                  * It may be called multiple times for same output(s) if a fee-bump is needed with regards
121                  * to an upcoming timelock expiration.
122                  * 
123                  * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
124                  * 
125                  * `per_commitment_key` is revocation secret which was provided by our counterparty when they
126                  * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
127                  * not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
128                  * so).
129                  */
130                 Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key);
131                 /**
132                  * Create a signature for the given input in a transaction spending a commitment transaction
133                  * HTLC output when our counterparty broadcasts an old state.
134                  * 
135                  * A justice transaction may claim multiple outputs at the same time if timelocks are
136                  * similar, but only a signature for the input at index `input` should be signed for here.
137                  * It may be called multiple times for same output(s) if a fee-bump is needed with regards
138                  * to an upcoming timelock expiration.
139                  * 
140                  * `amount` is the value of the output spent by this input, committed to in the BIP 143
141                  * signature.
142                  * 
143                  * `per_commitment_key` is revocation secret which was provided by our counterparty when they
144                  * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
145                  * not allow the spending of any funds by itself (you need our holder revocation_secret to do
146                  * so).
147                  * 
148                  * `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
149                  * (which is committed to in the BIP 143 signatures).
150                  */
151                 Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc);
152                 /**
153                  * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
154                  * transaction, either offered or received.
155                  * 
156                  * Such a transaction may claim multiples offered outputs at same time if we know the
157                  * preimage for each when we create it, but only the input at index `input` should be
158                  * signed for here. It may be called multiple times for same output(s) if a fee-bump is
159                  * needed with regards to an upcoming timelock expiration.
160                  * 
161                  * `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
162                  * outputs.
163                  * 
164                  * `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
165                  * 
166                  * `per_commitment_point` is the dynamic point corresponding to the channel state
167                  * detected onchain. It has been generated by our counterparty and is used to derive
168                  * channel state keys, which are then included in the witness script and committed to in the
169                  * BIP 143 signature.
170                  */
171                 Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc);
172                 /**
173                  * Create a signature for a (proposed) closing transaction.
174                  * 
175                  * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
176                  * chosen to forgo their output as dust.
177                  */
178                 Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx);
179                 /**
180                  * Computes the signature for a commitment transaction's anchor output used as an
181                  * input within `anchor_tx`, which spends the commitment transaction, at index `input`.
182                  */
183                 Result_SignatureNoneZ sign_holder_anchor_input(byte[] anchor_tx, long input);
184                 /**
185                  * Signs a channel announcement message with our funding key and our node secret key (aka
186                  * node_id or network_key), proving it comes from one of the channel participants.
187                  * 
188                  * The first returned signature should be from our node secret key, the second from our
189                  * funding key.
190                  * 
191                  * Note that if this fails or is rejected, the channel will not be publicly announced and
192                  * our counterparty may (though likely will not) close the channel on us for violating the
193                  * protocol.
194                  */
195                 Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
196                 /**
197                  * Set the counterparty static channel data, including basepoints,
198                  * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint. Since these
199                  * are static channel data, they MUST NOT be allowed to change to different values once set,
200                  * as LDK may call this method more than once.
201                  * 
202                  * channel_parameters.is_populated() MUST be true.
203                  */
204                 void provide_channel_parameters(ChannelTransactionParameters channel_parameters);
205         }
206         private static class LDKBaseSignHolder { BaseSign held; }
207         public static BaseSign new_impl(BaseSignInterface arg, ChannelPublicKeys pubkeys) {
208                 final LDKBaseSignHolder impl_holder = new LDKBaseSignHolder();
209                 impl_holder.held = new BaseSign(new bindings.LDKBaseSign() {
210                         @Override public byte[] get_per_commitment_point(long idx) {
211                                 byte[] ret = arg.get_per_commitment_point(idx);
212                                 Reference.reachabilityFence(arg);
213                                 byte[] result = InternalUtils.check_arr_len(ret, 33);
214                                 return result;
215                         }
216                         @Override public byte[] release_commitment_secret(long idx) {
217                                 byte[] ret = arg.release_commitment_secret(idx);
218                                 Reference.reachabilityFence(arg);
219                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
220                                 return result;
221                         }
222                         @Override public long validate_holder_commitment(long holder_tx, byte[][] preimages) {
223                                 org.ldk.structs.HolderCommitmentTransaction holder_tx_hu_conv = null; if (holder_tx < 0 || holder_tx > 4096) { holder_tx_hu_conv = new org.ldk.structs.HolderCommitmentTransaction(null, holder_tx); }
224                                 Result_NoneNoneZ ret = arg.validate_holder_commitment(holder_tx_hu_conv, preimages);
225                                 Reference.reachabilityFence(arg);
226                                 long result = ret == null ? 0 : ret.clone_ptr();
227                                 return result;
228                         }
229                         @Override public byte[] channel_keys_id() {
230                                 byte[] ret = arg.channel_keys_id();
231                                 Reference.reachabilityFence(arg);
232                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
233                                 return result;
234                         }
235                         @Override public long sign_counterparty_commitment(long commitment_tx, byte[][] preimages) {
236                                 org.ldk.structs.CommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new org.ldk.structs.CommitmentTransaction(null, commitment_tx); }
237                                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(commitment_tx_hu_conv, preimages);
238                                 Reference.reachabilityFence(arg);
239                                 long result = ret == null ? 0 : ret.clone_ptr();
240                                 return result;
241                         }
242                         @Override public long validate_counterparty_revocation(long idx, byte[] secret) {
243                                 Result_NoneNoneZ ret = arg.validate_counterparty_revocation(idx, secret);
244                                 Reference.reachabilityFence(arg);
245                                 long result = ret == null ? 0 : ret.clone_ptr();
246                                 return result;
247                         }
248                         @Override public long sign_holder_commitment_and_htlcs(long commitment_tx) {
249                                 org.ldk.structs.HolderCommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new org.ldk.structs.HolderCommitmentTransaction(null, commitment_tx); }
250                                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_holder_commitment_and_htlcs(commitment_tx_hu_conv);
251                                 Reference.reachabilityFence(arg);
252                                 long result = ret == null ? 0 : ret.clone_ptr();
253                                 return result;
254                         }
255                         @Override public long sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
256                                 Result_SignatureNoneZ ret = arg.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key);
257                                 Reference.reachabilityFence(arg);
258                                 long result = ret == null ? 0 : ret.clone_ptr();
259                                 return result;
260                         }
261                         @Override public long sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) {
262                                 org.ldk.structs.HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, htlc); }
263                                 Result_SignatureNoneZ ret = arg.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc_hu_conv);
264                                 Reference.reachabilityFence(arg);
265                                 long result = ret == null ? 0 : ret.clone_ptr();
266                                 return result;
267                         }
268                         @Override public long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) {
269                                 org.ldk.structs.HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, htlc); }
270                                 Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc_hu_conv);
271                                 Reference.reachabilityFence(arg);
272                                 long result = ret == null ? 0 : ret.clone_ptr();
273                                 return result;
274                         }
275                         @Override public long sign_closing_transaction(long closing_tx) {
276                                 org.ldk.structs.ClosingTransaction closing_tx_hu_conv = null; if (closing_tx < 0 || closing_tx > 4096) { closing_tx_hu_conv = new org.ldk.structs.ClosingTransaction(null, closing_tx); }
277                                 Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_hu_conv);
278                                 Reference.reachabilityFence(arg);
279                                 long result = ret == null ? 0 : ret.clone_ptr();
280                                 return result;
281                         }
282                         @Override public long sign_holder_anchor_input(byte[] anchor_tx, long input) {
283                                 Result_SignatureNoneZ ret = arg.sign_holder_anchor_input(anchor_tx, input);
284                                 Reference.reachabilityFence(arg);
285                                 long result = ret == null ? 0 : ret.clone_ptr();
286                                 return result;
287                         }
288                         @Override public long sign_channel_announcement(long msg) {
289                                 org.ldk.structs.UnsignedChannelAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UnsignedChannelAnnouncement(null, msg); }
290                                 Result_C2Tuple_SignatureSignatureZNoneZ ret = arg.sign_channel_announcement(msg_hu_conv);
291                                 Reference.reachabilityFence(arg);
292                                 long result = ret == null ? 0 : ret.clone_ptr();
293                                 return result;
294                         }
295                         @Override public void provide_channel_parameters(long channel_parameters) {
296                                 org.ldk.structs.ChannelTransactionParameters channel_parameters_hu_conv = null; if (channel_parameters < 0 || channel_parameters > 4096) { channel_parameters_hu_conv = new org.ldk.structs.ChannelTransactionParameters(null, channel_parameters); }
297                                 arg.provide_channel_parameters(channel_parameters_hu_conv);
298                                 Reference.reachabilityFence(arg);
299                         }
300                 }, pubkeys);
301                 return impl_holder.held;
302         }
303         /**
304          * Gets the per-commitment point for a specific commitment number
305          * 
306          * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
307          */
308         public byte[] get_per_commitment_point(long idx) {
309                 byte[] ret = bindings.BaseSign_get_per_commitment_point(this.ptr, idx);
310                 Reference.reachabilityFence(this);
311                 Reference.reachabilityFence(idx);
312                 return ret;
313         }
314
315         /**
316          * Gets the commitment secret for a specific commitment number as part of the revocation process
317          * 
318          * An external signer implementation should error here if the commitment was already signed
319          * and should refuse to sign it in the future.
320          * 
321          * May be called more than once for the same index.
322          * 
323          * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
324          */
325         public byte[] release_commitment_secret(long idx) {
326                 byte[] ret = bindings.BaseSign_release_commitment_secret(this.ptr, idx);
327                 Reference.reachabilityFence(this);
328                 Reference.reachabilityFence(idx);
329                 return ret;
330         }
331
332         /**
333          * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
334          * 
335          * This is required in order for the signer to make sure that releasing a commitment
336          * secret won't leave us without a broadcastable holder transaction.
337          * Policy checks should be implemented in this function, including checking the amount
338          * sent to us and checking the HTLCs.
339          * 
340          * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
341          * A validating signer should ensure that an HTLC output is removed only when the matching
342          * preimage is provided, or when the value to holder is restored.
343          * 
344          * Note that all the relevant preimages will be provided, but there may also be additional
345          * irrelevant or duplicate preimages.
346          */
347         public Result_NoneNoneZ validate_holder_commitment(org.ldk.structs.HolderCommitmentTransaction holder_tx, byte[][] preimages) {
348                 long ret = bindings.BaseSign_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr, preimages != null ? Arrays.stream(preimages).map(preimages_conv_8 -> InternalUtils.check_arr_len(preimages_conv_8, 32)).toArray(byte[][]::new) : null);
349                 Reference.reachabilityFence(this);
350                 Reference.reachabilityFence(holder_tx);
351                 Reference.reachabilityFence(preimages);
352                 if (ret >= 0 && ret <= 4096) { return null; }
353                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
354                 if (this != null) { this.ptrs_to.add(holder_tx); };
355                 return ret_hu_conv;
356         }
357
358         /**
359          * Returns an arbitrary identifier describing the set of keys which are provided back to you in
360          * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
361          * [`BaseSign`] object uniquely and lookup or re-derive its keys.
362          */
363         public byte[] channel_keys_id() {
364                 byte[] ret = bindings.BaseSign_channel_keys_id(this.ptr);
365                 Reference.reachabilityFence(this);
366                 return ret;
367         }
368
369         /**
370          * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
371          * 
372          * Note that if signing fails or is rejected, the channel will be force-closed.
373          * 
374          * Policy checks should be implemented in this function, including checking the amount
375          * sent to us and checking the HTLCs.
376          * 
377          * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
378          * A validating signer should ensure that an HTLC output is removed only when the matching
379          * preimage is provided, or when the value to holder is restored.
380          * 
381          * Note that all the relevant preimages will be provided, but there may also be additional
382          * irrelevant or duplicate preimages.
383          */
384         public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(org.ldk.structs.CommitmentTransaction commitment_tx, byte[][] preimages) {
385                 long ret = bindings.BaseSign_sign_counterparty_commitment(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr, preimages != null ? Arrays.stream(preimages).map(preimages_conv_8 -> InternalUtils.check_arr_len(preimages_conv_8, 32)).toArray(byte[][]::new) : null);
386                 Reference.reachabilityFence(this);
387                 Reference.reachabilityFence(commitment_tx);
388                 Reference.reachabilityFence(preimages);
389                 if (ret >= 0 && ret <= 4096) { return null; }
390                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
391                 if (this != null) { this.ptrs_to.add(commitment_tx); };
392                 return ret_hu_conv;
393         }
394
395         /**
396          * Validate the counterparty's revocation.
397          * 
398          * This is required in order for the signer to make sure that the state has moved
399          * forward and it is safe to sign the next counterparty commitment.
400          */
401         public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
402                 long ret = bindings.BaseSign_validate_counterparty_revocation(this.ptr, idx, InternalUtils.check_arr_len(secret, 32));
403                 Reference.reachabilityFence(this);
404                 Reference.reachabilityFence(idx);
405                 Reference.reachabilityFence(secret);
406                 if (ret >= 0 && ret <= 4096) { return null; }
407                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
408                 return ret_hu_conv;
409         }
410
411         /**
412          * Creates a signature for a holder's commitment transaction and its claiming HTLC transactions.
413          * 
414          * This will be called
415          * - with a non-revoked `commitment_tx`.
416          * - with the latest `commitment_tx` when we initiate a force-close.
417          * - with the previous `commitment_tx`, just to get claiming HTLC
418          * signatures, if we are reacting to a [`ChannelMonitor`]
419          * [replica](https://github.com/lightningdevkit/rust-lightning/blob/main/GLOSSARY.md#monitor-replicas)
420          * that decided to broadcast before it had been updated to the latest `commitment_tx`.
421          * 
422          * This may be called multiple times for the same transaction.
423          * 
424          * An external signer implementation should check that the commitment has not been revoked.
425          * 
426          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
427          */
428         public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(org.ldk.structs.HolderCommitmentTransaction commitment_tx) {
429                 long ret = bindings.BaseSign_sign_holder_commitment_and_htlcs(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr);
430                 Reference.reachabilityFence(this);
431                 Reference.reachabilityFence(commitment_tx);
432                 if (ret >= 0 && ret <= 4096) { return null; }
433                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
434                 if (this != null) { this.ptrs_to.add(commitment_tx); };
435                 return ret_hu_conv;
436         }
437
438         /**
439          * Create a signature for the given input in a transaction spending an HTLC transaction output
440          * or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
441          * 
442          * A justice transaction may claim multiple outputs at the same time if timelocks are
443          * similar, but only a signature for the input at index `input` should be signed for here.
444          * It may be called multiple times for same output(s) if a fee-bump is needed with regards
445          * to an upcoming timelock expiration.
446          * 
447          * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
448          * 
449          * `per_commitment_key` is revocation secret which was provided by our counterparty when they
450          * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
451          * not allow the spending of any funds by itself (you need our holder `revocation_secret` to do
452          * so).
453          */
454         public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
455                 long ret = bindings.BaseSign_sign_justice_revoked_output(this.ptr, justice_tx, input, amount, InternalUtils.check_arr_len(per_commitment_key, 32));
456                 Reference.reachabilityFence(this);
457                 Reference.reachabilityFence(justice_tx);
458                 Reference.reachabilityFence(input);
459                 Reference.reachabilityFence(amount);
460                 Reference.reachabilityFence(per_commitment_key);
461                 if (ret >= 0 && ret <= 4096) { return null; }
462                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
463                 return ret_hu_conv;
464         }
465
466         /**
467          * Create a signature for the given input in a transaction spending a commitment transaction
468          * HTLC output when our counterparty broadcasts an old state.
469          * 
470          * A justice transaction may claim multiple outputs at the same time if timelocks are
471          * similar, but only a signature for the input at index `input` should be signed for here.
472          * It may be called multiple times for same output(s) if a fee-bump is needed with regards
473          * to an upcoming timelock expiration.
474          * 
475          * `amount` is the value of the output spent by this input, committed to in the BIP 143
476          * signature.
477          * 
478          * `per_commitment_key` is revocation secret which was provided by our counterparty when they
479          * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
480          * not allow the spending of any funds by itself (you need our holder revocation_secret to do
481          * so).
482          * 
483          * `htlc` holds HTLC elements (hash, timelock), thus changing the format of the witness script
484          * (which is committed to in the BIP 143 signatures).
485          */
486         public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, org.ldk.structs.HTLCOutputInCommitment htlc) {
487                 long ret = bindings.BaseSign_sign_justice_revoked_htlc(this.ptr, justice_tx, input, amount, InternalUtils.check_arr_len(per_commitment_key, 32), htlc == null ? 0 : htlc.ptr);
488                 Reference.reachabilityFence(this);
489                 Reference.reachabilityFence(justice_tx);
490                 Reference.reachabilityFence(input);
491                 Reference.reachabilityFence(amount);
492                 Reference.reachabilityFence(per_commitment_key);
493                 Reference.reachabilityFence(htlc);
494                 if (ret >= 0 && ret <= 4096) { return null; }
495                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
496                 if (this != null) { this.ptrs_to.add(htlc); };
497                 return ret_hu_conv;
498         }
499
500         /**
501          * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
502          * transaction, either offered or received.
503          * 
504          * Such a transaction may claim multiples offered outputs at same time if we know the
505          * preimage for each when we create it, but only the input at index `input` should be
506          * signed for here. It may be called multiple times for same output(s) if a fee-bump is
507          * needed with regards to an upcoming timelock expiration.
508          * 
509          * `witness_script` is either an offered or received script as defined in BOLT3 for HTLC
510          * outputs.
511          * 
512          * `amount` is value of the output spent by this input, committed to in the BIP 143 signature.
513          * 
514          * `per_commitment_point` is the dynamic point corresponding to the channel state
515          * detected onchain. It has been generated by our counterparty and is used to derive
516          * channel state keys, which are then included in the witness script and committed to in the
517          * BIP 143 signature.
518          */
519         public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, org.ldk.structs.HTLCOutputInCommitment htlc) {
520                 long ret = bindings.BaseSign_sign_counterparty_htlc_transaction(this.ptr, htlc_tx, input, amount, InternalUtils.check_arr_len(per_commitment_point, 33), htlc == null ? 0 : htlc.ptr);
521                 Reference.reachabilityFence(this);
522                 Reference.reachabilityFence(htlc_tx);
523                 Reference.reachabilityFence(input);
524                 Reference.reachabilityFence(amount);
525                 Reference.reachabilityFence(per_commitment_point);
526                 Reference.reachabilityFence(htlc);
527                 if (ret >= 0 && ret <= 4096) { return null; }
528                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
529                 if (this != null) { this.ptrs_to.add(htlc); };
530                 return ret_hu_conv;
531         }
532
533         /**
534          * Create a signature for a (proposed) closing transaction.
535          * 
536          * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
537          * chosen to forgo their output as dust.
538          */
539         public Result_SignatureNoneZ sign_closing_transaction(org.ldk.structs.ClosingTransaction closing_tx) {
540                 long ret = bindings.BaseSign_sign_closing_transaction(this.ptr, closing_tx == null ? 0 : closing_tx.ptr);
541                 Reference.reachabilityFence(this);
542                 Reference.reachabilityFence(closing_tx);
543                 if (ret >= 0 && ret <= 4096) { return null; }
544                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
545                 if (this != null) { this.ptrs_to.add(closing_tx); };
546                 return ret_hu_conv;
547         }
548
549         /**
550          * Computes the signature for a commitment transaction's anchor output used as an
551          * input within `anchor_tx`, which spends the commitment transaction, at index `input`.
552          */
553         public Result_SignatureNoneZ sign_holder_anchor_input(byte[] anchor_tx, long input) {
554                 long ret = bindings.BaseSign_sign_holder_anchor_input(this.ptr, anchor_tx, input);
555                 Reference.reachabilityFence(this);
556                 Reference.reachabilityFence(anchor_tx);
557                 Reference.reachabilityFence(input);
558                 if (ret >= 0 && ret <= 4096) { return null; }
559                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
560                 return ret_hu_conv;
561         }
562
563         /**
564          * Signs a channel announcement message with our funding key and our node secret key (aka
565          * node_id or network_key), proving it comes from one of the channel participants.
566          * 
567          * The first returned signature should be from our node secret key, the second from our
568          * funding key.
569          * 
570          * Note that if this fails or is rejected, the channel will not be publicly announced and
571          * our counterparty may (though likely will not) close the channel on us for violating the
572          * protocol.
573          */
574         public Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(org.ldk.structs.UnsignedChannelAnnouncement msg) {
575                 long ret = bindings.BaseSign_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr);
576                 Reference.reachabilityFence(this);
577                 Reference.reachabilityFence(msg);
578                 if (ret >= 0 && ret <= 4096) { return null; }
579                 Result_C2Tuple_SignatureSignatureZNoneZ ret_hu_conv = Result_C2Tuple_SignatureSignatureZNoneZ.constr_from_ptr(ret);
580                 if (this != null) { this.ptrs_to.add(msg); };
581                 return ret_hu_conv;
582         }
583
584         /**
585          * Set the counterparty static channel data, including basepoints,
586          * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint. Since these
587          * are static channel data, they MUST NOT be allowed to change to different values once set,
588          * as LDK may call this method more than once.
589          * 
590          * channel_parameters.is_populated() MUST be true.
591          */
592         public void provide_channel_parameters(org.ldk.structs.ChannelTransactionParameters channel_parameters) {
593                 bindings.BaseSign_provide_channel_parameters(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr);
594                 Reference.reachabilityFence(this);
595                 Reference.reachabilityFence(channel_parameters);
596                 if (this != null) { this.ptrs_to.add(channel_parameters); };
597         }
598
599         /**
600          * Frees any resources associated with this object given its this_arg pointer.
601          * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
602          */
603         public ChannelPublicKeys get_pubkeys() {
604                 long ret = bindings.BaseSign_get_pubkeys(this.ptr);
605                 Reference.reachabilityFence(this);
606                 if (ret >= 0 && ret <= 4096) { return null; }
607                 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
608                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
609                 return ret_hu_conv;
610         }
611
612 }