[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / KeysManager.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Simple implementation of [`EntropySource`], [`NodeSigner`], and [`SignerProvider`] that takes a
13  * 32-byte seed for use as a BIP 32 extended key and derives keys from that.
14  * 
15  * Your `node_id` is seed/0'.
16  * Unilateral closes may use seed/1'.
17  * Cooperative closes may use seed/2'.
18  * The two close keys may be needed to claim on-chain funds!
19  * 
20  * This struct cannot be used for nodes that wish to support receiving phantom payments;
21  * [`PhantomKeysManager`] must be used instead.
22  * 
23  * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
24  * previously issued invoices and attempts to pay previous invoices will fail.
25  */
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class KeysManager extends CommonBase {
28         KeysManager(Object _dummy, long ptr) { super(ptr); }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 super.finalize();
32                 if (ptr != 0) { bindings.KeysManager_free(ptr); }
33         }
34
35         /**
36          * Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
37          * your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
38          * `starting_time` isn't strictly required to actually be a time, but it must absolutely,
39          * without a doubt, be unique to this instance. ie if you start multiple times with the same
40          * `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
41          * is to simply use the current time (with very high precision).
42          * 
43          * The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
44          * obviously, `starting_time` should be unique every time you reload the library - it is only
45          * used to generate new ephemeral key data (which will be stored by the individual channel if
46          * necessary).
47          * 
48          * Note that the seed is required to recover certain on-chain funds independent of
49          * [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
50          * for any channel, and some on-chain during-closing funds.
51          * 
52          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
53          */
54         public static KeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos) {
55                 long ret = bindings.KeysManager_new(InternalUtils.check_arr_len(seed, 32), starting_time_secs, starting_time_nanos);
56                 Reference.reachabilityFence(seed);
57                 Reference.reachabilityFence(starting_time_secs);
58                 Reference.reachabilityFence(starting_time_nanos);
59                 if (ret >= 0 && ret <= 4096) { return null; }
60                 org.ldk.structs.KeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.KeysManager(null, ret); }
61                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
62                 return ret_hu_conv;
63         }
64
65         /**
66          * Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
67          */
68         public byte[] get_node_secret_key() {
69                 byte[] ret = bindings.KeysManager_get_node_secret_key(this.ptr);
70                 Reference.reachabilityFence(this);
71                 return ret;
72         }
73
74         /**
75          * Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
76          */
77         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] params) {
78                 long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(params, 32));
79                 Reference.reachabilityFence(this);
80                 Reference.reachabilityFence(channel_value_satoshis);
81                 Reference.reachabilityFence(params);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
85                 return ret_hu_conv;
86         }
87
88         /**
89          * Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
90          * output to the given change destination (if sufficient change value remains). The
91          * transaction will have a feerate, at least, of the given value.
92          * 
93          * Returns `Err(())` if the output value is greater than the input value minus required fee,
94          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
95          * does not match the one we can spend.
96          * 
97          * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
98          * 
99          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
100          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
101          */
102         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight) {
103                 long ret = bindings.KeysManager_spend_spendable_outputs(this.ptr, descriptors != null ? Arrays.stream(descriptors).mapToLong(descriptors_conv_27 -> descriptors_conv_27.ptr).toArray() : null, outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_7 -> outputs_conv_7.ptr).toArray() : null, change_destination_script, feerate_sat_per_1000_weight);
104                 Reference.reachabilityFence(this);
105                 Reference.reachabilityFence(descriptors);
106                 Reference.reachabilityFence(outputs);
107                 Reference.reachabilityFence(change_destination_script);
108                 Reference.reachabilityFence(feerate_sat_per_1000_weight);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
111                 for (SpendableOutputDescriptor descriptors_conv_27: descriptors) { if (this != null) { this.ptrs_to.add(descriptors_conv_27); }; };
112                 return ret_hu_conv;
113         }
114
115         /**
116          * Constructs a new EntropySource which calls the relevant methods on this_arg.
117          * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
118          */
119         public EntropySource as_EntropySource() {
120                 long ret = bindings.KeysManager_as_EntropySource(this.ptr);
121                 Reference.reachabilityFence(this);
122                 if (ret >= 0 && ret <= 4096) { return null; }
123                 EntropySource ret_hu_conv = new EntropySource(null, ret);
124                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
125                 return ret_hu_conv;
126         }
127
128         /**
129          * Constructs a new NodeSigner which calls the relevant methods on this_arg.
130          * This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
131          */
132         public NodeSigner as_NodeSigner() {
133                 long ret = bindings.KeysManager_as_NodeSigner(this.ptr);
134                 Reference.reachabilityFence(this);
135                 if (ret >= 0 && ret <= 4096) { return null; }
136                 NodeSigner ret_hu_conv = new NodeSigner(null, ret);
137                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Constructs a new SignerProvider which calls the relevant methods on this_arg.
143          * This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
144          */
145         public SignerProvider as_SignerProvider() {
146                 long ret = bindings.KeysManager_as_SignerProvider(this.ptr);
147                 Reference.reachabilityFence(this);
148                 if (ret >= 0 && ret <= 4096) { return null; }
149                 SignerProvider ret_hu_conv = new SignerProvider(null, ret);
150                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
151                 return ret_hu_conv;
152         }
153
154 }