]> git.bitcoin.ninja Git - ldk-java/blob - c_sharp/src/org/ldk/structs/NodeSigner.cs
Update CI references to LDK 0.0.124 drop stale memchr pins
[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(RawBolt11Invoice invoice, 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.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.clone_ptr();
127                         return result;
128                 }
129                 public long sign_invoice(long _invoice, Recipient _recipient) {
130                         org.ldk.structs.RawBolt11Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.RawBolt11Invoice(null, _invoice); }
131                         Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_invoice_hu_conv, _recipient);
132                                 GC.KeepAlive(arg);
133                         long result = ret.clone_ptr();
134                         return result;
135                 }
136                 public long sign_bolt12_invoice_request(long _invoice_request) {
137                         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); }
138                         Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice_request(_invoice_request_hu_conv);
139                                 GC.KeepAlive(arg);
140                         long result = ret.clone_ptr();
141                         return result;
142                 }
143                 public long sign_bolt12_invoice(long _invoice) {
144                         org.ldk.structs.UnsignedBolt12Invoice _invoice_hu_conv = null; if (_invoice < 0 || _invoice > 4096) { _invoice_hu_conv = new org.ldk.structs.UnsignedBolt12Invoice(null, _invoice); }
145                         Result_SchnorrSignatureNoneZ ret = arg.sign_bolt12_invoice(_invoice_hu_conv);
146                                 GC.KeepAlive(arg);
147                         long result = ret.clone_ptr();
148                         return result;
149                 }
150                 public long sign_gossip_message(long _msg) {
151                         org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
152                         if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
153                         Result_ECDSASignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
154                                 GC.KeepAlive(arg);
155                         long result = ret.clone_ptr();
156                         return result;
157                 }
158         }
159
160         /** Creates a new instance of NodeSigner from a given implementation */
161         public static NodeSigner new_impl(NodeSignerInterface arg) {
162                 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
163                 LDKNodeSignerImpl impl = new LDKNodeSignerImpl(arg, impl_holder);
164                 long[] ptr_idx = bindings.LDKNodeSigner_new(impl);
165
166                 impl_holder.held = new NodeSigner(null, ptr_idx[0]);
167                 impl_holder.held.instance_idx = ptr_idx[1];
168                 impl_holder.held.bindings_instance = impl;
169                 return impl_holder.held;
170         }
171
172         /**
173          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
174          * 
175          * If the implementor of this trait supports [phantom node payments], then every node that is
176          * intended to be included in the phantom invoice route hints must return the same value from
177          * this method.
178          * 
179          * This method must return the same value each time it is called.
180          * 
181          * [phantom node payments]: PhantomKeysManager
182          */
183         public byte[] get_inbound_payment_key_material() {
184                 long ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
185                 GC.KeepAlive(this);
186                 if (ret >= 0 && ret <= 4096) { return null; }
187                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
188                 return ret_conv;
189         }
190
191         /**
192          * Get node id based on the provided [`Recipient`].
193          * 
194          * This method must return the same value each time it is called with a given [`Recipient`]
195          * parameter.
196          * 
197          * Errors if the [`Recipient`] variant is not supported by the implementation.
198          */
199         public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
200                 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
201                 GC.KeepAlive(this);
202                 GC.KeepAlive(recipient);
203                 if (ret >= 0 && ret <= 4096) { return null; }
204                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
205                 return ret_hu_conv;
206         }
207
208         /**
209          * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
210          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
211          * secret, though this is less efficient.
212          * 
213          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
214          * should be resolved to allow LDK to resume forwarding HTLCs.
215          * 
216          * Errors if the [`Recipient`] variant is not supported by the implementation.
217          */
218         public Result_ThirtyTwoBytesNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_BigEndianScalarZ tweak) {
219                 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(other_key, 33)), tweak.ptr);
220                 GC.KeepAlive(this);
221                 GC.KeepAlive(recipient);
222                 GC.KeepAlive(other_key);
223                 GC.KeepAlive(tweak);
224                 if (ret >= 0 && ret <= 4096) { return null; }
225                 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
226                 return ret_hu_conv;
227         }
228
229         /**
230          * Sign an invoice.
231          * 
232          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
233          * this trait to parse the invoice and make sure they're signing what they expect, rather than
234          * blindly signing the hash.
235          * 
236          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
237          * 
238          * The secret key used to sign the invoice is dependent on the [`Recipient`].
239          * 
240          * Errors if the [`Recipient`] variant is not supported by the implementation.
241          */
242         public Result_RecoverableSignatureNoneZ sign_invoice(org.ldk.structs.RawBolt11Invoice invoice, Recipient recipient) {
243                 long ret = bindings.NodeSigner_sign_invoice(this.ptr, invoice.ptr, recipient);
244                 GC.KeepAlive(this);
245                 GC.KeepAlive(invoice);
246                 GC.KeepAlive(recipient);
247                 if (ret >= 0 && ret <= 4096) { return null; }
248                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
249                 if (this != null) { this.ptrs_to.AddLast(invoice); };
250                 return ret_hu_conv;
251         }
252
253         /**
254          * Signs the [`TaggedHash`] of a BOLT 12 invoice request.
255          * 
256          * May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
257          * `invoice_request` is the callee.
258          * 
259          * Implementors may check that the `invoice_request` is expected rather than blindly signing
260          * the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
261          * the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
262          * [`UnsignedInvoiceRequest::payer_id`].
263          * 
264          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
265          */
266         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice_request(org.ldk.structs.UnsignedInvoiceRequest invoice_request) {
267                 long ret = bindings.NodeSigner_sign_bolt12_invoice_request(this.ptr, invoice_request.ptr);
268                 GC.KeepAlive(this);
269                 GC.KeepAlive(invoice_request);
270                 if (ret >= 0 && ret <= 4096) { return null; }
271                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
272                 if (this != null) { this.ptrs_to.AddLast(invoice_request); };
273                 return ret_hu_conv;
274         }
275
276         /**
277          * Signs the [`TaggedHash`] of a BOLT 12 invoice.
278          * 
279          * May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
280          * callee.
281          * 
282          * Implementors may check that the `invoice` is expected rather than blindly signing the tagged
283          * hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
284          * key or an ephemeral key to preserve privacy, whichever is associated with
285          * [`UnsignedBolt12Invoice::signing_pubkey`].
286          * 
287          * [`TaggedHash`]: crate::offers::merkle::TaggedHash
288          */
289         public Result_SchnorrSignatureNoneZ sign_bolt12_invoice(org.ldk.structs.UnsignedBolt12Invoice invoice) {
290                 long ret = bindings.NodeSigner_sign_bolt12_invoice(this.ptr, invoice.ptr);
291                 GC.KeepAlive(this);
292                 GC.KeepAlive(invoice);
293                 if (ret >= 0 && ret <= 4096) { return null; }
294                 Result_SchnorrSignatureNoneZ ret_hu_conv = Result_SchnorrSignatureNoneZ.constr_from_ptr(ret);
295                 if (this != null) { this.ptrs_to.AddLast(invoice); };
296                 return ret_hu_conv;
297         }
298
299         /**
300          * Sign a gossip message.
301          * 
302          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
303          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
304          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
305          * corresponding channel.
306          */
307         public Result_ECDSASignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
308                 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
309                 GC.KeepAlive(this);
310                 GC.KeepAlive(msg);
311                 if (ret >= 0 && ret <= 4096) { return null; }
312                 Result_ECDSASignatureNoneZ ret_hu_conv = Result_ECDSASignatureNoneZ.constr_from_ptr(ret);
313                 return ret_hu_conv;
314         }
315
316 }
317 } } }