[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / NodeSigner.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 that can handle cryptographic operations at the scope level of a node.
12  */
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class NodeSigner extends CommonBase {
15         final bindings.LDKNodeSigner bindings_instance;
16         NodeSigner(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
17         private NodeSigner(bindings.LDKNodeSigner arg) {
18                 super(bindings.LDKNodeSigner_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.NodeSigner_free(ptr); } super.finalize();
25         }
26         /**
27          * Destroys the object, freeing associated resources. After this call, any access
28          * to this object may result in a SEGFAULT or worse.
29          *
30          * You should generally NEVER call this method. You should let the garbage collector
31          * do this for you when it finalizes objects. However, it may be useful for types
32          * which represent locks and should be closed immediately to avoid holding locks
33          * until the GC runs.
34          */
35         public void destroy() {
36                 if (ptr != 0) { bindings.NodeSigner_free(ptr); }
37                 ptr = 0;
38         }
39         public static interface NodeSignerInterface {
40                 /**
41                  * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
42                  * 
43                  * If the implementor of this trait supports [phantom node payments], then every node that is
44                  * intended to be included in the phantom invoice route hints must return the same value from
45                  * this method.
46                  * 
47                  * This method must return the same value each time it is called.
48                  * 
49                  * [phantom node payments]: PhantomKeysManager
50                  */
51                 byte[] get_inbound_payment_key_material();
52                 /**
53                  * Get node id based on the provided [`Recipient`].
54                  * 
55                  * This method must return the same value each time it is called with a given [`Recipient`]
56                  * parameter.
57                  * 
58                  * Errors if the [`Recipient`] variant is not supported by the implementation.
59                  */
60                 Result_PublicKeyNoneZ get_node_id(Recipient recipient);
61                 /**
62                  * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
63                  * one is provided. Note that this tweak can be applied to `other_key` instead of our node
64                  * secret, though this is less efficient.
65                  * 
66                  * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
67                  * should be resolved to allow LDK to resume forwarding HTLCs.
68                  * 
69                  * Errors if the [`Recipient`] variant is not supported by the implementation.
70                  */
71                 Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, Option_ScalarZ tweak);
72                 /**
73                  * Sign an invoice.
74                  * 
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                  * 
79                  * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
80                  * 
81                  * The secret key used to sign the invoice is dependent on the [`Recipient`].
82                  * 
83                  * Errors if the [`Recipient`] variant is not supported by the implementation.
84                  */
85                 Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient);
86                 /**
87                  * Sign a gossip message.
88                  * 
89                  * Note that if this fails, LDK may panic and the message will not be broadcast to the network
90                  * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
91                  * message to be broadcast, as otherwise it may prevent one from receiving funds over the
92                  * corresponding channel.
93                  */
94                 Result_SignatureNoneZ sign_gossip_message(UnsignedGossipMessage msg);
95         }
96         private static class LDKNodeSignerHolder { NodeSigner held; }
97         public static NodeSigner new_impl(NodeSignerInterface arg) {
98                 final LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
99                 impl_holder.held = new NodeSigner(new bindings.LDKNodeSigner() {
100                         @Override public byte[] get_inbound_payment_key_material() {
101                                 byte[] ret = arg.get_inbound_payment_key_material();
102                                 Reference.reachabilityFence(arg);
103                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
104                                 return result;
105                         }
106                         @Override public long get_node_id(Recipient recipient) {
107                                 Result_PublicKeyNoneZ ret = arg.get_node_id(recipient);
108                                 Reference.reachabilityFence(arg);
109                                 long result = ret == null ? 0 : ret.clone_ptr();
110                                 return result;
111                         }
112                         @Override public long ecdh(Recipient recipient, byte[] other_key, long tweak) {
113                                 org.ldk.structs.Option_ScalarZ tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(tweak);
114                                 if (tweak_hu_conv != null) { tweak_hu_conv.ptrs_to.add(this); };
115                                 Result_SharedSecretNoneZ ret = arg.ecdh(recipient, other_key, tweak_hu_conv);
116                                 Reference.reachabilityFence(arg);
117                                 long result = ret == null ? 0 : ret.clone_ptr();
118                                 return result;
119                         }
120                         @Override public long sign_invoice(byte[] hrp_bytes, byte[] invoice_data, Recipient recipient) {
121                                 int invoice_data_conv_7_len = invoice_data.length;
122                                 UInt5[] invoice_data_conv_7_arr = new UInt5[invoice_data_conv_7_len];
123                                 for (int h = 0; h < invoice_data_conv_7_len; h++) {
124                                         byte invoice_data_conv_7 = invoice_data[h];
125                                         UInt5 invoice_data_conv_7_conv = new UInt5(invoice_data_conv_7);
126                                         invoice_data_conv_7_arr[h] = invoice_data_conv_7_conv;
127                                 }
128                                 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(hrp_bytes, invoice_data_conv_7_arr, recipient);
129                                 Reference.reachabilityFence(arg);
130                                 long result = ret == null ? 0 : ret.clone_ptr();
131                                 return result;
132                         }
133                         @Override public long sign_gossip_message(long msg) {
134                                 org.ldk.structs.UnsignedGossipMessage msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(msg);
135                                 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
136                                 Result_SignatureNoneZ ret = arg.sign_gossip_message(msg_hu_conv);
137                                 Reference.reachabilityFence(arg);
138                                 long result = ret == null ? 0 : ret.clone_ptr();
139                                 return result;
140                         }
141                 });
142                 return impl_holder.held;
143         }
144         /**
145          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
146          * 
147          * If the implementor of this trait supports [phantom node payments], then every node that is
148          * intended to be included in the phantom invoice route hints must return the same value from
149          * this method.
150          * 
151          * This method must return the same value each time it is called.
152          * 
153          * [phantom node payments]: PhantomKeysManager
154          */
155         public byte[] get_inbound_payment_key_material() {
156                 byte[] ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
157                 Reference.reachabilityFence(this);
158                 return ret;
159         }
160
161         /**
162          * Get node id based on the provided [`Recipient`].
163          * 
164          * This method must return the same value each time it is called with a given [`Recipient`]
165          * parameter.
166          * 
167          * Errors if the [`Recipient`] variant is not supported by the implementation.
168          */
169         public Result_PublicKeyNoneZ get_node_id(org.ldk.enums.Recipient recipient) {
170                 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
171                 Reference.reachabilityFence(this);
172                 Reference.reachabilityFence(recipient);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
175                 return ret_hu_conv;
176         }
177
178         /**
179          * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
180          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
181          * secret, though this is less efficient.
182          * 
183          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
184          * should be resolved to allow LDK to resume forwarding HTLCs.
185          * 
186          * Errors if the [`Recipient`] variant is not supported by the implementation.
187          */
188         public Result_SharedSecretNoneZ ecdh(org.ldk.enums.Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
189                 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
190                 Reference.reachabilityFence(this);
191                 Reference.reachabilityFence(recipient);
192                 Reference.reachabilityFence(other_key);
193                 Reference.reachabilityFence(tweak);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
196                 if (this != null) { this.ptrs_to.add(tweak); };
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Sign an invoice.
202          * 
203          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
204          * this trait to parse the invoice and make sure they're signing what they expect, rather than
205          * blindly signing the hash.
206          * 
207          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
208          * 
209          * The secret key used to sign the invoice is dependent on the [`Recipient`].
210          * 
211          * Errors if the [`Recipient`] variant is not supported by the implementation.
212          */
213         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, org.ldk.enums.Recipient recipient) {
214                 long ret = bindings.NodeSigner_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, recipient);
215                 Reference.reachabilityFence(this);
216                 Reference.reachabilityFence(hrp_bytes);
217                 Reference.reachabilityFence(invoice_data);
218                 Reference.reachabilityFence(recipient);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
221                 return ret_hu_conv;
222         }
223
224         /**
225          * Sign a gossip message.
226          * 
227          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
228          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
229          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
230          * corresponding channel.
231          */
232         public Result_SignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
233                 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
234                 Reference.reachabilityFence(this);
235                 Reference.reachabilityFence(msg);
236                 if (ret >= 0 && ret <= 4096) { return null; }
237                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
238                 if (this != null) { this.ptrs_to.add(msg); };
239                 return ret_hu_conv;
240         }
241
242 }