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