11d55c9646681863205f568ffbbbcc3cb1272ffc
[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                 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx);
70                 /**
71                  * Gets an arbitrary identifier describing the set of keys which are provided back to you in
72                  * some SpendableOutputDescriptor types. This should be sufficient to identify this
73                  * Sign object uniquely and lookup or re-derive its keys.
74                  */
75                 byte[] channel_keys_id();
76                 /**
77                  * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
78                  * 
79                  * Note that if signing fails or is rejected, the channel will be force-closed.
80                  * 
81                  * Policy checks should be implemented in this function, including checking the amount
82                  * sent to us and checking the HTLCs.
83                  */
84                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx);
85                 /**
86                  * Validate the counterparty's revocation.
87                  * 
88                  * This is required in order for the signer to make sure that the state has moved
89                  * forward and it is safe to sign the next counterparty commitment.
90                  */
91                 Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret);
92                 /**
93                  * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
94                  * This will only ever be called with a non-revoked commitment_tx.  This will be called with the
95                  * latest commitment_tx when we initiate a force-close.
96                  * This will be called with the previous latest, just to get claiming HTLC signatures, if we are
97                  * reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
98                  * the latest.
99                  * This may be called multiple times for the same transaction.
100                  * 
101                  * An external signer implementation should check that the commitment has not been revoked.
102                  * 
103                  * May return Err if key derivation fails.  Callers, such as ChannelMonitor, will panic in such a case.
104                  */
105                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx);
106                 /**
107                  * Create a signature for the given input in a transaction spending an HTLC transaction output
108                  * or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
109                  * 
110                  * A justice transaction may claim multiple outputs at the same time if timelocks are
111                  * similar, but only a signature for the input at index `input` should be signed for here.
112                  * It may be called multiple times for same output(s) if a fee-bump is needed with regards
113                  * to an upcoming timelock expiration.
114                  * 
115                  * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
116                  * 
117                  * per_commitment_key is revocation secret which was provided by our counterparty when they
118                  * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
119                  * not allow the spending of any funds by itself (you need our holder revocation_secret to do
120                  * so).
121                  */
122                 Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key);
123                 /**
124                  * Create a signature for the given input in a transaction spending a commitment transaction
125                  * HTLC output when our counterparty broadcasts an old state.
126                  * 
127                  * A justice transaction may claim multiple outputs at the same time if timelocks are
128                  * similar, but only a signature for the input at index `input` should be signed for here.
129                  * It may be called multiple times for same output(s) if a fee-bump is needed with regards
130                  * to an upcoming timelock expiration.
131                  * 
132                  * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
133                  * 
134                  * per_commitment_key is revocation secret which was provided by our counterparty when they
135                  * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
136                  * not allow the spending of any funds by itself (you need our holder revocation_secret to do
137                  * so).
138                  * 
139                  * htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
140                  * (which is committed to in the BIP 143 signatures).
141                  */
142                 Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc);
143                 /**
144                  * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
145                  * transaction, either offered or received.
146                  * 
147                  * Such a transaction may claim multiples offered outputs at same time if we know the
148                  * preimage for each when we create it, but only the input at index `input` should be
149                  * signed for here. It may be called multiple times for same output(s) if a fee-bump is
150                  * needed with regards to an upcoming timelock expiration.
151                  * 
152                  * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
153                  * outputs.
154                  * 
155                  * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
156                  * 
157                  * Per_commitment_point is the dynamic point corresponding to the channel state
158                  * detected onchain. It has been generated by our counterparty and is used to derive
159                  * channel state keys, which are then included in the witness script and committed to in the
160                  * BIP 143 signature.
161                  */
162                 Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc);
163                 /**
164                  * Create a signature for a (proposed) closing transaction.
165                  * 
166                  * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
167                  * chosen to forgo their output as dust.
168                  */
169                 Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx);
170                 /**
171                  * Signs a channel announcement message with our funding key, proving it comes from one
172                  * of the channel participants.
173                  * 
174                  * Note that if this fails or is rejected, the channel will not be publicly announced and
175                  * our counterparty may (though likely will not) close the channel on us for violating the
176                  * protocol.
177                  */
178                 Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
179                 /**
180                  * Set the counterparty static channel data, including basepoints,
181                  * counterparty_selected/holder_selected_contest_delay and funding outpoint.
182                  * This is done as soon as the funding outpoint is known.  Since these are static channel data,
183                  * they MUST NOT be allowed to change to different values once set.
184                  * 
185                  * channel_parameters.is_populated() MUST be true.
186                  * 
187                  * We bind holder_selected_contest_delay late here for API convenience.
188                  * 
189                  * Will be called before any signatures are applied.
190                  */
191                 void ready_channel(ChannelTransactionParameters channel_parameters);
192         }
193         private static class LDKBaseSignHolder { BaseSign held; }
194         public static BaseSign new_impl(BaseSignInterface arg, ChannelPublicKeys pubkeys) {
195                 final LDKBaseSignHolder impl_holder = new LDKBaseSignHolder();
196                 impl_holder.held = new BaseSign(new bindings.LDKBaseSign() {
197                         @Override public byte[] get_per_commitment_point(long idx) {
198                                 byte[] ret = arg.get_per_commitment_point(idx);
199                                 byte[] result = InternalUtils.check_arr_len(ret, 33);
200                                 return result;
201                         }
202                         @Override public byte[] release_commitment_secret(long idx) {
203                                 byte[] ret = arg.release_commitment_secret(idx);
204                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
205                                 return result;
206                         }
207                         @Override public long validate_holder_commitment(long holder_tx) {
208                                 HolderCommitmentTransaction holder_tx_hu_conv = null; if (holder_tx < 0 || holder_tx > 4096) { holder_tx_hu_conv = new HolderCommitmentTransaction(null, holder_tx); }
209                                 Result_NoneNoneZ ret = arg.validate_holder_commitment(holder_tx_hu_conv);
210                                 long result = ret == null ? 0 : ret.clone_ptr();
211                                 return result;
212                         }
213                         @Override public byte[] channel_keys_id() {
214                                 byte[] ret = arg.channel_keys_id();
215                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
216                                 return result;
217                         }
218                         @Override public long sign_counterparty_commitment(long commitment_tx) {
219                                 CommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new CommitmentTransaction(null, commitment_tx); }
220                                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(commitment_tx_hu_conv);
221                                 long result = ret == null ? 0 : ret.clone_ptr();
222                                 return result;
223                         }
224                         @Override public long validate_counterparty_revocation(long idx, byte[] secret) {
225                                 Result_NoneNoneZ ret = arg.validate_counterparty_revocation(idx, secret);
226                                 long result = ret == null ? 0 : ret.clone_ptr();
227                                 return result;
228                         }
229                         @Override public long sign_holder_commitment_and_htlcs(long commitment_tx) {
230                                 HolderCommitmentTransaction commitment_tx_hu_conv = null; if (commitment_tx < 0 || commitment_tx > 4096) { commitment_tx_hu_conv = new HolderCommitmentTransaction(null, commitment_tx); }
231                                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_holder_commitment_and_htlcs(commitment_tx_hu_conv);
232                                 long result = ret == null ? 0 : ret.clone_ptr();
233                                 return result;
234                         }
235                         @Override public long sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
236                                 Result_SignatureNoneZ ret = arg.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key);
237                                 long result = ret == null ? 0 : ret.clone_ptr();
238                                 return result;
239                         }
240                         @Override public long sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) {
241                                 HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); }
242                                 Result_SignatureNoneZ ret = arg.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc_hu_conv);
243                                 long result = ret == null ? 0 : ret.clone_ptr();
244                                 return result;
245                         }
246                         @Override public long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) {
247                                 HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); }
248                                 Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc_hu_conv);
249                                 long result = ret == null ? 0 : ret.clone_ptr();
250                                 return result;
251                         }
252                         @Override public long sign_closing_transaction(long closing_tx) {
253                                 ClosingTransaction closing_tx_hu_conv = null; if (closing_tx < 0 || closing_tx > 4096) { closing_tx_hu_conv = new ClosingTransaction(null, closing_tx); }
254                                 Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_hu_conv);
255                                 long result = ret == null ? 0 : ret.clone_ptr();
256                                 return result;
257                         }
258                         @Override public long sign_channel_announcement(long msg) {
259                                 UnsignedChannelAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new UnsignedChannelAnnouncement(null, msg); }
260                                 Result_SignatureNoneZ ret = arg.sign_channel_announcement(msg_hu_conv);
261                                 long result = ret == null ? 0 : ret.clone_ptr();
262                                 return result;
263                         }
264                         @Override public void ready_channel(long channel_parameters) {
265                                 ChannelTransactionParameters channel_parameters_hu_conv = null; if (channel_parameters < 0 || channel_parameters > 4096) { channel_parameters_hu_conv = new ChannelTransactionParameters(null, channel_parameters); }
266                                 arg.ready_channel(channel_parameters_hu_conv);
267                         }
268                 }, pubkeys);
269                 return impl_holder.held;
270         }
271         /**
272          * Gets the per-commitment point for a specific commitment number
273          * 
274          * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
275          */
276         public byte[] get_per_commitment_point(long idx) {
277                 byte[] ret = bindings.BaseSign_get_per_commitment_point(this.ptr, idx);
278                 Reference.reachabilityFence(this);
279                 Reference.reachabilityFence(idx);
280                 return ret;
281         }
282
283         /**
284          * Gets the commitment secret for a specific commitment number as part of the revocation process
285          * 
286          * An external signer implementation should error here if the commitment was already signed
287          * and should refuse to sign it in the future.
288          * 
289          * May be called more than once for the same index.
290          * 
291          * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
292          */
293         public byte[] release_commitment_secret(long idx) {
294                 byte[] ret = bindings.BaseSign_release_commitment_secret(this.ptr, idx);
295                 Reference.reachabilityFence(this);
296                 Reference.reachabilityFence(idx);
297                 return ret;
298         }
299
300         /**
301          * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
302          * 
303          * This is required in order for the signer to make sure that releasing a commitment
304          * secret won't leave us without a broadcastable holder transaction.
305          * Policy checks should be implemented in this function, including checking the amount
306          * sent to us and checking the HTLCs.
307          */
308         public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx) {
309                 long ret = bindings.BaseSign_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr & ~1);
310                 Reference.reachabilityFence(this);
311                 Reference.reachabilityFence(holder_tx);
312                 if (ret >= 0 && ret <= 4096) { return null; }
313                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
314                 this.ptrs_to.add(holder_tx);
315                 return ret_hu_conv;
316         }
317
318         /**
319          * Gets an arbitrary identifier describing the set of keys which are provided back to you in
320          * some SpendableOutputDescriptor types. This should be sufficient to identify this
321          * Sign object uniquely and lookup or re-derive its keys.
322          */
323         public byte[] channel_keys_id() {
324                 byte[] ret = bindings.BaseSign_channel_keys_id(this.ptr);
325                 Reference.reachabilityFence(this);
326                 return ret;
327         }
328
329         /**
330          * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
331          * 
332          * Note that if signing fails or is rejected, the channel will be force-closed.
333          * 
334          * Policy checks should be implemented in this function, including checking the amount
335          * sent to us and checking the HTLCs.
336          */
337         public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx) {
338                 long ret = bindings.BaseSign_sign_counterparty_commitment(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1);
339                 Reference.reachabilityFence(this);
340                 Reference.reachabilityFence(commitment_tx);
341                 if (ret >= 0 && ret <= 4096) { return null; }
342                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
343                 this.ptrs_to.add(commitment_tx);
344                 return ret_hu_conv;
345         }
346
347         /**
348          * Validate the counterparty's revocation.
349          * 
350          * This is required in order for the signer to make sure that the state has moved
351          * forward and it is safe to sign the next counterparty commitment.
352          */
353         public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
354                 long ret = bindings.BaseSign_validate_counterparty_revocation(this.ptr, idx, InternalUtils.check_arr_len(secret, 32));
355                 Reference.reachabilityFence(this);
356                 Reference.reachabilityFence(idx);
357                 Reference.reachabilityFence(secret);
358                 if (ret >= 0 && ret <= 4096) { return null; }
359                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
360                 return ret_hu_conv;
361         }
362
363         /**
364          * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
365          * This will only ever be called with a non-revoked commitment_tx.  This will be called with the
366          * latest commitment_tx when we initiate a force-close.
367          * This will be called with the previous latest, just to get claiming HTLC signatures, if we are
368          * reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
369          * the latest.
370          * This may be called multiple times for the same transaction.
371          * 
372          * An external signer implementation should check that the commitment has not been revoked.
373          * 
374          * May return Err if key derivation fails.  Callers, such as ChannelMonitor, will panic in such a case.
375          */
376         public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx) {
377                 long ret = bindings.BaseSign_sign_holder_commitment_and_htlcs(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1);
378                 Reference.reachabilityFence(this);
379                 Reference.reachabilityFence(commitment_tx);
380                 if (ret >= 0 && ret <= 4096) { return null; }
381                 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
382                 this.ptrs_to.add(commitment_tx);
383                 return ret_hu_conv;
384         }
385
386         /**
387          * Create a signature for the given input in a transaction spending an HTLC transaction output
388          * or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
389          * 
390          * A justice transaction may claim multiple outputs at the same time if timelocks are
391          * similar, but only a signature for the input at index `input` should be signed for here.
392          * It may be called multiple times for same output(s) if a fee-bump is needed with regards
393          * to an upcoming timelock expiration.
394          * 
395          * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
396          * 
397          * per_commitment_key is revocation secret which was provided by our counterparty when they
398          * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
399          * not allow the spending of any funds by itself (you need our holder revocation_secret to do
400          * so).
401          */
402         public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
403                 long ret = bindings.BaseSign_sign_justice_revoked_output(this.ptr, justice_tx, input, amount, InternalUtils.check_arr_len(per_commitment_key, 32));
404                 Reference.reachabilityFence(this);
405                 Reference.reachabilityFence(justice_tx);
406                 Reference.reachabilityFence(input);
407                 Reference.reachabilityFence(amount);
408                 Reference.reachabilityFence(per_commitment_key);
409                 if (ret >= 0 && ret <= 4096) { return null; }
410                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
411                 return ret_hu_conv;
412         }
413
414         /**
415          * Create a signature for the given input in a transaction spending a commitment transaction
416          * HTLC output when our counterparty broadcasts an old state.
417          * 
418          * A justice transaction may claim multiple outputs at the same time if timelocks are
419          * similar, but only a signature for the input at index `input` should be signed for here.
420          * It may be called multiple times for same output(s) if a fee-bump is needed with regards
421          * to an upcoming timelock expiration.
422          * 
423          * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
424          * 
425          * per_commitment_key is revocation secret which was provided by our counterparty when they
426          * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
427          * not allow the spending of any funds by itself (you need our holder revocation_secret to do
428          * so).
429          * 
430          * htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
431          * (which is committed to in the BIP 143 signatures).
432          */
433         public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) {
434                 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 & ~1);
435                 Reference.reachabilityFence(this);
436                 Reference.reachabilityFence(justice_tx);
437                 Reference.reachabilityFence(input);
438                 Reference.reachabilityFence(amount);
439                 Reference.reachabilityFence(per_commitment_key);
440                 Reference.reachabilityFence(htlc);
441                 if (ret >= 0 && ret <= 4096) { return null; }
442                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
443                 this.ptrs_to.add(htlc);
444                 return ret_hu_conv;
445         }
446
447         /**
448          * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
449          * transaction, either offered or received.
450          * 
451          * Such a transaction may claim multiples offered outputs at same time if we know the
452          * preimage for each when we create it, but only the input at index `input` should be
453          * signed for here. It may be called multiple times for same output(s) if a fee-bump is
454          * needed with regards to an upcoming timelock expiration.
455          * 
456          * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
457          * outputs.
458          * 
459          * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
460          * 
461          * Per_commitment_point is the dynamic point corresponding to the channel state
462          * detected onchain. It has been generated by our counterparty and is used to derive
463          * channel state keys, which are then included in the witness script and committed to in the
464          * BIP 143 signature.
465          */
466         public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) {
467                 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 & ~1);
468                 Reference.reachabilityFence(this);
469                 Reference.reachabilityFence(htlc_tx);
470                 Reference.reachabilityFence(input);
471                 Reference.reachabilityFence(amount);
472                 Reference.reachabilityFence(per_commitment_point);
473                 Reference.reachabilityFence(htlc);
474                 if (ret >= 0 && ret <= 4096) { return null; }
475                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
476                 this.ptrs_to.add(htlc);
477                 return ret_hu_conv;
478         }
479
480         /**
481          * Create a signature for a (proposed) closing transaction.
482          * 
483          * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
484          * chosen to forgo their output as dust.
485          */
486         public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx) {
487                 long ret = bindings.BaseSign_sign_closing_transaction(this.ptr, closing_tx == null ? 0 : closing_tx.ptr & ~1);
488                 Reference.reachabilityFence(this);
489                 Reference.reachabilityFence(closing_tx);
490                 if (ret >= 0 && ret <= 4096) { return null; }
491                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
492                 this.ptrs_to.add(closing_tx);
493                 return ret_hu_conv;
494         }
495
496         /**
497          * Signs a channel announcement message with our funding key, proving it comes from one
498          * of the channel participants.
499          * 
500          * Note that if this fails or is rejected, the channel will not be publicly announced and
501          * our counterparty may (though likely will not) close the channel on us for violating the
502          * protocol.
503          */
504         public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
505                 long ret = bindings.BaseSign_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
506                 Reference.reachabilityFence(this);
507                 Reference.reachabilityFence(msg);
508                 if (ret >= 0 && ret <= 4096) { return null; }
509                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
510                 this.ptrs_to.add(msg);
511                 return ret_hu_conv;
512         }
513
514         /**
515          * Set the counterparty static channel data, including basepoints,
516          * counterparty_selected/holder_selected_contest_delay and funding outpoint.
517          * This is done as soon as the funding outpoint is known.  Since these are static channel data,
518          * they MUST NOT be allowed to change to different values once set.
519          * 
520          * channel_parameters.is_populated() MUST be true.
521          * 
522          * We bind holder_selected_contest_delay late here for API convenience.
523          * 
524          * Will be called before any signatures are applied.
525          */
526         public void ready_channel(ChannelTransactionParameters channel_parameters) {
527                 bindings.BaseSign_ready_channel(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr & ~1);
528                 Reference.reachabilityFence(this);
529                 Reference.reachabilityFence(channel_parameters);
530                 this.ptrs_to.add(channel_parameters);
531         }
532
533         /**
534          * Frees any resources associated with this object given its this_arg pointer.
535          * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
536          */
537         public ChannelPublicKeys get_pubkeys() {
538                 long ret = bindings.BaseSign_get_pubkeys(this.ptr);
539                 Reference.reachabilityFence(this);
540                 if (ret >= 0 && ret <= 4096) { return null; }
541                 ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelPublicKeys(null, ret); }
542                 ret_hu_conv.ptrs_to.add(this);
543                 return ret_hu_conv;
544         }
545
546 }