Update auto-generated 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 javax.annotation.Nullable;
8
9 /**
10  * A trait to describe an object which can get user secrets and key material.
11  */
12 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
13 public class KeysInterface extends CommonBase {
14         final bindings.LDKKeysInterface bindings_instance;
15         KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
16         private KeysInterface(bindings.LDKKeysInterface arg) {
17                 super(bindings.LDKKeysInterface_new(arg));
18                 this.ptrs_to.add(arg);
19                 this.bindings_instance = arg;
20         }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
24         }
25
26         public static interface KeysInterfaceInterface {
27                 /**
28                  * Get node secret key (aka node_id or network_key).
29                  * 
30                  * This method must return the same value each time it is called.
31                  */
32                 byte[] get_node_secret();
33                 /**
34                  * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
35                  * 
36                  * This method should return a different value each time it is called, to avoid linking
37                  * on-chain funds across channels as controlled to the same user.
38                  */
39                 byte[] get_destination_script();
40                 /**
41                  * Get a script pubkey which we will send funds to when closing a channel.
42                  * 
43                  * This method should return a different value each time it is called, to avoid linking
44                  * on-chain funds across channels as controlled to the same user.
45                  */
46                 ShutdownScript get_shutdown_scriptpubkey();
47                 /**
48                  * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
49                  * restarted with some stale data!
50                  * 
51                  * This method must return a different value each time it is called.
52                  */
53                 Sign get_channel_signer(boolean inbound, long channel_value_satoshis);
54                 /**
55                  * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
56                  * onion packets and for temporary channel IDs. There is no requirement that these be
57                  * persisted anywhere, though they must be unique across restarts.
58                  * 
59                  * This method must return a different value each time it is called.
60                  */
61                 byte[] get_secure_random_bytes();
62                 /**
63                  * Reads a `Signer` for this `KeysInterface` from the given input stream.
64                  * This is only called during deserialization of other objects which contain
65                  * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
66                  * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
67                  * contain no versioning scheme. You may wish to include your own version prefix and ensure
68                  * you've read all of the provided bytes to ensure no corruption occurred.
69                  */
70                 Result_SignDecodeErrorZ read_chan_signer(byte[] reader);
71                 /**
72                  * Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's
73                  * preimage). By parameterizing by the preimage instead of the hash, we allow implementors of
74                  * this trait to parse the invoice and make sure they're signing what they expect, rather than
75                  * blindly signing the hash.
76                  */
77                 Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage);
78         }
79         private static class LDKKeysInterfaceHolder { KeysInterface held; }
80         public static KeysInterface new_impl(KeysInterfaceInterface arg) {
81                 final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
82                 impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
83                         @Override public byte[] get_node_secret() {
84                                 byte[] ret = arg.get_node_secret();
85                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
86                                 return result;
87                         }
88                         @Override public byte[] get_destination_script() {
89                                 byte[] ret = arg.get_destination_script();
90                                 return ret;
91                         }
92                         @Override public long get_shutdown_scriptpubkey() {
93                                 ShutdownScript ret = arg.get_shutdown_scriptpubkey();
94                                 long result = ret == null ? 0 : ret.clone_ptr();
95                                 return result;
96                         }
97                         @Override public long get_channel_signer(boolean inbound, long channel_value_satoshis) {
98                                 Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis);
99                                 long result = ret == null ? 0 : ret.clone_ptr();
100                                 impl_holder.held.ptrs_to.add(ret);
101                                 return result;
102                         }
103                         @Override public byte[] get_secure_random_bytes() {
104                                 byte[] ret = arg.get_secure_random_bytes();
105                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
106                                 return result;
107                         }
108                         @Override public long read_chan_signer(byte[] reader) {
109                                 Result_SignDecodeErrorZ ret = arg.read_chan_signer(reader);
110                                 long result = ret == null ? 0 : ret.clone_ptr();
111                                 return result;
112                         }
113                         @Override public long sign_invoice(byte[] invoice_preimage) {
114                                 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(invoice_preimage);
115                                 long result = ret == null ? 0 : ret.clone_ptr();
116                                 return result;
117                         }
118                 });
119                 return impl_holder.held;
120         }
121         /**
122          * Get node secret key (aka node_id or network_key).
123          * 
124          * This method must return the same value each time it is called.
125          */
126         public byte[] get_node_secret() {
127                 byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
128                 return ret;
129         }
130
131         /**
132          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
133          * 
134          * This method should return a different value each time it is called, to avoid linking
135          * on-chain funds across channels as controlled to the same user.
136          */
137         public byte[] get_destination_script() {
138                 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
139                 return ret;
140         }
141
142         /**
143          * Get a script pubkey which we will send funds to when closing a channel.
144          * 
145          * This method should return a different value each time it is called, to avoid linking
146          * on-chain funds across channels as controlled to the same user.
147          */
148         public ShutdownScript get_shutdown_scriptpubkey() {
149                 long ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr);
150                 if (ret >= 0 && ret <= 4096) { return null; }
151                 ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ShutdownScript(null, ret); }
152                 ret_hu_conv.ptrs_to.add(this);
153                 return ret_hu_conv;
154         }
155
156         /**
157          * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
158          * restarted with some stale data!
159          * 
160          * This method must return a different value each time it is called.
161          */
162         public Sign get_channel_signer(boolean inbound, long channel_value_satoshis) {
163                 long ret = bindings.KeysInterface_get_channel_signer(this.ptr, inbound, channel_value_satoshis);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 Sign ret_hu_conv = new Sign(null, ret);
166                 ret_hu_conv.ptrs_to.add(this);
167                 return ret_hu_conv;
168         }
169
170         /**
171          * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
172          * onion packets and for temporary channel IDs. There is no requirement that these be
173          * persisted anywhere, though they must be unique across restarts.
174          * 
175          * This method must return a different value each time it is called.
176          */
177         public byte[] get_secure_random_bytes() {
178                 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
179                 return ret;
180         }
181
182         /**
183          * Reads a `Signer` for this `KeysInterface` from the given input stream.
184          * This is only called during deserialization of other objects which contain
185          * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
186          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
187          * contain no versioning scheme. You may wish to include your own version prefix and ensure
188          * you've read all of the provided bytes to ensure no corruption occurred.
189          */
190         public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
191                 long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
194                 return ret_hu_conv;
195         }
196
197         /**
198          * Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's
199          * preimage). By parameterizing by the preimage instead of the hash, we allow implementors of
200          * this trait to parse the invoice and make sure they're signing what they expect, rather than
201          * blindly signing the hash.
202          */
203         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] invoice_preimage) {
204                 long ret = bindings.KeysInterface_sign_invoice(this.ptr, invoice_preimage);
205                 if (ret >= 0 && ret <= 4096) { return null; }
206                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
207                 return ret_hu_conv;
208         }
209
210 }