031985fff5f855f6ad745f7bf7a91d69ae42eade
[ldk-java] / src / main / java / org / ldk / structs / InMemorySigner.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 /**
12  * A simple implementation of Sign that just keeps the private keys in memory.
13  * 
14  * This implementation performs no policy checks and is insufficient by itself as
15  * a secure external signer.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class InMemorySigner extends CommonBase {
19         InMemorySigner(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.InMemorySigner_free(ptr); }
24         }
25
26         /**
27          * Private key of anchor tx
28          */
29         public byte[] get_funding_key() {
30                 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
31                 Reference.reachabilityFence(this);
32                 return ret;
33         }
34
35         /**
36          * Private key of anchor tx
37          */
38         public void set_funding_key(byte[] val) {
39                 bindings.InMemorySigner_set_funding_key(this.ptr, InternalUtils.check_arr_len(val, 32));
40                 Reference.reachabilityFence(this);
41                 Reference.reachabilityFence(val);
42         }
43
44         /**
45          * Holder secret key for blinded revocation pubkey
46          */
47         public byte[] get_revocation_base_key() {
48                 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
49                 Reference.reachabilityFence(this);
50                 return ret;
51         }
52
53         /**
54          * Holder secret key for blinded revocation pubkey
55          */
56         public void set_revocation_base_key(byte[] val) {
57                 bindings.InMemorySigner_set_revocation_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
58                 Reference.reachabilityFence(this);
59                 Reference.reachabilityFence(val);
60         }
61
62         /**
63          * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
64          */
65         public byte[] get_payment_key() {
66                 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
67                 Reference.reachabilityFence(this);
68                 return ret;
69         }
70
71         /**
72          * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
73          */
74         public void set_payment_key(byte[] val) {
75                 bindings.InMemorySigner_set_payment_key(this.ptr, InternalUtils.check_arr_len(val, 32));
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(val);
78         }
79
80         /**
81          * Holder secret key used in HTLC tx
82          */
83         public byte[] get_delayed_payment_base_key() {
84                 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
85                 Reference.reachabilityFence(this);
86                 return ret;
87         }
88
89         /**
90          * Holder secret key used in HTLC tx
91          */
92         public void set_delayed_payment_base_key(byte[] val) {
93                 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
94                 Reference.reachabilityFence(this);
95                 Reference.reachabilityFence(val);
96         }
97
98         /**
99          * Holder htlc secret key used in commitment tx htlc outputs
100          */
101         public byte[] get_htlc_base_key() {
102                 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
103                 Reference.reachabilityFence(this);
104                 return ret;
105         }
106
107         /**
108          * Holder htlc secret key used in commitment tx htlc outputs
109          */
110         public void set_htlc_base_key(byte[] val) {
111                 bindings.InMemorySigner_set_htlc_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
112                 Reference.reachabilityFence(this);
113                 Reference.reachabilityFence(val);
114         }
115
116         /**
117          * Commitment seed
118          */
119         public byte[] get_commitment_seed() {
120                 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
121                 Reference.reachabilityFence(this);
122                 return ret;
123         }
124
125         /**
126          * Commitment seed
127          */
128         public void set_commitment_seed(byte[] val) {
129                 bindings.InMemorySigner_set_commitment_seed(this.ptr, InternalUtils.check_arr_len(val, 32));
130                 Reference.reachabilityFence(this);
131                 Reference.reachabilityFence(val);
132         }
133
134         long clone_ptr() {
135                 long ret = bindings.InMemorySigner_clone_ptr(this.ptr);
136                 Reference.reachabilityFence(this);
137                 return ret;
138         }
139
140         /**
141          * Creates a copy of the InMemorySigner
142          */
143         public InMemorySigner clone() {
144                 long ret = bindings.InMemorySigner_clone(this.ptr);
145                 Reference.reachabilityFence(this);
146                 if (ret >= 0 && ret <= 4096) { return null; }
147                 InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InMemorySigner(null, ret); }
148                 ret_hu_conv.ptrs_to.add(this);
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Create a new InMemorySigner
154          */
155         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) {
156                 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));
157                 Reference.reachabilityFence(funding_key);
158                 Reference.reachabilityFence(revocation_base_key);
159                 Reference.reachabilityFence(payment_key);
160                 Reference.reachabilityFence(delayed_payment_base_key);
161                 Reference.reachabilityFence(htlc_base_key);
162                 Reference.reachabilityFence(commitment_seed);
163                 Reference.reachabilityFence(channel_value_satoshis);
164                 Reference.reachabilityFence(channel_keys_id);
165                 if (ret >= 0 && ret <= 4096) { return null; }
166                 InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InMemorySigner(null, ret); }
167                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
168                 return ret_hu_conv;
169         }
170
171         /**
172          * Counterparty pubkeys.
173          * Will panic if ready_channel wasn't called.
174          */
175         public ChannelPublicKeys counterparty_pubkeys() {
176                 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
177                 Reference.reachabilityFence(this);
178                 if (ret >= 0 && ret <= 4096) { return null; }
179                 ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelPublicKeys(null, ret); }
180                 ret_hu_conv.ptrs_to.add(this);
181                 return ret_hu_conv;
182         }
183
184         /**
185          * The contest_delay value specified by our counterparty and applied on holder-broadcastable
186          * transactions, ie the amount of time that we have to wait to recover our funds if we
187          * broadcast a transaction.
188          * Will panic if ready_channel wasn't called.
189          */
190         public short counterparty_selected_contest_delay() {
191                 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
192                 Reference.reachabilityFence(this);
193                 return ret;
194         }
195
196         /**
197          * The contest_delay value specified by us and applied on transactions broadcastable
198          * by our counterparty, ie the amount of time that they have to wait to recover their funds
199          * if they broadcast a transaction.
200          * Will panic if ready_channel wasn't called.
201          */
202         public short holder_selected_contest_delay() {
203                 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
204                 Reference.reachabilityFence(this);
205                 return ret;
206         }
207
208         /**
209          * Whether the holder is the initiator
210          * Will panic if ready_channel wasn't called.
211          */
212         public boolean is_outbound() {
213                 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
214                 Reference.reachabilityFence(this);
215                 return ret;
216         }
217
218         /**
219          * Funding outpoint
220          * Will panic if ready_channel wasn't called.
221          */
222         public OutPoint funding_outpoint() {
223                 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
224                 Reference.reachabilityFence(this);
225                 if (ret >= 0 && ret <= 4096) { return null; }
226                 OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new OutPoint(null, ret); }
227                 ret_hu_conv.ptrs_to.add(this);
228                 return ret_hu_conv;
229         }
230
231         /**
232          * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
233          * building transactions.
234          * 
235          * Will panic if ready_channel wasn't called.
236          */
237         public ChannelTransactionParameters get_channel_parameters() {
238                 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
239                 Reference.reachabilityFence(this);
240                 if (ret >= 0 && ret <= 4096) { return null; }
241                 ChannelTransactionParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelTransactionParameters(null, ret); }
242                 ret_hu_conv.ptrs_to.add(this);
243                 return ret_hu_conv;
244         }
245
246         /**
247          * Whether anchors should be used.
248          * Will panic if ready_channel wasn't called.
249          */
250         public boolean opt_anchors() {
251                 boolean ret = bindings.InMemorySigner_opt_anchors(this.ptr);
252                 Reference.reachabilityFence(this);
253                 return ret;
254         }
255
256         /**
257          * Sign the single input of spend_tx at index `input_idx` which spends the output
258          * described by descriptor, returning the witness stack for the input.
259          * 
260          * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
261          * or is not spending the outpoint described by `descriptor.outpoint`.
262          */
263         public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
264                 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
265                 Reference.reachabilityFence(this);
266                 Reference.reachabilityFence(spend_tx);
267                 Reference.reachabilityFence(input_idx);
268                 Reference.reachabilityFence(descriptor);
269                 if (ret >= 0 && ret <= 4096) { return null; }
270                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
271                 this.ptrs_to.add(descriptor);
272                 return ret_hu_conv;
273         }
274
275         /**
276          * Sign the single input of spend_tx at index `input_idx` which spends the output
277          * described by descriptor, returning the witness stack for the input.
278          * 
279          * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
280          * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
281          * sequence set to `descriptor.to_self_delay`.
282          */
283         public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
284                 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
285                 Reference.reachabilityFence(this);
286                 Reference.reachabilityFence(spend_tx);
287                 Reference.reachabilityFence(input_idx);
288                 Reference.reachabilityFence(descriptor);
289                 if (ret >= 0 && ret <= 4096) { return null; }
290                 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
291                 this.ptrs_to.add(descriptor);
292                 return ret_hu_conv;
293         }
294
295         /**
296          * Constructs a new BaseSign which calls the relevant methods on this_arg.
297          * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
298          */
299         public BaseSign as_BaseSign() {
300                 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
301                 Reference.reachabilityFence(this);
302                 if (ret >= 0 && ret <= 4096) { return null; }
303                 BaseSign ret_hu_conv = new BaseSign(null, ret);
304                 ret_hu_conv.ptrs_to.add(this);
305                 return ret_hu_conv;
306         }
307
308         /**
309          * Constructs a new Sign which calls the relevant methods on this_arg.
310          * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
311          */
312         public Sign as_Sign() {
313                 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
314                 Reference.reachabilityFence(this);
315                 if (ret >= 0 && ret <= 4096) { return null; }
316                 Sign ret_hu_conv = new Sign(null, ret);
317                 ret_hu_conv.ptrs_to.add(this);
318                 return ret_hu_conv;
319         }
320
321         /**
322          * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
323          */
324         public byte[] write() {
325                 byte[] ret = bindings.InMemorySigner_write(this.ptr);
326                 Reference.reachabilityFence(this);
327                 return ret;
328         }
329
330         /**
331          * Read a InMemorySigner from a byte array, created by InMemorySigner_write
332          */
333         public static Result_InMemorySignerDecodeErrorZ read(byte[] ser) {
334                 long ret = bindings.InMemorySigner_read(ser);
335                 Reference.reachabilityFence(ser);
336                 if (ret >= 0 && ret <= 4096) { return null; }
337                 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);
338                 return ret_hu_conv;
339         }
340
341 }