6 namespace org { namespace ldk { namespace structs {
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.
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!
18 * This struct cannot be used for nodes that wish to support receiving phantom payments;
19 * [`PhantomKeysManager`] must be used instead.
21 * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
22 * previously issued invoices and attempts to pay previous invoices will fail.
24 public class KeysManager : CommonBase {
25 internal KeysManager(object _dummy, long ptr) : base(ptr) { }
27 if (ptr != 0) { bindings.KeysManager_free(ptr); }
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).
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
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.
47 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
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);
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); };
61 * Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
63 public byte[] get_node_secret_key() {
64 long ret = bindings.KeysManager_get_node_secret_key(this.ptr);
66 if (ret >= 0 && ret <= 4096) { return null; }
67 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
72 * Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
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)));
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); };
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.
90 * Returns `Err(())` if the PSBT is missing a descriptor or if we fail to sign.
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`].
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));
98 GC.KeepAlive(descriptors);
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); }; };
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
110 public EntropySource as_EntropySource() {
111 long ret = bindings.KeysManager_as_EntropySource(this.ptr);
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); };
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
123 public NodeSigner as_NodeSigner() {
124 long ret = bindings.KeysManager_as_NodeSigner(this.ptr);
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); };
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
136 public OutputSpender as_OutputSpender() {
137 long ret = bindings.KeysManager_as_OutputSpender(this.ptr);
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); };
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
149 public SignerProvider as_SignerProvider() {
150 long ret = bindings.KeysManager_as_SignerProvider(this.ptr);
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); };