[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / NodeSigner.cs
1
2 using org.ldk.impl;
3 using org.ldk.enums;
4 using org.ldk.util;
5 using System;
6
7 namespace org { namespace ldk { namespace structs {
8
9
10
11 /** An implementation of NodeSigner */
12 public interface NodeSignerInterface {
13         /**Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
14          * 
15          * If the implementor of this trait supports [phantom node payments], then every node that is
16          * intended to be included in the phantom invoice route hints must return the same value from
17          * this method.
18          * 
19          * This method must return the same value each time it is called.
20          * 
21          * [phantom node payments]: PhantomKeysManager
22          */
23         byte[] get_inbound_payment_key_material();
24         /**Get node id based on the provided [`Recipient`].
25          * 
26          * This method must return the same value each time it is called with a given [`Recipient`]
27          * parameter.
28          * 
29          * Errors if the [`Recipient`] variant is not supported by the implementation.
30          */
31         Result_PublicKeyNoneZ get_node_id(Recipient recipient);
32         /**Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
33          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
34          * secret, though this is less efficient.
35          * 
36          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
37          * should be resolved to allow LDK to resume forwarding HTLCs.
38          * 
39          * Errors if the [`Recipient`] variant is not supported by the implementation.
40          */
41         Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, Option_BigEndianScalarZ tweak);
42         /**Sign an invoice.
43          * 
44          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
45          * this trait to parse the invoice and make sure they're signing what they expect, rather than
46          * blindly signing the hash.
47          * 
48          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
49          * 
50          * The secret key used to sign the invoice is dependent on the [`Recipient`].
51          * 
52          * Errors if the [`Recipient`] variant is not supported by the implementation.
53          */
54         Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient);
55         /**Signs the [`TaggedHash`] of a BOLT 12 invoice request.
56          * 
57          * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
58          * `invoice_request` is the callee.
59          * 
60          * Implementors may check that the `invoice_request` is expected rather than blindly signing
61          * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
62          * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
63          * [`UnsignedInvoiceRequest::payer_id`].
64          * 
65          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
66          */
67         Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(UnsignedInvoiceRequest invoice_request);
68         /**Signs the [`TaggedHash`] of a BOLT 12 invoice.
69          * 
70          * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
71          * callee.
72          * 
73          * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
74          * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
75          * key or an ephemeral key to preserve privacy, whichever is associated with
76          * [`UnsignedBolt12Invoice::signing_pubkey`].
77          * 
78          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
79          */
80         Result_SchnorrSignatureNoneZ sign_bolt12_invoice(UnsignedBolt12Invoice invoice);
81         /**Sign a gossip message.
82          * 
83          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
84          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
85          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
86          * corresponding channel.
87          */
88         Result_ECDSASignatureNoneZ sign_gossip_message(UnsignedGossipMessage msg);
89 }
90
91 /**
92  * A trait that can handle cryptographic operations at the scope level of a node.
93  */
94 public class NodeSigner : CommonBase {
95         internal bindings.LDKNodeSigner bindings_instance;
96         internal long instance_idx;
97
98         internal NodeSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
99         ~NodeSigner() {
100                 if (ptr != 0) { bindings.NodeSigner_free(ptr); }
101         }
102
103         private class LDKNodeSignerHolder { internal NodeSigner held; }
104         private class LDKNodeSignerImpl : bindings.LDKNodeSigner {
105                 internal LDKNodeSignerImpl(NodeSignerInterface arg, LDKNodeSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
106                 private NodeSignerInterface arg;
107                 private LDKNodeSignerHolder impl_holder;
108                 public long get_inbound_payment_key_material() {
109                         byte[] ret = arg.get_inbound_payment_key_material();
110                                 GC.KeepAlive(arg);
111                         long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
112                         return result;
113                 }
114                 public long get_node_id(Recipient _recipient) {
115                         Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
116                                 GC.KeepAlive(arg);
117                         long result = ret == null ? 0 : ret.clone_ptr();
118                         return result;
119                 }
120                 public long ecdh(Recipient _recipient, long _other_key, long _tweak) {
121                         byte[] _other_key_conv = InternalUtils.decodeUint8Array(_other_key);
122                         org.ldk.structs.Option_BigEndianScalarZ _tweak_hu_conv = org.ldk.structs.Option_BigEndianScalarZ.constr_from_ptr(_tweak);
123                         if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
124                         Result_ThirtyTwoBytesNoneZ ret = arg.ecdh(_recipient, _other_key_conv, _tweak_hu_conv);
125                                 GC.KeepAlive(arg);
126                         long result = ret == null ? 0 : ret.clone_ptr();
127                         return result;
128                 }
129                 public long sign_invoice(long _hrp_bytes, long _invoice_data, Recipient _recipient) {
130                         byte[] _hrp_bytes_conv = InternalUtils.decodeUint8Array(_hrp_bytes);
131                         int _invoice_data_conv_7_len = InternalUtils.getArrayLength(_invoice_data);
132                         UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
133                         for (int h = 0; h < _invoice_data_conv_7_len; h++) {
134                                 byte _invoice_data_conv_7 = InternalUtils.getU8ArrayElem(_invoice_data, h);
135                                 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
136                                 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
137                         }
138                         bindings.free_buffer(_invoice_data);
139                         Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes_conv, _invoice_data_conv_7_arr, _recipient);
140                                 GC.KeepAlive(arg);
141                         long result = ret == null ? 0 : ret.clone_ptr();
142                         return result;
143                 }
144                 public long sign_bolt12_invoice_request(long _invoice_request) {
145                         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); }
146                         Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(_invoice_request_hu_conv);
147                                 GC.KeepAlive(arg);
148                         long result = ret == null ? 0 : ret.clone_ptr();
149                         return result;
150                 }
151                 public long sign_bolt12_invoice(long _invoice) {
152                         org.ldk.structs.UnsignedBolt12Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, _invoice); }
153                         Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(_invoice_hu_conv);
154                                 GC.KeepAlive(arg);
155                         long result = ret == null ? 0 : ret.clone_ptr();
156                         return result;
157                 }
158                 public long sign_gossip_message(long _msg) {
159                         org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
160                         if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
161                         Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
162                                 GC.KeepAlive(arg);
163                         long result = ret == null ? 0 : ret.clone_ptr();
164                         return result;
165                 }
166         }
167
168         /** Creates a new instance of NodeSigner from a given implementation */
169         public static NodeSigner new_impl(NodeSignerInterface arg) {
170                 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
171                 LDKNodeSignerImpl impl = new LDKNodeSignerImpl(arg, impl_holder);
172                 long[] ptr_idx = bindings.LDKNodeSigner_new(impl);
173
174                 impl_holder.held = new NodeSigner(null, ptr_idx[0]);
175                 impl_holder.held.instance_idx = ptr_idx[1];
176                 impl_holder.held.bindings_instance = impl;
177                 return impl_holder.held;
178         }
179
180         /**
181          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
182          * 
183          * If the implementor of this trait supports [phantom node payments], then every node that is
184          * intended to be included in the phantom invoice route hints must return the same value from
185          * this method.
186          * 
187          * This method must return the same value each time it is called.
188          * 
189          * [phantom node payments]: PhantomKeysManager
190          */
191         public byte[] get_inbound_payment_key_material() {
192                 long ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
193                 GC.KeepAlive(this);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
196                 return ret_conv;
197         }
198
199         /**
200          * Get node id based on the provided [`Recipient`].
201          * 
202          * This method must return the same value each time it is called with a given [`Recipient`]
203          * parameter.
204          * 
205          * Errors if the [`Recipient`] variant is not supported by the implementation.
206          */
207         public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
208                 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
209                 GC.KeepAlive(this);
210                 GC.KeepAlive(recipient);
211                 if (ret >= 0 && ret <= 4096) { return null; }
212                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
218          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
219          * secret, though this is less efficient.
220          * 
221          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
222          * should be resolved to allow LDK to resume forwarding HTLCs.
223          * 
224          * Errors if the [`Recipient`] variant is not supported by the implementation.
225          */
226         public Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
227                 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(other_key, 33)), tweak.ptr);
228                 GC.KeepAlive(this);
229                 GC.KeepAlive(recipient);
230                 GC.KeepAlive(other_key);
231                 GC.KeepAlive(tweak);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
234                 if (this != null) { this.ptrs_to.AddLast(tweak); };
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Sign an invoice.
240          * 
241          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
242          * this trait to parse the invoice and make sure they're signing what they expect, rather than
243          * blindly signing the hash.
244          * 
245          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
246          * 
247          * The secret key used to sign the invoice is dependent on the [`Recipient`].
248          * 
249          * Errors if the [`Recipient`] variant is not supported by the implementation.
250          */
251         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient) {
252                 long ret = bindings.NodeSigner_sign_invoice(this.ptr, InternalUtils.encodeUint8Array(hrp_bytes), InternalUtils.encodeUint8Array(InternalUtils.convUInt5Array(invoice_data)), recipient);
253                 GC.KeepAlive(this);
254                 GC.KeepAlive(hrp_bytes);
255                 GC.KeepAlive(invoice_data);
256                 GC.KeepAlive(recipient);
257                 if (ret >= 0 && ret <= 4096) { return null; }
258                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
259                 return ret_hu_conv;
260         }
261
262         /**
263          * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
264          * 
265          * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
266          * `invoice_request` is the callee.
267          * 
268          * Implementors may check that the `invoice_request` is expected rather than blindly signing
269          * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
270          * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
271          * [`UnsignedInvoiceRequest::payer_id`].
272          * 
273          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
274          */
275         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
276                 long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request == null ? 0 : invoice_request.ptr);
277                 GC.KeepAlive(this);
278                 GC.KeepAlive(invoice_request);
279                 if (ret >= 0 && ret <= 4096) { return null; }
280                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
281                 if (this != null) { this.ptrs_to.AddLast(invoice_request); };
282                 return ret_hu_conv;
283         }
284
285         /**
286          * Signs the [`TaggedHash`] of a BOLT 12 invoice.
287          * 
288          * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
289          * callee.
290          * 
291          * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
292          * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
293          * key or an ephemeral key to preserve privacy, whichever is associated with
294          * [`UnsignedBolt12Invoice::signing_pubkey`].
295          * 
296          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
297          */
298         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
299                 long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice == null ? 0 : invoice.ptr);
300                 GC.KeepAlive(this);
301                 GC.KeepAlive(invoice);
302                 if (ret >= 0 && ret <= 4096) { return null; }
303                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
304                 if (this != null) { this.ptrs_to.AddLast(invoice); };
305                 return ret_hu_conv;
306         }
307
308         /**
309          * Sign a gossip message.
310          * 
311          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
312          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
313          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
314          * corresponding channel.
315          */
316         public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
317                 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
318                 GC.KeepAlive(this);
319                 GC.KeepAlive(msg);
320                 if (ret >= 0 && ret <= 4096) { return null; }
321                 Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);
322                 if (this != null) { this.ptrs_to.AddLast(msg); };
323                 return ret_hu_conv;
324         }
325
326 }
327 } } }