[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / KeysInterface.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  * A trait to describe an object which can get user secrets and key material.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class KeysInterface extends CommonBase {
15         final bindings.LDKKeysInterface bindings_instance;
16         KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private KeysInterface(bindings.LDKKeysInterface arg) {
18                 super(bindings.LDKKeysInterface_new(arg));
19                 this.ptrs_to.add(arg);
20                 this.bindings_instance = arg;
21         }
22         @Override @SuppressWarnings("deprecation")
23         protected void finalize() throws Throwable {
24                 if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
25         }
26
27         public static interface KeysInterfaceInterface {
28                 /**
29                  * Get node secret key based on the provided [`Recipient`].
30                  * 
31                  * The node_id/network_key is the public key that corresponds to this secret key.
32                  * 
33                  * This method must return the same value each time it is called with a given `Recipient`
34                  * parameter.
35                  * 
36                  * Errors if the `Recipient` variant is not supported by the implementation.
37                  */
38                 Result_SecretKeyNoneZ get_node_secret(Recipient recipient);
39                 /**
40                  * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
41                  * [`get_node_secret`].
42                  * 
43                  * This method must return the same value each time it is called with a given `Recipient`
44                  * parameter.
45                  * 
46                  * Errors if the `Recipient` variant is not supported by the implementation.
47                  * 
48                  * [`get_node_secret`]: KeysInterface::get_node_secret
49                  */
50                 Result_PublicKeyNoneZ get_node_id(Recipient recipient);
51                 /**
52                  * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
53                  * one is provided. Note that this tweak can be applied to `other_key` instead of our node
54                  * secret, though this is less efficient.
55                  * 
56                  * Errors if the `Recipient` variant is not supported by the implementation.
57                  * 
58                  * [`node secret`]: Self::get_node_secret
59                  */
60                 Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, Option_ScalarZ tweak);
61                 /**
62                  * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
63                  * 
64                  * This method should return a different value each time it is called, to avoid linking
65                  * on-chain funds across channels as controlled to the same user.
66                  */
67                 byte[] get_destination_script();
68                 /**
69                  * Get a script pubkey which we will send funds to when closing a channel.
70                  * 
71                  * This method should return a different value each time it is called, to avoid linking
72                  * on-chain funds across channels as controlled to the same user.
73                  */
74                 ShutdownScript get_shutdown_scriptpubkey();
75                 /**
76                  * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
77                  * restarted with some stale data!
78                  * 
79                  * This method must return a different value each time it is called.
80                  */
81                 Sign get_channel_signer(boolean inbound, long channel_value_satoshis);
82                 /**
83                  * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
84                  * onion packets and for temporary channel IDs. There is no requirement that these be
85                  * persisted anywhere, though they must be unique across restarts.
86                  * 
87                  * This method must return a different value each time it is called.
88                  */
89                 byte[] get_secure_random_bytes();
90                 /**
91                  * Reads a `Signer` for this `KeysInterface` from the given input stream.
92                  * This is only called during deserialization of other objects which contain
93                  * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
94                  * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
95                  * contain no versioning scheme. You may wish to include your own version prefix and ensure
96                  * you've read all of the provided bytes to ensure no corruption occurred.
97                  */
98                 Result_SignDecodeErrorZ read_chan_signer(byte[] reader);
99                 /**
100                  * Sign an invoice.
101                  * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
102                  * this trait to parse the invoice and make sure they're signing what they expect, rather than
103                  * blindly signing the hash.
104                  * The hrp is ascii bytes, while the invoice data is base32.
105                  * 
106                  * The secret key used to sign the invoice is dependent on the [`Recipient`].
107                  * 
108                  * Errors if the `Recipient` variant is not supported by the implementation.
109                  */
110                 Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient receipient);
111                 /**
112                  * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
113                  * 
114                  * If the implementor of this trait supports [phantom node payments], then every node that is
115                  * intended to be included in the phantom invoice route hints must return the same value from
116                  * this method.
117                  * 
118                  * This method must return the same value each time it is called.
119                  * 
120                  * [phantom node payments]: PhantomKeysManager
121                  */
122                 byte[] get_inbound_payment_key_material();
123         }
124         private static class LDKKeysInterfaceHolder { KeysInterface held; }
125         public static KeysInterface new_impl(KeysInterfaceInterface arg) {
126                 final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
127                 impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
128                         @Override public long get_node_secret(Recipient recipient) {
129                                 Result_SecretKeyNoneZ ret = arg.get_node_secret(recipient);
130                                 Reference.reachabilityFence(arg);
131                                 long result = ret == null ? 0 : ret.clone_ptr();
132                                 return result;
133                         }
134                         @Override public long get_node_id(Recipient recipient) {
135                                 Result_PublicKeyNoneZ ret = arg.get_node_id(recipient);
136                                 Reference.reachabilityFence(arg);
137                                 long result = ret == null ? 0 : ret.clone_ptr();
138                                 return result;
139                         }
140                         @Override public long ecdh(Recipient recipient, byte[] other_key, long tweak) {
141                                 org.ldk.structs.Option_ScalarZ tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(tweak);
142                                 if (tweak_hu_conv != null) { tweak_hu_conv.ptrs_to.add(this); };
143                                 Result_SharedSecretNoneZ ret = arg.ecdh(recipient, other_key, tweak_hu_conv);
144                                 Reference.reachabilityFence(arg);
145                                 long result = ret == null ? 0 : ret.clone_ptr();
146                                 return result;
147                         }
148                         @Override public byte[] get_destination_script() {
149                                 byte[] ret = arg.get_destination_script();
150                                 Reference.reachabilityFence(arg);
151                                 return ret;
152                         }
153                         @Override public long get_shutdown_scriptpubkey() {
154                                 ShutdownScript ret = arg.get_shutdown_scriptpubkey();
155                                 Reference.reachabilityFence(arg);
156                                 long result = ret == null ? 0 : ret.clone_ptr();
157                                 return result;
158                         }
159                         @Override public long get_channel_signer(boolean inbound, long channel_value_satoshis) {
160                                 Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis);
161                                 Reference.reachabilityFence(arg);
162                                 long result = ret == null ? 0 : ret.clone_ptr();
163                                 if (impl_holder.held != null) { impl_holder.held.ptrs_to.add(ret); };
164                                 return result;
165                         }
166                         @Override public byte[] get_secure_random_bytes() {
167                                 byte[] ret = arg.get_secure_random_bytes();
168                                 Reference.reachabilityFence(arg);
169                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
170                                 return result;
171                         }
172                         @Override public long read_chan_signer(byte[] reader) {
173                                 Result_SignDecodeErrorZ ret = arg.read_chan_signer(reader);
174                                 Reference.reachabilityFence(arg);
175                                 long result = ret == null ? 0 : ret.clone_ptr();
176                                 return result;
177                         }
178                         @Override public long sign_invoice(byte[] hrp_bytes, byte[] invoice_data, Recipient receipient) {
179                                 int invoice_data_conv_7_len = invoice_data.length;
180                                 UInt5[] invoice_data_conv_7_arr = new UInt5[invoice_data_conv_7_len];
181                                 for (int h = 0; h < invoice_data_conv_7_len; h++) {
182                                         byte invoice_data_conv_7 = invoice_data[h];
183                                         UInt5 invoice_data_conv_7_conv = new UInt5(invoice_data_conv_7);
184                                         invoice_data_conv_7_arr[h] = invoice_data_conv_7_conv;
185                                 }
186                                 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(hrp_bytes, invoice_data_conv_7_arr, receipient);
187                                 Reference.reachabilityFence(arg);
188                                 long result = ret == null ? 0 : ret.clone_ptr();
189                                 return result;
190                         }
191                         @Override public byte[] get_inbound_payment_key_material() {
192                                 byte[] ret = arg.get_inbound_payment_key_material();
193                                 Reference.reachabilityFence(arg);
194                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
195                                 return result;
196                         }
197                 });
198                 return impl_holder.held;
199         }
200         /**
201          * Get node secret key based on the provided [`Recipient`].
202          * 
203          * The node_id/network_key is the public key that corresponds to this secret key.
204          * 
205          * This method must return the same value each time it is called with a given `Recipient`
206          * parameter.
207          * 
208          * Errors if the `Recipient` variant is not supported by the implementation.
209          */
210         public Result_SecretKeyNoneZ get_node_secret(org.ldk.enums.Recipient recipient) {
211                 long ret = bindings.KeysInterface_get_node_secret(this.ptr, recipient);
212                 Reference.reachabilityFence(this);
213                 Reference.reachabilityFence(recipient);
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 Result_SecretKeyNoneZ ret_hu_conv = Result_SecretKeyNoneZ.constr_from_ptr(ret);
216                 return ret_hu_conv;
217         }
218
219         /**
220          * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
221          * [`get_node_secret`].
222          * 
223          * This method must return the same value each time it is called with a given `Recipient`
224          * parameter.
225          * 
226          * Errors if the `Recipient` variant is not supported by the implementation.
227          * 
228          * [`get_node_secret`]: KeysInterface::get_node_secret
229          */
230         public Result_PublicKeyNoneZ get_node_id(org.ldk.enums.Recipient recipient) {
231                 long ret = bindings.KeysInterface_get_node_id(this.ptr, recipient);
232                 Reference.reachabilityFence(this);
233                 Reference.reachabilityFence(recipient);
234                 if (ret >= 0 && ret <= 4096) { return null; }
235                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
236                 return ret_hu_conv;
237         }
238
239         /**
240          * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
241          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
242          * secret, though this is less efficient.
243          * 
244          * Errors if the `Recipient` variant is not supported by the implementation.
245          * 
246          * [`node secret`]: Self::get_node_secret
247          */
248         public Result_SharedSecretNoneZ ecdh(org.ldk.enums.Recipient recipient, byte[] other_key, Option_ScalarZ tweak) {
249                 long ret = bindings.KeysInterface_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
250                 Reference.reachabilityFence(this);
251                 Reference.reachabilityFence(recipient);
252                 Reference.reachabilityFence(other_key);
253                 Reference.reachabilityFence(tweak);
254                 if (ret >= 0 && ret <= 4096) { return null; }
255                 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
256                 return ret_hu_conv;
257         }
258
259         /**
260          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
261          * 
262          * This method should return a different value each time it is called, to avoid linking
263          * on-chain funds across channels as controlled to the same user.
264          */
265         public byte[] get_destination_script() {
266                 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
267                 Reference.reachabilityFence(this);
268                 return ret;
269         }
270
271         /**
272          * Get a script pubkey which we will send funds to when closing a channel.
273          * 
274          * This method should return a different value each time it is called, to avoid linking
275          * on-chain funds across channels as controlled to the same user.
276          */
277         public ShutdownScript get_shutdown_scriptpubkey() {
278                 long ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr);
279                 Reference.reachabilityFence(this);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
282                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
283                 return ret_hu_conv;
284         }
285
286         /**
287          * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
288          * restarted with some stale data!
289          * 
290          * This method must return a different value each time it is called.
291          */
292         public Sign get_channel_signer(boolean inbound, long channel_value_satoshis) {
293                 long ret = bindings.KeysInterface_get_channel_signer(this.ptr, inbound, channel_value_satoshis);
294                 Reference.reachabilityFence(this);
295                 Reference.reachabilityFence(inbound);
296                 Reference.reachabilityFence(channel_value_satoshis);
297                 if (ret >= 0 && ret <= 4096) { return null; }
298                 Sign ret_hu_conv = new Sign(null, ret);
299                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
300                 return ret_hu_conv;
301         }
302
303         /**
304          * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
305          * onion packets and for temporary channel IDs. There is no requirement that these be
306          * persisted anywhere, though they must be unique across restarts.
307          * 
308          * This method must return a different value each time it is called.
309          */
310         public byte[] get_secure_random_bytes() {
311                 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
312                 Reference.reachabilityFence(this);
313                 return ret;
314         }
315
316         /**
317          * Reads a `Signer` for this `KeysInterface` from the given input stream.
318          * This is only called during deserialization of other objects which contain
319          * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
320          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
321          * contain no versioning scheme. You may wish to include your own version prefix and ensure
322          * you've read all of the provided bytes to ensure no corruption occurred.
323          */
324         public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
325                 long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
326                 Reference.reachabilityFence(this);
327                 Reference.reachabilityFence(reader);
328                 if (ret >= 0 && ret <= 4096) { return null; }
329                 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
330                 return ret_hu_conv;
331         }
332
333         /**
334          * Sign an invoice.
335          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
336          * this trait to parse the invoice and make sure they're signing what they expect, rather than
337          * blindly signing the hash.
338          * The hrp is ascii bytes, while the invoice data is base32.
339          * 
340          * The secret key used to sign the invoice is dependent on the [`Recipient`].
341          * 
342          * Errors if the `Recipient` variant is not supported by the implementation.
343          */
344         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, org.ldk.enums.Recipient receipient) {
345                 long ret = bindings.KeysInterface_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, receipient);
346                 Reference.reachabilityFence(this);
347                 Reference.reachabilityFence(hrp_bytes);
348                 Reference.reachabilityFence(invoice_data);
349                 Reference.reachabilityFence(receipient);
350                 if (ret >= 0 && ret <= 4096) { return null; }
351                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
352                 return ret_hu_conv;
353         }
354
355         /**
356          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
357          * 
358          * If the implementor of this trait supports [phantom node payments], then every node that is
359          * intended to be included in the phantom invoice route hints must return the same value from
360          * this method.
361          * 
362          * This method must return the same value each time it is called.
363          * 
364          * [phantom node payments]: PhantomKeysManager
365          */
366         public byte[] get_inbound_payment_key_material() {
367                 byte[] ret = bindings.KeysInterface_get_inbound_payment_key_material(this.ptr);
368                 Reference.reachabilityFence(this);
369                 return ret;
370         }
371
372 }