1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * A simple implementation of Sign that just keeps the private keys in memory.
13 * This implementation performs no policy checks and is insufficient by itself as
14 * a secure external signer.
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class InMemorySigner extends CommonBase {
18 InMemorySigner(Object _dummy, long ptr) { super(ptr); }
19 @Override @SuppressWarnings("deprecation")
20 protected void finalize() throws Throwable {
22 if (ptr != 0) { bindings.InMemorySigner_free(ptr); }
26 * Private key of anchor tx
28 public byte[] get_funding_key() {
29 byte[] ret = bindings.InMemorySigner_get_funding_key(this.ptr);
34 * Private key of anchor tx
36 public void set_funding_key(byte[] val) {
37 bindings.InMemorySigner_set_funding_key(this.ptr, InternalUtils.check_arr_len(val, 32));
41 * Holder secret key for blinded revocation pubkey
43 public byte[] get_revocation_base_key() {
44 byte[] ret = bindings.InMemorySigner_get_revocation_base_key(this.ptr);
49 * Holder secret key for blinded revocation pubkey
51 public void set_revocation_base_key(byte[] val) {
52 bindings.InMemorySigner_set_revocation_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
56 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
58 public byte[] get_payment_key() {
59 byte[] ret = bindings.InMemorySigner_get_payment_key(this.ptr);
64 * Holder secret key used for our balance in counterparty-broadcasted commitment transactions
66 public void set_payment_key(byte[] val) {
67 bindings.InMemorySigner_set_payment_key(this.ptr, InternalUtils.check_arr_len(val, 32));
71 * Holder secret key used in HTLC tx
73 public byte[] get_delayed_payment_base_key() {
74 byte[] ret = bindings.InMemorySigner_get_delayed_payment_base_key(this.ptr);
79 * Holder secret key used in HTLC tx
81 public void set_delayed_payment_base_key(byte[] val) {
82 bindings.InMemorySigner_set_delayed_payment_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
86 * Holder htlc secret key used in commitment tx htlc outputs
88 public byte[] get_htlc_base_key() {
89 byte[] ret = bindings.InMemorySigner_get_htlc_base_key(this.ptr);
94 * Holder htlc secret key used in commitment tx htlc outputs
96 public void set_htlc_base_key(byte[] val) {
97 bindings.InMemorySigner_set_htlc_base_key(this.ptr, InternalUtils.check_arr_len(val, 32));
103 public byte[] get_commitment_seed() {
104 byte[] ret = bindings.InMemorySigner_get_commitment_seed(this.ptr);
111 public void set_commitment_seed(byte[] val) {
112 bindings.InMemorySigner_set_commitment_seed(this.ptr, InternalUtils.check_arr_len(val, 32));
116 long ret = bindings.InMemorySigner_clone_ptr(this.ptr);
121 * Creates a copy of the InMemorySigner
123 public InMemorySigner clone() {
124 long ret = bindings.InMemorySigner_clone(this.ptr);
125 if (ret >= 0 && ret <= 4096) { return null; }
126 InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InMemorySigner(null, ret); }
127 ret_hu_conv.ptrs_to.add(this);
132 * Create a new InMemorySigner
134 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) {
135 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));
136 if (ret >= 0 && ret <= 4096) { return null; }
137 InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InMemorySigner(null, ret); }
138 ret_hu_conv.ptrs_to.add(ret_hu_conv);
143 * Counterparty pubkeys.
144 * Will panic if ready_channel wasn't called.
146 public ChannelPublicKeys counterparty_pubkeys() {
147 long ret = bindings.InMemorySigner_counterparty_pubkeys(this.ptr);
148 if (ret >= 0 && ret <= 4096) { return null; }
149 ChannelPublicKeys ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelPublicKeys(null, ret); }
150 ret_hu_conv.ptrs_to.add(this);
155 * The contest_delay value specified by our counterparty and applied on holder-broadcastable
156 * transactions, ie the amount of time that we have to wait to recover our funds if we
157 * broadcast a transaction.
158 * Will panic if ready_channel wasn't called.
160 public short counterparty_selected_contest_delay() {
161 short ret = bindings.InMemorySigner_counterparty_selected_contest_delay(this.ptr);
166 * The contest_delay value specified by us and applied on transactions broadcastable
167 * by our counterparty, ie the amount of time that they have to wait to recover their funds
168 * if they broadcast a transaction.
169 * Will panic if ready_channel wasn't called.
171 public short holder_selected_contest_delay() {
172 short ret = bindings.InMemorySigner_holder_selected_contest_delay(this.ptr);
177 * Whether the holder is the initiator
178 * Will panic if ready_channel wasn't called.
180 public boolean is_outbound() {
181 boolean ret = bindings.InMemorySigner_is_outbound(this.ptr);
187 * Will panic if ready_channel wasn't called.
189 public OutPoint funding_outpoint() {
190 long ret = bindings.InMemorySigner_funding_outpoint(this.ptr);
191 if (ret >= 0 && ret <= 4096) { return null; }
192 OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new OutPoint(null, ret); }
193 ret_hu_conv.ptrs_to.add(this);
198 * Obtain a ChannelTransactionParameters for this channel, to be used when verifying or
199 * building transactions.
201 * Will panic if ready_channel wasn't called.
203 public ChannelTransactionParameters get_channel_parameters() {
204 long ret = bindings.InMemorySigner_get_channel_parameters(this.ptr);
205 if (ret >= 0 && ret <= 4096) { return null; }
206 ChannelTransactionParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new ChannelTransactionParameters(null, ret); }
207 ret_hu_conv.ptrs_to.add(this);
212 * Sign the single input of spend_tx at index `input_idx` which spends the output
213 * described by descriptor, returning the witness stack for the input.
215 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
216 * or is not spending the outpoint described by `descriptor.outpoint`.
218 public Result_CVec_CVec_u8ZZNoneZ sign_counterparty_payment_input(byte[] spend_tx, long input_idx, StaticPaymentOutputDescriptor descriptor) {
219 long ret = bindings.InMemorySigner_sign_counterparty_payment_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
220 if (ret >= 0 && ret <= 4096) { return null; }
221 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
222 this.ptrs_to.add(descriptor);
227 * Sign the single input of spend_tx at index `input_idx` which spends the output
228 * described by descriptor, returning the witness stack for the input.
230 * Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
231 * is not spending the outpoint described by `descriptor.outpoint`, or does not have a
232 * sequence set to `descriptor.to_self_delay`.
234 public Result_CVec_CVec_u8ZZNoneZ sign_dynamic_p2wsh_input(byte[] spend_tx, long input_idx, DelayedPaymentOutputDescriptor descriptor) {
235 long ret = bindings.InMemorySigner_sign_dynamic_p2wsh_input(this.ptr, spend_tx, input_idx, descriptor == null ? 0 : descriptor.ptr & ~1);
236 if (ret >= 0 && ret <= 4096) { return null; }
237 Result_CVec_CVec_u8ZZNoneZ ret_hu_conv = Result_CVec_CVec_u8ZZNoneZ.constr_from_ptr(ret);
238 this.ptrs_to.add(descriptor);
243 * Constructs a new BaseSign which calls the relevant methods on this_arg.
244 * This copies the `inner` pointer in this_arg and thus the returned BaseSign must be freed before this_arg is
246 public BaseSign as_BaseSign() {
247 long ret = bindings.InMemorySigner_as_BaseSign(this.ptr);
248 if (ret >= 0 && ret <= 4096) { return null; }
249 BaseSign ret_hu_conv = new BaseSign(null, ret);
250 ret_hu_conv.ptrs_to.add(this);
255 * Constructs a new Sign which calls the relevant methods on this_arg.
256 * This copies the `inner` pointer in this_arg and thus the returned Sign must be freed before this_arg is
258 public Sign as_Sign() {
259 long ret = bindings.InMemorySigner_as_Sign(this.ptr);
260 if (ret >= 0 && ret <= 4096) { return null; }
261 Sign ret_hu_conv = new Sign(null, ret);
262 ret_hu_conv.ptrs_to.add(this);
267 * Serialize the InMemorySigner object into a byte array which can be read by InMemorySigner_read
269 public byte[] write() {
270 byte[] ret = bindings.InMemorySigner_write(this.ptr);
275 * Read a InMemorySigner from a byte array, created by InMemorySigner_write
277 public static Result_InMemorySignerDecodeErrorZ read(byte[] ser) {
278 long ret = bindings.InMemorySigner_read(ser);
279 if (ret >= 0 && ret <= 4096) { return null; }
280 Result_InMemorySignerDecodeErrorZ ret_hu_conv = Result_InMemorySignerDecodeErrorZ.constr_from_ptr(ret);