X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=c_sharp%2Fsrc%2Forg%2Fldk%2Fstructs%2FSignerProvider.cs;h=9396d02fde4186899e7709a5add452c27b39e372;hb=8de7213fbf663ff60322896282dad51e8ab2f001;hp=5de97acd4fcc4e7bbea49edc9bb04d1b1090f632;hpb=afc50e5d491a11364849383b75a8f939df703bac;p=ldk-java diff --git a/c_sharp/src/org/ldk/structs/SignerProvider.cs b/c_sharp/src/org/ldk/structs/SignerProvider.cs index 5de97acd..9396d02f 100644 --- a/c_sharp/src/org/ldk/structs/SignerProvider.cs +++ b/c_sharp/src/org/ldk/structs/SignerProvider.cs @@ -1,3 +1,4 @@ + using org.ldk.impl; using org.ldk.enums; using org.ldk.util; @@ -5,103 +6,102 @@ using System; namespace org { namespace ldk { namespace structs { + + +/** An implementation of SignerProvider */ +public interface SignerProviderInterface { + /**Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through + * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow + * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated + * `channel_keys_id`. + * + * This method must return a different value each time it is called. + */ + byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, UInt128 user_channel_id); + /**Derives the private key material backing a `Signer`. + * + * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through + * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be + * re-derived from its `channel_keys_id`, which can be obtained through its trait method + * [`ChannelSigner::channel_keys_id`]. + */ + WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id); + /**Reads a [`Signer`] for this [`SignerProvider`] from the given input stream. + * This is only called during deserialization of other objects which contain + * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s). + * The bytes are exactly those which `::write()` writes, and + * contain no versioning scheme. You may wish to include your own version prefix and ensure + * you've read all of the provided bytes to ensure no corruption occurred. + * + * This method is slowly being phased out -- it will only be called when reading objects + * written by LDK versions prior to 0.0.113. + * + * [`Signer`]: Self::Signer + * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + */ + Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader); + /**Get a script pubkey which we send funds to when claiming on-chain contestable outputs. + * + * If this function returns an error, this will result in a channel failing to open. + * + * This method should return a different value each time it is called, to avoid linking + * on-chain funds across channels as controlled to the same user. + */ + Result_CVec_u8ZNoneZ get_destination_script(); + /**Get a script pubkey which we will send funds to when closing a channel. + * + * If this function returns an error, this will result in a channel failing to open or close. + * In the event of a failure when the counterparty is initiating a close, this can result in a + * channel force close. + * + * This method should return a different value each time it is called, to avoid linking + * on-chain funds across channels as controlled to the same user. + */ + Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey(); +} + /** * A trait that can return signer instances for individual channels. */ public class SignerProvider : CommonBase { - internal readonly bindings.LDKSignerProvider bindings_instance; + internal bindings.LDKSignerProvider bindings_instance; + internal long instance_idx; + internal SignerProvider(object _dummy, long ptr) : base(ptr) { bindings_instance = null; } - private SignerProvider(bindings.LDKSignerProvider arg) : base(bindings.LDKSignerProvider_new(arg)) { - this.ptrs_to.AddLast(arg); - this.bindings_instance = arg; - } ~SignerProvider() { if (ptr != 0) { bindings.SignerProvider_free(ptr); } } - public interface SignerProviderInterface { - /** - * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through - * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow - * implementations of [`SignerProvider`] to maintain a mapping between itself and the generated - * `channel_keys_id`. - * - * This method must return a different value each time it is called. - */ - byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, UInt128 _user_channel_id); - /** - * Derives the private key material backing a `Signer`. - * - * To derive a new `Signer`, a fresh `channel_keys_id` should be obtained through - * [`SignerProvider::generate_channel_keys_id`]. Otherwise, an existing `Signer` can be - * re-derived from its `channel_keys_id`, which can be obtained through its trait method - * [`ChannelSigner::channel_keys_id`]. - */ - WriteableEcdsaChannelSigner derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id); - /** - * Reads a [`Signer`] for this [`SignerProvider`] from the given input stream. - * This is only called during deserialization of other objects which contain - * [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s). - * The bytes are exactly those which `::write()` writes, and - * contain no versioning scheme. You may wish to include your own version prefix and ensure - * you've read all of the provided bytes to ensure no corruption occurred. - * - * This method is slowly being phased out -- it will only be called when reading objects - * written by LDK versions prior to 0.0.113. - * - * [`Signer`]: Self::Signer - * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor - * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager - */ - Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] _reader); - /** - * Get a script pubkey which we send funds to when claiming on-chain contestable outputs. - * - * If this function returns an error, this will result in a channel failing to open. - * - * This method should return a different value each time it is called, to avoid linking - * on-chain funds across channels as controlled to the same user. - */ - Result_ScriptNoneZ get_destination_script(); - /** - * Get a script pubkey which we will send funds to when closing a channel. - * - * If this function returns an error, this will result in a channel failing to open or close. - * In the event of a failure when the counterparty is initiating a close, this can result in a - * channel force close. - * - * This method should return a different value each time it is called, to avoid linking - * on-chain funds across channels as controlled to the same user. - */ - Result_ShutdownScriptNoneZ get_shutdown_scriptpubkey(); - } private class LDKSignerProviderHolder { internal SignerProvider held; } private class LDKSignerProviderImpl : bindings.LDKSignerProvider { internal LDKSignerProviderImpl(SignerProviderInterface arg, LDKSignerProviderHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; } private SignerProviderInterface arg; private LDKSignerProviderHolder impl_holder; - public byte[] generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, byte[] _user_channel_id) { + public long generate_channel_keys_id(bool _inbound, long _channel_value_satoshis, long _user_channel_id) { org.ldk.util.UInt128 _user_channel_id_conv = new org.ldk.util.UInt128(_user_channel_id); byte[] ret = arg.generate_channel_keys_id(_inbound, _channel_value_satoshis, _user_channel_id_conv); GC.KeepAlive(arg); - byte[] result = InternalUtils.check_arr_len(ret, 32); + long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32)); return result; } - public long derive_channel_signer(long _channel_value_satoshis, byte[] _channel_keys_id) { - WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id); + public long derive_channel_signer(long _channel_value_satoshis, long _channel_keys_id) { + byte[] _channel_keys_id_conv = InternalUtils.decodeUint8Array(_channel_keys_id); + WriteableEcdsaChannelSigner ret = arg.derive_channel_signer(_channel_value_satoshis, _channel_keys_id_conv); GC.KeepAlive(arg); long result = ret.clone_ptr(); if (impl_holder.held != null) { impl_holder.held.ptrs_to.AddLast(ret); }; return result; } - public long read_chan_signer(byte[] _reader) { - Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(_reader); + public long read_chan_signer(long _reader) { + byte[] _reader_conv = InternalUtils.decodeUint8Array(_reader); + Result_WriteableEcdsaChannelSignerDecodeErrorZ ret = arg.read_chan_signer(_reader_conv); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; } public long get_destination_script() { - Result_ScriptNoneZ ret = arg.get_destination_script(); + Result_CVec_u8ZNoneZ ret = arg.get_destination_script(); GC.KeepAlive(arg); long result = ret == null ? 0 : ret.clone_ptr(); return result; @@ -113,11 +113,19 @@ public class SignerProvider : CommonBase { return result; } } + + /** Creates a new instance of SignerProvider from a given implementation */ public static SignerProvider new_impl(SignerProviderInterface arg) { LDKSignerProviderHolder impl_holder = new LDKSignerProviderHolder(); - impl_holder.held = new SignerProvider(new LDKSignerProviderImpl(arg, impl_holder)); + LDKSignerProviderImpl impl = new LDKSignerProviderImpl(arg, impl_holder); + long[] ptr_idx = bindings.LDKSignerProvider_new(impl); + + impl_holder.held = new SignerProvider(null, ptr_idx[0]); + impl_holder.held.instance_idx = ptr_idx[1]; + impl_holder.held.bindings_instance = impl; return impl_holder.held; } + /** * Generates a unique `channel_keys_id` that can be used to obtain a [`Self::Signer`] through * [`SignerProvider::derive_channel_signer`]. The `user_channel_id` is provided to allow @@ -127,12 +135,14 @@ public class SignerProvider : CommonBase { * This method must return a different value each time it is called. */ public byte[] generate_channel_keys_id(bool inbound, long channel_value_satoshis, org.ldk.util.UInt128 user_channel_id) { - byte[] ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, user_channel_id.getLEBytes()); + long ret = bindings.SignerProvider_generate_channel_keys_id(this.ptr, inbound, channel_value_satoshis, InternalUtils.encodeUint8Array(user_channel_id.getLEBytes())); GC.KeepAlive(this); GC.KeepAlive(inbound); GC.KeepAlive(channel_value_satoshis); GC.KeepAlive(user_channel_id); - return ret; + if (ret >= 0 && ret <= 4096) { return null; } + byte[] ret_conv = InternalUtils.decodeUint8Array(ret); + return ret_conv; } /** @@ -144,7 +154,7 @@ public class SignerProvider : CommonBase { * [`ChannelSigner::channel_keys_id`]. */ public WriteableEcdsaChannelSigner derive_channel_signer(long channel_value_satoshis, byte[] channel_keys_id) { - long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32)); + long ret = bindings.SignerProvider_derive_channel_signer(this.ptr, channel_value_satoshis, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(channel_keys_id, 32))); GC.KeepAlive(this); GC.KeepAlive(channel_value_satoshis); GC.KeepAlive(channel_keys_id); @@ -170,7 +180,7 @@ public class SignerProvider : CommonBase { * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager */ public Result_WriteableEcdsaChannelSignerDecodeErrorZ read_chan_signer(byte[] reader) { - long ret = bindings.SignerProvider_read_chan_signer(this.ptr, reader); + long ret = bindings.SignerProvider_read_chan_signer(this.ptr, InternalUtils.encodeUint8Array(reader)); GC.KeepAlive(this); GC.KeepAlive(reader); if (ret >= 0 && ret <= 4096) { return null; } @@ -186,11 +196,11 @@ public class SignerProvider : CommonBase { * This method should return a different value each time it is called, to avoid linking * on-chain funds across channels as controlled to the same user. */ - public Result_ScriptNoneZ get_destination_script() { + public Result_CVec_u8ZNoneZ get_destination_script() { long ret = bindings.SignerProvider_get_destination_script(this.ptr); GC.KeepAlive(this); if (ret >= 0 && ret <= 4096) { return null; } - Result_ScriptNoneZ ret_hu_conv = Result_ScriptNoneZ.constr_from_ptr(ret); + Result_CVec_u8ZNoneZ ret_hu_conv = Result_CVec_u8ZNoneZ.constr_from_ptr(ret); return ret_hu_conv; }