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