Update java bindings with new generator and new upstream code
[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
8 /**
9  * A trait to describe an object which can get user secrets and key material.
10  */
11 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
12 public class KeysInterface extends CommonBase {
13         final bindings.LDKKeysInterface bindings_instance;
14         KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
15         private KeysInterface(bindings.LDKKeysInterface arg) {
16                 super(bindings.LDKKeysInterface_new(arg));
17                 this.ptrs_to.add(arg);
18                 this.bindings_instance = arg;
19         }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
23         }
24
25         public static interface KeysInterfaceInterface {
26                 /**
27                  * Get node secret key (aka node_id or network_key).
28                  * 
29                  * This method must return the same value each time it is called.
30                  */
31                 byte[] get_node_secret();
32                 /**
33                  * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
34                  * 
35                  * This method should return a different value each time it is called, to avoid linking
36                  * on-chain funds across channels as controlled to the same user.
37                  */
38                 byte[] get_destination_script();
39                 /**
40                  * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing
41                  * 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                 byte[] get_shutdown_pubkey();
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         private static class LDKKeysInterfaceHolder { KeysInterface held; }
73         public static KeysInterface new_impl(KeysInterfaceInterface arg) {
74                 final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
75                 impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() {
76                         @Override public byte[] get_node_secret() {
77                                 byte[] ret = arg.get_node_secret();
78                                 return ret;
79                         }
80                         @Override public byte[] get_destination_script() {
81                                 byte[] ret = arg.get_destination_script();
82                                 return ret;
83                         }
84                         @Override public byte[] get_shutdown_pubkey() {
85                                 byte[] ret = arg.get_shutdown_pubkey();
86                                 return ret;
87                         }
88                         @Override public long get_channel_signer(boolean inbound, long channel_value_satoshis) {
89                                 Sign ret = arg.get_channel_signer(inbound, channel_value_satoshis);
90                                 long result = ret == null ? 0 : ret.ptr;
91                                 impl_holder.held.ptrs_to.add(ret);
92                                 return result;
93                         }
94                         @Override public byte[] get_secure_random_bytes() {
95                                 byte[] ret = arg.get_secure_random_bytes();
96                                 return ret;
97                         }
98                         @Override public long read_chan_signer(byte[] reader) {
99                                 Result_SignDecodeErrorZ ret = arg.read_chan_signer(reader);
100                                 long result = ret != null ? ret.ptr : 0;
101                                 return result;
102                         }
103                 });
104                 return impl_holder.held;
105         }
106         /**
107          * Get node secret key (aka node_id or network_key).
108          * 
109          * This method must return the same value each time it is called.
110          */
111         public byte[] get_node_secret() {
112                 byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
113                 return ret;
114         }
115
116         /**
117          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
118          * 
119          * This method should return a different value each time it is called, to avoid linking
120          * on-chain funds across channels as controlled to the same user.
121          */
122         public byte[] get_destination_script() {
123                 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
124                 return ret;
125         }
126
127         /**
128          * Get a public key which we will send funds to (in the form of a P2WPKH output) when closing
129          * a channel.
130          * 
131          * This method should return a different value each time it is called, to avoid linking
132          * on-chain funds across channels as controlled to the same user.
133          */
134         public byte[] get_shutdown_pubkey() {
135                 byte[] ret = bindings.KeysInterface_get_shutdown_pubkey(this.ptr);
136                 return ret;
137         }
138
139         /**
140          * Get a new set of Sign for per-channel secrets. These MUST be unique even if you
141          * restarted with some stale data!
142          * 
143          * This method must return a different value each time it is called.
144          */
145         public Sign get_channel_signer(boolean inbound, long channel_value_satoshis) {
146                 long ret = bindings.KeysInterface_get_channel_signer(this.ptr, inbound, channel_value_satoshis);
147                 Sign ret_hu_conv = new Sign(null, ret);
148                 ret_hu_conv.ptrs_to.add(this);
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
154          * onion packets and for temporary channel IDs. There is no requirement that these be
155          * persisted anywhere, though they must be unique across restarts.
156          * 
157          * This method must return a different value each time it is called.
158          */
159         public byte[] get_secure_random_bytes() {
160                 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
161                 return ret;
162         }
163
164         /**
165          * Reads a `Signer` for this `KeysInterface` from the given input stream.
166          * This is only called during deserialization of other objects which contain
167          * `Sign`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
168          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
169          * contain no versioning scheme. You may wish to include your own version prefix and ensure
170          * you've read all of the provided bytes to ensure no corruption occurred.
171          */
172         public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
173                 long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
174                 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
175                 return ret_hu_conv;
176         }
177
178 }