830fa1f6b09bec041a95926f948ccacee968b760
[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 [`Sign`] 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[] node_secret, 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) {
153                 long ret = bindings.InMemorySigner_new(InternalUtils.check_arr_len(node_secret, 32), 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));
154                 GC.KeepAlive(node_secret);
155                 GC.KeepAlive(funding_key);
156                 GC.KeepAlive(revocation_base_key);
157                 GC.KeepAlive(payment_key);
158                 GC.KeepAlive(delayed_payment_base_key);
159                 GC.KeepAlive(htlc_base_key);
160                 GC.KeepAlive(commitment_seed);
161                 GC.KeepAlive(channel_value_satoshis);
162                 GC.KeepAlive(channel_keys_id);
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 [`BaseSign::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 [`BaseSign::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 [`BaseSign::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 [`BaseSign::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 [`BaseSign::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 [`BaseSign::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 whether anchors should be used.
251          * 
252          * Will panic if [`BaseSign::provide_channel_parameters`] has not been called before.
253          */
254         public bool opt_anchors() {
255                 bool ret = bindings.InMemorySigner_opt_anchors(this.ptr);
256                 GC.KeepAlive(this);
257                 return ret;
258         }
259
260         /**
261          * Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
262          * by `descriptor`, returning the witness stack for the input.
263          * 
264          * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
265          * is not spending the outpoint described by [`descriptor.outpoint`],
266          * or if an output descriptor `script_pubkey` does not match the one we can spend.
267          * 
268          * [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
269          */
270         public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, org.ldk.structs.StaticPaymentOutputDescriptor descriptor) {
271                 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
272                 GC.KeepAlive(this);
273                 GC.KeepAlive(spend_tx);
274                 GC.KeepAlive(input_idx);
275                 GC.KeepAlive(descriptor);
276                 if (ret >= 0 && ret <= 4096) { return null; }
277                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
278                 if (this != null) { this.ptrs_to.AddLast(descriptor); };
279                 return ret_hu_conv;
280         }
281
282         /**
283          * Sign the single input of `spend_tx` at index `input_idx` which spends the output
284          * described by `descriptor`, returning the witness stack for the input.
285          * 
286          * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
287          * is not spending the outpoint described by [`descriptor.outpoint`], does not have a
288          * sequence set to [`descriptor.to_self_delay`], or if an output descriptor
289          * `script_pubkey` does not match the one we can spend.
290          * 
291          * [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
292          * [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
293          */
294         public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, org.ldk.structs.DelayedPaymentOutputDescriptor descriptor) {
295                 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
296                 GC.KeepAlive(this);
297                 GC.KeepAlive(spend_tx);
298                 GC.KeepAlive(input_idx);
299                 GC.KeepAlive(descriptor);
300                 if (ret >= 0 && ret <= 4096) { return null; }
301                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
302                 if (this != null) { this.ptrs_to.AddLast(descriptor); };
303                 return ret_hu_conv;
304         }
305
306         /**
307          * Constructs a new BaseSign which calls the relevant methods on this_arg.
308          * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
309          */
310         public BaseSign as_BaseSign() {
311                 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
312                 GC.KeepAlive(this);
313                 if (ret >= 0 && ret <= 4096) { return null; }
314                 BaseSign ret_hu_conv = new BaseSign(null, ret);
315                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
316                 return ret_hu_conv;
317         }
318
319         /**
320          * Constructs a new Sign which calls the relevant methods on this_arg.
321          * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
322          */
323         public Sign as_Sign() {
324                 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
325                 GC.KeepAlive(this);
326                 if (ret >= 0 && ret <= 4096) { return null; }
327                 Sign ret_hu_conv = new Sign(null, ret);
328                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
329                 return ret_hu_conv;
330         }
331
332         /**
333          * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
334          */
335         public byte[] write() {
336                 byte[] ret = bindings.InMemorySigner_write(this.ptr);
337                 GC.KeepAlive(this);
338                 return ret;
339         }
340
341         /**
342          * Read a InMemorySigner from a byte array, created by InMemorySigner_write
343          */
344         public static Result_InMemorySignerDecodeErrorZ read(byte[] ser, byte[] arg) {
345                 long ret = bindings.InMemorySigner_read(ser, InternalUtils.check_arr_len(arg, 32));
346                 GC.KeepAlive(ser);
347                 GC.KeepAlive(arg);
348                 if (ret >= 0 && ret <= 4096) { return null; }
349                 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);
350                 return ret_hu_conv;
351         }
352
353 }
354 } } }