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 * 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`.
188 Result_SignatureNoneZ sign_holder_anchor_input(byte[] anchor_tx, long input);
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.
193 * The first returned signature should be from our node secret key, the second from our
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
200 Result_C2Tuple_SignatureSignatureZNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
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.
207 * channel_parameters.is_populated() MUST be true.
209 * We bind holder_selected_contest_delay late here for API convenience.
211 * Will be called before any signatures are applied.
213 void ready_channel(ChannelTransactionParameters channel_parameters);
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);
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);
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();
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);
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();
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();
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();
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();
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();
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();
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();
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();
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();
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);
310 return impl_holder.held;
313 * Gets the per-commitment point for a specific commitment number
315 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
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);
325 * Gets the commitment secret for a specific commitment number as part of the revocation process
327 * An external signer implementation should error here if the commitment was already signed
328 * and should refuse to sign it in the future.
330 * May be called more than once for the same index.
332 * Note that the commitment number starts at (1 << 48) - 1 and counts backwards.
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);
342 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
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.
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.
353 * NOTE: all the relevant preimages will be provided, but there may also be additional
354 * irrelevant or duplicate preimages.
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); };
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.
372 public byte[] channel_keys_id() {
373 byte[] ret = bindings.BaseSign_channel_keys_id(this.ptr);
374 Reference.reachabilityFence(this);
379 * Create a signature for a counterparty's commitment transaction and associated HTLC transactions.
381 * Note that if signing fails or is rejected, the channel will be force-closed.
383 * Policy checks should be implemented in this function, including checking the amount
384 * sent to us and checking the HTLCs.
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.
390 * NOTE: all the relevant preimages will be provided, but there may also be additional
391 * irrelevant or duplicate preimages.
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); };
405 * Validate the counterparty's revocation.
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.
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);
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
427 * This may be called multiple times for the same transaction.
429 * An external signer implementation should check that the commitment has not been revoked.
431 * May return Err if key derivation fails. Callers, such as ChannelMonitor, will panic in such a case.
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); };
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.
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.
452 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
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);
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.
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.
480 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
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).
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); };
505 * Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
506 * transaction, either offered or received.
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.
513 * Witness_script is either a offered or received script as defined in BOLT3 for HTLC
516 * Amount is value of the output spent by this input, committed to in the BIP 143 signature.
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
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); };
538 * Create a signature for a (proposed) closing transaction.
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.
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); };
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`.
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);
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.
571 * The first returned signature should be from our node secret key, the second from our
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
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); };
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.
594 * channel_parameters.is_populated() MUST be true.
596 * We bind holder_selected_contest_delay late here for API convenience.
598 * Will be called before any signatures are applied.
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); };
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.
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); };