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 outbound 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[][] outbound_htlc_preimages);
43 /**Validate the counterparty's revocation.
45 * This is required in order for the signer to make sure that the state has moved
46 * forward and it is safe to sign the next counterparty commitment.
48 Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret);
49 /**Returns an arbitrary identifier describing the set of keys which are provided back to you in
50 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
51 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
53 byte[] channel_keys_id();
54 /**Set the counterparty static channel data, including basepoints,
55 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
57 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
58 * instance, LDK will call this method exactly once - either immediately after construction
59 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
60 * information has been generated.
62 * channel_parameters.is_populated() MUST be true.
64 void provide_channel_parameters(ChannelTransactionParameters channel_parameters);
68 * A trait to handle Lightning channel key material without concretizing the channel type or
69 * the signature mechanism.
71 public class ChannelSigner : CommonBase {
72 internal bindings.LDKChannelSigner bindings_instance;
73 internal long instance_idx;
75 internal ChannelSigner(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
77 if (ptr != 0) { bindings.ChannelSigner_free(ptr); }
80 private class LDKChannelSignerHolder { internal ChannelSigner held; }
81 private class LDKChannelSignerImpl : bindings.LDKChannelSigner {
82 internal LDKChannelSignerImpl(ChannelSignerInterface arg, LDKChannelSignerHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
83 private ChannelSignerInterface arg;
84 private LDKChannelSignerHolder impl_holder;
85 public long get_per_commitment_point(long _idx) {
86 byte[] ret = arg.get_per_commitment_point(_idx);
88 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 33));
91 public long release_commitment_secret(long _idx) {
92 byte[] ret = arg.release_commitment_secret(_idx);
94 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
97 public long validate_holder_commitment(long _holder_tx, long _outbound_htlc_preimages) {
98 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); }
99 int _outbound_htlc_preimages_conv_8_len = InternalUtils.getArrayLength(_outbound_htlc_preimages);
100 byte[][] _outbound_htlc_preimages_conv_8_arr = new byte[_outbound_htlc_preimages_conv_8_len][];
101 for (int i = 0; i < _outbound_htlc_preimages_conv_8_len; i++) {
102 long _outbound_htlc_preimages_conv_8 = InternalUtils.getU64ArrayElem(_outbound_htlc_preimages, i);
103 byte[] _outbound_htlc_preimages_conv_8_conv = InternalUtils.decodeUint8Array(_outbound_htlc_preimages_conv_8);
104 _outbound_htlc_preimages_conv_8_arr[i] = _outbound_htlc_preimages_conv_8_conv;
106 bindings.free_buffer(_outbound_htlc_preimages);
107 Result_NoneNoneZ ret = arg.validate_holder_commitment(_holder_tx_hu_conv, _outbound_htlc_preimages_conv_8_arr);
109 long result = ret.clone_ptr();
112 public long validate_counterparty_revocation(long _idx, long _secret) {
113 byte[] _secret_conv = InternalUtils.decodeUint8Array(_secret);
114 Result_NoneNoneZ ret = arg.validate_counterparty_revocation(_idx, _secret_conv);
116 long result = ret.clone_ptr();
119 public long channel_keys_id() {
120 byte[] ret = arg.channel_keys_id();
122 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
125 public void provide_channel_parameters(long _channel_parameters) {
126 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); }
127 arg.provide_channel_parameters(_channel_parameters_hu_conv);
132 /** Creates a new instance of ChannelSigner from a given implementation */
133 public static ChannelSigner new_impl(ChannelSignerInterface arg, ChannelPublicKeys pubkeys) {
134 LDKChannelSignerHolder impl_holder = new LDKChannelSignerHolder();
135 LDKChannelSignerImpl impl = new LDKChannelSignerImpl(arg, impl_holder);
136 long[] ptr_idx = bindings.LDKChannelSigner_new(impl, pubkeys.clone_ptr());
138 impl_holder.held = new ChannelSigner(null, ptr_idx[0]);
139 impl_holder.held.instance_idx = ptr_idx[1];
140 impl_holder.held.bindings_instance = impl;
141 return impl_holder.held;
145 * Gets the per-commitment point for a specific commitment number
147 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
149 public byte[] get_per_commitment_point(long idx) {
150 long ret = bindings.ChannelSigner_get_per_commitment_point(this.ptr, idx);
153 if (ret >= 0 && ret <= 4096) { return null; }
154 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
159 * Gets the commitment secret for a specific commitment number as part of the revocation process
161 * An external signer implementation should error here if the commitment was already signed
162 * and should refuse to sign it in the future.
164 * May be called more than once for the same index.
166 * Note that the commitment number starts at `(1 << 48) - 1` and counts backwards.
168 public byte[] release_commitment_secret(long idx) {
169 long ret = bindings.ChannelSigner_release_commitment_secret(this.ptr, idx);
172 if (ret >= 0 && ret <= 4096) { return null; }
173 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
178 * Validate the counterparty's signatures on the holder commitment transaction and HTLCs.
180 * This is required in order for the signer to make sure that releasing a commitment
181 * secret won't leave us without a broadcastable holder transaction.
182 * Policy checks should be implemented in this function, including checking the amount
183 * sent to us and checking the HTLCs.
185 * The preimages of outbound HTLCs that were fulfilled since the last commitment are provided.
186 * A validating signer should ensure that an HTLC output is removed only when the matching
187 * preimage is provided, or when the value to holder is restored.
189 * Note that all the relevant preimages will be provided, but there may also be additional
190 * irrelevant or duplicate preimages.
192 public Result_NoneNoneZ validate_holder_commitment(org.ldk.structs.HolderCommitmentTransaction holder_tx, byte[][] outbound_htlc_preimages) {
193 long ret = bindings.ChannelSigner_validate_holder_commitment(this.ptr, holder_tx.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(outbound_htlc_preimages, outbound_htlc_preimages_conv_8 => InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(outbound_htlc_preimages_conv_8, 32)))));
195 GC.KeepAlive(holder_tx);
196 GC.KeepAlive(outbound_htlc_preimages);
197 if (ret >= 0 && ret <= 4096) { return null; }
198 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
199 if (this != null) { this.ptrs_to.AddLast(holder_tx); };
204 * Validate the counterparty's revocation.
206 * This is required in order for the signer to make sure that the state has moved
207 * forward and it is safe to sign the next counterparty commitment.
209 public Result_NoneNoneZ validate_counterparty_revocation(long idx, byte[] secret) {
210 long ret = bindings.ChannelSigner_validate_counterparty_revocation(this.ptr, idx, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(secret, 32)));
213 GC.KeepAlive(secret);
214 if (ret >= 0 && ret <= 4096) { return null; }
215 Result_NoneNoneZ ret_hu_conv = Result_NoneNoneZ.constr_from_ptr(ret);
220 * Returns an arbitrary identifier describing the set of keys which are provided back to you in
221 * some [`SpendableOutputDescriptor`] types. This should be sufficient to identify this
222 * [`EcdsaChannelSigner`] object uniquely and lookup or re-derive its keys.
224 public byte[] channel_keys_id() {
225 long ret = bindings.ChannelSigner_channel_keys_id(this.ptr);
227 if (ret >= 0 && ret <= 4096) { return null; }
228 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
233 * Set the counterparty static channel data, including basepoints,
234 * `counterparty_selected`/`holder_selected_contest_delay` and funding outpoint.
236 * This data is static, and will never change for a channel once set. For a given [`ChannelSigner`]
237 * instance, LDK will call this method exactly once - either immediately after construction
238 * (not including if done via [`SignerProvider::read_chan_signer`]) or when the funding
239 * information has been generated.
241 * channel_parameters.is_populated() MUST be true.
243 public void provide_channel_parameters(org.ldk.structs.ChannelTransactionParameters channel_parameters) {
244 bindings.ChannelSigner_provide_channel_parameters(this.ptr, channel_parameters.ptr);
246 GC.KeepAlive(channel_parameters);
247 if (this != null) { this.ptrs_to.AddLast(channel_parameters); };
251 * Frees any resources associated with this object given its this_arg pointer.
252 * Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
254 public ChannelPublicKeys get_pubkeys() {
255 long ret = bindings.ChannelSigner_get_pubkeys(this.ptr);
257 if (ret >= 0 && ret <= 4096) { return null; }
258 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
259 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };