[C#] Add marshaling logic for array C# -> C conversion
[ldk-java] / c_sharp / src / org / ldk / structs / KeysInterface.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 to describe an object which can get user secrets and key material.
10  */
11 public class KeysInterface : CommonBase {
12         internal readonly bindings.LDKKeysInterface bindings_instance;
13         internal KeysInterface(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14         private KeysInterface(bindings.LDKKeysInterface arg) : base(bindings.LDKKeysInterface_new(arg)) {
15                 this.ptrs_to.AddLast(arg);
16                 this.bindings_instance = arg;
17         }
18         ~KeysInterface() {
19                 if (ptr != 0) { bindings.KeysInterface_free(ptr); }
20         }
21
22         public interface KeysInterfaceInterface {
23                 /**
24                  * Get node secret key based on the provided [`Recipient`].
25                  * 
26                  * The `node_id`/`network_key` is the public key that corresponds to this secret key.
27                  * 
28                  * This method must return the same value each time it is called with a given [`Recipient`]
29                  * parameter.
30                  * 
31                  * Errors if the [`Recipient`] variant is not supported by the implementation.
32                  */
33                 Result_SecretKeyNoneZ get_node_secret(Recipient _recipient);
34                 /**
35                  * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
36                  * [`get_node_secret`].
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                  * [`get_node_secret`]: Self::get_node_secret
44                  */
45                 Result_PublicKeyNoneZ get_node_id(Recipient _recipient);
46                 /**
47                  * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
48                  * one is provided. Note that this tweak can be applied to `other_key` instead of our node
49                  * secret, though this is less efficient.
50                  * 
51                  * Errors if the [`Recipient`] variant is not supported by the implementation.
52                  * 
53                  * [`node secret`]: Self::get_node_secret
54                  */
55                 Result_SharedSecretNoneZ ecdh(Recipient _recipient, byte[] _other_key, Option_ScalarZ _tweak);
56                 /**
57                  * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
58                  * 
59                  * This method should return a different value each time it is called, to avoid linking
60                  * on-chain funds across channels as controlled to the same user.
61                  */
62                 byte[] get_destination_script();
63                 /**
64                  * Get a script pubkey which we will send funds to when closing a channel.
65                  * 
66                  * This method should return a different value each time it is called, to avoid linking
67                  * on-chain funds across channels as controlled to the same user.
68                  */
69                 ShutdownScript get_shutdown_scriptpubkey();
70                 /**
71                  * Get a new set of [`Sign`] for per-channel secrets. These MUST be unique even if you
72                  * restarted with some stale data!
73                  * 
74                  * This method must return a different value each time it is called.
75                  */
76                 byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, UInt128 _user_channel_id);
77                 /**
78                  * Derives the private key material backing a `Signer`.
79                  * 
80                  * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
81                  * [`KeysInterface::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
82                  * re-derived from its `channel_keys_id`, which can be obtained through its trait method
83                  * [`BaseSign::channel_keys_id`].
84                  */
85                 Sign derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id);
86                 /**
87                  * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
88                  * onion packets and for temporary channel IDs. There is no requirement that these be
89                  * persisted anywhere, though they must be unique across restarts.
90                  * 
91                  * This method must return a different value each time it is called.
92                  */
93                 byte[] get_secure_random_bytes();
94                 /**
95                  * Reads a [`Signer`] for this [`KeysInterface`] from the given input stream.
96                  * This is only called during deserialization of other objects which contain
97                  * [`Sign`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
98                  * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
99                  * contain no versioning scheme. You may wish to include your own version prefix and ensure
100                  * you've read all of the provided bytes to ensure no corruption occurred.
101                  * 
102                  * This method is slowly being phased out -- it will only be called when reading objects
103                  * written by LDK versions prior to 0.0.113.
104                  * 
105                  * [`Signer`]: Self::Signer
106                  * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
107                  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
108                  */
109                 Result_SignDecodeErrorZ read_chan_signer(byte[] _reader);
110                 /**
111                  * Sign an invoice.
112                  * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
113                  * this trait to parse the invoice and make sure they're signing what they expect, rather than
114                  * blindly signing the hash.
115                  * The `hrp` is ASCII bytes, while the invoice data is base32-encoded.
116                  * 
117                  * The secret key used to sign the invoice is dependent on the [`Recipient`].
118                  * 
119                  * Errors if the [`Recipient`] variant is not supported by the implementation.
120                  */
121                 Result_RecoverableSignatureNoneZ sign_invoice(byte[] _hrp_bytes, UInt5[] _invoice_data, Recipient _receipient);
122                 /**
123                  * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
124                  * 
125                  * If the implementor of this trait supports [phantom node payments], then every node that is
126                  * intended to be included in the phantom invoice route hints must return the same value from
127                  * this method.
128                  * 
129                  * This method must return the same value each time it is called.
130                  * 
131                  * [phantom node payments]: PhantomKeysManager
132                  */
133                 byte[] get_inbound_payment_key_material();
134         }
135         private class LDKKeysInterfaceHolder { internal KeysInterface held; }
136         private class LDKKeysInterfaceImpl : bindings.LDKKeysInterface {
137                 internal LDKKeysInterfaceImpl(KeysInterfaceInterface arg, LDKKeysInterfaceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
138                 private KeysInterfaceInterface arg;
139                 private LDKKeysInterfaceHolder impl_holder;
140                 public long get_node_secret(Recipient _recipient) {
141                         Result_SecretKeyNoneZ ret = arg.get_node_secret(_recipient);
142                                 GC.KeepAlive(arg);
143                         long result = ret == null ? 0 : ret.clone_ptr();
144                         return result;
145                 }
146                 public long get_node_id(Recipient _recipient) {
147                         Result_PublicKeyNoneZ ret = arg.get_node_id(_recipient);
148                                 GC.KeepAlive(arg);
149                         long result = ret == null ? 0 : ret.clone_ptr();
150                         return result;
151                 }
152                 public long ecdh(Recipient _recipient, byte[] _other_key, long _tweak) {
153                         org.ldk.structs.Option_ScalarZ _tweak_hu_conv = org.ldk.structs.Option_ScalarZ.constr_from_ptr(_tweak);
154                         if (_tweak_hu_conv != null) { _tweak_hu_conv.ptrs_to.AddLast(this); };
155                         Result_SharedSecretNoneZ ret = arg.ecdh(_recipient, _other_key, _tweak_hu_conv);
156                                 GC.KeepAlive(arg);
157                         long result = ret == null ? 0 : ret.clone_ptr();
158                         return result;
159                 }
160                 public byte[] get_destination_script() {
161                         byte[] ret = arg.get_destination_script();
162                                 GC.KeepAlive(arg);
163                         return ret;
164                 }
165                 public long get_shutdown_scriptpubkey() {
166                         ShutdownScript ret = arg.get_shutdown_scriptpubkey();
167                                 GC.KeepAlive(arg);
168                         long result = ret == null ? 0 : ret.clone_ptr();
169                         return result;
170                 }
171                 public byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, byte[] _user_channel_id) {
172                         org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id);
173                         byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv);
174                                 GC.KeepAlive(arg);
175                         byte[] result = InternalUtils.check_arr_len(ret, 32);
176                         return result;
177                 }
178                 public long derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id) {
179                         Sign ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id);
180                                 GC.KeepAlive(arg);
181                         long result = ret == null ? 0 : ret.clone_ptr();
182                         if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
183                         return result;
184                 }
185                 public byte[] get_secure_random_bytes() {
186                         byte[] ret = arg.get_secure_random_bytes();
187                                 GC.KeepAlive(arg);
188                         byte[] result = InternalUtils.check_arr_len(ret, 32);
189                         return result;
190                 }
191                 public long read_chan_signer(byte[] _reader) {
192                         Result_SignDecodeErrorZ ret = arg.read_chan_signer(_reader);
193                                 GC.KeepAlive(arg);
194                         long result = ret == null ? 0 : ret.clone_ptr();
195                         return result;
196                 }
197                 public long sign_invoice(byte[] _hrp_bytes, byte[] _invoice_data, Recipient _receipient) {
198                         int _invoice_data_conv_7_len = _invoice_data.Length;
199                         UInt5[] _invoice_data_conv_7_arr = new UInt5[_invoice_data_conv_7_len];
200                         for (int h = 0; h < _invoice_data_conv_7_len; h++) {
201                                 byte _invoice_data_conv_7 = _invoice_data[h];
202                                 UInt5 _invoice_data_conv_7_conv = new UInt5(_invoice_data_conv_7);
203                                 _invoice_data_conv_7_arr[h] = _invoice_data_conv_7_conv;
204                         }
205                         Result_RecoverableSignatureNoneZ ret = arg.sign_invoice(_hrp_bytes, _invoice_data_conv_7_arr, _receipient);
206                                 GC.KeepAlive(arg);
207                         long result = ret == null ? 0 : ret.clone_ptr();
208                         return result;
209                 }
210                 public byte[] get_inbound_payment_key_material() {
211                         byte[] ret = arg.get_inbound_payment_key_material();
212                                 GC.KeepAlive(arg);
213                         byte[] result = InternalUtils.check_arr_len(ret, 32);
214                         return result;
215                 }
216         }
217         public static KeysInterface new_impl(KeysInterfaceInterface arg) {
218                 LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder();
219                 impl_holder.held = new KeysInterface(new LDKKeysInterfaceImpl(arg, impl_holder));
220                 return impl_holder.held;
221         }
222         /**
223          * Get node secret key based on the provided [`Recipient`].
224          * 
225          * The `node_id`/`network_key` is the public key that corresponds to this secret key.
226          * 
227          * This method must return the same value each time it is called with a given [`Recipient`]
228          * parameter.
229          * 
230          * Errors if the [`Recipient`] variant is not supported by the implementation.
231          */
232         public Result_SecretKeyNoneZ get_node_secret(Recipient recipient) {
233                 long ret = bindings.KeysInterface_get_node_secret(this.ptr, recipient);
234                 GC.KeepAlive(this);
235                 GC.KeepAlive(recipient);
236                 if (ret >= 0 && ret <= 4096) { return null; }
237                 Result_SecretKeyNoneZ ret_hu_conv = Result_SecretKeyNoneZ.constr_from_ptr(ret);
238                 return ret_hu_conv;
239         }
240
241         /**
242          * Get node id based on the provided [`Recipient`]. This public key corresponds to the secret in
243          * [`get_node_secret`].
244          * 
245          * This method must return the same value each time it is called with a given [`Recipient`]
246          * parameter.
247          * 
248          * Errors if the [`Recipient`] variant is not supported by the implementation.
249          * 
250          * [`get_node_secret`]: Self::get_node_secret
251          */
252         public Result_PublicKeyNoneZ get_node_id(Recipient recipient) {
253                 long ret = bindings.KeysInterface_get_node_id(this.ptr, recipient);
254                 GC.KeepAlive(this);
255                 GC.KeepAlive(recipient);
256                 if (ret >= 0 && ret <= 4096) { return null; }
257                 Result_PublicKeyNoneZ ret_hu_conv = Result_PublicKeyNoneZ.constr_from_ptr(ret);
258                 return ret_hu_conv;
259         }
260
261         /**
262          * Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
263          * one is provided. Note that this tweak can be applied to `other_key` instead of our node
264          * secret, though this is less efficient.
265          * 
266          * Errors if the [`Recipient`] variant is not supported by the implementation.
267          * 
268          * [`node secret`]: Self::get_node_secret
269          */
270         public Result_SharedSecretNoneZ ecdh(Recipient recipient, byte[] other_key, org.ldk.structs.Option_ScalarZ tweak) {
271                 long ret = bindings.KeysInterface_ecdh(this.ptr, recipient, InternalUtils.check_arr_len(other_key, 33), tweak.ptr);
272                 GC.KeepAlive(this);
273                 GC.KeepAlive(recipient);
274                 GC.KeepAlive(other_key);
275                 GC.KeepAlive(tweak);
276                 if (ret >= 0 && ret <= 4096) { return null; }
277                 Result_SharedSecretNoneZ ret_hu_conv = Result_SharedSecretNoneZ.constr_from_ptr(ret);
278                 return ret_hu_conv;
279         }
280
281         /**
282          * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
283          * 
284          * This method should return a different value each time it is called, to avoid linking
285          * on-chain funds across channels as controlled to the same user.
286          */
287         public byte[] get_destination_script() {
288                 byte[] ret = bindings.KeysInterface_get_destination_script(this.ptr);
289                 GC.KeepAlive(this);
290                 return ret;
291         }
292
293         /**
294          * Get a script pubkey which we will send funds to when closing a channel.
295          * 
296          * This method should return a different value each time it is called, to avoid linking
297          * on-chain funds across channels as controlled to the same user.
298          */
299         public ShutdownScript get_shutdown_scriptpubkey() {
300                 long ret = bindings.KeysInterface_get_shutdown_scriptpubkey(this.ptr);
301                 GC.KeepAlive(this);
302                 if (ret >= 0 && ret <= 4096) { return null; }
303                 org.ldk.structs.ShutdownScript ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ShutdownScript(null, ret); }
304                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
305                 return ret_hu_conv;
306         }
307
308         /**
309          * Get a new set of [`Sign`] for per-channel secrets. These MUST be unique even if you
310          * restarted with some stale data!
311          * 
312          * This method must return a different value each time it is called.
313          */
314         public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
315                 byte[] ret = bindings.KeysInterface_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes());
316                 GC.KeepAlive(this);
317                 GC.KeepAlive(inbound);
318                 GC.KeepAlive(channel_value_satoshis);
319                 GC.KeepAlive(user_channel_id);
320                 return ret;
321         }
322
323         /**
324          * Derives the private key material backing a `Signer`.
325          * 
326          * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
327          * [`KeysInterface::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
328          * re-derived from its `channel_keys_id`, which can be obtained through its trait method
329          * [`BaseSign::channel_keys_id`].
330          */
331         public Sign derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
332                 long ret = bindings.KeysInterface_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32));
333                 GC.KeepAlive(this);
334                 GC.KeepAlive(channel_value_satoshis);
335                 GC.KeepAlive(channel_keys_id);
336                 if (ret >= 0 && ret <= 4096) { return null; }
337                 Sign ret_hu_conv = new Sign(null, ret);
338                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
339                 return ret_hu_conv;
340         }
341
342         /**
343          * Gets a unique, cryptographically-secure, random 32 byte value. This is used for encrypting
344          * onion packets and for temporary channel IDs. There is no requirement that these be
345          * persisted anywhere, though they must be unique across restarts.
346          * 
347          * This method must return a different value each time it is called.
348          */
349         public byte[] get_secure_random_bytes() {
350                 byte[] ret = bindings.KeysInterface_get_secure_random_bytes(this.ptr);
351                 GC.KeepAlive(this);
352                 return ret;
353         }
354
355         /**
356          * Reads a [`Signer`] for this [`KeysInterface`] from the given input stream.
357          * This is only called during deserialization of other objects which contain
358          * [`Sign`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
359          * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
360          * contain no versioning scheme. You may wish to include your own version prefix and ensure
361          * you've read all of the provided bytes to ensure no corruption occurred.
362          * 
363          * This method is slowly being phased out -- it will only be called when reading objects
364          * written by LDK versions prior to 0.0.113.
365          * 
366          * [`Signer`]: Self::Signer
367          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
368          * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
369          */
370         public Result_SignDecodeErrorZ read_chan_signer(byte[] reader) {
371                 long ret = bindings.KeysInterface_read_chan_signer(this.ptr, reader);
372                 GC.KeepAlive(this);
373                 GC.KeepAlive(reader);
374                 if (ret >= 0 && ret <= 4096) { return null; }
375                 Result_SignDecodeErrorZ ret_hu_conv = Result_SignDecodeErrorZ.constr_from_ptr(ret);
376                 return ret_hu_conv;
377         }
378
379         /**
380          * Sign an invoice.
381          * By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
382          * this trait to parse the invoice and make sure they're signing what they expect, rather than
383          * blindly signing the hash.
384          * The `hrp` is ASCII bytes, while the invoice data is base32-encoded.
385          * 
386          * The secret key used to sign the invoice is dependent on the [`Recipient`].
387          * 
388          * Errors if the [`Recipient`] variant is not supported by the implementation.
389          */
390         public Result_RecoverableSignatureNoneZ sign_invoice(byte[] hrp_bytes, UInt5[] invoice_data, Recipient receipient) {
391                 long ret = bindings.KeysInterface_sign_invoice(this.ptr, hrp_bytes, invoice_data != null ? InternalUtils.convUInt5Array(invoice_data) : null, receipient);
392                 GC.KeepAlive(this);
393                 GC.KeepAlive(hrp_bytes);
394                 GC.KeepAlive(invoice_data);
395                 GC.KeepAlive(receipient);
396                 if (ret >= 0 && ret <= 4096) { return null; }
397                 Result_RecoverableSignatureNoneZ ret_hu_conv = Result_RecoverableSignatureNoneZ.constr_from_ptr(ret);
398                 return ret_hu_conv;
399         }
400
401         /**
402          * Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
403          * 
404          * If the implementor of this trait supports [phantom node payments], then every node that is
405          * intended to be included in the phantom invoice route hints must return the same value from
406          * this method.
407          * 
408          * This method must return the same value each time it is called.
409          * 
410          * [phantom node payments]: PhantomKeysManager
411          */
412         public byte[] get_inbound_payment_key_material() {
413                 byte[] ret = bindings.KeysInterface_get_inbound_payment_key_material(this.ptr);
414                 GC.KeepAlive(this);
415                 return ret;
416         }
417
418 }
419 } } }