bf18391a74429e5038e0df96c3234ac119d12716
[ldk-java] / c_sharp / src / org / ldk / structs / InMemorySigner.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8
9 /**
10  * A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
11  * 
12  * This implementation performs no policy checks and is insufficient by itself as
13  * a secure external signer.
14  */
15 public class InMemorySigner : CommonBase {
16         internal InMemorySigner(object _dummy, long ptr) : base(ptr) { }
17         ~InMemorySigner() {
18                 if (ptr != 0) { bindings.InMemorySigner_free(ptr); }
19         }
20
21         /**
22          * Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
23          * holder's anchor output in a commitment transaction, if one is present.
24          */
25         public byte[] get_funding_key() {
26                 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
27                 GC.KeepAlive(this);
28                 return ret;
29         }
30
31         /**
32          * Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
33          * holder's anchor output in a commitment transaction, if one is present.
34          */
35         public void set_funding_key(byte[] val) {
36                 bindings.InMemorySigner_set_funding_key(this.ptr, InternalUtils.check_arr_len(val, 32));
37                 GC.KeepAlive(this);
38                 GC.KeepAlive(val);
39         }
40
41         /**
42          * Holder secret key for blinded revocation pubkey.
43          */
44         public byte[] get_revocation_base_key() {
45                 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
46                 GC.KeepAlive(this);
47                 return ret;
48         }
49
50         /**
51          * Holder secret key for blinded revocation pubkey.
52          */
53         public void set_revocation_base_key(byte[] val) {
54                 bindings.InMemorySigner_set_revocation_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
55                 GC.KeepAlive(this);
56                 GC.KeepAlive(val);
57         }
58
59         /**
60          * Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
61          */
62         public byte[] get_payment_key() {
63                 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
64                 GC.KeepAlive(this);
65                 return ret;
66         }
67
68         /**
69          * Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
70          */
71         public void set_payment_key(byte[] val) {
72                 bindings.InMemorySigner_set_payment_key(this.ptr, InternalUtils.check_arr_len(val, 32));
73                 GC.KeepAlive(this);
74                 GC.KeepAlive(val);
75         }
76
77         /**
78          * Holder secret key used in an HTLC transaction.
79          */
80         public byte[] get_delayed_payment_base_key() {
81                 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
82                 GC.KeepAlive(this);
83                 return ret;
84         }
85
86         /**
87          * Holder secret key used in an HTLC transaction.
88          */
89         public void set_delayed_payment_base_key(byte[] val) {
90                 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
91                 GC.KeepAlive(this);
92                 GC.KeepAlive(val);
93         }
94
95         /**
96          * Holder HTLC secret key used in commitment transaction HTLC outputs.
97          */
98         public byte[] get_htlc_base_key() {
99                 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
100                 GC.KeepAlive(this);
101                 return ret;
102         }
103
104         /**
105          * Holder HTLC secret key used in commitment transaction HTLC outputs.
106          */
107         public void set_htlc_base_key(byte[] val) {
108                 bindings.InMemorySigner_set_htlc_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
109                 GC.KeepAlive(this);
110                 GC.KeepAlive(val);
111         }
112
113         /**
114          * Commitment seed.
115          */
116         public byte[] get_commitment_seed() {
117                 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
118                 GC.KeepAlive(this);
119                 return ret;
120         }
121
122         /**
123          * Commitment seed.
124          */
125         public void set_commitment_seed(byte[] val) {
126                 bindings.InMemorySigner_set_commitment_seed(this.ptr, InternalUtils.check_arr_len(val, 32));
127                 GC.KeepAlive(this);
128                 GC.KeepAlive(val);
129         }
130
131         internal long clone_ptr() {
132                 long ret = bindings.InMemorySigner_clone_ptr(this.ptr);
133                 GC.KeepAlive(this);
134                 return ret;
135         }
136
137         /**
138          * Creates a copy of the InMemorySigner
139          */
140         public InMemorySigner clone() {
141                 long ret = bindings.InMemorySigner_clone(this.ptr);
142                 GC.KeepAlive(this);
143                 if (ret >= 0 && ret <= 4096) { return null; }
144                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
145                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
146                 return ret_hu_conv;
147         }
148
149         /**
150          * Creates a new [`InMemorySigner`].
151          */
152         public static InMemorySigner of(byte[] funding_key, byte[] revocation_base_key, byte[] payment_key, byte[] delayed_payment_base_key, byte[] htlc_base_key, byte[] commitment_seed, long channel_value_satoshis, byte[] channel_keys_id, byte[] rand_bytes_unique_start) {
153                 long ret = bindings.InMemorySigner_new(InternalUtils.check_arr_len(funding_key, 32), InternalUtils.check_arr_len(revocation_base_key, 32), InternalUtils.check_arr_len(payment_key, 32), InternalUtils.check_arr_len(delayed_payment_base_key, 32), InternalUtils.check_arr_len(htlc_base_key, 32), InternalUtils.check_arr_len(commitment_seed, 32), channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32), InternalUtils.check_arr_len(rand_bytes_unique_start, 32));
154                 GC.KeepAlive(funding_key);
155                 GC.KeepAlive(revocation_base_key);
156                 GC.KeepAlive(payment_key);
157                 GC.KeepAlive(delayed_payment_base_key);
158                 GC.KeepAlive(htlc_base_key);
159                 GC.KeepAlive(commitment_seed);
160                 GC.KeepAlive(channel_value_satoshis);
161                 GC.KeepAlive(channel_keys_id);
162                 GC.KeepAlive(rand_bytes_unique_start);
163                 if (ret >= 0 && ret <= 4096) { return null; }
164                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
165                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
166                 return ret_hu_conv;
167         }
168
169         /**
170          * Returns the counterparty's pubkeys.
171          * 
172          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
173          */
174         public ChannelPublicKeys counterparty_pubkeys() {
175                 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
176                 GC.KeepAlive(this);
177                 if (ret >= 0 && ret <= 4096) { return null; }
178                 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
179                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
180                 return ret_hu_conv;
181         }
182
183         /**
184          * Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
185          * transactions, i.e., the amount of time that we have to wait to recover our funds if we
186          * broadcast a transaction.
187          * 
188          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
189          */
190         public short counterparty_selected_contest_delay() {
191                 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
192                 GC.KeepAlive(this);
193                 return ret;
194         }
195
196         /**
197          * Returns the `contest_delay` value specified by us and applied on transactions broadcastable
198          * by our counterparty, i.e., the amount of time that they have to wait to recover their funds
199          * if they broadcast a transaction.
200          * 
201          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
202          */
203         public short holder_selected_contest_delay() {
204                 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
205                 GC.KeepAlive(this);
206                 return ret;
207         }
208
209         /**
210          * Returns whether the holder is the initiator.
211          * 
212          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
213          */
214         public bool is_outbound() {
215                 bool ret = bindings.InMemorySigner_is_outbound(this.ptr);
216                 GC.KeepAlive(this);
217                 return ret;
218         }
219
220         /**
221          * Funding outpoint
222          * 
223          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
224          */
225         public OutPoint funding_outpoint() {
226                 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
227                 GC.KeepAlive(this);
228                 if (ret >= 0 && ret <= 4096) { return null; }
229                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
230                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
231                 return ret_hu_conv;
232         }
233
234         /**
235          * Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
236          * building transactions.
237          * 
238          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
239          */
240         public ChannelTransactionParameters get_channel_parameters() {
241                 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
242                 GC.KeepAlive(this);
243                 if (ret >= 0 && ret <= 4096) { return null; }
244                 org.ldk.structs.ChannelTransactionParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTransactionParameters(null, ret); }
245                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
246                 return ret_hu_conv;
247         }
248
249         /**
250          * Returns the channel type features of the channel parameters. Should be helpful for
251          * determining a channel's category, i. e. legacy/anchors/taproot/etc.
252          * 
253          * Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
254          */
255         public ChannelTypeFeatures channel_type_features() {
256                 long ret = bindings.InMemorySigner_channel_type_features(this.ptr);
257                 GC.KeepAlive(this);
258                 if (ret >= 0 && ret <= 4096) { return null; }
259                 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
260                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
261                 return ret_hu_conv;
262         }
263
264         /**
265          * Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
266          * by `descriptor`, returning the witness stack for the input.
267          * 
268          * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
269          * is not spending the outpoint described by [`descriptor.outpoint`],
270          * or if an output descriptor `script_pubkey` does not match the one we can spend.
271          * 
272          * [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
273          */
274         public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, org.ldk.structs.StaticPaymentOutputDescriptor descriptor) {
275                 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
276                 GC.KeepAlive(this);
277                 GC.KeepAlive(spend_tx);
278                 GC.KeepAlive(input_idx);
279                 GC.KeepAlive(descriptor);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
282                 if (this != null) { this.ptrs_to.AddLast(descriptor); };
283                 return ret_hu_conv;
284         }
285
286         /**
287          * Sign the single input of `spend_tx` at index `input_idx` which spends the output
288          * described by `descriptor`, returning the witness stack for the input.
289          * 
290          * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
291          * is not spending the outpoint described by [`descriptor.outpoint`], does not have a
292          * sequence set to [`descriptor.to_self_delay`], or if an output descriptor
293          * `script_pubkey` does not match the one we can spend.
294          * 
295          * [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
296          * [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
297          */
298         public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, org.ldk.structs.DelayedPaymentOutputDescriptor descriptor) {
299                 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
300                 GC.KeepAlive(this);
301                 GC.KeepAlive(spend_tx);
302                 GC.KeepAlive(input_idx);
303                 GC.KeepAlive(descriptor);
304                 if (ret >= 0 && ret <= 4096) { return null; }
305                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
306                 if (this != null) { this.ptrs_to.AddLast(descriptor); };
307                 return ret_hu_conv;
308         }
309
310         /**
311          * Constructs a new EntropySource which calls the relevant methods on this_arg.
312          * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
313          */
314         public EntropySource as_EntropySource() {
315                 long ret = bindings.InMemorySigner_as_EntropySource(this.ptr);
316                 GC.KeepAlive(this);
317                 if (ret >= 0 && ret <= 4096) { return null; }
318                 EntropySource ret_hu_conv = new EntropySource(null, ret);
319                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
320                 return ret_hu_conv;
321         }
322
323         /**
324          * Constructs a new ChannelSigner which calls the relevant methods on this_arg.
325          * This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
326          */
327         public ChannelSigner as_ChannelSigner() {
328                 long ret = bindings.InMemorySigner_as_ChannelSigner(this.ptr);
329                 GC.KeepAlive(this);
330                 if (ret >= 0 && ret <= 4096) { return null; }
331                 ChannelSigner ret_hu_conv = new ChannelSigner(null, ret);
332                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
333                 return ret_hu_conv;
334         }
335
336         /**
337          * Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
338          * This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
339          */
340         public EcdsaChannelSigner as_EcdsaChannelSigner() {
341                 long ret = bindings.InMemorySigner_as_EcdsaChannelSigner(this.ptr);
342                 GC.KeepAlive(this);
343                 if (ret >= 0 && ret <= 4096) { return null; }
344                 EcdsaChannelSigner ret_hu_conv = new EcdsaChannelSigner(null, ret);
345                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
346                 return ret_hu_conv;
347         }
348
349         /**
350          * Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
351          * This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
352          */
353         public WriteableEcdsaChannelSigner as_WriteableEcdsaChannelSigner() {
354                 long ret = bindings.InMemorySigner_as_WriteableEcdsaChannelSigner(this.ptr);
355                 GC.KeepAlive(this);
356                 if (ret >= 0 && ret <= 4096) { return null; }
357                 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
358                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
359                 return ret_hu_conv;
360         }
361
362         /**
363          * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
364          */
365         public byte[] write() {
366                 byte[] ret = bindings.InMemorySigner_write(this.ptr);
367                 GC.KeepAlive(this);
368                 return ret;
369         }
370
371         /**
372          * Read a InMemorySigner from a byte array, created by InMemorySigner_write
373          */
374         public static Result_InMemorySignerDecodeErrorZ read(byte[] ser, org.ldk.structs.EntropySource arg) {
375                 long ret = bindings.InMemorySigner_read(ser, arg.ptr);
376                 GC.KeepAlive(ser);
377                 GC.KeepAlive(arg);
378                 if (ret >= 0 && ret <= 4096) { return null; }
379                 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);
380                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg); };
381                 return ret_hu_conv;
382         }
383
384 }
385 } } }