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::Signer`] 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::Signer
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.
51 Result_CVec_u8ZNoneZ get_destination_script();
52 /**Get a script pubkey which we will send funds to when closing a channel.
54 * If this function returns an error, this will result in a channel failing to open or close.
55 * In the event of a failure when the counterparty is initiating a close, this can result in a
56 * channel force close.
58 * This method should return a different value each time it is called, to avoid linking
59 * on-chain funds across channels as controlled to the same user.
61 Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey();
65 * A trait that can return signer instances for individual channels.
67 public class SignerProvider : CommonBase {
68 internal bindings.LDKSignerProvider bindings_instance;
69 internal long instance_idx;
71 internal SignerProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
73 if (ptr != 0) { bindings.SignerProvider_free(ptr); }
76 private class LDKSignerProviderHolder { internal SignerProvider held; }
77 private class LDKSignerProviderImpl : bindings.LDKSignerProvider {
78 internal LDKSignerProviderImpl(SignerProviderInterface arg, LDKSignerProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
79 private SignerProviderInterface arg;
80 private LDKSignerProviderHolder impl_holder;
81 public long generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, long _user_channel_id) {
82 org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id);
83 byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv);
85 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
88 public long derive_channel_signer(long _channel_value_satoshis, long _channel_keys_id) {
89 byte[] _channel_keys_id_conv = InternalUtils.decodeUint8Array(_channel_keys_id);
90 WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id_conv);
92 long result = ret.clone_ptr();
93 if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); };
96 public long read_chan_signer(long _reader) {
97 byte[] _reader_conv = InternalUtils.decodeUint8Array(_reader);
98 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(_reader_conv);
100 long result = ret == null ? 0 : ret.clone_ptr();
103 public long get_destination_script() {
104 Result_CVec_u8ZNoneZ 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();
117 /** Creates a new instance of SignerProvider from a given implementation */
118 public static SignerProvider new_impl(SignerProviderInterface arg) {
119 LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder();
120 LDKSignerProviderImpl impl = new LDKSignerProviderImpl(arg, impl_holder);
121 long[] ptr_idx = bindings.LDKSignerProvider_new(impl);
123 impl_holder.held = new SignerProvider(null, ptr_idx[0]);
124 impl_holder.held.instance_idx = ptr_idx[1];
125 impl_holder.held.bindings_instance = impl;
126 return impl_holder.held;
130 * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through
131 * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow
132 * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated
135 * This method must return a different value each time it is called.
137 public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) {
138 long ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, InternalUtils.encodeUint8Array(user_channel_id.getLEBytes()));
140 GC.KeepAlive(inbound);
141 GC.KeepAlive(channel_value_satoshis);
142 GC.KeepAlive(user_channel_id);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
149 * Derives the private key material backing a `Signer`.
151 * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through
152 * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be
153 * re-derived from its `channel_keys_id`, which can be obtained through its trait method
154 * [`ChannelSigner::channel_keys_id`].
156 public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) {
157 long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(channel_keys_id, 32)));
159 GC.KeepAlive(channel_value_satoshis);
160 GC.KeepAlive(channel_keys_id);
161 if (ret >= 0 && ret <= 4096) { return null; }
162 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
163 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
168 * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
169 * This is only called during deserialization of other objects which contain
170 * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
171 * The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
172 * contain no versioning scheme. You may wish to include your own version prefix and ensure
173 * you've read all of the provided bytes to ensure no corruption occurred.
175 * This method is slowly being phased out -- it will only be called when reading objects
176 * written by LDK versions prior to 0.0.113.
178 * [`Signer`]: Self::Signer
179 * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
180 * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
182 public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) {
183 long ret = bindings.SignerProvider_read_chan_signer(this.ptr, InternalUtils.encodeUint8Array(reader));
185 GC.KeepAlive(reader);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 Result_WriteableEcdsaChannelSignerDecodeErrorZ ret_hu_conv = Result_WriteableEcdsaChannelSignerDecodeErrorZ.constr_from_ptr(ret);
192 * Get a script pubkey which we send funds to when claiming on-chain contestable outputs.
194 * If this function returns an error, this will result in a channel failing to open.
196 * This method should return a different value each time it is called, to avoid linking
197 * on-chain funds across channels as controlled to the same user.
199 public Result_CVec_u8ZNoneZ get_destination_script() {
200 long ret = bindings.SignerProvider_get_destination_script(this.ptr);
202 if (ret >= 0 && ret <= 4096) { return null; }
203 Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret);
208 * Get a script pubkey which we will send funds to when closing a channel.
210 * If this function returns an error, this will result in a channel failing to open or close.
211 * In the event of a failure when the counterparty is initiating a close, this can result in a
212 * channel force close.
214 * This method should return a different value each time it is called, to avoid linking
215 * on-chain funds across channels as controlled to the same user.
217 public Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey() {
218 long ret = bindings.SignerProvider_get_shutdown_scriptpubkey(this.ptr);
220 if (ret >= 0 && ret <= 4096) { return null; }
221 Result_ShutdownScriptNoneZ ret_hu_conv = Result_ShutdownScriptNoneZ.constr_from_ptr(ret);