6 namespace org { namespace ldk { namespace structs {
9 * A trait to handle Lightning channel key material without concretizing the channel type or
10 * the signature mechanism.
12 public class ChannelSigner : CommonBase {
13 internal readonly bindings.LDKChannelSigner bindings_instance;
14 internal ChannelSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
15 private ChannelSigner(bindings.LDKChannelSigner arg, ChannelPublicKeys pubkeys) : base(bindings.LDKChannelSigner_new(arg, pubkeys == null ? 0 : pubkeys.clone_ptr())) {
16 this.ptrs_to.AddLast(arg);
17 this.bindings_instance = arg;
20 if (ptr != 0) { bindings.ChannelSigner_free(ptr); }
23 public interface ChannelSignerInterface {
25 * Gets the per-commitment point for a specific commitment number
27 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
29 byte[] get_per_commitment_point(long _idx);
31 * Gets the commitment secret for a specific commitment number as part of the revocation process
33 * An external signer implementation should error here if the commitment was already signed
34 * and should refuse to sign it in the future.
36 * May be called more than once for the same index.
38 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
40 byte[] release_commitment_secret(long _idx);
42 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
44 * This is required in order for the signer to make sure that releasing a commitment
45 * secret won't leave us without a broadcastable holder transaction.
46 * Policy checks should be implemented in this function, including checking the amount
47 * sent to us and checking the HTLCs.
49 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
50 * A validating signer should ensure that an HTLC output is removed only when the matching
51 * preimage is provided, or when the value to holder is restored.
53 * Note that all the relevant preimages will be provided, but there may also be additional
54 * irrelevant or duplicate preimages.
56 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction _holder_tx, byte[][] _preimages);
58 * Returns an arbitrary identifier describing the set of keys which are provided back to you in
59 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
60 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
62 byte[] channel_keys_id();
64 * Set the counterparty static channel data, including basepoints,
65 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
67 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
68 * instance, LDK will call this method exactly once - either immediately after construction
69 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
70 * information has been generated.
72 * channel_parameters.is_populated() MUST be true.
74 void provide_channel_parameters(ChannelTransactionParameters _channel_parameters);
76 private class LDKChannelSignerHolder { internal ChannelSigner held; }
77 private class LDKChannelSignerImpl : bindings.LDKChannelSigner {
78 internal LDKChannelSignerImpl(ChannelSignerInterface arg, LDKChannelSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
79 private ChannelSignerInterface arg;
80 private LDKChannelSignerHolder impl_holder;
81 public byte[] get_per_commitment_point(long _idx) {
82 byte[] ret = arg.get_per_commitment_point(_idx);
84 byte[] result = InternalUtils.check_arr_len(ret, 33);
87 public byte[] release_commitment_secret(long _idx) {
88 byte[] ret = arg.release_commitment_secret(_idx);
90 byte[] result = InternalUtils.check_arr_len(ret, 32);
93 public long validate_holder_commitment(long _holder_tx, byte[][] _preimages) {
94 org.ldk.structs.HolderCommitmentTransaction _holder_tx_hu_conv = null; if (_holder_tx < 0 || _holder_tx > 4096) { _holder_tx_hu_conv = new org.ldk.structs.HolderCommitmentTransaction(null, _holder_tx); }
95 Result_NoneNoneZ ret = arg.validate_holder_commitment(_holder_tx_hu_conv, _preimages);
97 long result = ret == null ? 0 : ret.clone_ptr();
100 public byte[] channel_keys_id() {
101 byte[] ret = arg.channel_keys_id();
103 byte[] result = InternalUtils.check_arr_len(ret, 32);
106 public void provide_channel_parameters(long _channel_parameters) {
107 org.ldk.structs.ChannelTransactionParameters _channel_parameters_hu_conv = null; if (_channel_parameters < 0 || _channel_parameters > 4096) { _channel_parameters_hu_conv = new org.ldk.structs.ChannelTransactionParameters(null, _channel_parameters); }
108 arg.provide_channel_parameters(_channel_parameters_hu_conv);
112 public static ChannelSigner new_impl(ChannelSignerInterface arg, ChannelPublicKeys pubkeys) {
113 LDKChannelSignerHolder impl_holder = new LDKChannelSignerHolder();
114 impl_holder.held = new ChannelSigner(new LDKChannelSignerImpl(arg, impl_holder), pubkeys);
115 return impl_holder.held;
118 * Gets the per-commitment point for a specific commitment number
120 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
122 public byte[] get_per_commitment_point(long idx) {
123 byte[] ret = bindings.ChannelSigner_get_per_commitment_point(this.ptr, idx);
130 * Gets the commitment secret for a specific commitment number as part of the revocation process
132 * An external signer implementation should error here if the commitment was already signed
133 * and should refuse to sign it in the future.
135 * May be called more than once for the same index.
137 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
139 public byte[] release_commitment_secret(long idx) {
140 byte[] ret = bindings.ChannelSigner_release_commitment_secret(this.ptr, idx);
147 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
149 * This is required in order for the signer to make sure that releasing a commitment
150 * secret won't leave us without a broadcastable holder transaction.
151 * Policy checks should be implemented in this function, including checking the amount
152 * sent to us and checking the HTLCs.
154 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
155 * A validating signer should ensure that an HTLC output is removed only when the matching
156 * preimage is provided, or when the value to holder is restored.
158 * Note that all the relevant preimages will be provided, but there may also be additional
159 * irrelevant or duplicate preimages.
161 public Result_NoneNoneZ validate_holder_commitment(org.ldk.structs.HolderCommitmentTransaction holder_tx, byte[][] preimages) {
162 long ret = bindings.ChannelSigner_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr, preimages != null ? InternalUtils.mapArray(preimages, preimages_conv_8 => InternalUtils.check_arr_len(preimages_conv_8, 32)) : null);
164 GC.KeepAlive(holder_tx);
165 GC.KeepAlive(preimages);
166 if (ret >= 0 && ret <= 4096) { return null; }
167 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
168 if (this != null) { this.ptrs_to.AddLast(holder_tx); };
173 * Returns an arbitrary identifier describing the set of keys which are provided back to you in
174 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
175 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
177 public byte[] channel_keys_id() {
178 byte[] ret = bindings.ChannelSigner_channel_keys_id(this.ptr);
184 * Set the counterparty static channel data, including basepoints,
185 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
187 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
188 * instance, LDK will call this method exactly once - either immediately after construction
189 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
190 * information has been generated.
192 * channel_parameters.is_populated() MUST be true.
194 public void provide_channel_parameters(org.ldk.structs.ChannelTransactionParameters channel_parameters) {
195 bindings.ChannelSigner_provide_channel_parameters(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr);
197 GC.KeepAlive(channel_parameters);
198 if (this != null) { this.ptrs_to.AddLast(channel_parameters); };
202 * Frees any resources associated with this object given its this_arg pointer.
203 * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
205 public ChannelPublicKeys get_pubkeys() {
206 long ret = bindings.ChannelSigner_get_pubkeys(this.ptr);
208 if (ret >= 0 && ret <= 4096) { return null; }
209 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };