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