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