[Java] Update auto-generated bindings to 0.0.117
[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_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, Option_BigEndianScalarZ 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                  * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
88                  * 
89                  * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
90                  * `invoice_request` is the callee.
91                  * 
92                  * Implementors may check that the `invoice_request` is expected rather than blindly signing
93                  * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
94                  * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
95                  * [`UnsignedInvoiceRequest::payer_id`].
96                  * 
97                  * [`TaggedHash`]: crate::offers::merkle::TaggedHash
98                  */
99                 Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(UnsignedInvoiceRequest invoice_request);
100                 /**
101                  * Signs the [`TaggedHash`] of a BOLT 12 invoice.
102                  * 
103                  * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
104                  * callee.
105                  * 
106                  * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
107                  * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
108                  * key or an ephemeral key to preserve privacy, whichever is associated with
109                  * [`UnsignedBolt12Invoice::signing_pubkey`].
110                  * 
111                  * [`TaggedHash`]: crate::offers::merkle::TaggedHash
112                  */
113                 Result_SchnorrSignatureNoneZ sign_bolt12_invoice(UnsignedBolt12Invoice invoice);
114                 /**
115                  * Sign a gossip message.
116                  * 
117                  * Note that if this fails, LDK may panic and the message will not be broadcast to the network
118                  * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
119                  * message to be broadcast, as otherwise it may prevent one from receiving funds over the
120                  * corresponding channel.
121                  */
122                 Result_ECDSASignatureNoneZ sign_gossip_message(UnsignedGossipMessage msg);
123         }
124         private static class LDKNodeSignerHolder { NodeSigner held; }
125         public static NodeSigner new_impl(NodeSignerInterface arg) {
126                 final LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
127                 impl_holder.held = new NodeSigner(new bindings.LDKNodeSigner() {
128                         @Override public byte[] get_inbound_payment_key_material() {
129                                 byte[] ret = arg.get_inbound_payment_key_material();
130                                 Reference.reachabilityFence(arg);
131                                 byte[] result = InternalUtils.check_arr_len(ret, 32);
132                                 return result;
133                         }
134                         @Override public long get_node_id(Recipient recipient) {
135                                 Result_PublicKeyNoneZ ret = arg.get_node_id(recipient);
136                                 Reference.reachabilityFence(arg);
137                                 long result = ret == null ? 0 : ret.clone_ptr();
138                                 return result;
139                         }
140                         @Override public long ecdh(Recipient recipient, byte[] other_key, long tweak) {
141                                 org.ldk.structs.Option_BigEndianScalarZ tweak_hu_conv = org.ldk.structs.Option_BigEndianScalarZ.constr_from_ptr(tweak);
142                                 if (tweak_hu_conv != null) { tweak_hu_conv.ptrs_to.add(this); };
143                                 Result_ThirtyTwoBytesNoneZ ret = arg.ecdh(recipient, other_key, tweak_hu_conv);
144                                 Reference.reachabilityFence(arg);
145                                 long result = ret == null ? 0 : ret.clone_ptr();
146                                 return result;
147                         }
148                         @Override public long sign_invoice(byte[] hrp_bytes, byte[] invoice_data, Recipient recipient) {
149                                 int invoice_data_conv_7_len = invoice_data.length;
150                                 UInt5[] invoice_data_conv_7_arr = new UInt5[invoice_data_conv_7_len];
151                                 for (int h = 0; h < invoice_data_conv_7_len; h++) {
152                                         byte invoice_data_conv_7 = invoice_data[h];
153                                         UInt5 invoice_data_conv_7_conv = new UInt5(invoice_data_conv_7);
154                                         invoice_data_conv_7_arr[h] = invoice_data_conv_7_conv;
155                                 }
156                                 Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(hrp_bytes, invoice_data_conv_7_arr, recipient);
157                                 Reference.reachabilityFence(arg);
158                                 long result = ret == null ? 0 : ret.clone_ptr();
159                                 return result;
160                         }
161                         @Override public long sign_bolt12_invoice_request(long invoice_request) {
162                                 org.ldk.structs.UnsignedInvoiceRequest invoice_request_hu_conv = null; if (invoice_request < 0 || invoice_request > 4096) { invoice_request_hu_conv = new org.ldk.structs.UnsignedInvoiceRequest(null, invoice_request); }
163                                 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(invoice_request_hu_conv);
164                                 Reference.reachabilityFence(arg);
165                                 long result = ret == null ? 0 : ret.clone_ptr();
166                                 return result;
167                         }
168                         @Override public long sign_bolt12_invoice(long invoice) {
169                                 org.ldk.structs.UnsignedBolt12Invoice invoice_hu_conv = null; if (invoice < 0 || invoice > 4096) { invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, invoice); }
170                                 Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(invoice_hu_conv);
171                                 Reference.reachabilityFence(arg);
172                                 long result = ret == null ? 0 : ret.clone_ptr();
173                                 return result;
174                         }
175                         @Override public long sign_gossip_message(long msg) {
176                                 org.ldk.structs.UnsignedGossipMessage msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(msg);
177                                 if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
178                                 Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(msg_hu_conv);
179                                 Reference.reachabilityFence(arg);
180                                 long result = ret == null ? 0 : ret.clone_ptr();
181                                 return result;
182                         }
183                 });
184                 return impl_holder.held;
185         }
186         /**
187          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
188          * 
189          * If the implementor of this trait supports [phantom node payments], then every node that is
190          * intended to be included in the phantom invoice route hints must return the same value from
191          * this method.
192          * 
193          * This method must return the same value each time it is called.
194          * 
195          * [phantom node payments]: PhantomKeysManager
196          */
197         public byte[] get_inbound_payment_key_material() {
198                 byte[] ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
199                 Reference.reachabilityFence(this);
200                 return ret;
201         }
202
203         /**
204          * Get node id based on the provided [`Recipient`].
205          * 
206          * This method must return the same value each time it is called with a given [`Recipient`]
207          * parameter.
208          * 
209          * Errors if the [`Recipient`] variant is not supported by the implementation.
210          */
211         public Result_PublicKeyNoneZ get_node_id(org.ldk.enums.Recipient recipient) {
212                 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
213                 Reference.reachabilityFence(this);
214                 Reference.reachabilityFence(recipient);
215                 if (ret >= 0 && ret <= 4096) { return null; }
216                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
217                 return ret_hu_conv;
218         }
219
220         /**
221          * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
222          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
223          * secret, though this is less efficient.
224          * 
225          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
226          * should be resolved to allow LDK to resume forwarding HTLCs.
227          * 
228          * Errors if the [`Recipient`] variant is not supported by the implementation.
229          */
230         public Result_ThirtyTwoBytesNoneZ ecdh(org.ldk.enums.Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
231                 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
232                 Reference.reachabilityFence(this);
233                 Reference.reachabilityFence(recipient);
234                 Reference.reachabilityFence(other_key);
235                 Reference.reachabilityFence(tweak);
236                 if (ret >= 0 && ret <= 4096) { return null; }
237                 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
238                 if (this != null) { this.ptrs_to.add(tweak); };
239                 return ret_hu_conv;
240         }
241
242         /**
243          * Sign an invoice.
244          * 
245          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
246          * this trait to parse the invoice and make sure they're signing what they expect, rather than
247          * blindly signing the hash.
248          * 
249          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
250          * 
251          * The secret key used to sign the invoice is dependent on the [`Recipient`].
252          * 
253          * Errors if the [`Recipient`] variant is not supported by the implementation.
254          */
255         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, org.ldk.enums.Recipient recipient) {
256                 long ret = bindings.NodeSigner_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, recipient);
257                 Reference.reachabilityFence(this);
258                 Reference.reachabilityFence(hrp_bytes);
259                 Reference.reachabilityFence(invoice_data);
260                 Reference.reachabilityFence(recipient);
261                 if (ret >= 0 && ret <= 4096) { return null; }
262                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
263                 return ret_hu_conv;
264         }
265
266         /**
267          * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
268          * 
269          * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
270          * `invoice_request` is the callee.
271          * 
272          * Implementors may check that the `invoice_request` is expected rather than blindly signing
273          * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
274          * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
275          * [`UnsignedInvoiceRequest::payer_id`].
276          * 
277          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
278          */
279         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
280                 long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request == null ? 0 : invoice_request.ptr);
281                 Reference.reachabilityFence(this);
282                 Reference.reachabilityFence(invoice_request);
283                 if (ret >= 0 && ret <= 4096) { return null; }
284                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
285                 if (this != null) { this.ptrs_to.add(invoice_request); };
286                 return ret_hu_conv;
287         }
288
289         /**
290          * Signs the [`TaggedHash`] of a BOLT 12 invoice.
291          * 
292          * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
293          * callee.
294          * 
295          * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
296          * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
297          * key or an ephemeral key to preserve privacy, whichever is associated with
298          * [`UnsignedBolt12Invoice::signing_pubkey`].
299          * 
300          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
301          */
302         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
303                 long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice == null ? 0 : invoice.ptr);
304                 Reference.reachabilityFence(this);
305                 Reference.reachabilityFence(invoice);
306                 if (ret >= 0 && ret <= 4096) { return null; }
307                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
308                 if (this != null) { this.ptrs_to.add(invoice); };
309                 return ret_hu_conv;
310         }
311
312         /**
313          * Sign a gossip message.
314          * 
315          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
316          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
317          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
318          * corresponding channel.
319          */
320         public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
321                 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
322                 Reference.reachabilityFence(this);
323                 Reference.reachabilityFence(msg);
324                 if (ret >= 0 && ret <= 4096) { return null; }
325                 Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);
326                 if (this != null) { this.ptrs_to.add(msg); };
327                 return ret_hu_conv;
328         }
329
330 }