[C#] Update auto-generated files
[ldk-java] / c_sharp / src / org / ldk / structs / NodeSigner.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * A trait that can handle cryptographic operations at the scope level of a node.
10  */
11 public class NodeSigner : CommonBase {
12         internal readonly bindings.LDKNodeSigner bindings_instance;
13         internal NodeSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14         private NodeSigner(bindings.LDKNodeSigner arg) : base(bindings.LDKNodeSigner_new(arg)) {
15                 this.ptrs_to.AddLast(arg);
16                 this.bindings_instance = arg;
17         }
18         ~NodeSigner() {
19                 if (ptr != 0) { bindings.NodeSigner_free(ptr); }
20         }
21
22         public interface NodeSignerInterface {
23                 /**
24                  * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
25                  * 
26                  * If the implementor of this trait supports [phantom node payments], then every node that is
27                  * intended to be included in the phantom invoice route hints must return the same value from
28                  * this method.
29                  * 
30                  * This method must return the same value each time it is called.
31                  * 
32                  * [phantom node payments]: PhantomKeysManager
33                  */
34                 byte[] get_inbound_payment_key_material();
35                 /**
36                  * Get node id based on the provided [`Recipient`].
37                  * 
38                  * This method must return the same value each time it is called with a given [`Recipient`]
39                  * parameter.
40                  * 
41                  * Errors if the [`Recipient`] variant is not supported by the implementation.
42                  */
43                 Result_PublicKeyNoneZ get_node_id(Recipient _recipient);
44                 /**
45                  * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
46                  * one is provided. Note that this tweak can be applied to `other_key` instead of our node
47                  * secret, though this is less efficient.
48                  * 
49                  * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
50                  * should be resolved to allow LDK to resume forwarding HTLCs.
51                  * 
52                  * Errors if the [`Recipient`] variant is not supported by the implementation.
53                  */
54                 Result_SharedSecretNoneZ ecdh(Recipient _recipient, byte[] _other_key, Option_ScalarZ _tweak);
55                 /**
56                  * Sign an invoice.
57                  * 
58                  * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
59                  * this trait to parse the invoice and make sure they're signing what they expect, rather than
60                  * blindly signing the hash.
61                  * 
62                  * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
63                  * 
64                  * The secret key used to sign the invoice is dependent on the [`Recipient`].
65                  * 
66                  * Errors if the [`Recipient`] variant is not supported by the implementation.
67                  */
68                 Result_RecoverableSignatureNoneZ sign_invoice(byte[] _hrp_bytes, UInt5[] _invoice_data, Recipient _recipient);
69                 /**
70                  * Sign a gossip message.
71                  * 
72                  * Note that if this fails, LDK may panic and the message will not be broadcast to the network
73                  * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
74                  * message to be broadcast, as otherwise it may prevent one from receiving funds over the
75                  * corresponding channel.
76                  */
77                 Result_SignatureNoneZ sign_gossip_message(UnsignedGossipMessage _msg);
78         }
79         private class LDKNodeSignerHolder { internal NodeSigner held; }
80         private class LDKNodeSignerImpl : bindings.LDKNodeSigner {
81                 internal LDKNodeSignerImpl(NodeSignerInterface arg, LDKNodeSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
82                 private NodeSignerInterface arg;
83                 private LDKNodeSignerHolder impl_holder;
84                 public byte[] get_inbound_payment_key_material() {
85                         byte[] ret = arg.get_inbound_payment_key_material();
86                                 GC.KeepAlive(arg);
87                         byte[] result = InternalUtils.check_arr_len(ret, 32);
88                         return result;
89                 }
90                 public long get_node_id(Recipient _recipient) {
91                         Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
92                                 GC.KeepAlive(arg);
93                         long result = ret == null ? 0 : ret.clone_ptr();
94                         return result;
95                 }
96                 public long ecdh(Recipient _recipient, byte[] _other_key, long _tweak) {
97                         org.ldk.structs.Option_ScalarZ _tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(_tweak);
98                         if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
99                         Result_SharedSecretNoneZ ret = arg.ecdh(_recipient, _other_key, _tweak_hu_conv);
100                                 GC.KeepAlive(arg);
101                         long result = ret == null ? 0 : ret.clone_ptr();
102                         return result;
103                 }
104                 public long sign_invoice(byte[] _hrp_bytes, byte[] _invoice_data, Recipient _recipient) {
105                         int _invoice_data_conv_7_len = _invoice_data.Length;
106                         UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
107                         for (int h = 0; h < _invoice_data_conv_7_len; h++) {
108                                 byte _invoice_data_conv_7 = _invoice_data[h];
109                                 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
110                                 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
111                         }
112                         Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes, _invoice_data_conv_7_arr, _recipient);
113                                 GC.KeepAlive(arg);
114                         long result = ret == null ? 0 : ret.clone_ptr();
115                         return result;
116                 }
117                 public long sign_gossip_message(long _msg) {
118                         org.ldk.structs.UnsignedGossipMessage _msg_hu_conv = org.ldk.structs.UnsignedGossipMessage.constr_from_ptr(_msg);
119                         if (_msg_hu_conv != null) { _msg_hu_conv.ptrs_to.AddLast(this); };
120                         Result_SignatureNoneZ ret = arg.sign_gossip_message(_msg_hu_conv);
121                                 GC.KeepAlive(arg);
122                         long result = ret == null ? 0 : ret.clone_ptr();
123                         return result;
124                 }
125         }
126         public static NodeSigner new_impl(NodeSignerInterface arg) {
127                 LDKNodeSignerHolder impl_holder = new LDKNodeSignerHolder();
128                 impl_holder.held = new NodeSigner(new LDKNodeSignerImpl(arg, impl_holder));
129                 return impl_holder.held;
130         }
131         /**
132          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
133          * 
134          * If the implementor of this trait supports [phantom node payments], then every node that is
135          * intended to be included in the phantom invoice route hints must return the same value from
136          * this method.
137          * 
138          * This method must return the same value each time it is called.
139          * 
140          * [phantom node payments]: PhantomKeysManager
141          */
142         public byte[] get_inbound_payment_key_material() {
143                 byte[] ret = bindings.NodeSigner_get_inbound_payment_key_material(this.ptr);
144                 GC.KeepAlive(this);
145                 return ret;
146         }
147
148         /**
149          * Get node id based on the provided [`Recipient`].
150          * 
151          * This method must return the same value each time it is called with a given [`Recipient`]
152          * parameter.
153          * 
154          * Errors if the [`Recipient`] variant is not supported by the implementation.
155          */
156         public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
157                 long ret = bindings.NodeSigner_get_node_id(this.ptr, recipient);
158                 GC.KeepAlive(this);
159                 GC.KeepAlive(recipient);
160                 if (ret >= 0 && ret <= 4096) { return null; }
161                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
162                 return ret_hu_conv;
163         }
164
165         /**
166          * Gets the ECDH shared secret of our node secret and `other_key`, multiplying by `tweak` if
167          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
168          * secret, though this is less efficient.
169          * 
170          * Note that if this fails while attempting to forward an HTLC, LDK will panic. The error
171          * should be resolved to allow LDK to resume forwarding HTLCs.
172          * 
173          * Errors if the [`Recipient`] variant is not supported by the implementation.
174          */
175         public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
176                 long ret = bindings.NodeSigner_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
177                 GC.KeepAlive(this);
178                 GC.KeepAlive(recipient);
179                 GC.KeepAlive(other_key);
180                 GC.KeepAlive(tweak);
181                 if (ret >= 0 && ret <= 4096) { return null; }
182                 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
183                 if (this != null) { this.ptrs_to.AddLast(tweak); };
184                 return ret_hu_conv;
185         }
186
187         /**
188          * Sign an invoice.
189          * 
190          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
191          * this trait to parse the invoice and make sure they're signing what they expect, rather than
192          * blindly signing the hash.
193          * 
194          * The `hrp_bytes` are ASCII bytes, while the `invoice_data` is base32.
195          * 
196          * The secret key used to sign the invoice is dependent on the [`Recipient`].
197          * 
198          * Errors if the [`Recipient`] variant is not supported by the implementation.
199          */
200         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient recipient) {
201                 long ret = bindings.NodeSigner_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, recipient);
202                 GC.KeepAlive(this);
203                 GC.KeepAlive(hrp_bytes);
204                 GC.KeepAlive(invoice_data);
205                 GC.KeepAlive(recipient);
206                 if (ret >= 0 && ret <= 4096) { return null; }
207                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
208                 return ret_hu_conv;
209         }
210
211         /**
212          * Sign a gossip message.
213          * 
214          * Note that if this fails, LDK may panic and the message will not be broadcast to the network
215          * or a possible channel counterparty. If LDK panics, the error should be resolved to allow the
216          * message to be broadcast, as otherwise it may prevent one from receiving funds over the
217          * corresponding channel.
218          */
219         public Result_SignatureNoneZ sign_gossip_message(org.ldk.structs.UnsignedGossipMessage msg) {
220                 long ret = bindings.NodeSigner_sign_gossip_message(this.ptr, msg.ptr);
221                 GC.KeepAlive(this);
222                 GC.KeepAlive(msg);
223                 if (ret >= 0 && ret <= 4096) { return null; }
224                 Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
225                 if (this != null) { this.ptrs_to.AddLast(msg); };
226                 return ret_hu_conv;
227         }
228
229 }
230 } } }