[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / KeysManager.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 /**
10  * Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
11  * 32-byte seed for use as a BIP 32 extended key and derives keys from that.
12  * 
13  * Your `node_id` is seed/0'.
14  * Unilateral closes may use seed/1'.
15  * Cooperative closes may use seed/2'.
16  * The two close keys may be needed to claim on-chain funds!
17  * 
18  * This struct cannot be used for nodes that wish to support receiving phantom payments;
19  * [`PhantomKeysManager`] must be used instead.
20  * 
21  * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
22  * previously issued invoices and attempts to pay previous invoices will fail.
23  */
24 public class KeysManager : CommonBase {
25         internal KeysManager(object _dummy, long ptr) : base(ptr) { }
26         ~KeysManager() {
27                 if (ptr != 0) { bindings.KeysManager_free(ptr); }
28         }
29
30         /**
31          * Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
32          * your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
33          * `starting_time` isn't strictly required to actually be a time, but it must absolutely,
34          * without a doubt, be unique to this instance. ie if you start multiple times with the same
35          * `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
36          * is to simply use the current time (with very high precision).
37          * 
38          * The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
39          * obviously, `starting_time` should be unique every time you reload the library - it is only
40          * used to generate new ephemeral key data (which will be stored by the individual channel if
41          * necessary).
42          * 
43          * Note that the seed is required to recover certain on-chain funds independent of
44          * [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
45          * for any channel, and some on-chain during-closing funds.
46          * 
47          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
48          */
49         public static KeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos) {
50                 long ret = bindings.KeysManager_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(seed, 32)), starting_time_secs, starting_time_nanos);
51                 GC.KeepAlive(seed);
52                 GC.KeepAlive(starting_time_secs);
53                 GC.KeepAlive(starting_time_nanos);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 org.ldk.structs.KeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.KeysManager(null, ret); }
56                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
57                 return ret_hu_conv;
58         }
59
60         /**
61          * Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
62          */
63         public byte[] get_node_secret_key() {
64                 long ret = bindings.KeysManager_get_node_secret_key(this.ptr);
65                 GC.KeepAlive(this);
66                 if (ret >= 0 && ret <= 4096) { return null; }
67                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
68                 return ret_conv;
69         }
70
71         /**
72          * Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
73          */
74         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] _params) {
75                 long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(_params, 32)));
76                 GC.KeepAlive(this);
77                 GC.KeepAlive(channel_value_satoshis);
78                 GC.KeepAlive(_params);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
81                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
87          * The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
88          * are no other inputs that need signing.
89          * 
90          * Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
91          * 
92          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
93          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
94          */
95         public Result_CVec_u8ZNoneZ sign_spendable_outputs_psbt(SpendableOutputDescriptor[] descriptors, byte[] psbt) {
96                 long ret = bindings.KeysManager_sign_spendable_outputs_psbt(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr)), InternalUtils.encodeUint8Array(psbt));
97                 GC.KeepAlive(this);
98                 GC.KeepAlive(descriptors);
99                 GC.KeepAlive(psbt);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
102                 foreach (SpendableOutputDescriptor descriptors_conv_27 in descriptors) { if (this != null) { this.ptrs_to.AddLast(descriptors_conv_27); }; };
103                 return ret_hu_conv;
104         }
105
106         /**
107          * Constructs a new EntropySource which calls the relevant methods on this_arg.
108          * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
109          */
110         public EntropySource as_EntropySource() {
111                 long ret = bindings.KeysManager_as_EntropySource(this.ptr);
112                 GC.KeepAlive(this);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 EntropySource ret_hu_conv = new EntropySource(null, ret);
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
116                 return ret_hu_conv;
117         }
118
119         /**
120          * Constructs a new NodeSigner which calls the relevant methods on this_arg.
121          * This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
122          */
123         public NodeSigner as_NodeSigner() {
124                 long ret = bindings.KeysManager_as_NodeSigner(this.ptr);
125                 GC.KeepAlive(this);
126                 if (ret >= 0 && ret <= 4096) { return null; }
127                 NodeSigner ret_hu_conv = new NodeSigner(null, ret);
128                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
129                 return ret_hu_conv;
130         }
131
132         /**
133          * Constructs a new OutputSpender which calls the relevant methods on this_arg.
134          * This copies the `inner` pointer in this_arg and thus the returned OutputSpender must be freed before this_arg is
135          */
136         public OutputSpender as_OutputSpender() {
137                 long ret = bindings.KeysManager_as_OutputSpender(this.ptr);
138                 GC.KeepAlive(this);
139                 if (ret >= 0 && ret <= 4096) { return null; }
140                 OutputSpender ret_hu_conv = new OutputSpender(null, ret);
141                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
142                 return ret_hu_conv;
143         }
144
145         /**
146          * Constructs a new SignerProvider which calls the relevant methods on this_arg.
147          * This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
148          */
149         public SignerProvider as_SignerProvider() {
150                 long ret = bindings.KeysManager_as_SignerProvider(this.ptr);
151                 GC.KeepAlive(this);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 SignerProvider ret_hu_conv = new SignerProvider(null, ret);
154                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
155                 return ret_hu_conv;
156         }
157
158 }
159 } } }