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