1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
14 * This implementation performs no policy checks and is insufficient by itself as
15 * a secure external signer.
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class InMemorySigner extends CommonBase {
19 InMemorySigner(Object _dummy, long ptr) { super(ptr); }
20 @Override @SuppressWarnings("deprecation")
21 protected void finalize() throws Throwable {
23 if (ptr != 0) { bindings.InMemorySigner_free(ptr); }
27 * Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
28 * holder's anchor output in a commitment transaction, if one is present.
30 public byte[] get_funding_key() {
31 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
32 Reference.reachabilityFence(this);
37 * Holder secret key in the 2-of-2 multisig script of a channel. This key also backs the
38 * holder's anchor output in a commitment transaction, if one is present.
40 public void set_funding_key(byte[] val) {
41 bindings.InMemorySigner_set_funding_key(this.ptr, InternalUtils.check_arr_len(val, 32));
42 Reference.reachabilityFence(this);
43 Reference.reachabilityFence(val);
47 * Holder secret key for blinded revocation pubkey.
49 public byte[] get_revocation_base_key() {
50 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
51 Reference.reachabilityFence(this);
56 * Holder secret key for blinded revocation pubkey.
58 public void set_revocation_base_key(byte[] val) {
59 bindings.InMemorySigner_set_revocation_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
60 Reference.reachabilityFence(this);
61 Reference.reachabilityFence(val);
65 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
67 public byte[] get_payment_key() {
68 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
69 Reference.reachabilityFence(this);
74 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions.
76 public void set_payment_key(byte[] val) {
77 bindings.InMemorySigner_set_payment_key(this.ptr, InternalUtils.check_arr_len(val, 32));
78 Reference.reachabilityFence(this);
79 Reference.reachabilityFence(val);
83 * Holder secret key used in an HTLC transaction.
85 public byte[] get_delayed_payment_base_key() {
86 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
87 Reference.reachabilityFence(this);
92 * Holder secret key used in an HTLC transaction.
94 public void set_delayed_payment_base_key(byte[] val) {
95 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
96 Reference.reachabilityFence(this);
97 Reference.reachabilityFence(val);
101 * Holder HTLC secret key used in commitment transaction HTLC outputs.
103 public byte[] get_htlc_base_key() {
104 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
105 Reference.reachabilityFence(this);
110 * Holder HTLC secret key used in commitment transaction HTLC outputs.
112 public void set_htlc_base_key(byte[] val) {
113 bindings.InMemorySigner_set_htlc_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
114 Reference.reachabilityFence(this);
115 Reference.reachabilityFence(val);
121 public byte[] get_commitment_seed() {
122 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
123 Reference.reachabilityFence(this);
130 public void set_commitment_seed(byte[] val) {
131 bindings.InMemorySigner_set_commitment_seed(this.ptr, InternalUtils.check_arr_len(val, 32));
132 Reference.reachabilityFence(this);
133 Reference.reachabilityFence(val);
137 long ret = bindings.InMemorySigner_clone_ptr(this.ptr);
138 Reference.reachabilityFence(this);
143 * Creates a copy of the InMemorySigner
145 public InMemorySigner clone() {
146 long ret = bindings.InMemorySigner_clone(this.ptr);
147 Reference.reachabilityFence(this);
148 if (ret >= 0 && ret <= 4096) { return null; }
149 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
150 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
155 * Creates a new [`InMemorySigner`].
157 public static InMemorySigner of(byte[] funding_key, byte[] revocation_base_key, byte[] payment_key, byte[] delayed_payment_base_key, byte[] htlc_base_key, byte[] commitment_seed, long channel_value_satoshis, byte[] channel_keys_id, byte[] rand_bytes_unique_start) {
158 long ret = bindings.InMemorySigner_new(InternalUtils.check_arr_len(funding_key, 32), InternalUtils.check_arr_len(revocation_base_key, 32), InternalUtils.check_arr_len(payment_key, 32), InternalUtils.check_arr_len(delayed_payment_base_key, 32), InternalUtils.check_arr_len(htlc_base_key, 32), InternalUtils.check_arr_len(commitment_seed, 32), channel_value_satoshis, InternalUtils.check_arr_len(channel_keys_id, 32), InternalUtils.check_arr_len(rand_bytes_unique_start, 32));
159 Reference.reachabilityFence(funding_key);
160 Reference.reachabilityFence(revocation_base_key);
161 Reference.reachabilityFence(payment_key);
162 Reference.reachabilityFence(delayed_payment_base_key);
163 Reference.reachabilityFence(htlc_base_key);
164 Reference.reachabilityFence(commitment_seed);
165 Reference.reachabilityFence(channel_value_satoshis);
166 Reference.reachabilityFence(channel_keys_id);
167 Reference.reachabilityFence(rand_bytes_unique_start);
168 if (ret >= 0 && ret <= 4096) { return null; }
169 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
170 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
175 * Returns the counterparty's pubkeys.
177 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
178 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
180 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
183 public ChannelPublicKeys counterparty_pubkeys() {
184 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
185 Reference.reachabilityFence(this);
186 if (ret >= 0 && ret <= 4096) { return null; }
187 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
188 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
193 * Returns the `contest_delay` value specified by our counterparty and applied on holder-broadcastable
194 * transactions, i.e., the amount of time that we have to wait to recover our funds if we
195 * broadcast a transaction.
197 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
198 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
200 public Option_u16Z counterparty_selected_contest_delay() {
201 long ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
202 Reference.reachabilityFence(this);
203 if (ret >= 0 && ret <= 4096) { return null; }
204 org.ldk.structs.Option_u16Z ret_hu_conv = org.ldk.structs.Option_u16Z.constr_from_ptr(ret);
205 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
210 * Returns the `contest_delay` value specified by us and applied on transactions broadcastable
211 * by our counterparty, i.e., the amount of time that they have to wait to recover their funds
212 * if they broadcast a transaction.
214 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
215 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
217 public Option_u16Z holder_selected_contest_delay() {
218 long ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
219 Reference.reachabilityFence(this);
220 if (ret >= 0 && ret <= 4096) { return null; }
221 org.ldk.structs.Option_u16Z ret_hu_conv = org.ldk.structs.Option_u16Z.constr_from_ptr(ret);
222 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
227 * Returns whether the holder is the initiator.
229 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
230 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
232 public Option_boolZ is_outbound() {
233 long ret = bindings.InMemorySigner_is_outbound(this.ptr);
234 Reference.reachabilityFence(this);
235 if (ret >= 0 && ret <= 4096) { return null; }
236 org.ldk.structs.Option_boolZ ret_hu_conv = org.ldk.structs.Option_boolZ.constr_from_ptr(ret);
237 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
244 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
245 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
247 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
250 public OutPoint funding_outpoint() {
251 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
252 Reference.reachabilityFence(this);
253 if (ret >= 0 && ret <= 4096) { return null; }
254 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
255 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
260 * Returns a [`ChannelTransactionParameters`] for this channel, to be used when verifying or
261 * building transactions.
263 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
264 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
266 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
269 public ChannelTransactionParameters get_channel_parameters() {
270 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
271 Reference.reachabilityFence(this);
272 if (ret >= 0 && ret <= 4096) { return null; }
273 org.ldk.structs.ChannelTransactionParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTransactionParameters(null, ret); }
274 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
279 * Returns the channel type features of the channel parameters. Should be helpful for
280 * determining a channel's category, i. e. legacy/anchors/taproot/etc.
282 * Will return `None` if [`ChannelSigner::provide_channel_parameters`] has not been called.
283 * In general, this is safe to `unwrap` only in [`ChannelSigner`] implementation.
285 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
288 public ChannelTypeFeatures channel_type_features() {
289 long ret = bindings.InMemorySigner_channel_type_features(this.ptr);
290 Reference.reachabilityFence(this);
291 if (ret >= 0 && ret <= 4096) { return null; }
292 org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); }
293 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
298 * Sign the single input of `spend_tx` at index `input_idx`, which spends the output described
299 * by `descriptor`, returning the witness stack for the input.
301 * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
302 * is not spending the outpoint described by [`descriptor.outpoint`],
303 * or if an output descriptor `script_pubkey` does not match the one we can spend.
305 * [`descriptor.outpoint`]: StaticPaymentOutputDescriptor::outpoint
307 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, org.ldk.structs.StaticPaymentOutputDescriptor descriptor) {
308 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
309 Reference.reachabilityFence(this);
310 Reference.reachabilityFence(spend_tx);
311 Reference.reachabilityFence(input_idx);
312 Reference.reachabilityFence(descriptor);
313 if (ret >= 0 && ret <= 4096) { return null; }
314 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
315 if (this != null) { this.ptrs_to.add(descriptor); };
320 * Sign the single input of `spend_tx` at index `input_idx` which spends the output
321 * described by `descriptor`, returning the witness stack for the input.
323 * Returns an error if the input at `input_idx` does not exist, has a non-empty `script_sig`,
324 * is not spending the outpoint described by [`descriptor.outpoint`], does not have a
325 * sequence set to [`descriptor.to_self_delay`], or if an output descriptor
326 * `script_pubkey` does not match the one we can spend.
328 * [`descriptor.outpoint`]: DelayedPaymentOutputDescriptor::outpoint
329 * [`descriptor.to_self_delay`]: DelayedPaymentOutputDescriptor::to_self_delay
331 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, org.ldk.structs.DelayedPaymentOutputDescriptor descriptor) {
332 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr);
333 Reference.reachabilityFence(this);
334 Reference.reachabilityFence(spend_tx);
335 Reference.reachabilityFence(input_idx);
336 Reference.reachabilityFence(descriptor);
337 if (ret >= 0 && ret <= 4096) { return null; }
338 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
339 if (this != null) { this.ptrs_to.add(descriptor); };
344 * Constructs a new EntropySource which calls the relevant methods on this_arg.
345 * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
347 public EntropySource as_EntropySource() {
348 long ret = bindings.InMemorySigner_as_EntropySource(this.ptr);
349 Reference.reachabilityFence(this);
350 if (ret >= 0 && ret <= 4096) { return null; }
351 EntropySource ret_hu_conv = new EntropySource(null, ret);
352 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
357 * Constructs a new ChannelSigner which calls the relevant methods on this_arg.
358 * This copies the `inner` pointer in this_arg and thus the returned ChannelSigner must be freed before this_arg is
360 public ChannelSigner as_ChannelSigner() {
361 long ret = bindings.InMemorySigner_as_ChannelSigner(this.ptr);
362 Reference.reachabilityFence(this);
363 if (ret >= 0 && ret <= 4096) { return null; }
364 ChannelSigner ret_hu_conv = new ChannelSigner(null, ret);
365 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
370 * Constructs a new EcdsaChannelSigner which calls the relevant methods on this_arg.
371 * This copies the `inner` pointer in this_arg and thus the returned EcdsaChannelSigner must be freed before this_arg is
373 public EcdsaChannelSigner as_EcdsaChannelSigner() {
374 long ret = bindings.InMemorySigner_as_EcdsaChannelSigner(this.ptr);
375 Reference.reachabilityFence(this);
376 if (ret >= 0 && ret <= 4096) { return null; }
377 EcdsaChannelSigner ret_hu_conv = new EcdsaChannelSigner(null, ret);
378 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
383 * Constructs a new WriteableEcdsaChannelSigner which calls the relevant methods on this_arg.
384 * This copies the `inner` pointer in this_arg and thus the returned WriteableEcdsaChannelSigner must be freed before this_arg is
386 public WriteableEcdsaChannelSigner as_WriteableEcdsaChannelSigner() {
387 long ret = bindings.InMemorySigner_as_WriteableEcdsaChannelSigner(this.ptr);
388 Reference.reachabilityFence(this);
389 if (ret >= 0 && ret <= 4096) { return null; }
390 WriteableEcdsaChannelSigner ret_hu_conv = new WriteableEcdsaChannelSigner(null, ret);
391 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
396 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
398 public byte[] write() {
399 byte[] ret = bindings.InMemorySigner_write(this.ptr);
400 Reference.reachabilityFence(this);
405 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
407 public static Result_InMemorySignerDecodeErrorZ read(byte[] ser, org.ldk.structs.EntropySource arg) {
408 long ret = bindings.InMemorySigner_read(ser, arg.ptr);
409 Reference.reachabilityFence(ser);
410 Reference.reachabilityFence(arg);
411 if (ret >= 0 && ret <= 4096) { return null; }
412 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);
413 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(arg); };