7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of ChannelSigner */
12 public interface ChannelSignerInterface {
13 /**Gets the per-commitment point for a specific commitment number
15 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
17 byte[] get_per_commitment_point(long idx);
18 /**Gets the commitment secret for a specific commitment number as part of the revocation process
20 * An external signer implementation should error here if the commitment was already signed
21 * and should refuse to sign it in the future.
23 * May be called more than once for the same index.
25 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
27 byte[] release_commitment_secret(long idx);
28 /**Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
30 * This is required in order for the signer to make sure that releasing a commitment
31 * secret won't leave us without a broadcastable holder transaction.
32 * Policy checks should be implemented in this function, including checking the amount
33 * sent to us and checking the HTLCs.
35 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
36 * A validating signer should ensure that an HTLC output is removed only when the matching
37 * preimage is provided, or when the value to holder is restored.
39 * Note that all the relevant preimages will be provided, but there may also be additional
40 * irrelevant or duplicate preimages.
42 Result_NoneNoneZ validate_holder_commitment(HolderCommitmentTransaction holder_tx, byte[][] preimages);
43 /**Returns an arbitrary identifier describing the set of keys which are provided back to you in
44 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
45 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
47 byte[] channel_keys_id();
48 /**Set the counterparty static channel data, including basepoints,
49 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
51 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
52 * instance, LDK will call this method exactly once - either immediately after construction
53 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
54 * information has been generated.
56 * channel_parameters.is_populated() MUST be true.
58 void provide_channel_parameters(ChannelTransactionParameters channel_parameters);
62 * A trait to handle Lightning channel key material without concretizing the channel type or
63 * the signature mechanism.
65 public class ChannelSigner : CommonBase {
66 internal bindings.LDKChannelSigner bindings_instance;
67 internal long instance_idx;
69 internal ChannelSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
71 if (ptr != 0) { bindings.ChannelSigner_free(ptr); }
74 private class LDKChannelSignerHolder { internal ChannelSigner held; }
75 private class LDKChannelSignerImpl : bindings.LDKChannelSigner {
76 internal LDKChannelSignerImpl(ChannelSignerInterface arg, LDKChannelSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
77 private ChannelSignerInterface arg;
78 private LDKChannelSignerHolder impl_holder;
79 public long get_per_commitment_point(long _idx) {
80 byte[] ret = arg.get_per_commitment_point(_idx);
82 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 33));
85 public long release_commitment_secret(long _idx) {
86 byte[] ret = arg.release_commitment_secret(_idx);
88 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
91 public long validate_holder_commitment(long _holder_tx, long _preimages) {
92 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); }
93 int _preimages_conv_8_len = InternalUtils.getArrayLength(_preimages);
94 byte[][] _preimages_conv_8_arr = new byte[_preimages_conv_8_len][];
95 for (int i = 0; i < _preimages_conv_8_len; i++) {
96 long _preimages_conv_8 = InternalUtils.getU64ArrayElem(_preimages, i);
97 byte[] _preimages_conv_8_conv = InternalUtils.decodeUint8Array(_preimages_conv_8);
98 _preimages_conv_8_arr[i] = _preimages_conv_8_conv;
100 bindings.free_buffer(_preimages);
101 Result_NoneNoneZ ret = arg.validate_holder_commitment(_holder_tx_hu_conv, _preimages_conv_8_arr);
103 long result = ret == null ? 0 : ret.clone_ptr();
106 public long channel_keys_id() {
107 byte[] ret = arg.channel_keys_id();
109 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
112 public void provide_channel_parameters(long _channel_parameters) {
113 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); }
114 arg.provide_channel_parameters(_channel_parameters_hu_conv);
119 /** Creates a new instance of ChannelSigner from a given implementation */
120 public static ChannelSigner new_impl(ChannelSignerInterface arg, ChannelPublicKeys pubkeys) {
121 LDKChannelSignerHolder impl_holder = new LDKChannelSignerHolder();
122 LDKChannelSignerImpl impl = new LDKChannelSignerImpl(arg, impl_holder);
123 long[] ptr_idx = bindings.LDKChannelSigner_new(impl, pubkeys == null ? 0 : pubkeys.clone_ptr());
125 impl_holder.held = new ChannelSigner(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 * Gets the per-commitment point for a specific commitment number
134 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
136 public byte[] get_per_commitment_point(long idx) {
137 long ret = bindings.ChannelSigner_get_per_commitment_point(this.ptr, idx);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
146 * Gets the commitment secret for a specific commitment number as part of the revocation process
148 * An external signer implementation should error here if the commitment was already signed
149 * and should refuse to sign it in the future.
151 * May be called more than once for the same index.
153 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
155 public byte[] release_commitment_secret(long idx) {
156 long ret = bindings.ChannelSigner_release_commitment_secret(this.ptr, idx);
159 if (ret >= 0 && ret <= 4096) { return null; }
160 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
165 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
167 * This is required in order for the signer to make sure that releasing a commitment
168 * secret won't leave us without a broadcastable holder transaction.
169 * Policy checks should be implemented in this function, including checking the amount
170 * sent to us and checking the HTLCs.
172 * The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
173 * A validating signer should ensure that an HTLC output is removed only when the matching
174 * preimage is provided, or when the value to holder is restored.
176 * Note that all the relevant preimages will be provided, but there may also be additional
177 * irrelevant or duplicate preimages.
179 public Result_NoneNoneZ validate_holder_commitment(org.ldk.structs.HolderCommitmentTransaction holder_tx, byte[][] preimages) {
180 long ret = bindings.ChannelSigner_validate_holder_commitment(this.ptr, holder_tx == null ? 0 : holder_tx.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(preimages, preimages_conv_8 => InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(preimages_conv_8, 32)))));
182 GC.KeepAlive(holder_tx);
183 GC.KeepAlive(preimages);
184 if (ret >= 0 && ret <= 4096) { return null; }
185 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
186 if (this != null) { this.ptrs_to.AddLast(holder_tx); };
191 * Returns an arbitrary identifier describing the set of keys which are provided back to you in
192 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
193 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
195 public byte[] channel_keys_id() {
196 long ret = bindings.ChannelSigner_channel_keys_id(this.ptr);
198 if (ret >= 0 && ret <= 4096) { return null; }
199 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
204 * Set the counterparty static channel data, including basepoints,
205 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
207 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
208 * instance, LDK will call this method exactly once - either immediately after construction
209 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
210 * information has been generated.
212 * channel_parameters.is_populated() MUST be true.
214 public void provide_channel_parameters(org.ldk.structs.ChannelTransactionParameters channel_parameters) {
215 bindings.ChannelSigner_provide_channel_parameters(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr);
217 GC.KeepAlive(channel_parameters);
218 if (this != null) { this.ptrs_to.AddLast(channel_parameters); };
222 * Frees any resources associated with this object given its this_arg pointer.
223 * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
225 public ChannelPublicKeys get_pubkeys() {
226 long ret = bindings.ChannelSigner_get_pubkeys(this.ptr);
228 if (ret >= 0 && ret <= 4096) { return null; }
229 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
230 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };