[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / ChannelSigner.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 handle Lightning channel key material without concretizing the channel type or
12  * the signature mechanism.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class ChannelSigner extends CommonBase {
16         final bindings.LDKChannelSigner bindings_instance;
17         ChannelSigner(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
18         private ChannelSigner(bindings.LDKChannelSigner arg, ChannelPublicKeys pubkeys) {
19                 super(bindings.LDKChannelSigner_new(arg, pubkeys == null ? 0 : pubkeys.clone_ptr()));
20                 this.ptrs_to.add(arg);
21                 this.bindings_instance = arg;
22         }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 if (ptr != 0) { bindings.ChannelSigner_free(ptr); } super.finalize();
26         }
27         /**
28          * Destroys the object, freeing associated resources. After this call, any access
29          * to this object may result in a SEGFAULT or worse.
30          *
31          * You should generally NEVER call this method. You should let the garbage collector
32          * do this for you when it finalizes objects. However, it may be useful for types
33          * which represent locks and should be closed immediately to avoid holding locks
34          * until the GC runs.
35          */
36         public void destroy() {
37                 if (ptr != 0) { bindings.ChannelSigner_free(ptr); }
38                 ptr = 0;
39         }
40         public static interface ChannelSignerInterface {
41                 /**
42                  * Gets the per-commitment point for a specific commitment number
43                  * 
44                  * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
45                  */
46                 byte[] get_per_commitment_point(long idx);
47                 /**
48                  * Gets the commitment secret for a specific commitment number as part of the revocation process
49                  * 
50                  * An external signer implementation should error here if the commitment was already signed
51                  * and should refuse to sign it in the future.
52                  * 
53                  * May be called more than once for the same index.
54                  * 
55                  * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
56                  */
57                 byte[] release_commitment_secret(long idx);
58                 /**
59                  * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
60                  * 
61                  * This is required in order for the signer to make sure that releasing a commitment
62                  * secret won't leave us without a broadcastable holder transaction.
63                  * Policy checks should be implemented in this function, including checking the amount
64                  * sent to us and checking the HTLCs.
65                  * 
66                  * The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
67                  * A validating signer should ensure that an HTLC output is removed only when the matching
68                  * preimage is provided, or when the value to holder is restored.
69                  * 
70                  * Note that all the relevant preimages will be provided, but there may also be additional
71                  * irrelevant or duplicate preimages.
72                  */
73                 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] outbound_htlc_preimages);
74                 /**
75                  * Validate the counterparty's revocation.
76                  * 
77                  * This is required in order for the signer to make sure that the state has moved
78                  * forward and it is safe to sign the next counterparty commitment.
79                  */
80                 Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret);
81                 /**
82                  * Returns an arbitrary identifier describing the set of keys which are provided back to you in
83                  * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
84                  * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
85                  */
86                 byte[] channel_keys_id();
87                 /**
88                  * Set the counterparty static channel data, including basepoints,
89                  * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
90                  * 
91                  * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
92                  * instance, LDK will call this method exactly once - either immediately after construction
93                  * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
94                  * information has been generated.
95                  * 
96                  * channel_parameters.is_populated() MUST be true.
97                  */
98                 void provide_channel_parameters(ChannelTransactionParameters channel_parameters);
99         }
100         private static class LDKChannelSignerHolder { ChannelSigner held; }
101         public static ChannelSigner new_impl(ChannelSignerInterface arg, ChannelPublicKeys pubkeys) {
102                 final LDKChannelSignerHolder impl_holder = new LDKChannelSignerHolder();
103                 impl_holder.held = new ChannelSigner(new bindings.LDKChannelSigner() {
104                         @Override public byte[] get_per_commitment_point(long idx) {
105                                 byte[] ret = arg.get_per_commitment_point(idx);
106                                 Reference.reachabilityFence(arg);
107                                 byte[] result = InternalUtils.check_arr_len(ret, 33);
108                                 return result;
109                         }
110                         @Override public byte[] release_commitment_secret(long idx) {
111                                 byte[] ret = arg.release_commitment_secret(idx);
112                                 Reference.reachabilityFence(arg);
113                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
114                                 return result;
115                         }
116                         @Override public long validate_holder_commitment(long holder_tx, byte[][] outbound_htlc_preimages) {
117                                 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); }
118                                 Result_NoneNoneZ ret = arg.validate_holder_commitment(holder_tx_hu_conv, outbound_htlc_preimages);
119                                 Reference.reachabilityFence(arg);
120                                 long result = ret == null ? 0 : ret.clone_ptr();
121                                 return result;
122                         }
123                         @Override public long validate_counterparty_revocation(long idx, byte[] secret) {
124                                 Result_NoneNoneZ ret = arg.validate_counterparty_revocation(idx, secret);
125                                 Reference.reachabilityFence(arg);
126                                 long result = ret == null ? 0 : ret.clone_ptr();
127                                 return result;
128                         }
129                         @Override public byte[] channel_keys_id() {
130                                 byte[] ret = arg.channel_keys_id();
131                                 Reference.reachabilityFence(arg);
132                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
133                                 return result;
134                         }
135                         @Override public void provide_channel_parameters(long channel_parameters) {
136                                 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); }
137                                 arg.provide_channel_parameters(channel_parameters_hu_conv);
138                                 Reference.reachabilityFence(arg);
139                         }
140                 }, pubkeys);
141                 return impl_holder.held;
142         }
143         /**
144          * Gets the per-commitment point for a specific commitment number
145          * 
146          * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
147          */
148         public byte[] get_per_commitment_point(long idx) {
149                 byte[] ret = bindings.ChannelSigner_get_per_commitment_point(this.ptr, idx);
150                 Reference.reachabilityFence(this);
151                 Reference.reachabilityFence(idx);
152                 return ret;
153         }
154
155         /**
156          * Gets the commitment secret for a specific commitment number as part of the revocation process
157          * 
158          * An external signer implementation should error here if the commitment was already signed
159          * and should refuse to sign it in the future.
160          * 
161          * May be called more than once for the same index.
162          * 
163          * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
164          */
165         public byte[] release_commitment_secret(long idx) {
166                 byte[] ret = bindings.ChannelSigner_release_commitment_secret(this.ptr, idx);
167                 Reference.reachabilityFence(this);
168                 Reference.reachabilityFence(idx);
169                 return ret;
170         }
171
172         /**
173          * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
174          * 
175          * This is required in order for the signer to make sure that releasing a commitment
176          * secret won't leave us without a broadcastable holder transaction.
177          * Policy checks should be implemented in this function, including checking the amount
178          * sent to us and checking the HTLCs.
179          * 
180          * The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
181          * A validating signer should ensure that an HTLC output is removed only when the matching
182          * preimage is provided, or when the value to holder is restored.
183          * 
184          * Note that all the relevant preimages will be provided, but there may also be additional
185          * irrelevant or duplicate preimages.
186          */
187         public Result_NoneNoneZ validate_holder_commitment(org.ldk.structs.HolderCommitmentTransaction holder_tx, byte[][] outbound_htlc_preimages) {
188                 long ret = bindings.ChannelSigner_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr, outbound_htlc_preimages != null ? Arrays.stream(outbound_htlc_preimages).map(outbound_htlc_preimages_conv_8 -> InternalUtils.check_arr_len(outbound_htlc_preimages_conv_8, 32)).toArray(byte[][]::new) : null);
189                 Reference.reachabilityFence(this);
190                 Reference.reachabilityFence(holder_tx);
191                 Reference.reachabilityFence(outbound_htlc_preimages);
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
194                 if (this != null) { this.ptrs_to.add(holder_tx); };
195                 return ret_hu_conv;
196         }
197
198         /**
199          * Validate the counterparty's revocation.
200          * 
201          * This is required in order for the signer to make sure that the state has moved
202          * forward and it is safe to sign the next counterparty commitment.
203          */
204         public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
205                 long ret = bindings.ChannelSigner_validate_counterparty_revocation(this.ptr, idx, InternalUtils.check_arr_len(secret, 32));
206                 Reference.reachabilityFence(this);
207                 Reference.reachabilityFence(idx);
208                 Reference.reachabilityFence(secret);
209                 if (ret >= 0 && ret <= 4096) { return null; }
210                 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
211                 return ret_hu_conv;
212         }
213
214         /**
215          * Returns an arbitrary identifier describing the set of keys which are provided back to you in
216          * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
217          * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
218          */
219         public byte[] channel_keys_id() {
220                 byte[] ret = bindings.ChannelSigner_channel_keys_id(this.ptr);
221                 Reference.reachabilityFence(this);
222                 return ret;
223         }
224
225         /**
226          * Set the counterparty static channel data, including basepoints,
227          * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
228          * 
229          * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
230          * instance, LDK will call this method exactly once - either immediately after construction
231          * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
232          * information has been generated.
233          * 
234          * channel_parameters.is_populated() MUST be true.
235          */
236         public void provide_channel_parameters(org.ldk.structs.ChannelTransactionParameters channel_parameters) {
237                 bindings.ChannelSigner_provide_channel_parameters(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr);
238                 Reference.reachabilityFence(this);
239                 Reference.reachabilityFence(channel_parameters);
240                 if (this != null) { this.ptrs_to.add(channel_parameters); };
241         }
242
243         /**
244          * Frees any resources associated with this object given its this_arg pointer.
245          * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
246          */
247         public ChannelPublicKeys get_pubkeys() {
248                 long ret = bindings.ChannelSigner_get_pubkeys(this.ptr);
249                 Reference.reachabilityFence(this);
250                 if (ret >= 0 && ret <= 4096) { return null; }
251                 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
252                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
253                 return ret_hu_conv;
254         }
255
256 }