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