6 namespace org { namespace ldk { namespace structs {
9 * A trait that can return signer instances for individual channels.
11 public class SignerProvider : CommonBase {
12 internal readonly bindings.LDKSignerProvider bindings_instance;
13 internal SignerProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14 private SignerProvider(bindings.LDKSignerProvider arg) : base(bindings.LDKSignerProvider_new(arg)) {
15 this.ptrs_to.AddLast(arg);
16 this.bindings_instance = arg;
19 if (ptr != 0) { bindings.SignerProvider_free(ptr); }
22 public interface SignerProviderInterface {
24 * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
25 * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
26 * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
29 * This method must return a different value each time it is called.
31 byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, UInt128 _user_channel_id);
33 * Derives the private key material backing a `Signer`.
35 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
36 * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
37 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
38 * [`ChannelSigner::channel_keys_id`].
40 WriteableEcdsaChannelSigner derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id);
42 * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
43 * This is only called during deserialization of other objects which contain
44 * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
45 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
46 * contain no versioning scheme. You may wish to include your own version prefix and ensure
47 * you've read all of the provided bytes to ensure no corruption occurred.
49 * This method is slowly being phased out -- it will only be called when reading objects
50 * written by LDK versions prior to 0.0.113.
52 * [`Signer`]: Self::Signer
53 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
54 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
56 Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] _reader);
58 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
60 * If this function returns an error, this will result in a channel failing to open.
62 * This method should return a different value each time it is called, to avoid linking
63 * on-chain funds across channels as controlled to the same user.
65 Result_ScriptNoneZ get_destination_script();
67 * Get a script pubkey which we will send funds to when closing a channel.
69 * If this function returns an error, this will result in a channel failing to open or close.
70 * In the event of a failure when the counterparty is initiating a close, this can result in a
71 * channel force close.
73 * This method should return a different value each time it is called, to avoid linking
74 * on-chain funds across channels as controlled to the same user.
76 Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey();
78 private class LDKSignerProviderHolder { internal SignerProvider held; }
79 private class LDKSignerProviderImpl : bindings.LDKSignerProvider {
80 internal LDKSignerProviderImpl(SignerProviderInterface arg, LDKSignerProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
81 private SignerProviderInterface arg;
82 private LDKSignerProviderHolder impl_holder;
83 public byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, byte[] _user_channel_id) {
84 org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id);
85 byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv);
87 byte[] result = InternalUtils.check_arr_len(ret, 32);
90 public long derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id) {
91 WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id);
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(byte[] _reader) {
98 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(_reader);
100 long result = ret == null ? 0 : ret.clone_ptr();
103 public long get_destination_script() {
104 Result_ScriptNoneZ ret = arg.get_destination_script();
106 long result = ret == null ? 0 : ret.clone_ptr();
109 public long get_shutdown_scriptpubkey() {
110 Result_ShutdownScriptNoneZ ret = arg.get_shutdown_scriptpubkey();
112 long result = ret == null ? 0 : ret.clone_ptr();
116 public static SignerProvider new_impl(SignerProviderInterface arg) {
117 LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder();
118 impl_holder.held = new SignerProvider(new LDKSignerProviderImpl(arg, impl_holder));
119 return impl_holder.held;
122 * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
123 * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
124 * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
127 * This method must return a different value each time it is called.
129 public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
130 byte[] ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes());
132 GC.KeepAlive(inbound);
133 GC.KeepAlive(channel_value_satoshis);
134 GC.KeepAlive(user_channel_id);
139 * Derives the private key material backing a `Signer`.
141 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
142 * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
143 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
144 * [`ChannelSigner::channel_keys_id`].
146 public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
147 long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32));
149 GC.KeepAlive(channel_value_satoshis);
150 GC.KeepAlive(channel_keys_id);
151 if (ret >= 0 && ret <= 4096) { return null; }
152 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
153 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
158 * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
159 * This is only called during deserialization of other objects which contain
160 * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
161 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
162 * contain no versioning scheme. You may wish to include your own version prefix and ensure
163 * you've read all of the provided bytes to ensure no corruption occurred.
165 * This method is slowly being phased out -- it will only be called when reading objects
166 * written by LDK versions prior to 0.0.113.
168 * [`Signer`]: Self::Signer
169 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
170 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
172 public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) {
173 long ret = bindings.SignerProvider_read_chan_signer(this.ptr, reader);
175 GC.KeepAlive(reader);
176 if (ret >= 0 && ret <= 4096) { return null; }
177 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret_hu_conv = Result_WriteableEcdsaChannelSignerDecodeErrorZ.constr_from_ptr(ret);
182 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
184 * If this function returns an error, this will result in a channel failing to open.
186 * This method should return a different value each time it is called, to avoid linking
187 * on-chain funds across channels as controlled to the same user.
189 public Result_ScriptNoneZ get_destination_script() {
190 long ret = bindings.SignerProvider_get_destination_script(this.ptr);
192 if (ret >= 0 && ret <= 4096) { return null; }
193 Result_ScriptNoneZ ret_hu_conv = Result_ScriptNoneZ.constr_from_ptr(ret);
198 * Get a script pubkey which we will send funds to when closing a channel.
200 * If this function returns an error, this will result in a channel failing to open or close.
201 * In the event of a failure when the counterparty is initiating a close, this can result in a
202 * channel force close.
204 * This method should return a different value each time it is called, to avoid linking
205 * on-chain funds across channels as controlled to the same user.
207 public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() {
208 long ret = bindings.SignerProvider_get_shutdown_scriptpubkey(this.ptr);
210 if (ret >= 0 && ret <= 4096) { return null; }
211 Result_ShutdownScriptNoneZ ret_hu_conv = Result_ShutdownScriptNoneZ.constr_from_ptr(ret);