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 Sign 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 * Private key of anchor tx
29 public byte[] get_funding_key() {
30 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
31 Reference.reachabilityFence(this);
36 * Private key of anchor tx
38 public void set_funding_key(byte[] val) {
39 bindings.InMemorySigner_set_funding_key(this.ptr, InternalUtils.check_arr_len(val, 32));
40 Reference.reachabilityFence(this);
41 Reference.reachabilityFence(val);
45 * Holder secret key for blinded revocation pubkey
47 public byte[] get_revocation_base_key() {
48 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
49 Reference.reachabilityFence(this);
54 * Holder secret key for blinded revocation pubkey
56 public void set_revocation_base_key(byte[] val) {
57 bindings.InMemorySigner_set_revocation_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
58 Reference.reachabilityFence(this);
59 Reference.reachabilityFence(val);
63 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
65 public byte[] get_payment_key() {
66 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
67 Reference.reachabilityFence(this);
72 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
74 public void set_payment_key(byte[] val) {
75 bindings.InMemorySigner_set_payment_key(this.ptr, InternalUtils.check_arr_len(val, 32));
76 Reference.reachabilityFence(this);
77 Reference.reachabilityFence(val);
81 * Holder secret key used in HTLC tx
83 public byte[] get_delayed_payment_base_key() {
84 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
85 Reference.reachabilityFence(this);
90 * Holder secret key used in HTLC tx
92 public void set_delayed_payment_base_key(byte[] val) {
93 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
94 Reference.reachabilityFence(this);
95 Reference.reachabilityFence(val);
99 * Holder htlc secret key used in commitment tx htlc outputs
101 public byte[] get_htlc_base_key() {
102 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
103 Reference.reachabilityFence(this);
108 * Holder htlc secret key used in commitment tx htlc outputs
110 public void set_htlc_base_key(byte[] val) {
111 bindings.InMemorySigner_set_htlc_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
112 Reference.reachabilityFence(this);
113 Reference.reachabilityFence(val);
119 public byte[] get_commitment_seed() {
120 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
121 Reference.reachabilityFence(this);
128 public void set_commitment_seed(byte[] val) {
129 bindings.InMemorySigner_set_commitment_seed(this.ptr, InternalUtils.check_arr_len(val, 32));
130 Reference.reachabilityFence(this);
131 Reference.reachabilityFence(val);
135 long ret = bindings.InMemorySigner_clone_ptr(this.ptr);
136 Reference.reachabilityFence(this);
141 * Creates a copy of the InMemorySigner
143 public InMemorySigner clone() {
144 long ret = bindings.InMemorySigner_clone(this.ptr);
145 Reference.reachabilityFence(this);
146 if (ret >= 0 && ret <= 4096) { return null; }
147 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
148 ret_hu_conv.ptrs_to.add(this);
153 * Create a new InMemorySigner
155 public static InMemorySigner of(byte[] node_secret, 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) {
156 long ret = bindings.InMemorySigner_new(InternalUtils.check_arr_len(node_secret, 32), 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));
157 Reference.reachabilityFence(node_secret);
158 Reference.reachabilityFence(funding_key);
159 Reference.reachabilityFence(revocation_base_key);
160 Reference.reachabilityFence(payment_key);
161 Reference.reachabilityFence(delayed_payment_base_key);
162 Reference.reachabilityFence(htlc_base_key);
163 Reference.reachabilityFence(commitment_seed);
164 Reference.reachabilityFence(channel_value_satoshis);
165 Reference.reachabilityFence(channel_keys_id);
166 if (ret >= 0 && ret <= 4096) { return null; }
167 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
168 ret_hu_conv.ptrs_to.add(ret_hu_conv);
173 * Counterparty pubkeys.
174 * Will panic if ready_channel wasn't called.
176 public ChannelPublicKeys counterparty_pubkeys() {
177 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
178 Reference.reachabilityFence(this);
179 if (ret >= 0 && ret <= 4096) { return null; }
180 org.ldk.structs.ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelPublicKeys(null, ret); }
181 ret_hu_conv.ptrs_to.add(this);
186 * The contest_delay value specified by our counterparty and applied on holder-broadcastable
187 * transactions, ie the amount of time that we have to wait to recover our funds if we
188 * broadcast a transaction.
189 * Will panic if ready_channel wasn't called.
191 public short counterparty_selected_contest_delay() {
192 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
193 Reference.reachabilityFence(this);
198 * The contest_delay value specified by us and applied on transactions broadcastable
199 * by our counterparty, ie the amount of time that they have to wait to recover their funds
200 * if they broadcast a transaction.
201 * Will panic if ready_channel wasn't called.
203 public short holder_selected_contest_delay() {
204 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
205 Reference.reachabilityFence(this);
210 * Whether the holder is the initiator
211 * Will panic if ready_channel wasn't called.
213 public boolean is_outbound() {
214 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
215 Reference.reachabilityFence(this);
221 * Will panic if ready_channel wasn't called.
223 public OutPoint funding_outpoint() {
224 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
225 Reference.reachabilityFence(this);
226 if (ret >= 0 && ret <= 4096) { return null; }
227 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
228 ret_hu_conv.ptrs_to.add(this);
233 * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
234 * building transactions.
236 * Will panic if ready_channel wasn't called.
238 public ChannelTransactionParameters get_channel_parameters() {
239 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
240 Reference.reachabilityFence(this);
241 if (ret >= 0 && ret <= 4096) { return null; }
242 org.ldk.structs.ChannelTransactionParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTransactionParameters(null, ret); }
243 ret_hu_conv.ptrs_to.add(this);
248 * Whether anchors should be used.
249 * Will panic if ready_channel wasn't called.
251 public boolean opt_anchors() {
252 boolean ret = bindings.InMemorySigner_opt_anchors(this.ptr);
253 Reference.reachabilityFence(this);
258 * Sign the single input of spend_tx at index `input_idx` which spends the output
259 * described by descriptor, returning the witness stack for the input.
261 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
262 * is not spending the outpoint described by `descriptor.outpoint`,
263 * or if an output descriptor script_pubkey does not match the one we can spend.
265 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
266 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
267 Reference.reachabilityFence(this);
268 Reference.reachabilityFence(spend_tx);
269 Reference.reachabilityFence(input_idx);
270 Reference.reachabilityFence(descriptor);
271 if (ret >= 0 && ret <= 4096) { return null; }
272 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
273 this.ptrs_to.add(descriptor);
278 * Sign the single input of spend_tx at index `input_idx` which spends the output
279 * described by descriptor, returning the witness stack for the input.
281 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
282 * is not spending the outpoint described by `descriptor.outpoint`, does not have a
283 * sequence set to `descriptor.to_self_delay`, or if an output descriptor
284 * script_pubkey does not match the one we can spend.
286 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
287 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
288 Reference.reachabilityFence(this);
289 Reference.reachabilityFence(spend_tx);
290 Reference.reachabilityFence(input_idx);
291 Reference.reachabilityFence(descriptor);
292 if (ret >= 0 && ret <= 4096) { return null; }
293 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
294 this.ptrs_to.add(descriptor);
299 * Constructs a new BaseSign which calls the relevant methods on this_arg.
300 * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
302 public BaseSign as_BaseSign() {
303 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
304 Reference.reachabilityFence(this);
305 if (ret >= 0 && ret <= 4096) { return null; }
306 BaseSign ret_hu_conv = new BaseSign(null, ret);
307 ret_hu_conv.ptrs_to.add(this);
312 * Constructs a new Sign which calls the relevant methods on this_arg.
313 * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
315 public Sign as_Sign() {
316 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
317 Reference.reachabilityFence(this);
318 if (ret >= 0 && ret <= 4096) { return null; }
319 Sign ret_hu_conv = new Sign(null, ret);
320 ret_hu_conv.ptrs_to.add(this);
325 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
327 public byte[] write() {
328 byte[] ret = bindings.InMemorySigner_write(this.ptr);
329 Reference.reachabilityFence(this);
334 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
336 public static Result_InMemorySignerDecodeErrorZ read(byte[] ser, byte[] arg) {
337 long ret = bindings.InMemorySigner_read(ser, InternalUtils.check_arr_len(arg, 32));
338 Reference.reachabilityFence(ser);
339 Reference.reachabilityFence(arg);
340 if (ret >= 0 && ret <= 4096) { return null; }
341 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);