7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of SignerProvider */
12 public interface SignerProviderInterface {
13 /**Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
14 * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
15 * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
18 * This method must return a different value each time it is called.
20 byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, UInt128 user_channel_id);
21 /**Derives the private key material backing a `Signer`.
23 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
24 * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
25 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
26 * [`ChannelSigner::channel_keys_id`].
28 WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id);
29 /**Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
30 * This is only called during deserialization of other objects which contain
31 * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
32 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
33 * contain no versioning scheme. You may wish to include your own version prefix and ensure
34 * you've read all of the provided bytes to ensure no corruption occurred.
36 * This method is slowly being phased out -- it will only be called when reading objects
37 * written by LDK versions prior to 0.0.113.
39 * [`Signer`]: Self::EcdsaSigner
40 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
41 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
43 Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader);
44 /**Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
46 * If this function returns an error, this will result in a channel failing to open.
48 * This method should return a different value each time it is called, to avoid linking
49 * on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
50 * used to derive a unique value for each channel.
52 Result_CVec_u8ZNoneZ get_destination_script(byte[] channel_keys_id);
53 /**Get a script pubkey which we will send funds to when closing a channel.
55 * If this function returns an error, this will result in a channel failing to open or close.
56 * In the event of a failure when the counterparty is initiating a close, this can result in a
57 * channel force close.
59 * This method should return a different value each time it is called, to avoid linking
60 * on-chain funds across channels as controlled to the same user.
62 Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey();
66 * A trait that can return signer instances for individual channels.
68 public class SignerProvider : CommonBase {
69 internal bindings.LDKSignerProvider bindings_instance;
70 internal long instance_idx;
72 internal SignerProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
74 if (ptr != 0) { bindings.SignerProvider_free(ptr); }
77 private class LDKSignerProviderHolder { internal SignerProvider held; }
78 private class LDKSignerProviderImpl : bindings.LDKSignerProvider {
79 internal LDKSignerProviderImpl(SignerProviderInterface arg, LDKSignerProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
80 private SignerProviderInterface arg;
81 private LDKSignerProviderHolder impl_holder;
82 public long generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, long _user_channel_id) {
83 org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id);
84 byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv);
86 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
89 public long derive_channel_signer(long _channel_value_satoshis, long _channel_keys_id) {
90 byte[] _channel_keys_id_conv = InternalUtils.decodeUint8Array(_channel_keys_id);
91 WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id_conv);
93 long result = ret.clone_ptr();
94 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
97 public long read_chan_signer(long _reader) {
98 byte[] _reader_conv = InternalUtils.decodeUint8Array(_reader);
99 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(_reader_conv);
101 long result = ret.clone_ptr();
104 public long get_destination_script(long _channel_keys_id) {
105 byte[] _channel_keys_id_conv = InternalUtils.decodeUint8Array(_channel_keys_id);
106 Result_CVec_u8ZNoneZ ret = arg.get_destination_script(_channel_keys_id_conv);
108 long result = ret.clone_ptr();
111 public long get_shutdown_scriptpubkey() {
112 Result_ShutdownScriptNoneZ ret = arg.get_shutdown_scriptpubkey();
114 long result = ret.clone_ptr();
119 /** Creates a new instance of SignerProvider from a given implementation */
120 public static SignerProvider new_impl(SignerProviderInterface arg) {
121 LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder();
122 LDKSignerProviderImpl impl = new LDKSignerProviderImpl(arg, impl_holder);
123 long[] ptr_idx = bindings.LDKSignerProvider_new(impl);
125 impl_holder.held = new SignerProvider(null, ptr_idx[0]);
126 impl_holder.held.instance_idx = ptr_idx[1];
127 impl_holder.held.bindings_instance = impl;
128 return impl_holder.held;
132 * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::EcdsaSigner`] through
133 * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
134 * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
137 * This method must return a different value each time it is called.
139 public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
140 long ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, InternalUtils.encodeUint8Array(user_channel_id.getLEBytes()));
142 GC.KeepAlive(inbound);
143 GC.KeepAlive(channel_value_satoshis);
144 GC.KeepAlive(user_channel_id);
145 if (ret >= 0 && ret <= 4096) { return null; }
146 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
151 * Derives the private key material backing a `Signer`.
153 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
154 * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
155 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
156 * [`ChannelSigner::channel_keys_id`].
158 public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
159 long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(channel_keys_id, 32)));
161 GC.KeepAlive(channel_value_satoshis);
162 GC.KeepAlive(channel_keys_id);
163 if (ret >= 0 && ret <= 4096) { return null; }
164 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
165 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
170 * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
171 * This is only called during deserialization of other objects which contain
172 * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
173 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
174 * contain no versioning scheme. You may wish to include your own version prefix and ensure
175 * you've read all of the provided bytes to ensure no corruption occurred.
177 * This method is slowly being phased out -- it will only be called when reading objects
178 * written by LDK versions prior to 0.0.113.
180 * [`Signer`]: Self::EcdsaSigner
181 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
182 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
184 public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) {
185 long ret = bindings.SignerProvider_read_chan_signer(this.ptr, InternalUtils.encodeUint8Array(reader));
187 GC.KeepAlive(reader);
188 if (ret >= 0 && ret <= 4096) { return null; }
189 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret_hu_conv = Result_WriteableEcdsaChannelSignerDecodeErrorZ.constr_from_ptr(ret);
194 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
196 * If this function returns an error, this will result in a channel failing to open.
198 * This method should return a different value each time it is called, to avoid linking
199 * on-chain funds across channels as controlled to the same user. `channel_keys_id` may be
200 * used to derive a unique value for each channel.
202 public Result_CVec_u8ZNoneZ get_destination_script(byte[] channel_keys_id) {
203 long ret = bindings.SignerProvider_get_destination_script(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(channel_keys_id, 32)));
205 GC.KeepAlive(channel_keys_id);
206 if (ret >= 0 && ret <= 4096) { return null; }
207 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
212 * Get a script pubkey which we will send funds to when closing a channel.
214 * If this function returns an error, this will result in a channel failing to open or close.
215 * In the event of a failure when the counterparty is initiating a close, this can result in a
216 * channel force close.
218 * This method should return a different value each time it is called, to avoid linking
219 * on-chain funds across channels as controlled to the same user.
221 public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() {
222 long ret = bindings.SignerProvider_get_shutdown_scriptpubkey(this.ptr);
224 if (ret >= 0 && ret <= 4096) { return null; }
225 Result_ShutdownScriptNoneZ ret_hu_conv = Result_ShutdownScriptNoneZ.constr_from_ptr(ret);