1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
11 * A trait to sign lightning channel transactions as described in BOLT 3.
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.
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.
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.
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;
38 @Override @SuppressWarnings("deprecation")
39 protected void finalize() throws Throwable {
40 if (ptr != 0) { bindings.BaseSign_free(ptr); } super.finalize();
43 public static interface BaseSignInterface {
45 * Gets the per-commitment point for a specific commitment number
47 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
49 byte[] get_per_commitment_point(long idx);
51 * Gets the commitment secret for a specific commitment number as part of the revocation process
53 * An external signer implementation should error here if the commitment was already signed
54 * and should refuse to sign it in the future.
56 * May be called more than once for the same index.
58 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
60 byte[] release_commitment_secret(long idx);
62 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
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.
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.
73 * NOTE: all the relevant preimages will be provided, but there may also be additional
74 * irrelevant or duplicate preimages.
76 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages);
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.
82 byte[] channel_keys_id();
84 * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
86 * Note that if signing fails or is rejected, the channel will be force-closed.
88 * Policy checks should be implemented in this function, including checking the amount
89 * sent to us and checking the HTLCs.
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.
95 * NOTE: all the relevant preimages will be provided, but there may also be additional
96 * irrelevant or duplicate preimages.
98 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages);
100 * Validate the counterparty's revocation.
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.
105 Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret);
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
113 * This may be called multiple times for the same transaction.
115 * An external signer implementation should check that the commitment has not been revoked.
117 * May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case.
119 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx);
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.
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.
129 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
136 Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key);
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.
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.
146 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
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).
156 Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc);
158 * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
159 * transaction, either offered or received.
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.
166 * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
169 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
176 Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc);
178 * Create a signature for a (proposed) closing transaction.
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.
183 Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx);
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.
188 * The first returned signature should be from our node secret key, the second from our
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
195 Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
197 * Set the counterparty static channel data, including basepoints,
198 * counterparty_selected/holder_selected_contest_delay and funding outpoint.
199 * This is done as soon as the funding outpoint is known. Since these are static channel data,
200 * they MUST NOT be allowed to change to different values once set.
202 * channel_parameters.is_populated() MUST be true.
204 * We bind holder_selected_contest_delay late here for API convenience.
206 * Will be called before any signatures are applied.
208 void ready_channel(ChannelTransactionParameters channel_parameters);
210 private static class LDKBaseSignHolder { BaseSign held; }
211 public static BaseSign new_impl(BaseSignInterface arg, ChannelPublicKeys pubkeys) {
212 final LDKBaseSignHolder impl_holder = new LDKBaseSignHolder();
213 impl_holder.held = new BaseSign(new bindings.LDKBaseSign() {
214 @Override public byte[] get_per_commitment_point(long idx) {
215 byte[] ret = arg.get_per_commitment_point(idx);
216 Reference.reachabilityFence(arg);
217 byte[] result = InternalUtils.check_arr_len(ret, 33);
220 @Override public byte[] release_commitment_secret(long idx) {
221 byte[] ret = arg.release_commitment_secret(idx);
222 Reference.reachabilityFence(arg);
223 byte[] result = InternalUtils.check_arr_len(ret, 32);
226 @Override public long validate_holder_commitment(long holder_tx, byte[][] preimages) {
227 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); }
228 Result_NoneNoneZ ret = arg.validate_holder_commitment(holder_tx_hu_conv, preimages);
229 Reference.reachabilityFence(arg);
230 long result = ret == null ? 0 : ret.clone_ptr();
233 @Override public byte[] channel_keys_id() {
234 byte[] ret = arg.channel_keys_id();
235 Reference.reachabilityFence(arg);
236 byte[] result = InternalUtils.check_arr_len(ret, 32);
239 @Override public long sign_counterparty_commitment(long commitment_tx, byte[][] preimages) {
240 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); }
241 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(commitment_tx_hu_conv, preimages);
242 Reference.reachabilityFence(arg);
243 long result = ret == null ? 0 : ret.clone_ptr();
246 @Override public long validate_counterparty_revocation(long idx, byte[] secret) {
247 Result_NoneNoneZ ret = arg.validate_counterparty_revocation(idx, secret);
248 Reference.reachabilityFence(arg);
249 long result = ret == null ? 0 : ret.clone_ptr();
252 @Override public long sign_holder_commitment_and_htlcs(long commitment_tx) {
253 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); }
254 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_holder_commitment_and_htlcs(commitment_tx_hu_conv);
255 Reference.reachabilityFence(arg);
256 long result = ret == null ? 0 : ret.clone_ptr();
259 @Override public long sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
260 Result_SignatureNoneZ ret = arg.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key);
261 Reference.reachabilityFence(arg);
262 long result = ret == null ? 0 : ret.clone_ptr();
265 @Override public long sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) {
266 org.ldk.structs.HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, htlc); }
267 Result_SignatureNoneZ ret = arg.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc_hu_conv);
268 Reference.reachabilityFence(arg);
269 long result = ret == null ? 0 : ret.clone_ptr();
272 @Override public long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) {
273 org.ldk.structs.HTLCOutputInCommitment htlc_hu_conv = null; if (htlc < 0 || htlc > 4096) { htlc_hu_conv = new org.ldk.structs.HTLCOutputInCommitment(null, htlc); }
274 Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, input, amount, per_commitment_point, htlc_hu_conv);
275 Reference.reachabilityFence(arg);
276 long result = ret == null ? 0 : ret.clone_ptr();
279 @Override public long sign_closing_transaction(long closing_tx) {
280 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); }
281 Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_hu_conv);
282 Reference.reachabilityFence(arg);
283 long result = ret == null ? 0 : ret.clone_ptr();
286 @Override public long sign_channel_announcement(long msg) {
287 org.ldk.structs.UnsignedChannelAnnouncement msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.UnsignedChannelAnnouncement(null, msg); }
288 Result_C2Tuple_SignatureSignatureZNoneZ ret = arg.sign_channel_announcement(msg_hu_conv);
289 Reference.reachabilityFence(arg);
290 long result = ret == null ? 0 : ret.clone_ptr();
293 @Override public void ready_channel(long channel_parameters) {
294 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); }
295 arg.ready_channel(channel_parameters_hu_conv);
296 Reference.reachabilityFence(arg);
299 return impl_holder.held;
302 * Gets the per-commitment point for a specific commitment number
304 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
306 public byte[] get_per_commitment_point(long idx) {
307 byte[] ret = bindings.BaseSign_get_per_commitment_point(this.ptr, idx);
308 Reference.reachabilityFence(this);
309 Reference.reachabilityFence(idx);
314 * Gets the commitment secret for a specific commitment number as part of the revocation process
316 * An external signer implementation should error here if the commitment was already signed
317 * and should refuse to sign it in the future.
319 * May be called more than once for the same index.
321 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
323 public byte[] release_commitment_secret(long idx) {
324 byte[] ret = bindings.BaseSign_release_commitment_secret(this.ptr, idx);
325 Reference.reachabilityFence(this);
326 Reference.reachabilityFence(idx);
331 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
333 * This is required in order for the signer to make sure that releasing a commitment
334 * secret won't leave us without a broadcastable holder transaction.
335 * Policy checks should be implemented in this function, including checking the amount
336 * sent to us and checking the HTLCs.
338 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
339 * A validating signer should ensure that an HTLC output is removed only when the matching
340 * preimage is provided, or when the value to holder is restored.
342 * NOTE: all the relevant preimages will be provided, but there may also be additional
343 * irrelevant or duplicate preimages.
345 public Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages) {
346 long ret = bindings.BaseSign_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr & ~1, preimages != null ? Arrays.stream(preimages).map(preimages_conv_8 -> InternalUtils.check_arr_len(preimages_conv_8, 32)).toArray(byte[][]::new) : null);
347 Reference.reachabilityFence(this);
348 Reference.reachabilityFence(holder_tx);
349 Reference.reachabilityFence(preimages);
350 if (ret >= 0 && ret <= 4096) { return null; }
351 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
352 this.ptrs_to.add(holder_tx);
357 * Gets an arbitrary identifier describing the set of keys which are provided back to you in
358 * some SpendableOutputDescriptor types. This should be sufficient to identify this
359 * Sign object uniquely and lookup or re-derive its keys.
361 public byte[] channel_keys_id() {
362 byte[] ret = bindings.BaseSign_channel_keys_id(this.ptr);
363 Reference.reachabilityFence(this);
368 * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
370 * Note that if signing fails or is rejected, the channel will be force-closed.
372 * Policy checks should be implemented in this function, including checking the amount
373 * sent to us and checking the HTLCs.
375 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
376 * A validating signer should ensure that an HTLC output is removed only when the matching
377 * preimage is provided, or when the value to holder is restored.
379 * NOTE: all the relevant preimages will be provided, but there may also be additional
380 * irrelevant or duplicate preimages.
382 public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(CommitmentTransaction commitment_tx, byte[][] preimages) {
383 long ret = bindings.BaseSign_sign_counterparty_commitment(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1, preimages != null ? Arrays.stream(preimages).map(preimages_conv_8 -> InternalUtils.check_arr_len(preimages_conv_8, 32)).toArray(byte[][]::new) : null);
384 Reference.reachabilityFence(this);
385 Reference.reachabilityFence(commitment_tx);
386 Reference.reachabilityFence(preimages);
387 if (ret >= 0 && ret <= 4096) { return null; }
388 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
389 this.ptrs_to.add(commitment_tx);
394 * Validate the counterparty's revocation.
396 * This is required in order for the signer to make sure that the state has moved
397 * forward and it is safe to sign the next counterparty commitment.
399 public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
400 long ret = bindings.BaseSign_validate_counterparty_revocation(this.ptr, idx, InternalUtils.check_arr_len(secret, 32));
401 Reference.reachabilityFence(this);
402 Reference.reachabilityFence(idx);
403 Reference.reachabilityFence(secret);
404 if (ret >= 0 && ret <= 4096) { return null; }
405 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
410 * Create a signatures for a holder's commitment transaction and its claiming HTLC transactions.
411 * This will only ever be called with a non-revoked commitment_tx. This will be called with the
412 * latest commitment_tx when we initiate a force-close.
413 * This will be called with the previous latest, just to get claiming HTLC signatures, if we are
414 * reacting to a ChannelMonitor replica that decided to broadcast before it had been updated to
416 * This may be called multiple times for the same transaction.
418 * An external signer implementation should check that the commitment has not been revoked.
420 * May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case.
422 public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_holder_commitment_and_htlcs(HolderCommitmentTransaction commitment_tx) {
423 long ret = bindings.BaseSign_sign_holder_commitment_and_htlcs(this.ptr, commitment_tx == null ? 0 : commitment_tx.ptr & ~1);
424 Reference.reachabilityFence(this);
425 Reference.reachabilityFence(commitment_tx);
426 if (ret >= 0 && ret <= 4096) { return null; }
427 Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
428 this.ptrs_to.add(commitment_tx);
433 * Create a signature for the given input in a transaction spending an HTLC transaction output
434 * or a commitment transaction `to_local` output when our counterparty broadcasts an old state.
436 * A justice transaction may claim multiple outputs at the same time if timelocks are
437 * similar, but only a signature for the input at index `input` should be signed for here.
438 * It may be called multiple times for same output(s) if a fee-bump is needed with regards
439 * to an upcoming timelock expiration.
441 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
443 * per_commitment_key is revocation secret which was provided by our counterparty when they
444 * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
445 * not allow the spending of any funds by itself (you need our holder revocation_secret to do
448 public Result_SignatureNoneZ sign_justice_revoked_output(byte[] justice_tx, long input, long amount, byte[] per_commitment_key) {
449 long ret = bindings.BaseSign_sign_justice_revoked_output(this.ptr, justice_tx, input, amount, InternalUtils.check_arr_len(per_commitment_key, 32));
450 Reference.reachabilityFence(this);
451 Reference.reachabilityFence(justice_tx);
452 Reference.reachabilityFence(input);
453 Reference.reachabilityFence(amount);
454 Reference.reachabilityFence(per_commitment_key);
455 if (ret >= 0 && ret <= 4096) { return null; }
456 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
461 * Create a signature for the given input in a transaction spending a commitment transaction
462 * HTLC output when our counterparty broadcasts an old state.
464 * A justice transaction may claim multiple outputs at the same time if timelocks are
465 * similar, but only a signature for the input at index `input` should be signed for here.
466 * It may be called multiple times for same output(s) if a fee-bump is needed with regards
467 * to an upcoming timelock expiration.
469 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
471 * per_commitment_key is revocation secret which was provided by our counterparty when they
472 * revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
473 * not allow the spending of any funds by itself (you need our holder revocation_secret to do
476 * htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
477 * (which is committed to in the BIP 143 signatures).
479 public Result_SignatureNoneZ sign_justice_revoked_htlc(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) {
480 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);
481 Reference.reachabilityFence(this);
482 Reference.reachabilityFence(justice_tx);
483 Reference.reachabilityFence(input);
484 Reference.reachabilityFence(amount);
485 Reference.reachabilityFence(per_commitment_key);
486 Reference.reachabilityFence(htlc);
487 if (ret >= 0 && ret <= 4096) { return null; }
488 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
489 this.ptrs_to.add(htlc);
494 * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
495 * transaction, either offered or received.
497 * Such a transaction may claim multiples offered outputs at same time if we know the
498 * preimage for each when we create it, but only the input at index `input` should be
499 * signed for here. It may be called multiple times for same output(s) if a fee-bump is
500 * needed with regards to an upcoming timelock expiration.
502 * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
505 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
507 * Per_commitment_point is the dynamic point corresponding to the channel state
508 * detected onchain. It has been generated by our counterparty and is used to derive
509 * channel state keys, which are then included in the witness script and committed to in the
512 public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) {
513 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);
514 Reference.reachabilityFence(this);
515 Reference.reachabilityFence(htlc_tx);
516 Reference.reachabilityFence(input);
517 Reference.reachabilityFence(amount);
518 Reference.reachabilityFence(per_commitment_point);
519 Reference.reachabilityFence(htlc);
520 if (ret >= 0 && ret <= 4096) { return null; }
521 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
522 this.ptrs_to.add(htlc);
527 * Create a signature for a (proposed) closing transaction.
529 * Note that, due to rounding, there may be one \"missing\" satoshi, and either party may have
530 * chosen to forgo their output as dust.
532 public Result_SignatureNoneZ sign_closing_transaction(ClosingTransaction closing_tx) {
533 long ret = bindings.BaseSign_sign_closing_transaction(this.ptr, closing_tx == null ? 0 : closing_tx.ptr & ~1);
534 Reference.reachabilityFence(this);
535 Reference.reachabilityFence(closing_tx);
536 if (ret >= 0 && ret <= 4096) { return null; }
537 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
538 this.ptrs_to.add(closing_tx);
543 * Signs a channel announcement message with our funding key and our node secret key (aka
544 * node_id or network_key), proving it comes from one of the channel participants.
546 * The first returned signature should be from our node secret key, the second from our
549 * Note that if this fails or is rejected, the channel will not be publicly announced and
550 * our counterparty may (though likely will not) close the channel on us for violating the
553 public Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
554 long ret = bindings.BaseSign_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
555 Reference.reachabilityFence(this);
556 Reference.reachabilityFence(msg);
557 if (ret >= 0 && ret <= 4096) { return null; }
558 Result_C2Tuple_SignatureSignatureZNoneZ ret_hu_conv = Result_C2Tuple_SignatureSignatureZNoneZ.constr_from_ptr(ret);
559 this.ptrs_to.add(msg);
564 * Set the counterparty static channel data, including basepoints,
565 * counterparty_selected/holder_selected_contest_delay and funding outpoint.
566 * This is done as soon as the funding outpoint is known. Since these are static channel data,
567 * they MUST NOT be allowed to change to different values once set.
569 * channel_parameters.is_populated() MUST be true.
571 * We bind holder_selected_contest_delay late here for API convenience.
573 * Will be called before any signatures are applied.
575 public void ready_channel(ChannelTransactionParameters channel_parameters) {
576 bindings.BaseSign_ready_channel(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr & ~1);
577 Reference.reachabilityFence(this);
578 Reference.reachabilityFence(channel_parameters);
579 this.ptrs_to.add(channel_parameters);
583 * Frees any resources associated with this object given its this_arg pointer.
584 * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
586 public ChannelPublicKeys get_pubkeys() {
587 long ret = bindings.BaseSign_get_pubkeys(this.ptr);
588 Reference.reachabilityFence(this);
589 if (ret >= 0 && ret <= 4096) { return null; }
590 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
591 ret_hu_conv.ptrs_to.add(this);