[C#] Update auto-generated C# bindings
[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          * Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
108          * output to the given change destination (if sufficient change value remains). The
109          * transaction will have a feerate, at least, of the given value.
110          * 
111          * The `locktime` argument is used to set the transaction's locktime. If `None`, the
112          * transaction will have a locktime of 0. It it recommended to set this to the current block
113          * height to avoid fee sniping, unless you have some specific reason to use a different
114          * locktime.
115          * 
116          * Returns `Err(())` if the output value is greater than the input value minus required fee,
117          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
118          * does not match the one we can spend.
119          * 
120          * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
121          * 
122          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
123          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
124          */
125         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, org.ldk.structs.Option_u32Z locktime) {
126                 long ret = bindings.KeysManager_spend_spendable_outputs(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(outputs, outputs_conv_7 => outputs_conv_7.ptr)), InternalUtils.encodeUint8Array(change_destination_script), feerate_sat_per_1000_weight, locktime.ptr);
127                 GC.KeepAlive(this);
128                 GC.KeepAlive(descriptors);
129                 GC.KeepAlive(outputs);
130                 GC.KeepAlive(change_destination_script);
131                 GC.KeepAlive(feerate_sat_per_1000_weight);
132                 GC.KeepAlive(locktime);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
135                 foreach (SpendableOutputDescriptor descriptors_conv_27 in descriptors) { if (this != null) { this.ptrs_to.AddLast(descriptors_conv_27); }; };
136                 if (this != null) { this.ptrs_to.AddLast(locktime); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Constructs a new EntropySource which calls the relevant methods on this_arg.
142          * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
143          */
144         public EntropySource as_EntropySource() {
145                 long ret = bindings.KeysManager_as_EntropySource(this.ptr);
146                 GC.KeepAlive(this);
147                 if (ret >= 0 && ret <= 4096) { return null; }
148                 EntropySource ret_hu_conv = new EntropySource(null, ret);
149                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Constructs a new NodeSigner which calls the relevant methods on this_arg.
155          * This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
156          */
157         public NodeSigner as_NodeSigner() {
158                 long ret = bindings.KeysManager_as_NodeSigner(this.ptr);
159                 GC.KeepAlive(this);
160                 if (ret >= 0 && ret <= 4096) { return null; }
161                 NodeSigner ret_hu_conv = new NodeSigner(null, ret);
162                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
163                 return ret_hu_conv;
164         }
165
166         /**
167          * Constructs a new SignerProvider which calls the relevant methods on this_arg.
168          * This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
169          */
170         public SignerProvider as_SignerProvider() {
171                 long ret = bindings.KeysManager_as_SignerProvider(this.ptr);
172                 GC.KeepAlive(this);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 SignerProvider ret_hu_conv = new SignerProvider(null, ret);
175                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
176                 return ret_hu_conv;
177         }
178
179 }
180 } } }