[C#] Update auto-generated files
[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.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                 byte[] ret = bindings.KeysManager_get_node_secret_key(this.ptr);
65                 GC.KeepAlive(this);
66                 return ret;
67         }
68
69         /**
70          * Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
71          */
72         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] _params) {
73                 long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(_params, 32));
74                 GC.KeepAlive(this);
75                 GC.KeepAlive(channel_value_satoshis);
76                 GC.KeepAlive(_params);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
79                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Signs the given [`PartiallySignedTransaction`] which spends the given [`SpendableOutputDescriptor`]s.
85          * The resulting inputs will be finalized and the PSBT will be ready for broadcast if there
86          * are no other inputs that need signing.
87          * 
88          * Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
89          * 
90          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
91          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
92          */
93         public Result_PartiallySignedTransactionNoneZ sign_spendable_outputs_psbt(SpendableOutputDescriptor[] descriptors, byte[] psbt) {
94                 long ret = bindings.KeysManager_sign_spendable_outputs_psbt(this.ptr, descriptors != null ? InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr) : null, psbt);
95                 GC.KeepAlive(this);
96                 GC.KeepAlive(descriptors);
97                 GC.KeepAlive(psbt);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 Result_PartiallySignedTransactionNoneZ ret_hu_conv = Result_PartiallySignedTransactionNoneZ.constr_from_ptr(ret);
100                 foreach (SpendableOutputDescriptor descriptors_conv_27 in descriptors) { if (this != null) { this.ptrs_to.AddLast(descriptors_conv_27); }; };
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
106          * output to the given change destination (if sufficient change value remains). The
107          * transaction will have a feerate, at least, of the given value.
108          * 
109          * The `locktime` argument is used to set the transaction's locktime. If `None`, the
110          * transaction will have a locktime of 0. It it recommended to set this to the current block
111          * height to avoid fee sniping, unless you have some specific reason to use a different
112          * locktime.
113          * 
114          * Returns `Err(())` if the output value is greater than the input value minus required fee,
115          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
116          * does not match the one we can spend.
117          * 
118          * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
119          * 
120          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
121          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
122          */
123         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, org.ldk.structs.Option_PackedLockTimeZ locktime) {
124                 long ret = bindings.KeysManager_spend_spendable_outputs(this.ptr, descriptors != null ? InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr) : null, outputs != null ? InternalUtils.mapArray(outputs, outputs_conv_7 => outputs_conv_7.ptr) : null, change_destination_script, feerate_sat_per_1000_weight, locktime.ptr);
125                 GC.KeepAlive(this);
126                 GC.KeepAlive(descriptors);
127                 GC.KeepAlive(outputs);
128                 GC.KeepAlive(change_destination_script);
129                 GC.KeepAlive(feerate_sat_per_1000_weight);
130                 GC.KeepAlive(locktime);
131                 if (ret >= 0 && ret <= 4096) { return null; }
132                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
133                 foreach (SpendableOutputDescriptor descriptors_conv_27 in descriptors) { if (this != null) { this.ptrs_to.AddLast(descriptors_conv_27); }; };
134                 if (this != null) { this.ptrs_to.AddLast(locktime); };
135                 return ret_hu_conv;
136         }
137
138         /**
139          * Constructs a new EntropySource which calls the relevant methods on this_arg.
140          * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
141          */
142         public EntropySource as_EntropySource() {
143                 long ret = bindings.KeysManager_as_EntropySource(this.ptr);
144                 GC.KeepAlive(this);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 EntropySource ret_hu_conv = new EntropySource(null, ret);
147                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Constructs a new NodeSigner which calls the relevant methods on this_arg.
153          * This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
154          */
155         public NodeSigner as_NodeSigner() {
156                 long ret = bindings.KeysManager_as_NodeSigner(this.ptr);
157                 GC.KeepAlive(this);
158                 if (ret >= 0 && ret <= 4096) { return null; }
159                 NodeSigner ret_hu_conv = new NodeSigner(null, ret);
160                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
161                 return ret_hu_conv;
162         }
163
164         /**
165          * Constructs a new SignerProvider which calls the relevant methods on this_arg.
166          * This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
167          */
168         public SignerProvider as_SignerProvider() {
169                 long ret = bindings.KeysManager_as_SignerProvider(this.ptr);
170                 GC.KeepAlive(this);
171                 if (ret >= 0 && ret <= 4096) { return null; }
172                 SignerProvider ret_hu_conv = new SignerProvider(null, ret);
173                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
174                 return ret_hu_conv;
175         }
176
177 }
178 } } }